lagrange_element/
lagrange_element.rs

1use ndelement::ciarlet::lagrange;
2use ndelement::{
3    traits::FiniteElement,
4    types::{Continuity, ReferenceCellType},
5};
6use rlst::{DynArray, rlst_dynamic_array};
7
8fn main() {
9    // Create a P2 element on a triangle
10    let element =
11        lagrange::create::<f64, f64>(ReferenceCellType::Triangle, 2, Continuity::Standard);
12
13    println!("This element has {} basis functions.", element.dim());
14
15    // Create an array to store the basis function values
16    let mut basis_values = DynArray::<f64, 4>::from_shape(element.tabulate_array_shape(0, 1));
17    // Create array containing the point [1/3, 1/3]
18    let mut points = rlst_dynamic_array!(f64, [2, 1]);
19    points[[0, 0]] = 1.0 / 3.0;
20    points[[1, 0]] = 1.0 / 3.0;
21    // Tabulate the element's basis functions at the point
22    element.tabulate(&points, 0, &mut basis_values);
23    println!(
24        "The values of the basis functions at the point (1/3, 1/3) are: {:?}",
25        basis_values.data()
26    );
27
28    // Set point to [1, 0]
29    points[[0, 0]] = 1.0;
30    points[[1, 0]] = 0.0;
31    // Tabulate the element's basis functions at the point
32    element.tabulate(&points, 0, &mut basis_values);
33    println!(
34        "The values of the basis functions at the point (1, 0) are: {:?}",
35        basis_values.data()
36    );
37}