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:
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
|
Abstract base class for constant-step stiff solvers. |
- class rkstiff.solvercs.BaseSolverCS(lin_op, nl_func, loglevel='WARNING')[source]
Bases:
BaseSolverAbstract 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 numericloggingconstants.
- lin_op
Linear operator passed at construction.
- Type:
np.ndarray
- nl_func
Nonlinear function for the system.
- Type:
Callable[[np.ndarray], np.ndarray]
- Raises:
ValueError – If
lin_opis 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
- 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
tandu.store_freq (int, default=1) – Frequency of storing data; every
store_freqsteps.
- Returns:
Final solution vector at \(t_f\).
- Return type:
np.ndarray
- Raises:
ValueError – If
hexceeds the total time spantf - t0.
Notes
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