Skip to main content

OdeSolver

Enum OdeSolver 

Source
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

Source

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.

Source

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.

Source

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.

Source

pub const fn name(&self) -> &'static str

The stepper’s name, for diagnostics and log lines.

Source

pub const fn requires_jacobian(&self) -> bool

Whether this stepper calls OdeSystem::jacobian, whose default implementation panics. true only for Rosenbrock23.

Source

pub fn config(&self) -> &OdeSolverConfig

The adaptive step-size controller settings in force.

Source

pub fn config_mut(&mut self) -> &mut OdeSolverConfig

Mutable access to the controller settings, e.g. to lower max_steps.

Source

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.

Source

pub fn integrate<Sys: OdeSystem + ?Sized>( &mut self, ode: &Sys, x_start: f64, x_end: f64, y: &mut Vec<f64>, dx_est: &mut f64, ) -> Result<(), OdeError>

Integrate ode from x_start to x_end, updating y in place and leaving the last accepted step size in dx_est.

§Errors

OdeError::StepSizeUnderflow or OdeError::MaxStepsExceeded.

Trait Implementations§

Source§

impl Clone for OdeSolver

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OdeSolver

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.