Skip to main content

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 = lagrange::create::<f64, f64>(
11        ReferenceCellType::Triangle,
12        2,
13        Continuity::Standard,
14        lagrange::Variant::Equispaced,
15    );
16
17    println!("This element has {} basis functions.", element.dim());
18
19    // Create an array to store the basis function values
20    let mut basis_values = DynArray::<f64, 4>::from_shape(element.tabulate_array_shape(0, 1));
21    // Create array containing the point [1/3, 1/3]
22    let mut points = rlst_dynamic_array!(f64, [2, 1]);
23    points[[0, 0]] = 1.0 / 3.0;
24    points[[1, 0]] = 1.0 / 3.0;
25    // Tabulate the element's basis functions at the point
26    element.tabulate(&points, 0, &mut basis_values);
27    println!(
28        "The values of the basis functions at the point (1/3, 1/3) are: {:?}",
29        basis_values.data().unwrap()
30    );
31
32    // Set point to [1, 0]
33    points[[0, 0]] = 1.0;
34    points[[1, 0]] = 0.0;
35    // Tabulate the element's basis functions at the point
36    element.tabulate(&points, 0, &mut basis_values);
37    println!(
38        "The values of the basis functions at the point (1, 0) are: {:?}",
39        basis_values.data().unwrap()
40    );
41}