Skip to main content

runmat_meshing/solid/
error.rs

1use runmat_meshing_cad::{CadEvaluationError, CadTopologyError, SourceTopologyError};
2use runmat_meshing_core::{MeshBackendKind, MeshKindRequest, VolumeElementKind};
3use runmat_meshing_curve::{CurveDiscretizationError, CurveValidationError};
4use runmat_meshing_plc::{build::PlcBuildError, validate::PlcValidationError};
5use runmat_meshing_surface::{SurfaceDiscretizationError, SurfaceValidationError};
6use runmat_meshing_tetrahedron::{
7    generate::TetrahedronGenerationError, recover::TetrahedronRecoveryError, structured_grid,
8};
9
10#[derive(Debug)]
11pub enum SolidMeshingError {
12    UnsupportedBackend(MeshBackendKind),
13    UnsupportedMeshKind(MeshKindRequest),
14    UnsupportedElementKind(VolumeElementKind),
15    InvalidElementBudget,
16    InvalidTargetSize,
17    SourceTopology(SourceTopologyError),
18    CadTopology(CadTopologyError),
19    CadEvaluation(CadEvaluationError),
20    Curve(CurveDiscretizationError),
21    CurveValidation(CurveValidationError),
22    Surface(SurfaceDiscretizationError),
23    SurfaceValidation(SurfaceValidationError),
24    ProtectedBoundaryComplex(PlcBuildError),
25    ProtectedBoundaryValidation(PlcValidationError),
26    Tetrahedron(TetrahedronGenerationError),
27    TetrahedronRecovery(TetrahedronRecoveryError),
28    StructuredGrid(structured_grid::MeshingError),
29}
30
31impl std::fmt::Display for SolidMeshingError {
32    fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33        match self {
34            Self::UnsupportedBackend(backend) => {
35                write!(formatter, "unsupported solid meshing backend: {backend:?}")
36            }
37            Self::UnsupportedMeshKind(kind) => {
38                write!(formatter, "unsupported analysis mesh kind: {kind:?}")
39            }
40            Self::UnsupportedElementKind(kind) => {
41                write!(formatter, "unsupported volume element kind: {kind:?}")
42            }
43            Self::InvalidElementBudget => write!(formatter, "max_elements must be greater than 0"),
44            Self::InvalidTargetSize => {
45                write!(
46                    formatter,
47                    "target_size must be auto or a finite positive length"
48                )
49            }
50            Self::SourceTopology(err) => write!(formatter, "source topology failed: {err}"),
51            Self::CadTopology(err) => write!(formatter, "CAD topology failed: {err}"),
52            Self::CadEvaluation(err) => write!(formatter, "CAD evaluation failed: {err}"),
53            Self::Curve(err) => write!(formatter, "curve meshing failed: {err}"),
54            Self::CurveValidation(err) => write!(formatter, "curve validation failed: {err}"),
55            Self::Surface(err) => write!(formatter, "surface meshing failed: {err}"),
56            Self::SurfaceValidation(err) => write!(formatter, "surface validation failed: {err}"),
57            Self::ProtectedBoundaryComplex(err) => write!(formatter, "PLC build failed: {err}"),
58            Self::ProtectedBoundaryValidation(err) => {
59                write!(formatter, "PLC validation failed: {err}")
60            }
61            Self::Tetrahedron(err) => write!(formatter, "Tetrahedron generation failed: {err}"),
62            Self::TetrahedronRecovery(err) => {
63                write!(formatter, "Tetrahedron recovery queue failed: {err}")
64            }
65            Self::StructuredGrid(err) => {
66                write!(
67                    formatter,
68                    "structured-grid Tetrahedron meshing failed: {err}"
69                )
70            }
71        }
72    }
73}
74
75impl std::error::Error for SolidMeshingError {}