Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Part 3: Symplectic Integration - Geometry Over Accuracy

Module 3: ODE Methods & Conservation | ASTR 596

San Diego State University

Learning Outcomes

By the end of this section, you will be able to:


The Fundamental Insight

Instead of minimizing local truncation error, symplectic integrators preserve geometric properties:

  1. Phase space volume (Liouville’s theorem)

  2. Time reversibility

  3. Bounded energy error (oscillates but doesn’t grow)

  4. Poincaré invariants (action integrals)

The profound trade-off: symplectic methods may be less accurate locally but maintain qualitative correctness globally.

Hamiltonian Mechanics Refresher

Before diving into symplectic integration, let’s recall the Hamiltonian formulation of mechanics. For a system with positions qq and momenta pp, the Hamiltonian H(q,p,t)H(q,p,t) represents total energy:

H(q,p)=T(p)+V(q)H(q,p) = T(p) + V(q)

where T(p)T(p) is kinetic energy and V(q)V(q) is potential energy.

For a particle of mass mm in potential V(q)V(q):

H=p22m+V(q)H = \frac{p^2}{2m} + V(q)

Hamilton’s equations govern the evolution:

dqdt=Hp,dpdt=Hq\boxed{\frac{dq}{dt} = \frac{\partial H}{\partial p}, \quad \frac{dp}{dt} = -\frac{\partial H}{\partial q}}

These equations have remarkable properties:

The Phase Space Perspective

In phase space, each point (q,p)(q,p) represents a complete state of the system. Trajectories follow contours of constant energy H=EH = E.

Phase space structure of Hamiltonian systems. (Left) Harmonic oscillator: closed orbits on energy surfaces. (Middle) Pendulum: separatrix divides oscillation from rotation. (Right) Liouville’s theorem: phase space volume is preserved under Hamiltonian flow—areas deform but don’t change size. This geometric structure is what symplectic integrators preserve, ensuring long-term stability.

Figure 1:Phase space structure of Hamiltonian systems. (Left) Harmonic oscillator: closed orbits on energy surfaces. (Middle) Pendulum: separatrix divides oscillation from rotation. (Right) Liouville’s theorem: phase space volume is preserved under Hamiltonian flow—areas deform but don’t change size. This geometric structure is what symplectic integrators preserve, ensuring long-term stability.

Liouville’s Theorem

Liouville’s theorem states that phase space volume is preserved under Hamiltonian flow. Mathematically, for a volume element dV=dqdpdV = dq\,dp:

d(dV)dt=0\frac{d(dV)}{dt} = 0

This is equivalent to saying the flow is incompressible. Standard numerical methods violate this theorem! They artificially compress or expand phase space, leading to systematic errors.

The Leapfrog/Verlet Method

The leapfrog method (also called Verlet or Störmer-Verlet) staggers position and velocity updates to preserve symplectic structure.

The Algorithm

For a Hamiltonian H(q,p)=T(p)+V(q)H(q,p) = T(p) + V(q) where T(p)=p2/(2m)T(p) = p^2/(2m):

Algorithm: Leapfrog IntegrationInput: qn,pn,h,force function F(q)=V(q)Step 1 (kick):pn+1/2=pn+h2F(qn)Step 2 (drift):qn+1=qn+hmpn+1/2Step 3 (kick):pn+1=pn+1/2+h2F(qn+1)Output: qn+1,pn+1\boxed{ \begin{align} \text{Algorithm: Leapfrog Integration} \\ \hline &\text{Input: } q_n, p_n, h, \text{force function } F(q) = -\nabla V(q) \\ &\text{Step 1 (kick):} \quad p_{n+1/2} = p_n + \frac{h}{2}F(q_n) \\ &\text{Step 2 (drift):} \quad q_{n+1} = q_n + \frac{h}{m}p_{n+1/2} \\ &\text{Step 3 (kick):} \quad p_{n+1} = p_{n+1/2} + \frac{h}{2}F(q_{n+1}) \\ &\text{Output: } q_{n+1}, p_{n+1} \end{align} }

