Skip to main content

carapace_core/model/
error.rs

1use std::fmt;
2
3/// A model that cannot be analyzed as built, found by `Domain::validate`
4/// before any equation is assembled. Node and element indices are insertion
5/// order (the order the objects were added to the `Domain`), so a caller
6/// that created them from a table can map them straight back to a row.
7#[derive(Debug, Clone, Copy, PartialEq)]
8pub enum ModelError {
9    /// A nodal load is applied to a DOF that no element stiffens, that is
10    /// not fixed, that carries no mass and that no constraint uses: the load
11    /// would have nothing to push against and would be silently dropped.
12    LoadOnInactiveDof { node: usize, dof: usize },
13    /// Two constraints define the same slave DOF.
14    DuplicateSlave { node: usize, dof: usize },
15    /// A constraint's slave DOF is also fixed by the user.
16    SlaveIsFixed { node: usize, dof: usize },
17    /// A slave depends on itself, directly or through other slaves.
18    ConstraintCycle { node: usize, dof: usize },
19    /// A constraint master is fixed with a nonzero value: constraints are
20    /// homogeneous and have already eliminated its contribution, so its
21    /// slaves would not follow it. (Prescribing such a DOF later is refused
22    /// by `Domain::can_prescribe` for the same reason.)
23    ConstraintOnPrescribedDof { node: usize, dof: usize },
24    /// A slave's nonzero initial displacement, velocity or acceleration
25    /// disagrees with what its masters imply.
26    InconsistentInitialState { node: usize, dof: usize },
27    /// Nodal mass on a slave that combines several unknowns, which a
28    /// diagonal mass matrix cannot represent.
29    MassOnConstrainedDof { node: usize, dof: usize },
30    /// An element load assigned to an element that cannot carry that kind of
31    /// load (a body force on a beam, a beam load on a continuum element, an
32    /// edge load past the element's last edge).
33    IncompatibleElementLoad { element: usize },
34    /// An element rejected its own geometry or parameters.
35    InvalidElement {
36        element: usize,
37        reason: &'static str,
38    },
39}
40
41impl fmt::Display for ModelError {
42    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43        match self {
44            ModelError::LoadOnInactiveDof { node, dof } => write!(
45                f,
46                "a nodal load is applied to DOF {dof} of node {node}, which no element stiffens \
47                 (and which is not fixed or used by a constraint)"
48            ),
49            ModelError::DuplicateSlave { node, dof } => {
50                write!(f, "DOF {dof} of node {node} is the slave of more than one constraint")
51            }
52            ModelError::SlaveIsFixed { node, dof } => write!(
53                f,
54                "DOF {dof} of node {node} is a constraint slave and is also fixed"
55            ),
56            ModelError::ConstraintCycle { node, dof } => write!(
57                f,
58                "DOF {dof} of node {node} depends on itself through its constraints"
59            ),
60            ModelError::ConstraintOnPrescribedDof { node, dof } => write!(
61                f,
62                "DOF {dof} of node {node} is a constraint master and is fixed at a nonzero value; \
63                 constraints cannot follow a prescribed master"
64            ),
65            ModelError::InconsistentInitialState { node, dof } => write!(
66                f,
67                "DOF {dof} of node {node} is a constraint slave whose initial state disagrees with its masters"
68            ),
69            ModelError::MassOnConstrainedDof { node, dof } => write!(
70                f,
71                "DOF {dof} of node {node} is constrained to several unknowns and carries a nodal mass; \
72                 assign the mass at a master node"
73            ),
74            ModelError::IncompatibleElementLoad { element } => write!(
75                f,
76                "element {element} cannot carry the kind of element load assigned to it"
77            ),
78            ModelError::InvalidElement { element, reason } => {
79                write!(f, "element {element} is invalid: {reason}")
80            }
81        }
82    }
83}
84
85impl std::error::Error for ModelError {}