Skip to content

Commit

Permalink
Fixed clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
tbetcke committed Dec 28, 2024
1 parent 90dab45 commit 5f49e01
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 43 deletions.
4 changes: 2 additions & 2 deletions benches/assembly_benchmark.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bempp::boundary_assemblers::BoundaryAssemblerOptions;
use bempp::function::DefaultFunctionSpace;
use bempp::function::FunctionSpace;
use bempp::function::FunctionSpaceTrait;
use bempp::laplace::assembler::single_layer;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use mpi;
Expand All @@ -18,7 +18,7 @@ pub fn assembly_parts_benchmark(c: &mut Criterion) {
let grid = bempp::shapes::regular_sphere(i, 1, &comm);
let element = LagrangeElementFamily::<f64>::new(0, Continuity::Discontinuous);

let space = DefaultFunctionSpace::new(&grid, &element);
let space = FunctionSpace::new(&grid, &element);
let mut options = BoundaryAssemblerOptions::default();
options.set_regular_quadrature_degree(ReferenceCellType::Triangle, 16);
options.set_singular_quadrature_degree(
Expand Down
4 changes: 2 additions & 2 deletions examples/assembly.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bempp::boundary_assemblers::BoundaryAssemblerOptions;
use bempp::function::DefaultFunctionSpace;
use bempp::function::FunctionSpace;
use bempp::laplace::assembler::single_layer;
use ndelement::ciarlet::LagrangeElementFamily;
use ndelement::types::{Continuity, ReferenceCellType};
Expand All @@ -11,7 +11,7 @@ fn main() {
let comm = mpi::topology::SimpleCommunicator::self_comm();
let grid = bempp::shapes::regular_sphere(0, 1, &comm);
let element = LagrangeElementFamily::<f64>::new(1, Continuity::Standard);
let space = DefaultFunctionSpace::new(&grid, &element);
let space = FunctionSpace::new(&grid, &element);

// Adjust the quadrature degree for non-singular integrals on a triangle.
// This makes the integrals use a quadrature rule with 16 points
Expand Down
16 changes: 8 additions & 8 deletions src/boundary_assemblers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::boundary_assemblers::cell_pair_assemblers::{
};
use crate::boundary_assemblers::helpers::KernelEvaluator;
use crate::boundary_assemblers::helpers::{equal_grids, RawData2D, RlstArray, SparseMatrixData};
use crate::function::FunctionSpace;
use crate::function::FunctionSpaceTrait;
use bempp_quadrature::duffy::{
quadrilateral_duffy, quadrilateral_triangle_duffy, triangle_duffy, triangle_quadrilateral_duffy,
};
Expand Down Expand Up @@ -119,7 +119,7 @@ impl<'o, T: RlstScalar + MatrixInverse, Integrand: BoundaryIntegrand<T = T>, K:
BoundaryAssembler<'o, T, Integrand, K>
{
/// Assemble the singular part into a CSR matrix.
pub fn assemble_singular<Space: FunctionSpace<T = T> + Sync>(
pub fn assemble_singular<Space: FunctionSpaceTrait<T = T> + Sync>(
&self,
trial_space: &Space,
test_space: &Space,
Expand Down Expand Up @@ -155,7 +155,7 @@ impl<'o, T: RlstScalar + MatrixInverse, Integrand: BoundaryIntegrand<T = T>, K:
}

/// Assemble into a dense matrix.
pub fn assemble<Space: FunctionSpace<T = T> + Sync>(
pub fn assemble<Space: FunctionSpaceTrait<T = T> + Sync>(
&self,
trial_space: &Space,
test_space: &Space,
Expand All @@ -173,7 +173,7 @@ impl<'o, T: RlstScalar + MatrixInverse, Integrand: BoundaryIntegrand<T = T>, K:
}

/// Assemble into a dense matrix.
pub fn assemble_into_memory<Space: FunctionSpace<T = T> + Sync>(
pub fn assemble_into_memory<Space: FunctionSpaceTrait<T = T> + Sync>(
&self,
trial_space: &Space,
test_space: &Space,
Expand Down Expand Up @@ -231,7 +231,7 @@ impl<'o, T: RlstScalar + MatrixInverse, Integrand: BoundaryIntegrand<T = T>, K:
}

/// Assemble the singular contributions
fn assemble_singular_part<Space: FunctionSpace<T = T> + Sync>(
fn assemble_singular_part<Space: FunctionSpaceTrait<T = T> + Sync>(
&self,
shape: [usize; 2],
trial_space: &Space,
Expand Down Expand Up @@ -393,7 +393,7 @@ impl<'o, T: RlstScalar + MatrixInverse, Integrand: BoundaryIntegrand<T = T>, K:
}

/// Assemble the non-singular contributions into a dense matrix
fn assemble_nonsingular_part<Space: FunctionSpace<T = T> + Sync>(
fn assemble_nonsingular_part<Space: FunctionSpaceTrait<T = T> + Sync>(
&self,
output: &RawData2D<T>,
trial_space: &Space,
Expand Down Expand Up @@ -609,7 +609,7 @@ where
#[allow(clippy::too_many_arguments)]
fn assemble_batch_singular<
T: RlstScalar + MatrixInverse,
Space: FunctionSpace<T = T>,
Space: FunctionSpaceTrait<T = T>,
Integrand: BoundaryIntegrand<T = T>,
K: Kernel<T = T>,
>(
Expand Down Expand Up @@ -688,7 +688,7 @@ fn assemble_batch_singular<
#[allow(clippy::too_many_arguments)]
fn assemble_batch_nonadjacent<
T: RlstScalar + MatrixInverse,
Space: FunctionSpace<T = T>,
Space: FunctionSpaceTrait<T = T>,
Integrand: BoundaryIntegrand<T = T>,
K: Kernel<T = T>,
>(
Expand Down
12 changes: 5 additions & 7 deletions src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type DofList = Vec<Vec<usize>>;
type OwnerData = Vec<(usize, usize, usize, usize)>;

/// A function space
pub trait FunctionSpace {
pub trait FunctionSpaceTrait {
/// Communicator
type C: Communicator;
/// Scalar type
Expand Down Expand Up @@ -70,7 +70,7 @@ pub trait FunctionSpace {
}

/// Implementation of a general function space.
pub struct DefaultFunctionSpace<
pub struct FunctionSpace<
'a,
C: Communicator,
T: RlstScalar + MatrixInverse,
Expand All @@ -88,11 +88,10 @@ pub struct DefaultFunctionSpace<
}

unsafe impl<
'a,
C: Communicator,
T: RlstScalar + MatrixInverse,
GridImpl: ParallelGrid<C> + Grid<T = T::Real, EntityDescriptor = ReferenceCellType>,
> Sync for DefaultFunctionSpace<'a, C, T, GridImpl>
> Sync for FunctionSpace<'_, C, T, GridImpl>
{
}

Expand All @@ -101,7 +100,7 @@ impl<
C: Communicator,
T: RlstScalar + MatrixInverse,
GridImpl: ParallelGrid<C> + Grid<T = T::Real, EntityDescriptor = ReferenceCellType>,
> DefaultFunctionSpace<'a, C, T, GridImpl>
> FunctionSpace<'a, C, T, GridImpl>
{
/// Create new function space
pub fn new(
Expand Down Expand Up @@ -239,11 +238,10 @@ impl<
}

impl<
'a,
C: Communicator,
T: RlstScalar + MatrixInverse,
GridImpl: ParallelGrid<C> + Grid<T = T::Real, EntityDescriptor = ReferenceCellType>,
> FunctionSpace for DefaultFunctionSpace<'a, C, T, GridImpl>
> FunctionSpaceTrait for FunctionSpace<'_, C, T, GridImpl>
{
type T = T;
type Grid = GridImpl;
Expand Down
18 changes: 9 additions & 9 deletions tests/compare_to_bempp_cl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::LazyLock;

use approx::*;
use bempp::boundary_assemblers::BoundaryAssemblerOptions;
use bempp::function::DefaultFunctionSpace;
use bempp::function::FunctionSpace;
use bempp::{helmholtz, laplace};
use cauchy::c64;
use mpi::environment::Universe;
Expand All @@ -23,7 +23,7 @@ fn test_laplace_single_layer_dp0_dp0() {

let grid = bempp::shapes::regular_sphere(0, 1, &comm);
let element = LagrangeElementFamily::<f64>::new(0, Continuity::Discontinuous);
let space = DefaultFunctionSpace::new(&grid, &element);
let space = FunctionSpace::new(&grid, &element);
let options = BoundaryAssemblerOptions::default();

let matrix = laplace::assembler::single_layer(&options).assemble(&space, &space);
Expand All @@ -45,7 +45,7 @@ fn test_laplace_double_layer_dp0_dp0() {
let comm = mpi::topology::SimpleCommunicator::self_comm();
let grid = bempp::shapes::regular_sphere(0, 1, &comm);
let element = LagrangeElementFamily::<f64>::new(0, Continuity::Discontinuous);
let space = DefaultFunctionSpace::new(&grid, &element);
let space = FunctionSpace::new(&grid, &element);
let options = BoundaryAssemblerOptions::default();

let matrix = laplace::assembler::double_layer(&options).assemble(&space, &space);
Expand All @@ -67,7 +67,7 @@ fn test_laplace_adjoint_double_layer_dp0_dp0() {
let comm = mpi::topology::SimpleCommunicator::self_comm();
let grid = bempp::shapes::regular_sphere(0, 1, &comm);
let element = LagrangeElementFamily::<f64>::new(0, Continuity::Discontinuous);
let space = DefaultFunctionSpace::new(&grid, &element);
let space = FunctionSpace::new(&grid, &element);
let options = BoundaryAssemblerOptions::default();

let matrix = laplace::assembler::adjoint_double_layer(&options).assemble(&space, &space);
Expand All @@ -90,7 +90,7 @@ fn test_laplace_hypersingular_p1_p1() {
let grid = bempp::shapes::regular_sphere(0, 1, &comm);

let element = LagrangeElementFamily::<f64>::new(1, Continuity::Standard);
let space = DefaultFunctionSpace::new(&grid, &element);
let space = FunctionSpace::new(&grid, &element);
let options = BoundaryAssemblerOptions::default();

let matrix = laplace::assembler::hypersingular(&options).assemble(&space, &space);
Expand Down Expand Up @@ -118,7 +118,7 @@ fn test_helmholtz_single_layer_dp0_dp0() {
let comm = mpi::topology::SimpleCommunicator::self_comm();
let grid = bempp::shapes::regular_sphere(0, 1, &comm);
let element = LagrangeElementFamily::<c64>::new(0, Continuity::Discontinuous);
let space = DefaultFunctionSpace::new(&grid, &element);
let space = FunctionSpace::new(&grid, &element);
let options = BoundaryAssemblerOptions::default();

let matrix = helmholtz::assembler::single_layer(3.0, &options).assemble(&space, &space);
Expand All @@ -140,7 +140,7 @@ fn test_helmholtz_double_layer_dp0_dp0() {
let comm = mpi::topology::SimpleCommunicator::self_comm();
let grid = bempp::shapes::regular_sphere(0, 1, &comm);
let element = LagrangeElementFamily::<c64>::new(0, Continuity::Discontinuous);
let space = DefaultFunctionSpace::new(&grid, &element);
let space = FunctionSpace::new(&grid, &element);
let options = BoundaryAssemblerOptions::default();

let matrix = helmholtz::assembler::double_layer(3.0, &options).assemble(&space, &space);
Expand All @@ -161,7 +161,7 @@ fn test_helmholtz_adjoint_double_layer_dp0_dp0() {
let comm = mpi::topology::SimpleCommunicator::self_comm();
let grid = bempp::shapes::regular_sphere(0, 1, &comm);
let element = LagrangeElementFamily::<c64>::new(0, Continuity::Discontinuous);
let space = DefaultFunctionSpace::new(&grid, &element);
let space = FunctionSpace::new(&grid, &element);
let options = BoundaryAssemblerOptions::default();

let matrix = helmholtz::assembler::adjoint_double_layer(3.0, &options).assemble(&space, &space);
Expand All @@ -183,7 +183,7 @@ fn test_helmholtz_hypersingular_p1_p1() {
let comm = mpi::topology::SimpleCommunicator::self_comm();
let grid = bempp::shapes::regular_sphere(0, 1, &comm);
let element = LagrangeElementFamily::<c64>::new(1, Continuity::Standard);
let space = DefaultFunctionSpace::new(&grid, &element);
let space = FunctionSpace::new(&grid, &element);
let options = BoundaryAssemblerOptions::default();

let matrix = helmholtz::assembler::hypersingular(3.0, &options).assemble(&space, &space);
Expand Down
22 changes: 7 additions & 15 deletions tests/test_space.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use bempp::function::{assign_dofs, DefaultFunctionSpace, FunctionSpace};
use bempp::function::{assign_dofs, FunctionSpace, FunctionSpaceTrait};
use bempp::shapes::{regular_sphere, screen_triangles};
use mpi::topology::SimpleCommunicator;
use ndelement::ciarlet::{LagrangeElementFamily, RaviartThomasElementFamily};
use ndelement::types::{Continuity, ReferenceCellType};
use ndgrid::traits::{Entity, Grid, Topology};
Expand All @@ -14,13 +13,6 @@ static MPI_UNIVERSE: LazyLock<Universe> = std::sync::LazyLock::new(|| {
.0
});

fn get_comm() -> SimpleCommunicator {
use mpi;

let _ = mpi::initialize();
mpi::topology::SimpleCommunicator::self_comm()
}

fn run_test(
grid: &(impl Grid<T = f64, EntityDescriptor = ReferenceCellType> + Sync),
degree: usize,
Expand Down Expand Up @@ -149,7 +141,7 @@ fn test_dofmap_lagrange0() {
let grid = regular_sphere::<f64, _>(2, 1, &comm);
//let grid = regular_sphere::<f64, _>(2, 1, &comm);
let element = LagrangeElementFamily::<f64>::new(0, Continuity::Discontinuous);
let space = DefaultFunctionSpace::new(&grid, &element);
let space = FunctionSpace::new(&grid, &element);
assert_eq!(space.local_size(), space.global_size());
assert_eq!(
space.local_size(),
Expand All @@ -163,7 +155,7 @@ fn test_dofmap_lagrange1() {
let comm = mpi::topology::SimpleCommunicator::self_comm();
let grid = regular_sphere::<f64, _>(2, 1, &comm);
let element = LagrangeElementFamily::<f64>::new(1, Continuity::Standard);
let space = DefaultFunctionSpace::new(&grid, &element);
let space = FunctionSpace::new(&grid, &element);
assert_eq!(space.local_size(), space.global_size());
assert_eq!(
space.local_size(),
Expand All @@ -177,7 +169,7 @@ fn test_dofmap_lagrange2() {
let comm = mpi::topology::SimpleCommunicator::self_comm();
let grid = regular_sphere::<f64, _>(2, 1, &comm);
let element = LagrangeElementFamily::<f64>::new(2, Continuity::Standard);
let space = DefaultFunctionSpace::new(&grid, &element);
let space = FunctionSpace::new(&grid, &element);
assert_eq!(space.local_size(), space.global_size());
assert_eq!(
space.local_size(),
Expand All @@ -192,7 +184,7 @@ fn test_colouring_p1() {
let comm = mpi::topology::SimpleCommunicator::self_comm();
let grid = regular_sphere::<f64, _>(2, 1, &comm);
let element = LagrangeElementFamily::<f64>::new(1, Continuity::Standard);
let space = DefaultFunctionSpace::new(&grid, &element);
let space = FunctionSpace::new(&grid, &element);
let colouring = &space.cell_colouring()[&ReferenceCellType::Triangle];
let cells = grid.entity_iter(2).collect::<Vec<_>>();
let mut n = 0;
Expand Down Expand Up @@ -232,7 +224,7 @@ fn test_colouring_dp0() {
let comm = mpi::topology::SimpleCommunicator::self_comm();
let grid = regular_sphere::<f64, _>(2, 1, &comm);
let element = LagrangeElementFamily::<f64>::new(0, Continuity::Discontinuous);
let space = DefaultFunctionSpace::new(&grid, &element);
let space = FunctionSpace::new(&grid, &element);
let colouring = &space.cell_colouring()[&ReferenceCellType::Triangle];
let mut n = 0;
for i in colouring {
Expand All @@ -259,7 +251,7 @@ fn test_colouring_rt1() {
let comm = mpi::topology::SimpleCommunicator::self_comm();
let grid = regular_sphere::<f64, _>(2, 1, &comm);
let element = LagrangeElementFamily::<f64>::new(1, Continuity::Standard);
let space = DefaultFunctionSpace::new(&grid, &element);
let space = FunctionSpace::new(&grid, &element);
let colouring = &space.cell_colouring()[&ReferenceCellType::Triangle];
let mut n = 0;
for i in colouring {
Expand Down

0 comments on commit 5f49e01

Please sign in to comment.