Skip to content

Commit 24a488e

Browse files
authoredJan 26, 2025··
Testing for cell order and global indexing (#83)
1 parent 482daf1 commit 24a488e

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed
 

‎examples/parallel_grid.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use ndgrid::{
1010
};
1111

1212
fn main() {
13-
let n = 8;
13+
let n = 100;
1414

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

@@ -40,6 +40,28 @@ fn main() {
4040
b.create_parallel_grid(&comm, 0)
4141
};
4242

43+
// Check that owned cells are sorted ahead of ghost cells
44+
45+
let cell_count_owned = grid
46+
.local_grid()
47+
.cell_iter()
48+
.filter(|entity| entity.is_owned())
49+
.count();
50+
51+
// Now check that the first `cell_count_owned` entities are actually owned.
52+
for cell in grid.local_grid().cell_iter().take(cell_count_owned) {
53+
assert!(cell.is_owned())
54+
}
55+
56+
// Now make sure that the indices of the global cells are in consecutive order
57+
58+
let mut cell_global_count = grid.cell_layout().local_range().0;
59+
60+
for cell in grid.local_grid().cell_iter().take(cell_count_owned) {
61+
assert_eq!(cell.global_index(), cell_global_count);
62+
cell_global_count += 1;
63+
}
64+
4365
// Get the global indices.
4466

4567
let global_vertices = grid

‎src/traits/entity.rs

+5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ pub trait Entity {
4040
/// The ownership of this entity
4141
fn ownership(&self) -> Ownership;
4242

43+
/// Return true if the entity is owned
44+
fn is_owned(&self) -> bool {
45+
matches!(self.ownership(), Ownership::Owned)
46+
}
47+
4348
/// The insertion id of this entity
4449
fn id(&self) -> Option<usize>;
4550
}

‎src/traits/grid.rs

+4
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ pub trait Grid {
7171
fn entity_from_id(&self, dim: usize, id: usize) -> Option<Self::Entity<'_>>;
7272

7373
/// Iterator over all cells
74+
///
75+
/// This iterator first iterates through owned cells
76+
/// and then through ghosts. The owned cells are sorted
77+
/// by global index.
7478
fn cell_iter(&self) -> Self::EntityIter<'_> {
7579
let tdim = self.topology_dim();
7680
self.entity_iter(tdim)

0 commit comments

Comments
 (0)
Please sign in to comment.