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
0
votes
0 answers

Using Velocity Verlet to simulate 3-body motion in 3D

As the title states, I want to use the velocity Verlet algorithm to simulate the trajectories of 3 bodies in 3D. The code is based from this. My problem is the trajectories outputted seem to be small oscillations propagating as straight lines,…
Vaeu
  • 1
0
votes
0 answers

Nested for loops and Verlet lists optimization C++

I'm doing a simulation of Molecular dynamics with C++. The main structure of my code is the following particle Molecule[N]; collider Newton; //initialization of the molecules for(t=0; t<=tmax; t+=dt){ for(int i=0; I
0
votes
0 answers

Particle Collision Simulation Python

I'm trying to create a relatively simple particle simulation, which should account for gravity, drag, the collision with other particles (inelastic collision) and the collision with walls (perfectly elastic). I got the gravity and drag part working…
0
votes
1 answer

Python error, 'int' object is not subscriptable

I'm trying to solve differential equations using the Vertel algorithm, but I'm not able to rid myself of this error. Any suggestions? def Vertel(dt, x0, v0, t, tstop, pravastrana, M=1): i = 0 x = x0 v = v0 k = 1 # Spring…
0
votes
1 answer

Leapfrog algorithm to compute a objects trajectory in a Gravitational field around a central body (Python 3.8.2)

I pretty much deleted the last code and started new. I added a new class called Object which is the replacement for the lists called body_1 and body_2. Also all the calculations are now done from within the Object class. Most previous existing…
0
votes
1 answer

Assigning value to C array with iterative formula

Context I would like to simulate the trajectory of a particle in an electrical field. I want its position, velocity and acceleration at each time step. Each of these variables will be stored in an array so I can write it on a file and plot it later.…
Aldehyde
  • 35
  • 8
0
votes
0 answers

Attempting to do verlet integration

I have tried adapting euler method code, and am using euler to calculate the first value so there are two for me to use in verlet but when i plot the graph i just get two perpendicular straight lines. this is the code: for t in t_array: if t ==…
Soph44
  • 1
0
votes
0 answers

Why does total energy of N coupled harmonic oscillators increase with increase in N?

I am trying to analyse the energy behaviour of n coupled harmonic oscillators where the initial displacements are distributed/defined by sine wave equation at various values of time. My total energy plot seems to appx. double from n= 4 to 8 to 16…
0
votes
0 answers

Molecular dynamic, velocity verlet: Kinetic energy divergence

I'm trying to write a simple MD program in C/C++ (I'm used to C but I'm trying to learning C++, so my code is a little "mix"... I know that this is suboptimal and I will move to full C++ as soon as I fully understand it). Everything seems to run but…
Aethyr
  • 1
  • 2
0
votes
1 answer

I joined multiple images into a rope. How can I decrease the rope stretchiness?

I created a rope based off this tutorial, except my rope has one ball attached on each end of the rope. High Level: This is how they create the rope. create an array of SKNodes append each rope segment (node) to the array add each node to the…
Sami
  • 579
  • 5
  • 25
0
votes
0 answers

Verlet Integration 2D Physic, implementing angular constraint

I am trying to implement an angular constraint into a simple verlet integration based 2D physic engine. This is the code I am currently using: int indexA = physicAngularConstraint[i].indexA; int indexB = physicAngularConstraint[i].indexB; int indexC…
user473730
0
votes
1 answer

Simple Harmonic Motion - Verlet - External force - Matlab

I ran through the algebra which I had previously done for the Verlet method without the force - this lead to the same code as you see below, but the "+(2*F/D)" term was missing when I ignored the external force. The algorithm worked accurately, as…
james.sw.clark
  • 357
  • 1
  • 8
  • 20
0
votes
1 answer

segment fault on programming C

I am tyring to make velocity Verlet method, by using C language. I thought I made it good. However, there pops up 'Segmentation fault(core dumped)' whenever, I increase the size of the vector or array, x and y. For the size n equal and less than…
supergentle
  • 1,001
  • 1
  • 14
  • 33
0
votes
1 answer

Swift Rope Verlets

I'm trying to implement a verlet rope in swift. I'm running into the problem where when trying to fix the position of the point masses from constraints, they very rapidly grow apart and then the coordinates become NaNs. Any idea what could be wrong…
circuitlego
  • 3,469
  • 5
  • 22
  • 22
-1
votes
0 answers

Have I implemented the Verlet algorithm for a spring simulation correctly?

I have tried to write a program in Python for the Verlet algorithm to simulate a mass on a spring. Here is the code: attempted code However, this is the graph that resulted. I am not sure if it is correct or not.resulting graph