Hamiltonian¶

class
gala.potential.hamiltonian.
Hamiltonian
¶ Bases:
gala.potential.common.CommonBase
Represents a composition of a gravitational potential and a reference frame.
This class is used to integrate orbits and compute quantities when working in noninertial 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 Cimplemented integrators and will be fast (to check if your object is Cenabled, check the
.c_enabled
attribute). Parameters
 potential
PotentialBase
subclass The gravitational potential.
 frame
FrameBase
subclass (optional) The reference frame.
 potential
Attributes Summary
Compute the energy (the value of the Hamiltonian) at the given phasespace position(s).
Compute the gradient of the Hamiltonian at the given phasespace position(s).
Compute the Hessian of the Hamiltonian at the given phasespace position(s).
Integrate an orbit in the current potential using the integrator class provided.
Attributes Documentation

energy
¶ Compute the energy (the value of the Hamiltonian) at the given phasespace position(s).
 Parameters
 w
PhaseSpacePosition
, array_like The phasespace 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 phasespace position has shape
w.shape
, the output energy will have shapew.shape[1:]
.
 H

gradient
¶ Compute the gradient of the Hamiltonian at the given phasespace position(s).
 Parameters
 w
PhaseSpacePosition
, array_like The phasespace 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: this can’t return a quantity, because units are different dH/dq vs. dH/dp
 grad
Quantity
The gradient of the potential. Will have the same shape as the input phasespace position,
w
.

hessian
¶ Compute the Hessian of the Hamiltonian at the given phasespace position(s).
 Parameters
 w
PhaseSpacePosition
, array_like The phasespace 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: see TODO about units about
 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_dim
byn_dim
array (matrix) for each position, where the dimensionality of phasespace isn_dim
.

integrate_orbit
¶ Integrate an orbit in the current potential using the integrator class provided. Uses same time specification as
Integrator.run()
– see the documentation forgala.integrate
for more information. Parameters
 w0
PhaseSpacePosition
, array_like Initial conditions.
 Integrator
Integrator
(optional) Integrator class to use. By default, uses
LeapfrogIntegrator
if the frame is static andDOPRI853Integrator
else. Integrator_kwargsdict (optional)
Any extra keyword argumets to pass to the integrator class when initializing. Only works in nonCython mode.
 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.
 **time_spec
Specification of how long to integrate. See documentation for
parse_time_specification
.
 w0
 Returns
 orbit
Orbit
 orbit

units
¶