rkstiff.solvercs

Base solver infrastructure for rkstiff constant step PDE solvers

Constant-step solver infrastructure for stiff time-dependent systems.

This module defines BaseSolverCS, a foundation for solvers that advance semi-linear differential equations using fixed time steps:

\[\frac{\partial \mathbf{U}}{\partial t} = \mathcal{L}\mathbf{U} + \mathcal{N}(\mathbf{U}),\]

where \(\mathcal{L}\) is a (possibly stiff) linear operator and \(\mathcal{N}\) is a nonlinear function. Subclasses such as ETD4 or ETD5 implement constant-step exponential Runge-Kutta methods based on this interface.

Classes

BaseSolverCS(lin_op, nl_func[, loglevel])

Abstract base class for constant-step stiff solvers.

class rkstiff.solvercs.BaseSolverCS(lin_op, nl_func, loglevel='WARNING')[source]

Bases: BaseSolver

Abstract base class for constant-step stiff solvers.

Provides the common structure for fixed-step exponential Runge-Kutta and related integrators. Derived classes implement stage updates and solver-specific initialization.

The governing semi-linear equation is

\[\frac{\partial \mathbf{U}}{\partial t} = \mathcal{L}\mathbf{U} + \mathcal{N}(\mathbf{U}),\]

where \(\mathcal{L}\) represents the linear (stiff) operator and \(\mathcal{N}\) the nonlinear component.

Parameters:
  • lin_op (np.ndarray) – Linear operator \(\mathcal{L}\). Must be 1D (diagonal) or a 2D square matrix.

  • nl_func (Callable[[np.ndarray], np.ndarray]) – Nonlinear function \(\mathcal{N}(\mathbf{U})\).

  • loglevel (str or int, default='WARNING') – Logging verbosity. Accepts string names ('DEBUG', 'INFO'…) or numeric logging constants.

lin_op

Linear operator passed at construction.

Type:

np.ndarray

nl_func

Nonlinear function for the system.

Type:

Callable[[np.ndarray], np.ndarray]

t

Time points recorded during evolution.

Type:

list[float]

u

Solution vectors recorded during evolution.

Type:

list[np.ndarray]

Raises:

ValueError – If lin_op is not 1D or a square 2D matrix.

Notes

  • Subclasses must implement _reset() and _update_stages().

  • The step size remains constant throughout evolution.

  • For adaptive time-stepping, use rkstiff.solveras.BaseSolverAS.

References

P. Whalen, M. Brio, and J. V. Moloney, Exponential time-differencing with embedded Runge-Kutta adaptive step control, J. Comput. Phys. 280 (2015), 579–601.

__init__(lin_op, nl_func, loglevel='WARNING')[source]

Initialize a constant-step solver and validate inputs.

property solver_type: SolverType

Return the solver type for constant-step solvers.

Returns:

Always returns SolverType.CONSTANT_STEP.

Return type:

SolverType

Examples

>>> from rkstiff.if4 import IF4
>>> solver = IF4(lin_op, nl_func)
>>> solver.solver_type == SolverType.CONSTANT_STEP
True
reset()[source]

Reset solver state and clear stored time/solution data.

Return type:

None

step(u, h)[source]

Perform a single constant-step propagation.

Parameters:
  • u (np.ndarray) – Current solution vector.

  • h (float) – Constant step size (must be non-negative).

Returns:

Updated solution after one full time step.

Return type:

np.ndarray

Notes

This method simply wraps _update_stages() and performs minimal validation and logging.

evolve(u, t0, tf, h, store_data=True, store_freq=1)[source]

Integrate the system from \(t_0\) to \(t_f\) using fixed step size.

Repeatedly applies step() with constant \(h\) until the final time is reached.

Parameters:
  • u (np.ndarray) – Initial solution vector at \(t_0\).

  • t0 (float) – Initial time.

  • tf (float) – Final time (integration stops when t tf).

  • h (float) – Constant step size \(\Delta t\).

  • store_data (bool, default=True) – Whether to store intermediate results in t and u.

  • store_freq (int, default=1) – Frequency of storing data; every store_freq steps.

Returns:

Final solution vector at \(t_f\).

Return type:

np.ndarray

Raises:

ValueError – If h exceeds the total time span tf - t0.

Notes

  • The time grid is uniformly spaced with spacing \(h\).

  • Stored data can be accessed through t and u.

Example

>>> solver = ETD4(lin_op, nl_func)
>>> u_final = solver.evolve(u0, t0=0.0, tf=10.0, h=0.05)
>>> len(solver.t)
200
set_loglevel(loglevel)

Adjust the solver’s logging verbosity at runtime.

Parameters:

loglevel (str or int) – New logging level. Accepts standard string levels or numeric constants from logging.

Return type:

None

Examples

>>> solver.set_loglevel("INFO")
>>> solver.set_loglevel(logging.DEBUG)