Skip to content

Commit

Permalink
copy element-only examples from bempp
Browse files Browse the repository at this point in the history
  • Loading branch information
mscroggs committed Jun 25, 2024
1 parent 27d1f4f commit 48e11b3
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
20 changes: 20 additions & 0 deletions examples/element_family.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use ndelement::ciarlet::LagrangeElementFamily;

Check warning on line 1 in examples/element_family.rs

View workflow job for this annotation

GitHub Actions / Rust style checks (--features "mpi,strict")

Diff in /home/runner/work/ndelement/ndelement/examples/element_family.rs

Check warning on line 1 in examples/element_family.rs

View workflow job for this annotation

GitHub Actions / Rust style checks

Diff in /home/runner/work/ndelement/ndelement/examples/element_family.rs

Check warning on line 1 in examples/element_family.rs

View workflow job for this annotation

GitHub Actions / Rust style checks (--features "mpi,strict")

Diff in /home/runner/work/ndelement/ndelement/examples/element_family.rs

Check warning on line 1 in examples/element_family.rs

View workflow job for this annotation

GitHub Actions / Rust style checks

Diff in /home/runner/work/ndelement/ndelement/examples/element_family.rs
use ndelement::{ReferenceCellType, Continuity};

Check failure on line 2 in examples/element_family.rs

View workflow job for this annotation

GitHub Actions / Run Rust tests (stable, mpich, --features "mpi,strict")

unresolved imports `ndelement::ReferenceCellType`, `ndelement::Continuity`

Check failure on line 2 in examples/element_family.rs

View workflow job for this annotation

GitHub Actions / Run Rust tests (stable, openmpi, --features "mpi,strict")

unresolved imports `ndelement::ReferenceCellType`, `ndelement::Continuity`

Check failure on line 2 in examples/element_family.rs

View workflow job for this annotation

GitHub Actions / Run Rust tests (stable, mpich, --features "mpi,strict")

unresolved imports `ndelement::ReferenceCellType`, `ndelement::Continuity`
use ndelement::traits::{ElementFamily, FiniteElement};

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::<f64>::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());
}
36 changes: 36 additions & 0 deletions examples/lagrange_element.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use ndelement::ciarlet::lagrange;

Check warning on line 1 in examples/lagrange_element.rs

View workflow job for this annotation

GitHub Actions / Rust style checks (--features "mpi,strict")

Diff in /home/runner/work/ndelement/ndelement/examples/lagrange_element.rs

Check warning on line 1 in examples/lagrange_element.rs

View workflow job for this annotation

GitHub Actions / Rust style checks

Diff in /home/runner/work/ndelement/ndelement/examples/lagrange_element.rs

Check warning on line 1 in examples/lagrange_element.rs

View workflow job for this annotation

GitHub Actions / Rust style checks (--features "mpi,strict")

Diff in /home/runner/work/ndelement/ndelement/examples/lagrange_element.rs

Check warning on line 1 in examples/lagrange_element.rs

View workflow job for this annotation

GitHub Actions / Rust style checks

Diff in /home/runner/work/ndelement/ndelement/examples/lagrange_element.rs
use ndelement::{types::{Continuity, ReferenceCellType}, traits::FiniteElement};
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::<f64>(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()
);
}
3 changes: 0 additions & 3 deletions examples/null.rs

This file was deleted.

0 comments on commit 48e11b3

Please sign in to comment.