Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Verlet integration

From Wikipedia, the free encyclopedia
(Redirected fromVelocity Verlet)
Numerical integration algorithm

Verlet integration (French pronunciation:[vɛʁˈlɛ]) is a numerical method used tointegrateNewton'sequations of motion.[1] It is frequently used to calculatetrajectories of particles inmolecular dynamics simulations andcomputer graphics. The algorithm was first used in 1791 byJean Baptiste Delambre and has been rediscovered many times since then, most recently byLoup Verlet in the 1960s for use in molecular dynamics. It was also used byP. H. Cowell andA. C. C. Crommelin in 1909 to compute the orbit ofHalley's Comet, and byCarl Størmer in 1907 to study the trajectories of electrical particles in amagnetic field (hence it is also calledStørmer's method).[2]The Verlet integrator provides goodnumerical stability, as well as other properties that are important inphysical systems such astime reversibility andpreservation of the symplectic form on phase space, at no significant additional computational cost over the simpleEuler method.

Basic Størmer–Verlet

[edit]

For asecond-order differential equation of the typex¨(t)=A(x(t)){\displaystyle {\ddot {\mathbf {x} }}(t)=\mathbf {A} {\bigl (}\mathbf {x} (t){\bigr )}} with initial conditionsx(t0)=x0{\displaystyle \mathbf {x} (t_{0})=\mathbf {x} _{0}} andx˙(t0)=v0{\displaystyle {\dot {\mathbf {x} }}(t_{0})=\mathbf {v} _{0}}, an approximate numerical solutionxnx(tn){\displaystyle \mathbf {x} _{n}\approx \mathbf {x} (t_{n})} at the timestn=t0+nΔt{\displaystyle t_{n}=t_{0}+n\,\Delta t} with step sizeΔt>0{\displaystyle \Delta t>0} can be obtained by the following method:

  1. setx1=x0+v0Δt+12A(x0)Δt2{\textstyle \mathbf {x} _{1}=\mathbf {x} _{0}+\mathbf {v} _{0}\,\Delta t+{\tfrac {1}{2}}\mathbf {A} (\mathbf {x} _{0})\,\Delta t^{2}},
  2. forn = 1, 2, ... iteratexn+1=2xnxn1+A(xn)Δt2.{\displaystyle \mathbf {x} _{n+1}=2\mathbf {x} _{n}-\mathbf {x} _{n-1}+\mathbf {A} (\mathbf {x} _{n})\,\Delta t^{2}.}

Equations of motion

[edit]

Newton's equation of motion for conservative physical systems isMx¨(t)=F(x(t))=V(x(t)),{\displaystyle {\boldsymbol {M}}{\ddot {\mathbf {x} }}(t)=F{\bigl (}\mathbf {x} (t){\bigr )}=-\nabla V{\bigl (}\mathbf {x} (t){\bigr )},}or individuallymkx¨k(t)=Fk(x(t))=xkV(x(t)),{\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)},}where

This equation, for various choices of the potential functionV{\displaystyle V}, can be used to describe the evolution of diverse physical systems, from the motion ofinteracting molecules to theorbit 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 tox¨(t)=A(x(t)){\displaystyle {\ddot {\mathbf {x} }}(t)=\mathbf {A} {\bigl (}\mathbf {x} (t){\bigr )}}with some suitable vector-valued functionA(x){\displaystyle \mathbf {A} (\mathbf {x} )} representing the position-dependent acceleration. Typically, an initial positionx(0)=x0{\displaystyle \mathbf {x} (0)=\mathbf {x} _{0}} and an initial velocityv(0)=x˙(0)=v0{\displaystyle \mathbf {v} (0)={\dot {\mathbf {x} }}(0)=\mathbf {v} _{0}} are also given.

Verlet integration (without velocities)

[edit]

To discretize and numerically solve thisinitial value problem, a time stepΔt>0{\displaystyle \Delta t>0} is chosen, and the sampling-point sequencetn=nΔt{\displaystyle t_{n}=n\,\Delta t} considered. The task is to construct a sequence of pointsxn{\displaystyle \mathbf {x} _{n}} that closely follow the pointsx(tn){\displaystyle \mathbf {x} (t_{n})} on the trajectory of the exact solution.

WhereEuler's method uses theforward difference approximation to the first derivative in differential equations of order one, Verlet integration can be seen as using thecentral difference approximation to the second derivative:Δ2xnΔt2=xn+1xnΔtxnxn1ΔtΔt=xn+12xn+xn1Δt2=an=A(xn).{\displaystyle {\begin{aligned}{\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{aligned}}}

Verlet integration in the form used as theStørmer method[3] uses this equation to obtain the next position vector from the previous two without using the velocity asxn+1=2xnxn1+anΔt2,an=A(xn).{\displaystyle {\begin{aligned}\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{aligned}}}

Discretisation error

[edit]

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Δt{\displaystyle \Delta t} of degree three. The local error is quantified by inserting the exact valuesx(tn1),x(tn),x(tn+1){\displaystyle \mathbf {x} (t_{n-1}),\mathbf {x} (t_{n}),\mathbf {x} (t_{n+1})} into the iteration and computing theTaylor expansions at timet=tn{\displaystyle t=t_{n}} of the position vectorx(t±Δt){\displaystyle \mathbf {x} (t\pm \Delta t)} in different time directions:x(t+Δt)=x(t)+v(t)Δt+a(t)Δt22+b(t)Δt36+O(Δt4)x(tΔt)=x(t)v(t)Δt+a(t)Δt22b(t)Δt36+O(Δt4),{\displaystyle {\begin{aligned}\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)}\\[1ex]\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{aligned}}}wherex{\displaystyle \mathbf {x} } is the position,v=x˙{\displaystyle \mathbf {v} ={\dot {\mathbf {x} }}} the velocity,a=x¨{\displaystyle \mathbf {a} ={\ddot {\mathbf {x} }}} the acceleration, andb=a˙=x{\displaystyle \mathbf {b} ={\dot {\mathbf {a} }}={\overset {\dots }{\mathbf {x} }}} thejerk (third derivative of the position with respect to the time).

