Questions tagged [verlet-integration]

Verlet integration is a method for the numerical solution of differential equations that simulate mechanical systems or more generally conservative or Hamiltonian systems. The method belongs to the family of symplectic integration methods, preserving energy and other first integrals almost perfectly.

The problem to solve

Verlet integration is a method for the numerical solution of differential equations

x''(t) = a( x(t) ),    x(t0)=x0, x'(t0)=v0

that simulate mechanical systems and other conservative or Hamiltonian systems. The objects of the system are assumed to be enumerated and their positions assembled into the vector x(t), their velocities assembled in the vector valued function v(t)=x'(t). a(t) consists of the accelerations of the single objects corresponding to the force acting on each object, divided by its mass.

Verlet integration is a symplectic integrator and will only work as expected on conservative systems, which, for example, excludes the consideration of friction. More precisely this means that the system is required do possess an energy function

E(x,v) = 0.5 * vT*M*v + P(x)

where the first term is the kinetic energy, M is the (symmetric, and often diagonal) mass matrix and P(x) the potential energy. Then the force acting on the objects of the system is minus the gradient of the potential energy and thus the acceleration is

a(x) = - M-1 * grad P(x).

Usually the dynamically system is encoded via evaluation of the function a(x), such a procedure is named eval_a(x) in this article.


The solution obtained

Verlet integration, like any numerical integration of ODE, produces sequences

(xn), (vn), (n in IN)

of sample points in the phase space of positions and velocities corresponding to a prescribed sequence (tn) of time instants, so that xn and vn approximate the exact solutions x(tn) and v(tn)=x'(tn).

In the formulation of the method the velocities are of secondary importance, the basic version even leaves them out.


The numerical method(s)

Verlet integration comes in three main flavors, all three for a constant time step dt, so that tn=t0+n*dt. All three compute the same position sequence, basic Verlet computes only this. The other two also compute velocities, while the leapfrog variant has the least operations, for exact velocities the velocity Verlet method should be used.

  • basic Verlet: before each step n->n+1, the variables t, x, x_old are tn, xn, xn-1, initialization returns with the state for n=1.

    verlet_init:
        x_old = x0
        a = eval_a( x0 );
        x = x0 + v0*dt + 0.5*a*dt*dt;   t=t0+dt;
    
    verlet_step:
        a = eval_a(x);
        x_new = 2*x-x_old + a*dt*dt;
        x_old = x;
        x = x_new; t+=dt;
        do_collisions(t,x,x_old);
    
  • velocity verlet: before each step n->n+1, the variables t, x, v are tn, xn, vn, initialization returns with the state for n=0.

    verlet_init:
        a = eval_a( x0 );
        v = v0;
        x = x0; t = t0;
    
    verlet_step:
        v += a*0.5*dt;
        x += v*dt; t += dt;
        do_collisions(t,x,v,dt);
        a = eval_a(x);
        v += a*0.5*dt;
        do_statistics(t,x,v); 
    
  • leapfrog verlet: before each step n->n+1, the variables t, x, v are tn, xn, vn+0.5, where tn+0.5=tn+0.5*dt, initialization returns with the state for n=0.

    verlet_init:
        a = eval_a( x0 );
        v = v0 + 0.5*a*dt;
        x = x0;     t=t0;
    
    verlet_step:
        x += v*dt; t += dt;
        do_collisions(t,x,v,dt);
        a = eval_a(x);
        v += a*dt;
    

