Hamiltonian#
- class gala.potential.hamiltonian.Hamiltonian(potential, frame=None)#
Bases:
CommonBaseRepresents a composition of a gravitational potential and a reference frame.
This class is used to integrate orbits and compute quantities when working in non-inertial reference frames. The input potential and frame objects must have the same dimensionality and the same unit system. If both the potential and the frame are implemented in C, numerical orbit integration will use the C-implemented integrators and will be fast (to check if your object is C-enabled, check the
.c_enabledattribute).- Parameters:
- potential
PotentialBasesubclass The gravitational potential.
- frame
FrameBasesubclass (optional) The reference frame.
- potential
Attributes Summary
Methods Summary
__call__(w)Call self as a function.
energy(w[, t])Compute the energy (the value of the Hamiltonian) at the given phase-space position(s).
gradient(w[, t])Compute the gradient of the Hamiltonian at the given phase-space position(s).
hessian(w[, t])Compute the Hessian of the Hamiltonian at the given phase-space position(s).
integrate_orbit(w0[, Integrator, ...])Integrate an orbit in the current potential using the integrator class provided.
Attributes Documentation
- units#
Methods Documentation
- __call__(w)#
Call self as a function.
- energy(w, t=0.0)#
Compute the energy (the value of the Hamiltonian) at the given phase-space position(s).
- Parameters:
- w
PhaseSpacePosition, array_like The phase-space position to compute the value of the Hamiltonian. If the input object has no units (i.e. is an
ndarray), it is assumed to be in the same unit system as the potential class.
- w
- Returns:
- H
Quantity Energy per unit mass or value of the Hamiltonian. If the input phase-space position has shape
w.shape, the output energy will have shapew.shape[1:].
- H
- gradient(w, t=0.0)#
Compute the gradient of the Hamiltonian at the given phase-space position(s).
- Parameters:
- w
PhaseSpacePosition, array_like The phase-space position to compute the value of the Hamiltonian. If the input object has no units (i.e. is an
ndarray), it is assumed to be in the same unit system as the potential class.
- w
- Returns:
- hessian(w, t=0.0)#
Compute the Hessian of the Hamiltonian at the given phase-space position(s).
- Parameters:
- w
PhaseSpacePosition, array_like The phase-space position to compute the value of the Hamiltonian. If the input object has no units (i.e. is an
ndarray), it is assumed to be in the same unit system as the potential class.
- w
- Returns:
- # TODO:
seeTODOaboutunitsabout - hess
Quantity The Hessian matrix of second derivatives of the potential. If the input position has shape
w.shape, the output energy will have shape(w.shape[0],w.shape[0]) + w.shape[1:]. That is, ann_dimbyn_dimarray (matrix) for each position, where the dimensionality of phase-space isn_dim.
- # TODO:
- integrate_orbit(w0, Integrator=None, Integrator_kwargs={}, cython_if_possible=True, save_all=True, **time_spec)#
Integrate an orbit in the current potential using the integrator class provided. Uses same time specification as
Integrator.run()– see the documentation forgala.integratefor more information.- Parameters:
- w0
PhaseSpacePosition, array_like Initial conditions.
- Integrator
Integrator,str(optional) Integrator class to use, or a string name like ‘leapfrog’, ‘dopri853’, ‘ruth4’. By default, uses
LeapfrogIntegratorif the frame is static andDOPRI853Integratorelse.- Integrator_kwargs
dict(optional) Any extra keyword arguments to pass to the integrator class when initializing. For example, you can pass in the
atolandrtolkeyword arguments to set the absolute and relative tolerances for the DOPRI853 integrator.- cython_if_possiblebool (optional)
If there is a Cython version of the integrator implemented, and the potential object has a C instance, using Cython will be much faster.
- save_allbool (optional)
Controls whether to store the phase-space position at all intermediate timesteps. Set to False to store only the final values (i.e. the phase-space position(s) at the final timestep). Default is True.
- **time_spec
Specification of how long to integrate. Most commonly, this is a timestep
dtand number of stepsn_steps, or a timestepdt, initial timet1, and final timet2. You may also pass in a time array witht. See documentation forparse_time_specificationfor more information.
- w0
- Returns:
- orbit
Orbit
- orbit