differential_equations/
status.rs

1//! Status for solving differential equations
2
3#[cfg(feature = "serde")]
4use serde::{Deserialize, Serialize};
5
6use std::fmt::{Debug, Display};
7
8use crate::{
9    error::Error,
10    traits::{Real, State},
11};
12
13/// Status for solving differential equations
14///
15/// # Variants
16/// * `Uninitialized` - NumericalMethod has not been initialized.
17/// * `Initialized`   - NumericalMethod has been initialized.
18/// * `Error`         - NumericalMethod encountered an error.
19/// * `Solving`       - NumericalMethod is solving.
20/// * `RejectedStep`  - NumericalMethod rejected step.
21/// * `Interrupted`   - NumericalMethod was interrupted by Solout with reason.
22/// * `Complete`      - NumericalMethod completed.
23///
24#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
25#[derive(Debug, PartialEq, Clone)]
26pub enum Status<T, Y>
27where
28    T: Real,
29    Y: State<T>,
30{
31    /// Uninitialized state
32    Uninitialized,
33    /// Initialized state
34    Initialized,
35    /// General Error pass through from solver
36    Error(Error<T, Y>),
37    /// Currently being solved
38    Solving,
39    /// Step was rejected, typically will retry with smaller step size
40    RejectedStep,
41    /// Solver was interrupted by Solout function with reason
42    Interrupted,
43    /// Solver has completed the integration successfully.
44    Complete,
45}
46
47impl<T, Y> Display for Status<T, Y>
48where
49    T: Real + Display,
50    Y: State<T> + Display,
51{
52    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
53        match self {
54            Self::Uninitialized => write!(f, "NumericalMethod: Uninitialized"),
55            Self::Initialized => write!(f, "NumericalMethod: Initialized"),
56            Self::Error(err) => write!(f, "NumericalMethod Error: {}", err),
57            Self::Solving => write!(f, "NumericalMethod: Solving in progress"),
58            Self::RejectedStep => write!(f, "NumericalMethod: Step rejected"),
59            Self::Interrupted => write!(f, "NumericalMethod: Interrupted"),
60            Self::Complete => write!(f, "NumericalMethod: Complete"),
61        }
62    }
63}