Skip to content

Commit

Permalink
Removed more traits
Browse files Browse the repository at this point in the history
  • Loading branch information
tbetcke committed Nov 4, 2024
1 parent efe22b4 commit 13f9f8f
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 88 deletions.
2 changes: 1 addition & 1 deletion benches/assembly_benchmark.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use bempp::assembly::boundary::integrands::SingleLayerBoundaryIntegrand;
use bempp::assembly::boundary::{BoundaryAssembler, BoundaryAssemblerOptions};
use bempp::assembly::kernels::KernelEvaluator;
use bempp::function::FunctionSpace;
use bempp::function::SerialFunctionSpace;
use bempp::traits::FunctionSpace;
use criterion::{criterion_group, criterion_main, Criterion};
use green_kernels::laplace_3d::Laplace3dKernel;
use green_kernels::types::GreenKernelEvalType;
Expand Down
2 changes: 1 addition & 1 deletion examples/assembly.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bempp::assembly::boundary::{BoundaryAssembler, BoundaryAssemblerOptions};
use bempp::function::FunctionSpace;
use bempp::function::SerialFunctionSpace;
use bempp::laplace::assembler::laplace_single_layer;
use bempp::traits::FunctionSpace;
use ndelement::ciarlet::LagrangeElementFamily;
use ndelement::types::{Continuity, ReferenceCellType};
use ndgrid::shapes::regular_sphere;
Expand Down
2 changes: 1 addition & 1 deletion src/assembly/boundary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ pub use assemblers::{BoundaryAssembler, BoundaryAssemblerOptions};
mod test {
use super::*;
use crate::assembly::kernels::KernelEvaluator;
use crate::function::FunctionSpace;
use crate::function::SerialFunctionSpace;
use crate::traits::FunctionSpace;
use approx::*;
use green_kernels::laplace_3d::Laplace3dKernel;
use green_kernels::types::GreenKernelEvalType;
Expand Down
2 changes: 1 addition & 1 deletion src/assembly/boundary/assemblers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use super::cell_pair_assemblers::{
use super::integrands::BoundaryIntegrand;
use crate::assembly::common::{equal_grids, RawData2D, RlstArray, SparseMatrixData};
use crate::assembly::kernels::KernelEvaluator;
use crate::traits::FunctionSpace;
use crate::function::FunctionSpace;
#[cfg(feature = "mpi")]
use crate::traits::ParallelBoundaryAssembly;

Check failure on line 12 in src/assembly/boundary/assemblers.rs

View workflow job for this annotation

GitHub Actions / Build docs

unresolved import `crate::traits::ParallelBoundaryAssembly`

Check failure on line 12 in src/assembly/boundary/assemblers.rs

View workflow job for this annotation

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

unresolved import `crate::traits::ParallelBoundaryAssembly`

Check failure on line 12 in src/assembly/boundary/assemblers.rs

View workflow job for this annotation

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

unresolved import `crate::traits::ParallelBoundaryAssembly`

Check failure on line 12 in src/assembly/boundary/assemblers.rs

View workflow job for this annotation

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

unresolved import `crate::traits::ParallelBoundaryAssembly`
#[cfg(feature = "mpi")]
Expand Down
2 changes: 1 addition & 1 deletion src/assembly/fmm_tools.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! FMM tools
use crate::assembly::common::SparseMatrixData;
use crate::function::FunctionSpace;
use crate::function::SerialFunctionSpace;
use crate::traits::FunctionSpace;
use bempp_quadrature::simplex_rules::simplex_rule;
use ndelement::traits::FiniteElement;
use ndelement::types::ReferenceCellType;
Expand Down
79 changes: 79 additions & 0 deletions src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,82 @@
mod function_space;

pub use function_space::*;

#[cfg(feature = "mpi")]
use mpi::traits::Communicator;
use ndelement::{traits::FiniteElement, types::ReferenceCellType};
#[cfg(feature = "mpi")]
use ndgrid::traits::ParallelGrid;
use ndgrid::{traits::Grid, types::Ownership};
use rlst::RlstScalar;
use std::collections::HashMap;

/// A function space
pub trait FunctionSpace {
/// Scalar type
type T: RlstScalar;
/// The grid type
type Grid: Grid<T = <Self::T as RlstScalar>::Real, EntityDescriptor = ReferenceCellType>;
/// The finite element type
type FiniteElement: FiniteElement<T = Self::T> + Sync;

/// Get the grid that the element is defined on
fn grid(&self) -> &Self::Grid;

/// Get the finite element used to define this function space
fn element(&self, cell_type: ReferenceCellType) -> &Self::FiniteElement;

/// Check if the function space is stored in serial
fn is_serial(&self) -> bool {
// self.grid().is_serial()
true
}

/// Get the DOF numbers on the local process associated with the given entity
fn get_local_dof_numbers(&self, entity_dim: usize, entity_number: usize) -> &[usize];

/// Get the number of DOFs associated with the local process
fn local_size(&self) -> usize;

/// Get the number of DOFs on all processes
fn global_size(&self) -> usize;

/// Get the local DOF numbers associated with a cell
fn cell_dofs(&self, cell: usize) -> Option<&[usize]>;

/// Get the local DOF numbers associated with a cell
///
/// # Safety
/// The function uses unchecked array access
unsafe fn cell_dofs_unchecked(&self, cell: usize) -> &[usize];

/// Compute a colouring of the cells so that no two cells that share an entity with DOFs associated with it are assigned the same colour
fn cell_colouring(&self) -> HashMap<ReferenceCellType, Vec<Vec<usize>>>;

/// Get the global DOF index associated with a local DOF index
fn global_dof_index(&self, local_dof_index: usize) -> usize;

/// Get ownership of a local DOF
fn ownership(&self, local_dof_index: usize) -> Ownership;
}

#[cfg(feature = "mpi")]
/// A function space in parallel
pub trait ParallelFunctionSpace<C: Communicator>: FunctionSpace {
/// Parallel grid type
type ParallelGrid: ParallelGrid<C>
+ Grid<T = <Self::T as RlstScalar>::Real, EntityDescriptor = ReferenceCellType>;
/// The type of the serial space on each process
type LocalSpace<'a>: FunctionSpace<T = Self::T> + Sync
where
Self: 'a;

/// MPI communicator
fn comm(&self) -> &C;

/// Get the grid
fn grid(&self) -> &Self::ParallelGrid;

/// Get the local space on the process
fn local_space(&self) -> &Self::LocalSpace<'_>;
}
2 changes: 1 addition & 1 deletion src/function/function_space/serial.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Serial function space

use crate::function::function_space::assign_dofs;
use crate::traits::FunctionSpace;
use crate::function::FunctionSpace;
use ndelement::ciarlet::CiarletElement;
use ndelement::traits::{ElementFamily, FiniteElement};
use ndelement::types::ReferenceCellType;
Expand Down
2 changes: 1 addition & 1 deletion src/helmholtz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub mod assembler {
},
kernels::KernelEvaluator,
},
traits::FunctionSpace,
function::FunctionSpace,
};

