How to close the function doneHook in PeriTriaxController

Asked by Zhicheng Gao on 2021-06-01

I don't want to call any Python command again when the sample is isotropic compacted, so I set doneHook=uninitalized. Is that right?
The code of mine is shown below:
##______________ First section, generate sample_________

from __future__ import print_function
from yade import pack, qt, plot
from math import *

nRead=readParamsFromTable(
        ## model parameters
        num_spheres=10000,
        targetPorosity=0.387,
        confiningPressure=-100000,
        ## material parameters
        compFricDegree=15,#contact friction during the confining phase
        finalFricDegree=30,#contact friction during the deviatoric loading
        young=2e8,
        poisson=.2,
        density=2600,
        alphaKr=7.5,
        alphaKtw=0,
        etaRoll=.22,
        etaTwist=0,
        normalCohesion=0,
        shearCohesion=0,
        ## fluid parameters
        fluidDensity=1000,
        dynamicViscosity=.001,
        ## control parameters
        damp=0,
        stabilityThreshold=.001,
        ## output specifications
        filename='suffusion',
        unknowOk=True
)

from yade.params.table import *

O.periodic=True
O.cell.hSize=Matrix3(.05,0,0, 0,.05,0, 0,0,.05)
# create materials for spheres
#shear strength is the sum of friction and adhesion, so the momentRotationLaw=True
O.materials.append(CohFrictMat(alphaKr=alphaKr,alphaKtw=alphaKtw,density=density,etaRoll=etaRoll,etaTwist=etaTwist,frictionAngle=radians(compFricDegree),momentRotationLaw=True,normalCohesion=normalCohesion,poisson=poisson,shearCohesion=shearCohesion,young=young,label='spheres'))

# generate particles packing
sp=pack.SpherePack()
sp.makeCloud((0,0,0),(.05,.05,.05),psdSizes=[0.00008,0.000125,0.0001592,0.0002003,0.0003153,0.000399,0.000502,0.0005743],psdCumm=[0.0,0.00628,0.0565,0.198,0.721,0.915,0.991,1.0],num=num_spheres)
sp.toSimulation(material='spheres')

O.engines=[
        ForceResetter(),
        InsertionSortCollider([Bo1_Sphere_Aabb()]),
        InteractionLoop(
            [Ig2_Sphere_Sphere_ScGeom6D()],
            [Ip2_CohFrictMat_CohFrictMat_CohFrictPhys(label='contact',setCohesionNow=False,setCohesionOnNewContacts=False)],
            [Law2_ScGeom6D_CohFrictPhys_CohesionMoment(useIncrementalForm=True,always_use_moment_law=True)]),
        PeriodicFlowEngine(dead=1,label='flow'),#introduced as a dead engine for the moment, see 2nd section
        GlobalStiffnessTimeStepper(active=1,timeStepUpdateInterval=100,timestepSafetyCoefficient=0.8),
        PeriTriaxController(label='triax',
            # specify target values and whether they are strains or stresses
            goal=(confiningPressure,confiningPressure,confiningPressure), stressMask=7,
            # type of servo-control, the strain rate isn't determined, it shloud check the unbalanced force
            dynCell=True,maxStrainRate=(1,1,1),
            # wait until the unbalanced force goes below this value
            maxUnbalanced=stabilityThreshold,relStressTol=1e-3,
            doneHook='compactionFinished()'
            ),
        NewtonIntegrator(damping=0)
]
import sys
def compactionFinished():
        #check the current porosity
        porosity=porosity()
        # if the current porosity is lager than target Porosity and comFricDegree is lager than 10,
        # then we decrease friction value and apply it to all the bodies and contacts,
        # else we decrease rolling friction value.
        if porosity>targetPorosity and compFricDegree>10:
            O.pause()
            # we decrease friction value and apply it to all the bodies and contacts
            compFricDegree = 0.95*compFricDegree
            setContactFriction(radians(compFricDegree))
            print('Friction:', compFricDegree,'porosity:', porosity)
            # python syntax, make each step printout
            sys.stdout.flush()
            # Run again to the target confining pressure
            O.run()
        elif porosity>targetPorosity:
            O.pause()
            # we decrease rolling fiction value and apply it to all the bodies and contacts
            for b in O.bodies:
                b.mat.etaRoll=0.95*etaRoll
            for i in O.interactions:
                i.phys.etaRoll=0.95*etaRoll
            print('Rollingfriction:', b.mat.etaRoll, 'porosity:', porosity)
            sys.stdout.flush()
            O.run()
        else:
     # after sample preparation, save the state
            O.save('compactedState'+filename+'.yade.gz')
            print('Compacted state saved', 'porosity', porosity)
            # next time, don't call any python command
            triax.doneHook=uninitalized
            O.pause()
O.run()

Question information

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

Hello,

>so I set doneHook=uninitalized. Is that right?

I would guess no, there will probably be a KeyErr complaint saying that "uninitialized" does not exist.

Usually in python you would use None for something like this.

doneHook=None

Hope it helps,

Rob

Revision history for this message
Zhicheng Gao (zhichenggao) said :
#2

