Deactivate triaxial stress controller

Asked by Yuxuan Wang on 2020-07-13

Hello Yade programmers and users,
I encountered a problem in my recent simulation script which has been troubling me, and it’d be much appreciated if I can get some advice.

Here are the steps I’m trying to accomplish:
1. Make a loose pack of particles following defined PSD.
2. Use compression engine to generate a denser pack.
3. At defined iteration #, turn off compression engine.
4. Filter pack with pack.filterpack into desired shape.
5. Continue with further steps (gravity deposition, geometry rotation, etc).

My question came with step 3. While using “triaxialStressController.dead=True” to turn off the compression engine, I kept getting the following error:
---------------------------------------------------
---> 97 controller.dead=True,
ArgumentError: Python argument types in
    None.None(TriaxialStressController, tuple)
did not match C++ signature:
    None(Engine {lvalue}, bool)
---------------------------------------------------
Here is my script using yade 2018.02b:

#!/usr/bin/python
# -*- coding: utf-8 -*-

from __future__ import print_function
import matplotlib; matplotlib.rc('axes',grid=True)
import pylab
from yade import pack, plot, qt
from yade import export

### DEFINING VARIABLES AND MATERIALS ###

#geometry definition
Ri,Rs,Ro=6.5,8.5,10.5
H=3.5
p=H/2
k=0.01
Hs=H*k
hs=Hs/2
Rx=2*Ro
Hx=2*H

c1=geom.facetCylinder(center=(0,0,p),radius=Ro, height=H, segmentsNumber=20, wallMask=6)
c2=geom.facetCylinder(center=(0,0,hs),radius=Rs, height=Hs, segmentsNumber=20, wallMask=7)
c3=geom.facetCylinder(center=(0,0,p),radius=Ri, height=H, segmentsNumber=20, wallMask=7)

nRead=readParamsFromTable(
 num_spheres=5000,
 compFricDegree = 30,
 unknownOk=True
)

from yade.params import table
num_spheres=table.num_spheres
compFricDegree = table.compFricDegree
damp=0.2
young=5e6 # contact stiffness
mn,mx=Vector3(-50,-50,-50),Vector3(50,50,50) # corners of the initial packing

## create materials for spheres and plates
O.materials.append(FrictMat(young=young,poisson=0.5,frictionAngle=radians(compFricDegree),density=2600,label='spheres'))
O.materials.append(FrictMat(young=young,poisson=0.5,frictionAngle=0,density=0,label='walls'))

## create walls around the packing
walls=aabbWalls([mn,mx],thickness=0,material='walls')
wallIds=O.bodies.append(walls)

## use a SpherePack object to generate a psd loose particles packing
global sp
sp=pack.SpherePack()
sp.makeCloud(mn,mx,num=6000,psdSizes=[1,2,2.25,2.5,3,4,6],psdCumm=[0.,0.1,0.3,0.3,.3,.7,1.])
sp.toSimulation(material='spheres')

### DEFINING ENGINES ###

triax=TriaxialStressController(
 thickness = 0,
 stressMask = 7,
 internalCompaction=False,
 label='controller'
)

newton=NewtonIntegrator(damping=damp)

O.engines=[
 ForceResetter(),
 InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Box_Aabb()]),
 InteractionLoop(
  [Ig2_Sphere_Sphere_ScGeom(),Ig2_Box_Sphere_ScGeom()],
  [Ip2_FrictMat_FrictMat_FrictPhys()],
  [Law2_ScGeom_FrictPhys_CundallStrack()]
 ),

 PyRunner(command='stop()',iterPeriod=10,label='checker'),
 GlobalStiffnessTimeStepper(active=1,timeStepUpdateInterval=100,timestepSafetyCoefficient=0.8),
 triax,
 newton
]

#Display spheres with 2 colors for seeing rotations better
Gl1_Sphere.stripes=0
if nRead==0: yade.qt.Controller(), yade.qt.View()

### APPLYING CONFINING PRESSURE ###

triax.goal1=triax.goal2=triax.goal3=-10000

def stop():
 if O.iter<100:return
 controller.dead=True,
 checker.command='gravityDeposition()'

def gravityDeposition():
  pred=pack.inCylinder((0,0,0),(0,0,H),Ro)-pack.inCylinder((0,0,0),(0,0,Hs),Rs)-pack.inCylinder((0,0,0),(0,0,H),Ri)
  assembly=pack.filterSpherePack(pred,sp,True)
  assembly.toSimulation()

#...connect to next steps in simulation
---------------------------------------------------
Thanks for the help in advance!

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Jan Stránský
Solved:
2020-07-15
Last query:
2020-07-15
Last reply:
2020-07-14
Chu (arcoubuntu) said : #1

Hi Yuxuan,

--> controller.dead=True,
There may shouldn't be ' , '

Reagrds

Jan Stránský (honzik) said : #2

