Skip to main content

scirs2_integrate/pde/
error.rs

1use std::error::Error;
2use std::fmt;
3
4use crate::error::IntegrateError;
5
6/// Errors that may occur in PDE-related operations
7#[derive(Debug)]
8pub enum PDEError {
9    /// Error with boundary conditions specification
10    BoundaryConditions(String),
11
12    /// Error with domain specification
13    DomainError(String),
14
15    /// Error with discretization
16    DiscretizationError(String),
17
18    /// Error with method of lines integration
19    MOLError(String),
20
21    /// Error with finite difference computation
22    FiniteDifferenceError(String),
23
24    /// Error with finite element computation
25    FiniteElementError(String),
26
27    /// Error with spectral method computation
28    SpectralError(String),
29
30    /// Error with grid specification or configuration
31    InvalidGrid(String),
32
33    /// Error with parameter specification
34    InvalidParameter(String),
35
36    /// General computation error
37    ComputationError(String),
38
39    /// Underlying ODE solver error during method of lines integration
40    ODEError(IntegrateError),
41
42    /// Other PDE-related errors
43    Other(String),
44}
45
46impl fmt::Display for PDEError {
47    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48        match self {
49            PDEError::BoundaryConditions(msg) => write!(f, "Boundary condition error: {msg}"),
50            PDEError::DomainError(msg) => write!(f, "Domain error: {msg}"),
51            PDEError::DiscretizationError(msg) => write!(f, "Discretization error: {msg}"),
52            PDEError::MOLError(msg) => write!(f, "Method of lines error: {msg}"),
53            PDEError::FiniteDifferenceError(msg) => write!(f, "Finite difference error: {msg}"),
54            PDEError::FiniteElementError(msg) => write!(f, "Finite element error: {msg}"),
55            PDEError::SpectralError(msg) => write!(f, "Spectral method error: {msg}"),
56            PDEError::InvalidGrid(msg) => write!(f, "Invalid grid error: {msg}"),
57            PDEError::InvalidParameter(msg) => write!(f, "Invalid parameter error: {msg}"),
58            PDEError::ComputationError(msg) => write!(f, "Computation error: {msg}"),
59            PDEError::ODEError(err) => write!(f, "ODE solver error: {err}"),
60            PDEError::Other(msg) => write!(f, "PDE error: {msg}"),
61        }
62    }
63}
64
65impl Error for PDEError {}
66
67/// Result type for PDE operations
68pub type PDEResult<T> = Result<T, PDEError>;
69
70// Conversion from IntegrateError to PDEError
71impl From<IntegrateError> for PDEError {
72    fn from(err: IntegrateError) -> Self {
73        PDEError::ODEError(err)
74    }
75}