← Back to team overview

yade-dev team mailing list archive

Re: evaluating expressions in python

 

Sorry, Bruno, I do not understand, what is the problem in.
Take back your script. I have cleaned it a little bit from warnings.

You have 2 O.run() in your script. Why?
Why do you comment the one of "runs" and await the same result?

I think you do not have python-mistakes in your code. Look for a logic of
your script.
I have never worked with PeriTriaxController and it is difficult for me to
understand quickly how it is working in details.

Try to figure out those to O.runs() and if it still a problem, I will try to
help.
______________________________

Anton Gladkyy


2010/5/26 Bruno Chareyre <bruno.chareyre@xxxxxxxxxxx>

> I can be a bit more specific now. I found that it works "sometimes".
> Here is a script. If you run it straightaway, it will print :
>
> "refstrain= 2.0  (should be 2.0), phase= 1  (should be 1)"
>
> Now, comment the two last lines and run it again (until it stops
> automatically or as soon as you see "Now εz will go from 0 to .2" output).
>
> print refstrain,phase
> : 0.0 0
>
> Thanks for help.
>
> Bruno
>
> Anton Gladky a écrit :
>
>> Put your code in f separate file and start with YADE.
>> If it does not work - please, send the script here.
>> ______________________________
>>
>> Anton Gladkyy
>>
>>
>> 2010/5/26 Bruno Chareyre <bruno.chareyre@xxxxxxxxxxx <mailto:
>> bruno.chareyre@xxxxxxxxxxx>>
>>
>>
>>    Thank you. I get the logic (I also get declaring and defining at
>>    the same time is the source of all mess).
>>    I'm afraid I'll still need your help as it seems what usualy works
>>    doesn't in Yade case. I tried the same code as below in a
>>    standalone python console : no problem. In Yade however, there
>>    seem to be still a scope issue and the declared global is not found.
>>    I suspect something with "modules", or something specific to
>>    Ipython... any idea?
>>
>>    Bruno
>>
>>
>>    Yade [18]: tt=1
>>    Yade [19]: def changett():
>>    ....: global tt
>>    ....: tt+=1
>>    ....: print tt
>>    ....: tt=10
>>    ....: print tt
>>    ....:
>>    Yade [20]: tt
>>    -> [20]: 1
>>    Yade [21]: changett()
>>
>>  ---------------------------------------------------------------------------
>>    <type 'exceptions.NameError'> Traceback (most recent call last)
>>
>>    /home/bruno/YADE/bin/<ipython console> in <module>()
>>
>>    /home/bruno/YADE/bin/<ipython console> in changett()
>>
>>    <type 'exceptions.NameError'>: global name 'tt' is not defined
>>
>>
>>
>>
>>
>>
>>
>>
>>    Václav Šmilauer a écrit :
>>
>>            A small python question. Anyone got this problem before?
>>
>>        different scopes, different variables
>>
>> http://docs.python.org/tutorial/classes.html#python-scopes-and-namespaces
>>
>>        google out the "global" keyword for a workaround.
>>
>>
>>
>>        _______________________________________________
>>        Mailing list: https://launchpad.net/~yade-dev<https://launchpad.net/%7Eyade-dev>
>>        <https://launchpad.net/%7Eyade-dev>
>>
>>        Post to     : yade-dev@xxxxxxxxxxxxxxxxxxx
>>        <mailto:yade-dev@xxxxxxxxxxxxxxxxxxx>
>>
>>        Unsubscribe : https://launchpad.net/~yade-dev<https://launchpad.net/%7Eyade-dev>
>>        <https://launchpad.net/%7Eyade-dev>
>>
>>        More help   : https://help.launchpad.net/ListHelp
>>
>>
>>
>>
>>    --     _______________
>>    Bruno Chareyre
>>    Associate Professor
>>    Grenoble INP
>>    Lab. 3SR
>>    BP 53 - 38041, Grenoble cedex 9 - France
>>    Tél : 33 4 56 52 86 21
>>    Fax : 33 4 76 82 70 43
>>    ________________
>>
>>
>>    _______________________________________________
>>    Mailing list: https://launchpad.net/~yade-dev<https://launchpad.net/%7Eyade-dev>
>>    <https://launchpad.net/%7Eyade-dev>
>>
>>    Post to     : yade-dev@xxxxxxxxxxxxxxxxxxx
>>    <mailto:yade-dev@xxxxxxxxxxxxxxxxxxx>
>>
>>    Unsubscribe : https://launchpad.net/~yade-dev<https://launchpad.net/%7Eyade-dev>
>>    <https://launchpad.net/%7Eyade-dev>
>>
>>    More help   : https://help.launchpad.net/ListHelp
>>
>>
>> ------------------------------------------------------------------------
>>
>>
>> _______________________________________________
>> Mailing list: https://launchpad.net/~yade-dev<https://launchpad.net/%7Eyade-dev>
>> Post to     : yade-dev@xxxxxxxxxxxxxxxxxxx
>> Unsubscribe : https://launchpad.net/~yade-dev<https://launchpad.net/%7Eyade-dev>
>> More help   : https://help.launchpad.net/ListHelp
>>
>>
>
>
> --
> _______________
> Bruno Chareyre
> Associate Professor
> Grenoble INP
> Lab. 3SR
> BP 53 - 38041, Grenoble cedex 9 - France
> Tél : 33 4 56 52 86 21
> Fax : 33 4 76 82 70 43
> ________________
>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~yade-dev<https://launchpad.net/%7Eyade-dev>
> Post to     : yade-dev@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~yade-dev<https://launchpad.net/%7Eyade-dev>
> More help   : https://help.launchpad.net/ListHelp
>
>
# coding: utf-8
# 2009 © Václav Šmilauer <eudoxos@xxxxxxxx>
"Test and demonstrate use of PeriTriaxController."
from yade import *
from yade import pack,log,qt
log.setLevel('PeriTriaxController',log.TRACE)
O.periodic=True
O.cell.refSize=Vector3(.1,.1,.1)
#O.cell.Hsize=Matrix3(0.1,0,0, 0,0.1,0, 0,0,0.1)
sp=pack.SpherePack()
radius=5e-3
num=sp.makeCloud(Vector3().Zero,O.cell.refSize,radius,.2,100,periodic=True) # min,max,radius,rRelFuzz,spheresInCell,periodic
O.bodies.append([utils.sphere(s[0],s[1]) for s in sp])


