pub enum OdeSolver {
Euler(Euler),
Rkf45(Rkf45),
Rosenbrock23(Rosenbrock23),
}Expand description
Which stepper integrates the system — enum dispatch over the closed set of solvers this crate ports.
The steppers carry per-equation scratch buffers sized at construction, so a
solver built for n equations must only be used with an n-equation
system. All variants integrate a bare f64 state vector in the caller’s own
units; only OdeSolverConfig tolerances are interpreted here.
Cloning a solver clones its scratch buffers; the clone integrates independently of the original.
Variants§
Euler(Euler)
Explicit first-order Euler with adaptive step size. Cheapest per step, but the global error falls only linearly in the step size — use it for smooth, non-stiff systems where accuracy is not critical.
Rkf45(Rkf45)
Explicit Runge-Kutta-Fehlberg 4(5), the general-purpose default for non-stiff systems. Six derivative evaluations per step, fifth-order propagation with an embedded fourth-order error estimate.
Rosenbrock23(Rosenbrock23)
Semi-implicit W-method Rosenbrock23 for stiff systems. Requires the
system to implement OdeSystem::jacobian; the default jacobian
panics, so check OdeSolver::requires_jacobian before selecting it
for a system you did not write.
Implementations§
Source§impl OdeSolver
impl OdeSolver
Sourcepub fn euler(n: usize, abs_tol: f64, rel_tol: f64) -> Self
pub fn euler(n: usize, abs_tol: f64, rel_tol: f64) -> Self
Explicit Euler for an n-equation system.
abs_tol is the absolute and rel_tol the relative per-equation error
tolerance, both dimensionless ratios against the state values; the
remaining controller parameters take their OdeSolverConfig::default
values.
Sourcepub fn rkf45(n: usize, abs_tol: f64, rel_tol: f64) -> Self
pub fn rkf45(n: usize, abs_tol: f64, rel_tol: f64) -> Self
Runge-Kutta-Fehlberg 4(5) for an n-equation system. See
OdeSolver::euler for the tolerance arguments.
Sourcepub fn rosenbrock23(n: usize, abs_tol: f64, rel_tol: f64) -> Self
pub fn rosenbrock23(n: usize, abs_tol: f64, rel_tol: f64) -> Self
Stiff Rosenbrock23 for an n-equation system. See OdeSolver::euler
for the tolerance arguments. The system must implement
OdeSystem::jacobian.
Sourcepub const fn requires_jacobian(&self) -> bool
pub const fn requires_jacobian(&self) -> bool
Whether this stepper calls OdeSystem::jacobian, whose default
implementation panics. true only for
Rosenbrock23.
Sourcepub fn config(&self) -> &OdeSolverConfig
pub fn config(&self) -> &OdeSolverConfig
The adaptive step-size controller settings in force.
Sourcepub fn config_mut(&mut self) -> &mut OdeSolverConfig
pub fn config_mut(&mut self) -> &mut OdeSolverConfig
Mutable access to the controller settings, e.g. to lower max_steps.
Sourcepub fn solve_step<Sys: OdeSystem + ?Sized>(
&mut self,
ode: &Sys,
x: &mut f64,
y: &mut Vec<f64>,
dx_try: &mut f64,
) -> Result<(), OdeError>
pub fn solve_step<Sys: OdeSystem + ?Sized>( &mut self, ode: &Sys, x: &mut f64, y: &mut Vec<f64>, dx_try: &mut f64, ) -> Result<(), OdeError>
Take one adaptive step of ode. On return x and y are advanced and
dx_try holds the step size suggested for the next call.
Sys is ?Sized, so this accepts both a concrete &MySystem (static
dispatch) and a &dyn OdeSystem (dynamic) without a second method.
§Errors
OdeError::StepSizeUnderflow if the tolerance cannot be met.