just to make the Chu's answer a bit more verbose. If you put comma the end of the assignment line, Python interpret it as a tulple:
###
a = True
b = True,
print(a)
print(b)
print(type(a))
print(type(b))
###
This is what the error says, that it expects a boolean (e.g. True), but got a tuple: (True,)

cheers
Jan

Yuxuan Wang (ywang1) said : #3

Thanks for the clarification, Chu and Jan! I am still quite new to python and struggled to understand the error message. It's clear now!

I hoped to use "triaxialStressEngine.dead" to stop the walls from compressing the particles while O.engines is still running. Now although it returns “true” when I ask for “In [3]: controller.dead” in the terminal, the walls don’t stop compressing. Is it because “triaxialStressEngine.dead” isn’t the way to accomplish it or are there other errors in my code?

I have done some slight modifications on “stop()” and “gravityDeposition()” at the end of my code.

Really appreciate your help!
-Yuxuan
----------------------------
#!/usr/bin/python
# -*- coding: utf-8 -*-

from __future__ import print_function
import matplotlib; matplotlib.rc('axes',grid=True)
import pylab
from yade import pack, plot, qt
from yade import export

############################################
### DEFINING VARIABLES AND MATERIALS ###
############################################

#geometry definition
Ri,Rs,Ro=6.5,8.5,10.5
H=3.5
p=H/2
k=0.01
Hs=H*k
hs=Hs/2
Rx=2*Ro
Hx=2*H

c1=geom.facetCylinder(center=(0,0,p),radius=Ro, height=H, segmentsNumber=20, wallMask=6)
c2=geom.facetCylinder(center=(0,0,hs),radius=Rs, height=Hs, segmentsNumber=20, wallMask=7)
c3=geom.facetCylinder(center=(0,0,p),radius=Ri, height=H, segmentsNumber=20, wallMask=7)

nRead=readParamsFromTable(
 num_spheres=5000,
 compFricDegree = 30,
 unknownOk=True
)

from yade.params import table
num_spheres=table.num_spheres
compFricDegree = table.compFricDegree
damp=0.2
young=5e6 # contact stiffness
mn,mx=Vector3(-50,-50,-50),Vector3(50,50,50) # corners of the initial packing

## create materials for spheres and plates
O.materials.append(FrictMat(young=young,poisson=0.5,frictionAngle=radians(compFricDegree),density=2600,label='spheres'))
O.materials.append(FrictMat(young=young,poisson=0.5,frictionAngle=0,density=0,label='walls'))

## create walls around the packing
walls=aabbWalls([mn,mx],thickness=0,material='walls')
wallIds=O.bodies.append(walls)

## use a SpherePack object to generate a psd loose particles packing
global sp
sp=pack.SpherePack()
sp.makeCloud(mn,mx,num=6000,psdSizes=[1,2,2.25,2.5,3,4,6],psdCumm=[0.,0.1,0.3,0.3,.3,.7,1.])
sp.toSimulation(material='spheres')

############################
### DEFINING ENGINES ###
############################

triax=TriaxialStressController(
 thickness = 0,
 stressMask = 7,
 internalCompaction=False,
 label='controller'
)

newton=NewtonIntegrator(damping=damp)

O.engines=[
 ForceResetter(),
 InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Box_Aabb()]),
 InteractionLoop(
  [Ig2_Sphere_Sphere_ScGeom(),Ig2_Box_Sphere_ScGeom()],
  [Ip2_FrictMat_FrictMat_FrictPhys()],
  [Law2_ScGeom_FrictPhys_CundallStrack()]
 ),

 PyRunner(command='stop()',iterPeriod=10,label='checker'),
 GlobalStiffnessTimeStepper(active=1,timeStepUpdateInterval=100,timestepSafetyCoefficient=0.8),
 triax,
 newton
]

#Display spheres with 2 colors for seeing rotations better
Gl1_Sphere.stripes=0
if nRead==0: yade.qt.Controller(), yade.qt.View()

#######################################
### APPLYING CONFINING PRESSURE ###
#######################################

triax.goal1=triax.goal2=triax.goal3=-10000

def stop():
 if O.iter<100:return
 else:
  controller.dead=True
  #O.pause()
  checker.command='gravityDeposition()'

def gravityDeposition():
 if O.iter<103:
  pred=pack.inCylinder((0,0,0),(0,0,H),Ro)-pack.inCylinder((0,0,0),(0,0,Hs),Rs)-pack.inCylinder((0,0,0),(0,0,H),Ri)
  assembly=pack.filterSpherePack(pred,sp,True)
  assembly.toSimulation()
 else:
  print ('done')
  #O.pause()
#...connect to next steps in simulation

Best Jan Stránský (honzik) said : #4

controller.dead=True deactivates the controller, but does nothing with already given velocities of the walls.
If you want the walls to have zero velocity, try to set it explicitly:

for wall in walls:
   wall.state.vel = Vector3.Zero

cheers
Jan

Yuxuan Wang (ywang1) said : #5

Thanks Jan Stránský, that solved my question.