/// Assembler for the Helmholtz single layer operator.
Expand Down
2 changes: 1 addition & 1 deletion src/laplace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub mod assembler {
},
kernels::KernelEvaluator,
},
traits::FunctionSpace,
function::FunctionSpace,
};

/// Assembler for the Laplace single layer operator.
Expand Down
1 change: 0 additions & 1 deletion src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@

mod function;

pub use function::FunctionSpace;
#[cfg(feature = "mpi")]
pub use function::ParallelFunctionSpace;

Check failure on line 6 in src/traits.rs

View workflow job for this annotation

GitHub Actions / Build docs

unresolved import `function::ParallelFunctionSpace`

Check failure on line 6 in src/traits.rs

View workflow job for this annotation

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

unresolved import `function::ParallelFunctionSpace`

Check failure on line 6 in src/traits.rs

View workflow job for this annotation

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

unresolved import `function::ParallelFunctionSpace`

Check failure on line 6 in src/traits.rs

View workflow job for this annotation

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

unresolved import `function::ParallelFunctionSpace`
78 changes: 0 additions & 78 deletions src/traits/function.rs
Original file line number Diff line number Diff line change
@@ -1,79 +1 @@
//! Functions and functions spaces
#[cfg(feature = "mpi")]
use mpi::traits::Communicator;
use ndelement::{traits::FiniteElement, types::ReferenceCellType};
#[cfg(feature = "mpi")]
use ndgrid::traits::ParallelGrid;
use ndgrid::{traits::Grid, types::Ownership};
use rlst::RlstScalar;
use std::collections::HashMap;

