1. What this solves
A Cartesian pendulum must stay on its circle and its velocity must stay tangent to that circle. The same requirements apply to fixed bond lengths. RATTLE adds both corrections to the kick–drift–kick form of stormer-verlet. It gives second-order trajectories for smooth problems and is reversible and symplectic on the constrained phase space when the constraint equations are solved exactly on the local branch.
2. When to use
Use a fixed step with positive constant masses, a smooth autonomous force , and smooth independent constraints . Set with one row per constraint. Start with both and to the requested solve tolerance. The reference accepts diagonal masses, ordinary Cartesian velocities, and dense solves for the constraint multipliers. Repeat each particle mass for all of its Cartesian coordinates.
3. When not to use (and what to use instead)
| Situation | Use instead |
|---|---|
| Unconstrained conservative mechanics | stormer-verlet for resolved position-dependent forces or gauss-legendre-4 for canonical nonseparable systems. |
| Constraints involving velocities independently of position, dependent constraint rows, or configuration-dependent masses | Use a constrained or DAE formulation designed for that system. Find an independent constraint set before applying this RATTLE form. |
| Langevin or velocity-dependent forces | Use a constrained splitting that includes the thermostat or velocity term. For an unconstrained nonstiff ODE, use dormand-prince-rk45. |
| Fast unconstrained modes give instability | Reduce the step to resolve them or reconsider the formulation. The constraint solve removes only motion normal to the prescribed manifold. |
4. Algorithm
Let be signed and the diagonal mass matrix. Both multiplier signs below are defined by the displayed equations.
- Make the first Verlet half kick and the free drift .
- Starting from , solve with . A Newton update solves , then subtracts from . Hold the old constraint directions fixed in the drift correction. The same displacement changes the half-step velocity by .
- Form the second half kick . Solve and set .
- Return only after both constraint residuals meet the tolerance. With no constraints the two Verlet kicks and drift are sufficient, as in
stormer-verlet.
The local root tends to the starting configuration as tends to zero. A projection using the new normal in the drift may satisfy the position equation and still change the integrator and its geometric properties.
5. Parameters
| Parameter | How to choose it |
|---|---|
| Signed fixed step | Resolve the fastest motion in the remaining degrees of freedom. Halve and compare at the same physical time. A zero step returns the input. |
| Constraint tolerance | The reference uses absolute infinity-norm tolerance 1e-13 for scaled position and tangency residuals. Scale each constraint by a fixed characteristic magnitude when units differ. Tighten the solve and check whether the trajectory and energy measurements change. |
| Newton limit | The reference permits 20 updates. Report a failure on a singular matrix or unconverged residual. Use a smaller step or fix the constraint geometry before restarting. |
7. Verification
Implement step(q, v, h, mass, force, constraints, gradients) -> (q_next, v_next) in port_adapter.py. Each callback takes a coordinate vector and the gradient callback returns a sequence of rows. Run python <skill>/checks/check_port.py from the adapter directory and show its output. Other languages can use the formulas and fixed cases in checks/cases.json. The checker also measures second order, signed-step reversal, residuals, and the energy envelope of a long pendulum run.
On your problem, track and separately, compare at least two time steps, and compare the peak energy errors in early and late windows. The method usually has an oscillating energy error on smooth, well-resolved conservative trajectories. Quadratic-looking convergence or a small residual alone does not establish long-time energy behaviour.
8. Failure signatures
| Symptom | Likely cause |
|---|---|
| Distances stay fixed but velocities develop a normal component | The final velocity correction was omitted or used the old gradient. |
| Position Newton fails or jumps to a distant root | The free drift is too large, or constraint gradients are nearly dependent. |
| Forward–backward drift grows and energy error accumulates | Check convergence of both solves, consistent mass weighting, and the constraint directions used in the drift. |
| Residuals are tiny but the trajectory is wrong | Check the sign of the force and whether the step resolves the unconstrained dynamics. |
9. Files and commands
reference/rattle.py advances one signed step. uv run examples/pendulum.py exercises a Cartesian pendulum. uv run verify/check_cases.py checks the reference, three deliberately broken ports, and an infeasible drift. To regenerate fixtures, run uv run checks/make_cases.py; its output is the stored JSON.
10. Sources
- Andersen introduced the position and velocity corrections for the Verlet update. Andersen (1983)
- Leimkuhler and Skeel prove that the converged constrained map is symplectic (Sect. 4) and state that it is time reversible. Leimkuhler and Skeel (1994)