← Back to team overview

yade-users team mailing list archive

Re: [Question #656538]: Measuring Force, Trapdoor displacement and Surface displacement

 

Question #656538 on Yade changed:
https://answers.launchpad.net/yade/+question/656538

    Status: Open => Answered

Jan Stránský proposed the following answer:
Hello,
what is written in the script directly (not in function etc) is executed and never called again (like O.bodies[1].state.displ()). To be able to plot the data, first you need to coleect the data during simulation:

#############
from yade import plot # put such import at the beginning of the file

...

O.engines = [
   ...
   PyRunner(iterPeriod=10,command='plotAddData()'),
]

...

def computeSurfaceDisplacement():
   vertices = []
   for b in O.bodies:
      if not isinstance(b.shape,Polyhedra): continue
      pos = b.state.pos # center of polyhedron
      ori = b.state.ori
      vs = b.shape.v
      vs = [pos + ori*v for v in vs] # vertices of polyhedron in global coordinate system
      vertices.extend(vs)
   maxZ = max(v[2] for v in vertices) # you would need something much more sophisticated, just to give you an idea
   return maxZ
##

def plotAddData():
   sd = computeSurfaceDisplacement()
   plot.addData(
      i = O.iter,
      tDspl = O.bodies[1].state.displ(),
      fLeft = sum(O.forces.f(id)[2] for id in (2,3)),
      surfDspl = sd,
   )

plot.plots = {'i':'surfDspl', 'i ':'fLeft', 'i  ':'tDspl'}
##############

for proper surfaceDisplacement, you would probably need some record of "initial" surface after gravity deposition. You can do it in checker function:
#############
def checker():
   if O.iter == nGravityDeposition:
      recordInitialSurface()
   ...

def recordInitialSurface():
   global initSurf
   ... # some code here to "save" what the surface is
#############

cheers
Jan

-- 
You received this question notification because your team yade-users is
an answer contact for Yade.