Release 0.16.1 Hamiltonian mechanics

Dynamical systems

Zymplectic is a portable, high-performance C/C++ platform for studying dynamical systems with an extensive collection of explicit symplectic partitioned Runge–Kutta and Runge–Kutta–Nyström methods.

Portable 200+ integrators 100+ example dynamical systems

In dedication of accuracy

Explicit symplectic integration

Introduction

A Hamiltonian describes a system through a single function that is often its total energy.

For a separable system, the Hamiltonian H is written as the sum of kinetic energy T, which depends on momentum p, and potential energy V, which depends on position q.

\[ H(q,p) = T(p) + V(q) \]

In plain language: the system’s state is split into a momentum part and a position part.

Hamilton’s equations connect those two coordinates. Momentum changes in response to the slope of the energy with respect to position; position changes in response to its slope with respect to momentum.

\[ \begin{aligned} \dot{p} &= -\frac{\partial H}{\partial q}, \\[4pt] \dot{q} &= \frac{\partial H}{\partial p}. \end{aligned} \]

A splitting method advances the state through a sequence of small substeps. At stage i, it first updates position and then momentum:

\[ \begin{aligned} q_i &= q_{i-1} + \tau c_i \frac{\partial T}{\partial p}\!\left(p_{i-1}\right), \\[6pt] p_i &= p_{i-1} - \tau d_i \frac{\partial V}{\partial q}\!\left(q_i\right). \end{aligned} \]

Here, τ is the time step; ci and di are splitting coefficients; and the number of coefficient pairs determines the number of stages. Their values determine the splitting method’s order and accuracy.

Unlike a general-purpose Runge-Kutta methods, a symplectic integrator preserves the geometry of phase space. The energy is generally not perfectly constant at every step; instead, the energy error tends to remain bounded and oscillatory over long integrations. This behavior is especially valuable in celestial mechanics, accelerator physics, molecular dynamics, and quantum chemistry.

Zymplectic energy error display Open original interface image
Relative energy error as a function of time for the Hénon-Heiles system, a double pendulum and a gyro wheel. The energy is conserved over long simulations.

Extended applications

The cleanest case is autonomous and separable, but related techniques can also treat systems whose kinetic or potential energy changes explicitly with time:

\[ H(q,p,t) = T(p,t) + V(q,t) \]

These are non-autonomous systems, so the Hamiltonian need not be conserved. More advanced formulations extend the same splitting to non-separable systems, where position and momentum cannot be isolated into independent terms:

\[ H(q,p,t) = f(p,q,t) \]

With care, the same computational patterns can also be useful for differential equations that are not governed by a Hamiltonian, although some symplectic guarantees may no longer apply.

The Zymplectic project

Zymplectic differs from broad differential-equation libraries such as GSL or JuliaDiffEq: it is intentionally focused on Hamiltonian systems and explicit symplectic integrators.

The application loads C/C++ source files containing Hamilton’s equations, compiles them, and runs the resulting model with the chosen method, visualisation, and numerical settings. It can present simulated objects, trajectories, energy surfaces, and error data without requiring users to learn a large application interface.

The downloadable package includes either MinGW GCC or Clang, so it can work without a separate IDE or compiler installation. The included MinGW are replacable with other and possibly newer builds of GCC or Clang.

Zymplectic's catalogue of numerical methods ranges from simple symplectic Euler and leapfrog methods to high-order symplectic partitioned Runge–Kutta and Runge–Kutta–Nyström schemes, but includes also customized construction of higher order methods by Yoshida's composition method as well as formally unpublished techniques.

Dynamical systems

