# Recording Force and Position

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) 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).

Thanks!

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

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

# FUNCTIONAL COMPONENTS
# 1
def myFunction():
print("Hello")
#print("dsdsHello")
# 2

#PRINTING
from pprint import pprint

# SIMULATION LOOP
O.engines=[

#PyRunner(command='myFunction()',iterPeriod=100),
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),
]

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

# SAVE SIMULATION
O.saveTmp()

## Question information

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

I did the following, but it give an error.

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

#PyRunner(command='myFunction()',iterPeriod=100),
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),
]

 mrhappy (mrhappy) said on 2020-01-21: #2

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

 mrhappy (mrhappy) said on 2020-01-21: #3

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