Tracking variables

Asked by Luis Barbosa

Hi everybody,
I don`t get the idea of tracking variables, I`ve studied at User`s Manual but I still have problem.
I`m studying some contact laws due to this I need print or plot some output data in order to compare these laws and in the future to analyze the empirical results.
I used: PyRunner(command="AddData",iterPeriod=5)
                     from yade import plot
                     def myAddData():
                     b=O.bodies[1]
                     plot.addData(z1=b.state.pos[2], v1=b.state.vel.norm(), i=O.iter, t=O.time) #OK, this worked!

But I don`t know if I must use a different kind of command for each variable and how to use correctly the def.
I`m trying to print or plot normalForce, cohesion... in each interaction to get some output data, but the error of: name 'command' is not difined, always appears.

If anyone knows where I can find more information about the commands and defs or a short explanation here, of the general idea, I`ll be very gratefull!

Thanks!!

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Jan Stránský
Solved:
Last query:
Last reply:
Revision history for this message
Jan Stránský (honzik) said :
#1

Hi Luis

> I used: PyRunner(command="AddData",iterPeriod=5)
> from yade import plot
> def myAddData():
> b=O.bodies[1]
> plot.addData(z1=b.state.pos[2],
v1=b.state.vel.norm(), i=O.iter, t=O.time) #OK, this worked!
>
> But I don`t know if I must use a different kind of command for each
variable and how to use correctly the def.
> I`m trying to print or plot normalForce, cohesion... in each interaction
to get some output data, but the error of: name 'command' is not difined,
always appears.
>

You defined a function "myAddData", so you should call it in the PyRunner:

def myAddData():
  # your definition

O.engines = [
  ...
  PyRunner(iterPeriod=5, command="myAddData()"),
  ...
]

HTH
Jan

Revision history for this message
Luis Barbosa (luis-pires-b) said :
#2

Hi Jan, thank you for attention.

I'm trying plot data from this script:
#Law2_ScGeom_MindlinPhys_Mindlin
# import yade modules that we will use below

from yade import plot

#Definir material
# create rectangular box from facets nao coesiva
O.materials.append(FrictMat(young=15e6,poisson=.4,frictionAngle=radians(20),density=4000,))
O.bodies.append(utils.geom.facetBox((.5,.5,.5),(.5,.5,.5),wallMask=31))
# Criar a esfera coesiva
O.materials.append(CohFrictMat(young=15e6,poisson=0.3,density=2600,frictionAngle=radians(30),isCohesive=True,normalCohesion=1e10,shearCohesion=1e10,momentRotationLaw=True,etaRoll=0.1,label='spheres'))
#O.bodies.append([utils.sphere(center=(0.5,0.5,1),radius=.07)])
O.bodies.append([utils.sphere(center=(0.5,0.6,0.5),radius=.07)])
# Criar interacoes
O.engines=[
   ForceResetter(),
   InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()]),
InteractionLoop(
[Ig2_Sphere_Sphere_ScGeom6D(),Ig2_Facet_Sphere_ScGeom()],
[Ip2_FrictMat_FrictMat_MindlinPhys(en=0.1,es=0.1,label='damping'), Ip2_CohFrictMat_CohFrictMat_CohFrictPhys (setCohesionNow=True,label="cohesiveIp")],
[Law2_ScGeom_MindlinPhys_Mindlin(label='contactLaw'),Law2_ScGeom6D_CohFrictPhys_CohesionMoment(useIncrementalForm=True,
always_use_moment_law=True,label='cohesiveLaw')]
),

   GravityEngine(gravity=(0,0,-9.81)),
   NewtonIntegrator(damping=0.0),
   PyRunner(command='myAddData()',iterPeriod=10),
]
#______________________________________________________________________
damping.useDamping=True

O.dt=.5e-2*utils.PWaveTimeStep()

def myAddData():
  i=O.interactions[9,10]
  plot.addData(Fn=i.phys.normalForce[9],v1=b.state.vel.norm(), i=O.iter, t=O.time)

plot.plots={
        't':('Fn','v1')
}

plot.plot()

O.saveTmp()

But occurs this error:

NameError Traceback (most recent call last)
/home/luis/<string> in <module>()

NameError: name 'myAddData' is not defined

But in the same way I've ploted the position and velocity, without problem. I think that I'm not doing the def correctly to normalForce. What is the problem

Thanks a lot!

Revision history for this message
Jérôme Duriez (jduriez) said :
#3

Hi,

> What is the problem

The problem, as you computer says (always trust him !), is that your definition of the function myAddData is not taken into account... I do not know if this might be related, but you have surely an error in "i.phys.normalForce[9]" : i.phys.normalForce is a vector with three real numbers, how could you access the 9-th element ?

Jérôme

Revision history for this message
Jérôme Duriez (jduriez) said :
#4

The 10-th element, in fact... But it does not change anything...

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

Hi Luis,
what version of Yade do you use and how do you run the simulation (writing
commands one by one to the console or writing the script and then run that
script)?
Thanks
Jan

2014-05-25 16:41 GMT+02:00 Luis Barbosa <
<email address hidden>>:

> Question #249243 on Yade changed:
> https://answers.launchpad.net/yade/+question/249243
>
> Status: Answered => Open
>
> Luis Barbosa is still having a problem:
> Hi Jan, thank you for attention.
>
> I'm trying plot data from this script:
> #Law2_ScGeom_MindlinPhys_Mindlin
> # import yade modules that we will use below
>
> from yade import plot
>
> #Definir material
> # create rectangular box from facets nao coesiva
>
> O.materials.append(FrictMat(young=15e6,poisson=.4,frictionAngle=radians(20),density=4000,))
> O.bodies.append(utils.geom.facetBox((.5,.5,.5),(.5,.5,.5),wallMask=31))
> # Criar a esfera coesiva
>
> O.materials.append(CohFrictMat(young=15e6,poisson=0.3,density=2600,frictionAngle=radians(30),isCohesive=True,normalCohesion=1e10,shearCohesion=1e10,momentRotationLaw=True,etaRoll=0.1,label='spheres'))
> #O.bodies.append([utils.sphere(center=(0.5,0.5,1),radius=.07)])
> O.bodies.append([utils.sphere(center=(0.5,0.6,0.5),radius=.07)])
> # Criar interacoes
> O.engines=[
> ForceResetter(),
> InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()]),
> InteractionLoop(
> [Ig2_Sphere_Sphere_ScGeom6D(),Ig2_Facet_Sphere_ScGeom()],
> [Ip2_FrictMat_FrictMat_MindlinPhys(en=0.1,es=0.1,label='damping'),
> Ip2_CohFrictMat_CohFrictMat_CohFrictPhys
> (setCohesionNow=True,label="cohesiveIp")],
>
> [Law2_ScGeom_MindlinPhys_Mindlin(label='contactLaw'),Law2_ScGeom6D_CohFrictPhys_CohesionMoment(useIncrementalForm=True,
> always_use_moment_law=True,label='cohesiveLaw')]
> ),
>
> GravityEngine(gravity=(0,0,-9.81)),
> NewtonIntegrator(damping=0.0),
> PyRunner(command='myAddData()',iterPeriod=10),
> ]
> #______________________________________________________________________
> damping.useDamping=True
>
> O.dt=.5e-2*utils.PWaveTimeStep()
>
> def myAddData():
> i=O.interactions[9,10]
> plot.addData(Fn=i.phys.normalForce[9],v1=b.state.vel.norm(),
> i=O.iter, t=O.time)
>
> plot.plots={
> 't':('Fn','v1')
> }
>
> plot.plot()
>
> O.saveTmp()
>
> But occurs this error:
>
> NameError Traceback (most recent call last)
> /home/luis/<string> in <module>()
>
> NameError: name 'myAddData' is not defined
>
> But in the same way I've ploted the position and velocity, without
> problem. I think that I'm not doing the def correctly to normalForce.
> What is the problem
>
> Thanks a lot!
>
> --
> You received this question notification because you are a member of
> yade-users, which is an answer contact for Yade.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~yade-users
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~yade-users
> More help : https://help.launchpad.net/ListHelp
>

Revision history for this message
Luis Barbosa (luis-pires-b) said :
#6

Hi Jérôme,
You are right, that was a mistake, but even changing it the error still appears.

Hi Jan,
My Yade is Yadedaily 1.05.0
I`m saving the script as .py and after I run it.