The 100 dynamical systems included in the 0.16.1 release, not including advanced and constrained systems.

  1. 00henon-heiles
  2. 01simple pendulum
  3. 02pendulum on cart with spring
  4. 03two-pendulum cart
  5. 04two-body central-force
  6. 05two-body polar coordinates
  7. 06two-body on cylinder
  8. 07solar system
  9. 08N-body system jacobi
  10. 09three body stable
  11. 10rolling disk
  12. 11atwood machine
  13. 12swinging atwood
  14. 13horizontal atwood (variant 1)
  15. 14horizontal atwood (variant 2)
  16. 15double pendulum (variant 1)
  17. 16double pendulum (variant 2)
  18. 17double pendulum (variant 3)
  19. 18100 double pendulums
  20. 19100 double pendulums in spring
  21. 20double pendulum in spring
  22. 21double pendulum on cart with spring
  23. 22double pendulum variable length
  24. 23double pendulum flail
  25. 24double pendulum slider crank
  26. 25double pendulum interacting spheres
  27. 26driven double pendulum
  28. 27rotating double pendulum
  29. 28double spherical pendulum
  30. 29triple pendulum zero gravity
  31. 30N-pendulum
  32. 31N-pendulum nonautonomous
  33. 32N-spherical pendulum
  34. 33semicircle rocking pendulum
  35. 34crank-rocker extended
  36. 35gyro single spoke
  37. 36gyro single spoke SPC
  38. 37gyro wheel
  39. 38kapitza pendulum
  40. 39spherical pendulum
  41. 40spherical pendulum platform
  42. 41spherical pendulum SPC
  43. 42facault pendulum
  44. 43spring pendulum
  45. 44spring N-pendulum
  46. 45spring hanging chain
  47. 46spring coupled pendulums
  48. 47pendulum with spring
  49. 48pendulum with spring SPC
  50. 49pendulums hanging from springs
  51. 50double-compound pendulum
  52. 51pendulum wheel (variant 1)
  53. 52pendulum wheel (variant 2)
  54. 53bead pendulum
  55. 54bead on rotating wire
  56. 55beads on a rotating hoop
  57. 56bead in a swinging hoop with spring
  58. 57bead on suspended rope 2D
  59. 58bead on suspended rope 3D
  60. 59quadrupole mass spectrometer
  61. 60soft boundary billiards
  62. 61gyroscope frame
  63. 62black hole kerr metric (variant 1)
  64. 63black hole kerr metric (variant 2)
  65. 64black hole kerr de sitter
  66. 65vortex motion
  67. 66wave
  68. 67wave grid
  69. 68schrodinger equation 1D
  70. 69schrodinger equation 2D
  71. 70schrodinger eigenstates 1D
  72. 71wave pendulum
  73. 72maxwell-boltzmann distribution
  74. 73maxwells equations 2D
  75. 74magnetic dipole stoermer problem
  76. 75kinetic mobile
  77. 76cycloidal pendulum
  78. 77brachistochrone
  79. 78wilberforce pendulum
  80. 79sphere on radial surface
  81. 80sliding box
  82. 81rail pendulum
  83. 82rail spring
  84. 83spherical atwood (variant 1)
  85. 84spherical atwood (variant 2)
  86. 85quaternion rigid bodies
  87. 86quaternion rigid body on spring
  88. 87quaternion L-rod
  89. 88quaternion reaction wheels
  90. 89gravitational wedge billiard
  91. 90elastic boundary (variant 1)
  92. 91elastic boundary (variant 2)
  93. 92tesseract
  94. 93rolling on curve
  95. 94rolling on flat plane
  96. 95galilean cannon
  97. 96oscillating spring platform
  98. 97three body fixed perimeter
  99. 98rolling sphere
  100. 99rolling ellipsoid

Showcases

  1. 01 The two-body problem
  2. 02 Trajectories of Hamiltonian systems
  3. 03 Integrator: autonomous and separable
  4. 04 The quadrupole mass spectrometer
  5. 05 The Kapitza pendulum
  6. 06 The double pendulum
  7. 07 Benchmark: fifth-order integrators
  8. 08 Soft-boundary billiards
  9. 09 Spherical pendulum: Euler angles
  10. 10 Spherical pendulum: stereographic projection

Showcase list last updated 2023.03.27

Ease of use

A model needs Hamilton’s equations, initial conditions, and a short initialisation function. Macro-augmented C++ keeps comprehensive systems compact while retaining native performance.

Example Minimal Hénon–Heiles model
#include "math.h"

const double lambda = 1.0;
double _q_init[] = {0.3, 0.0}; // position
double _p_init[] = {0.0, 0.4}; // momentum

double energy_H(Arg) {
    return lambda*q2*(q1@2 - q2@2/3.0)
         + 0.5*(q1@2 + q2@2 + p1@2 + p2@2);
}

void dH(Arg) {
    dq1 = q1 + lambda*2*q1*q2;
    dq2 = q2 + lambda*(q1@2 - q2@2);
    dp1 = p1;
    dp2 = p2;
}

void main() {
    Z.H(energy_H, dH, 0);
}

Objects can be paired with one another or assigned to separate kinetic and potential energies, making larger physical systems possible with relatively little model code. Or multiple objects can be applied to the same system:

