Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
eb64a06
Initial symplectic integrator
JacobHass8 Jun 20, 2026
62c80b7
Generalized to floats
JacobHass8 Jun 21, 2026
45ebaff
Added driver function
JacobHass8 Jun 21, 2026
34d3cd8
Added error handling and default arguments
JacobHass8 Jun 22, 2026
098ab7d
Initial testing
JacobHass8 Jun 22, 2026
fd343b7
Added SHO test
JacobHass8 Jun 23, 2026
63eac98
Switched to map functionality
JacobHass8 Jun 23, 2026
a3a916f
Added documentation
JacobHass8 Jun 25, 2026
1281885
Fixed typo
JacobHass8 Jun 25, 2026
5e7705b
Updated docs and max function
JacobHass8 Jun 26, 2026
e31880b
Changed functions to only accept vectors
JacobHass8 Jun 26, 2026
645aa1a
Completely eliminated valarrays
JacobHass8 Jun 27, 2026
d56a8a4
Merge branch 'boostorg:develop' into symplectic-integrators
JacobHass8 Jul 5, 2026
cdd64cf
Added a couple more tests
JacobHass8 Jul 5, 2026
8526f33
Merge branch 'symplectic-integrators' of github.com:JacobHass8/math i…
JacobHass8 Jul 5, 2026
290e326
Changed function namespaces
JacobHass8 Jul 5, 2026
bb09041
Added SRKN from paper
JacobHass8 Jul 6, 2026
e6d67b0
Added simple pendulum test
JacobHass8 Jul 6, 2026
bc972a6
Changed template to RandomAccessContainer
JacobHass8 Jul 7, 2026
40eea88
Added singleton support
JacobHass8 Jul 12, 2026
bba6241
Added higher order method
JacobHass8 Jul 12, 2026
89ef4c0
Added higher order method (previous commit was wrong file)
JacobHass8 Jul 12, 2026
7ab8540
Added order 11 tests
JacobHass8 Jul 12, 2026
f304b0a
Fixed hh test derivatives
JacobHass8 Jul 12, 2026
ab543eb
Fixed void_t bug
JacobHass8 Jul 14, 2026
e9e3342
Added float and long double tests
JacobHass8 Jul 14, 2026
92b7ac1
Updated documentation
JacobHass8 Jul 15, 2026
fc772a4
Added multiprecision support
JacobHass8 Jul 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added doc/equations/harmonic_oscillator.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions doc/equations/harmonic_oscillator.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions doc/html/quadrature.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
</dl></dd>
<dt><span class="section"><a href="math_toolkit/fourier_integrals.html">Fourier Integrals</a></span></dt>
<dt><span class="section"><a href="math_toolkit/naive_monte_carlo.html">Naive Monte Carlo Integration</a></span></dt>
<dt><span class="section"><a href="math_toolkit/symplectic.html">Symplectic Integration</a></span></dt>
<dt><span class="section"><a href="math_toolkit/wavelet_transforms.html">Wavelet Transforms</a></span></dt>
<dt><span class="section"><a href="math_toolkit/diff.html">Numerical Differentiation</a></span></dt>
<dt><span class="section"><a href="math_toolkit/autodiff.html">Automatic Differentiation</a></span></dt>
Expand Down
1 change: 1 addition & 0 deletions doc/math.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,7 @@ and as a CD ISBN 0-9504833-2-X 978-0-9504833-2-0, Classification 519.2-dc22.
[include quadrature/double_exponential.qbk]
[include quadrature/ooura_fourier_integrals.qbk]
[include quadrature/naive_monte_carlo.qbk]
[include quadrature/symplectic.qbk]
[include quadrature/wavelet_transforms.qbk]
[include differentiation/numerical_differentiation.qbk]
[include differentiation/autodiff.qbk]
Expand Down
106 changes: 106 additions & 0 deletions doc/quadrature/symplectic.qbk
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
[/
Copyright (c) 2026 Jacob Hass
Use, modification and distribution are subject to the
Boost Software License, Version 1.0. (See accompanying file
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
]

[section:symplectic Symplectic Integration]

[heading Synopsis]

#include <boost/math/quadrature/symmetric.hpp>
namespace boost{ namespace math{ namespace quadrature {

template <class ReturnType, class RealType, class Func>
std::pair<std::vector<ReturnType>, std::vector<ReturnType> > integrate_hamiltonian(const ReturnType p0,
const ReturnType q0,
const RealType dt,
const unsigned steps,
Func dHdp,
Func dHdq,
std::string method = "Y6")

template <class ReturnType, class RealType, class Func, class ``__Policy``>
std::pair<std::vector<ReturnType>, std::vector<ReturnType> > integrate_hamiltonian(const ReturnType p0,
const ReturnType q0,
const RealType dt,
const unsigned steps,
Func dHdp,
Func dHdq,
std::string method,
const ``__Policy``& pol)

}}} // namespaces

[heading Description]

The functional `integrate_hamiltonian` calculates the phase space trajectory for a given Hamiltonian.
The trajectories are calculated using symplectic integration which preserves the energy of
a system. Even higher order traditional numerical integration algorithms will gain or lose
energy at long times. The functional implements the methods in [@https://www.sciencedirect.com/science/article/abs/pii/0375960190900923 Yoshida's]
landmark paper and methods by [@https://www.sciencedirect.com/science/article/pii/S0377042701004927?fr=RR-2&ref=pdf_download&rr=a1b51ec059e1fbec Blanes and Moan].
We assume that the Hamiltonian is separable so that it can be written as `H = T(p) + V(q)`.

We now give an example for a simple harmonic oscillator with the Hamiltonian
[/ $H = \frac{p^2}{2m} + \frac{1}{2}kx^2$ ]
[equation harmonic_oscillator]

For simplicity we will assume `k = m = 1`. Then the partial derivatives of the Hamiltonian
with respect to `p` and `q` are

double dHdp(double p)
{
return p;
}

double dHdq(double q)
{
return q;
}

Note that the functional can be readily generalized to multiple coordinates by changing the
signature of `dHdp` to

std::vector<double> dHdp(std::vector<double> p)
{
// calculate the partial derivatives with respect to each p_i
}

We then define the timestep size and number of steps of the algorithm to go from `t=0` to `t=100`

RealType dt = 0.05;
RealType t_end = 100;
unsigned int steps = t_end / dt;

Lastly, we define the initial conditions so that the oscillator starts from rest at `x=1`

RealType q0 = 1;
RealType p0 = 0;

We now evolve the system using the following

std::vector<RealType> p;
std::vector<RealType> q;

std::tie(p, q) = boost::math::quadrature::integrate_hamiltonian(p0, q0, dt, steps, dHdp, dHdq, "Y6");

The ouput vectors `q, p` are the position and momentum of the system at each time. In
higher dimensions the output will be a vector of vectors.

The last argument that we pass to `integrate_hamiltonian`, "Y6" here, sets the integration
method to use. The string "Y6" stands for Yoshida's 6th order integrator. Yoshida's 2nd and
4th order methods are also available by passing the string "Y2", or "Y4" respectively.
The 4th order and 6th order symplectic Runge-Kutta-Nystrom methods from Table 3 of Blanes and Moan
are available using the strings "SRKNB6" and "SRKNB11".

[optional_policy]

References:

Yoshida, Haruo. [`Construction of higher order symplectic integrators], Physics Letters A, 150.5-7 (1990): 262-268.

Blanes, Sergio, and Per Christian Moan. [`Practical symplectic partitioned runge–kutta and runge–kutta–nyström methods`], Journal of Computational and Applied Mathematics 142.2 (2002): 313-330.

[endsect] [/section:symplectic Symplectic Integration]

Loading
Loading