differential_equations/status.rs
1//! Status for solving differential equations
2
3use crate::{
4 Error,
5 traits::{Real, CallBackData},
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, const R: usize, const C: usize, D>
22where
23 T: Real,
24 D: CallBackData,
25{
26 Uninitialized, // NumericalMethods default to this until solver.init is called
27 Initialized, // After solver.init is called
28 Error(Error<T, R, C>), // If the solver encounters an error, this status is set so solver status is indicated that an error.
29 Solving, // While the Differential Equation is being solved
30 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
31 Interrupted(D), // If the solver is interrupted by event with reason
32 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.
33}
34
35impl<T, const R: usize, const C: usize, D> Display for Status<T, R, C, D>
36where
37 T: Real + Display,
38 D: CallBackData + Display,
39{
40 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41 match self {
42 Self::Uninitialized => write!(f, "NumericalMethod: Uninitialized"),
43 Self::Initialized => write!(f, "NumericalMethod: Initialized"),
44 Self::Error(err) => write!(f, "NumericalMethod Error: {}", err),
45 Self::Solving => write!(f, "NumericalMethod: Solving in progress"),
46 Self::RejectedStep => write!(f, "NumericalMethod: Step rejected"),
47 Self::Interrupted(reason) => write!(f, "NumericalMethod: Interrupted - {}", reason),
48 Self::Complete => write!(f, "NumericalMethod: Complete"),
49 }
50 }
51}