Why “Leapfrog”?

Positions and momenta “leapfrog” over each other in time:

Time:     t₀    t₁/₂    t₁    t₃/₂    t₂
          |      |      |      |      |
Position: q₀            q₁            q₂
Momentum:       p₁/₂          p₃/₂

This staggering is key to symplecticity!

Implementation Tips for Your N-body Project

Proof of Symplecticity

A transformation is symplectic if it preserves the symplectic 2-form. We’ll prove leapfrog is symplectic by showing each sub-step preserves the symplectic structure.

Step 1: Analyze Each Sub-step

The leapfrog map can be decomposed into three shear transformations:

  1. First kick: (q,p)(q,p+h2F(q))(q,p) \mapsto (q, p + \frac{h}{2}F(q))

  2. Drift: (q,p)(q+hmp,p)(q,p) \mapsto (q + \frac{h}{m}p, p)

  3. Second kick: (q,p)(q,p+h2F(q))(q,p) \mapsto (q, p + \frac{h}{2}F(q))

Step 2: Show Each Shear is Symplectic

For the momentum kick (q,p)(q,ph2V(q))(q,p) \mapsto (q, p - \frac{h}{2}\nabla V(q)):

The Jacobian is:

Jkick=(I0h22VI)J_{\text{kick}} = \begin{pmatrix} I & 0 \\ -\frac{h}{2}\nabla^2 V & I \end{pmatrix}

Verify the symplectic condition:

JTΩJ=(Ih2(2V)T0I)(0II0)(I0h22VI)J^T \Omega J = \begin{pmatrix} I & -\frac{h}{2}(\nabla^2 V)^T \\ 0 & I \end{pmatrix} \begin{pmatrix} 0 & I \\ -I & 0 \end{pmatrix} \begin{pmatrix} I & 0 \\ -\frac{h}{2}\nabla^2 V & I \end{pmatrix}
=(0II0)=Ω= \begin{pmatrix} 0 & I \\ -I & 0 \end{pmatrix} = \Omega \quad \checkmark

Similarly for the drift step.

Step 3: Composition Preserves Symplecticity

Since the composition of symplectic maps is symplectic:

Jtotal=JkickJdriftJkickJ_{\text{total}} = J_{\text{kick}} \cdot J_{\text{drift}} \cdot J_{\text{kick}}

is symplectic. Therefore, leapfrog preserves phase space structure exactly!

Volume Preservation

The determinant of each Jacobian is 1:

det(J)=1\det(J) = 1

Phase space volume is exactly preserved, satisfying Liouville’s theorem.

The Modified Hamiltonian

Leapfrog doesn’t conserve the original Hamiltonian HH exactly. Instead, it exactly conserves a modified Hamiltonian:

H~=H+h2H2+h4H4+\tilde{H} = H + h^2 H_2 + h^4 H_4 + \ldots

The correction terms can be computed using backward error analysis. For the harmonic oscillator with H=12(p2+ω2q2)H = \frac{1}{2}(p^2 + \omega^2 q^2):

H2=ω224{H,{H,H}}H_2 = \frac{\omega^2}{24}\{H, \{H, H\}\}

where {f,g}=fqgpfpgq\{f,g\} = \frac{\partial f}{\partial q}\frac{\partial g}{\partial p} - \frac{\partial f}{\partial p}\frac{\partial g}{\partial q} is the Poisson bracket.

The key insight: H~H=O(h2)\tilde{H} - H = O(h^2) is bounded! Energy oscillates within a band but never drifts away.

Energy behavior comparison. (Top) RK4 exhibits monotonic energy drift while Leapfrog energy oscillates within bounded envelope. (Bottom) Phase space trajectories: RK4 spirals outward, Leapfrog remains on a nearby invariant torus of the modified Hamiltonian. This demonstrates the fundamental advantage of symplectic methods—trading local accuracy for global stability.

