Skip to main content

diffeq/
error.rs

1use crate::ode::runge_kutta::WeightType;
2use thiserror::Error;
3
4#[derive(Error, Debug)]
5pub enum OdeError {
6    #[error("{msg}")]
7    Uninitialized { msg: String },
8    #[error("Expected {expected:?} weights, found {found:?} weights")]
9    InvalidButcherTableauWeightType {
10        expected: WeightType,
11        found: WeightType,
12    },
13    #[error(
14        "Encountered NAN after {computation} computations while solving at timestamp {timestamp}"
15    )]
16    NAN { computation: usize, timestamp: f64 },
17    #[error("Zero time span is not allowed")]
18    ZeroTimeSpan,
19    #[error("Initial step has wrong sign")]
20    InvalidInitstep,
21    #[error("Unable to compute matrix operation")]
22    InvalidMatrix,
23}
24
25impl OdeError {
26    pub(crate) fn uninitialized<T: ToString>(s: T) -> Self {
27        OdeError::Uninitialized { msg: s.to_string() }
28    }
29}
30
31/// Enumeration of the errors that may arise during integration.
32#[derive(Error, Debug)]
33pub enum IntegrationError {
34    #[error("Maximum steps reached at {at}, after {n_step} steps")]
35    MaxNumStepReached { at: f64, n_step: u32 },
36    #[error("Encountered step size underflow at {at}")]
37    StepSizeUnderflow { at: f64 },
38    #[error("Stiffness detected at {at}")]
39    StiffnessDetected { at: f64 },
40}