Skip to content

Commit

Permalink
WIP: Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
tbetcke committed Jun 19, 2024
1 parent b073d89 commit bf92657
Show file tree
Hide file tree
Showing 32 changed files with 2,024 additions and 2,122 deletions.
6 changes: 3 additions & 3 deletions examples/element_family.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bempp::element::ciarlet::LagrangeElementFamily;
use bempp::traits::{
element::{Continuity, ElementFamily, FiniteElement},
types::ReferenceCellType,
types::ReferenceCell,
};

extern crate blas_src;
Expand All @@ -13,10 +13,10 @@ fn main() {
let family = LagrangeElementFamily::<f64>::new(2, Continuity::Continuous);

// Get the element in the family on a triangle
let element = family.element(ReferenceCellType::Triangle);
let element = family.element(ReferenceCell::Triangle);
println!("Cell: {:?}", element.cell_type());

// Get the element in the family on a triangle
let element = family.element(ReferenceCellType::Quadrilateral);
let element = family.element(ReferenceCell::Quadrilateral);
println!("Cell: {:?}", element.cell_type());
}
70 changes: 36 additions & 34 deletions examples/flat_triangle_grid.rs
Original file line number Diff line number Diff line change
@@ -1,43 +1,45 @@
use bempp::grid::flat_triangle_grid::FlatTriangleGridBuilder;
use bempp::traits::grid::{Builder, Cell, Geometry, Grid, Point};
// use bempp::grid::flat_triangle_grid::FlatTriangleGridBuilder;
// use bempp::traits::grid::{Builder, Cell, Geometry, Grid, Point};

extern crate blas_src;
extern crate lapack_src;

/// Creating a flat triangle grid
///
/// In a flat triangle grid, all the cells are flat triangles in 3D space.
fn main() {
// The grid will be created using the grid builder
let mut b = FlatTriangleGridBuilder::<f64>::new();
// Add four points, giving them the ids 1 to 4
b.add_point(1, [0.0, 0.0, 0.0]);
b.add_point(2, [1.0, 0.0, 1.0]);
b.add_point(3, [1.0, 1.0, 0.0]);
b.add_point(4, [0.0, 1.0, 0.0]);
// Add two cells. The vertex ids used above are used to define the cells
b.add_cell(0, [1, 2, 3]);
b.add_cell(1, [2, 3, 4]);
// Create the grid
let grid = b.create_grid();
// fn main() {
// // The grid will be created using the grid builder
// let mut b = FlatTriangleGridBuilder::<f64>::new();
// // Add four points, giving them the ids 1 to 4
// b.add_point(1, [0.0, 0.0, 0.0]);
// b.add_point(2, [1.0, 0.0, 1.0]);
// b.add_point(3, [1.0, 1.0, 0.0]);
// b.add_point(4, [0.0, 1.0, 0.0]);
// // Add two cells. The vertex ids used above are used to define the cells
// b.add_cell(0, [1, 2, 3]);
// b.add_cell(1, [2, 3, 4]);
// // Create the grid
// let grid = b.create_grid();

// Print the coordinates or each point in the mesh. Note that that point indices
// start from 0 and are not equal to the ids used when inputting the points
let mut coords = vec![0.0; grid.physical_dimension()];
for point in grid.iter_all_points() {
point.coords(coords.as_mut_slice());
println!("point {} (id {}): {:#?}", point.index(), point.id(), coords);
}
// // Print the coordinates or each point in the mesh. Note that that point indices
// // start from 0 and are not equal to the ids used when inputting the points
// let mut coords = vec![0.0; grid.physical_dimension()];
// for point in grid.iter_all_points() {
// point.coords(coords.as_mut_slice());
// println!("point {} (id {}): {:#?}", point.index(), point.id(), coords);
// }

// Print the vertices of each cell
for cell in grid.iter_all_cells() {
println!(
"cell {}: {:?} ",
cell.index(),
cell.geometry()
.vertices()
.map(|v| v.index())
.collect::<Vec<_>>()
);
}
}
// // Print the vertices of each cell
// for cell in grid.iter_all_cells() {
// println!(
// "cell {}: {:?} ",
// cell.index(),
// cell.geometry()
// .vertices()
// .map(|v| v.index())
// .collect::<Vec<_>>()
// );
// }
// }

pub fn main() {}
4 changes: 2 additions & 2 deletions examples/lagrange_element.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bempp::element::ciarlet::lagrange;
use bempp::traits::{
element::{Continuity, FiniteElement},
types::ReferenceCellType,
types::ReferenceCell,
};
use rlst::{rlst_dynamic_array2, rlst_dynamic_array4, RawAccess};

