Skip to content

Commit

Permalink
First version of neighborhood evaluator is done.
Browse files Browse the repository at this point in the history
  • Loading branch information
tbetcke committed Jan 4, 2025
1 parent 67ba3a3 commit 64aeda1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
5 changes: 2 additions & 3 deletions examples/neighbour_evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn main() {
let mut points = rlst_dynamic_array2!(f64, [2, n_points]);
points.fill_from_equally_distributed(&mut rng);

let grid = bempp::shapes::regular_sphere::<f64, _>(100, 1, &world);
let grid = bempp::shapes::regular_sphere::<f64, _>(3, 1, &world);

// Now get the active cells on the current process.

Expand All @@ -51,11 +51,10 @@ fn main() {
// Create an element in the space.

let mut x = space.zero();
let mut y = space.zero();

x.view_mut()
.local_mut()
.fill_from_equally_distributed(&mut rng);

let res = evaluator.apply(&x);
let _res = evaluator.apply(&x);
}
36 changes: 17 additions & 19 deletions src/evaluator_tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,31 +258,18 @@ impl<
// We now need to setup the ghost communicator structure. When cells are target that interface process
// boundaries, there sources are on another process, hence need ghost communicators to get the data.

// This struct stores the relevant indices of the ghost cells.
#[derive(Clone, Copy)]
struct GhostIndices {
// The local index of the ghost cell on the current rank.
local_index: usize,
// The local index of the ghost cell on the owning rank.
owning_local_index: usize,
};
let mut global_index_to_ghost = HashMap::<usize, GhostIndices>::default();
// This map stores the local index associated with a global index.
let mut global_index_to_local = HashMap::<usize, usize>::default();

// We iterate through the cells to figure out ghost cells and their originating ranks.
let mut ghost_global_indices: Vec<usize> = Vec::new();
let mut ghost_ranks: Vec<usize> = Vec::new();

for cell in grid.entity_iter(tdim) {
if let Ownership::Ghost(owning_rank, owning_local_index) = cell.ownership() {
if let Ownership::Ghost(owning_rank, _) = cell.ownership() {
ghost_global_indices.push(cell.global_index());
ghost_ranks.push(owning_rank);
global_index_to_ghost.insert(
cell.global_index(),
GhostIndices {
local_index: cell.local_index(),
owning_local_index,
},
);
global_index_to_local.insert(cell.global_index(), cell.local_index());
}
}

Expand All @@ -301,7 +288,7 @@ impl<
let receive_local_indices = ghost_communicator
.receive_indices()
.iter()
.map(|global_index| global_index_to_ghost[global_index].local_index)
.map(|global_index| global_index_to_local[global_index])
.collect_vec();

Self {
Expand Down Expand Up @@ -514,9 +501,20 @@ where
geometry_map.points(active_cell_index, target_points.data_mut());

// Get all the neighbouring celll indices.
// This is a bit cumbersome. We go through the points of the target cell and add all cells that are connected
// to each point, using a `unique` iterator to remove duplicates.
let mut source_cells = cell_entity
.topology()
.connected_entity_iter(tdim)
.sub_entity_iter(0)
.flat_map(|v| {
local_grid
.entity(0, v)
.unwrap()
.topology()
.connected_entity_iter(tdim)
.collect_vec()
})
.unique()
.collect_vec();
// We add the target cell itself to get the self interactions.
source_cells.push(active_cell_index);
Expand Down

0 comments on commit 64aeda1

Please sign in to comment.