/// A function space
pub trait FunctionSpace {
/// Scalar type
type T: RlstScalar;
/// The grid type
type Grid: Grid<T = <Self::T as RlstScalar>::Real, EntityDescriptor = ReferenceCellType>;
/// The finite element type
type FiniteElement: FiniteElement<T = Self::T> + Sync;

/// Get the grid that the element is defined on
fn grid(&self) -> &Self::Grid;

/// Get the finite element used to define this function space
fn element(&self, cell_type: ReferenceCellType) -> &Self::FiniteElement;

/// Check if the function space is stored in serial
fn is_serial(&self) -> bool {
// self.grid().is_serial()
true
}

/// Get the DOF numbers on the local process associated with the given entity
fn get_local_dof_numbers(&self, entity_dim: usize, entity_number: usize) -> &[usize];

/// Get the number of DOFs associated with the local process
fn local_size(&self) -> usize;

/// Get the number of DOFs on all processes
fn global_size(&self) -> usize;

/// Get the local DOF numbers associated with a cell
fn cell_dofs(&self, cell: usize) -> Option<&[usize]>;

/// Get the local DOF numbers associated with a cell
///
/// # Safety
/// The function uses unchecked array access
unsafe fn cell_dofs_unchecked(&self, cell: usize) -> &[usize];

/// Compute a colouring of the cells so that no two cells that share an entity with DOFs associated with it are assigned the same colour
fn cell_colouring(&self) -> HashMap<ReferenceCellType, Vec<Vec<usize>>>;

/// Get the global DOF index associated with a local DOF index
fn global_dof_index(&self, local_dof_index: usize) -> usize;

/// Get ownership of a local DOF
fn ownership(&self, local_dof_index: usize) -> Ownership;
}

#[cfg(feature = "mpi")]
/// A function space in parallel
pub trait ParallelFunctionSpace<C: Communicator>: FunctionSpace {
/// Parallel grid type
type ParallelGrid: ParallelGrid<C>
+ Grid<T = <Self::T as RlstScalar>::Real, EntityDescriptor = ReferenceCellType>;
/// The type of the serial space on each process
type LocalSpace<'a>: FunctionSpace<T = Self::T> + Sync
where
Self: 'a;

/// MPI communicator
fn comm(&self) -> &C;

/// Get the grid
fn grid(&self) -> &Self::ParallelGrid;

/// Get the local space on the process
fn local_space(&self) -> &Self::LocalSpace<'_>;
}
2 changes: 1 addition & 1 deletion tests/compare_to_bempp_cl.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use approx::*;
use bempp::assembly::boundary::BoundaryAssemblerOptions;
use bempp::function::FunctionSpace;
use bempp::function::SerialFunctionSpace;
use bempp::helmholtz::assembler::{
helmholtz_adjoint_double_layer, helmholtz_double_layer, helmholtz_hypersingular,
Expand All @@ -8,7 +9,6 @@ use bempp::helmholtz::assembler::{
use bempp::laplace::assembler::{
laplace_adjoint_double_layer, laplace_double_layer, laplace_hypersingular, laplace_single_layer,
};
use bempp::traits::FunctionSpace;
use cauchy::c64;
use ndelement::ciarlet::LagrangeElementFamily;
use ndelement::types::Continuity;
Expand Down

0 comments on commit 13f9f8f

Please sign in to comment.