Hacker News new | past | comments | ask | show | jobs | submit login
Newtonian Gravity with Velocity Verlet and OpenGL (2016) (go.ro)
21 points by aroman_ro 11 days ago | hide | past | web | favorite | 7 comments

> I had an old program where I implemented the Leapfrog method, but for this post I decided to use the Verlet integration.

Those are mathematically equivalent methods though...aren't they?

I guess you may call them that way. They are very similar and although you can discuss some tiny details, in the end for such project it's a matter of taste, really.

What are the tiny details?!

In Leapfrog we iterate

   v <- v + a(x)dt
   x <- x + vdt
With Euler initialisation this is equivalent to:

   v <- v + a(x)dt/2
   x <- x + vdt
   v <- v + a(x)dt/2
(consider a sequence of steps: we'll have two v <- v + a(x)dt/2 updates next to each other, which gives v <- v + a(x)dt)

This is exactly the same as velocity verlet, if you substitute the value for v computed in the first update into the next two equations:

   x <- x + (v + a(x)dt/2)dt
   v <- (v + a(x_prev)dt/2) + a(x)dt/2

The biggest is that in real molecular dynamics simulation you need the position and velocity at the same time. If you want to calculate the total energy, for example, you need both positions and velocity at one time moment. It's not a big deal for a simple project to simply average the 'before' and 'after' velocities... but again, those are tiny details. There is the initial state issue, again, a tiny detail. You may find more...

With leapfrog you can use x + v dt/2 for the positions to calculate the energy. Or use this update rule:

    x += v*dt/2
    v += a(x)*dt
    x += v*dt/2
This gives you the x,v at the same time, yet still doesn't require storing the accelerations. The acceleration calculation can imperatively update v :)

In fact, if you call that update leapfrog(dt), then you can get a fourth order symplectic method like so:

Where c1,c2 are particular coefficients which you have to ask Yoshida.

As I said, tiny details :)

Applications are open for YC Summer 2019

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact