conspire/domain/fem/block/element/surface/linear/triangle/
mod.rs

1#[cfg(test)]
2pub mod test;
3
4use crate::{
5    fem::block::element::{
6        ElementNodalEitherCoordinates, FiniteElement, ParametricCoordinate, ParametricCoordinates,
7        ParametricReference, ShapeFunctions, ShapeFunctionsGradients,
8        surface::{M, linear::LinearSurfaceElement},
9    },
10    math::{ScalarList, Tensor},
11};
12use std::f64::consts::FRAC_PI_3;
13
14// When implement G=3, share the methods with cohesive linear wedge.
15
16const G: usize = 1;
17const N: usize = 3;
18const P: usize = N;
19
20pub type Triangle = LinearSurfaceElement<G, N>;
21
22impl FiniteElement<G, M, N, P> for Triangle {
23    fn integration_points() -> ParametricCoordinates<G, M> {
24        [[1.0 / 3.0; M]].into()
25    }
26    fn integration_weights(&self) -> &ScalarList<G> {
27        &self.integration_weights
28    }
29    fn parametric_reference() -> ParametricReference<M, N> {
30        [[0.0, 0.0], [1.0, 0.0], [0.0, 1.0]].into()
31    }
32    fn parametric_weights() -> ScalarList<G> {
33        [1.0 / 2.0; G].into()
34    }
35    fn scaled_jacobians<const I: usize>(
36        nodal_coordinates: ElementNodalEitherCoordinates<I, N>,
37    ) -> ScalarList<P> {
38        let sin_60 = FRAC_PI_3.sin();
39        angles(nodal_coordinates)
40            .into_iter()
41            .map(|angle| angle.sin() / sin_60)
42            .collect()
43    }
44    fn shape_functions(parametric_coordinate: ParametricCoordinate<M>) -> ShapeFunctions<N> {
45        let [xi_1, xi_2] = parametric_coordinate.into();
46        [1.0 - xi_1 - xi_2, xi_1, xi_2].into()
47    }
48    fn shape_functions_gradients(
49        _parametric_coordinate: ParametricCoordinate<M>,
50    ) -> ShapeFunctionsGradients<M, N> {
51        [[-1.0, -1.0], [1.0, 0.0], [0.0, 1.0]].into()
52    }
53}
54
55fn angles<const I: usize>(nodal_coordinates: ElementNodalEitherCoordinates<I, N>) -> ScalarList<N> {
56    let l_10 = (&nodal_coordinates[1] - &nodal_coordinates[0]).normalized();
57    let l_02 = (&nodal_coordinates[0] - &nodal_coordinates[2]).normalized();
58    let l_21 = (&nodal_coordinates[2] - &nodal_coordinates[1]).normalized();
59    [
60        (-&l_02 * &l_10).acos(),
61        (-l_10 * &l_21).acos(),
62        (-l_21 * l_02).acos(),
63    ]
64    .into()
65}