Adding these two expansions givesx(t+Δt)=2x(t)x(tΔt)+a(t)Δt2+O(Δt4).{\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)}.}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,a(t)=A(x(t)){\displaystyle \mathbf {a} (t)=\mathbf {A} {\bigl (}\mathbf {x} (t){\bigr )}}, whereas in the iteration it is computed at the central iteration point,an=A(xn){\displaystyle \mathbf {a} _{n}=\mathbf {A} (\mathbf {x} _{n})}. 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

[edit]

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 theexponential function.

Consider the linear differential equationx¨(t)=w2x(t){\displaystyle {\ddot {x}}(t)=w^{2}x(t)} with a constantw{\displaystyle w}. Its exact basis solutions areewt{\displaystyle e^{wt}} andewt{\displaystyle e^{-wt}}.

The Størmer method applied to this differential equation leads to a linearrecurrence relationxn+12xn+xn1=h2w2xn,{\displaystyle x_{n+1}-2x_{n}+x_{n-1}=h^{2}w^{2}x_{n},}orxn+12(1+12(wh)2)xn+xn1=0.{\displaystyle x_{n+1}-2\left(1+{\tfrac {1}{2}}\left(wh\right)^{2}\right)x_{n}+x_{n-1}=0.}It can be solved by finding the roots of its characteristic polynomialq22(1+12(wh)2)q+1=0{\displaystyle q^{2}-2\left(1+{\tfrac {1}{2}}(wh)^{2}\right)q+1=0}. These areq±=1+12(wh)2±wh1+14(wh)2.{\displaystyle q_{\pm }=1+{\tfrac {1}{2}}\left(wh\right)^{2}\pm wh{\sqrt {1+{\tfrac {1}{4}}\left(wh\right)^{2}}}.}The basis solutions of the linear recurrence arexn=q+n{\displaystyle x_{n}=q_{+}^{n}} andxn=qn{\displaystyle x_{n}=q_{-}^{n}}. To compare them with the exact solutions, Taylor expansions are computed:q+=1+12(wh)2+wh(1+18(wh)23128(wh)4+O(h6))=1+(wh)+12(wh)2+18(wh)33128(wh)5+O(h7).{\displaystyle {\begin{aligned}q_{+}&=1+{\tfrac {1}{2}}(wh)^{2}+wh\left(1+{\tfrac {1}{8}}(wh)^{2}-{\tfrac {3}{128}}(wh)^{4}+{\mathcal {O}}{\left(h^{6}\right)}\right)\\&=1+(wh)+{\tfrac {1}{2}}(wh)^{2}+{\tfrac {1}{8}}(wh)^{3}-{\tfrac {3}{128}}(wh)^{5}+{\mathcal {O}}{\left(h^{7}\right)}.\end{aligned}}}The quotient of this series with the exponentialewh{\displaystyle e^{wh}} starts with1124(wh)3+O(h5){\displaystyle 1-{\tfrac {1}{24}}(wh)^{3}+{\mathcal {O}}{\left(h^{5}\right)}}, soq+=(1124(wh)3+O(h5))ewh=e124(wh)3+O(h5)ewh.{\displaystyle {\begin{aligned}q_{+}&=\left(1-{\tfrac {1}{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{aligned}}}From there it follows that for the first basis solution the error can be computed asxn=q+n=e124(wh)2wtn+O(h4)ewtn=ewtn(1124(wh)2wtn+O(h4))=ewtn+O(h2tnewtn).{\displaystyle {\begin{aligned}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}}{\left(h^{4}\right)}\right)\\&=e^{wt_{n}}+{\mathcal {O}}{\left(h^{2}t_{n}e^{wt_{n}}\right)}.\end{aligned}}}That is, although the localdiscretization 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

