#![allow(missing_docs)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[allow(dead_code)]
pub enum MaterialClass {
Elastic,
Plastic,
Viscous,
}
#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct PyMaterial {
pub name: String,
pub class: MaterialClass,
pub young_modulus: f64,
pub poisson_ratio: f64,
pub density: f64,
pub yield_stress: Option<f64>,
pub hardening_modulus: Option<f64>,
pub viscosity: Option<f64>,
}
impl PyMaterial {
pub fn elastic(name: &str, young: f64, poisson: f64, density: f64) -> Self {
Self {
name: name.to_owned(),
class: MaterialClass::Elastic,
young_modulus: young,
poisson_ratio: poisson,
density,
yield_stress: None,
hardening_modulus: None,
viscosity: None,
}
}
pub fn plastic(
name: &str,
young: f64,
poisson: f64,
density: f64,
yield_stress: f64,
hardening: f64,
) -> Self {
Self {
name: name.to_owned(),
class: MaterialClass::Plastic,
young_modulus: young,
poisson_ratio: poisson,
density,
yield_stress: Some(yield_stress),
hardening_modulus: Some(hardening),
viscosity: None,
}
}
pub fn viscous_fluid(name: &str, density: f64, viscosity: f64) -> Self {
Self {
name: name.to_owned(),
class: MaterialClass::Viscous,
young_modulus: 0.0,
poisson_ratio: 0.0,
density,
yield_stress: None,
hardening_modulus: None,
viscosity: Some(viscosity),
}
}
pub fn steel() -> Self {
Self::elastic("Steel", 200.0e9, 0.3, 7850.0)
}
pub fn aluminium() -> Self {
Self::elastic("Aluminium 6061", 69.0e9, 0.33, 2700.0)
}
pub fn rubber() -> Self {
Self::elastic("Natural Rubber", 0.05e9, 0.49, 920.0)
}
pub fn concrete() -> Self {
Self::elastic("Concrete", 30.0e9, 0.2, 2400.0)
}
pub fn titanium() -> Self {
Self::elastic("Titanium Ti-6Al-4V", 114.0e9, 0.34, 4430.0)
}
pub fn water() -> Self {
Self::viscous_fluid("Water (20°C)", 998.2, 1.002e-3)
}
pub fn air() -> Self {
Self::viscous_fluid("Air (20°C, 1 atm)", 1.204, 1.81e-5)
}
pub fn shear_modulus(&self) -> f64 {
self.young_modulus / (2.0 * (1.0 + self.poisson_ratio))
}
pub fn bulk_modulus(&self) -> f64 {
self.young_modulus / (3.0 * (1.0 - 2.0 * self.poisson_ratio))
}
pub fn lame_lambda(&self) -> f64 {
let e = self.young_modulus;
let nu = self.poisson_ratio;
e * nu / ((1.0 + nu) * (1.0 - 2.0 * nu))
}
pub fn p_wave_speed(&self) -> f64 {
let k = self.bulk_modulus();
let g = self.shear_modulus();
let m_modulus = k + 4.0 / 3.0 * g;
if self.density > 0.0 {
(m_modulus / self.density).sqrt()
} else {
0.0
}
}
}