Facing problem with "target porosity part" in triaxial test script

Asked by Swapnil

Hi friends,
I have been trying to work on the triaxial test using the example script in (1). My script is as follows:

#triaxial test on dry sand

import matplotlib
matplotlib.use('Qt4Agg')
from yade import pack,plot,qt
import math

num_spheres=10000 # number of spheres
young=3e10
targetPorosity= 0.45
compFricDegree = 35 # initial contact friction during the confining phase
finalFricDegree = 42 # contact friction during the deviatoric loading
mn,mx=Vector3(0,0,0),Vector3(0.1,0.1,0.1) # corners of the initial packing

O.materials.append(FrictMat(young=young,poisson=0.3,frictionAngle=radians(compFricDegree),density=2600,label='spheres'))
O.materials.append(FrictMat(young=young,poisson=0.5,frictionAngle=0,density=0,label='walls'))
walls=aabbWalls([mn,mx],thickness=0,material='walls')
wallIds=O.bodies.append(walls)

pred=pack.inAlignedBox(mn,mx)
sp=pack.randomDensePack(pred,radius=0.005,spheresInCell=num_spheres,material='spheres')#returnSpherePack=True)
O.bodies.append(sp)
#SpherePack.toSimulation(material='spheres')

newton=NewtonIntegrator(damping=0.3)

O.engines=[
 ForceResetter(),
 InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Box_Aabb(),Bo1_Wall_Aabb()]),
 InteractionLoop(
  [Ig2_Sphere_Sphere_ScGeom(),Ig2_Box_Sphere_ScGeom(), Ig2_Wall_Sphere_ScGeom()],
  [Ip2_FrictMat_FrictMat_FrictPhys()],
  [Law2_ScGeom_FrictPhys_CundallStrack()]
 ),
 TriaxialStressController(label='triax',
 maxMultiplier=1.+2e4/young, # spheres growing factor (fast growth)
 finalMaxMultiplier=1.+2e3/young, # spheres growing factor (slow growth)
 thickness = 0,
 stressMask =7,
 max_vel = 0.025,
 internalCompaction=True, # If true the confining pressure is generated by growing particles
),GlobalStiffnessTimeStepper(active=1,timeStepUpdateInterval=25,timestepSafetyCoefficient=0.8),PyRunner(iterPeriod=100,command='addPlotData()'),
 newton
]
O.dt=0.25*PWaveTimeStep()
#O.dt=0.005*PWaveTimeStep()
#strain_rate=-0.05
triax.goal1=triax.goal2=triax.goal3=-5e5

#Deviatoric loading
##We move to deviatoric loading, let us turn internal compaction off to keep particles sizes constant
triax.internalCompaction=False

## Change contact friction (remember that decreasing it would generate instantaneous instabilities)
setContactFriction(radians(finalFricDegree))

##set stress control on y and z, we will impose strain rate on x
triax.stressMask = 6
##now goal1 is the target strain rate
triax.goal1=-0.001
## we define the lateral stresses during the test, here the same 10kPa as for the initial confinement.
triax.goal2=-5e5
triax.goal3=-5e5
##Save temporary state in live memory. This state will be reloaded from the interface with the "reload" button.
O.saveTmp()

def addPlotData():
  plot.addData(e11=-triax.strain[0], e22=-triax.strain[1], e33=-triax.strain[2],
        ev=-triax.strain[0]-triax.strain[1]-triax.strain[2],
      s11=-triax.stress(triax.wall_right_id)[0],
      s22=-triax.stress(triax.wall_top_id)[1],
      s33=-triax.stress(triax.wall_front_id)[2],
      i=O.iter)

plot.plots={'i':('e11','e22','e33',None,'s11','s22','s33')}
plot.plots={'e11':('s11'),'e22':('s22'),'e33':('s33')} #,'s22','s33')}
plot.plot()
--------------------
It appears to work fine (at least gives results) until I try to introduce a target porosity factor, again using the master example script in (1). When I add the following part into my script it runs with an repetitive error saying: "Error in line 1, áddplotdata not defined"

#Porosity
import sys #this is only for the flush() below
while triax.porosity>targetPorosity:
 ## we decrease friction value and apply it to all the bodies and contacts
 compFricDegree = 0.95*compFricDegree
 setContactFriction(radians(compFricDegree))
 print "\r Friction: ",compFricDegree," porosity:",triax.porosity,
 sys.stdout.flush()
 ## while we run steps, triax will tend to grow particles as the packing
 ## keeps shrinking as a consequence of decreasing friction. Consequently
 ## porosity will decrease
 O.run(500,1)

Any ideas what could possibly be going wrong from my side?

(1)https://github.com/yade/trunk/blob/master/examples/triax-tutorial/script-session1.py

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
Jérôme Duriez (jduriez) said :
#1

Hello,

In the error message printed by YADE, is there indeed a "á" with an accent ? (like in your problem description).

If yes, I guess it means you're asking somewhere to call "áddplotdata" (with accent), whereas that's "addplotdata" (or "addPlotData"...) that is defined elsewhere...

In fine, without a precise and clear statement of the exact commands you actually typed and that actually triggered the error, it's hard to answer... ;-)

Jerome

Revision history for this message
Swapnil (swapspace) said :
#2

Nope Jerome. Sorry that was a typo here and not on the script ;)
Its "addplotdata"

Revision history for this message
Swapnil (swapspace) said :
#3