I`m basically following the script of the example:
http://bazaar.launchpad.net/~yade-pkg/yade/git-trunk/view/head:/examples/test/Damping_HM.py

But I cannot run this example, due to errors.

Thank you!
Luis

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

Hi Luis,

if you get a lot of errors, it is always good to look at the very first
one. After running 11 steps of your script, I got:

     31
     32 def myAddData():
---> 33 i=O.interactions[9,10]
     34
plot.addData(Fn=i.phys.normalForce[9],v1=b.state.vel.norm(), i=O.iter,
t=O.time)
     35

IndexError: No such interaction

So the problem here is that you are accessing interaction that does not
exist. As the fix you can test the interaction existence and save e.g. zero
if it does not exist.

cheers
Jan

2014-05-26 16:16 GMT+02:00 Luis Barbosa <
<email address hidden>>:

> Question #249243 on Yade changed:
> https://answers.launchpad.net/yade/+question/249243
>
> Status: Answered => Open
>
> Luis Barbosa is still having a problem:
> Hi Jérôme,
> You are right, that was a mistake, but even changing it the error still
> appears.
>
> Hi Jan,
> My Yade is Yadedaily 1.05.0
> I`m saving the script as .py and after I run it.
>
> I`m basically following the script of the example:
>
> http://bazaar.launchpad.net/~yade-pkg/yade/git-trunk/view/head:/examples/test/Damping_HM.py
>
> But I cannot run this example, due to errors.
>
> Thank you!
> Luis
>
> --
> You received this question notification because you are a member of
> yade-users, which is an answer contact for Yade.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~yade-users
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~yade-users
> More help : https://help.launchpad.net/ListHelp
>

Revision history for this message
Luis Barbosa (luis-pires-b) said :
#8

Hi Jan, that happened because the sphere didn't touch the face at that time.
I've got to print the values of normal force in the terminal during the interactions, but I couldn't plot or export the data to .txt to analyze it.
Any idea?

Tks, Luis

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

Hi Luis,

I am not sure if I understand correctly. if you use the script without
changes, it will not work, because of the error I mentioned. You have to
make it errorless. Have you changed something? See also my last suggestion
with zero force saving if the interaction does not exist. As far as I am
convinced, it should work.

If you still have problems, please provide us with your current script such
that we can discuss concrete problems

thanks
Jan

2014-06-17 21:41 GMT+02:00 Luis Barbosa <
<email address hidden>>:

> Question #249243 on Yade changed:
> https://answers.launchpad.net/yade/+question/249243
>
> Status: Answered => Open
>
> Luis Barbosa is still having a problem:
> Hi Jan, that happened because the sphere didn't touch the face at that
> time.
> I've got to print the values of normal force in the terminal during the
> interactions, but I couldn't plot or export the data to .txt to analyze it.
> Any idea?
>
> Tks, Luis
>
> --
> You received this question notification because you are a member of
> yade-users, which is an answer contact for Yade.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~yade-users
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~yade-users
> More help : https://help.launchpad.net/ListHelp
>

Revision history for this message
Luis Barbosa (luis-pires-b) said :
#10

Hi Jan, this is my script, when there is interaction the value of force is printed and when not is printed 'no interaction...'
If I'm able to export data could solve my problem for while.

tks, Luis

from yade import plot

O.materials.append(FrictMat(young=15e6,poisson=.4,frictionAngle=radians(20),density=4000,))
O.bodies.append(utils.geom.facetBox((.5,.5,.5),(.5,.5,.5),wallMask=31))
O.materials.append(CohFrictMat(young=15e6,poisson=0.3,density=2600,frictionAngle=radians(30),isCohesive=True,normalCohesion=1e10,shearCohesion=1e10,momentRotationLaw=True,etaRoll=0.1,label='spheres'))
O.bodies.append([utils.sphere(center=(0.5,0.5,0.5),radius=.07)])
O.engines=[
   ForceResetter(),
   InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()]),
InteractionLoop(
[Ig2_Sphere_Sphere_ScGeom6D(),Ig2_Facet_Sphere_ScGeom()],
[Ip2_FrictMat_FrictMat_MindlinPhys(en=0.1,es=0.1,label='damping'), Ip2_CohFrictMat_CohFrictMat_CohFrictPhys (setCohesionNow=True,label="cohesiveIp")],
[Law2_ScGeom_MindlinPhys_Mindlin(label='contactLaw'),Law2_ScGeom6D_CohFrictPhys_CohesionMoment(useIncrementalForm=True,
always_use_moment_law=True,label='cohesiveLaw')]
),

   GravityEngine(gravity=(0,0,-9.81)),
   NewtonIntegrator(damping=0.0),
   PyRunner(command='myAddData()',iterPeriod=10),

]
#______________________________________________________________________
damping.useDamping=True

O.dt=.5e-2*utils.PWaveTimeStep()

def myAddData():
 try:
  i=O.interactions[9,10]
  print i.phys.normalForce
 except:
  print "No interaction between"

O.saveTmp()

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

Hello Luis,

there are several ways how to export the data. You can use plot module for
that

def myAddData():
   try:
      i=O.interactions[9,10]
      #print i.phys.normalForce
      plot.addData(f=i.phys.normalForce)
   except IndexError: # it is good to specify what exception you except if
it is reasonable
      pass
      #print "No interaction between"
O.run(whatever,True)
plot.saveDataTxt(fileName) # [1]

Or you can have your own list containing data

data = []
def myAddData():
   try:
      i=O.interactions[9,10]
      f = i.phys.normalForce
      data.append(f)
   except IndexError:
      pass
O.run(whatever,True)
# do whtever with data

or using files

ff = open(someFile,'w')
def myAddData():
   try:
      i=O.interactions[9,10]
      f = i.phys.normalForce
      ff.write('%g %g %g\n'%(f[0],f[1],f[2]))
   except IndexError:
      pass
O.run(whatever,True)
ff.close()

cheers
Jan

[1] https://yade-dem.org/doc/yade.plot.html#yade.plot.saveDataTxt

2014-06-17 22:21 GMT+02:00 Luis Barbosa <
<email address hidden>>:

> Question #249243 on Yade changed:
> https://answers.launchpad.net/yade/+question/249243
>
> Status: Answered => Open
>
> Luis Barbosa is still having a problem:
> Hi Jan, this is my script, when there is interaction the value of force is
> printed and when not is printed 'no interaction...'
> If I'm able to export data could solve my problem for while.
>
> tks, Luis
>
>
> from yade import plot
>
>
> O.materials.append(FrictMat(young=15e6,poisson=.4,frictionAngle=radians(20),density=4000,))
> O.bodies.append(utils.geom.facetBox((.5,.5,.5),(.5,.5,.5),wallMask=31))
>
> O.materials.append(CohFrictMat(young=15e6,poisson=0.3,density=2600,frictionAngle=radians(30),isCohesive=True,normalCohesion=1e10,shearCohesion=1e10,momentRotationLaw=True,etaRoll=0.1,label='spheres'))
> O.bodies.append([utils.sphere(center=(0.5,0.5,0.5),radius=.07)])
> O.engines=[
> ForceResetter(),
> InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()]),
> InteractionLoop(
> [Ig2_Sphere_Sphere_ScGeom6D(),Ig2_Facet_Sphere_ScGeom()],
> [Ip2_FrictMat_FrictMat_MindlinPhys(en=0.1,es=0.1,label='damping'),
> Ip2_CohFrictMat_CohFrictMat_CohFrictPhys
> (setCohesionNow=True,label="cohesiveIp")],
>
> [Law2_ScGeom_MindlinPhys_Mindlin(label='contactLaw'),Law2_ScGeom6D_CohFrictPhys_CohesionMoment(useIncrementalForm=True,
> always_use_moment_law=True,label='cohesiveLaw')]
> ),
>
> GravityEngine(gravity=(0,0,-9.81)),
> NewtonIntegrator(damping=0.0),
> PyRunner(command='myAddData()',iterPeriod=10),
>
> ]
> #______________________________________________________________________
> damping.useDamping=True
>
> O.dt=.5e-2*utils.PWaveTimeStep()
>
> def myAddData():
> try:
> i=O.interactions[9,10]
> print i.phys.normalForce
> except:
> print "No interaction between"
>
> O.saveTmp()
>
> --
> You received this question notification because you are a member of
> yade-users, which is an answer contact for Yade.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~yade-users
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~yade-users
> More help : https://help.launchpad.net/ListHelp
>

Revision history for this message
Luis Barbosa (luis-pires-b) said :
#12

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