From 611c8d87958a1c7585a690eee4f4ac55cc816f77 Mon Sep 17 00:00:00 2001 From: Timo Betcke Date: Tue, 31 Dec 2024 19:50:46 +0100 Subject: [PATCH] WIP: Testing evaluators --- Cargo.toml | 3 +- examples/test_green_evaluators.rs | 60 +++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 examples/test_green_evaluators.rs diff --git a/Cargo.toml b/Cargo.toml index 58fdd422..9341f92a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,8 @@ green-kernels = { git = "https://github.com/bempp/green-kernels.git", features = # c-api-tools = { version = "0.1.0" } kifmm = { git = "https://github.com/bempp/kifmm.git", features = ["mpi"] } bempp-distributed-tools = { git = "https://github.com/bempp/distributed_tools.git"} - +rand = "0.8" +rand_chacha = "0.3" [dev-dependencies] approx = "0.5" diff --git a/examples/test_green_evaluators.rs b/examples/test_green_evaluators.rs new file mode 100644 index 00000000..2f93bb1a --- /dev/null +++ b/examples/test_green_evaluators.rs @@ -0,0 +1,60 @@ +// Compare dense and FMM Green's function evaluators. + +use bempp::greens_function_evaluators::kifmm_evaluator::KiFmmEvaluator; +use bempp_distributed_tools::IndexLayoutFromLocalCounts; +use green_kernels::{laplace_3d::Laplace3dKernel, types::GreenKernelEvalType}; +use rand::{Rng, SeedableRng}; +use rand_chacha::ChaCha8Rng; +use rlst::{operator::interface::DistributedArrayVectorSpace, Element, LinearSpace}; + +fn main() { + // Number of points per process. + let npoints = 10000; + let mut rng = ChaCha8Rng::seed_from_u64(0); + + // Create random sources and targets. + + let sources = (0..3 * npoints) + .map(|_| rng.gen_range(-1.0..1.0)) + .collect::>(); + + let targets = sources.clone(); + + // Initialise MPI + + let universe = mpi::initialize().unwrap(); + let world = universe.world(); + + // Initalise the index layout. + + let index_layout = IndexLayoutFromLocalCounts::new(npoints, &world); + + // Create the vector space. + + let space = DistributedArrayVectorSpace::<_, f64>::new(&index_layout); + + // Create a random vector of charges. + + let mut charges = space.zero(); + + charges + .view_mut() + .local_mut() + .fill_from_equally_distributed(&mut rng); + + // Create the dense evaluator. + + let dense_evaluator = bempp::greens_function_evaluators::dense_evaluator::DenseEvaluator::new( + &sources, + &targets, + GreenKernelEvalType::Value, + false, + Laplace3dKernel::default(), + &space, + &space, + ); + + // Create the FMM evaluator. + + let fmm_evaluator = KiFmmEvaluator::new(&sources, &targets, 3, 2, 10, &space, &space); +}