[edit]

Note that at the start of the Verlet iteration at stepn=1{\displaystyle n=1}, timet=t1=Δt{\displaystyle t=t_{1}=\Delta t}, computingx2{\displaystyle \mathbf {x} _{2}}, one already needs the position vectorx1{\displaystyle \mathbf {x} _{1}} at timet=t1{\displaystyle t=t_{1}}. At first sight, this could give problems, because the initial conditions are known only at the initial timet0=0{\displaystyle t_{0}=0}. However, from these the accelerationa0=A(x0){\displaystyle \mathbf {a} _{0}=\mathbf {A} (\mathbf {x} _{0})} is known, and a suitable approximation for the position at the first time step can be obtained using theTaylor polynomial of degree two:x1=x0+v0Δt+12a0Δt2x(Δt)+O(Δt3).{\displaystyle {\begin{aligned}\mathbf {x} _{1}&=\mathbf {x} _{0}+\mathbf {v} _{0}\Delta t+{\tfrac {1}{2}}\mathbf {a} _{0}\Delta t^{2}\\&\approx \mathbf {x} (\Delta t)+{\mathcal {O}}{\left(\Delta t^{3}\right)}.\end{aligned}}}

The error on the first time step then is of orderO(Δt3){\displaystyle {\mathcal {O}}{\left(\Delta t^{3}\right)}}. 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 timetn{\displaystyle t_{n}} is of the orderO(eLtnΔt2){\displaystyle {\mathcal {O}}{\left(e^{Lt_{n}}\Delta t^{2}\right)}}, both for the distance of the position vectorsxn{\displaystyle \mathbf {x} _{n}} tox(tn){\displaystyle \mathbf {x} (t_{n})} as for the distance of the divided differencesxn+1xnΔt{\displaystyle {\tfrac {\mathbf {x} _{n+1}-\mathbf {x} _{n}}{\Delta t}}} tox(tn+1)x(tn)Δt{\displaystyle {\tfrac {\mathbf {x} (t_{n+1})-\mathbf {x} (t_{n})}{\Delta t}}}. Moreover, to obtain this second-order global error, the initial error needs to be of at least third order.

Non-constant time differences

[edit]

