1. What this solves
You want to follow a system of particles or bodies that move under forces derived from a potential energy, such as planets around a star, atoms in a molecule or masses on springs, for many oscillations or orbits. A general-purpose solver lets the total energy creep up or down over a long run, so the simulation slowly stops being physical. Störmer–Verlet keeps the energy error small and bounded for very long times, at the cost of one force evaluation per step.
In technical terms: it is a second-order, explicit, symplectic and time-reversible integrator for separable Hamiltonians . It exactly conserves linear and angular momentum when the forces do.
2. When to use
- Equations of motion , : the force depends on positions only, masses are constant, and there is no explicit time dependence.
- Long runs where qualitative correctness matters (energy, phase-space structure, conserved momenta): molecular dynamics in the NVE ensemble, celestial mechanics, lattice and spring models.
- A fixed step size is acceptable. For a fastest oscillation of angular frequency , stability requires ; in practice use or smaller for accuracy.
- Moderate accuracy is enough: the error is .
3. When not to use (and what to use instead)
| Situation | Use instead |
|---|---|
| Force depends on velocity (friction, drag, magnetic forces, thermostats) | A general ODE solver such as dormand-prince-rk45, or a splitting designed for that term (for example a Langevin splitting) |
| You need much higher accuracy per unit of work on a smooth problem | yoshida4 (fourth order, still symplectic) |
| Stiff problem: very fast modes you do not need to resolve | An implicit method such as backward-euler or implicit-midpoint |
| Non-separable Hamiltonian, e.g. position-dependent mass | implicit-midpoint (symplectic for any Hamiltonian) |
| Adaptive step sizes or output at arbitrary times, over a short or moderate run | dormand-prince-rk45 |
| Output at arbitrary times over a long run where energy must stay bounded | Keep Verlet at a fixed step and interpolate between steps, or choose so that the output times fall on the step grid. Do not change from step to step: that destroys the long-time energy behaviour. |
| Holonomic constraints (fixed bond lengths, rigid molecules) | A constrained variant such as RATTLE or SHAKE, or SETTLE for rigid water (not in this library) |
4. Algorithm
Let be the step size, the diagonal mass matrix and .
Kick-drift-kick (velocity Verlet), the usual form:
Keep for the first kick of the next step, so each step costs one force evaluation (plus one at the start).
Drift-kick-drift (position Verlet):
Both forms are second order, symplectic and time-reversible. They are conjugate to each other (they differ only by a half drift or half kick at the start and end of a run), so their long-time behaviour is the same. Choose KDK when you want positions and momenta (and forces) at the same time points; DKD is natural when forces are wanted at midpoints. Running with integrates backwards.
5. Parameters
| Parameter | How to choose it |
|---|---|
| Step size | Set by the fastest motion: start near – of the shortest period and confirm with the energy check in section 7. Halving divides errors by about 4. |
| Form (KDK or DKD) | Equivalent accuracy. KDK is the common choice in molecular dynamics. |
| Output interval | Output every steps without changing ; output does not affect the trajectory. |
7. Verification
Step 1: check your implementation against this skill. Do this after porting and before using the results. Show the output to the user.
Get the files: put
checks/check_port.pyandchecks/cases.jsonin the same folder (the script readscases.jsonfrom beside itself). Through MCP, fetch both withget_file; or download and unpack the skill's zip.Python: create
port_adapter.pyin your working directory withSCHEMES = ("kdk",)(or the forms you implemented) and a functionintegrate(q0, p0, h, n_steps, mass, force, scheme)that calls your code and returns the final(q, p)with canonical momenta. Then run it from the directory that containsport_adapter.py, with the Python environment in which your code works:python <folder-with-the-check-files>/check_port.pyIt compares your results with fixed cases computed by the reference implementation (only rounding differences are allowed), and checks convergence order 2, bounded energy over 1,000 periods (unit mass) and on two springs with different masses, and returning to the start after integrating with .
Other languages: run each case in
checks/cases.jsonwith your code (problems, initial states, step sizes and step counts are given there) and compareqandpwithexpectedwithintol.
A failed fixed case almost always means a porting mistake: force sign, half versus full kicks, a missing kick, momentum used as velocity, or KDK and DKD mixed up.
Step 2: check the method on your own problem.
- Convergence order. Integrate to a fixed time with , , , compared with a much finer run or an exact solution. The error ratio should approach 4, an observed order near 2.
- Energy. Record every step over a long run. The error should oscillate around a constant level proportional to , with no systematic growth. Compare the maximum error over the first and last tenth of the run.
- Reversibility. Integrate steps, flip the sign of the momenta, integrate more steps and flip back. You should return to the initial state up to rounding error.
- Conserved momenta. If the forces conserve total linear or angular momentum, those should stay constant to rounding error.
8. Failure signatures
| Symptom | Likely cause |
|---|---|
| Observed order near 1 | Velocity-dependent force used inside the kicks, or the force is evaluated at the wrong position. verify/check_negative.py shows the velocity-dependent case. |
| Energy grows steadily | Step size changed during the run, or a non-conservative force. |
| Energy jumps, then the run blows up | Step size above the stability limit for the fastest mode, or particles getting too close (singular potential). |
| System expands or collapses immediately | Force sign error (), or mixing velocities and momenta with non-unit masses. |
| Results depend on output frequency | Output code modifies the state, or the force is recomputed inconsistently. |
9. Files and commands
Run from this folder with uv and Python 3.11 or newer; only the standard library is used.
uv run examples/harmonic.py
uv run examples/kepler.py
uv run verify/check_order.py
uv run verify/check_energy.py
uv run verify/check_reversibility.py
uv run verify/check_negative.py
uv run verify/check_cases.py
reference/stormer_verlet.py: KDK and DKD steps and a fixed-step driver.examples/: harmonic oscillator convergence table and a 100-period Kepler orbit; expected output in*.expected.txt.checks/: for checking your implementation.cases.jsonholds fixed cases;check_port.pyruns them and the property checks throughport_adapter.py;make_cases.pyregeneratescases.jsonfrom the reference implementation.verify/: evidence for the claims in this file, run on the reference implementation: convergence order, long-time energy and angular momentum, reversibility and cost, the failure for velocity-dependent forces, and that the fixed cases catch five typical porting mistakes.
10. Sources
- E. Hairer, C. Lubich, G. Wanner. Geometric Numerical Integration, 2nd ed. Springer, 2006. https://doi.org/10.1007/3-540-30666-8
- E. Hairer, C. Lubich, G. Wanner. Geometric numerical integration illustrated by the Störmer–Verlet method. Acta Numerica 12 (2003) 399–450. https://doi.org/10.1017/S0962492902000144