yade-users team mailing list archive
-
yade-users team
-
Mailing list archive
-
Message #02773
Python script : i.phys=NoneType ??
ReHello,
Again a question, sorry but python is finally not so easy for me.
In the attached script I want to consider the contact between two
spheres and store (in python data) the value of the normal force of the
interaction. As in mindlin_test.py I use something like :
VecFn=i.phys.normalForce
At the launch of the script this does not work : i.phys is considered as
a 'NonType' and does not have thus an attribute 'normalForce'.
If, just after this launch, I type the same lines in yade shell, it does
not present any problem : i.phys is indeed a 'NormalInelasticityPhys'
and contains thus a 'normalForce'
Log-proof :
jduriez@c1solimara-l:~/YADE/bin$ ./yade-trunk
/home/3S-LAB/jduriez/yade/scripts/NormalInelasticityTest.py
Welcome to Yade
bzr2144
-----BLABLA FIXME-----
Running script /home/3S-LAB/jduriez/yade/scripts/NormalInelasticityTest.py
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/3S-LAB/jduriez/yade/scripts/NormalInelasticityTest.py",
line 40, in defData
VecFn=i.phys.normalForce
AttributeError: 'NoneType' object has no attribute 'normalForce'
[[ ^L clears screen, ^U kills line. F12 controller, F11 3d view, F10
both, F9 generator, F8 plot. ]]
Yade [1]: i=O.interactions[1,0]
Yade [2]: VecFn=i.phys.normalForce
Yade [3]: i.phys.blabla
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/home/3S-LAB/jduriez/YADE/lib/yade-trunk/py/yade/__init__.pyc in <module>()
----> 1
2
3
4
5
AttributeError: 'NormalInelasticityPhys' object has no attribute 'blabla'
I thought once that there could be a problem at the very first iteration
where the interaction is not yet defined (with its physics), but making
a free-iteration (see commented lines) before does not change anything.
Moreover, it appeared me finally as a non-valid explanation due to the
order of the Engines.
Thanks a lot
--
Jérôme Duriez
ATER Iut 1 Grenoble, département GMP - Laboratoire 3S-R
04.56.52.86.49 (ne pas laisser de messages sur le répondeur)
# Script to test the constitutive law contained in NormalInelasticityLaw
from yade import plot
#Def of the material which will be used
O.materials.append(CohesiveFrictionalMat(density=2600,young=4.0e9,poisson=.04,frictionAngle=.6,label='Materiau1'))
#Def of the bodies of the simulations : 2 spheres, with names which will be useful after
O.bodies.append(utils.sphere([0,0,0], 1, dynamic=False, wire=False, color=None, highlight=False, material='Materiau1'))
O.bodies.append(utils.sphere([0,2,0], 1, dynamic=True, wire=False, color=None, highlight=False, material='Materiau1'))
LowerSphere=O.bodies[0]
UpperSphere=O.bodies[1]
#Def of the engines taking part to the simulation loop
O.engines=[
ForceResetter(),
BoundDispatcher([Bo1_Sphere_Aabb()]),
InsertionSortCollider(),
InteractionGeometryDispatcher([Ig2_Sphere_Sphere_ScGeom()]),
InteractionPhysicsDispatcher([Ip2_2xCohFrictMat_NormalInelasticityPhys()]),
# ConstitutiveLawDispatcher([Law2_ScGeom_NormalInelasticityPhys_NormalInelasticity()]),
Law2_ScGeom_NormalInelasticityPhys_NormalInelasticity(),
NewtonIntegrator(damping=0.0)
,PeriodicPythonRunner(iterPeriod=1,command='defData()')
,PeriodicPythonRunner(iterPeriod=1,command='letMove()')
]
#O.run(1,True) #one cycle "for free", so that the interaction between spheres will be defined (with his physics and so on)
#O.engines=O.engines+[PeriodicPythonRunner(iterPeriod=1,command='defData()')]
#O.engines=O.engines+[PeriodicPythonRunner(iterPeriod=1,command='letMove()')] # python function which will impose the relative movement between spheres
#Def of the python command defData() :
def defData():
i=O.interactions[1,0]
VecFn=i.phys.normalForce
VecDist=UpperSphere.state.pos-LowerSphere.state.pos
plot.addData(Normfn=VecFn.Length(),FnY=VecFn[1],step=O.iter,un=LowerSphere.shape.radius+UpperSphere.shape.radius-VecDist.Length())
#Def of the python command letMove() :
# Will move "by hand" the upperSphere towards or away from the lower one. Modifying by hand only the speed of bodies is indeed not sufficient, see NewtonsIntegrator, and https://bugs.launchpad.net/yade/+bug/398089
#Load for the first 10 iterations
#Unload for the 7 following iterations
#Then reload
def letMove():
vImposed=[0,-1,0]
if O.iter < 18 and O.iter>10:
vImposed=[0,1,0]
UpperSphere.state.vel=vImposed
UpperSphere.state.pos=UpperSphere.state.pos+UpperSphere.state.vel*O.dt
O.dt=1e-5
O.run(40,True)
## make one plot: step as function of fn
plot.plots={'step':('un')}
plot.plot()
plot.plots={'step':('Normfn')}
plot.plots={'un':('Normfn')}
Follow ups