From 13f9f8f5cd9f91a4b87fbde98bdfbe27a8f46dcf Mon Sep 17 00:00:00 2001 From: Timo Betcke Date: Mon, 4 Nov 2024 09:04:56 +0000 Subject: [PATCH] Removed more traits --- benches/assembly_benchmark.rs | 2 +- examples/assembly.rs | 2 +- src/assembly/boundary.rs | 2 +- src/assembly/boundary/assemblers.rs | 2 +- src/assembly/fmm_tools.rs | 2 +- src/function.rs | 79 +++++++++++++++++++++++++++ src/function/function_space/serial.rs | 2 +- src/helmholtz.rs | 2 +- src/laplace.rs | 2 +- src/traits.rs | 1 - src/traits/function.rs | 78 -------------------------- tests/compare_to_bempp_cl.rs | 2 +- 12 files changed, 88 insertions(+), 88 deletions(-) diff --git a/benches/assembly_benchmark.rs b/benches/assembly_benchmark.rs index 740095bf..7f0a97e3 100644 --- a/benches/assembly_benchmark.rs +++ b/benches/assembly_benchmark.rs @@ -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; diff --git a/examples/assembly.rs b/examples/assembly.rs index 5e6fd015..feb912de 100644 --- a/examples/assembly.rs +++ b/examples/assembly.rs @@ -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; diff --git a/src/assembly/boundary.rs b/src/assembly/boundary.rs index f1d902b7..e893ac6b 100644 --- a/src/assembly/boundary.rs +++ b/src/assembly/boundary.rs @@ -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; diff --git a/src/assembly/boundary/assemblers.rs b/src/assembly/boundary/assemblers.rs index 204f6a92..edcb3b66 100644 --- a/src/assembly/boundary/assemblers.rs +++ b/src/assembly/boundary/assemblers.rs @@ -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; #[cfg(feature = "mpi")] diff --git a/src/assembly/fmm_tools.rs b/src/assembly/fmm_tools.rs index efd05c7c..3193750a 100644 --- a/src/assembly/fmm_tools.rs +++ b/src/assembly/fmm_tools.rs @@ -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; diff --git a/src/function.rs b/src/function.rs index 23eff6b6..61f3688e 100644 --- a/src/function.rs +++ b/src/function.rs @@ -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::Real, EntityDescriptor = ReferenceCellType>; + /// The finite element type + type FiniteElement: FiniteElement + 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>>; + + /// 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: FunctionSpace { + /// Parallel grid type + type ParallelGrid: ParallelGrid + + Grid::Real, EntityDescriptor = ReferenceCellType>; + /// The type of the serial space on each process + type LocalSpace<'a>: FunctionSpace + 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<'_>; +} diff --git a/src/function/function_space/serial.rs b/src/function/function_space/serial.rs index a1d0312c..735e0f8c 100644 --- a/src/function/function_space/serial.rs +++ b/src/function/function_space/serial.rs @@ -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; diff --git a/src/helmholtz.rs b/src/helmholtz.rs index 78cfea8b..0aafe543 100644 --- a/src/helmholtz.rs +++ b/src/helmholtz.rs @@ -17,7 +17,7 @@ pub mod assembler { }, kernels::KernelEvaluator, }, - traits::FunctionSpace, + function::FunctionSpace, }; /// Assembler for the Helmholtz single layer operator. diff --git a/src/laplace.rs b/src/laplace.rs index 9298585a..ed6a553a 100644 --- a/src/laplace.rs +++ b/src/laplace.rs @@ -15,7 +15,7 @@ pub mod assembler { }, kernels::KernelEvaluator, }, - traits::FunctionSpace, + function::FunctionSpace, }; /// Assembler for the Laplace single layer operator. diff --git a/src/traits.rs b/src/traits.rs index 6930b5c0..a3bb2da5 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -2,6 +2,5 @@ mod function; -pub use function::FunctionSpace; #[cfg(feature = "mpi")] pub use function::ParallelFunctionSpace; diff --git a/src/traits/function.rs b/src/traits/function.rs index d6bc51e7..983c1415 100644 --- a/src/traits/function.rs +++ b/src/traits/function.rs @@ -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::Real, EntityDescriptor = ReferenceCellType>; - /// The finite element type - type FiniteElement: FiniteElement + 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>>; - - /// 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: FunctionSpace { - /// Parallel grid type - type ParallelGrid: ParallelGrid - + Grid::Real, EntityDescriptor = ReferenceCellType>; - /// The type of the serial space on each process - type LocalSpace<'a>: FunctionSpace + 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<'_>; -} diff --git a/tests/compare_to_bempp_cl.rs b/tests/compare_to_bempp_cl.rs index c06de765..8a2f5e80 100644 --- a/tests/compare_to_bempp_cl.rs +++ b/tests/compare_to_bempp_cl.rs @@ -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, @@ -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;