The sequence of the computations must be preserved, however the lines inside `verlet_step' may be rotated. Then the initialization needs to be adapted so that the unrolled loop stays the same.


Numerical errors

The approximation error at time t behaves as O(eLt*dt2), it is a second order method.

The Verlet integration method belongs to the family of symplectic integration methods. These preserve the energy E and other first integrals of the system almost perfectly. In the Verlet method the energy oscillates with time constant amplitude O(dt2) around the initial energy level.

46 questions
2
votes
1 answer

Verlet / Euler Integration is inaccurate

I want create some physx to game, and I started with small example to understand how it works. During this i had a few problems but i resolved them in 90%. To create my exmaple i studied some other examples and to create this one i used:…
Griva
  • 1,618
  • 20
  • 37
2
votes
2 answers

Solar System Simulation Project (velocity verlet help)

For my modelling and simulation class project, I want to simulate a solar system. I'm starting with just a star (sun) and a planet (earth), but I'm running into a few problems already. I've spent some time now just reviewing and learning about…
Zarch
  • 111
  • 1
  • 10
2
votes
1 answer

Ragdoll joint angle constraints

I am doing a C# project on ragdolls based on Thomas Jakobsen's article http://www.gpgstudy.com/gpgiki/GDC%202001%3A%20Advanced%20Character%20Physics I have converted the logic to 2D and everything seems to be working only I am having problems…
2
votes
1 answer

Runaway Velocities when implementing Velocity Verlet Algorithm in Periodic Molecular Dynamics Simulation

I'm trying to write a molecular dynamics simulation for a lennard-jones fluid in a 2d box with either periodic or reflective boundary conditions. The simulation seems to run well with reflective boundaries but for some reason the particles in the…
user1353285
  • 191
  • 1
  • 10
1
vote
1 answer

Velocity-Verlet Double-Well Algorithm Python

I am implemententing the Verlet algorithm for a double well potential V(x) = x^4-20x^2, as to create a simple phase portrait.The generated phase portrait has an augmented oval shape and is clearly incorrect. I have a feeling that my problem is…
New2Python
  • 25
  • 3
1
vote
1 answer

N-body simulation python

I am trying to code an N-body simulation code in python and have successfully managed to produce a system involving the Sun, Earth and Jupiter as below using a leapfrog approximation method. However, when I try and extend the same code for N bodies…
1
vote
1 answer

How to implement a velocity Verlet integrator which works for the harmonic oscillator in python?

I am new to python and i am trying to implement a velocity Verlet integrator which works for the harmonic oscillator. As you can see from my notebook below (taken from: http://hplgit.github.io/prog4comp/doc/pub/._p4c-solarized-Python022.html), the…
1
vote
1 answer

Simulating Earth's orbit using symplectic Euler in Python

I'm trying to simulate the motion of earth around the sun. (This is the task I am trying to do) This is what I've come up with so far import numpy as np import matplotlib.pyplot as plt #Set parameters: N = 365 # Earth days in a…
1
vote
1 answer

Verlet Integration in Python resulting in particles running away

My fallowing code (was supposed to) solve the equation of motion for two bodies but the result is the particles running way and I wasn't able to find where is the error import numpy as np import matplotlib.pyplot as plt plt.style.use('ggplot') DIM…
0xhfff
  • 1,215
  • 2
  • 9
  • 6
1
vote
2 answers

Universal law of gravitation - order of operations

I'm working on a little N-Body Simulation in JavaScript. It's running as I expected, but I noticed something odd. The simulation uses a verlet integrator and the function that accumulates the forces has the line: force.length = (this.gravity *…
Hal50000
  • 639
  • 1
  • 6
  • 16
1
vote
1 answer

Error in velocity verlet algorithm

Apparently it's O(t^2). I've just realised I don't know what that means. What is the expression for the expected error in the position for the velocity verlet algorithm? Related to the timestep, but in what way? I keep reading about local and global…
user13948
  • 443
  • 1
  • 6
  • 14
1
vote
1 answer

MATLAB: Verlet Algorithm -

Below is my code for the Verlet function, to be called from my main script. % verlet.m % uses the verlet step algorithm to integrate the simple harmonic % oscillator. % stepsize h, for a second-order ODE function vout =…
james.sw.clark
  • 357
  • 1
  • 8
  • 20
1
vote
1 answer

Lennard-Jones potential simulation

import pygame import random import numpy as np import matplotlib.pyplot as plt import math number_of_particles = 70 my_particles = [] background_colour = (255,255,255) width, height = 500, 500 sigma = 1 e = 1 dt = 0.1 v = 0 a = 0 r = 1 def…
Iwko
  • 73
  • 1
  • 4
  • 10
1
vote
2 answers

Verlet algorithm implementation in Python

I have problem with implementation of verlet algorithm in Python. I tried this code: x[0] = 1 v[0] = 0 t[0] = 0 a[0] = 1 for i in range (0, 1000): x[i+1] = x[i] - v[i] * dt + (a[i] * (dt**2) * 0.5) v[i] = (x[i+1] - x[i-1]) * 0.5 * dt …
Iwko
  • 73
  • 1
  • 4
  • 10
0
votes
0 answers

Fastest way to generate cloth with a list of points and a list of constraints (verlet)

I have made a verlet integration physics sandbox, and I want it to start with a cloth. It stores points and constraints in separate lists, and the list of constraints references the items in the list of points. points = [,