A disadvantage of the Størmer–Verlet method is that if the time step (Δt{\displaystyle \Delta t}) changes, the method does not approximate the solution to the differential equation. This can be corrected using the formula[4]xi+1=xi+(xixi1)ΔtiΔti1+aiΔti2.{\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}.}

A more exact derivation uses the Taylor series (to second order) atti{\displaystyle t_{i}} for timesti+1=ti+Δti{\displaystyle t_{i+1}=t_{i}+\Delta t_{i}} andti1=tiΔti1{\displaystyle t_{i-1}=t_{i}-\Delta t_{i-1}} to obtain after elimination ofvi{\displaystyle \mathbf {v} _{i}}xi+1xiΔti+xi1xiΔti1=aiΔti+Δti12,{\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}},}so that the iteration formula becomesxi+1=xi+(xixi1)ΔtiΔti1+aiΔti+Δti12Δti.{\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}.}

Computing velocities – Størmer–Verlet method

[edit]

The velocities are not explicitly given in the basic Størmer equation, but often they are necessary for the calculation of certainphysical quantities like thekinetic energy. This can create technical challenges inmolecular dynamics simulations, because kinetic energy and instantaneous temperatures at timet{\displaystyle t} cannot be calculated for a system until the positions are known at timet+Δt{\displaystyle t+\Delta t}. This deficiency can either be dealt with using thevelocity Verlet algorithm or by estimating the velocity using the position terms and themean value theorem:v(t)=x(t+Δt)x(tΔt)2Δt+O(Δt2).{\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)}.}

Note that this velocity term is a step behind the position term, since this is for the velocity at timet{\displaystyle t}, nott+Δt{\displaystyle t+\Delta t}, meaning thatvn=xn+1xn12Δt{\displaystyle \mathbf {v} _{n}={\tfrac {\mathbf {x} _{n+1}-\mathbf {x} _{n-1}}{2\Delta t}}} is a second-order approximation tov(tn){\displaystyle \mathbf {v} (t_{n})}. With the same argument, but halving the time step,vn+12=xn+1xnΔt{\displaystyle \mathbf {v} _{n+{\frac {1}{2}}}={\tfrac {\mathbf {x} _{n+1}-\mathbf {x} _{n}}{\Delta t}}} is a second-order approximation tov(tn+1/2){\displaystyle \mathbf {v} {\left(t_{n+1/2}\right)}}, withtn+12=tn+12Δt{\displaystyle t_{n+{\frac {1}{2}}}=t_{n}+{\tfrac {1}{2}}\Delta t}.

One can shorten the interval to approximate the velocity at timet+Δt{\displaystyle t+\Delta t} at the cost of accuracy:v(t+Δt)=x(t+Δt)x(t)Δt+O(Δt).{\displaystyle \mathbf {v} (t{+}\Delta t)={\frac {\mathbf {x} (t{+}\Delta t)-\mathbf {x} (t)}{\Delta t}}+{\mathcal {O}}(\Delta t).}

Velocity Verlet

[edit]

A related, and more commonly used algorithm is the velocity Verlet algorithm,[5] similar to theleapfrog 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:

