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.

2. Time integration: Euler, Velocity Verlet, and symplectic shadow Hamiltonians

School of Engineering and Digital Sciences, Nazarbayev University

Track: core  ·  Prerequisites: Chapter 1, ODE integration (engnumeric)

This chapter builds and verifies the core algorithms for time integration: euler, velocity verlet, and symplectic shadow hamiltonians in plain Python and NumPy, checking every result against an exact statistical-mechanics limit or published benchmark.

2.1 Physical principles and governing equations

The Velocity Verlet integrator splits Hamiltonian evolution symmetrically into half-kick, drift, force evaluation, and half-kick:

v ⁣(t+Δt2)=v(t)+Δt2f(t),r(t+Δt)=r(t)+Δt v ⁣(t+Δt2),v(t+Δt)=v ⁣(t+Δt2)+Δt2f(t+Δt).(2.1)\mathbf{v}\!\left(t + \tfrac{\Delta t}{2}\right) = \mathbf{v}(t) + \frac{\Delta t}{2}\mathbf{f}(t), \qquad \mathbf{r}(t + \Delta t) = \mathbf{r}(t) + \Delta t\,\mathbf{v}\!\left(t + \tfrac{\Delta t}{2}\right), \qquad \mathbf{v}(t + \Delta t) = \mathbf{v}\!\left(t + \tfrac{\Delta t}{2}\right) + \frac{\Delta t}{2}\mathbf{f}(t + \Delta t). \tag{2.1}

Because Velocity Verlet is symplectic and time-reversible, it conserves a nearby shadow Hamiltonian H~=H+O(Δt2)\tilde{H} = H + O(\Delta t^2) with zero secular energy drift over long trajectories, whereas explicit Euler spirals outward exponentially.

2.2 Inside the algorithm

2.3 Checks

Velocity Verlet energy-fluctuation scaling slope = 2.05 (expected 2.00)
Time-reversal position error after 50 steps = 8.88e-16
<Figure size 1120x430 with 2 Axes>

Figure 2.1. (a) Primary physical or dynamical observable computed from scratch in engsim. (b) Quantitative verification against the analytical or benchmark reference.

2.4 What to trust

  • Numerical predictions are verified to the stated tolerances against exact analytical limits (engsim.reference).

  • Finite-size effects (NN, periodic image interactions) and timestep truncation (O(Δt2)O(\Delta t^2)) should always be checked before comparing against bulk experimental data.

Summary

  • The algorithm is implemented transparently in pure NumPy without hidden black-box routines.

  • All core physical invariants (conservation laws, ensemble variance, or scaling exponents) are verified quantitatively in code.

Exercises

  1. Momentum conservation: Verify that total linear momentum ∑ivi\sum_i \mathbf{v}_i stays zero to <10−13<10^{-13} over 200 Velocity Verlet steps.

  2. Stability threshold: Find the maximum stable timestep Δtmax⁡\Delta t_{\max} for a 1D harmonic oscillator (ω=1\omega = 1) under Velocity Verlet (exact theoretical limit Δtmax⁡=2/ω=2.0\Delta t_{\max} = 2/\omega = 2.0).

  3. Shadow energy: Verify that E~=12v2+12x2(1−Δt2/4)\tilde{E} = \frac{1}{2}v^2 + \frac{1}{2}x^2(1 - \Delta t^2/4) is conserved to O(Δt4)O(\Delta t^4) on the harmonic oscillator.

Worked solutions are provided in 02_solutions.ipynb.

Suggested references

  • D. Frenkel and B. Smit, Understanding Molecular Simulation (3rd ed., Academic Press, 2023).

  • M. P. Allen and D. J. Tildesley, Computer Simulation of Liquids (2nd ed., Oxford University Press, 2017).