LeapfrogIntegrator¶

class
gala.integrate.
LeapfrogIntegrator
(func, func_args=(), func_units=None)[source]¶ Bases:
gala.integrate.core.Integrator
A symplectic, Leapfrog integrator.
Given a function for computing time derivatives of the phasespace coordinates, this object computes the orbit at specified times.
See also
Naming convention for variables:
im1 = i1 im1_2 = i1/2 ip1 = i+1 ip1_2 = i+1/2
Parameters:  func : func
A callable object that computes the phasespace time derivatives at a time and point in phase space.
 func_args : tuple (optional)
Any extra arguments for the derivative function.
 func_units :
UnitSystem
(optional) If using units, this is the unit system assumed by the integrand function.
Examples
Using
q
as our coordinate variable andp
as the conjugate momentum, we want to numerically solve for an orbit in the potential (Hamiltonian)\[\begin{split}\Phi &= \frac{1}{2}q^2\\ H(q,p) &= \frac{1}{2}(p^2 + q^2)\end{split}\]In this system,
\[\begin{split}\dot{q} &= \frac{\partial \Phi}{\partial p} = p \\ \dot{p} &= \frac{\partial \Phi}{\partial q} = q\end{split}\]We will use the variable
w
to represent the full phasespace vector, \(w = (q,p)\). We define a function that computes the time derivates at any given time,t
, and phasespace position,w
:def F(t,w): dw = [w[1], w[0]] return dw
Note
The force here is not time dependent, but this function always has to accept the independent variable (e.g., time) as the first argument.
To create an integrator object, just pass this acceleration function in to the constructor, and then we can integrate orbits from a given vector of initial conditions:
integrator = LeapfrogIntegrator(acceleration) times,ws = integrator.run(w0=[1.,0.], dt=0.1, n_steps=1000)
Note
When integrating a single vector of initial conditions, the return array will have 2 axes. In the above example, the returned array will have shape
(2,1001)
. If an array of initial conditions are passed in, the return array will have 3 axes, where the last axis is for the individual orbits.Methods Summary
run
(w0[, mmap])Run the integrator starting from the specified phasespace position. step
(t, x_im1, v_im1_2, dt)Step forward the positions and velocities by the given timestep. Methods Documentation

run
(w0, mmap=None, **time_spec)[source]¶ Run the integrator starting from the specified phasespace position. The initial conditions
w0
should be aPhaseSpacePosition
instance.There are a few combinations of keyword arguments accepted for specifying the timestepping. For example, you can specify a fixed timestep (
dt
) and a number of steps (n_steps
), or an array of times:dt, n_steps[, t1] : (numeric, int[, numeric]) A fixed timestep dt and a number of steps to run for. dt, t1, t2 : (numeric, numeric, numeric) A fixed timestep dt, an initial time, and a final time. t : array_like An array of times to solve on.
Warning
Right now, this always returns a
Orbit
instance. This is wrong and will change!Todo
Allow specifying the return orbit class.
Parameters:  w0 :
PhaseSpacePosition
Initial conditions.
 **time_spec
Timestep information passed to
parse_time_specification
.
Returns:  orbit :
Orbit
 w0 :