differential_equations/dde/numerical_method.rs
1//! Numerical Methods for solving delay differential equations (DDEs).
2
3use crate::{
4 Error, Status,
5 alias::Evals,
6 dde::DDE,
7 traits::{CallBackData, Real, State},
8};
9
10/// DDENumericalMethod Trait for DDE NumericalMethods
11///
12/// DDE NumericalMethods implement this trait to solve delay differential equations.
13/// The `step` function is called iteratively by a solver function (like `solve_dde`)
14/// to advance the solution.
15///
16pub trait DDENumericalMethod<const L: usize, T, V, H, D = String>
17where
18 T: Real,
19 V: State<T>,
20 H: Fn(T) -> V,
21 D: CallBackData,
22{
23 /// Initialize DDENumericalMethod before solving DDE.
24 ///
25 /// # Arguments
26 /// * `dde` - System of DDEs to solve.
27 /// * `t0` - Initial time.
28 /// * `tf` - Final time.
29 /// * `y0` - Initial state at `t0`.
30 /// * `phi` - Initial history function `phi(t)` returning state `V` for `t <= t0`.
31 ///
32 /// # Returns
33 /// * Result<NumEvals, Error<T, V>> - Ok(evals) if initialization is successful, Err otherwise.
34 ///
35 fn init<F>(&mut self, dde: &F, t0: T, tf: T, y0: &V, phi: H) -> Result<Evals, Error<T, V>>
36 where
37 F: DDE<L, T, V, D>;
38
39 /// Perform one integration step for the DDE.
40 ///
41 /// # Arguments
42 /// * `dde` - System of DDEs to solve.
43 ///
44 /// # Returns
45 /// * Result<NumEvals, Error<T, V>> - Ok(evals) if step is successful, Err otherwise.
46 ///
47 fn step<F>(&mut self, dde: &F) -> Result<Evals, Error<T, V>>
48 where
49 F: DDE<L, T, V, D>;
50
51 // Access fields of the solver
52
53 /// Access time of the current state (end of the last accepted step).
54 fn t(&self) -> T;
55
56 /// Access solution state `y` at the current time `t`.
57 fn y(&self) -> &V;
58
59 /// Access time at the beginning of the last accepted step.
60 fn t_prev(&self) -> T;
61
62 /// Access solution state `y` at the beginning of the last accepted step.
63 fn y_prev(&self) -> &V;
64
65 /// Access the proposed step size `h` for the *next* step attempt.
66 fn h(&self) -> T;
67
68 /// Set the step size `h` for the *next* step attempt.
69 fn set_h(&mut self, h: T);
70
71 /// Get the current status of the solver (Solving, Complete, Error, etc.).
72 fn status(&self) -> &Status<T, V, D>;
73
74 /// Set the status of the solver.
75 fn set_status(&mut self, status: Status<T, V, D>);
76}