local variable 'compFricDegree' referenced before assignment

Asked by Rong Zhao

Hello, everyone!
I am trying to specify porosity value after the compaction in periodic triaxial test base on the following codes, but there is something wrong with it.
First, I am not sure whether porosity can be specified after the compaction in a periodic triaxial test like the example of the triaxial test using TriaxialStressController.

Second, when I try to realize it in the periodic triaxial test using PeriTriaxController(), there is something wrong with it( local variable 'compFricDegree' referenced before assignment). Here is my conde.
# Specify the porosity in periodic triaxial test

from yade import pack, qt, plot

sigmaIso=-1e5
targetPorosity = 0.3
compFricDegree = 30
young = 5e6
num_spheres = 1000
mn, mx = Vector3(0,0,0), Vector3(1,1,1)

# generate loose packing

O.materials.append(FrictMat(young=young,poisson=0.5,frictionAngle=radians(compFricDegree),density=2600,label='spheres'))
O.periodic=True
sp=pack.SpherePack()
sp.makeCloud(mn,mx,-1,0.3333,num_spheres,False, 0.95,seed=1)
sp.toSimulation()

# Set simulation loop
O.engines=[
 ForceResetter(),
 InsertionSortCollider([Bo1_Sphere_Aabb()]),
 InteractionLoop(
  [Ig2_Sphere_Sphere_ScGeom()],
  [Ip2_FrictMat_FrictMat_FrictPhys()],
  [Law2_ScGeom_FrictPhys_CundallStrack()]
 ),
 PeriTriaxController(label='triax',
  # specify target values and whether they are strains or stresses
  goal=(sigmaIso,sigmaIso,sigmaIso),stressMask=7,
  # type of servo-control
  dynCell=True,maxStrainRate=(10,10,10),
  # wait until the unbalanced force goes below this value
  maxUnbalanced=.1,relStressTol=1e-3,
  # call this function when goal is reached and the packing is stable
  doneHook='compactionFinished()'
 ),
 NewtonIntegrator(damping=.2),
]

O.dt=.5*PWaveTimeStep()

def compactionFinished():
 print('Compaction Finished')
 O.pause()
 pc = utils.porosity()
 print("Porosity after compaction: " + str(pc))
 # Reach a Specified Porosity precisely
 import sys #this is only for the flush() below
 while pc > targetPorosity:
     # we decrease friction value and apply it to all the bodies and contacts
     compFricDegree = 0.95*compFricDegree
     setContactFriction(radians(compFricDegree))
     pc = utils.porosity()
     print "\r Friction: ",compFricDegree," porosity:",utils.porosity()
     sys.stdout.flush()
     O.run(500,1)
 return pc

Thanks!

Question information

Language:
English Edit question
Status:
Answered
For:
Yade Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Robert Caulk (rcaulk) said :
#1

Hello,

>something wrong with it (local variable 'compFricDegree' referenced before assignment)

Please copy and paste the entire trace.

Revision history for this message
Robert Caulk (rcaulk) said :
#2

Your line

compFricDegree = 0.95*compFricDegree

inside your compactionFinished() scope, is referencing the local variable compFricDegree before (during) assignment.

Here you will find your solution [1], specifically the section titled "scope".

[1]https://sebastianraschka.com/Articles/2014_python_scope_and_namespaces.html

Can you help with this problem?

Provide an answer of your own, or ask Rong Zhao for more information if necessary.

To post a message you must log in.