Skip to content

Commit

Permalink
Add FiniteElement, ElementFamily
Browse files Browse the repository at this point in the history
  • Loading branch information
mscroggs committed Jun 21, 2024
1 parent c92eba0 commit 8fd30c0
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! n-dimensional grid
#![cfg_attr(feature = "strict", deny(warnings))]
#![warn(missing_docs)]

pub mod traits;
5 changes: 5 additions & 0 deletions src/traits.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//! Traits
mod element;

pub use element::{ElementFamily, FiniteElement};
59 changes: 59 additions & 0 deletions src/traits/element.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//! Finite element trait
use rlst::{RandomAccessByRef, RandomAccessMut, RlstScalar, Shape};
use std::fmt::Debug;
use std::hash::Hash;

pub trait FiniteElement {
//! A finite element defined on a reference cell
/// The scalar type
type T: RlstScalar;
/// Cell type
type CellType: Debug + PartialEq + Eq + Clone + Copy + Hash;
/// Map type
type MapType: Debug + PartialEq + Eq + Clone + Copy + Hash;

/// The reference cell type
fn cell_type(&self) -> Self::CellType;

/// The highest degree polynomial in the element's polynomial set
fn embedded_superdegree(&self) -> usize;

/// The number of basis functions
fn dim(&self) -> usize;

/// The value shape
fn value_shape(&self) -> &[usize];

/// The value size
fn value_size(&self) -> usize;

/// Tabulate the values of the basis functions and their derivatives at a set of points
fn tabulate<Array2: RandomAccessByRef<2, Item = <Self::T as RlstScalar>::Real> + Shape<2>>(
&self,
points: &Array2,
nderivs: usize,
data: &mut impl RandomAccessMut<4, Item = Self::T>,
);

/// The DOFs that are associated with a subentity of the reference cell
fn entity_dofs(&self, entity_dim: usize, entity_number: usize) -> Option<&[usize]>;

/// The push forward / pull back map to use for this element
fn map_type(&self) -> Self::MapType;

/// Get the required shape for a tabulation array
fn tabulate_array_shape(&self, nderivs: usize, npoints: usize) -> [usize; 4];
}

pub trait ElementFamily {
//! A family of finite elements
/// The scalar type
type T: RlstScalar;
/// Cell type
type CellType: Debug + PartialEq + Eq + Clone + Copy + Hash;
/// The finite element type
type FiniteElement: FiniteElement<T = Self::T, CellType = Self::CellType>;

/// Get an elenent for a cell type
fn element(&self, cell_type: Self::CellType) -> Self::FiniteElement;
}

0 comments on commit 8fd30c0

Please sign in to comment.