Skip to content

OdeState

Defined in: state.rs:12

pub trait OdeState: [Clone](https://doc.rust-lang.org/std/clone/trait.Clone.html) + [Sized](https://doc.rust-lang.org/std/marker/trait.Sized.html)

Algebraic operations required by generic ODE solvers.

Types implementing this trait can be used as state vectors in RK4, Dormand-Prince, and other integration methods without the integrator knowing anything about the domain-specific structure.

fn zero_like(&self) -> Self

Create a zero vector with the same shape.


fn axpy(&self, scale: f64, other: &Self) -> Self

Compute self + scale * other (AXPY operation).


fn scale(&self, factor: f64) -> Self

Compute self * factor.


fn is_finite(&self) -> bool

Check whether all components are finite (not NaN or Inf).


fn error_norm(&self, y_next: &Self, error: &Self, tol: &Tolerances) -> f64

Compute the RMS error norm for adaptive step-size control.

Uses the mixed absolute/relative tolerance formula: sc_i = atol + rtol * max(|y_n_i|, |y_{n+1}_i|) err = sqrt(1/N * sum((delta_i / sc_i)^2))


fn project(&mut self, _t: f64) -> Projection

Post-step projection (e.g., quaternion normalization, bound clamping).

Integrators call this once per accepted step, on the state that is about to be published (so callbacks and event checks see the projected state). It is never called on rejected candidates or on intermediate stages. The one exception is the low-level step_full of the adaptive solvers, which hands back the raw candidate and its error estimate for a caller running its own step-size control; projecting an accepted candidate is then that caller’s job.

The return value tells the integrator whether the state was actually modified. Adaptive methods with the FSAL property reuse the last stage derivative as the first stage of the next step; that derivative was evaluated at the unprojected candidate, so it is only valid when the projection left the state alone. Returning Projection::Unchanged after modifying the state therefore feeds the next step a derivative taken at a different point.

The default implementation is a no-op and returns Projection::Unchanged.