Dear Robert,
According to your suggestion, I have modified the code, but there is an error

 ArgumentError: Python argument types in
    None.None(PeriTriaxController, NoneType)
did not match C++ signature:
    None(PeriTriaxController {lvalue}, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)
Compacted state saved porosity 0.366658082769

the code is followed:
from __future__ import print_function
from yade import pack, qt, plot
from math import *

nRead=readParamsFromTable(
        ## model parameters
        num_spheres=100,
        targetPorosity= .387,
        confiningPressure=-100000,
        ## material parameters
        compFricDegree=15,#contact friction during the confining phase
        finalFricDegree=30,#contact friction during the deviatoric loading
        young=2e8,
        poisson=.2,
        density=2600,
        alphaKr=7.5,
        alphaKtw=0,
 competaRoll=.22,
        finaletaRoll=.22,
        etaTwist=0,
        normalCohesion=0,
        shearCohesion=0,
        ## fluid parameters
        fluidDensity=1000,
        dynamicViscosity=.001,
        ## control parameters
        damp=0,
        stabilityThreshold=.001,
        ## output specifications
        filename='suffusion',
        unknowOk=True
)

from yade.params.table import *

O.periodic=True
O.cell.hSize=Matrix3(.001,0,0, 0,.001,0, 0,0,.001)
# create materials for spheres
#shear strength is the sum of friction and adhesion, so the momentRotationLaw=True
O.materials.append(CohFrictMat(alphaKr=alphaKr,alphaKtw=alphaKtw,density=density,etaRoll=competaRoll,etaTwist=etaTwist,frictionAngle=radians(compFricDegree),momentRotationLaw=True,normalCohesion=normalCohesion,poisson=poisson,shearCohesion=shearCohesion,young=young,label='spheres'))

# generate particles packing
sp=pack.SpherePack()
sp.makeCloud((0,0,0),(.001,.001,.001),psdSizes=[0.00008,0.000125,0.0001592,0.0002003,0.0003153,0.000399,0.000502,0.0005743],psdCumm=[0.0,0.00628,0.0565,0.198,0.721,0.915,0.991,1.0],num=num_spheres)
sp.toSimulation(material='spheres')

O.engines=[
        ForceResetter(),
        InsertionSortCollider([Bo1_Sphere_Aabb()]),
        InteractionLoop(
            [Ig2_Sphere_Sphere_ScGeom6D()],
            [Ip2_CohFrictMat_CohFrictMat_CohFrictPhys(label='contact',setCohesionNow=False,setCohesionOnNewContacts=False)],
            [Law2_ScGeom6D_CohFrictPhys_CohesionMoment(useIncrementalForm=True,always_use_moment_law=True)],
 ),
        PeriodicFlowEngine(dead=1,label="flow"),#introduced as a dead engine for the moment, see 2nd section
        GlobalStiffnessTimeStepper(active=1,timeStepUpdateInterval=100,timestepSafetyCoefficient=0.8),
        PeriTriaxController(label='triax',
            # specify target values and whether they are strains or stresses
            goal=(confiningPressure,confiningPressure,confiningPressure), stressMask=7,
            # type of servo-control, the strain rate isn't determined, it shloud check the unbalanced force
            dynCell=True,maxStrainRate=(10,10,10),
            # wait until the unbalanced force goes below this value
            maxUnbalanced=stabilityThreshold,relStressTol=1e-3,
            doneHook='compactionFinished()'
            ),
        NewtonIntegrator(damping=0)
]
qt.View()
import sys
def compactionFinished():
        #check the current porosity
        # if the current porosity is lager than target Porosity and comFricDegree is lager than 10,
        # then we decrease friction value and apply it to all the bodies and contacts,
        # else we decrease rolling friction value.
 global compFricDegree, competaRoll
        if porosity()>targetPorosity and compFricDegree>5:
            # we decrease friction value and apply it to all the bodies and contacts
            compFricDegree = 0.95*compFricDegree
            setContactFriction(radians(compFricDegree))
            print('Friction:', compFricDegree,'porosity:', porosity())
            # python syntax, make each step printout
            sys.stdout.flush()
        elif porosity()>targetPorosity:
            # we decrease rolling fiction value and apply it to all the bodies and contacts
     competaRoll=0.95*competaRoll
            for b in O.bodies:
                b.mat.etaRoll=competaRoll
            for i in O.interactions:
                i.phys.etaRoll=competaRoll
            print('Rollingfriction:', b.mat.etaRoll, 'porosity:', porosity())
            sys.stdout.flush()
        else:
     # after sample preparation, save the state
            O.save('compactedState'+filename+'.yade.gz')
            print('Compacted state saved', 'porosity', porosity())
            # next time, called python command
            triax.doneHook=None
            O.pause()
O.run()

Revision history for this message
Zhicheng Gao (zhichenggao) said :
#3

Dear Robert,
According to your suggestion, I have modified the code, but there is an error

 ArgumentError: Python argument types in
    None.None(PeriTriaxController, NoneType)
did not match C++ signature:
    None(PeriTriaxController {lvalue}, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)
Compacted state saved porosity 0.366658082769

the code is followed:
from __future__ import print_function
from yade import pack, qt, plot
from math import *

