Skip to content

Commit

Permalink
revert changes to tree
Browse files Browse the repository at this point in the history
  • Loading branch information
mscroggs committed Dec 15, 2023
1 parent 6aa70b3 commit eef69f0
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 127 deletions.
4 changes: 1 addition & 3 deletions tree/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ memoffset = "0.6"
rand = "0.8.*"
hyksort = { path = "../hyksort", optional = true }
bempp-traits = { path = "../traits" }
rlst = { git = "https://github.com/linalg-rs/rlst.git" }
rlst-dense = { git = "https://github.com/linalg-rs/rlst.git" }
rlst-common = { git = "https://github.com/linalg-rs/rlst.git" }
rlst = { git = "https://github.com/linalg-rs/rlst.git" , branch = "legacy"}
num = "0.4"

[features]
Expand Down
113 changes: 1 addition & 112 deletions tree/examples/test_adaptive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,118 +115,7 @@
// }
// }
#[cfg(feature = "mpi")]
use mpi::{environment::Universe, topology::UserCommunicator, traits::*};

use bempp_tree::implementations::helpers::points_fixture;

#[cfg(feature = "mpi")]
use bempp_tree::types::{domain::Domain, morton::MortonKey, multi_node::MultiNodeTree};

use bempp_traits::types::Scalar;
use rlst_dense::traits::RawAccess;

use rand::distributions::uniform::SampleUniform;

use num::traits::Float;

/// Test that the leaves on separate nodes do not overlap.
#[cfg(feature = "mpi")]
fn test_no_overlaps<T: Float + Default + Scalar<Real = T>>(
world: &UserCommunicator,
tree: &MultiNodeTree<T>,
) {
// Communicate bounds from each process
let max = tree.leaves.iter().max().unwrap();
let min = tree.leaves.iter().min().unwrap();

// Gather all bounds at root
let size = world.size();
let rank = world.rank();

let next_rank = if rank + 1 < size { rank + 1 } else { 0 };
let previous_rank = if rank > 0 { rank - 1 } else { size - 1 };

let previous_process = world.process_at_rank(previous_rank);
let next_process = world.process_at_rank(next_rank);

// Send max to partner
if rank < (size - 1) {
next_process.send(max);
}

let mut partner_max = MortonKey::default();

if rank > 0 {
previous_process.receive_into(&mut partner_max);
}

// Test that the partner's minimum node is greater than the process's maximum node
if rank > 0 {
assert!(partner_max < *min)
}
}

/// Test that the globally defined domain contains all the points at a given node.
#[cfg(feature = "mpi")]
fn test_global_bounds<T: Float + Default + Scalar + Equivalence + SampleUniform>(
world: &UserCommunicator,
) {
let npoints = 10000;
let points = points_fixture::<T>(npoints, None, None);

let comm = world.duplicate();

let domain = Domain::from_global_points(points.data(), &comm);

// Test that all local points are contained within the global domain
for i in 0..npoints {
let x = points.data()[i];
let y = points.data()[i + npoints];
let z = points.data()[i + 2 * npoints];

assert!(domain.origin[0] <= x && x <= domain.origin[0] + domain.diameter[0]);
assert!(domain.origin[1] <= y && y <= domain.origin[1] + domain.diameter[1]);
assert!(domain.origin[2] <= z && z <= domain.origin[2] + domain.diameter[2]);
}
}

#[cfg(feature = "mpi")]
fn main() {
// Setup an MPI environment
let universe: Universe = mpi::initialize().unwrap();
let world = universe.world();
let comm = world.duplicate();

// Setup tree parameters
let adaptive = true;
let n_crit = Some(50);
let depth: Option<_> = None;
let n_points = 10000;
let k = 2;

let points = points_fixture::<f64>(n_points, None, None);
let global_idxs: Vec<_> = (0..n_points).collect();

let tree = MultiNodeTree::new(
&comm,
points.data(),
adaptive,
n_crit,
depth,
k,
&global_idxs,
);

test_global_bounds::<f64>(&comm);
if world.rank() == 0 {
println!("\t ... test_global_bounds passed on adaptive tree");
}

test_no_overlaps(&comm, &tree);
if world.rank() == 0 {
println!("\t ... test_no_overlaps passed on adaptive tree");
}
}
fn main() {}

