differential_equations/dde/
numerical_method.rs

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