Figure 2:Energy behavior comparison. (Top) RK4 exhibits monotonic energy drift while Leapfrog energy oscillates within bounded envelope. (Bottom) Phase space trajectories: RK4 spirals outward, Leapfrog remains on a nearby invariant torus of the modified Hamiltonian. This demonstrates the fundamental advantage of symplectic methods—trading local accuracy for global stability.

Higher-Order Symplectic Methods

Yoshida’s Fourth-Order Method

By composing leapfrog steps with carefully chosen timesteps, we can achieve higher-order accuracy while maintaining symplecticity. The coefficients come from solving order conditions to eliminate O(h3)O(h^3) errors.

The strange values involving 21/32^{1/3} arise from the algebraic constraints of maintaining symplecticity while achieving fourth-order accuracy:

w0=21/3221/3,w1=1221/3w_0 = -\frac{2^{1/3}}{2 - 2^{1/3}}, \quad w_1 = \frac{1}{2 - 2^{1/3}}

The algorithm combines leapfrog steps with timesteps cihc_i h where:

c1=c4=w1/2,c2=c3=(w0+w1)/2c_1 = c_4 = w_1/2, \quad c_2 = c_3 = (w_0 + w_1)/2

Forest-Ruth Method

An alternative fourth-order symplectic integrator with different stability properties. The choice between methods depends on the specific problem’s characteristics.

Performance Comparison: 1000-Year Integration

Testing on Earth’s orbit (eccentricity e=0.017e = 0.017, period = 365.25 days):

MethodOrderEnergy ErrorPhase ErrorStable?
Euler1+100%100 radiansNo
RK22+10%10 radiansNo
RK44+0.1%0.1 radiansNo
Leapfrog2±0.01% (bounded)0.01 radiansYes
Yoshida44±0.0001% (bounded)0.0001 radiansYes

Leapfrog with only second-order accuracy outperforms fourth-order RK4 for long-term stability!

When to Use Symplectic Methods

Problem TypeRequirementBest MethodReason
Solar system (Gyr)Long-term stabilitySymplecticBounded energy error
Satellite (days)Trajectory accuracyRK45 adaptiveShort duration
Galaxy mergerPhase space structureSymplecticPreserve invariants
Molecular dynamicsEnergy conservationSymplectic1015 timesteps
Dissipative systemInclude frictionRK4No Hamiltonian structure

Simple Example: Pendulum Dynamics

Let’s see symplectic integration in action with a nonlinear pendulum:

import numpy as np

def pendulum_leapfrog(theta0, omega0, g, L, h, n_steps):
    """
    Integrate pendulum with leapfrog
    Preserves energy for nonlinear oscillations
    """
    theta, omega = theta0, omega0
    energies = []
    
    for _ in range(n_steps):
        # Initial energy
        E = 0.5*L**2*omega**2 - g*L*np.cos(theta)
        energies.append(E)
        
        # Leapfrog update
        omega_half = omega - 0.5*h*(g/L)*np.sin(theta)
        theta_new = theta + h*omega_half
        omega_new = omega_half - 0.5*h*(g/L)*np.sin(theta_new)
        
        theta, omega = theta_new, omega_new
    
    return energies

The energy remains bounded even for large amplitude oscillations where linearization fails!


Bridge to Part 4: Stability Analysis

You’ve seen the profound difference between local accuracy and geometric preservation. Symplectic methods sacrifice pointwise precision for global stability, keeping simulations physically meaningful over cosmic timescales.

But choosing the right integrator is only part of the challenge. We also need to understand when methods become unstable, how to diagnose problems, and what limits our timestep choices. In Part 4, we’ll analyze stability regions to predict when methods explode and understand the special challenges of stiff equations.

Next: Part 4 - Stability Analysis