use super::{ElementKind, Facet, Interpolation};
use crate::atoms::ElementType;
pub struct Tet4;
pub(super) const EDGES: &[[usize; 2]] = &[[0, 1], [1, 2], [2, 0], [0, 3], [1, 3], [2, 3]];
const FACETS: &[Facet] = &[
Facet {
element_type: ElementType::TRI3,
nodes: &[1, 2, 3],
},
Facet {
element_type: ElementType::TRI3,
nodes: &[0, 3, 2],
},
Facet {
element_type: ElementType::TRI3,
nodes: &[0, 1, 3],
},
Facet {
element_type: ElementType::TRI3,
nodes: &[0, 2, 1],
},
];
pub(super) fn contains_simplex(xi: &[f64], tol: f64) -> bool {
let (a, b, c) = (xi[0], xi[1], xi[2]);
a >= -tol && b >= -tol && c >= -tol && a + b + c <= 1.0 + tol
}
impl ElementKind for Tet4 {
fn element_type(&self) -> ElementType {
ElementType::TET4
}
fn ref_nodes(&self) -> &'static [&'static [f64]] {
&[
&[0.0, 0.0, 0.0],
&[1.0, 0.0, 0.0],
&[0.0, 1.0, 0.0],
&[0.0, 0.0, 1.0],
]
}
fn reversal_permutation(&self) -> &'static [usize] {
&[0, 2, 1, 3]
}
fn corner_count(&self) -> usize {
4
}
fn facets(&self) -> &'static [Facet] {
FACETS
}
fn edges(&self) -> &'static [[usize; 2]] {
EDGES
}
fn ref_centroid(&self) -> &'static [f64] {
&[0.25, 0.25, 0.25]
}
fn ref_measure(&self) -> f64 {
1.0 / 6.0
}
fn contains_ref(&self, xi: &[f64], tol: f64) -> bool {
contains_simplex(xi, tol)
}
fn clamp_ref(&self, _xi: &mut [f64]) {}
fn degree(&self) -> Option<Interpolation> {
Some(Interpolation::Lagrange1)
}
fn shape_into(&self, xi: &[f64], out: &mut [f64]) {
let (a, b, c) = (xi[0], xi[1], xi[2]);
out[0] = 1.0 - a - b - c;
out[1] = a;
out[2] = b;
out[3] = c;
}
fn dshape_into(&self, _xi: &[f64], out: &mut [f64]) {
out.copy_from_slice(&[
-1.0, -1.0, -1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, ]);
}
fn gauss(&self) -> (Vec<f64>, Vec<f64>) {
let alpha = (5.0 - 5.0_f64.sqrt()) / 20.0;
let beta = (5.0 + 3.0 * 5.0_f64.sqrt()) / 20.0;
(
vec![
alpha, alpha, alpha, beta, alpha, alpha, alpha, beta, alpha, alpha, alpha, beta,
],
vec![1.0 / 24.0; 4],
)
}
fn vtk_code(&self) -> u8 {
10 }
fn gmsh_code(&self) -> u32 {
4
}
fn quadratic(&self) -> Option<ElementType> {
Some(ElementType::TET10)
}
}