コンテンツにスキップ

Integrator

このコンテンツはまだ日本語訳がありません。

Defined in: integrator.rs:15

pub trait Integrator

Common interface for fixed-step numerical integrators.

Implementors provide step_unprojected(Integrator::step_unprojected), which advances the state by a single time step and leaves the result raw. Default implementations of step(Integrator::step), integrate(Integrator::integrate) and integrate_with_events(Integrator::integrate_with_events) build on it to provide multi-step integration with optional event detection.

fn step_unprojected<S: DynamicalSystem>(&self, system: &S, t: f64, state: &::State, dt: f64) -> ::State

One integration step from t by dt, without the post-step projection.

This is the raw candidate the method produced. A root-event search reads it: OdeState::project(crate::OdeState::project) pulls a state back onto its constraint surface, and can erase the very sign change that shows a boundary was crossed. It is also what the search re-steps with while narrowing a bracket, so the states it tries are never projected.


fn step<S: DynamicalSystem>(&self, system: &S, t: f64, state: &::State, dt: f64) -> ::State

One integration step from t by dt, projected.

What a caller stepping by hand wants: the state is the one a walk would publish. A fixed-step method keeps no stage derivative across steps, so whether the projection changed anything does not matter here.


fn integrate<S, F>(&self, system: &S, initial: ::State, t0: f64, t_end: f64, dt: f64, callback: F) -> ::State where S: DynamicalSystem, F: FnMut(f64, &::State)

Integrate a dynamical system from t0 to t_end using fixed step size dt.

Calls callback(t, &state) after each step, allowing the caller to record intermediate states (e.g., for energy monitoring or trajectory output).

Returns the final state at t_end.

Panics if the arguments cannot produce a terminating integration — dt <= 0, a non-finite dt, t_end < t0, or a dt so small relative to t that t + dt rounds back to t — and if a step produces a non-finite state. Use try_integrate(Integrator::try_integrate) to handle those cases without panicking. Previously the invalid arguments spun forever and the non-finite state ran to the end of the span.


fn try_integrate<S, F>(&self, system: &S, initial: ::State, t0: f64, t_end: f64, dt: f64, callback: F) -> [Result<::State, IntegrationError>](https://doc.rust-lang.org/std/result/enum.Result.html) where S: DynamicalSystem, F: FnMut(f64, &::State)

Fallible variant of integrate(Integrator::integrate).

Returns Err instead of panicking when the step size or time span cannot produce a terminating integration, and stops with IntegrationError::NonFiniteState at the first step whose result is not finite — the state after that step is not a trajectory, and every step taken from it is wasted.


fn integrate_with_events<S, F, E, B>(&self, system: &S, initial: ::State, t0: f64, t_end: f64, dt: f64, callback: F, event_check: E) -> IntegrationOutcome<::State, B> where S: DynamicalSystem, F: FnMut(f64, &::State), E: [Fn(f64, &::State) -> ControlFlow<B>](https://doc.rust-lang.org/std/ops/function/trait.Fn.html)

Integrate a dynamical system with event detection and NaN/Inf checking.

For a span that advances, event_check(t0, &initial) runs first, before any step: a level-triggered event can already hold at t0, and reporting it after a step would name a state the predicate itself rejects. Terminating there returns the initial state at t0 and calls no callback, since the callback reports accepted steps and none was taken. A span with t0 == t_end takes no step, so it asks nothing and returns the initial state as it came in.

Then, after each step:

  1. Checks for NaN/Inf in state → returns IntegrationOutcome::Error
  2. Calls callback(t, &state)
  3. Calls event_check(t, &state) → if Break(reason), returns Terminated

fn stepper<‘a, S: DynamicalSystem>(&‘a self, system: &‘a S, initial: ::State, t0: f64, dt: f64) -> FixedStepper<‘a, Self, S>

A stepper that advances this solver towards one target time after another, in steps of dt from t0.

For a loop that decides where to stop as it goes — one checking events per step, or splitting its span at the discontinuities a Segments(crate::Segments) walk finds. The whole-span loops above are this stepper driven to t_end in one call.