コンテンツにスキップ

Integrator

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

Defined in: integrator.rs:13

pub trait Integrator

Common interface for fixed-step numerical integrators.

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

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

Perform a single integration step, advancing the state from t by dt.


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.