Example extended Added custom graphics
...

double _q_init[] = {0.3, 0.0,  0.2, 0.0,  0.1, 0.0};
double _p_init[] = {0.0, 0.4,  0.0, 0.3,  0.0, 0.2};

void DrawFunc() {
	for (int i = 0; i < 3; ++i)
		draw.sphere(obj_q[i][0], obj_q[i][1], 0, 0.1); 
}

void IterFunc() {
	// print output?
}

void main() {
	Z.OnDraw = DrawFunc; //graphics event
	Z.OnIter = IterFunc; //iteration event
    Z.H(energy_H, dH, 0); //multiple objects
    Z.H(energy_H, dH, 1);
    Z.H(energy_H, dH, 2);	
}

While some native graphics are supported without code, custom graphics support a wide range of practical graphical functions that work for both 2D and 3D display.

Zymplectic interface showing a three-dimensional simulation and numerical controls Open original interface image
The interface combines a control panel GUI, a graphics display, and an output console (not shown).

Further reading

  1. Geometric Numerical Integration: Structure-Preserving Algorithms for Ordinary Differential Equations Hairer, E., Lubich, C., & Wanner, G. (2002). Springer Series in Computational Mathematics, Vol. 31. Springer. DOI
  2. 3D time-dependent wave-packet approach in hyperspherical coordinates for the H + O₂ reaction on the CHIPR and DMBE IV potential energy surfaces Sun, Z., Yang, W., & Zhang, D. H. (2012). Physical Chemistry Chemical Physics, 14, 1827–1835. DOI
  3. Composition methods in the presence of small parameters McLachlan, R. I. (1995). BIT Numerical Mathematics, 35(2), 258–268. DOI
  4. Runge–Kutta methods for quadratic ordinary differential equations Iserles, A., Ramaswami, G., & Sofroniou, M. (1998). BIT Numerical Mathematics, 38, 315–346. DOI
  5. Practical splitting methods for the adaptive integration of nonlinear evolution equations. Part I: Construction of optimized schemes and pairs of schemes Auzinger, W., Hofstätter, H., Ketcheson, D., & Koch, O. (2017). BIT Numerical Mathematics, 57(1), 55–74. DOI
  6. High precision symplectic integrators for the Solar System Farrés, A., Laskar, J., Blanes, S., Casas, F., Makazaga, J., & Murua, A. (2013). Celestial Mechanics and Dynamical Astronomy, 116(2), 141–174. DOI
  7. Fourth-order symplectic integration Forest, E., & Ruth, R. D. (1990). Physica D: Nonlinear Phenomena, 43(1), 105–117. DOI
  8. Construction of higher order symplectic integrators Yoshida, H. (1990). Physics Letters A, 150(5–7), 262–268. DOI
  9. Fractal decomposition of exponential operators with applications to many-body theories and Monte Carlo simulations Suzuki, M. (1990). Physics Letters A, 146(6), 319–323. DOI
  10. Canonical Runge–Kutta–Nyström methods of orders five and six Okunbor, D. I., & Skeel, R. D. (1994). Journal of Computational and Applied Mathematics, 51(3), 375–382. DOI
  11. Runge–Kutta–Nyström symplectic splitting methods of order 8 Blanes, S., Casas, F., & Escorihuela-Tomàs, A. (2022). Applied Numerical Mathematics, 182, 14–27. DOI
  12. Symplectic methods for the numerical integration of the Schrödinger equation Monovasilis, T., & Simos, T. E. (2007). Computational Materials Science, 38(3), 526–532. DOI
  13. Practical splitting methods for the adaptive integration of nonlinear evolution equations Auzinger, W., Hofstätter, H., Ketcheson, D. I., & Koch, O. (2019). Computer Physics Communications, 234, 106–115. DOI
  14. High-order symplectic integration: an assessment Schlier, Ch., & Seiter, A. (2000). Computer Physics Communications, 130(1–2), 176–189. DOI
  15. Symplectic analytically integrable decomposition algorithms: Classification, derivation, and application to molecular dynamics, quantum and celestial mechanics simulations Omelyan, I. P., Mryglod, I. M., & Folk, R. (2003). Computer Physics Communications, 151(3), 272–314. DOI
  16. Practical symplectic partitioned Runge–Kutta and Runge–Kutta–Nyström methods Blanes, S., & Moan, P. C. (2002). Journal of Computational and Applied Mathematics, 142(2), 313–330. DOI
  17. Derivation of symmetric composition constants for symmetric integrators Sofroniou, M., & Spaletta, G. (2005). Optimization Methods and Software, 20(4–5), 597–613. DOI
  18. Optimized Fifth Order Symplectic Integrators for Orbital Problems Tselios, K., & Simos, T. E. (2013). Revista Mexicana de Astronomía y Astrofísica, 49(1), 11–24.
  19. The accuracy of symplectic integrators McLachlan, R. I., & Atela, P. (1992). Nonlinearity, 5(2), 541–562. DOI
  20. Composition constants for raising the orders of unconventional schemes for ordinary differential equations Kahan, W., & Li, R.-C. (1997). Mathematics of Computation, 66(219), 1089–1099. DOI
  21. Optimized Verlet-like algorithms for molecular dynamics simulations Omelyan, I. P., Mryglod, I. M., & Folk, R. (2002). Physical Review E, 65(5), 056706. DOI
  22. A canonical integration technique Ruth, R. D. (1983). IEEE Transactions on Nuclear Science, 30(4), 2669–2671. DOI
  23. Variable steps for symplectic integrators Calvo, M. P., & Sanz-Serna, J. M. (1993). SIAM Journal on Scientific and Statistical Computing, 14(4), 936–952. DOI
  24. On the numerical integration of ordinary differential equations by symmetric composition methods McLachlan, R. I. (1995). SIAM Journal on Scientific Computing, 16(1), 151–168. DOI
  25. Fifth Order Runge–Kutta–Nyström Methods with Complex Coefficients Gürkan, M. A. (2012). arXiv preprint arXiv:1203.3279. DOI
  26. Selection and improvement of product formulae for best performance of quantum simulation Morales, M. E. S., Costa, P. C. S., Pantaleoni, G., Burgarth, D. K., Sanders, Y. R., & Berry, D. W. (2022). arXiv preprint arXiv:2210.15817. DOI
  27. A tenth order symplectic Runge–Kutta–Nyström method Tsitouras, Ch. (1999). Celestial Mechanics and Dynamical Astronomy, 74(3), 223–230. DOI
  28. High order symplectic integrators for perturbed Hamiltonian systems Laskar, J., & Robutel, P. (2001). Celestial Mechanics and Dynamical Astronomy, 80(1–2), 39–62. DOI
  29. Explicit methods in extended phase space for inseparable Hamiltonian problems Pihajoki, P. (2015). Celestial Mechanics and Dynamical Astronomy, 121(3), 211–231. DOI
  30. Explicit symplectic approximation of nonseparable Hamiltonians: Algorithm and long time performance Tao, M. (2016). Physical Review E, 94(4), 043303. DOI
  31. Higher order explicit symmetric integrators for inseparable forms of coordinates and momenta Liu, L., Wu, X., Huang, G., & Liu, F. (2016). Monthly Notices of the Royal Astronomical Society, 459(2), 1968–1976. DOI
  32. Semiexplicit symplectic integrators for non-separable Hamiltonian systems Jayawardana, B., & Ohsawa, T. (2023). Mathematics of Computation, 92(339), 251–281. DOI
  33. Preservation of quadratic invariants by semiexplicit symplectic integrators for nonseparable Hamiltonian systems Ohsawa, T. (2023). SIAM Journal on Numerical Analysis, 61(3), 1293–1315. DOI
  34. Runge–Kutta methods determined from extended phase space methods for Hamiltonian systems McLachlan, R. I. (2025). Numerical Algorithms, 100(3), 983–993. DOI
  35. Pseudo-symplectic Runge–Kutta methods Aubry, A., & Chartier, P. (1998). BIT Numerical Mathematics, 38(3), 439–461. DOI
  36. Eight-stage pseudo-symplectic Runge–Kutta methods of order (4, 8) Stepanov, M. (2023). arXiv preprint arXiv:2301.09335. DOI
  37. Order conditions for nonlinearly partitioned Runge–Kutta methods Tran, B. K., Southworth, B. S., & Buvoli, T. (2025). Electronic Transactions on Numerical Analysis, 63, 171–198. DOI
  38. Efficient fourth order symplectic integrators for near-harmonic separable Hamiltonian systems Nielsen, K. M. E. (2015). arXiv preprint arXiv:1501.04345. DOI