O.engines=[
	ForceResetter(),
	BoundDispatcher([Bo1_Sphere_Aabb()]),
	InsertionSortCollider(nBins=5,sweepLength=.05*radius),
	InteractionDispatchers(
		[Ig2_Sphere_Sphere_Dem3DofGeom()],
		[Ip2_FrictMat_FrictMat_FrictPhys()],
		[Law2_Dem3DofGeom_FrictPhys_Basic()]
	),
	#PeriTriaxController(maxUnbalanced=0.01,relStressTol=0.02,goal=[-1e4,-1e4,0],stressMask=3,globUpdate=5,maxStrainRate=[1.,1.,1.],doneHook='triaxDone()',label='triax'),
	#using cell inertia
	PeriTriaxController(dynCell=True,mass=0.2,maxUnbalanced=0.01,relStressTol=0.02,goal=[-1e4,-1e4,0],stressMask=3,globUpdate=5,maxStrainRate=[1.,1.,1.],doneHook='triaxDone()',label='triax'),
	NewtonIntegrator(damping=.2),
]
O.dt=utils.PWaveTimeStep()
O.run();
qt.View()

phase=0
refstrain=0.0
def triaxDone():
	global phase, refstrain
	if phase==0:
		print 'Here we are:\nstress',triax.stress,'\nstrain',triax.strain,'\nstiffness',triax.stiff
		print 'Now εz will go from 0 to .2 while σx and σy will be kept the same.'
		triax.goal=[-1e4,-1e4,-0.2]
		refstrain=2.0
		phase+=1
	elif phase==1:
		print 'Here we are:\nstress',triax.stress,'\nstrain',triax.strain,'\nstiffness',triax.stiff
		print 'Done, pausing now.'
		O.pause()
		
#O.run(30000,True)
#print "refstrain=",refstrain," (should be 2.0), phase=",phase," (should be 1)"
		
	


References