Recording Force and Position

Asked by mrhappy on 2020-01-21

Hi,

I am want to run a simulation where I have two balls. I want to record the force and the displacment of one of the balls (O.bodies[1]) using plot.addData. Currently, I can store the time at every 1000 iterations. What do I add to " plot.addData(t=O.time) " so that it can also record the force (x, y, and z) and the displacement (x, y, and z) for (O.bodies[1]).

Thanks!

# PARTICLES
O.bodies.append([
 # fixed: particle's position in space will not change (support)
 sphere(center=(0,0,0),radius=0.5,fixed=True),
 # this particles is free, subject to dynamics
 sphere((0,0,2),radius=0.5)
])
O.bodies[0].state.density = 5
O.bodies[1].state.density = 5

# BOUNDARY CONDITION
O.bodies[1].state.blockedDOFs = "z"
O.bodies[1].state.vel = (0,0,-1)

# FUNCTIONAL COMPONENTS
# 1
def myFunction():
        print("Hello")
 #print("dsdsHello")
# 2
def addPlotData():
        plot.addData(t=O.time) #HERE

#PRINTING
from yade import plot
from pprint import pprint

# SIMULATION LOOP
O.engines=[

 #PyRunner(command='myFunction()',iterPeriod=100),
 PyRunner(command='addPlotData()',iterPeriod=1000),
 ForceResetter(),
 InsertionSortCollider([Bo1_Sphere_Aabb()]),
 InteractionLoop(
  [Ig2_Sphere_Sphere_ScGeom()], # collision geometry
  [Ip2_FrictMat_FrictMat_FrictPhys()], # collision "physics"
  [Law2_ScGeom_FrictPhys_CundallStrack()] # contact law -- apply forces
),
 # Apply gravity force to particles. damping: numerical dissipation of energy.
 NewtonIntegrator(gravity=(0,0,0),damping=0.1),
 PyRunner(command='addPlotData()',iterPeriod=20), # call the addPlotData function every 20 iterations
]

#TIME STEP
O.dt=.5e-4*PWaveTimeStep()

# SAVE SIMULATION
O.saveTmp()

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
mrhappy
Solved:
2020-01-21
Last query:
2020-01-21
Last reply:
mrhappy (mrhappy) said : #1

I did the following, but it give an error.

def addPlotData():
        plot.addData(t=O.time,dis = O.bodies[1].state.displ(),)

O.engines=[
 ## Resets forces and momenta the act on bodies
 ForceResetter(),

 #PyRunner(command='myFunction()',iterPeriod=100),
 PyRunner(command='addPlotData()',iterPeriod=10),
 ForceResetter(),
 InsertionSortCollider([Bo1_Sphere_Aabb()]),
 InteractionLoop(
  [Ig2_Sphere_Sphere_ScGeom()], # collision geometry
  [Ip2_FrictMat_FrictMat_FrictPhys()], # collision "physics"
  [Law2_ScGeom_FrictPhys_CundallStrack()] # contact law -- apply forces
),
 # Apply gravity force to particles. damping: numerical dissipation of energy.
 NewtonIntegrator(gravity=(0,0,0),damping=0.1),
 PyRunner(command='addPlotData()',iterPeriod=20), # call the addPlotData function every 20 iterations
]

mrhappy (mrhappy) said : #2

The position can be found with the following line of code:
plot.addData(t=O.time,DX1 = O.bodies[1].state.pos[0],DY1 = O.bodies[1].state.pos[1],DZ1 = O.bodies[1].state.pos[2])

mrhappy (mrhappy) said : #3

The force can be found from this:
FX1 = O.forces.f(1)[0]