Skip to content

Commit

Permalink
Code compiles again
Browse files Browse the repository at this point in the history
  • Loading branch information
tbetcke committed Jan 15, 2025
1 parent f3fef6b commit 69ac00c
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 91 deletions.
15 changes: 3 additions & 12 deletions benches/assembly_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use bempp::boundary_assemblers::BoundaryAssemblerOptions;
use bempp::function::FunctionSpace;
use bempp::function::LocalFunctionSpaceTrait;
use bempp::laplace::assembler::single_layer;
use bempp_distributed_tools::SingleProcessIndexLayout;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use ndelement::ciarlet::LagrangeElementFamily;
use ndelement::types::{Continuity, ReferenceCellType};
use rlst::IndexLayout;

pub fn assembly_parts_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("assembly");
Expand All @@ -28,24 +28,15 @@ pub fn assembly_parts_benchmark(c: &mut Criterion) {
options.set_batch_size(128);

let assembler = single_layer(&options);
let index_layout = SingleProcessIndexLayout::new(0, space.global_size(), &comm);
let index_layout = IndexLayout::from_local_counts(space.global_size(), &comm);

group.bench_function(
format!(
"Assembly of singular terms of {}x{} matrix",
space.global_size(),
space.global_size()
),
|b| {
b.iter(|| {
black_box(assembler.assemble_singular(
&space,
&index_layout,
&space,
&index_layout,
))
})
},
|b| b.iter(|| black_box(assembler.assemble_singular(&space, &space))),
);
}
group.finish();
Expand Down
62 changes: 24 additions & 38 deletions examples/laplace_evaluator.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! This file implements an example Laplace evaluator test the different involved operators.
use std::rc::Rc;

