use crate::models::symmetry::MaterialSymmetry;
use crate::models::tensor::Kinematics;
const MATERIAL_COMPONENTS: &[&str] = &["E", "nu"];
pub(crate) const OPTIONAL_COMPONENTS: &[&str] = &["alpha", "rho"];
pub(crate) const RHO_SLOT: usize = 1;
const ORTHOTROPIC_2D: &[&str] = &[
"E_1", "E_2", "E_3", "nu_12", "nu_13", "nu_23", "G_12", "G_13", "G_23", "V1X", "V1Y",
];
const ORTHOTROPIC_3D: &[&str] = &[
"E_1", "E_2", "E_3", "nu_12", "nu_13", "nu_23", "G_12", "G_13", "G_23", "V1X", "V1Y", "V1Z",
"V2X", "V2Y", "V2Z",
];
const ANISOTROPIC_2D: &[&str] = &[
"C_11", "C_12", "C_13", "C_14", "C_15", "C_16", "C_22", "C_23", "C_24", "C_25", "C_26", "C_33",
"C_34", "C_35", "C_36", "C_44", "C_45", "C_46", "C_55", "C_56", "C_66", "V1X", "V1Y",
];
const ANISOTROPIC_3D: &[&str] = &[
"C_11", "C_12", "C_13", "C_14", "C_15", "C_16", "C_22", "C_23", "C_24", "C_25", "C_26", "C_33",
"C_34", "C_35", "C_36", "C_44", "C_45", "C_46", "C_55", "C_56", "C_66", "V1X", "V1Y", "V1Z",
"V2X", "V2Y", "V2Z",
];
pub(crate) fn material_contract(
symmetry: MaterialSymmetry,
space_dim: usize,
) -> &'static [&'static str] {
match (symmetry, space_dim) {
(MaterialSymmetry::Isotropic, _) => MATERIAL_COMPONENTS,
(MaterialSymmetry::Orthotropic, 2) => ORTHOTROPIC_2D,
(MaterialSymmetry::Orthotropic, _) => ORTHOTROPIC_3D,
(MaterialSymmetry::Anisotropic, 2) => ANISOTROPIC_2D,
(MaterialSymmetry::Anisotropic, _) => ANISOTROPIC_3D,
}
}
pub fn constitutive(e: f64, nu: f64, kinematics: Kinematics, space_dim: usize) -> Vec<Vec<f64>> {
let mut d = [[0.0_f64; 6]; 6];
let v = constitutive_into(e, nu, kinematics, space_dim, &mut d);
d[..v].iter().map(|r| r[..v].to_vec()).collect()
}
pub fn constitutive_into(
e: f64,
nu: f64,
kinematics: Kinematics,
space_dim: usize,
d: &mut [[f64; 6]; 6],
) -> usize {
match (space_dim, kinematics) {
(2, Kinematics::PlaneStress) => {
let c = e / (1.0 - nu * nu);
d[0][0] = c;
d[0][1] = c * nu;
d[1][0] = c * nu;
d[1][1] = c;
d[2][2] = c * (1.0 - nu) / 2.0;
3
}
(2, Kinematics::PlaneStrain) => {
let c = e / ((1.0 + nu) * (1.0 - 2.0 * nu));
d[0][0] = c * (1.0 - nu);
d[0][1] = c * nu;
d[1][0] = c * nu;
d[1][1] = c * (1.0 - nu);
d[2][2] = c * (1.0 - 2.0 * nu) / 2.0;
3
}
(2, Kinematics::Axisymmetric) => {
let c = e / ((1.0 + nu) * (1.0 - 2.0 * nu));
let (d_n, d_off) = (c * (1.0 - nu), c * nu);
for i in 0..3 {
for j in 0..3 {
d[i][j] = if i == j { d_n } else { d_off };
}
}
d[3][3] = c * (1.0 - 2.0 * nu) / 2.0;
4
}
_ => {
let c = e / ((1.0 + nu) * (1.0 - 2.0 * nu));
let g = c * (1.0 - 2.0 * nu) / 2.0;
for i in 0..3 {
for j in 0..3 {
d[i][j] = if i == j { c * (1.0 - nu) } else { c * nu };
}
}
d[3][3] = g;
d[4][4] = g;
d[5][5] = g;
6
}
}
}
pub fn lame(e: f64, nu: f64) -> (f64, f64) {
let lambda = e * nu / ((1.0 + nu) * (1.0 - 2.0 * nu));
let mu = e / (2.0 * (1.0 + nu));
(lambda, mu)
}
pub fn elastic_stress(eps: &[f64; 6], lambda: f64, mu: f64) -> [f64; 6] {
let tr = eps[0] + eps[1] + eps[2];
[
lambda * tr + 2.0 * mu * eps[0],
lambda * tr + 2.0 * mu * eps[1],
lambda * tr + 2.0 * mu * eps[2],
2.0 * mu * eps[3],
2.0 * mu * eps[4],
2.0 * mu * eps[5],
]
}
pub fn elastic_tangent(lambda: f64, mu: f64) -> [[f64; 6]; 6] {
let mut c = [[0.0; 6]; 6];
for i in 0..3 {
for j in 0..3 {
c[i][j] = if i == j { lambda + 2.0 * mu } else { lambda };
}
}
for i in 3..6 {
c[i][i] = mu;
}
c
}