nRead=readParamsFromTable(
        ## model parameters
        num_spheres=100,
        targetPorosity= .387,
        confiningPressure=-100000,
        ## material parameters
        compFricDegree=15,#contact friction during the confining phase
        finalFricDegree=30,#contact friction during the deviatoric loading
        young=2e8,
        poisson=.2,
        density=2600,
        alphaKr=7.5,
        alphaKtw=0,
 competaRoll=.22,
        finaletaRoll=.22,
        etaTwist=0,
        normalCohesion=0,
        shearCohesion=0,
        ## fluid parameters
        fluidDensity=1000,
        dynamicViscosity=.001,
        ## control parameters
        damp=0,
        stabilityThreshold=.001,
        ## output specifications
        filename='suffusion',
        unknowOk=True
)

from yade.params.table import *

O.periodic=True
O.cell.hSize=Matrix3(.001,0,0, 0,.001,0, 0,0,.001)
# create materials for spheres
#shear strength is the sum of friction and adhesion, so the momentRotationLaw=True
O.materials.append(CohFrictMat(alphaKr=alphaKr,alphaKtw=alphaKtw,density=density,etaRoll=competaRoll,etaTwist=etaTwist,frictionAngle=radians(compFricDegree),momentRotationLaw=True,normalCohesion=normalCohesion,poisson=poisson,shearCohesion=shearCohesion,young=young,label='spheres'))

# generate particles packing
sp=pack.SpherePack()
sp.makeCloud((0,0,0),(.001,.001,.001),psdSizes=[0.00008,0.000125,0.0001592,0.0002003,0.0003153,0.000399,0.000502,0.0005743],psdCumm=[0.0,0.00628,0.0565,0.198,0.721,0.915,0.991,1.0],num=num_spheres)
sp.toSimulation(material='spheres')

O.engines=[
        ForceResetter(),
        InsertionSortCollider([Bo1_Sphere_Aabb()]),
        InteractionLoop(
            [Ig2_Sphere_Sphere_ScGeom6D()],
            [Ip2_CohFrictMat_CohFrictMat_CohFrictPhys(label='contact',setCohesionNow=False,setCohesionOnNewContacts=False)],
            [Law2_ScGeom6D_CohFrictPhys_CohesionMoment(useIncrementalForm=True,always_use_moment_law=True)],
 ),
        PeriodicFlowEngine(dead=1,label="flow"),#introduced as a dead engine for the moment, see 2nd section
        GlobalStiffnessTimeStepper(active=1,timeStepUpdateInterval=100,timestepSafetyCoefficient=0.8),
        PeriTriaxController(label='triax',
            # specify target values and whether they are strains or stresses
            goal=(confiningPressure,confiningPressure,confiningPressure), stressMask=7,
            # type of servo-control, the strain rate isn't determined, it shloud check the unbalanced force
            dynCell=True,maxStrainRate=(10,10,10),
            # wait until the unbalanced force goes below this value
            maxUnbalanced=stabilityThreshold,relStressTol=1e-3,
            doneHook='compactionFinished()'
            ),
        NewtonIntegrator(damping=0)
]
qt.View()
import sys
def compactionFinished():
        #check the current porosity
        # if the current porosity is lager than target Porosity and comFricDegree is lager than 10,
        # then we decrease friction value and apply it to all the bodies and contacts,
        # else we decrease rolling friction value.
 global compFricDegree, competaRoll
        if porosity()>targetPorosity and compFricDegree>5:
            # we decrease friction value and apply it to all the bodies and contacts
            compFricDegree = 0.95*compFricDegree
            setContactFriction(radians(compFricDegree))
            print('Friction:', compFricDegree,'porosity:', porosity())
            # python syntax, make each step printout
            sys.stdout.flush()
        elif porosity()>targetPorosity:
            # we decrease rolling fiction value and apply it to all the bodies and contacts
     competaRoll=0.95*competaRoll
            for b in O.bodies:
                b.mat.etaRoll=competaRoll
            for i in O.interactions:
                i.phys.etaRoll=competaRoll
            print('Rollingfriction:', b.mat.etaRoll, 'porosity:', porosity())
            sys.stdout.flush()
        else:
     # after sample preparation, save the state
            O.save('compactedState'+filename+'.yade.gz')
            print('Compacted state saved', 'porosity', porosity())
            # next time, called python command
            triax.doneHook=None
            O.pause()
O.run()

Revision history for this message
Jan Stránský (honzik) said :
#4

As the error says, it expects a string, not None. Try
triax.doneHook=""

Another point, why to bother with it at all? What happen if you delete the line? After all, you call it already **inside** triax.doneHook.
Modifying the doneHook inside doneHook, when the hook is over and the triax is done, does not make much sense..

cheers
Jan

Revision history for this message
Zhicheng Gao (zhichenggao) said :
#5

Because, in the next step, I want to erode the sample under the condition of isotropic pressure

Revision history for this message
Launchpad Janitor (janitor) said :
#6

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

Revision history for this message
Jan Stránský (honzik) said :
#7

Does
triax.doneHook=""
what you want or not?
Jan