Skip to main content

OdeIntegrator

Enum OdeIntegrator 

Source
pub enum OdeIntegrator<S: OdeSystem = NoTypedSystem> {
    TypedState(TypedStateIntegrator<S>),
    DynSystem(DynSystemIntegrator),
}
Expand description

Enum-dispatch wrapper over the two ways of owning an ODE system.

This is the type to store when a struct needs “an integrator” as a field. Neither variant borrows, so no lifetime parameter propagates outward — the reason this wrapper exists.

The type argument S names the concrete system used by TypedState. It defaults to NoTypedSystem, so an integrator that only ever uses DynSystem can be written as a plain OdeIntegrator.

§Choosing a variant

TypedStateDynSystem
System known at compile timeyesno
Dispatchstatic, inlinablevtable
Ownershipby valueshared, Arc
Use whennormal case — prefer thisthe type is chosen at run time

Variants§

§

TypedState(TypedStateIntegrator<S>)

The typed-state integrator: a concrete system owned by value, with static dispatch. Preferred.

§

DynSystem(DynSystemIntegrator)

The dyn-system integrator: Arc<dyn OdeSystem + Send + Sync>. Kept by maintainer decision, for flexibility where the system type is not statically known.

Implementations§

Source§

impl<S: OdeSystem> OdeIntegrator<S>

Source

pub fn typed(system: S, solver: OdeSolver) -> Self

Build the preferred, statically-typed integrator from an owned system.

let integrator = OdeIntegrator::typed(Decay, OdeSolver::rkf45(1, 1e-8, 1e-6));
assert!(integrator.is_typed_state());
Source

pub fn n_eqns(&self) -> usize

Number of coupled equations the stored system reports.

Source

pub fn solver(&self) -> &OdeSolver

The stepper in use.

Source

pub fn solver_mut(&mut self) -> &mut OdeSolver

Mutable access to the stepper, e.g. to adjust tolerances between steps.

Source

pub const fn is_typed_state(&self) -> bool

true for the preferred, statically-dispatched variant.

Source

pub fn typed_system(&self) -> Option<&S>

The owned system, when this is the typed variant; None otherwise.

Source

pub fn shared_system(&self) -> Option<&SharedOdeSystem>

The shared system, when this is the dyn variant; None otherwise.

Source

pub fn solve_step( &mut self, x: &mut f64, y: &mut Vec<f64>, dx_try: &mut f64, ) -> Result<(), OdeError>

Take one adaptive step. x is the independent variable, y the state vector (both in the caller’s units), dx_try the step size to attempt; on return dx_try is the size suggested for the next call.

§Errors

OdeError::StepSizeUnderflow if the requested tolerance cannot be met at any representable step size.

Source

pub fn integrate( &mut self, x_start: f64, x_end: f64, y: &mut Vec<f64>, dx_est: &mut f64, ) -> Result<(), OdeError>

Integrate 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 if the interval could not be spanned within config().max_steps sub-steps.

Source§

impl OdeIntegrator<NoTypedSystem>

Source

pub fn shared(system: SharedOdeSystem, solver: OdeSolver) -> Self

Build the shared, runtime-typed integrator.

Only available on OdeIntegrator<NoTypedSystem> — i.e. on the default-parameter spelling OdeIntegrator — so that the unused type argument never has to be written out.

let shared: SharedOdeSystem = Arc::new(Decay);
let integrator = OdeIntegrator::shared(shared, OdeSolver::rkf45(1, 1e-8, 1e-6));
assert!(!integrator.is_typed_state());

Trait Implementations§

Source§

impl<S: Debug + OdeSystem> Debug for OdeIntegrator<S>

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> 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, 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.