diff --git a/examples/element_family.rs b/examples/element_family.rs new file mode 100644 index 0000000..4241040 --- /dev/null +++ b/examples/element_family.rs @@ -0,0 +1,20 @@ +use ndelement::ciarlet::LagrangeElementFamily; +use ndelement::traits::{ElementFamily, FiniteElement}; +use ndelement::types::{Continuity, ReferenceCellType}; + +extern crate blas_src; +extern crate lapack_src; + +fn main() { + // Create the degree 2 Lagrange element family. A family is a set of finite elements with the + // same family type, degree, and continuity across a set of cells + let family = LagrangeElementFamily::::new(2, Continuity::Continuous); + + // Get the element in the family on a triangle + let element = family.element(ReferenceCellType::Triangle); + println!("Cell: {:?}", element.cell_type()); + + // Get the element in the family on a triangle + let element = family.element(ReferenceCellType::Quadrilateral); + println!("Cell: {:?}", element.cell_type()); +} diff --git a/examples/lagrange_element.rs b/examples/lagrange_element.rs new file mode 100644 index 0000000..49d3f49 --- /dev/null +++ b/examples/lagrange_element.rs @@ -0,0 +1,39 @@ +use ndelement::ciarlet::lagrange; +use ndelement::{ + traits::FiniteElement, + types::{Continuity, ReferenceCellType}, +}; +use rlst::{rlst_dynamic_array2, rlst_dynamic_array4, RawAccess}; + +extern crate blas_src; +extern crate lapack_src; + +fn main() { + // Create a P2 element on a triangle + let element = lagrange::create::(ReferenceCellType::Triangle, 2, Continuity::Continuous); + + println!("This element has {} basis functions.", element.dim()); + + // Create an array to store the basis function values + let mut basis_values = rlst_dynamic_array4!(f64, element.tabulate_array_shape(0, 1)); + // Create array containing the point [1/3, 1/3] + let mut points = rlst_dynamic_array2!(f64, [1, 2]); + points[[0, 0]] = 1.0 / 3.0; + points[[0, 1]] = 1.0 / 3.0; + // Tabulate the element's basis functions at the point + element.tabulate(&points, 0, &mut basis_values); + println!( + "The values of the basis functions at the point (1/3, 1/3) are: {:?}", + basis_values.data() + ); + + // Set point to [1, 0] + points[[0, 0]] = 1.0; + points[[0, 1]] = 0.0; + // Tabulate the element's basis functions at the point + element.tabulate(&points, 0, &mut basis_values); + println!( + "The values of the basis functions at the point (1, 0) are: {:?}", + basis_values.data() + ); +} diff --git a/examples/null.rs b/examples/null.rs deleted file mode 100644 index 1b59178..0000000 --- a/examples/null.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("grid"); -}