Overview of the leapfrog method
The Leapfrog Method is a type of time integration method for numerically solving time-evolving equations of motion (especially Hamiltonian dynamical systems), especially often used to solve Newton’s equation of motion (F=ma), and often used in molecular dynamics simulations and celestial mechanics. It is often used in molecular dynamics simulations and celestial mechanics.
The features of the leapfrog method include the following.
- Sequential numerical integration method: the current position \(x(t)\) and velocity \(v(t)\) are alternately updated.
- Time Reversibility: time can be advanced backwards in time to return to the original trajectory → excellent energy conservation.
- 2nd-order accuracy: high accuracy in small time increments with an error of \(O(\Delta t^2)\).
Symplectic integral method: numerically faithful reproduction of the motion of the Hamiltonian system, with excellent energy conservation over long timescales.
The algorithm for the leapfrog method is as follows, where the position \(x(t)\) and velocity \(v(t)\) are calculated with a half-step shift.
- Half step update of velocity: \[v(t+\frac{\Delta t}{2})=v(t)+\frac{\Delta t}{2}\alpha (t)\]
- Update position: \[x(t+\Delta t)=x(t)+\Delta t\cdot v(t+\frac{\Delta t}{2})\]
- Calculation of acceleration (based on the force\(F\)):\[\alpha(t+\Delta t)=\frac{F(t+\Delta t)}{m}\]
- Late step update of velocity:\[v(t+\Delta t)=v(t+\frac{\Delta t}{2})+\frac{\Delta t}{2}\alpha(t+\Delta t)\]
The advantages and disadvantages of the leapfrog method are as follows.
- Advantages.
- High energy conservation (symplectic nature).
- Time-reversal symmetry and robustness to long simulations
- Low computational cost (alternating velocity and position)
- Disadvantages.
- Difficult to apply in non-commutative dynamical systems
- Accuracy degrades with large time increments
- Output processing is a little cumbersome because velocity and position are not obtained at the same time
The leapfrog method is a numerical solution method for the equations of motion, often used in simulations where energy conservation is particularly important, and is applied to molecular dynamics, astrodynamics and plasma simulations, as energy is unlikely to diverge even in long calculations. It is also relatively easy to implement in Python, and the solution can be obtained with good accuracy by alternately updating the velocity and position.
implementation example
1. simulation of single oscillations (spring motion): single oscillations according to Hooke’s law \(F=-kx\) of the spring constant \(k\) are calculated numerically using the leapfrog method.
import numpy as np
import matplotlib.pyplot as plt
# Parameter setting
m = 1.0 # mass
k = 1.0 # spring constant
x = 1.0 # initial position
v = 0.0 # initial velocity
dt = 0.01 # time step width
t_max = 10 # Simulation time
# record list
times = np.arange(0, t_max, dt)
positions = []
velocities = []
# initial acceleration
a = -k * x / m
v_half = v + 0.5 * dt * a # Half-step speed update
# Simulation using the leapfrog method
for t in times:
x += dt * v_half # position update
a = -k * x / m # Accelerated update
v_half += dt * a # Speed Update
# record
positions.append(x)
velocities.append(v_half)
# Plotting the results
plt.figure(figsize=(8, 4))
plt.plot(times, positions, label="Position")
plt.plot(times, velocities, label="Velocity", linestyle="dashed")
plt.xlabel("Time")
plt.ylabel("Value")
plt.legend()
plt.title("Leapfrog Method Simulation of Simple Harmonic Motion")
plt.show()
- Point.
- The leapfrog method updates the velocity \(v\) by shifting it by half a step.
- High energy conservation and low numerical error.
2. astronomical simulation (planetary orbit): simulates the motion of a planet around a central star in a two-dimensional plane.
import numpy as np
import matplotlib.pyplot as plt
# Parameter setting (unit system adjusted accordingly)
G = 1.0 # gravitational constant (G)
M = 1.0 # Mass of central body
dt = 0.01 # clock tick
t_max = 10 # Simulation time
# Initial conditions (approximation of circular motion)
r = 1.0
v_init = np.sqrt(G * M / r) # Initial velocity of circular orbit
x, y = r, 0.0
vx, vy = 0.0, v_init
# record list
times = np.arange(0, t_max, dt)
positions_x, positions_y = [], []
# Half-step speed update
r_vec = np.array([x, y])
v_vec = np.array([vx, vy])
a_vec = -G * M * r_vec / np.linalg.norm(r_vec)**3
v_half = v_vec + 0.5 * dt * a_vec
# Calculated using the leapfrog method.
for t in times:
r_vec += dt * v_half # position update
a_vec = -G * M * r_vec / np.linalg.norm(r_vec)**3 # ACU
v_half += dt * a_vec # Velocity update
# record
positions_x.append(r_vec[0])
positions_y.append(r_vec[1])
# Plotting the results
plt.figure(figsize=(6, 6))
plt.plot(positions_x, positions_y, label="Orbit")
plt.scatter([0], [0], color="red", label="Central Star") # centre star
plt.xlabel("x")
plt.ylabel("y")
plt.legend()
plt.title("Planetary Orbit Simulation using Leapfrog Method")
plt.axis("equal")
plt.show()
- Point.
- Uses Newton’s law of universal gravitation \(F=\frac{GMm}{r^2}\).
- High energy conservation even in long simulations.
Application examples
The leapfrog method is widely used in the following fields as a numerical integration method with excellent energy conservation.
1. astronomical simulations (N-body problem)
- APPLICATIONS:
- Calculation of long-term orbits of planets and stars
- Simulation of galaxy collisions and star cluster formation
- Prediction of asteroid orbits
- Specific examples: the Leapfrog method is used by NASA and ESA (European Space Agency) space missions to calculate spacecraft trajectories, for example, in the simulation of the trajectory of Halley’s comet and the trajectory analysis of the Jupiter orbiter Juno.
2. molecular dynamics simulation (Molecular Dynamics, MD)
- Application examples:
- Dynamic structure analysis of proteins
- Materials science (simulation of nanomaterials, polymers)
- Biophysics (drug design, analysis of enzyme behaviour)
- Specific examples: the leapfrog method is used together with the Velocity Verlet method in the molecular dynamics simulation software GROMACS and LAMMPS. For example, numerical integration methods, including the leapfrog method, are also used in the analysis of spike proteins of new coronaviruses.
3. plasma simulation (PIC method, Particle-in-Cell)
- Application examples:
- Magnetic confinement fusion (tokamak devices, laser fusion)
- Space plasma (simulation of solar wind and magnetosphere)
- Semiconductor processes (analysis of plasma etching)
- Specific examples:
- Simulation of plasma behaviour in TER (International Thermonuclear Experimental Reactor)
- Analysis of the interaction between the Earth’s magnetosphere and the solar wind
- Analysis of the behaviour of the ion engines of the space probe Hayabusa-2
4. game engines and CG physics simulation
- Application examples:
- Rigid body and fluid simulation in game engines (Unity, Unreal Engine)
- CG movies (fluid animation of smoke, flames, water, etc.)
- Collision detection and character movement simulation
- Specific examples:
- Physics simulation for the films Avatar and Interstellar
- Real-time rigid-body and fluid calculations using Unity and Houdini
5. robotics and control systems
- Application examples:
- Bipedal robots (balance control)
- Flight stabilisation of drones
- Trajectory optimisation of industrial robots
- Specific examples:
- Motion simulation of Boston Dynamics’ Atlas and Spot robots.
- Simulation of NASA’s Mars Exploration Rover
reference book
Reference books related to the leapfrog method
This section describes reference books on the leapfrog method.
Fundamentals of Numerical Analysis and Numerical Integration
Mechanics and simulation (celestial mechanics, molecular dynamics)
Classical Mechanics.
By Herbert Goldstein.
A classic book for learning the theoretical foundations of mechanics.
Explains how the symplectic integral method (including the leapfrog method) applies to physical simulations.
‘Astrophysics With a PC: An Introduction to Computational Astrophysics’
‘Understanding Molecular Simulation’ by.
by Daan Frenkel and Berend Smit.
The bible of molecular dynamics simulation.
It describes in detail calculation methods using the Velocity Verlet and Leapfrog methods.
Molecular Dynamics Simulation: Elementary Methods.
by J. M. Haile.
An introduction to molecular dynamics, with detailed examples of algorithms and implementations of the leapfrog method.
Plasma Physics and Numerical Simulation
‘Plasma Physics via Computer Simulation’
By C.K. Birdsall and A.B. Langdon
Fundamentals of the Particle-in-Cell (PIC) method in plasma simulation.
A numerical solution of plasma particle motion using the leapfrog method is presented.
The Fluid-Kinetic Particle-in-Cell Solver for Plasma Simulations.
By Toshiki Tajima.
Comprehensive description of numerical analysis methods for plasma physics.
It contains many concrete examples of electromagnetic field simulations using the leapfrog method.
Game physics and robot control
Real-Time Collision Detection.
By Christer Ericson
Describes simulation methods for rigid bodies and fluids in game engines.
Learn how to use numerical integration methods (such as the leapfrog method) in physics engines.
Physics-Based Animation.
By Kenny Erleben.
Describes techniques for creating physically realistic movement in games and CG animation.
Includes many concrete examples of physics simulations using the Leapfrog Method.
‘Robot Dynamics and Control’ by.
By Mark W. Spong, Seth Hutchinson and M. Vidyasagar
Describes a method for numerically solving the equations of motion of a robot.
It teaches the simulation of robot dynamics by applying the leapfrog method.
コメント