differential_equations/
status.rs

1//! Status for solving differential equations
2
3use std::fmt::{Debug, Display};
4
5use crate::{
6    error::Error,
7    traits::{CallBackData, Real, State},
8};
9
10/// Status for solving differential equations
11///
12/// # Variants
13/// * `Uninitialized` - NumericalMethod has not been initialized.
14/// * `Initialized`   - NumericalMethod has been initialized.
15/// * `Error`         - NumericalMethod encountered an error.
16/// * `Solving`       - NumericalMethod is solving.
17/// * `RejectedStep`  - NumericalMethod rejected step.
18/// * `Interrupted`   - NumericalMethod was interrupted by event with reason.
19/// * `Complete`      - NumericalMethod completed.
20///
21#[derive(Debug, PartialEq, Clone)]
22pub enum Status<T, Y, D>
23where
24    T: Real,
25    Y: State<T>,
26    D: CallBackData,
27{
28    Uninitialized,      // NumericalMethods default to this until solver.init is called
29    Initialized,        // After solver.init is called
30    Error(Error<T, Y>), // If the solver encounters an error, this status is set so solver status is indicated that an error.
31    Solving,            // While the Differential Equation is being solved
32    RejectedStep, // If the solver rejects a step, in this case it will repeat with new smaller step size typically, will return to Solving once the step is accepted
33    Interrupted(D), // If the solver is interrupted by event with reason
34    Complete, // If the solver is solving and has reached the final time of the IMatrix<T, R, C, S>P then Complete is returned to indicate such.
35}
36
37impl<T, Y, D> Display for Status<T, Y, D>
38where
39    T: Real + Display,
40    Y: State<T> + Display,
41    D: CallBackData + Display,
42{
43    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
44        match self {
45            Self::Uninitialized => write!(f, "NumericalMethod: Uninitialized"),
46            Self::Initialized => write!(f, "NumericalMethod: Initialized"),
47            Self::Error(err) => write!(f, "NumericalMethod Error: {}", err),
48            Self::Solving => write!(f, "NumericalMethod: Solving in progress"),
49            Self::RejectedStep => write!(f, "NumericalMethod: Step rejected"),
50            Self::Interrupted(reason) => write!(f, "NumericalMethod: Interrupted - {}", reason),
51            Self::Complete => write!(f, "NumericalMethod: Complete"),
52        }
53    }
54}