Newton Integrator updating of position and velocity

Asked by Mukesh Tiwari

Hi
I am trying to look at how Yade updates postion and velocity through a simple example of a body falling freely under gravity. The code is:

O.bodies.append([utils.sphere((0,0,1),.5)])

b = O.bodies[0]
#b.state.vel=(0,0,0)
print O.time,b.state.vel[2],b.state.pos[2]

O.engines=[
   ForceResetter(),
   NewtonIntegrator(damping=0,gravity=(0,0,-9.81)),
   PyRunner(command='addData()',iterPeriod=1),
]

O.dt = 0.1

def addData():
    print O.time,b.state.vel[2],b.state.pos[2]

O.run(10,True)

Now the output which I obtain is :

0.0 0.0 1.0
0.1 -1.962 0.7057
0.2 -2.943 0.4114
0.3 -3.924 0.019
0.4 -4.905 -0.4715
0.5 -5.886 -1.0601
0.6 -6.867 -1.7468
0.7 -7.848 -2.5316
0.8 -8.829 -3.4145
0.9 -9.81 -4.3955

The velocity at dt =0.1 should be -0.981 but it gives the expected value at 2*dt. Similarly the position at dt=0.1 is what one expects at 6*dt. I am not sure if there is something wrong in what I do or if there is some other issue.

Thanks
Mukesh

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Bruno Chareyre
Solved:
Last query:
Last reply:
Revision history for this message
Anton Gladky (gladky-anton) said :
#1

Hi,

add initRun=True to PyRunner:

PyRunner(initRun=True,command='addData()',iterPeriod=1),

Running script test.py
0.0 -0.981 0.9019
0.1 -1.962 0.7057
0.2 -2.943 0.4114
0.3 -3.924 0.019
0.4 -4.905 -0.4715
0.5 -5.886 -1.0601
0.6 -6.867 -1.7468
0.7 -7.848 -2.5316
0.8 -8.829 -3.4145
0.9 -9.81 -4.3955

Anton

2012/6/21 Mukesh Tiwari <email address hidden>:
> New question #201064 on Yade:
> https://answers.launchpad.net/yade/+question/201064
>
> Hi
> I am trying to look at how Yade updates postion and velocity through a simple example of a body falling freely under gravity. The code is:
>
> O.bodies.append([utils.sphere((0,0,1),.5)])
>
> b = O.bodies[0]
> #b.state.vel=(0,0,0)
> print O.time,b.state.vel[2],b.state.pos[2]
>
>
> O.engines=[
>   ForceResetter(),
>   NewtonIntegrator(damping=0,gravity=(0,0,-9.81)),
>   PyRunner(command='addData()',iterPeriod=1),
> ]
>
> O.dt = 0.1
>
>
> def addData():
>    print O.time,b.state.vel[2],b.state.pos[2]
>
> O.run(10,True)
>
> Now the output which I obtain is :
>
> 0.0    0.0     1.0
> 0.1  -1.962  0.7057
> 0.2  -2.943  0.4114
> 0.3  -3.924  0.019
> 0.4  -4.905  -0.4715
> 0.5  -5.886  -1.0601
> 0.6  -6.867  -1.7468
> 0.7  -7.848  -2.5316
> 0.8  -8.829  -3.4145
> 0.9  -9.81   -4.3955
>
> The velocity at dt =0.1  should be -0.981 but it gives the expected value at 2*dt. Similarly the position at dt=0.1 is what one expects at 6*dt. I am not sure if there is something wrong in what I do or if there is some other issue.
>
> Thanks
> Mukesh
>
> --
> 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
Mukesh Tiwari (mukesh-tiwari) said :
#2

Thanks Anton,

The velocity agrees completley but the position still has an issue. I think it should be simply g t^2/2 which I don't get.

Mukesh

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

Hello Mukesh,

Nice "Yade exercise" ;-)

Your results are consistent with the way Yade computes things (see http://bazaar.launchpad.net/~yade-dev/yade/trunk/view/head:/pkg/dem/NewtonIntegrator.cpp, or documentation surely)

E.g, you have indeed :
position(t=0.4) = position(t=0.3) + speed(t=0.4) * 0.1, and so on for other times
(velocities are computed first, before modifiying positions)

In my opinion, the discrete (in time !) feature of this integration scheme is the only reason why you do not get the exact solution. Try with smaller dt, and you should certainly approach the result you expect.

Revision history for this message
Mukesh Tiwari (mukesh-tiwari) said :
#4

Thanks I will take a look at it...

Revision history for this message
Best Bruno Chareyre (bruno-chareyre) said :
#5

See "motion integration" in http://yade-dem.org/doc/formulation.html.
As suggested by Jerome your results are consistent with the formulation.
Note the velocity at iteration N does not represent velocity of time
N*dt, instead it is for time (N-0.5)*dt.

Revision history for this message
Mukesh Tiwari (mukesh-tiwari) said :
#6

Thanks Chareyre, that solved my question.