Expand All @@ -10,7 +10,7 @@ extern crate lapack_src;

fn main() {
// Create a P2 element on a triangle
let element = lagrange::create::<f64>(ReferenceCellType::Triangle, 2, Continuity::Continuous);
let element = lagrange::create::<f64>(ReferenceCell::Triangle, 2, Continuity::Continuous);

println!("This element has {} basis functions.", element.dim());

Expand Down
2 changes: 1 addition & 1 deletion examples/test_parallel_grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use bempp::{
element::Continuity,
function::FunctionSpace,
grid::{Builder, Cell, Geometry, Grid, ParallelBuilder, Point},
types::{Ownership, ReferenceCellType},
types::{Ownership, ReferenceCell},
},
};
#[cfg(feature = "mpi")]
Expand Down
118 changes: 48 additions & 70 deletions src/element/ciarlet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::element::polynomials::{
};
use crate::element::reference_cell;
use crate::traits::element::{Continuity, FiniteElement, MapType};
use crate::traits::types::ReferenceCellType;
use crate::traits::types::ReferenceCell;
use rlst::LinAlg;
use rlst::{
rlst_dynamic_array2, rlst_dynamic_array3, Array, BaseArray, RandomAccessByRef, RandomAccessMut,
Expand All @@ -22,7 +22,7 @@ type EntityWeights<T> = [Vec<Array<T, BaseArray<T, VectorContainer<T>, 3>, 3>>;

/// A Ciarlet element
pub struct CiarletElement<T: RlstScalar> {
cell_type: ReferenceCellType,
cell_type: ReferenceCell,
degree: usize,
embedded_superdegree: usize,
map_type: MapType,
Expand All @@ -43,7 +43,7 @@ where
/// Create a Ciarlet element
#[allow(clippy::too_many_arguments)]
pub fn create(
cell_type: ReferenceCellType,
cell_type: ReferenceCell,
degree: usize,
value_shape: Vec<usize>,
polynomial_coeffs: Array<T, BaseArray<T, VectorContainer<T>, 3>, 3>,
Expand Down Expand Up @@ -243,7 +243,7 @@ impl<T: RlstScalar> FiniteElement for CiarletElement<T> {
self.map_type
}

fn cell_type(&self) -> ReferenceCellType {
fn cell_type(&self) -> ReferenceCell {
self.cell_type
}
fn embedded_superdegree(&self) -> usize {
Expand Down Expand Up @@ -306,14 +306,14 @@ mod test {
fn check_dofs(e: impl FiniteElement) {
let mut ndofs = 0;
for (dim, entity_count) in match e.cell_type() {
ReferenceCellType::Point => vec![1],
ReferenceCellType::Interval => vec![2, 1],
ReferenceCellType::Triangle => vec![3, 3, 1],
ReferenceCellType::Quadrilateral => vec![4, 4, 1],
ReferenceCellType::Tetrahedron => vec![4, 6, 4, 1],
ReferenceCellType::Hexahedron => vec![8, 12, 6, 1],
ReferenceCellType::Prism => vec![6, 9, 5, 1],
ReferenceCellType::Pyramid => vec![5, 8, 5, 1],
ReferenceCell::Point => vec![1],
ReferenceCell::Interval => vec![2, 1],
ReferenceCell::Triangle => vec![3, 3, 1],
ReferenceCell::Quadrilateral => vec![4, 4, 1],
ReferenceCell::Tetrahedron => vec![4, 6, 4, 1],
ReferenceCell::Hexahedron => vec![8, 12, 6, 1],
ReferenceCell::Prism => vec![6, 9, 5, 1],
ReferenceCell::Pyramid => vec![5, 8, 5, 1],
}
.iter()
.enumerate()
Expand All @@ -327,13 +327,13 @@ mod test {

#[test]
fn test_lagrange_1() {
let e = lagrange::create::<f64>(ReferenceCellType::Triangle, 1, Continuity::Continuous);
let e = lagrange::create::<f64>(ReferenceCell::Triangle, 1, Continuity::Continuous);
assert_eq!(e.value_size(), 1);
}

#[test]
fn test_lagrange_0_interval() {
let e = lagrange::create::<f64>(ReferenceCellType::Interval, 0, Continuity::Discontinuous);
let e = lagrange::create::<f64>(ReferenceCell::Interval, 0, Continuity::Discontinuous);
assert_eq!(e.value_size(), 1);
let mut data = rlst_dynamic_array4!(f64, e.tabulate_array_shape(0, 4));
let mut points = rlst_dynamic_array2!(f64, [4, 1]);
Expand All @@ -351,7 +351,7 @@ mod test {

#[test]
fn test_lagrange_1_interval() {
let e = lagrange::create::<f64>(ReferenceCellType::Interval, 1, Continuity::Continuous);
let e = lagrange::create::<f64>(ReferenceCell::Interval, 1, Continuity::Continuous);
assert_eq!(e.value_size(), 1);
let mut data = rlst_dynamic_array4!(f64, e.tabulate_array_shape(0, 4));
let mut points = rlst_dynamic_array2!(f64, [4, 1]);
Expand All @@ -376,7 +376,7 @@ mod test {

#[test]
fn test_lagrange_0_triangle() {
let e = lagrange::create::<f64>(ReferenceCellType::Triangle, 0, Continuity::Discontinuous);
let e = lagrange::create::<f64>(ReferenceCell::Triangle, 0, Continuity::Discontinuous);
assert_eq!(e.value_size(), 1);
let mut data = rlst_dynamic_array4!(f64, e.tabulate_array_shape(0, 6));

Expand Down Expand Up @@ -404,7 +404,7 @@ mod test {

#[test]
fn test_lagrange_1_triangle() {
let e = lagrange::create::<f64>(ReferenceCellType::Triangle, 1, Continuity::Continuous);
let e = lagrange::create::<f64>(ReferenceCell::Triangle, 1, Continuity::Continuous);
assert_eq!(e.value_size(), 1);
let mut data = rlst_dynamic_array4!(f64, e.tabulate_array_shape(0, 6));
let mut points = rlst_dynamic_array2!(f64, [6, 2]);
Expand Down Expand Up @@ -441,66 +441,46 @@ mod test {

#[test]
fn test_lagrange_higher_degree_triangle() {
lagrange::create::<f64>(ReferenceCellType::Triangle, 2, Continuity::Continuous);
lagrange::create::<f64>(ReferenceCellType::Triangle, 3, Continuity::Continuous);
lagrange::create::<f64>(ReferenceCellType::Triangle, 4, Continuity::Continuous);
lagrange::create::<f64>(ReferenceCellType::Triangle, 5, Continuity::Continuous);

lagrange::create::<f64>(ReferenceCellType::Triangle, 2, Continuity::Discontinuous);
lagrange::create::<f64>(ReferenceCellType::Triangle, 3, Continuity::Discontinuous);
lagrange::create::<f64>(ReferenceCellType::Triangle, 4, Continuity::Discontinuous);
lagrange::create::<f64>(ReferenceCellType::Triangle, 5, Continuity::Discontinuous);
lagrange::create::<f64>(ReferenceCell::Triangle, 2, Continuity::Continuous);
lagrange::create::<f64>(ReferenceCell::Triangle, 3, Continuity::Continuous);
lagrange::create::<f64>(ReferenceCell::Triangle, 4, Continuity::Continuous);
lagrange::create::<f64>(ReferenceCell::Triangle, 5, Continuity::Continuous);

lagrange::create::<f64>(ReferenceCell::Triangle, 2, Continuity::Discontinuous);
lagrange::create::<f64>(ReferenceCell::Triangle, 3, Continuity::Discontinuous);
lagrange::create::<f64>(ReferenceCell::Triangle, 4, Continuity::Discontinuous);
lagrange::create::<f64>(ReferenceCell::Triangle, 5, Continuity::Discontinuous);
}

#[test]
fn test_lagrange_higher_degree_interval() {
lagrange::create::<f64>(ReferenceCellType::Interval, 2, Continuity::Continuous);
lagrange::create::<f64>(ReferenceCellType::Interval, 3, Continuity::Continuous);
lagrange::create::<f64>(ReferenceCellType::Interval, 4, Continuity::Continuous);
lagrange::create::<f64>(ReferenceCellType::Interval, 5, Continuity::Continuous);

lagrange::create::<f64>(ReferenceCellType::Interval, 2, Continuity::Discontinuous);
lagrange::create::<f64>(ReferenceCellType::Interval, 3, Continuity::Discontinuous);
lagrange::create::<f64>(ReferenceCellType::Interval, 4, Continuity::Discontinuous);
lagrange::create::<f64>(ReferenceCellType::Interval, 5, Continuity::Discontinuous);
lagrange::create::<f64>(ReferenceCell::Interval, 2, Continuity::Continuous);
lagrange::create::<f64>(ReferenceCell::Interval, 3, Continuity::Continuous);
lagrange::create::<f64>(ReferenceCell::Interval, 4, Continuity::Continuous);
lagrange::create::<f64>(ReferenceCell::Interval, 5, Continuity::Continuous);

lagrange::create::<f64>(ReferenceCell::Interval, 2, Continuity::Discontinuous);
lagrange::create::<f64>(ReferenceCell::Interval, 3, Continuity::Discontinuous);
lagrange::create::<f64>(ReferenceCell::Interval, 4, Continuity::Discontinuous);
lagrange::create::<f64>(ReferenceCell::Interval, 5, Continuity::Discontinuous);
}

#[test]
fn test_lagrange_higher_degree_quadrilateral() {
lagrange::create::<f64>(ReferenceCellType::Quadrilateral, 2, Continuity::Continuous);
lagrange::create::<f64>(ReferenceCellType::Quadrilateral, 3, Continuity::Continuous);
lagrange::create::<f64>(ReferenceCellType::Quadrilateral, 4, Continuity::Continuous);
lagrange::create::<f64>(ReferenceCellType::Quadrilateral, 5, Continuity::Continuous);

lagrange::create::<f64>(
ReferenceCellType::Quadrilateral,
2,
Continuity::Discontinuous,
);
lagrange::create::<f64>(
ReferenceCellType::Quadrilateral,
3,
Continuity::Discontinuous,
);
lagrange::create::<f64>(
ReferenceCellType::Quadrilateral,
4,
Continuity::Discontinuous,
);
lagrange::create::<f64>(
ReferenceCellType::Quadrilateral,
5,
Continuity::Discontinuous,
);
lagrange::create::<f64>(ReferenceCell::Quadrilateral, 2, Continuity::Continuous);
lagrange::create::<f64>(ReferenceCell::Quadrilateral, 3, Continuity::Continuous);
lagrange::create::<f64>(ReferenceCell::Quadrilateral, 4, Continuity::Continuous);
lagrange::create::<f64>(ReferenceCell::Quadrilateral, 5, Continuity::Continuous);

lagrange::create::<f64>(ReferenceCell::Quadrilateral, 2, Continuity::Discontinuous);
lagrange::create::<f64>(ReferenceCell::Quadrilateral, 3, Continuity::Discontinuous);
lagrange::create::<f64>(ReferenceCell::Quadrilateral, 4, Continuity::Discontinuous);
lagrange::create::<f64>(ReferenceCell::Quadrilateral, 5, Continuity::Discontinuous);
}

#[test]
fn test_lagrange_0_quadrilateral() {
let e = lagrange::create::<f64>(
ReferenceCellType::Quadrilateral,
0,
Continuity::Discontinuous,
);
let e = lagrange::create::<f64>(ReferenceCell::Quadrilateral, 0, Continuity::Discontinuous);
assert_eq!(e.value_size(), 1);
let mut data = rlst_dynamic_array4!(f64, e.tabulate_array_shape(0, 6));
let mut points = rlst_dynamic_array2!(f64, [6, 2]);
Expand All @@ -526,8 +506,7 @@ mod test {

#[test]
fn test_lagrange_1_quadrilateral() {
let e =
lagrange::create::<f64>(ReferenceCellType::Quadrilateral, 1, Continuity::Continuous);
let e = lagrange::create::<f64>(ReferenceCell::Quadrilateral, 1, Continuity::Continuous);
assert_eq!(e.value_size(), 1);
let mut data = rlst_dynamic_array4!(f64, e.tabulate_array_shape(0, 6));
let mut points = rlst_dynamic_array2!(f64, [6, 2]);
Expand Down Expand Up @@ -569,8 +548,7 @@ mod test {

#[test]
fn test_lagrange_2_quadrilateral() {
let e =
lagrange::create::<f64>(ReferenceCellType::Quadrilateral, 2, Continuity::Continuous);
let e = lagrange::create::<f64>(ReferenceCell::Quadrilateral, 2, Continuity::Continuous);
assert_eq!(e.value_size(), 1);
let mut data = rlst_dynamic_array4!(f64, e.tabulate_array_shape(0, 6));
let mut points = rlst_dynamic_array2!(f64, [6, 2]);
Expand Down Expand Up @@ -642,7 +620,7 @@ mod test {

#[test]
fn test_raviart_thomas_1_triangle() {
let e = raviart_thomas::create(ReferenceCellType::Triangle, 1, Continuity::Continuous);
let e = raviart_thomas::create(ReferenceCell::Triangle, 1, Continuity::Continuous);
assert_eq!(e.value_size(), 2);
let mut data = rlst_dynamic_array4!(f64, e.tabulate_array_shape(0, 6));
let mut points = rlst_dynamic_array2!(f64, [6, 2]);
Expand Down
Loading

0 comments on commit bf92657

Please sign in to comment.