pub trait Entity {
type T: Scalar;
type EntityDescriptor: Debug + PartialEq + Eq + Clone + Copy + Hash;
type Topology<'a>: Topology<EntityDescriptor = Self::EntityDescriptor>
where Self: 'a;
type Geometry<'a>: Geometry<T = Self::T>
where Self: 'a;
// Required methods
fn entity_type(&self) -> Self::EntityDescriptor;
fn local_index(&self) -> usize;
fn global_index(&self) -> usize;
fn geometry(&self) -> Self::Geometry<'_>;
fn topology(&self) -> Self::Topology<'_>;
fn ownership(&self) -> Ownership;
fn id(&self) -> Option<usize>;
// Provided method
fn is_owned(&self) -> bool { ... }
}Expand description
Definition of a grid entity
A grid entity can be a vertex, edge, face or cell. This trait provides a unified interface to any type of entity.
Required Associated Types§
Sourcetype EntityDescriptor: Debug + PartialEq + Eq + Clone + Copy + Hash
type EntityDescriptor: Debug + PartialEq + Eq + Clone + Copy + Hash
Type used as identifier of different entity types. In most cases this is given by ReferenceCellType.
Sourcetype Topology<'a>: Topology<EntityDescriptor = Self::EntityDescriptor>
where
Self: 'a
type Topology<'a>: Topology<EntityDescriptor = Self::EntityDescriptor> where Self: 'a
Topology type
Required Methods§
Sourcefn entity_type(&self) -> Self::EntityDescriptor
fn entity_type(&self) -> Self::EntityDescriptor
The entity type (eg triangle, quadrilateral) of this entity.
Sourcefn local_index(&self) -> usize
fn local_index(&self) -> usize
The local index of this entity on the current process.
Sourcefn global_index(&self) -> usize
fn global_index(&self) -> usize
The global index of this entity across all processes.
Provided Methods§
Sourcefn is_owned(&self) -> bool
fn is_owned(&self) -> bool
Return true if the entity is owned.
Examples found in repository?
ndgrid/examples/test_partitioners.rs (line 47)
13fn run_test<C: Communicator>(comm: &C, partitioner: GraphPartitioner) {
14 let n = 10;
15
16 let mut b = SingleElementGridBuilder::<f64>::new(2, (ReferenceCellType::Quadrilateral, 1));
17
18 let rank = comm.rank();
19 let grid = if rank == 0 {
20 let mut i = 0;
21 for y in 0..n {
22 for x in 0..n {
23 b.add_point(i, &[x as f64 / (n - 1) as f64, y as f64 / (n - 1) as f64]);
24 i += 1;
25 }
26 }
27
28 let mut i = 0;
29 for y in 0..n - 1 {
30 for x in 0..n - 1 {
31 let sw = n * y + x;
32 b.add_cell(i, &[sw, sw + 1, sw + n, sw + n + 1]);
33 i += 1;
34 }
35 }
36
37 b.create_parallel_grid_root(comm, partitioner)
38 } else {
39 b.create_parallel_grid(comm, 0)
40 };
41
42 // Check that owned cells are sorted ahead of ghost cells
43
44 let cell_count_owned = grid
45 .local_grid()
46 .entity_iter(ReferenceCellType::Quadrilateral)
47 .filter(|entity| entity.is_owned())
48 .count();
49
50 // Now check that the first `cell_count_owned` entities are actually owned.
51 for cell in grid
52 .local_grid()
53 .entity_iter(ReferenceCellType::Quadrilateral)
54 .take(cell_count_owned)
55 {
56 assert!(cell.is_owned())
57 }
58
59 // Now make sure that the indices of the global cells are in consecutive order
60
61 let mut cell_global_count = grid.cell_layout().local_range().0;
62
63 for cell in grid
64 .local_grid()
65 .entity_iter(ReferenceCellType::Quadrilateral)
66 .take(cell_count_owned)
67 {
68 assert_eq!(cell.global_index(), cell_global_count);
69 cell_global_count += 1;
70 }
71
72 // Get the global indices.
73
74 let global_vertices = grid
75 .local_grid()
76 .entity_iter(ReferenceCellType::Point)
77 .filter(|e| matches!(e.ownership(), Ownership::Owned))
78 .map(|e| e.global_index())
79 .collect::<Vec<_>>();
80
81 let nvertices = global_vertices.len();
82
83 let global_cells = grid
84 .local_grid()
85 .entity_iter(ReferenceCellType::Quadrilateral)
86 .filter(|e| matches!(e.ownership(), Ownership::Owned))
87 .map(|e| e.global_index())
88 .collect::<Vec<_>>();
89
90 let ncells = global_cells.len();
91
92 let mut total_cells: usize = 0;
93 let mut total_vertices: usize = 0;
94
95 comm.all_reduce_into(&ncells, &mut total_cells, SystemOperation::sum());
96 comm.all_reduce_into(&nvertices, &mut total_vertices, SystemOperation::sum());
97
98 assert_eq!(total_cells, (n - 1) * (n - 1));
99 assert_eq!(total_vertices, n * n);
100}More examples
ndgrid/examples/parallel_grid.rs (line 53)
13fn main() {
14 // The SingleElementGridBuilder is used to create the mesh
15 let mut b = SingleElementGridBuilder::<f64>::new(2, (ReferenceCellType::Quadrilateral, 1));
16
17 let universe: Universe = mpi::initialize().unwrap();
18 let comm = universe.world();
19 let rank = comm.rank();
20
21 // Add points and cells to the builder on process 0
22 let n = 10;
23 let grid = if rank == 0 {
24 let mut i = 0;
25 for y in 0..n {
26 for x in 0..n {
27 b.add_point(i, &[x as f64 / (n - 1) as f64, y as f64 / (n - 1) as f64]);
28 i += 1;
29 }
30 }
31
32 let mut i = 0;
33 for y in 0..n - 1 {
34 for x in 0..n - 1 {
35 let sw = n * y + x;
36 b.add_cell(i, &[sw, sw + 1, sw + n, sw + n + 1]);
37 i += 1;
38 }
39 }
40
41 // Distribute the grid
42 // In this example, we use Scotch to partition the grid into pieces to be handles by each process
43 b.create_parallel_grid_root(&comm, GraphPartitioner::Scotch)
44 } else {
45 // receice the grid
46 b.create_parallel_grid(&comm, 0)
47 };
48
49 // Check that owned cells are sorted ahead of ghost cells
50 let cell_count_owned = grid
51 .local_grid()
52 .entity_iter(ReferenceCellType::Quadrilateral)
53 .filter(|entity| entity.is_owned())
54 .count();
55
56 // Now check that the first `cell_count_owned` entities are actually owned.
57 for cell in grid
58 .local_grid()
59 .entity_iter(ReferenceCellType::Quadrilateral)
60 .take(cell_count_owned)
61 {
62 assert!(cell.is_owned())
63 }
64
65 // Now make sure that the indices of the global cells are in consecutive order
66 let mut cell_global_count = grid.cell_layout().local_range().0;
67
68 for cell in grid
69 .local_grid()
70 .entity_iter(ReferenceCellType::Quadrilateral)
71 .take(cell_count_owned)
72 {
73 assert_eq!(cell.global_index(), cell_global_count);
74 cell_global_count += 1;
75 }
76
77 // Get the global indices
78 let global_vertices = grid
79 .local_grid()
80 .entity_iter(ReferenceCellType::Point)
81 .filter(|e| matches!(e.ownership(), Ownership::Owned))
82 .map(|e| e.global_index())
83 .collect::<Vec<_>>();
84
85 let nvertices = global_vertices.len();
86
87 let global_cells = grid
88 .local_grid()
89 .entity_iter(ReferenceCellType::Quadrilateral)
90 .filter(|e| matches!(e.ownership(), Ownership::Owned))
91 .map(|e| e.global_index())
92 .collect::<Vec<_>>();
93
94 let ncells = global_cells.len();
95
96 let mut total_cells: usize = 0;
97 let mut total_vertices: usize = 0;
98
99 comm.all_reduce_into(&ncells, &mut total_cells, SystemOperation::sum());
100 comm.all_reduce_into(&nvertices, &mut total_vertices, SystemOperation::sum());
101
102 // Check that the total number of cells and vertices are correct
103 assert_eq!(total_cells, (n - 1) * (n - 1));
104 assert_eq!(total_vertices, n * n);
105}Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.