use super::penta6::{contains_prism, Penta6, EDGES};
use super::quadrature::{gauss3_1d, tri6_gauss};
use super::{ElementKind, Facet, Interpolation};
use crate::atoms::ElementType;
pub struct Penta15;
const FACETS: &[Facet] = &[
Facet {
element_type: ElementType::TRI6,
nodes: &[0, 2, 1, 8, 7, 6],
},
Facet {
element_type: ElementType::TRI6,
nodes: &[3, 4, 5, 9, 10, 11],
},
Facet {
element_type: ElementType::QUA8,
nodes: &[0, 1, 4, 3, 6, 13, 9, 12],
},
Facet {
element_type: ElementType::QUA8,
nodes: &[1, 2, 5, 4, 7, 14, 10, 13],
},
Facet {
element_type: ElementType::QUA8,
nodes: &[2, 0, 3, 5, 8, 12, 11, 14],
},
];
impl ElementKind for Penta15 {
fn element_type(&self) -> ElementType {
ElementType::PENTA15
}
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],
&[1.0, 0.0, 1.0],
&[0.0, 1.0, 1.0],
&[0.5, 0.0, 0.0],
&[0.5, 0.5, 0.0],
&[0.0, 0.5, 0.0],
&[0.5, 0.0, 1.0],
&[0.5, 0.5, 1.0],
&[0.0, 0.5, 1.0],
&[0.0, 0.0, 0.5],
&[1.0, 0.0, 0.5],
&[0.0, 1.0, 0.5],
]
}
fn reversal_permutation(&self) -> &'static [usize] {
&[0, 2, 1, 3, 5, 4, 8, 7, 6, 11, 10, 9, 12, 14, 13]
}
fn corner_count(&self) -> usize {
6
}
fn facets(&self) -> &'static [Facet] {
FACETS
}
fn edges(&self) -> &'static [[usize; 2]] {
EDGES
}
fn ref_centroid(&self) -> &'static [f64] {
Penta6.ref_centroid()
}
fn ref_measure(&self) -> f64 {
Penta6.ref_measure()
}
fn contains_ref(&self, xi: &[f64], tol: f64) -> bool {
contains_prism(xi, tol)
}
fn clamp_ref(&self, _xi: &mut [f64]) {}
fn degree(&self) -> Option<Interpolation> {
Some(Interpolation::Lagrange2)
}
fn shape_into(&self, xi: &[f64], out: &mut [f64]) {
let (a, b, t) = (xi[0], xi[1], xi[2]);
let (l1, l2, l3) = (1.0 - a - b, a, b);
let bot = |li: f64| li * (2.0 * li - 1.0) * (1.0 - t) - 2.0 * li * t * (1.0 - t);
let top = |li: f64| li * (2.0 * li - 1.0) * t - 2.0 * li * t * (1.0 - t);
out.copy_from_slice(&[
bot(l1),
bot(l2),
bot(l3),
top(l1),
top(l2),
top(l3),
4.0 * l1 * l2 * (1.0 - t), 4.0 * l2 * l3 * (1.0 - t), 4.0 * l3 * l1 * (1.0 - t), 4.0 * l1 * l2 * t, 4.0 * l2 * l3 * t, 4.0 * l3 * l1 * t, 4.0 * l1 * t * (1.0 - t), 4.0 * l2 * t * (1.0 - t), 4.0 * l3 * t * (1.0 - t), ]);
}
fn dshape_into(&self, xi: &[f64], out: &mut [f64]) {
let (a, b, t) = (xi[0], xi[1], xi[2]);
let (l1, l2, l3) = (1.0 - a - b, a, b);
let dl = [[-1.0, -1.0], [1.0, 0.0], [0.0, 1.0]]; let ls = [l1, l2, l3];
let corner = |i: usize, top: bool| {
let li = ls[i];
let f = li * (2.0 * li - 1.0); let coef = if top {
(4.0 * li - 1.0) * t - 2.0 * (t - t * t)
} else {
(4.0 * li - 1.0) * (1.0 - t) - 2.0 * (t - t * t)
};
let dc = if top {
f - 2.0 * li * (1.0 - 2.0 * t)
} else {
-f - 2.0 * li * (1.0 - 2.0 * t)
};
[coef * dl[i][0], coef * dl[i][1], dc]
};
let tri_edge = |i: usize, j: usize, top: bool| {
let (la, lb) = (ls[i], ls[j]);
let zfac = if top { t } else { 1.0 - t };
let da = 4.0 * zfac * (la * dl[j][0] + lb * dl[i][0]);
let db = 4.0 * zfac * (la * dl[j][1] + lb * dl[i][1]);
let dc = if top { 4.0 * la * lb } else { -4.0 * la * lb };
[da, db, dc]
};
let vertical = |i: usize| {
let li = ls[i];
[
4.0 * (t - t * t) * dl[i][0],
4.0 * (t - t * t) * dl[i][1],
4.0 * li * (1.0 - 2.0 * t),
]
};
let rows = [
corner(0, false),
corner(1, false),
corner(2, false),
corner(0, true),
corner(1, true),
corner(2, true),
tri_edge(0, 1, false),
tri_edge(1, 2, false),
tri_edge(2, 0, false),
tri_edge(0, 1, true),
tri_edge(1, 2, true),
tri_edge(2, 0, true),
vertical(0),
vertical(1),
vertical(2),
];
for (i, row) in rows.iter().enumerate() {
out[3 * i..3 * i + 3].copy_from_slice(row);
}
}
fn gauss(&self) -> (Vec<f64>, Vec<f64>) {
let (tri_xi, tri_w) = tri6_gauss();
let (gp, gw) = gauss3_1d();
let mut xi = Vec::with_capacity(18 * 3);
let mut w = Vec::with_capacity(18);
for tg in 0..tri_w.len() {
for k in 0..3 {
xi.push(tri_xi[2 * tg]);
xi.push(tri_xi[2 * tg + 1]);
xi.push(0.5 + 0.5 * gp[k]);
w.push(tri_w[tg] * 0.5 * gw[k]);
}
}
(xi, w)
}
fn vtk_code(&self) -> u8 {
26 }
fn gmsh_code(&self) -> u32 {
18
}
fn med_permutation(&self) -> &'static [usize] {
&[0, 2, 1, 3, 5, 4, 8, 7, 6, 11, 10, 9, 12, 14, 13]
}
fn gmsh_permutation(&self) -> &'static [usize] {
&[0, 1, 2, 3, 4, 5, 6, 9, 7, 12, 14, 13, 8, 10, 11]
}
fn linear_parent(&self) -> Option<ElementType> {
Some(ElementType::PENTA6)
}
}