Skip to content

otf.time_integration.solver

Explicit and wrapped ODE solvers for time integration.

This module provides a small collection of time-integration algorithms used by the otf package: simple single-step and multistage integrators (e.g. ForwardEuler, RK4), multistep Adams methods, and a SolveIvp wrapper around scipy.integrate.solve_ivp that matches the solver interface used in this package.

Classes:

Name Description
ForwardEuler

Forward Euler solver.

FourStepAdamsBashforth

Four-step Adams–Bashforth explicit multistep integrator.

RK4

4th-order Runge–Kutta solver.

SolveIvp

scipy.integrate.solve_ivp wrapper matching the solver interface.

TwoStepAdamsBashforth

Two-step explicit Adams–Bashforth multistep integrator.

ForwardEuler

ForwardEuler(system: BaseSystem)

Bases: SinglestepSolver

Forward Euler solver.

See documentation of SinglestepSolver.

Source code in src/otf/time_integration/base.py
def __init__(self, system: BaseSystem):
    """Create a single-step solver for `system`.

    Parameters
    ----------
    system
        The system to integrate. For `solve_true`, `system` should be a
        `System_ModelKnown` instance (checked by `solve_true`).
    """

    super().__init__(system)

    self._step_true, self._step_assimilated = self._step_factory()

FourStepAdamsBashforth

FourStepAdamsBashforth(
    system: BaseSystem,
    pre_multistep_solver: BaseSolver | None = None,
)

Bases: MultistepSolver

Four-step Adams–Bashforth explicit multistep integrator.

Requires a pre_multistep_solver to generate the first three steps when beginning integration, or callers must supply the initial history of four states. pre_multistep_solver may be passed as None in which case the caller is responsible for providing the required initial history when invoking solve/solve_true.

Initialize the four-step Adams–Bashforth solver.

Parameters:

Name Type Description Default
system BaseSystem

The system to integrate.

required
pre_multistep_solver BaseSolver | None

Optional solver used to produce initial steps until four history values are available. If None, callers must provide the four initial states when starting integration.

None
Source code in src/otf/time_integration/solver.py
def __init__(
    self, system: BaseSystem, pre_multistep_solver: BaseSolver | None = None
):
    """Initialize the four-step Adams–Bashforth solver.

    Parameters
    ----------
    system
        The system to integrate.
    pre_multistep_solver
        Optional solver used to produce initial steps until four history
        values are available. If `None`, callers must provide the four
        initial states when starting integration.
    """

    super().__init__(system, pre_multistep_solver)

RK4

RK4(system: System_ModelKnown)

Bases: MultistageSolver

4th-order Runge–Kutta solver.

See documentation of base_solver.SinglestepSolver.

See https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods

Source code in src/otf/time_integration/base.py
def __init__(self, system: System_ModelKnown):
    """Create a multistage solver bound to `system`.

    Parameters
    ----------
    system
        A `System_ModelKnown` instance providing `f_true` and related model
        methods required by multistage integrators.
    """

    assert isinstance(system, System_ModelKnown), (
        "`system` must be of type `System_ModelKnown`"
    )

    super().__init__(system)

    self._step_true, self._step = self._step_factory()

SolveIvp

SolveIvp(system: BaseSystem, options: dict = dict())

Bases: MultistageSolver

scipy.integrate.solve_ivp wrapper matching the solver interface.

This adapter lets users employ SciPy's solve_ivp while keeping the same external solve/solve_true signatures used across other solvers in this package. Note that integration is performed in NumPy/SciPy (not JAX).

Initialize the SolveIvp adapter.

Parameters:

Name Type Description Default
system BaseSystem

An instance of BaseSystem to simulate forward in time.

required
options dict

Optional keyword arguments that are passed directly to scipy.integrate.solve_ivp.

dict()
Notes

Integration is performed by SciPy (NumPy), not JAX. The options dictionary may be modified after initialization.

Source code in src/otf/time_integration/solver.py
def __init__(self, system: BaseSystem, options: dict = dict()):
    """Initialize the SolveIvp adapter.

    Parameters
    ----------
    system
        An instance of `BaseSystem` to simulate forward in time.
    options
        Optional keyword arguments that are passed directly to
        `scipy.integrate.solve_ivp`.

    Notes
    -----
    Integration is performed by SciPy (NumPy), not JAX. The `options`
    dictionary may be modified after initialization.
    """

    self._system = system
    self.options = options

TwoStepAdamsBashforth

TwoStepAdamsBashforth(
    system: BaseSystem,
    pre_multistep_solver: BaseSolver | None = None,
)

Bases: MultistepSolver

Two-step explicit Adams–Bashforth multistep integrator.

This class implements the classical two-step Adams–Bashforth method for explicit integration of the nonlinear terms. A pre_multistep_solver may be provided to generate initial steps when starting the integration. If pre_multistep_solver is None, callers must supply the required two initial history states when invoking solve/solve_true.

Initialize the two-step Adams–Bashforth solver.

Parameters:

Name Type Description Default
system BaseSystem

The system to integrate.

required
pre_multistep_solver BaseSolver | None

Optional solver used to produce initial steps until two history values are available. If None, callers must provide the two initial states when starting integration.

None
Source code in src/otf/time_integration/solver.py
def __init__(
    self, system: BaseSystem, pre_multistep_solver: BaseSolver | None = None
):
    """Initialize the two-step Adams–Bashforth solver.

    Parameters
    ----------
    system
        The system to integrate.
    pre_multistep_solver
        Optional solver used to produce initial steps until two history
        values are available. If `None`, callers must provide the two
        initial states when starting integration.
    """

    super().__init__(system, pre_multistep_solver)