differential_equations/ode/
numerical_method.rs

1//! Numerical methods for ODEs.
2
3use crate::{
4    error::Error,
5    ode::ODE,
6    stats::Evals,
7    status::Status,
8    traits::{Real, State},
9};
10
11/// Trait for ODE solvers.
12///
13/// Implemented by types that can solve ODEs via repeated calls to `step`.
14pub trait OrdinaryNumericalMethod<T, Y>
15where
16    T: Real,
17    Y: State<T>,
18{
19    /// Initialize the solver before integration
20    ///
21    /// # Arguments
22    /// * `system` - System of ODEs to solve.
23    /// * `t0`     - Initial time.
24    /// * `tf`     - Final time.
25    /// * `y0`     - Initial state.
26    ///
27    /// # Returns
28    /// * Result<Evals, Error<T, Y>> - Ok if initialization is successful,
29    ///
30    fn init<F>(&mut self, ode: &F, t0: T, tf: T, y0: &Y) -> Result<Evals, Error<T, Y>>
31    where
32        F: ODE<T, Y>;
33
34    /// Advance the solution by one step
35    ///
36    /// # Arguments
37    /// * `system` - System of ODEs to solve.
38    ///
39    /// # Returns
40    /// * Result<Evals, Errors<T, Y>> - Ok if step is successful with the number of function evaluations,
41    ///
42    fn step<F>(&mut self, ode: &F) -> Result<Evals, Error<T, Y>>
43    where
44        F: ODE<T, Y>;
45
46    // Accessors
47
48    /// Time of last accepted step
49    fn t(&self) -> T;
50
51    /// State at last accepted step
52    fn y(&self) -> &Y;
53
54    /// Time of previous accepted step
55    fn t_prev(&self) -> T;
56
57    /// State at previous accepted step
58    fn y_prev(&self) -> &Y;
59
60    /// Step size for next step
61    fn h(&self) -> T;
62
63    /// Set step size for next step
64    fn set_h(&mut self, h: T);
65
66    /// Current solver status
67    fn status(&self) -> &Status<T, Y>;
68
69    /// Set solver status
70    fn set_status(&mut self, status: Status<T, Y>);
71}