x(t+Δt)=x(t)+v(t)Δt+12a(t)Δt2,v(t+Δt)=v(t)+a(t)+a(t+Δt)2Δt.{\displaystyle {\begin{aligned}\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{aligned}}}

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. Calculatev(t+12Δt)=v(t)+12a(t)Δt{\displaystyle \mathbf {v} \left(t+{\tfrac {1}{2}}\,\Delta t\right)=\mathbf {v} (t)+{\tfrac {1}{2}}\,\mathbf {a} (t)\,\Delta t}.
  2. Calculatex(t+Δt)=x(t)+v(t+12Δt)Δt{\displaystyle \mathbf {x} (t+\Delta t)=\mathbf {x} (t)+\mathbf {v} \left(t+{\tfrac {1}{2}}\,\Delta t\right)\,\Delta t}.
  3. Derivea(t+Δt){\displaystyle \mathbf {a} (t+\Delta t)} from the interaction potential usingx(t+Δt){\displaystyle \mathbf {x} (t+\Delta t)}.
  4. Calculatev(t+Δt)=v(t+12Δt)+12a(t+Δt)Δt{\displaystyle \mathbf {v} (t+\Delta t)=\mathbf {v} \left(t+{\tfrac {1}{2}}\,\Delta t\right)+{\tfrac {1}{2}}\,\mathbf {a} (t+\Delta t)\Delta t}.

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

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

  1. Calculatex(t+Δt)=x(t)+v(t)Δt+12a(t)Δt2{\displaystyle \mathbf {x} (t+\Delta t)=\mathbf {x} (t)+\mathbf {v} (t)\,\Delta t+{\tfrac {1}{2}}\,\mathbf {a} (t)\,\Delta t^{2}}.
  2. Derivea(t+Δt){\displaystyle \mathbf {a} (t+\Delta t)} from the interaction potential usingx(t+Δt){\displaystyle \mathbf {x} (t+\Delta t)}.
  3. Calculatev(t+Δt)=v(t)+12(a(t)+a(t+Δt))Δt{\displaystyle \mathbf {v} (t+\Delta t)=\mathbf {v} (t)+{\tfrac {1}{2}}\,{\bigl (}\mathbf {a} (t)+\mathbf {a} (t+\Delta t){\bigr )}\Delta t}.

Note, however, that this algorithm assumes that accelerationa(t+Δt){\displaystyle \mathbf {a} (t+\Delta t)} only depends on positionx(t+Δt){\displaystyle \mathbf {x} (t+\Delta t)} and does not depend on velocityv(t+Δt){\displaystyle \mathbf {v} (t+\Delta t)}.

One might note that the long-term results of velocity Verlet, and similarly of leapfrog are one order better than thesemi-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 themidpoint method, of order two. Additionally, if the acceleration indeed results from the forces in a conservative mechanical orHamiltonian 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 orangular momentum, that are always preserved or nearly preserved in asymplectic integrator.[6]

The velocity Verlet method is a special case of theNewmark-beta method withβ=0{\displaystyle \beta =0} andγ=12{\textstyle \gamma ={\tfrac {1}{2}}}.

Algorithmic representation

[edit]

Sincevelocity Verlet is a generally useful algorithm in 3D applications, a solution written in C++ could look like below. This type of position integration will significantly increase accuracy in 3D simulations and games when compared with the regular Euler method.

structBody{Vec3dpos{0.0,0.0,0.0};Vec3dvel{2.0,0.0,0.0};// 2 m/s along x-axisVec3dacc{0.0,0.0,0.0};// no acceleration at firstdoublemass=1.0;// 1kg/**     * Updates pos and vel using "Velocity Verlet" integration     * @param dt DeltaTime / time step [eg: 0.01]     */voidupdate(doubledt){Vec3dnew_pos=pos+vel*dt+acc*(dt*dt*0.5);Vec3dnew_acc=apply_forces();Vec3dnew_vel=vel+(acc+new_acc)*(dt*0.5);pos=new_pos;vel=new_vel;acc=new_acc;}/**     * To apply velocity to your objects, calculate the required Force vector instead     * and apply the accumulated forces here.     */Vec3dapply_forces()const{Vec3dnew_acc=Vec3d{0.0,0.0,-9.81};// 9.81 m/s² down in the z-axis// Apply any other forces here...// NOTE: Avoid depending on `vel` because Velocity Verlet assumes acceleration depends on position.returnnew_acc;}};

Error terms

[edit]
Main article:Truncation error (numerical integration)

The global truncation error of the Verlet method isO(Δt2){\displaystyle {\mathcal {O}}{\left(\Delta t^{2}\right)}}, both for position and velocity.This is in contrast with the fact that the local error in position is onlyO(Δt4){\displaystyle {\mathcal {O}}{\left(\Delta t^{4}\right)}} 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:

error(x(t0+Δt))=O(Δt4){\displaystyle \operatorname {error} {\bigl (}x(t_{0}+\Delta t){\bigr )}={\mathcal {O}}{\left(\Delta t^{4}\right)}}

and

x(t0+2Δt)=2x(t0+Δt)x(t0)+Δt2x¨(t0+Δt)+O(Δt4).{\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)}.}

