Jump to content

Verlet integration

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Rubik123 (talk | contribs) at 18:06, 19 October 2007 (Fixed the equation - It should reduce to normal equation given f = 0). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Verlet integration is a method for calculating the trajectories of particles in molecular dynamics simulations. The verlet integrator offers greater stability than the much simpler Euler integration methods, as well as other properties that are important in physical systems such as time-reversibility and area preserving properties. Stability of the technique depends fairly heavily upon either a uniform update rate, or the ability to accurately identify positions at a small time delta into the past. The method was developed by French physicist Loup Verlet in 1967.

The algorithm

At first it may seem natural to simply calculate trajectories using Euler integration, which is defined by

where is the current time and is the time step. However, this kind of integration suffers from many problems, as discussed at Euler integration. The Verlet algorithm reduces the level of errors introduced into the integration by calculating the position at the next time step from the positions at the previous and current time steps, without using the velocity.

The velocity at each time step is then not calculated until the next time step.

This can create technical challenges in molecular dynamics simulations, because kinetic energy and instantaneous temperatures at time cannot be calculated for a system until the positions are known at time .

The Verlet equations can also be modified to create a very simple damping effect (for instance, to emulate air friction in computer games):

Where f is a number representing the fraction of the velocity per update that is lost to friction (0-1).

Velocity Verlet

A related algorithm is the velocity Verlet algorithm[1]. This uses a similar approach but incorporates explicit velocity:

Derivation

The Verlet integrator can be derived from the Taylor expansion of a trajectory. Let be the trajectory of a particle at time . The Taylor expansion around time then gives:

and

Adding these together gives:

Arranging into the more conventional format:

where the term represents fourth-order and higher terms in the Taylor expansion.

This offers the clear advantage that the third-order term from the Taylor expansion cancels out, thus making the Verlet integrator an order more accurate than integration by simple Taylor expansion alone.

Furthermore, by subtracting the two original Taylors series, we obtain the velocity as:

The velocity calculation is thus two orders less accurate than the trajectory calculation. However, this error does not accumulate because the velocity is recalculated from the more accurate trajectories at every timestep.

Error terms

The local error in position of the Verlet integrator is as described above, and the local error in velocity is .

The global error in position, in contrast, is and the global error in velocity is . These can be derived by noting the following:

and

Therefore:

Similarly:

Which can be generalized to (it can be shown by induction, but it is given here without proof):

If we consider the global error in position between and , where , it is clear that:

And therefore, the global (cumulative) error over a constant interval of time is given by:

Because the velocity is determined in a non-cumulative way from the positions in the Verlet integrator, the global error in velocity is also .

In molecular dynamics simulations, the global error is typically far more important than the local error, and the Verlet integrator is therefore known as a second-order integrator.

Constraints

The most notable thing that is now easier due to using Verlet integration rather than Eulerian is that constraints between particles are very easy to do. A constraint is a connection between multiple points that limits them in some way, perhaps setting them at a specific distance or keeping them apart, or making sure they are closer than a specific distance. Often physics systems use springs between the points in order to keep them in the locations they are supposed to be. However, using springs of infinite stiffness between two points usually gives the best results coupled with the verlet algorithm. Here's how:

The x variables are the positions of the points, the d variables are temporary (they are added for optimization as the results of their expressions are needed multiple times), and r is the distance that is supposed to be between the two points. Currently this is in one dimension; however, it is easily expanded to two or three. Simply find the delta (first equation) of each dimension, and then add the deltas squared to the inside of the square root of the second equation (Pythagorean theorem). Then, duplicate the last two equations for the number of dimensions there are. This is where verlet makes constraints simple - instead of say, applying a velocity to the points that would eventually satisfy the constraint, you can simply position the point where it should be and the verlet integrator takes care of the rest.

Here's what an optimized 2D verlet constraint would look like in C:

dx = x2-x1;
dy = y2-y1;
d1 = sqrt (dx*dx + dy*dy);
d2 = 0.5*(d1-r)/d1;
dx = dx*d2;
dy = dy*d2;
x1 += dx;
x2 -= dx;
y1 += dy;
y2 -= dy;

3D:

dx = x2-x1;
dy = y2-y1;
dz = z2-z1;
d1 = sqrt(dx*dx+dy*dy+dz*dz);
d2 = 0.5*(d1-r)/d1;
dx = dx*d2;
dy = dy*d2;
dz = dz*d2;
x1 += dx;
x2 -= dx;
y1 += dy;
y2 -= dy;
z1 += dz;
z2 -= dz;

Problems, however, arise when multiple constraints position a vertex. One way to solve this is to loop through all the vertices in a simulation in a criss cross manner, so that at every vertex the constraint relaxation of the last vertex is already used speed up the spread of the information. Either use fine time steps for the simulation, use a fixed number of constraint solving steps per time step, or solve constrains until they are met by a specific deviation.

When approximating the constraints locally to first order this is the same as the Gauss-Seidel method. For small matrices it is known that LU decomposition is faster. Large systems can be divided into clusters (for example: each ragdoll=cluster). Inside cluster the LU method is used, inter cluster the Gauss-Seidel method is used. The matrix code can be reused: The dependency of the forces on the positions can be approximated locally to first order, and the verlet integration can be made more implicit.

For big matrices sophisticated solvers (look especially for "The sizes of these small dense matrices can be tuned to match the sweet spot" in [2]) for sparse matrices exist, any self made Verlet integration has to compete with these. The usage of (clusters of) matrices is not generally more precise or stable, but addresses the specific problem, that a force on one vertex of a sheet of cloth should reach any other vertex in a low number of time steps even if a fine grid is used for the cloth [3] (link needs refinement) and not form a sound wave.

Another way to solve Holonomic constraints is to use constraint algorithms.

Collision reactions

One way of reacting to collisions is to use a penalty-based system which basically applies a set force to a point upon contact. The problem with this is that it is very difficult to choose the force imparted. Use too strong a force and objects will become unstable, too weak and the objects will penetrate each other. Another way is to use projection collision reactions which takes the offending point and attempts to move it the shortest distance possible to move it out of the other object.

The Verlet integration would automatically handle the velocity imparted via the collision in the latter case, however note that this is not guaranteed to do so in a way that is consistent with collision physics (that is, changes in momentum are not guaranteed to be realistic). Instead of implicitly changing the velocity term, you would need to explicitly control the final velocities of the objects colliding (by changing the recorded position from the previous time step).

The two simplest methods for deciding on a new velocity are perfectly elastic collisions and inelastic collisions. A slightly more complicated strategy that offers more control would involve using the coefficient of restitution.

See also