Skip to content
This repository was archived by the owner on Dec 2, 2025. It is now read-only.

Commit 2c3a3bc

Browse files
authored
Add MappedFiniteElement trait (#109)
* add MappedFiniteElement trait * doc
1 parent 047b8da commit 2c3a3bc

3 files changed

Lines changed: 54 additions & 35 deletions

File tree

src/bindings.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ pub mod ciarlet {
254254
ciarlet::CiarletElement,
255255
map::{ContravariantPiolaMap, CovariantPiolaMap, IdentityMap},
256256
reference_cell,
257-
traits::{ElementFamily, FiniteElement, Map},
257+
traits::{ElementFamily, FiniteElement, Map, MappedFiniteElement},
258258
types::{Continuity, ReferenceCellType},
259259
};
260260
use c_api_tools::{DType, DTypeIdentifier, cfuncs, concretise_types};
@@ -495,7 +495,7 @@ pub mod ciarlet {
495495
gen_type(name = "maptype", replace_with = ["IdentityMap", "CovariantPiolaMap", "ContravariantPiolaMap"]),
496496
field(arg = 0, name = "element", wrapper = "CiarletElementT", replace_with = ["CiarletElement<{{dtype}}, {{maptype}}>"])
497497
)]
498-
pub fn ciarlet_element_physical_value_size<E: FiniteElement>(
498+
pub fn ciarlet_element_physical_value_size<E: MappedFiniteElement>(
499499
element: &E,
500500
gdim: usize,
501501
) -> usize {
@@ -507,7 +507,7 @@ pub mod ciarlet {
507507
gen_type(name = "maptype", replace_with = ["IdentityMap", "CovariantPiolaMap", "ContravariantPiolaMap"]),
508508
field(arg = 0, name = "element", wrapper = "CiarletElementT", replace_with = ["CiarletElement<{{dtype}}, {{maptype}}>"])
509509
)]
510-
pub fn ciarlet_element_physical_value_rank<E: FiniteElement>(
510+
pub fn ciarlet_element_physical_value_rank<E: MappedFiniteElement>(
511511
element: &E,
512512
gdim: usize,
513513
) -> usize {
@@ -519,7 +519,7 @@ pub mod ciarlet {
519519
gen_type(name = "maptype", replace_with = ["IdentityMap", "CovariantPiolaMap", "ContravariantPiolaMap"]),
520520
field(arg = 0, name = "element", wrapper = "CiarletElementT", replace_with = ["CiarletElement<{{dtype}}, {{maptype}}>"])
521521
)]
522-
pub fn ciarlet_element_physical_value_shape<E: FiniteElement>(
522+
pub fn ciarlet_element_physical_value_shape<E: MappedFiniteElement>(
523523
element: &E,
524524
gdim: usize,
525525
shape: *mut usize,
@@ -537,7 +537,7 @@ pub mod ciarlet {
537537
gen_type(name = "maptype", replace_with = ["IdentityMap", "CovariantPiolaMap", "ContravariantPiolaMap"]),
538538
field(arg = 0, name = "element", wrapper = "CiarletElementT", replace_with = ["CiarletElement<{{dtype}}, {{maptype}}>"])
539539
)]
540-
pub fn ciarlet_element_push_forward<E: FiniteElement<CellType = ReferenceCellType>>(
540+
pub fn ciarlet_element_push_forward<E: MappedFiniteElement<CellType = ReferenceCellType>>(
541541
element: &E,
542542
npoints: usize,
543543
nfunctions: usize,
@@ -606,7 +606,7 @@ pub mod ciarlet {
606606
gen_type(name = "maptype", replace_with = ["IdentityMap", "CovariantPiolaMap", "ContravariantPiolaMap"]),
607607
field(arg = 0, name = "element", wrapper = "CiarletElementT", replace_with = ["CiarletElement<{{dtype}}, {{maptype}}>"])
608608
)]
609-
pub fn ciarlet_element_pull_back<E: FiniteElement<CellType = ReferenceCellType>>(
609+
pub fn ciarlet_element_pull_back<E: MappedFiniteElement<CellType = ReferenceCellType>>(
610610
element: &E,
611611
npoints: usize,
612612
nfunctions: usize,
@@ -685,7 +685,7 @@ pub mod ciarlet {
685685
gen_type(name = "maptype", replace_with = ["IdentityMap", "CovariantPiolaMap", "ContravariantPiolaMap"]),
686686
field(arg = 0, name = "element", wrapper = "CiarletElementT", replace_with = ["CiarletElement<{{dtype}}, {{maptype}}>"])
687687
)]
688-
pub fn ciarlet_element_embedded_superdegree<E: FiniteElement>(element: &E) -> usize {
688+
pub fn ciarlet_element_embedded_superdegree<E: MappedFiniteElement>(element: &E) -> usize {
689689
element.lagrange_superdegree()
690690
}
691691

src/ciarlet.rs

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ extern crate lapack_src;
3232
use crate::math;
3333
use crate::polynomials::{legendre_shape, polynomial_count, tabulate_legendre_polynomials};
3434
use crate::reference_cell;
35-
use crate::traits::{FiniteElement, Map};
35+
use crate::traits::{FiniteElement, Map, MappedFiniteElement};
3636
use crate::types::{Continuity, DofTransformation, ReferenceCellType, Transformation};
3737
use itertools::izip;
3838
use num::{One, Zero};
@@ -621,26 +621,27 @@ where
621621
&self.interpolation_weights
622622
}
623623
}
624+
624625
impl<T: RlstScalar, M: Map> FiniteElement for CiarletElement<T, M> {
625626
type CellType = ReferenceCellType;
626-
type TransformationType = Transformation;
627627
type T = T;
628+
628629
fn value_shape(&self) -> &[usize] {
629630
&self.value_shape
630631
}
632+
631633
fn value_size(&self) -> usize {
632634
self.value_size
633635
}
634636

635637
fn cell_type(&self) -> ReferenceCellType {
636638
self.cell_type
637639
}
638-
fn lagrange_superdegree(&self) -> usize {
639-
self.embedded_superdegree
640-
}
640+
641641
fn dim(&self) -> usize {
642642
self.dim
643643
}
644+
644645
fn tabulate<
645646
Array2Impl: ValueArrayImpl<<Self::T as RlstScalar>::Real, 2>,
646647
Array4MutImpl: MutableArrayImpl<Self::T, 4>,
@@ -681,27 +682,39 @@ impl<T: RlstScalar, M: Map> FiniteElement for CiarletElement<T, M> {
681682
}
682683
}
683684
}
685+
686+
fn tabulate_array_shape(&self, nderivs: usize, npoints: usize) -> [usize; 4] {
687+
let deriv_count = compute_derivative_count(nderivs, self.cell_type());
688+
let point_count = npoints;
689+
let basis_count = self.dim();
690+
let value_size = self.value_size();
691+
[deriv_count, point_count, basis_count, value_size]
692+
}
693+
684694
fn entity_dofs(&self, entity_dim: usize, entity_number: usize) -> Option<&[usize]> {
685695
if entity_dim < 4 && entity_number < self.entity_dofs[entity_dim].len() {
686696
Some(&self.entity_dofs[entity_dim][entity_number])
687697
} else {
688698
None
689699
}
690700
}
701+
691702
fn entity_closure_dofs(&self, entity_dim: usize, entity_number: usize) -> Option<&[usize]> {
692703
if entity_dim < 4 && entity_number < self.entity_closure_dofs[entity_dim].len() {
693704
Some(&self.entity_closure_dofs[entity_dim][entity_number])
694705
} else {
695706
None
696707
}
697708
}
698-
fn tabulate_array_shape(&self, nderivs: usize, npoints: usize) -> [usize; 4] {
699-
let deriv_count = compute_derivative_count(nderivs, self.cell_type());
700-
let point_count = npoints;
701-
let basis_count = self.dim();
702-
let value_size = self.value_size();
703-
[deriv_count, point_count, basis_count, value_size]
709+
}
710+
711+
impl<T: RlstScalar, M: Map> MappedFiniteElement for CiarletElement<T, M> {
712+
type TransformationType = Transformation;
713+
714+
fn lagrange_superdegree(&self) -> usize {
715+
self.embedded_superdegree
704716
}
717+
705718
fn push_forward<
706719
Array3RealImpl: ValueArrayImpl<<Self::T as RlstScalar>::Real, 3>,
707720
Array4Impl: ValueArrayImpl<Self::T, 4>,
@@ -724,6 +737,7 @@ impl<T: RlstScalar, M: Map> FiniteElement for CiarletElement<T, M> {
724737
physical_values,
725738
)
726739
}
740+
727741
fn pull_back<
728742
Array3RealImpl: ValueArrayImpl<<Self::T as RlstScalar>::Real, 3>,
729743
Array4Impl: ValueArrayImpl<Self::T, 4>,
@@ -746,9 +760,11 @@ impl<T: RlstScalar, M: Map> FiniteElement for CiarletElement<T, M> {
746760
reference_values,
747761
)
748762
}
763+
749764
fn physical_value_shape(&self, gdim: usize) -> Vec<usize> {
750765
self.map.physical_value_shape(gdim)
751766
}
767+
752768
fn dof_transformation(
753769
&self,
754770
entity: ReferenceCellType,

src/traits.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rlst::{Array, MutableArrayImpl, RlstScalar, ValueArrayImpl};
44
use std::fmt::Debug;
55
use std::hash::Hash;
66

7-
/// This trait provides the definition of a finite element.
7+
/// A finite element.
88
pub trait FiniteElement {
99
/// The scalar type
1010
type T: RlstScalar;
@@ -14,21 +14,9 @@ pub trait FiniteElement {
1414
/// The cell type is typically defined through [ReferenceCellType](crate::types::ReferenceCellType).
1515
type CellType: Debug + PartialEq + Eq + Clone + Copy + Hash;
1616

17-
/// Transformation type
18-
///
19-
/// The Transformation type specifies possible transformations of the dofs on the reference element.
20-
/// In most cases these will be rotations and reflections as defined in [Transformation](crate::types::Transformation).
21-
type TransformationType: Debug + PartialEq + Eq + Clone + Copy + Hash;
22-
2317
/// The reference cell type, eg one of `Point`, `Interval`, `Triangle`, etc.
2418
fn cell_type(&self) -> Self::CellType;
2519

26-
/// The smallest degree Lagrange space that contains all possible polynomials of the finite element's polynomial space.
27-
///
28-
/// Details on the definition of the degree of Lagrange spaces of finite elements are
29-
/// given [here](https://defelement.org/ciarlet.html#The+degree+of+a+finite+element).
30-
fn lagrange_superdegree(&self) -> usize;
31-
3220
/// The number of basis functions.
3321
fn dim(&self) -> usize;
3422

@@ -75,6 +63,9 @@ pub trait FiniteElement {
7563
data: &mut Array<Array4MutImpl, 4>,
7664
);
7765

66+
/// Get the required shape for a tabulation array.
67+
fn tabulate_array_shape(&self, nderivs: usize, npoints: usize) -> [usize; 4];
68+
7869
/// Return the dof indices that are associated with the subentity with index `entity_number` and dimension `entity_dim`.
7970
///
8071
/// - For `entity_dim = 0` this returns the degrees of freedom (dofs) associated with the corresponding point.
@@ -92,9 +83,21 @@ pub trait FiniteElement {
9283
/// associated with the boundary of an entity. For an edge (for example) it returns the dofs associated
9384
/// with the vertices at the boundary of the edge (as well as the dofs associated with the edge itself).
9485
fn entity_closure_dofs(&self, entity_dim: usize, entity_number: usize) -> Option<&[usize]>;
86+
}
9587

96-
/// Get the required shape for a tabulation array.
97-
fn tabulate_array_shape(&self, nderivs: usize, npoints: usize) -> [usize; 4];
88+
/// A finite element that is mapped from a reference cell.
89+
pub trait MappedFiniteElement: FiniteElement {
90+
/// Transformation type
91+
///
92+
/// The Transformation type specifies possible transformations of the dofs on the reference element.
93+
/// In most cases these will be rotations and reflections as defined in [Transformation](crate::types::Transformation).
94+
type TransformationType: Debug + PartialEq + Eq + Clone + Copy + Hash;
95+
96+
/// The smallest degree Lagrange space that contains all possible polynomials of the finite element's polynomial space.
97+
///
98+
/// Details on the definition of the degree of Lagrange spaces of finite elements are
99+
/// given [here](https://defelement.org/ciarlet.html#The+degree+of+a+finite+element).
100+
fn lagrange_superdegree(&self) -> usize;
98101

99102
/// Push function values forward to a physical cell.
100103
///
@@ -117,7 +120,7 @@ pub trait FiniteElement {
117120
/// is the topological dimension, and the third dimension is the geometric dimension. If the Jacobian is rectangular then the
118121
/// inverse Jacobian is the pseudo-inverse of the Jacobian, ie the matrix $J^\dagger$ such that $J^\dagger J = I$.
119122
/// - `physical_values`: The output array of the push operation. This shape of this array is the same as the `reference_values`
120-
/// input, with the [FiniteElement::physical_value_size] used instead of the reference value size.
123+
/// input, with the [MappedFiniteElement::physical_value_size] used instead of the reference value size.
121124
fn push_forward<
122125
Array3RealImpl: ValueArrayImpl<<Self::T as RlstScalar>::Real, 3>,
123126
Array4Impl: ValueArrayImpl<Self::T, 4>,
@@ -134,7 +137,7 @@ pub trait FiniteElement {
134137

135138
/// Pull function values back to the reference cell.
136139
///
137-
/// This is the inverse operation to [FiniteElement::push_forward].
140+
/// This is the inverse operation to [MappedFiniteElement::push_forward].
138141
fn pull_back<
139142
Array3RealImpl: ValueArrayImpl<<Self::T as RlstScalar>::Real, 3>,
140143
Array4Impl: ValueArrayImpl<Self::T, 4>,

0 commit comments

Comments
 (0)