Verlet integration

From HandWiki
Short description: Numerical integration algorithm

Verlet integration (French pronunciation: ​[vɛʁˈlɛ]) is a numerical method used to integrate Newton's equations of motion.[1] It is frequently used to calculate trajectories of particles in molecular dynamics simulations and computer graphics. The algorithm was first used in 1791 by Jean Baptiste Delambre and has been rediscovered many times since then, most recently by Loup Verlet in the 1960s for use in molecular dynamics. It was also used by P. H. Cowell and A. C. C. Crommelin in 1909 to compute the orbit of Halley's Comet, and by Carl Størmer in 1907 to study the trajectories of electrical particles in a magnetic field (hence it is also called Störmer's method).[2] The Verlet integrator provides good numerical stability, as well as other properties that are important in physical systems such as time reversibility and preservation of the symplectic form on phase space, at no significant additional computational cost over the simple Euler method.

Basic Störmer–Verlet

For a second-order differential equation of the type [math]\displaystyle{ \ddot{\mathbf x}(t) = \mathbf A\bigl(\mathbf x(t)\bigr) }[/math] with initial conditions [math]\displaystyle{ \mathbf x(t_0) = \mathbf x_0 }[/math] and [math]\displaystyle{ \dot{\mathbf x}(t_0) = \mathbf v_0 }[/math], an approximate numerical solution [math]\displaystyle{ \mathbf x_n \approx \mathbf x(t_n) }[/math] at the times [math]\displaystyle{ t_n = t_0 + n\,\Delta t }[/math] with step size [math]\displaystyle{ \Delta t \gt 0 }[/math] can be obtained by the following method:

  1. set [math]\displaystyle{ \mathbf x_1 = \mathbf x_0 + \mathbf v_0\,\Delta t + \tfrac 1 2 \mathbf A(\mathbf x_0)\,\Delta t^2 }[/math],
  2. for n = 1, 2, ... iterate [math]\displaystyle{ \mathbf x_{n+1} = 2 \mathbf x_n - \mathbf x_{n-1} + \mathbf A(\mathbf x_n)\,\Delta t^2. }[/math]

Equations of motion

Newton's equation of motion for conservative physical systems is

[math]\displaystyle{ \boldsymbol M \ddot{\mathbf x}(t) = F\bigl(\mathbf x(t)\bigr) = -\nabla V\bigl(\mathbf x(t)\bigr), }[/math]

or individually

[math]\displaystyle{ m_k \ddot{\mathbf x}_k(t) = F_k\bigl(\mathbf x(t)\bigr) = -\nabla_{\mathbf x_k} V\left(\mathbf x(t)\right), }[/math]

where

  • [math]\displaystyle{ t }[/math] is the time,
  • [math]\displaystyle{ \mathbf x(t) = \bigl(\mathbf x_1(t), \ldots, \mathbf x_N(t)\bigr) }[/math] is the ensemble of the position vector of [math]\displaystyle{ N }[/math] objects,
  • [math]\displaystyle{ V }[/math] is the scalar potential function,
  • [math]\displaystyle{ F }[/math] is the negative gradient of the potential, giving the ensemble of forces on the particles,
  • [math]\displaystyle{ \boldsymbol M }[/math] is the mass matrix, typically diagonal with blocks with mass [math]\displaystyle{ m_k }[/math] for every particle.

This equation, for various choices of the potential function [math]\displaystyle{ V }[/math], can be used to describe the evolution of diverse physical systems, from the motion of interacting molecules to the orbit of the planets.

After a transformation to bring the mass to the right side and forgetting the structure of multiple particles, the equation may be simplified to

[math]\displaystyle{ \ddot{\mathbf x}(t) = \mathbf A\bigl(\mathbf x(t)\bigr) }[/math]

with some suitable vector-valued function [math]\displaystyle{ \mathbf A(\mathbf x) }[/math] representing the position-dependent acceleration. Typically, an initial position [math]\displaystyle{ \mathbf x(0) = \mathbf x_0 }[/math] and an initial velocity [math]\displaystyle{ \mathbf v(0) = \dot{\mathbf x}(0) = \mathbf v_0 }[/math] are also given.

Verlet integration (without velocities)

To discretize and numerically solve this initial value problem, a time step [math]\displaystyle{ \Delta t \gt 0 }[/math] is chosen, and the sampling-point sequence [math]\displaystyle{ t_n = n\,\Delta t }[/math] considered. The task is to construct a sequence of points [math]\displaystyle{ \mathbf x_n }[/math] that closely follow the points [math]\displaystyle{ \mathbf x(t_n) }[/math] on the trajectory of the exact solution.

Where Euler's method uses the forward difference approximation to the first derivative in differential equations of order one, Verlet integration can be seen as using the central difference approximation to the second derivative:

[math]\displaystyle{ \begin{align} \frac{\Delta^2\mathbf x_n}{\Delta t^2} &= \frac{\frac{\mathbf x_{n+1} - \mathbf x_n}{\Delta t} - \frac{\mathbf x_n - \mathbf x_{n-1}}{\Delta t}}{\Delta t}\\[6pt] &= \frac{\mathbf x_{n+1} - 2 \mathbf x_n + \mathbf x_{n-1}}{\Delta t^2} = \mathbf a_n = \mathbf A(\mathbf x_n). \end{align} }[/math]

Verlet integration in the form used as the Störmer method[3] uses this equation to obtain the next position vector from the previous two without using the velocity as

[math]\displaystyle{ \begin{align} \mathbf x_{n+1} &= 2 \mathbf x_n - \mathbf x_{n-1} + \mathbf a_n\,\Delta t^2, \\[6pt] \mathbf a_n &= \mathbf A(\mathbf x_n). \end{align} }[/math]

Discretisation error

The time symmetry inherent in the method reduces the level of local errors introduced into the integration by the discretization by removing all odd-degree terms, here the terms in [math]\displaystyle{ \Delta t }[/math] of degree three. The local error is quantified by inserting the exact values [math]\displaystyle{ \mathbf x(t_{n-1}), \mathbf x(t_n), \mathbf x(t_{n+1}) }[/math] into the iteration and computing the Taylor expansions at time [math]\displaystyle{ t = t_n }[/math] of the position vector [math]\displaystyle{ \mathbf{x}(t \pm \Delta t) }[/math] in different time directions:

[math]\displaystyle{ \begin{align} \mathbf{x}(t + \Delta t) &= \mathbf{x}(t) + \mathbf{v}(t)\Delta t + \frac{\mathbf{a}(t) \Delta t^2}{2} + \frac{\mathbf{b}(t) \Delta t^3}{6} + \mathcal{O}\left(\Delta t^4\right)\\ \mathbf{x}(t - \Delta t) &= \mathbf{x}(t) - \mathbf{v}(t)\Delta t + \frac{\mathbf{a}(t) \Delta t^2}{2} - \frac{\mathbf{b}(t) \Delta t^3}{6} + \mathcal{O}\left(\Delta t^4\right), \end{align} }[/math]

where [math]\displaystyle{ \mathbf{x} }[/math] is the position, [math]\displaystyle{ \mathbf{v} = \dot{\mathbf x} }[/math] the velocity, [math]\displaystyle{ \mathbf{a} = \ddot{\mathbf x} }[/math] the acceleration, and [math]\displaystyle{ \mathbf{b} = \dot{\mathbf a} = \overset{\dots}{\mathbf x} }[/math] the jerk (third derivative of the position with respect to the time).

Adding these two expansions gives

[math]\displaystyle{ \mathbf{x}(t + \Delta t) = 2\mathbf{x}(t) - \mathbf{x}(t - \Delta t) + \mathbf{a}(t) \Delta t^2 + \mathcal{O}\left(\Delta t^4\right). }[/math]

We can see that the first- and third-order terms from the Taylor expansion cancel out, thus making the Verlet integrator an order more accurate than integration by simple Taylor expansion alone.

Caution should be applied to the fact that the acceleration here is computed from the exact solution, [math]\displaystyle{ \mathbf a(t) = \mathbf A\bigl(\mathbf x(t)\bigr) }[/math], whereas in the iteration it is computed at the central iteration point, [math]\displaystyle{ \mathbf a_n = \mathbf A(\mathbf x_n) }[/math]. In computing the global error, that is the distance between exact solution and approximation sequence, those two terms do not cancel exactly, influencing the order of the global error.

A simple example

To gain insight into the relation of local and global errors, it is helpful to examine simple examples where the exact solution, as well as the approximate solution, can be expressed in explicit formulas. The standard example for this task is the exponential function.

Consider the linear differential equation [math]\displaystyle{ \ddot x(t) = w^2 x(t) }[/math] with a constant [math]\displaystyle{ w }[/math]. Its exact basis solutions are [math]\displaystyle{ e^{wt} }[/math] and [math]\displaystyle{ e^{-wt} }[/math].

The Störmer method applied to this differential equation leads to a linear recurrence relation

[math]\displaystyle{ x_{n+1} - 2x_n + x_{n-1} = h^2 w^2 x_n, }[/math]

or

[math]\displaystyle{ x_{n+1} - 2\left(1 + \tfrac12(wh)^2\right) x_n + x_{n-1} = 0. }[/math]

It can be solved by finding the roots of its characteristic polynomial [math]\displaystyle{ q^2 - 2\left(1 + \tfrac12(wh)^2\right)q + 1 = 0 }[/math]. These are

[math]\displaystyle{ q_\pm = 1 + \tfrac 1 2 (wh)^2 \pm wh \sqrt{1 + \tfrac 1 4 (wh)^2}. }[/math]

The basis solutions of the linear recurrence are [math]\displaystyle{ x_n = q_+^n }[/math] and [math]\displaystyle{ x_n = q_-^n }[/math]. To compare them with the exact solutions, Taylor expansions are computed:

[math]\displaystyle{ \begin{align} q_+ &= 1 + \tfrac12(wh)^2 + wh\left(1 + \tfrac18(wh)^2 - \tfrac{3}{128}(wh)^4 + \mathcal O\left(h^6\right)\right)\\ &= 1 + (wh) + \tfrac12(wh)^2 + \tfrac18(wh)^3 - \tfrac{3}{128}(wh)^5 + \mathcal O\left(h^7\right). \end{align} }[/math]

The quotient of this series with the one of the exponential [math]\displaystyle{ e^{wh} }[/math] starts with [math]\displaystyle{ 1 - \tfrac1{24}(wh)^3 + \mathcal O\left(h^5\right) }[/math], so

[math]\displaystyle{ \begin{align} q_+ &= \left(1 - \tfrac1{24}(wh)^3 + \mathcal O\left(h^5\right)\right)e^{wh}\\ &= e^{-\frac{1}{24}(wh)^3 + \mathcal O\left(h^5\right)}\,e^{wh}. \end{align} }[/math]

From there it follows that for the first basis solution the error can be computed as

[math]\displaystyle{ \begin{align} x_n = q_+^{n} &= e^{-\frac{1}{24}(wh)^2\,wt_n + \mathcal O\left(h^4\right)}\,e^{wt_n}\\ &= e^{wt_n}\left(1 - \tfrac{1}{24}(wh)^2\,wt_n + \mathcal O(h^4)\right)\\ &= e^{wt_n} + \mathcal O\left(h^2 t_n e^{wt_n}\right). \end{align} }[/math]

That is, although the local discretization error is of order 4, due to the second order of the differential equation the global error is of order 2, with a constant that grows exponentially in time.

Starting the iteration

Note that at the start of the Verlet iteration at step [math]\displaystyle{ n = 1 }[/math], time [math]\displaystyle{ t = t_1 = \Delta t }[/math], computing [math]\displaystyle{ \mathbf x_2 }[/math], one already needs the position vector [math]\displaystyle{ \mathbf x_1 }[/math] at time [math]\displaystyle{ t = t_1 }[/math]. At first sight, this could give problems, because the initial conditions are known only at the initial time [math]\displaystyle{ t_0 = 0 }[/math]. However, from these the acceleration [math]\displaystyle{ \mathbf a_0 = \mathbf A(\mathbf x_0) }[/math] is known, and a suitable approximation for the position at the first time step can be obtained using the Taylor polynomial of degree two:

[math]\displaystyle{ \mathbf x_1 = \mathbf{x}_0 + \mathbf{v}_0 \Delta t + \tfrac12 \mathbf a_0 \Delta t^2 \approx \mathbf{x}(\Delta t) + \mathcal{O}\left(\Delta t^3\right). }[/math]

The error on the first time step then is of order [math]\displaystyle{ \mathcal O\left(\Delta t^3\right) }[/math]. This is not considered a problem because on a simulation over a large number of time steps, the error on the first time step is only a negligibly small amount of the total error, which at time [math]\displaystyle{ t_n }[/math] is of the order [math]\displaystyle{ \mathcal O\left(e^{Lt_n} \Delta t^2\right) }[/math], both for the distance of the position vectors [math]\displaystyle{ \mathbf x_n }[/math] to [math]\displaystyle{ \mathbf x(t_n) }[/math] as for the distance of the divided differences [math]\displaystyle{ \tfrac{\mathbf x_{n+1} - \mathbf x_n}{\Delta t} }[/math] to [math]\displaystyle{ \tfrac{\mathbf x(t_{n+1}) - \mathbf x(t_n)}{\Delta t} }[/math]. Moreover, to obtain this second-order global error, the initial error needs to be of at least third order.

Non-constant time differences

A disadvantage of the Störmer–Verlet method is that if the time step ([math]\displaystyle{ \Delta t }[/math]) changes, the method does not approximate the solution to the differential equation. This can be corrected using the formula[4]

[math]\displaystyle{ \mathbf x_{i+1} = \mathbf x_i + \left(\mathbf x_i - \mathbf x_{i-1}\right) \frac{\Delta t_i}{\Delta t_{i-1}} + \mathbf a_i \Delta t_i^2. }[/math]

A more exact derivation uses the Taylor series (to second order) at [math]\displaystyle{ t_i }[/math] for times [math]\displaystyle{ t_{i+1} = t_i + \Delta t_i }[/math] and [math]\displaystyle{ t_{i-1} = t_i - \Delta t_{i-1} }[/math] to obtain after elimination of [math]\displaystyle{ \mathbf v_i }[/math]

[math]\displaystyle{ \frac{\mathbf x_{i+1} - \mathbf x_i}{\Delta t_i} + \frac{\mathbf x_{i-1} - \mathbf x_i}{\Delta t_{i-1}} = \mathbf a_i\,\frac{\Delta t_{i} + \Delta t_{i-1}}2, }[/math]

so that the iteration formula becomes

[math]\displaystyle{ \mathbf x_{i+1} = \mathbf x_i + (\mathbf x_i - \mathbf x_{i-1}) \frac{\Delta t_i}{\Delta t_{i-1}} + \mathbf a_i\,\frac{\Delta t_{i} + \Delta t_{i-1}}2\,\Delta t_i. }[/math]

Computing velocities – Störmer–Verlet method

The velocities are not explicitly given in the basic Störmer equation, but often they are necessary for the calculation of certain physical quantities like the kinetic energy. This can create technical challenges in molecular dynamics simulations, because kinetic energy and instantaneous temperatures at time [math]\displaystyle{ t }[/math] cannot be calculated for a system until the positions are known at time [math]\displaystyle{ t + \Delta t }[/math]. This deficiency can either be dealt with using the velocity Verlet algorithm or by estimating the velocity using the position terms and the mean value theorem:

[math]\displaystyle{ \mathbf{v}(t) = \frac{\mathbf{x}(t + \Delta t) - \mathbf{x}(t - \Delta t)}{2\Delta t} + \mathcal{O}\left(\Delta t^2\right). }[/math]

Note that this velocity term is a step behind the position term, since this is for the velocity at time [math]\displaystyle{ t }[/math], not [math]\displaystyle{ t + \Delta t }[/math], meaning that [math]\displaystyle{ \mathbf v_n = \tfrac{\mathbf x_{n+1} - \mathbf x_{n-1}}{2\Delta t} }[/math] is a second-order approximation to [math]\displaystyle{ \mathbf{v}(t_n) }[/math]. With the same argument, but halving the time step, [math]\displaystyle{ \mathbf v_{n+\frac12} = \tfrac{\mathbf x_{n+1} - \mathbf x_n}{\Delta t} }[/math] is a second-order approximation to [math]\displaystyle{ \mathbf{v}\left(t_{n+\frac12}\right) }[/math], with [math]\displaystyle{ t_{n+\frac12} = t_n + \tfrac12 \Delta t }[/math].

One can shorten the interval to approximate the velocity at time [math]\displaystyle{ t + \Delta t }[/math] at the cost of accuracy:

[math]\displaystyle{ \mathbf{v}(t + \Delta t) = \frac{\mathbf{x}(t + \Delta t) - \mathbf{x}(t)}{\Delta t} + \mathcal{O}(\Delta t). }[/math]

Velocity Verlet

A related, and more commonly used, algorithm is the velocity Verlet algorithm,[5] similar to the leapfrog method, except that the velocity and position are calculated at the same value of the time variable (leapfrog does not, as the name suggests). This uses a similar approach, but explicitly incorporates velocity, solving the problem of the first time step in the basic Verlet algorithm:

[math]\displaystyle{ \begin{align} \mathbf{x}(t + \Delta t) &= \mathbf{x}(t) + \mathbf{v}(t)\, \Delta t + \tfrac{1}{2} \,\mathbf{a}(t) \Delta t^2, \\[6pt] \mathbf{v}(t + \Delta t) &= \mathbf{v}(t) + \frac{\mathbf{a}(t) + \mathbf{a}(t + \Delta t)}{2} \Delta t. \end{align} }[/math]

It can be shown that the error in the velocity Verlet is of the same order as in the basic Verlet. Note that the velocity algorithm is not necessarily more memory-consuming, because, in basic Verlet, we keep track of two vectors of position, while in velocity Verlet, we keep track of one vector of position and one vector of velocity. The standard implementation scheme of this algorithm is:

  1. Calculate [math]\displaystyle{ \mathbf{v}\left(t + \tfrac12\,\Delta t\right) = \mathbf{v}(t) + \tfrac12\,\mathbf{a}(t)\,\Delta t }[/math].
  2. Calculate [math]\displaystyle{ \mathbf{x}(t + \Delta t) = \mathbf{x}(t) + \mathbf{v}\left(t + \tfrac12\,\Delta t\right)\, \Delta t }[/math].
  3. Derive [math]\displaystyle{ \mathbf{a}(t + \Delta t) }[/math] from the interaction potential using [math]\displaystyle{ \mathbf{x}(t + \Delta t) }[/math].
  4. Calculate [math]\displaystyle{ \mathbf{v}(t + \Delta t) = \mathbf{v}\left(t + \tfrac12\,\Delta t\right) + \tfrac12\,\mathbf{a}(t + \Delta t)\Delta t }[/math].

This algorithm also works with variable time steps, and is identical to the 'kick-drift-kick' form of leapfrog method integration.

Eliminating the half-step velocity, this algorithm may be shortened to

  1. Calculate [math]\displaystyle{ \mathbf{x}(t + \Delta t) = \mathbf{x}(t) + \mathbf{v}(t)\,\Delta t + \tfrac12 \,\mathbf{a}(t)\,\Delta t^2 }[/math].
  2. Derive [math]\displaystyle{ \mathbf{a}(t + \Delta t) }[/math] from the interaction potential using [math]\displaystyle{ \mathbf{x}(t + \Delta t) }[/math].
  3. Calculate [math]\displaystyle{ \mathbf{v}(t + \Delta t) = \mathbf{v}(t) + \tfrac12\,\bigl(\mathbf{a}(t) + \mathbf{a}(t + \Delta t)\bigr)\Delta t }[/math].

Note, however, that this algorithm assumes that acceleration [math]\displaystyle{ \mathbf{a}(t + \Delta t) }[/math] only depends on position [math]\displaystyle{ \mathbf{x}(t + \Delta t) }[/math] and does not depend on velocity [math]\displaystyle{ \mathbf{v}(t + \Delta t) }[/math].

One might note that the long-term results of velocity Verlet, and similarly of leapfrog are one order better than the semi-implicit Euler method. The algorithms are almost identical up to a shift by half a time step in the velocity. This can be proven by rotating the above loop to start at step 3 and then noticing that the acceleration term in step 1 could be eliminated by combining steps 2 and 4. The only difference is that the midpoint velocity in velocity Verlet is considered the final velocity in semi-implicit Euler method.

The global error of all Euler methods is of order one, whereas the global error of this method is, similar to the midpoint method, of order two. Additionally, if the acceleration indeed results from the forces in a conservative mechanical or Hamiltonian system, the energy of the approximation essentially oscillates around the constant energy of the exactly solved system, with a global error bound again of order one for semi-explicit Euler and order two for Verlet-leapfrog. The same goes for all other conserved quantities of the system like linear or angular momentum, that are always preserved or nearly preserved in a symplectic integrator.[6]

The velocity Verlet method is a special case of the Newmark-beta method with [math]\displaystyle{ \beta = 0 }[/math] and [math]\displaystyle{ \gamma = \tfrac12 }[/math].

Algorithmic representation

Since velocity Verlet is a generally useful algorithm in 3D applications, a general solution written in C++ could look like below. A simplified drag force is used to demonstrate change in acceleration, however it is only needed if acceleration is not constant.

struct Body
{
    Vec3d pos { 0.0, 0.0, 0.0 };
    Vec3d vel { 2.0, 0.0, 0.0 }; // 2 m/s along x-axis
    Vec3d acc { 0.0, 0.0, 0.0 }; // no acceleration at first
    double mass = 1.0; // 1kg
    double drag = 0.1; // rho*C*Area – simplified drag for this example

    /**
     * Update pos and vel using "Velocity Verlet" integration
     * @param dt DeltaTime / time step [eg: 0.01]
     */
    void update(double dt)
    {
        Vec3d new_pos = pos + vel*dt + acc*(dt*dt*0.5);
        Vec3d new_acc = apply_forces(); // only needed if acceleration is not constant
        Vec3d new_vel = vel + (acc+new_acc)*(dt*0.5);
        pos = new_pos;
        vel = new_vel;
        acc = new_acc;
    }

    Vec3d apply_forces() const
    {
        Vec3d grav_acc = Vec3d{0.0, 0.0, -9.81 }; // 9.81 m/s² down in the z-axis
        Vec3d drag_force = 0.5 * drag * (vel * vel); // D = 0.5 * (rho * C * Area * vel^2)
        Vec3d drag_acc = drag_force / mass; // a = F/m
        return grav_acc - drag_acc;
    }
};

Error terms

The global truncation error of the Verlet method is [math]\displaystyle{ \mathcal O\left(\Delta t^2\right) }[/math], both for position and velocity. This is in contrast with the fact that the local error in position is only [math]\displaystyle{ \mathcal O\left(\Delta t^4\right) }[/math] as described above. The difference is due to the accumulation of the local truncation error over all of the iterations.

The global error can be derived by noting the following:

[math]\displaystyle{ \operatorname{error}\bigl(x(t_0 + \Delta t)\bigr) = \mathcal O\left(\Delta t^4\right) }[/math]

and

[math]\displaystyle{ x(t_0 + 2\Delta t) = 2x(t_0 + \Delta t) - x(t_0) + \Delta t^2 \ddot{x}(t_0 + \Delta t) + \mathcal O\left(\Delta t^4\right). }[/math]

Therefore

[math]\displaystyle{ \operatorname{error}\bigl(x(t_0 + 2\Delta t)\bigr) = 2\cdot\operatorname{error}\bigl(x(t_0 + \Delta t)\bigr) + \mathcal O\left(\Delta t^4\right) = 3\,\mathcal O\left(\Delta t^4\right). }[/math]

Similarly:

[math]\displaystyle{ \begin{align} \operatorname{error}\bigl(x(t_0 + 3\Delta t)\bigl) &= 6\,\mathcal O\left(\Delta t^4\right), \\[6px] \operatorname{error}\bigl(x(t_0 + 4\Delta t)\bigl) &= 10\,\mathcal O\left(\Delta t^4\right), \\[6px] \operatorname{error}\bigl(x(t_0 + 5\Delta t)\bigl) &= 15\,\mathcal O\left(\Delta t^4\right), \end{align} }[/math]

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

[math]\displaystyle{ \operatorname{error}\bigl(x(t_0 + n\Delta t)\bigr) = \frac{n(n+1)}{2}\,\mathcal O\left(\Delta t^4\right). }[/math]

If we consider the global error in position between [math]\displaystyle{ x(t) }[/math] and [math]\displaystyle{ x(t + T) }[/math], where [math]\displaystyle{ T = n\Delta t }[/math], it is clear that[citation needed]

[math]\displaystyle{ \operatorname{error}\bigl(x(t_0 + T)\bigr) = \left(\frac{T^2}{2\Delta t^2} + \frac{T}{2\Delta t}\right) \mathcal O\left(\Delta t^4\right), }[/math]

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

[math]\displaystyle{ \operatorname{error}\bigr(x(t_0 + T)\bigl) = \mathcal O\left(\Delta t^2\right). }[/math]

Because the velocity is determined in a non-cumulative way from the positions in the Verlet integrator, the global error in velocity is also [math]\displaystyle{ \mathcal O\left(\Delta t^2\right) }[/math].

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

Systems of multiple particles with constraints are simpler to solve with Verlet integration than with Euler methods. Constraints between points may be, for example, potentials constraining them to a specific distance or attractive forces. They may be modeled as springs connecting the particles. Using springs of infinite stiffness, the model may then be solved with a Verlet algorithm.

In one dimension, the relationship between the unconstrained positions [math]\displaystyle{ \tilde{x}_i^{(t)} }[/math] and the actual positions [math]\displaystyle{ x_i^{(t)} }[/math] of points [math]\displaystyle{ i }[/math] at time [math]\displaystyle{ t }[/math], given a desired constraint distance of [math]\displaystyle{ r }[/math], can be found with the algorithm

[math]\displaystyle{ \begin{align} d_1 &= x_2^{(t)} - x_1^{(t)}, \\[6px] d_2 &= \|d_1\|, \\[6px] d_3 &= \frac{d_2 - r}{d_2}, \\[6px] x_1^{(t + \Delta t)} &= \tilde{x}_1^{(t + \Delta t)} + \tfrac{1}{2} d_1 d_3, \\[6px] x_2^{(t + \Delta t)} &= \tilde{x}_2^{(t + \Delta t)} - \tfrac{1}{2} d_1 d_3. \end{align} }[/math]

Verlet integration is useful because it directly relates the force to the position, rather than solving the problem using velocities.

Problems, however, arise when multiple constraining forces act on each particle. One way to solve this is to loop through every point in a simulation, so that at every point the constraint relaxation of the last is already used to speed up the spread of the information. In a simulation this may be implemented by using small time steps for the simulation, using a fixed number of constraint-solving steps per time step, or solving constraints 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 clusters the LU method is used, between clusters 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.

Sophisticated software, such as SuperLU[7] exists to solve complex problems using sparse matrices. Specific techniques, such as using (clusters of) matrices, may be used to address the specific problem, such as that of force propagating through a sheet of cloth without forming a sound wave.[8]

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 by 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, one 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 and inelastic collisions. A slightly more complicated strategy that offers more control would involve using the coefficient of restitution.

See also

Literature

  1. Verlet, Loup (1967). "Computer "Experiments" on Classical Fluids. I. Thermodynamical Properties of Lennard−Jones Molecules". Physical Review 159 (1): 98–103. doi:10.1103/PhysRev.159.98. Bibcode1967PhRv..159...98V. 
  2. Press, W. H.; Teukolsky, S. A.; Vetterling, W. T.; Flannery, B. P. (2007). "Section 17.4. Second-Order Conservative Equations". Numerical Recipes: The Art of Scientific Computing (3rd ed.). New York: Cambridge University Press. ISBN 978-0-521-88068-8. http://apps.nrbook.com/empanel/index.html#pg=928. 
  3. webpage with a description of the Störmer method.
  4. Dummer, Jonathan. "A Simple Time-Corrected Verlet Integration Method". http://lonesock.net/article/verlet.html. 
  5. Swope, William C.; H. C. Andersen; P. H. Berens; K. R. Wilson (1 January 1982). "A computer simulation method for the calculation of equilibrium constants for the formation of physical clusters of molecules: Application to small water clusters". The Journal of Chemical Physics 76 (1): 648 (Appendix). doi:10.1063/1.442716. Bibcode1982JChPh..76..637S. 
  6. Hairer, Ernst; Lubich, Christian; Wanner, Gerhard (2003). "Geometric numerical integration illustrated by the Störmer/Verlet method". Acta Numerica 12: 399–450. doi:10.1017/S0962492902000144. Bibcode2003AcNum..12..399H. 
  7. SuperLU User's Guide.
  8. Baraff, D.; Witkin, A. (1998). "Large Steps in Cloth Simulation". Computer Graphics Proceedings Annual Conference Series: 43–54. https://www.cs.cmu.edu/~baraff/papers/sig98.pdf. 

External links