Source code for solprop.stepper.runge_kutta
# SPDX-FileCopyrightText: 2026 John C. Travers and contributors
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""The interaction-picture Runge-Kutta march as a run's integrator.
:class:`RungeKutta` is the embedded explicit Runge-Kutta pair in the interaction picture
(IP-DOPRI5 by default), one of three integrators beside
:class:`solprop.stepper.multistep.Multistep`, the low-call Adams method, and
:class:`solprop.stepper.low_storage.LowStorageRungeKutta`, the fixed-schedule replay.
Which one a run takes by default depends on the interface;
``docs/guide/numerics/choosing-a-stepper.md`` compares them.
"""
from dataclasses import dataclass
from solprop.stepper.tableau import DOPRI5, Tableau
__all__ = ["RungeKutta"]
[docs]
@dataclass(frozen=True)
class RungeKutta:
"""The interaction-picture Runge-Kutta march with an embedded error estimate.
Every accepted step pays the tableau's stages in source calls (six for DOPRI5 on
the native backend, which recycles the first-same-as-last stage, and all seven on
the NumPy reference) and keeps no history, where the Adams method
holds from seven to about sixty further copies of the state, by backend and
formulation: the integrator to choose when a source evaluation is cheap or the
state is too large for the Adams history
(``docs/guide/numerics/choosing-a-stepper.md``).
Equality is by the tableau's identity, as :class:`~solprop.stepper.tableau.Tableau`
compares.
Attributes
----------
tableau : solprop.stepper.tableau.Tableau
The scheme. Default DOPRI5, whose continuous extension interpolates save planes.
Examples
--------
>>> from solprop.stepper.runge_kutta import RungeKutta
>>> from solprop.stepper.tableau import TSIT5
>>> RungeKutta()
RungeKutta(tableau=DOPRI5)
>>> RungeKutta(TSIT5).name
'Tsit5'
"""
tableau: Tableau = DOPRI5
def __repr__(self) -> str:
"""Return the representation, naming the tableau.
Returns
-------
str
``RungeKutta(tableau=<name>)``.
"""
return f"RungeKutta(tableau={self.tableau.name})"
[docs]
@property
def name(self) -> str: # numpydoc ignore=RT01
"""The tableau's name, the method's record name."""
return self.tableau.name