use bempp::{
boundary_assemblers::BoundaryAssemblerOptions, evaluator_tools::NeighbourEvaluator,
function::LocalFunctionSpaceTrait,
Expand All @@ -15,9 +17,7 @@ use rand::SeedableRng;
use rand_chacha::ChaCha8Rng;
use rlst::{
assert_array_relative_eq,
operator::interface::{
distributed_sparse_operator::DistributedCsrMatrixOperator, DistributedArrayVectorSpace,
},
operator::{interface::DistributedArrayVectorSpace, zero_element, Operator},
rlst_dynamic_array1, AsApply, Element, IndexLayout, LinearSpace, MultInto, OperatorBase,
};

Expand Down Expand Up @@ -58,34 +58,30 @@ fn main() {

//First initialise the index layouts.

let space_layout =
bempp_distributed_tools::SingleProcessIndexLayout::new(0, space.global_size(), &world);
let space_layout = Rc::new(bempp_distributed_tools::IndexLayout::from_local_counts(
space.global_size(),
&world,
));

let point_layout =
bempp_distributed_tools::SingleProcessIndexLayout::new(0, quad_degree * n_cells, &world);
let point_layout = Rc::new(bempp_distributed_tools::IndexLayout::from_local_counts(
quad_degree * n_cells,
&world,
));

// Instantiate function spaces.

let array_function_space = DistributedArrayVectorSpace::<_, f64>::new(&space_layout);
let point_function_space = DistributedArrayVectorSpace::<_, f64>::new(&point_layout);
let array_function_space =
DistributedArrayVectorSpace::<_, f64>::from_index_layout(space_layout.clone());
let point_function_space =
DistributedArrayVectorSpace::<_, f64>::from_index_layout(point_layout.clone());

let qrule = bempp_quadrature::simplex_rules::simplex_rule_triangle(quad_degree).unwrap();

let space_to_point = bempp::evaluator_tools::basis_to_point_map(
&space,
&array_function_space,
&point_function_space,
&qrule.points,
&qrule.weights,
);
let space_to_point =
bempp::evaluator_tools::basis_to_point_map(&space, &qrule.points, &qrule.weights, false);

let point_to_space = bempp::evaluator_tools::point_to_basis_map(
&space,
&point_function_space,
&array_function_space,
&qrule.points,
&qrule.weights,
);
let point_to_space =
bempp::evaluator_tools::basis_to_point_map(&space, &qrule.points, &qrule.weights, true);

// We now have to get all the points from the grid. We do this by iterating through all cells.

Expand Down Expand Up @@ -123,37 +119,27 @@ fn main() {
1,
3,
5,
&point_function_space,
&point_function_space,
point_function_space.clone(),
point_function_space.clone(),
);

let correction = NeighbourEvaluator::new(
&qrule.points,
Laplace3dKernel::default(),
green_kernels::types::GreenKernelEvalType::Value,
&point_function_space,
&point_function_space,
space.support_cells(),
&grid,
);

let corrected_evaluator = kernel_evaluator.r().sum(correction.r().scale(-1.0));

let prod1 = corrected_evaluator.r().product(space_to_point.r());

let singular_operator = DistributedCsrMatrixOperator::new(
assembler.assemble_singular(
&space,
array_function_space.index_layout(),
&space,
array_function_space.index_layout(),
),
&array_function_space,
&array_function_space,
);
let singular_operator = Operator::from(assembler.assemble_singular(&space, &space));

let laplace_evaluator = (point_to_space.product(prod1)).sum(singular_operator.r());

let mut x = array_function_space.zero();
let mut x = zero_element(array_function_space.clone());
x.view_mut()
.local_mut()
.fill_from_equally_distributed(&mut rng);
Expand Down
21 changes: 11 additions & 10 deletions examples/neighbour_evaluator.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//! Test the neighbour evaluator
use std::rc::Rc;

use bempp::evaluator_tools::NeighbourEvaluator;
use bempp_distributed_tools::IndexLayoutFromLocalCounts;
use green_kernels::laplace_3d::Laplace3dKernel;
use itertools::Itertools;
use mpi::traits::Communicator;
use ndelement::types::ReferenceCellType;
use ndgrid::{
Expand All @@ -12,8 +14,8 @@ use ndgrid::{
use rand::SeedableRng;
use rand_chacha::ChaCha8Rng;
use rlst::{
operator::interface::DistributedArrayVectorSpace, rlst_dynamic_array2, AsApply, Element,
IndexLayout, LinearSpace, RandomAccessMut, RawAccess,
operator::{interface::DistributedArrayVectorSpace, zero_element},
rlst_dynamic_array2, AsApply, Element, IndexLayout, LinearSpace, RandomAccessMut, RawAccess,
};

fn main() {
Expand All @@ -36,16 +38,15 @@ fn main() {
.filter(|e| matches!(e.ownership(), Ownership::Owned))
.count();

let index_layout = IndexLayoutFromLocalCounts::new(n_cells * n_points, &world);
let index_layout = Rc::new(IndexLayout::from_local_counts(n_cells * n_points, &world));

let space = DistributedArrayVectorSpace::<_, f64>::new(&index_layout);
let space = DistributedArrayVectorSpace::<_, f64>::from_index_layout(index_layout.clone());

let neighbour_evaluator = NeighbourEvaluator::new(
points.data(),
Laplace3dKernel::default(),
green_kernels::types::GreenKernelEvalType::Value,
&space,
&space,
&(0..grid.entity_count(ReferenceCellType::Triangle)).collect_vec(),
&grid,
);

Expand Down Expand Up @@ -76,11 +77,11 @@ fn main() {
green_kernels::types::GreenKernelEvalType::Value,
true,
Laplace3dKernel::default(),
&space,
&space,
space.clone(),
space.clone(),
);

let mut x = space.zero();
let mut x = zero_element(space.clone());

*x.view_mut().local_mut().get_mut([0]).unwrap() = 1.0;
*x.view_mut().local_mut().get_mut([1]).unwrap() = 2.0;
Expand Down
41 changes: 20 additions & 21 deletions examples/test_green_evaluators.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// Compare dense and FMM Green's function evaluators.

use std::rc::Rc;

use bempp::greens_function_evaluators::kifmm_evaluator::KiFmmEvaluator;
use bempp_distributed_tools::IndexLayoutFromLocalCounts;
use green_kernels::{laplace_3d::Laplace3dKernel, types::GreenKernelEvalType};
use mpi::traits::{Communicator, Root};
use rand::{Rng, SeedableRng};
use rand_chacha::ChaCha8Rng;
use rlst::{
operator::interface::DistributedArrayVectorSpace, rlst_dynamic_array1, AsApply, Element,
LinearSpace, NormedSpace, RawAccessMut,
operator::{interface::DistributedArrayVectorSpace, zero_element},
rlst_dynamic_array1, AsApply, Element, IndexLayout, LinearSpace, NormedSpace, RawAccessMut,
};

fn main() {
Expand All @@ -35,15 +36,15 @@ fn main() {

// Initalise the index layout.

let index_layout = IndexLayoutFromLocalCounts::new(npoints, &world);
let index_layout = Rc::new(IndexLayout::from_local_counts(npoints, &world));

// Create the vector space.

let space = DistributedArrayVectorSpace::<_, f64>::new(&index_layout);
let space = DistributedArrayVectorSpace::<_, f64>::from_index_layout(index_layout.clone());

// Create a random vector of charges.

let mut charges = space.zero();
let mut charges = zero_element(space.clone());

// charges
// .view_mut()
Expand All @@ -60,13 +61,14 @@ fn main() {
GreenKernelEvalType::Value,
false,
Laplace3dKernel::default(),
&space,
&space,
space.clone(),
space.clone(),
);

// Create the FMM evaluator.

let fmm_evaluator = KiFmmEvaluator::new(&sources, &targets, 3, 1, 5, &space, &space);
let fmm_evaluator =
KiFmmEvaluator::new(&sources, &targets, 3, 1, 5, space.clone(), space.clone());

// Apply the dense evaluator.

Expand All @@ -80,11 +82,7 @@ fn main() {

let dense_norm = space.norm(&output_dense);

let rel_diff = space.norm(
&space
.new_from(&output_dense)
.sum(&space.new_from(&output_fmm).neg()),
) / dense_norm;
let rel_diff = space.norm(&output_dense.clone().sum(&output_fmm.clone().neg())) / dense_norm;

if world.rank() == 0 {
println!("The relative error is: {}", rel_diff);
Expand Down Expand Up @@ -125,31 +123,32 @@ fn main() {

let root_comm = mpi::topology::SimpleCommunicator::self_comm();

let index_layout_root = IndexLayoutFromLocalCounts::new(npoints * size, &root_comm);
let space_root = DistributedArrayVectorSpace::<_, f64>::new(&index_layout_root);
let index_layout_root = Rc::new(IndexLayout::from_local_counts(npoints * size, &root_comm));
let space_root =
DistributedArrayVectorSpace::<_, f64>::from_index_layout(index_layout_root);
let evaluator_dense_on_root =
bempp::greens_function_evaluators::dense_evaluator::DenseEvaluator::new(
&gathered_sources,
&gathered_targets,
GreenKernelEvalType::Value,
false,
Laplace3dKernel::default(),
&space_root,
&space_root,
space_root.clone(),
space_root.clone(),
);
let fmm_evaluator_on_root = KiFmmEvaluator::new(
&gathered_sources,
&gathered_targets,
3,
1,
5,
&space_root,
&space_root,
space_root.clone(),
space_root.clone(),
);

// Create the charge vector on root.

let mut charges_on_root = space_root.zero();
let mut charges_on_root = zero_element(space_root);

charges_on_root
.view_mut()
Expand Down
25 changes: 16 additions & 9 deletions src/evaluator_tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ use crate::function::FunctionSpaceTrait;

/// Create a linear operator from the map of a basis to points. The points are sorted by global
/// index of the corresponding cells.
pub fn basis_to_point_map<'a, T: RlstScalar + Equivalence, Space: FunctionSpaceTrait<T = T>>(
pub fn basis_to_point_map<
'a,
T: RlstScalar + Equivalence,
C: Communicator,
Space: FunctionSpaceTrait<T = T, C = C>,
>(
function_space: &'a Space,
quadrature_points: &[T::Real],
quadrature_weights: &[T::Real],
Expand Down Expand Up @@ -290,7 +295,9 @@ impl<
// We now setup the array space. This is a distributed array space with a layout corresponding
// to the number of points on each process.

let array_space = Rc::new(IndexLayout::from_local_counts(n_cells * n_points, comm));
let array_space = DistributedArrayVectorSpace::from_index_layout(Rc::new(
IndexLayout::from_local_counts(n_cells * n_points, comm),
));

// We now setup the ghost communicator. The chunk sizes is `n_points` per triangle.

Expand Down Expand Up @@ -345,7 +352,7 @@ impl<
self.grid.entity_count(reference_cell) * self.n_points
);

let rank = self.domain_space.index_layout().comm().rank() as usize;
let rank = self.array_space.index_layout().comm().rank() as usize;
// We first setup the send data.

let mut send_data =
Expand All @@ -358,7 +365,7 @@ impl<
self.ghost_communicator.send_indices().iter()
) {
let local_start_index = self.global_cell_index_to_owned_active_cell_index
[send_global_index]
[&send_global_index]
* self.n_points;
let local_end_index = local_start_index + self.n_points;
send_chunk.copy_from_slice(&x.local().r().data()[local_start_index..local_end_index]);
Expand Down Expand Up @@ -393,7 +400,7 @@ impl<
// We go through the cells, get the global index of the cell, multiply it with `n_points` and
// use that as global start index for the data in x.

for &cell in self.active_cells.iter() {
for cell in self.active_cells.iter() {
let x_start = self.global_cell_index_to_active_cell_index[cell] * self.n_points;
let x_end = x_start + self.n_points;
out.data_mut()[x_start..x_end].copy_from_slice(&x.local().data()[x_start..x_end]);
Expand All @@ -412,8 +419,8 @@ impl<
write!(
f,
"Neighbourhood Evaluator with dimenion [{}, {}].",
self.range_space.index_layout().number_of_global_indices(),
self.domain_space.index_layout().number_of_global_indices()
self.array_space.index_layout().number_of_global_indices(),
self.array_space.index_layout().number_of_global_indices()
)
}
}
Expand All @@ -431,11 +438,11 @@ impl<
type Range = DistributedArrayVectorSpace<'a, C, T>;

fn domain(&self) -> Rc<Self::Domain> {
self.domain_space.clone()
self.array_space.clone()
}

fn range(&self) -> Rc<Self::Range> {
self.range_space.clone()
self.array_space.clone()
}
}

Expand Down
Loading

0 comments on commit 69ac00c

Please sign in to comment.