1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//! Provides the [`GeneralIntegrator`](crate::GeneralIntegrator) trait

#[doc(hidden)]
mod integrate;
#[doc(hidden)]
mod runge_kutta_4th;

#[cfg(test)]
mod test_method;

use anyhow::{self, Context};
use nalgebra::DVector;
use numeric_literals::replace_float_literals;

use crate::prepare::prepare;
use crate::{Float, Result, ResultExt, Token};

pub(self) use integrate::integrate;
pub(self) use runge_kutta_4th::runge_kutta_4th;

/// General integrators
pub enum Integrators {
    /// 4th-order Runge-Kutta method
    RungeKutta4th,
}

/// A general integrator for a system of 1st-order ODEs
pub trait Integrator<F: Float> {
    /// Update the current state as defined by a
    /// system of 1st-order ODEs, return the result
    ///
    /// Arguments:
    /// * `t` --- Current time moment;
    /// * `x` --- Current state of the system.
    fn update(&self, t: F, x: &[F]) -> anyhow::Result<Vec<F>>;
    // The rest of the methods are defined by these macros
    integrate!();
    prepare!();
    runge_kutta_4th!();
}