Some tools for Hamiltonian systems
Project description
pyHamSys
pyHamSys is a Python package for scientific computing involving Hamiltonian systems
Installation:
pip install pyhamsys
Symplectic Integrators
pyHamSys includes a class SymplecticIntegrator containing the following symplectic splitting integrators:
Verlet
(order 2, all purpose), also referred to as Strang or Störmer-Verlet splitting- From Forest, Ruth, Physica D 43, 105 (1990):
FR
(order 4, all purpose)
- From Yoshida, Phys. Lett. A 150, 262 (1990):
Yo#
: # should be replaced by an even integer, e.g.,Yo6
for 6th order symplectic integrator (all purpose)Yos6
: (order 6, all purpose) optimized symplectic integrator (solution A from Table 1)
- From McLachlan, SIAM J. Sci. Comp. 16, 151 (1995):
M2
(order 2, all purpose)M4
(order 4, all purpose)
- From Omelyan, Mryglod, Folk, Comput. Phys. Commun. 146, 188 (2002):
EFRL
(order 4) optimized for H = A + BPEFRL
andVEFRL
(order 4) optimized for H = A(p) + B(q). ForPEFRL
, chi should be exp(h XA)exp(h XB). ForVEFRL
, chi should be exp(h XB)exp(h XA).
- From Blanes, Moan, J. Comput. Appl. Math. 142, 313 (2002):
BM4
(order 4, all purpose) refers to S6BM6
(order 6, all purpose) refers to S10RKN4b
(order 4) refers to SRKN6b optimized for H = A(p) + B(q). Here chi should be exp(h XB)exp(h XA).RKN6b
(order 6) refers to SRKN11b optimized for H = A(p) + B(q). Here chi should be exp(h XB)exp(h XA).RKN6a
(order 6) refers to SRKN14a optimized for H = A(p) + B(q). Here chi should be exp(h XA)exp(h XB).
- From Blanes, Casas, Farrés, Laskar, Makazaga, Murua, Appl. Numer. Math. 68, 58 (2013):
ABA104
(order (10,4)) optimized for H = A + ε B. Here chi should be exp(h XA)exp(h XB).ABA864
(order (8,6,4)) optimized for H = A + ε B. Here chi should be exp(h XA)exp(h XB).ABA1064
(order (10,6,4)) optimized for H = A + ε B. Here chi should be exp(h XA)exp(h XB).
All purpose integrators are for any splitting of the Hamiltonian H=∑k Ak in any order of the functions Ak. Otherwise, the order of the operators is specified for each integrator.
Usage: integrator = SymplecticIntegrator(name, step) where name is one of the names listed above and step is the time step of the integrator (float).
The function integrator._integrate
integrates the Hamiltonian flow by one time step.
The function integrator.integrate
integrates the Hamiltonian flow from the initial conditions specified by the initial state vector y using integrator, one of the selected symplectic splitting integrators. It returns the value of y at times defines by the float, list or numpy array times.
Parameters:
- chi : function of (h, y), y being the state vector. Function returning exp(h Xn)...exp(h X1) y. If the selected integrator is not all purpose, refer to the list above for the specific ordering of the operators. The operator Xk is the Liouville operator associated with the function Ak, i.e., for Hamiltonian flows Xk = {Ak , ·} where {· , ·} is the Poisson bracket.
- chi_star : function of (h, y). Function returning exp(h X1)...exp(h Xn) y.
- y : initial state vector (numpy array)
- times : times at which the values of the state vector are computed
- command : function of (t, y). Function to be run at each time step (e.g., plotting an observable associated with the state vector, or register specific events).
Remarks:
- If the vector field is explicitly time dependent, it should be first autonomized by adding time as an extra variable
- If times is a linearly spaced list or array, or if times is an integer or a float, the time step is slightly readjusted so that the output times contain the values in times
- If times is not linearly spaced, a linear interpolation of the solution is performed; the accuracy of the integrator might be lost
Returns:
Bunch object with the following fields defined:
- t : final integration time if times is a float or integer
times if times is a list or a numpy array
all computed times if times is a list or numpy array with a single element - y : state vector at times t
- time_step : time step used in the computation
References:
- Hairer, Lubich, Wanner, 2003, Geometric Numerical Integration: Structure-Preserving Algorithms for Ordinary Differential Equations (Springer)
- McLachlan, Tuning symplectic integrators is easy and worthwhile, Commun. Comput. Phys. 31, 987 (2022); arxiv:2104.10269
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.