Skip to main content

scirs2_integrate/ode/
error.rs

1//! Error types for ODE solvers.
2
3use std::error::Error;
4use std::fmt;
5
6/// Errors that can occur during ODE solving.
7#[derive(Debug)]
8pub enum ODEError {
9    /// The solver failed to converge to a solution.
10    Convergence,
11    /// The step size became too small.
12    StepSizeTooSmall,
13    /// The solver exceeded the maximum number of steps.
14    MaxStepsExceeded,
15    /// The solver encountered NaN or Inf values.
16    NumericalInstability,
17    /// An invalid input was provided to the solver.
18    InvalidInput(String),
19    /// A general error occurred.
20    General(String),
21}
22
23impl fmt::Display for ODEError {
24    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25        match self {
26            ODEError::Convergence => write!(f, "Failed to converge to a solution"),
27            ODEError::StepSizeTooSmall => write!(f, "Step size became too small"),
28            ODEError::MaxStepsExceeded => write!(f, "Exceeded maximum number of steps"),
29            ODEError::NumericalInstability => {
30                write!(f, "Encountered numerical instability (NaN or Inf)")
31            }
32            ODEError::InvalidInput(msg) => write!(f, "Invalid input: {}", msg),
33            ODEError::General(msg) => write!(f, "Error: {}", msg),
34        }
35    }
36}
37
38impl Error for ODEError {}