differential_equations/
status.rs

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