RK5Integrator#
- class gala.integrate.RK5Integrator(func, func_args=(), func_units=None, progress=False, save_all=True)[source]#
Bases:
IntegratorFifth-order Runge-Kutta integrator with fixed timesteps.
This integrator implements the classical fifth-order Runge-Kutta method (RK5) using the Dormand-Prince coefficients. It provides fifth-order accuracy for smooth problems with a fixed timestep, making it suitable for problems where high accuracy is needed and the solution varies smoothly in time.
Unlike adaptive methods, this integrator uses a fixed timestep throughout the integration, which can be more predictable but may be less efficient for problems with varying time scales.
- Parameters:
- func
callable() A function that computes the phase-space coordinate derivatives. Must have signature
func(t, w, *func_args)wheretis time,wis the phase-space position array, and*func_argsare additional arguments.- func_args
tuple, optional Additional arguments to pass to the derivative function.
- func_units
UnitSystem, optional Unit system assumed by the integrand function.
- progressbool, optional
Display a progress bar during integration. Default is False.
- save_allbool, optional
Save the orbit at all timesteps. If False, only save the final state. Default is True.
- func
Notes
The RK5 method uses six function evaluations per timestep to achieve fifth-order accuracy. The update formula is:
\[\begin{split}w_{n+1} = w_n + \\sum_{i=1}^{6} c_i k_i\end{split}\]where the \(k_i\) are intermediate slope estimates computed using the Dormand-Prince coefficients.
- Advantages:
Fifth-order accuracy for smooth problems
Stable and robust for most ODE systems
Predictable computational cost (6 function evaluations per step)
- Disadvantages:
Not symplectic (may not conserve energy for Hamiltonian systems)
Fixed timestep can be inefficient
More expensive per step than lower-order methods
References
Dormand, J. R. & Prince, P. J. (1980). A family of embedded Runge-Kutta formulae. Journal of Computational and Applied Mathematics, 6(1), 19-26.
Hairer, E., Nørsett, S. P. & Wanner, G. (1993). Solving Ordinary Differential Equations I. Springer-Verlag.
Examples
Integrate a simple harmonic oscillator:
def derivs(t, w): return np.array([w[1], -w[0]]) # [dx/dt, dv/dt] integrator = RK5Integrator(derivs) orbit = integrator(w0=[1.0, 0.0], dt=0.01, n_steps=1000)
Methods Summary
__call__(w0[, mmap])Run the integrator starting from the specified initial conditions.
run(w0[, mmap])step(t, w, dt)Advance the integration by one timestep using the RK5 method.
Methods Documentation
- __call__(w0, mmap=None, **time_spec)[source]#
Run the integrator starting from the specified initial conditions.
This method integrates the orbit forward in time from the given initial phase-space position according to the time specification.
- Parameters:
- w0
PhaseSpacePosition Initial conditions for the integration.
- mmap
ndarray, optional A pre-allocated memory-mapped array to store the results. Must have the correct shape for the expected output.
- **time_spec
Keyword arguments specifying the integration time. Accepted combinations include:
dt, n_steps[, t1]: Fixed timestep and number of stepsdt, t1, t2: Fixed timestep with start and end timest: Array of specific times to integrate to
- w0
- Returns:
- orbit
Orbit The integrated orbit containing positions, velocities, and times.
- orbit
Notes
The time specification is parsed by
parse_time_specification(). See that function’s documentation for more details on the accepted formats.
- run(w0, mmap=None, **time_spec)#
Deprecated since version 1.9: The run function is deprecated and may be removed in a future version. Use Integrator call method instead.
Run the integrator starting from the specified phase-space position.
Deprecated since version 1.9: Use the
__call__method instead.
- step(t, w, dt)[source]#
Advance the integration by one timestep using the RK5 method.
This method performs a single Runge-Kutta step using the classical fifth-order formula with Dormand-Prince coefficients.
- Parameters:
- Returns:
- w_new
ndarray Updated state vector at time
t + dt.
- w_new
Notes
The method computes six intermediate slopes \(k_1, ..., k_6\) and combines them with the Dormand-Prince weights to achieve fifth-order accuracy.