pyhamsys


Namepyhamsys JSON
Version 0.32 PyPI version JSON
download
home_pagehttp://github.com/cchandre/pyhamsys
SummarySome tools for Hamiltonian systems
upload_time2024-07-09 15:53:09
maintainerNone
docs_urlNone
authorCristel Chandre
requires_python>=3.6
licenseBSD
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pyHamSys
pyHamSys is a Python package for scientific computing involving Hamiltonian systems

![PyPI](https://img.shields.io/pypi/v/pyhamsys)
![License](https://img.shields.io/badge/license-BSD-lightgray)

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)](https://doi.org/10.1016/0167-2789(90)90019-L): 
    - `FR` (order 4, all purpose)
- From [Yoshida, Phys. Lett. A 150, 262 (1990)](https://doi.org/10.1016/0375-9601(90)90092-3):
    - `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)](https://doi.org/10.1137/0916010):
    - `M2` (order 2, all purpose)
    - `M4` (order 4, all purpose)
- From [Omelyan, Mryglod, Folk, Comput. Phys. Commun. 146, 188 (2002)](https://doi.org/10.1016/S0010-4655(02)00451-4): 
    - `EFRL` (order 4) optimized for *H* = *A* + *B*
    - `PEFRL` and `VEFRL` (order 4) optimized for *H* = *A*(*p*) + *B*(*q*). For `PEFRL`, *chi* should be exp(*h* X<sub>A</sub>)exp(*h* X<sub>B</sub>). For `VEFRL`, *chi* should be exp(*h* X<sub>B</sub>)exp(*h* X<sub>A</sub>).
- From [Blanes, Moan, J. Comput. Appl. Math. 142, 313 (2002)](https://doi.org/10.1016/S0377-0427(01)00492-7):
    - `BM4` (order 4, all purpose) refers to S<sub>6</sub> 
    - `BM6` (order 6, all purpose) refers to S<sub>10</sub>
    - `RKN4b` (order 4) refers to SRKN<sub>6</sub><sup>*b*</sup> optimized for *H* = *A*(*p*) + *B*(*q*). Here *chi* should be exp(*h* X<sub>B</sub>)exp(*h* X<sub>A</sub>).
    - `RKN6b` (order 6) refers to SRKN<sub>11</sub><sup>*b*</sup> optimized for *H* = *A*(*p*) + *B*(*q*). Here *chi* should be exp(*h* X<sub>B</sub>)exp(*h* X<sub>A</sub>).
    - `RKN6a` (order 6) refers to SRKN<sub>14</sub><sup>*a*</sup> optimized for *H* = *A*(*p*) + *B*(*q*). Here *chi* should be exp(*h* X<sub>A</sub>)exp(*h* X<sub>B</sub>).
- From [Blanes, Casas, Farrés, Laskar, Makazaga, Murua, Appl. Numer. Math. 68, 58 (2013)](http://dx.doi.org/10.1016/j.apnum.2013.01.003):
    - `ABA104` (order (10,4)) optimized for *H* = *A* + &epsilon; *B*. Here *chi* should be exp(*h* X<sub>A</sub>)exp(*h* X<sub>B</sub>).
    - `ABA864` (order (8,6,4)) optimized for *H* = *A* + &epsilon; *B*. Here *chi* should be exp(*h* X<sub>A</sub>)exp(*h* X<sub>B</sub>).
    - `ABA1064` (order (10,6,4)) optimized for *H* = *A* + &epsilon; *B*. Here *chi* should be exp(*h* X<sub>A</sub>)exp(*h* X<sub>B</sub>).
    
All purpose integrators are for any splitting of the Hamiltonian *H*=&sum;<sub>*k*</sub> *A*<sub>*k*</sub> in any order of the functions *A*<sub>*k*</sub>. Otherwise, the order of the operators is specified for each integrator. These integrators are used in the functions `solve_ivp_symp` and `solve_ivp_sympext` by specifying the entry `method` (default is `BM4`). 

----
## HamSys class

### Parameters
- `ndof` : number of degrees of freedom of the Hamiltonian system
       	'ndof' should be an integer or half an integer. Half integers denote an explicit time dependence.

### Attributes
- `hamiltonian` : callable  
	A function of (*t*, *y*) which returns the Hamiltonian *H*(*t*,*y*) where *y* is the state vector.
- `y_dot` : callable  
  	A function of (*t*, *y*) which returns {*y*,*H*(*t*,*y*)} where *y* is the state vector and *H* is the Hamiltonian. In canonical coordinates (used, e.g., in `solve_ivp_sympext`) where *y* = (*q*, *p*), this function returns (&part;*H*/&part;*p*, -&part;*H*/&part;*q*).
- `k_dot` : callable  
	A function of (*t*, *y*) which returns {*k*,*H*(*t*,*y*)} = -&part;*H*/&part;*t* where *k* is canonically conjugate to *t* and *H* is the Hamiltonian.

### Functions
- `compute_vector_field` : from a callable function (Hamiltonian in canonical coordinates) written with symbolic variables (SymPy), computes the vector fields, `y_dot` and `k_dot`.

	Determine Hamilton's equations of motion from a given scalar function &ndash;the Hamiltonian&ndash; *H*(*q*, *p*, *t*) where *q* and *p* are respectively positions and momenta.

	#### Parameters
	- `hamiltonian` : callable
		Function *H*(*q*, *p*, *t*) &ndash;the Hamiltonian expressed in symbolic variables&ndash;, expressed using [SymPy](https://www.sympy.org/en/index.html) functions.
	- `output` : bool, optional
		If True, displays the equations of motion. Default is False.
	
	The function `compute_vector_field` determines the HamSys function attributes `y_dot` and `k_dot` to be used in `solve_ivp_sympext`. The derivatives are computed symbolically using SymPy.

- `compute_energy` : callable
  	A function of `sol` &ndash;a solution provided by `solve_ivp_sympext`&ndash; and `maxerror`, a boolean indicating whether the maximum error in total energy is given (if True) or all the values of the total energy (if False). 
	#### Parameters
	- `sol` : OdeSolution  
   		Solution provided by `solve_ivp_sympext`. 
 	- `maxerror` : bool, optional  
    		Default is True.

---
## solve_ivp_symp and solve_ivp_sympext

The functions `solve_ivp_symp` and `solve_ivp_sympext` solve an initial value problem for a Hamiltonian system using an element of the class SymplecticIntegrator, an explicit symplectic splitting scheme (see [1]). These functions numerically integrate a system of ordinary differential equations given an initial value:  
	&nbsp; d*y* / d*t* = {*y*, *H*(*t*, *y*)}  
	&nbsp; *y*(*t*<sub>0</sub>) = *y*<sub>0</sub>  
Here *t* is a 1-D independent variable (time), *y*(*t*) is an N-D vector-valued function (state). A Hamiltonian *H*(*t*, *y*) and a Poisson bracket {. , .} determine the differential equations. The goal is to find *y*(*t*) approximately satisfying the differential equations, given an initial value *y*(*t*<sub>0</sub>) = *y*<sub>0</sub>. 

The function `solve_ivp_symp` solves an initial value problem using an explicit symplectic integration. The Hamiltonian flow is defined by two functions `chi` and `chi_star` of (*h*, *t*, *y*) (see [2]). This function works for any set of coordinates, canonical or non-canonical, provided that the splitting *H*=&sum;<sub>*k*</sub> *A*<sub>*k*</sub> leads to facilitated expressions for the operators exp(*h* X<sub>*k*</sub>) where X<sub>*k*</sub> = {*A*<sub>*k*</sub> , &centerdot;}.

The function `solve_ivp_sympext` solves an initial value problem using an explicit symplectic approximation obtained by an extension in phase space (see [3]). This symplectic approximation works for canonical Poisson brackets, and the state vector should be of the form *y* = (*q*, *p*). 

### Parameters:  

  - `chi` (for `solve_ivp_symp`) : callable  
	Function of (*h*, *t*, *y*) returning exp(*h* X<sub>*n*</sub>)...exp(*h* X<sub>1</sub>) *y* at time *t*. If the selected integrator is not all purpose, refer to the list above for the specific ordering of the operators. The operator X<sub>*k*</sub> is the Liouville operator associated with the function *A*<sub>*k*</sub>, i.e., for Hamiltonian flows X<sub>*k*</sub> = {*A*<sub>*k*</sub> , &centerdot;} where {&centerdot; , &centerdot;} is the Poisson bracket.
	`chi` must return an array of the same shape as `y`.
  - `chi_star` (for `solve_ivp_symp`) : callable   
	Function of (*h*, *t*, *y*) returning exp(*h* X<sub>1</sub>)...exp(*h* X<sub>*n*</sub>) *y* at time *t*.
	`chi_star` must return an array of the same shape as `y`.
  - `hs` (for `solve_ivp_sympext`) : element of class HamSys  
	The attributes `y_dot` of `hs` should be defined. If `check_energy` is True. It the Hamiltonian system has an explicit time dependence (i.e., the parameter `ndof` of `hs`  is half an integer), the attribute `k_dot` of `hs` should be specified. 
  - `t_span` : 2-member sequence  
	Interval of integration (*t*<sub>0</sub>, *t*<sub>f</sub>). The solver starts with *t*=*t*<sub>0</sub> and integrates until it reaches *t*=*t*<sub>f</sub>. Both *t*<sub>0</sub> and *t*<sub>f</sub> must be floats or values interpretable by the float conversion function.	
  - `y0` : array_like, shape (n,)  
	Initial state.
  - `step` : float   
	Step size.
  - `t_eval` : array_like or None, optional  
	Times at which to store the computed solution, must be sorted and equally spaced, and lie within `t_span`. If None (default), use points selected by the solver.
  - `method` : string, optional  
 	Integration methods are listed on [pyhamsys](https://pypi.org/project/pyhamsys/).   
	'BM4' is the default.
  - `omega` (for `solve_ivp_sympext`) : float, optional  
   	Coupling parameter in the extended phase space (see [3]). Default = 10.
  - `command` : function of (*t*, *y*)  
	Function to be run at each step size (e.g., plotting an observable associated with the state vector *y*, or register specific events).
  - `check_energy` (for `solve_ivp_sympext`) : bool, optional  
	If True, the attribute `hamiltonian` of `hs` should be defined. Default is False. 

### Returns:  
&nbsp; Bunch object with the following fields defined:
   - `t` : ndarray, shape (n_points,)  
	Time points.
   - `y` : ndarray, shape (n, n_points)  
	Values of the solution `y` at `t`.
   - `k` (for `solve_ivp_sympext`) : ndarray, shape (n//2, n_points)
     	Values of `k` at `t`. Only for `solve_ivp_sympext` and if `check_energy` is True for a Hamiltonian system with an explicit time dependence (i.e., the parameter `ndof` of `hs`  is half an integer).
   - `err` (for `solve_ivp_sympext`) : float
     	Error in the computation of the total energy. Only for `solve_ivp_sympext` and if `check_energy` is True.
   - `step` : step size used in the computation.

### Remarks:   
  - Use `solve_ivp_symp` is the Hamiltonian can be split and if each partial operator exp(*h* X<sub>*k*</sub>) can be easily expressed/computed. Otherwise use `solve_ivp_sympext` if your coordinates are canonical.  
  - If `t_eval` is a linearly spaced list or array, or if `t_eval` is None (default), the step size is slightly readjusted so that the output times contain the values in `t_eval`, or the final time *t*<sub>f</sub> corresponds to an integer number of step sizes. The step size used in the computation is recorded in the solution as `sol.step`.  

### References:  
  - [1] Hairer, Lubich, Wanner, 2003, *Geometric Numerical Integration: Structure-Preserving Algorithms for Ordinary Differential Equations* (Springer)  
  - [2] McLachlan, *Tuning symplectic integrators is easy and worthwhile*, Commun. Comput. Phys. 31, 987 (2022); [arxiv:2104.10269](https://arxiv.org/abs/2104.10269)  
  - [3] Tao, M., *Explicit symplectic approximation of nonseparable Hamiltonians: Algorithm and long time performance*, Phys. Rev. E 94, 043303 (2016)

### Example

```python
>>> import numpy as xp
>>> import sympy as sp
>>> import matplotlib.pyplot as plt
>>> from pyhamsys import HamSys, solve_ivp_sympext
>>> hs = HamSys()
>>> hamiltonian = lambda q, p, t: p**2 / 2 - sp.cos(q)
>>> hs.compute_vector_field(hamiltonian, output=True)
>>> sol = solve_ivp_sympext(hs, (0, 20), xp.asarray([3, 0]), step=1e-1, check_energy=True)
>>> print(f"Error in energy : {sol.err}")
>>> plt.plot(sol.y[0], sol.y[1])
>>> plt.show()
```
---
For more information: <cristel.chandre@cnrs.fr>

            

Raw data

            {
    "_id": null,
    "home_page": "http://github.com/cchandre/pyhamsys",
    "name": "pyhamsys",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": null,
    "author": "Cristel Chandre",
    "author_email": "cristel.chandre@cnrs.fr",
    "download_url": "https://files.pythonhosted.org/packages/6d/e2/c2a3a389c3aedba5c1d136d509f9e1c94c67c8cc381e317c4cd34a7439a6/pyhamsys-0.32.tar.gz",
    "platform": null,
    "description": "# pyHamSys\npyHamSys is a Python package for scientific computing involving Hamiltonian systems\n\n![PyPI](https://img.shields.io/pypi/v/pyhamsys)\n![License](https://img.shields.io/badge/license-BSD-lightgray)\n\nInstallation: \n```\npip install pyhamsys\n```\n\n## Symplectic Integrators\npyHamSys includes a class SymplecticIntegrator containing the following symplectic splitting integrators:\n\n- `Verlet` (order 2, all purpose), also referred to as Strang or St\u00f6rmer-Verlet splitting \n- From [Forest, Ruth, Physica D 43, 105 (1990)](https://doi.org/10.1016/0167-2789(90)90019-L): \n    - `FR` (order 4, all purpose)\n- From [Yoshida, Phys. Lett. A 150, 262 (1990)](https://doi.org/10.1016/0375-9601(90)90092-3):\n    - `Yo#`: # should be replaced by an even integer, e.g., `Yo6` for 6th order symplectic integrator (all purpose)\n    - `Yos6`: (order 6, all purpose) optimized symplectic integrator (solution A from Table 1)\n- From [McLachlan, SIAM J. Sci. Comp. 16, 151 (1995)](https://doi.org/10.1137/0916010):\n    - `M2` (order 2, all purpose)\n    - `M4` (order 4, all purpose)\n- From [Omelyan, Mryglod, Folk, Comput. Phys. Commun. 146, 188 (2002)](https://doi.org/10.1016/S0010-4655(02)00451-4): \n    - `EFRL` (order 4) optimized for *H* = *A* + *B*\n    - `PEFRL` and `VEFRL` (order 4) optimized for *H* = *A*(*p*) + *B*(*q*). For `PEFRL`, *chi* should be exp(*h* X<sub>A</sub>)exp(*h* X<sub>B</sub>). For `VEFRL`, *chi* should be exp(*h* X<sub>B</sub>)exp(*h* X<sub>A</sub>).\n- From [Blanes, Moan, J. Comput. Appl. Math. 142, 313 (2002)](https://doi.org/10.1016/S0377-0427(01)00492-7):\n    - `BM4` (order 4, all purpose) refers to S<sub>6</sub> \n    - `BM6` (order 6, all purpose) refers to S<sub>10</sub>\n    - `RKN4b` (order 4) refers to SRKN<sub>6</sub><sup>*b*</sup> optimized for *H* = *A*(*p*) + *B*(*q*). Here *chi* should be exp(*h* X<sub>B</sub>)exp(*h* X<sub>A</sub>).\n    - `RKN6b` (order 6) refers to SRKN<sub>11</sub><sup>*b*</sup> optimized for *H* = *A*(*p*) + *B*(*q*). Here *chi* should be exp(*h* X<sub>B</sub>)exp(*h* X<sub>A</sub>).\n    - `RKN6a` (order 6) refers to SRKN<sub>14</sub><sup>*a*</sup> optimized for *H* = *A*(*p*) + *B*(*q*). Here *chi* should be exp(*h* X<sub>A</sub>)exp(*h* X<sub>B</sub>).\n- From [Blanes, Casas, Farr\u00e9s, Laskar, Makazaga, Murua, Appl. Numer. Math. 68, 58 (2013)](http://dx.doi.org/10.1016/j.apnum.2013.01.003):\n    - `ABA104` (order (10,4)) optimized for *H* = *A* + &epsilon; *B*. Here *chi* should be exp(*h* X<sub>A</sub>)exp(*h* X<sub>B</sub>).\n    - `ABA864` (order (8,6,4)) optimized for *H* = *A* + &epsilon; *B*. Here *chi* should be exp(*h* X<sub>A</sub>)exp(*h* X<sub>B</sub>).\n    - `ABA1064` (order (10,6,4)) optimized for *H* = *A* + &epsilon; *B*. Here *chi* should be exp(*h* X<sub>A</sub>)exp(*h* X<sub>B</sub>).\n    \nAll purpose integrators are for any splitting of the Hamiltonian *H*=&sum;<sub>*k*</sub> *A*<sub>*k*</sub> in any order of the functions *A*<sub>*k*</sub>. Otherwise, the order of the operators is specified for each integrator. These integrators are used in the functions `solve_ivp_symp` and `solve_ivp_sympext` by specifying the entry `method` (default is `BM4`). \n\n----\n## HamSys class\n\n### Parameters\n- `ndof` : number of degrees of freedom of the Hamiltonian system\n       \t'ndof' should be an integer or half an integer. Half integers denote an explicit time dependence.\n\n### Attributes\n- `hamiltonian` : callable  \n\tA function of (*t*, *y*) which returns the Hamiltonian *H*(*t*,*y*) where *y* is the state vector.\n- `y_dot` : callable  \n  \tA function of (*t*, *y*) which returns {*y*,*H*(*t*,*y*)} where *y* is the state vector and *H* is the Hamiltonian. In canonical coordinates (used, e.g., in `solve_ivp_sympext`) where *y* = (*q*, *p*), this function returns (&part;*H*/&part;*p*, -&part;*H*/&part;*q*).\n- `k_dot` : callable  \n\tA function of (*t*, *y*) which returns {*k*,*H*(*t*,*y*)} = -&part;*H*/&part;*t* where *k* is canonically conjugate to *t* and *H* is the Hamiltonian.\n\n### Functions\n- `compute_vector_field` : from a callable function (Hamiltonian in canonical coordinates) written with symbolic variables (SymPy), computes the vector fields, `y_dot` and `k_dot`.\n\n\tDetermine Hamilton's equations of motion from a given scalar function &ndash;the Hamiltonian&ndash; *H*(*q*, *p*, *t*) where *q* and *p* are respectively positions and momenta.\n\n\t#### Parameters\n\t- `hamiltonian` : callable\n\t\tFunction *H*(*q*, *p*, *t*) &ndash;the Hamiltonian expressed in symbolic variables&ndash;, expressed using [SymPy](https://www.sympy.org/en/index.html) functions.\n\t- `output` : bool, optional\n\t\tIf True, displays the equations of motion. Default is False.\n\t\n\tThe function `compute_vector_field` determines the HamSys function attributes `y_dot` and `k_dot` to be used in `solve_ivp_sympext`. The derivatives are computed symbolically using SymPy.\n\n- `compute_energy` : callable\n  \tA function of `sol` &ndash;a solution provided by `solve_ivp_sympext`&ndash; and `maxerror`, a boolean indicating whether the maximum error in total energy is given (if True) or all the values of the total energy (if False). \n\t#### Parameters\n\t- `sol` : OdeSolution  \n   \t\tSolution provided by `solve_ivp_sympext`. \n \t- `maxerror` : bool, optional  \n    \t\tDefault is True.\n\n---\n## solve_ivp_symp and solve_ivp_sympext\n\nThe functions `solve_ivp_symp` and `solve_ivp_sympext` solve an initial value problem for a Hamiltonian system using an element of the class SymplecticIntegrator, an explicit symplectic splitting scheme (see [1]). These functions numerically integrate a system of ordinary differential equations given an initial value:  \n\t&nbsp; d*y* / d*t* = {*y*, *H*(*t*, *y*)}  \n\t&nbsp; *y*(*t*<sub>0</sub>) = *y*<sub>0</sub>  \nHere *t* is a 1-D independent variable (time), *y*(*t*) is an N-D vector-valued function (state). A Hamiltonian *H*(*t*, *y*) and a Poisson bracket {. , .} determine the differential equations. The goal is to find *y*(*t*) approximately satisfying the differential equations, given an initial value *y*(*t*<sub>0</sub>) = *y*<sub>0</sub>. \n\nThe function `solve_ivp_symp` solves an initial value problem using an explicit symplectic integration. The Hamiltonian flow is defined by two functions `chi` and `chi_star` of (*h*, *t*, *y*) (see [2]). This function works for any set of coordinates, canonical or non-canonical, provided that the splitting *H*=&sum;<sub>*k*</sub> *A*<sub>*k*</sub> leads to facilitated expressions for the operators exp(*h* X<sub>*k*</sub>) where X<sub>*k*</sub> = {*A*<sub>*k*</sub> , &centerdot;}.\n\nThe function `solve_ivp_sympext` solves an initial value problem using an explicit symplectic approximation obtained by an extension in phase space (see [3]). This symplectic approximation works for canonical Poisson brackets, and the state vector should be of the form *y* = (*q*, *p*). \n\n### Parameters:  \n\n  - `chi` (for `solve_ivp_symp`) : callable  \n\tFunction of (*h*, *t*, *y*) returning exp(*h* X<sub>*n*</sub>)...exp(*h* X<sub>1</sub>) *y* at time *t*. If the selected integrator is not all purpose, refer to the list above for the specific ordering of the operators. The operator X<sub>*k*</sub> is the Liouville operator associated with the function *A*<sub>*k*</sub>, i.e., for Hamiltonian flows X<sub>*k*</sub> = {*A*<sub>*k*</sub> , &centerdot;} where {&centerdot; , &centerdot;} is the Poisson bracket.\n\t`chi` must return an array of the same shape as `y`.\n  - `chi_star` (for `solve_ivp_symp`) : callable   \n\tFunction of (*h*, *t*, *y*) returning exp(*h* X<sub>1</sub>)...exp(*h* X<sub>*n*</sub>) *y* at time *t*.\n\t`chi_star` must return an array of the same shape as `y`.\n  - `hs` (for `solve_ivp_sympext`) : element of class HamSys  \n\tThe attributes `y_dot` of `hs` should be defined. If `check_energy` is True. It the Hamiltonian system has an explicit time dependence (i.e., the parameter `ndof` of `hs`  is half an integer), the attribute `k_dot` of `hs` should be specified. \n  - `t_span` : 2-member sequence  \n\tInterval of integration (*t*<sub>0</sub>, *t*<sub>f</sub>). The solver starts with *t*=*t*<sub>0</sub> and integrates until it reaches *t*=*t*<sub>f</sub>. Both *t*<sub>0</sub> and *t*<sub>f</sub> must be floats or values interpretable by the float conversion function.\t\n  - `y0` : array_like, shape (n,)  \n\tInitial state.\n  - `step` : float   \n\tStep size.\n  - `t_eval` : array_like or None, optional  \n\tTimes at which to store the computed solution, must be sorted and equally spaced, and lie within `t_span`. If None (default), use points selected by the solver.\n  - `method` : string, optional  \n \tIntegration methods are listed on [pyhamsys](https://pypi.org/project/pyhamsys/).   \n\t'BM4' is the default.\n  - `omega` (for `solve_ivp_sympext`) : float, optional  \n   \tCoupling parameter in the extended phase space (see [3]). Default = 10.\n  - `command` : function of (*t*, *y*)  \n\tFunction to be run at each step size (e.g., plotting an observable associated with the state vector *y*, or register specific events).\n  - `check_energy` (for `solve_ivp_sympext`) : bool, optional  \n\tIf True, the attribute `hamiltonian` of `hs` should be defined. Default is False. \n\n### Returns:  \n&nbsp; Bunch object with the following fields defined:\n   - `t` : ndarray, shape (n_points,)  \n\tTime points.\n   - `y` : ndarray, shape (n, n_points)  \n\tValues of the solution `y` at `t`.\n   - `k` (for `solve_ivp_sympext`) : ndarray, shape (n//2, n_points)\n     \tValues of `k` at `t`. Only for `solve_ivp_sympext` and if `check_energy` is True for a Hamiltonian system with an explicit time dependence (i.e., the parameter `ndof` of `hs`  is half an integer).\n   - `err` (for `solve_ivp_sympext`) : float\n     \tError in the computation of the total energy. Only for `solve_ivp_sympext` and if `check_energy` is True.\n   - `step` : step size used in the computation.\n\n### Remarks:   \n  - Use `solve_ivp_symp` is the Hamiltonian can be split and if each partial operator exp(*h* X<sub>*k*</sub>) can be easily expressed/computed. Otherwise use `solve_ivp_sympext` if your coordinates are canonical.  \n  - If `t_eval` is a linearly spaced list or array, or if `t_eval` is None (default), the step size is slightly readjusted so that the output times contain the values in `t_eval`, or the final time *t*<sub>f</sub> corresponds to an integer number of step sizes. The step size used in the computation is recorded in the solution as `sol.step`.  \n\n### References:  \n  - [1] Hairer, Lubich, Wanner, 2003, *Geometric Numerical Integration: Structure-Preserving Algorithms for Ordinary Differential Equations* (Springer)  \n  - [2] McLachlan, *Tuning symplectic integrators is easy and worthwhile*, Commun. Comput. Phys. 31, 987 (2022); [arxiv:2104.10269](https://arxiv.org/abs/2104.10269)  \n  - [3] Tao, M., *Explicit symplectic approximation of nonseparable Hamiltonians: Algorithm and long time performance*, Phys. Rev. E 94, 043303 (2016)\n\n### Example\n\n```python\n>>> import numpy as xp\n>>> import sympy as sp\n>>> import matplotlib.pyplot as plt\n>>> from pyhamsys import HamSys, solve_ivp_sympext\n>>> hs = HamSys()\n>>> hamiltonian = lambda q, p, t: p**2 / 2 - sp.cos(q)\n>>> hs.compute_vector_field(hamiltonian, output=True)\n>>> sol = solve_ivp_sympext(hs, (0, 20), xp.asarray([3, 0]), step=1e-1, check_energy=True)\n>>> print(f\"Error in energy : {sol.err}\")\n>>> plt.plot(sol.y[0], sol.y[1])\n>>> plt.show()\n```\n---\nFor more information: <cristel.chandre@cnrs.fr>\n",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "Some tools for Hamiltonian systems",
    "version": "0.32",
    "project_urls": {
        "Homepage": "http://github.com/cchandre/pyhamsys"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a91a6489d7d5f3b8b4a0f8c6edb01229ddf7154aadfc69943281b643d1713f46",
                "md5": "33cc0eb8d7ca9bf162276a43be24bfc7",
                "sha256": "4727ef540153b052c58d1aa446d79c01617112b7236677cc5ea0a6670875863b"
            },
            "downloads": -1,
            "filename": "pyhamsys-0.32-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "33cc0eb8d7ca9bf162276a43be24bfc7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 13804,
            "upload_time": "2024-07-09T15:53:05",
            "upload_time_iso_8601": "2024-07-09T15:53:05.123650Z",
            "url": "https://files.pythonhosted.org/packages/a9/1a/6489d7d5f3b8b4a0f8c6edb01229ddf7154aadfc69943281b643d1713f46/pyhamsys-0.32-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6de2c2a3a389c3aedba5c1d136d509f9e1c94c67c8cc381e317c4cd34a7439a6",
                "md5": "2ebb36fe20b4b7a0d5bf699cd1869489",
                "sha256": "ba5deeb9fb20c9862ee67f3b5e4b75d50a5bb20ed70a08194d2cadf82a215049"
            },
            "downloads": -1,
            "filename": "pyhamsys-0.32.tar.gz",
            "has_sig": false,
            "md5_digest": "2ebb36fe20b4b7a0d5bf699cd1869489",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 13315,
            "upload_time": "2024-07-09T15:53:09",
            "upload_time_iso_8601": "2024-07-09T15:53:09.477179Z",
            "url": "https://files.pythonhosted.org/packages/6d/e2/c2a3a389c3aedba5c1d136d509f9e1c94c67c8cc381e317c4cd34a7439a6/pyhamsys-0.32.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-09 15:53:09",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "cchandre",
    "github_project": "pyhamsys",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pyhamsys"
}
        
Elapsed time: 0.25554s