use core::fmt;
use core::str::FromStr;
use crate::Error;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum Hypothesis {
AxisymmetricalGeneralisedPlaneStrain,
AxisymmetricalGeneralisedPlaneStress,
Axisymmetrical,
PlaneStress,
PlaneStrain,
GeneralisedPlaneStrain,
Tridimensional,
}
impl Hypothesis {
pub const ALL: [Hypothesis; 7] = [
Hypothesis::AxisymmetricalGeneralisedPlaneStrain,
Hypothesis::AxisymmetricalGeneralisedPlaneStress,
Hypothesis::Axisymmetrical,
Hypothesis::PlaneStress,
Hypothesis::PlaneStrain,
Hypothesis::GeneralisedPlaneStrain,
Hypothesis::Tridimensional,
];
pub const fn name(self) -> &'static str {
match self {
Hypothesis::AxisymmetricalGeneralisedPlaneStrain => {
"AxisymmetricalGeneralisedPlaneStrain"
}
Hypothesis::AxisymmetricalGeneralisedPlaneStress => {
"AxisymmetricalGeneralisedPlaneStress"
}
Hypothesis::Axisymmetrical => "Axisymmetrical",
Hypothesis::PlaneStress => "PlaneStress",
Hypothesis::PlaneStrain => "PlaneStrain",
Hypothesis::GeneralisedPlaneStrain => "GeneralisedPlaneStrain",
Hypothesis::Tridimensional => "Tridimensional",
}
}
pub const fn space_dimension(self) -> usize {
match self {
Hypothesis::AxisymmetricalGeneralisedPlaneStrain
| Hypothesis::AxisymmetricalGeneralisedPlaneStress => 1,
Hypothesis::Axisymmetrical
| Hypothesis::PlaneStress
| Hypothesis::PlaneStrain
| Hypothesis::GeneralisedPlaneStrain => 2,
Hypothesis::Tridimensional => 3,
}
}
}
impl fmt::Display for Hypothesis {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.name())
}
}
impl FromStr for Hypothesis {
type Err = Error;
fn from_str(s: &str) -> Result<Self, Error> {
Hypothesis::ALL
.into_iter()
.find(|h| h.name() == s)
.ok_or_else(|| Error::UnknownHypothesis(s.to_owned()))
}
}