Hi Jerome, did you try it out? Does it work fine for your system?

Revision history for this message
Swapnil (swapspace) said :
#4

the full code I am trying is as follows:

import matplotlib
matplotlib.use('Qt4Agg')
from yade import pack,plot,qt
import math

num_spheres=1000 # number of spheres
young=3e10
targetPorosity= 0.40
compFricDegree = 40 # initial contact friction during the confining phase
finalFricDegree = 30 # contact friction during the deviatoric loading
mn,mx=Vector3(0,0,0),Vector3(0.01,0.01,0.01) # corners of the initial packing

O.materials.append(FrictMat(young=young,poisson=0.3,frictionAngle=radians(compFricDegree),density=2600,label='spheres'))
O.materials.append(FrictMat(young=young,poisson=0.5,frictionAngle=0,density=0,label='walls'))
walls=aabbWalls([mn,mx],thickness=0,material='walls')
wallIds=O.bodies.append(walls)

pred=pack.inAlignedBox(mn,mx)
sp=pack.randomDensePack(pred,radius=0.0005,spheresInCell=num_spheres,material='spheres')#returnSpherePack=True)
O.bodies.append(sp)
#SpherePack.toSimulation(material='spheres')

newton=NewtonIntegrator(damping=0.3)

O.engines=[
 ForceResetter(),
 InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Box_Aabb(),Bo1_Wall_Aabb()]),
 InteractionLoop(
  [Ig2_Sphere_Sphere_ScGeom(),Ig2_Box_Sphere_ScGeom(), Ig2_Wall_Sphere_ScGeom()],
  [Ip2_FrictMat_FrictMat_FrictPhys()],
  [Law2_ScGeom_FrictPhys_CundallStrack()]
 ),
 TriaxialStressController(label='triax',
 maxMultiplier=1.+2e4/young, # spheres growing factor (fast growth)
 finalMaxMultiplier=1.+2e3/young, # spheres growing factor (slow growth)
 thickness = 0,
 stressMask =7,
 max_vel = 0.025,
 internalCompaction=True, # If true the confining pressure is generated by growing particles
),GlobalStiffnessTimeStepper(active=1,timeStepUpdateInterval=50,timestepSafetyCoefficient=0.8),PyRunner(iterPeriod=100,command='addPlotData()'),
 newton
]
O.dt=0.25*PWaveTimeStep()
#O.dt=0.005*PWaveTimeStep()
#strain_rate=-0.05
triax.goal1=triax.goal2=triax.goal3=-2e5

#Porosity
import sys #this is only for the flush() below
while triax.porosity>targetPorosity:
 ## we decrease friction value and apply it to all the bodies and contacts
  compFricDegree = 0.95*compFricDegree
  setContactFriction(radians(compFricDegree))
  #print "\r Friction:",compFricDegree,"porosity:",triax.porosity,sys.stdout.flush()
 ## while we run steps, triax will tend to grow particles as the packing
 ## keeps shrinking as a consequence of decreasing friction. Consequently
 ## porosity will decrease
  O.run(500,1)

#Deviatoric loading
##We move to deviatoric loading, let us turn internal compaction off to keep particles sizes constant
triax.internalCompaction=False

## Change contact friction (remember that decreasing it would generate instantaneous instabilities)
setContactFriction(radians(finalFricDegree))

##set stress control on y and z, we will impose strain rate on x
triax.stressMask = 6
##now goal1 is the target strain rate
triax.goal1=-0.001
## we define the lateral stresses during the test, for the initial confinement.
triax.goal2=-2e5
triax.goal3=-2e5
##Save temporary state in live memory. This state will be reloaded from the interface with the "reload" button.
O.saveTmp()

def addPlotData():
  plot.addData(e11=-triax.strain[0], e22=-triax.strain[1], e33=-triax.strain[2],
        ev=-triax.strain[0]-triax.strain[1]-triax.strain[2],
      s11=-triax.stress(triax.wall_right_id)[0],
      s22=-triax.stress(triax.wall_top_id)[1],
      s33=-triax.stress(triax.wall_front_id)[2],
      i=O.iter)

plot.plots={'i':('e11','e22','e33',None,'s11','s22','s33')}
plot.plots={'e11':('s11'),'e22':('s22'),'e33':('s33')} #,'s22','s33')}
plot.plot()

As in above, when I include the #porosity segment: the error, which I can clearly read now, is:
Traceback (most recent call last):
file "<string>", line 1, in <module>
Nameerror: name 'addPlotData' is not defined.

any ideas why it appears and how to rectify it?

Revision history for this message
Jérôme Duriez (jduriez) said :
#5

Thanks for the clarification, this kind of error essentially means you're calling an addPlotData function which is not known, i.e. defined, at the time you call it. (it is not really YADE-specific, that's a normal behavior for a computer)

Indeed, the definition of addPlotData() here comes at the end of your script, after the first O.run() commands, hence after the first calls to addPlotData().

You have to move the definition of addPlotData() at a suitable place, ie before any O.run (before that the PyRunner calling addPlotData could be executed, strictly speaking)

Jérôme

Revision history for this message
Swapnil (swapspace) said :
#6

Thanks a lot Jerome ! The problem was indeed with the position of "Run(500,1)". Upon shifting the command to the bottom of the script, it appears to have gotten rid of the error. However, I am still waiting to see the difference in the results with my slow-moving system :D

Can you help with this problem?

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

To post a message you must log in.