Skip to main content

Entity

Trait Entity 

Source
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§

Source

type T: Scalar

Scalar type

Source

type EntityDescriptor: Debug + PartialEq + Eq + Clone + Copy + Hash

Type used as identifier of different entity types. In most cases this is given by ReferenceCellType.

Source

type Topology<'a>: Topology<EntityDescriptor = Self::EntityDescriptor> where Self: 'a

Topology type

Source

type Geometry<'a>: Geometry<T = Self::T> where Self: 'a

Geometry type

Required Methods§

Source

fn entity_type(&self) -> Self::EntityDescriptor

The entity type (eg triangle, quadrilateral) of this entity.

Source

fn local_index(&self) -> usize

The local index of this entity on the current process.

Source

fn global_index(&self) -> usize

The global index of this entity across all processes.

Source

fn geometry(&self) -> Self::Geometry<'_>

The geometry of this entity.

Source

fn topology(&self) -> Self::Topology<'_>

The topology of this entity.

Source

fn ownership(&self) -> Ownership

The ownership of this entity.

Source

fn id(&self) -> Option<usize>

The insertion id of this entity.

Return None if the entity has no insertion id.

Provided Methods§

Source

fn is_owned(&self) -> bool

Return true if the entity is owned.

Examples found in repository?
ndgrid/examples/test_parallel_grid.rs (line 50)
16fn run_partitioner_test<C: Communicator>(comm: &C, partitioner: GraphPartitioner) {
17    let n = 10;
18
19    let mut b = SingleElementGridBuilder::<f64>::new(2, (ReferenceCellType::Quadrilateral, 1));
20
21    let rank = comm.rank();
22    let grid = if rank == 0 {
23        let mut i = 0;
24        for y in 0..n {
25            for x in 0..n {
26                b.add_point(i, &[x as f64 / (n - 1) as f64, y as f64 / (n - 1) as f64]);
27                i += 1;
28            }
29        }
30
31        let mut i = 0;
32        for y in 0..n - 1 {
33            for x in 0..n - 1 {
34                let sw = n * y + x;
35                b.add_cell(i, &[sw, sw + 1, sw + n, sw + n + 1]);
36                i += 1;
37            }
38        }
39
40        b.create_parallel_grid_root(comm, partitioner)
41    } else {
42        b.create_parallel_grid(comm, 0)
43    };
44
45    // Check that owned cells are sorted ahead of ghost cells
46
47    let cell_count_owned = grid
48        .local_grid()
49        .entity_iter(ReferenceCellType::Quadrilateral)
50        .filter(|entity| entity.is_owned())
51        .count();
52
53    // Now check that the first `cell_count_owned` entities are actually owned.
54    for cell in grid
55        .local_grid()
56        .entity_iter(ReferenceCellType::Quadrilateral)
57        .take(cell_count_owned)
58    {
59        assert!(cell.is_owned())
60    }
61
62    // Now make sure that the indices of the global cells are in consecutive order
63
64    let mut cell_global_count = grid.cell_layout().local_range().0;
65
66    for cell in grid
67        .local_grid()
68        .entity_iter(ReferenceCellType::Quadrilateral)
69        .take(cell_count_owned)
70    {
71        assert_eq!(cell.global_index(), cell_global_count);
72        cell_global_count += 1;
73    }
74
75    // Get the global indices.
76
77    let global_vertices = grid
78        .local_grid()
79        .entity_iter(ReferenceCellType::Point)
80        .filter(|e| matches!(e.ownership(), Ownership::Owned))
81        .map(|e| e.global_index())
82        .collect::<Vec<_>>();
83
84    let nvertices = global_vertices.len();
85
86    let global_cells = grid
87        .local_grid()
88        .entity_iter(ReferenceCellType::Quadrilateral)
89        .filter(|e| matches!(e.ownership(), Ownership::Owned))
90        .map(|e| e.global_index())
91        .collect::<Vec<_>>();
92
93    let ncells = global_cells.len();
94
95    let mut total_cells: usize = 0;
96    let mut total_vertices: usize = 0;
97
98    comm.all_reduce_into(&ncells, &mut total_cells, SystemOperation::sum());
99    comm.all_reduce_into(&nvertices, &mut total_vertices, SystemOperation::sum());
100
101    assert_eq!(total_cells, (n - 1) * (n - 1));
102    assert_eq!(total_vertices, n * n);
103}
More examples
Hide additional 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.

Implementors§

Source§

impl<E: Entity> Entity for GridEntity<E>

Source§

type T = <E as Entity>::T

Source§

type EntityDescriptor = <E as Entity>::EntityDescriptor

Source§

type Topology<'a> = <E as Entity>::Topology<'a> where Self: 'a

Source§

type Geometry<'a> = <E as Entity>::Geometry<'a> where Self: 'a