Skip to main content

Some tools for Hamiltonian systems

Project description

pyHamSys

pyHamSys is a Python package for scientific computing involving Hamiltonian systems

PyPI License

Installation:

pip install pyhamsys

Symplectic Integrators

pyHamSys includes a class SymplecticIntegrator containing the following symplectic splitting integrators:

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyhamsys-0.0.7.tar.gz (9.3 kB view hashes)

Uploaded Source

Built Distribution

pyhamsys-0.0.7-py3-none-any.whl (9.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page