yade-users team mailing list archive
-
yade-users team
-
Mailing list archive
-
Message #02420
Re: Python force - plot
Check the script in attachment. Constitutive law is changed.
______________________________
Anton Gladkyy
2010/2/22 chiara modenese <c.modenese@xxxxxxxxx>
> Yes that is not working as well. I dont know if it is PeriodicPythonRunner
> or something else.. But I repeat that I have tried to define another
> function to write in a file some data (nothing to do with plot and so on)
> and I still got the error. The problem is in the PeriodicPythonRunner (and
> it seems just for me since for you is working..).
>
>
>
>
> On 22 February 2010 15:13, Anton Gladky <gladky.anton@xxxxxxxxx> wrote:
>
>> Hi,
>>
>>
>> plot.addData(fn=inter.phys.normalForce,step=O.iter)
>>
>> Is it not working for you as well? If it works, so the problem is not in
>> PeriodicPhythonRunner.
>> ______________________________
>>
>> Anton Gladkyy
>>
>>
>> 2010/2/22 chiara modenese <c.modenese@xxxxxxxxx>
>>
>> Hi Vaclav,
>>>
>>> for me this PeriodicPhythonRunner is not working.. (I cannot really see
>>> why..) I am using the release 2039.. Is the script working well also for
>>> you?
>>> Is this the only way to store data with python at each time step? What
>>> about c++? Should I use a kind of simple scene preprocessor file and in
>>> addiction a sort of TStateRecorder?
>>>
>>> Thanks a lot (I think it is quite crucial to know how to store data -
>>> whatever - throughout a simulation..)
>>> Chiara
>>>
>>>
>>>
>>>
>>> On 22 February 2010 14:54, chiara modenese <c.modenese@xxxxxxxxx> wrote:
>>>
>>>>
>>>>
>>>> 2010/2/22 Václav Šmilauer <eudoxos@xxxxxxxx>
>>>>
>>>>
>>>>> > 1) How do I apply a force (not the gravity) to the bodies? Which
>>>>> > engine should I call?
>>>>> ForceEngine:
>>>>>
>>>>>
>>>>> https://www.yade-dem.org/sphinx/yade.wrapper.html#yade.wrapper.ForceEngine
>>>>>
>>>>
>>>> Thanks
>>>>
>>>>>
>>>>> > 2) I get this error using the PeriodicPythonRunner engine to create
>>>>> > some plots:
>>>>> >
>>>>> > NameError: name 'myAddPlotData' is not defined
>>>>> That is weird... you have O.run(...) before def myAddPlotData():,
>>>>> right?
>>>>>
>>>>>
>>>> No, actually I do not have O.run() in the script at all. I do type that
>>>> in the console..
>>>> I have tried to define a different function to write data in a file
>>>> instead of plotting them but I have still got the same error (NameError ...)
>>>>
>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> Mailing list: https://launchpad.net/~yade-users<https://launchpad.net/%7Eyade-users>
>>>>> Post to : yade-users@xxxxxxxxxxxxxxxxxxx
>>>>> Unsubscribe : https://launchpad.net/~yade-users<https://launchpad.net/%7Eyade-users>
>>>>> More help : https://help.launchpad.net/ListHelp
>>>>>
>>>>
>>>>
>>>
>>> _______________________________________________
>>> Mailing list: https://launchpad.net/~yade-users<https://launchpad.net/%7Eyade-users>
>>> Post to : yade-users@xxxxxxxxxxxxxxxxxxx
>>> Unsubscribe : https://launchpad.net/~yade-users<https://launchpad.net/%7Eyade-users>
>>> More help : https://help.launchpad.net/ListHelp
>>>
>>>
>>
>> _______________________________________________
>> Mailing list: https://launchpad.net/~yade-users<https://launchpad.net/%7Eyade-users>
>> Post to : yade-users@xxxxxxxxxxxxxxxxxxx
>> Unsubscribe : https://launchpad.net/~yade-users<https://launchpad.net/%7Eyade-users>
>> More help : https://help.launchpad.net/ListHelp
>>
>>
>
#!/usr/local/bin/yade-trunk -x
# -*- coding: utf-8 -*-
# -*- encoding=utf-8 -*-
##
## SCRIPT TO TEST A NEW CONSTITUTIVE LAW (MINDLIN)
## to run type ***execfile('/media/disk/DPhil/Class_Yade/Mindlin/test_mindlin.py')
O.initializers=[BoundDispatcher([Bo1_Sphere_Aabb(),Bo1_Box_Aabb()])]
## list of engines
O.engines=[
ForceResetter(),
BoundDispatcher([Bo1_Sphere_Aabb(),Bo1_Box_Aabb()]),
InsertionSortCollider(),
InteractionDispatchers(
[Ig2_Sphere_Sphere_Dem3DofGeom(),Ig2_Facet_Sphere_Dem3DofGeom()],
[Ip2_FrictMat_FrictMat_FrictPhys()],
[Law2_Dem3DofGeom_FrictPhys_Basic()],
),
GravityEngine(gravity=(-1000,0,0)), # here I would like to apply a force, not the gravity..
NewtonIntegrator(damping=.2),
###
### NOTE this extra engine:
###
### You want snapshot to be taken every 1 sec (realTimeLim) or every 50 iterations (iterLim),
### whichever comes soones. virtTimeLim attribute is unset, hence virtual time period is not taken into account.
PeriodicPythonRunner(iterPeriod=20,command='myAddPlotData()')
]
## define and append material
mat=FrictMat(young=600.0e6,poisson=0.6,density=2.60e3,frictionAngle=26,label='Friction')
O.materials.append(mat)
## create two spheres (one will be fixed) and append them
from yade import utils
s0=utils.sphere([0,0,0],1,color=[0,1,0],dynamic=False,wire=True,material='Friction')
s1=utils.sphere([2,0,0],1,color=[0,2,0],dynamic=True,wire=True,material='Friction')
O.bodies.append(s0)
O.bodies.append(s1)
## time step
O.dt=.2*utils.PWaveTimeStep()
from yade import qt
qt.View()
qt.Controller()
############################################
##### now the part pertaining to plots #####
############################################
from math import *
from yade import plot
## make one plot: step as function of fn
plot.plots={'step':('fn')}
## this function is called by plotDataCollector
## it should add data with the labels that we will plot
## if a datum is not specified (but exists), it will be NaN and will not be plotted
def myAddPlotData():
inter=O.interactions[0,1]
## store some numbers under some labels
plot.addData(fn=inter.phys.normalForce,step=O.iter)
# O.run(int(2./O.dt),True);
## We will have:
## 1) data in graphs (if you call plot.plot())
## 2) data in file (if you call plot.saveGnuplot('/tmp/a')
## 3) data in memory as plot.data['step'], plot.data['fn'], plot.data['un'], etc. under the labels they were saved
References