test_parallel_grid/
test_parallel_grid.rs

1use mpi::{environment::Universe, traits::Communicator};
2use ndelement::types::ReferenceCellType;
3use ndgrid::{
4    SingleElementGridBuilder,
5    traits::{Builder, Grid, ParallelBuilder, ParallelGrid},
6    types::GraphPartitioner,
7};
8
9/// Test that using non-contiguous numbering does not cause panic
10fn test_noncontiguous_numbering<C: Communicator>(comm: &C) {
11    let rank = comm.rank();
12    let mut b = SingleElementGridBuilder::<f64>::new(3, (ReferenceCellType::Quadrilateral, 1));
13
14    let g = if rank == 0 {
15        let n = 5;
16        for y in 0..n {
17            for x in 0..n {
18                b.add_point(
19                    2 * (y * n + x) + 5,
20                    &[x as f64 / (n - 1) as f64, y as f64 / (n - 1) as f64, 0.0],
21                );
22            }
23        }
24
25        for i in 0..n - 1 {
26            for j in 0..n - 1 {
27                b.add_cell(
28                    3 * (i * (n - 1) + j),
29                    &[
30                        2 * (j * n + i) + 5,
31                        2 * (j * n + i + 1) + 5,
32                        2 * (j * n + i + n) + 5,
33                        2 * (j * n + i + n + 1) + 5,
34                    ],
35                );
36            }
37        }
38
39        b.create_parallel_grid_root(comm, GraphPartitioner::None)
40    } else {
41        b.create_parallel_grid(comm, 0)
42    };
43
44    assert!(g.local_grid().entity_count(ReferenceCellType::Point) > 0);
45}
46
47/// Run tests
48fn main() {
49    let universe: Universe = mpi::initialize().unwrap();
50    let world = universe.world();
51    let rank = world.rank();
52
53    if rank == 0 {
54        println!("Testing non-contiguous numbering");
55    }
56    test_noncontiguous_numbering(&world);
57}