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
TypedState | DynSystem | |
|---|---|---|
| System known at compile time | yes | no |
| Dispatch | static, inlinable | vtable |
| Ownership | by value | shared, Arc |
| Use when | normal case — prefer this | the 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>
impl<S: OdeSystem> OdeIntegrator<S>
Sourcepub fn typed(system: S, solver: OdeSolver) -> Self
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());Sourcepub fn solver_mut(&mut self) -> &mut OdeSolver
pub fn solver_mut(&mut self) -> &mut OdeSolver
Mutable access to the stepper, e.g. to adjust tolerances between steps.
Sourcepub const fn is_typed_state(&self) -> bool
pub const fn is_typed_state(&self) -> bool
true for the preferred, statically-dispatched variant.
Sourcepub fn typed_system(&self) -> Option<&S>
pub fn typed_system(&self) -> Option<&S>
The owned system, when this is the typed variant; None otherwise.
The shared system, when this is the dyn variant; None otherwise.
Sourcepub fn solve_step(
&mut self,
x: &mut f64,
y: &mut Vec<f64>,
dx_try: &mut f64,
) -> Result<(), OdeError>
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.
Sourcepub fn integrate(
&mut self,
x_start: f64,
x_end: f64,
y: &mut Vec<f64>,
dx_est: &mut f64,
) -> Result<(), OdeError>
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>
impl OdeIntegrator<NoTypedSystem>
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());