Skip to content

Commit

Permalink
Testing for cell order and global indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
tbetcke committed Jan 26, 2025
1 parent 482daf1 commit af319a8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
24 changes: 23 additions & 1 deletion examples/parallel_grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use ndgrid::{
};

fn main() {
let n = 8;
let n = 100;

let mut b = SingleElementGridBuilder::<f64>::new(2, (ReferenceCellType::Quadrilateral, 1));

Expand Down Expand Up @@ -40,6 +40,28 @@ fn main() {
b.create_parallel_grid(&comm, 0)
};

// Check that owned cells are sorted ahead of ghost cells

let cell_count_owned = grid
.local_grid()
.cell_iter()
.filter(|entity| entity.is_owned())
.count();

// Now check that the first `cell_count_owned` entities are actually owned.
for cell in grid.local_grid().cell_iter().take(cell_count_owned) {
assert!(cell.is_owned())
}

// Now make sure that the indices of the global cells are in consecutive order

let mut cell_global_count = grid.cell_layout().local_range().0;

for cell in grid.local_grid().cell_iter().take(cell_count_owned) {
assert_eq!(cell.global_index(), cell_global_count);
cell_global_count += 1;
}

// Get the global indices.

let global_vertices = grid
Expand Down
5 changes: 5 additions & 0 deletions src/traits/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ pub trait Entity {
/// The ownership of this entity
fn ownership(&self) -> Ownership;

/// Return true if the entity is owned
fn is_owned(&self) -> bool {
matches!(self.ownership(), Ownership::Owned)
}

/// The insertion id of this entity
fn id(&self) -> Option<usize>;
}
4 changes: 4 additions & 0 deletions src/traits/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ pub trait Grid {
fn entity_from_id(&self, dim: usize, id: usize) -> Option<Self::Entity<'_>>;

/// Iterator over all cells
///
/// This iterator first iterates through owned cells
/// and then through ghosts. The owned cells are sorted
/// by global index.
fn cell_iter(&self) -> Self::EntityIter<'_> {
let tdim = self.topology_dim();
self.entity_iter(tdim)
Expand Down

0 comments on commit af319a8

Please sign in to comment.