Therefore

error(x(t0+2Δt))=2error(x(t0+Δt))+O(Δt4)=3O(Δt4).{\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)}.}

Similarly:

error(x(t0+3Δt))=6O(Δt4),error(x(t0+4Δt))=10O(Δt4),error(x(t0+5Δt))=15O(Δt4),{\displaystyle {\begin{aligned}\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{aligned}}}

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

error(x(t0+nΔt))=n(n+1)2O(Δt4).{\displaystyle \operatorname {error} {\bigl (}x(t_{0}+n\Delta t){\bigr )}={\frac {n(n+1)}{2}}\,{\mathcal {O}}\left(\Delta t^{4}\right).}

If we consider the global error in position betweenx(t){\displaystyle x(t)} andx(t+T){\displaystyle x(t+T)}, whereT=nΔt{\displaystyle T=n\Delta t}, it is clear that[citation needed]

error(x(t0+T))=(T22Δt2+T2Δt)O(Δt4),{\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)},}

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

error(x(t0+T))=O(Δt2).{\displaystyle \operatorname {error} {\bigr (}x(t_{0}+T){\bigl )}={\mathcal {O}}{\left(\Delta t^{2}\right)}.}

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

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

[edit]
Main article:Constraint algorithm

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 assprings 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 positionsx~i(t){\displaystyle {\tilde {x}}_{i}^{(t)}} and the actual positionsxi(t){\displaystyle x_{i}^{(t)}} of pointsi{\displaystyle i} at timet{\displaystyle t}, given a desired constraint distance ofr{\displaystyle r}, can be found with the algorithm

d1=x2(t)x1(t),d2=d1,d3=d2rd2,x1(t+Δt)=x~1(t+Δt)+12d1d3,x2(t+Δt)=x~2(t+Δt)12d1d3.{\displaystyle {\begin{aligned}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{aligned}}}

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 theGauss–Seidel method. For smallmatrices it is known thatLU decomposition is faster. Large systems can be divided into clusters (for example, eachragdoll = cluster). Inside clusters the LU method is used, between clusters theGauss–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 asound wave.[8]

Another way to solveholonomic constraints is to useconstraint algorithms.

Collision reactions

[edit]

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 withcollision 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 perfectlyelastic andinelastic collisions. A slightly more complicated strategy that offers more control would involve using thecoefficient of restitution.

See also

[edit]

Literature

[edit]
  1. ^Verlet, Loup (1967)."Computer "Experiments" on Classical Fluids. I. Thermodynamical Properties of Lennard−Jones Molecules".Physical Review.159 (1):98–103.Bibcode:1967PhRv..159...98V.doi:10.1103/PhysRev.159.98.
  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.
  3. ^webpageArchived 2004-08-03 at theWayback Machine with a description of the Størmer method.
  4. ^Dummer, Jonathan."A Simple Time-Corrected Verlet Integration Method". Archived fromthe original on 2020-01-06. Retrieved2014-02-26.
  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).Bibcode:1982JChPh..76..637S.doi:10.1063/1.442716.
  6. ^Hairer, Ernst; Lubich, Christian; Wanner, Gerhard (2003). "Geometric numerical integration illustrated by the Størmer/Verlet method".Acta Numerica.12:399–450.Bibcode:2003AcNum..12..399H.CiteSeerX 10.1.1.7.7106.doi:10.1017/S0962492902000144.S2CID 122016794.
  7. ^SuperLU User's GuideArchived 2011-07-20 at theWayback Machine.
  8. ^Baraff, D.; Witkin, A. (1998)."Large Steps in Cloth Simulation"(PDF).Computer Graphics Proceedings. Annual Conference Series:43–54.

External links

[edit]


First-order methods
Second-order methods
Higher-order methods
Theory
Related
Retrieved from "https://en.wikipedia.org/w/index.php?title=Verlet_integration&oldid=1334248551#Velocity_Verlet"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp