1use diffsol_la::error::LaError;
2use thiserror::Error;
3
4#[derive(Error, Debug, Clone)]
11pub enum NlError {
12 #[error("Non-linear solver error: {0}")]
13 NonLinearSolverError(#[from] NonLinearSolverError),
14 #[error("Linear algebra error: {0}")]
15 LaError(#[from] LaError),
16 #[error("Error: {0}")]
17 Other(String),
18}
19
20#[derive(Error, Debug, Clone)]
22pub enum NonLinearSolverError {
23 #[error("Initial condition solver did not converge")]
24 InitialConditionDidNotConverge,
25 #[error("Newton iterations did not converge, maximum iterations reached")]
26 NewtonMaxIterations,
27 #[error("Newton iteration diverged")]
28 NewtonDiverged,
29 #[error("Newton linesearch failed to find a suitable step in max iterations")]
30 LinesearchFailedMaxIterations,
31 #[error("Newton linesearch failed, minimum step size reached")]
32 LinesearchFailedMinStep,
33 #[error("LU solve failed")]
34 LuSolveFailed,
35 #[error("Jacobian not reset before calling solve")]
36 JacobianNotReset,
37 #[error("State has wrong length: expected {expected}, got {found}")]
38 WrongStateLength { expected: usize, found: usize },
39 #[error("Error: {0}")]
40 Other(String),
41}
42
43#[macro_export]
44macro_rules! non_linear_solver_error {
45 ($variant:ident) => {
46 $crate::error::NlError::from($crate::error::NonLinearSolverError::$variant)
47 };
48 ($variant:ident, $($arg:tt)*) => {
49 $crate::error::NlError::from($crate::error::NonLinearSolverError::$variant($($arg)*))
50 };
51}