#[cfg(not(feature = "mpi"))]
fn main() {}
10 changes: 4 additions & 6 deletions tree/src/implementations/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ use num::Float;
use rand::prelude::*;
use rand::SeedableRng;

use rlst_dense::{
array::Array, base_array::BaseArray, data_container::VectorContainer, rlst_dynamic_array2,
};
use rlst::dense::{base_matrix::BaseMatrix, rlst_dynamic_mat, Dynamic, Matrix, VectorContainer};

use crate::types::morton::MortonKey;

/// Alias for an rlst container for point data.
pub type PointsMat<T> = Array<T, BaseArray<T, VectorContainer<T>, 2>, 2>;
pub type PointsMat<T> = Matrix<T, BaseMatrix<T, VectorContainer<T>, Dynamic>, Dynamic>;

/// Points fixture for testing, uniformly samples in each axis from min to max.
///
Expand All @@ -38,7 +36,7 @@ pub fn points_fixture<T: Float + Scalar + rand::distributions::uniform::SampleUn
between = rand::distributions::Uniform::from(T::zero()..T::one());
}

let mut points = rlst_dynamic_array2![T, [npoints, 3]];
let mut points = rlst_dynamic_mat![T, (npoints, 3)];

for i in 0..npoints {
points[[i, 0]] = between.sample(&mut range);
Expand All @@ -63,7 +61,7 @@ pub fn points_fixture_col<T: Float + Scalar + rand::distributions::uniform::Samp
let between1 = rand::distributions::Uniform::from(T::zero()..T::from(0.1).unwrap());
let between2 = rand::distributions::Uniform::from(T::zero()..T::from(500).unwrap());

let mut points = rlst_dynamic_array2![T, [npoints, 3]];
let mut points = rlst_dynamic_mat![T, (npoints, 3)];

for i in 0..npoints {
// One axis has a different sampling
Expand Down
4 changes: 2 additions & 2 deletions tree/src/implementations/impl_domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl<T: Float + Default> Domain<T> {
#[cfg(test)]
mod test {
use bempp_traits::types::Scalar;
use rlst_dense::traits::{RawAccess, Shape};
use rlst::dense::{RawAccess, Shape};

use crate::implementations::helpers::{points_fixture, points_fixture_col, PointsMat};

Expand All @@ -80,7 +80,7 @@ mod test {
assert!(domain.diameter.iter().all(|&x| x == domain.diameter[0]));

// Test that all local points are contained within the local domain
let npoints = points.shape()[0];
let npoints = points.shape().0;
for i in 0..npoints {
let point = [points[[i, 0]], points[[i, 1]], points[[i, 2]]];

Expand Down
6 changes: 3 additions & 3 deletions tree/src/implementations/impl_morton.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ impl MortonKeyInterface for MortonKey {
#[cfg(test)]
mod test {
use itertools::Itertools;
use rlst_dense::traits::{RawAccess, Shape};
use rlst::dense::{RawAccess, Shape};
use std::vec;

use crate::implementations::helpers::points_fixture;
Expand Down Expand Up @@ -1193,7 +1193,7 @@ mod test {

let mut keys: Vec<MortonKey> = Vec::new();

for i in 0..points.shape()[0] {
for i in 0..points.shape().0 {
let point = [points[[i, 0]], points[[i, 1]], points[[i, 2]]];

keys.push(MortonKey::from_point(&point, &domain, DEEPEST_LEVEL));
Expand Down Expand Up @@ -1466,7 +1466,7 @@ mod test {

let mut keys = Vec::new();

for i in 0..points.shape()[0] {
for i in 0..points.shape().0 {
let point = [points[[i, 0]], points[[i, 1]], points[[i, 2]]];
keys.push(MortonKey::from_point(&point, &domain, DEEPEST_LEVEL))
}
Expand Down
2 changes: 1 addition & 1 deletion tree/src/implementations/impl_single_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ where
#[cfg(test)]
mod test {

use rlst_dense::traits::RawAccess;
use rlst::dense::RawAccess;

use crate::implementations::helpers::{points_fixture, points_fixture_col};

Expand Down

0 comments on commit eef69f0

Please sign in to comment.