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 mesh entity

A mesh 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?
ndmesh/examples/test_parallel_mesh.rs (line 50)
17fn run_partitioner_test<C: Communicator>(comm: &C, partitioner: GraphPartitioner) {
18    let n = 10;
19
20    let mut b = SingleElementMeshBuilder::<f64>::new(2, (ReferenceCellType::Quadrilateral, 1));
21
22    let rank = comm.rank();
23    let mesh = 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        b.create_parallel_mesh_root(comm, partitioner)
42    } else {
43        b.create_parallel_mesh(comm, 0)
44    };
45
46    // Check that owned cells are sorted ahead of ghost cells
47    let cell_count_owned = mesh
48        .local_mesh()
49        .entity_iter(ReferenceCellType::Quadrilateral)
50        .filter(|entity| entity.is_owned())
51        .count();
52
53    // Check that the first `cell_count_owned` entities are actually owned.
54    for cell in mesh
55        .local_mesh()
56        .entity_iter(ReferenceCellType::Quadrilateral)
57        .take(cell_count_owned)
58    {
59        assert!(cell.is_owned())
60    }
61
62    // Make sure that the indices of the global cells are in consecutive order
63    for (cell_global_count, cell) in izip!(
64        mesh.cell_layout().local_range().0..,
65        mesh.local_mesh()
66            .entity_iter(ReferenceCellType::Quadrilateral)
67            .take(cell_count_owned)
68    ) {
69        assert_eq!(cell.global_index(), cell_global_count);
70    }
71
72    // Get the global indices.
73
74    let global_vertices = mesh
75        .local_mesh()
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 = mesh
84        .local_mesh()
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
Hide additional examples
ndmesh/examples/parallel_mesh.rs (line 54)
14fn main() {
15    // The SingleElementMeshBuilder is used to create the mesh
16    let mut b = SingleElementMeshBuilder::<f64>::new(2, (ReferenceCellType::Quadrilateral, 1));
17
18    let universe: Universe = mpi::initialize().unwrap();
19    let comm = universe.world();
20    let rank = comm.rank();
21
22    // Add points and cells to the builder on process 0
23    let n = 10;
24    let mesh = if rank == 0 {
25        let mut i = 0;
26        for y in 0..n {
27            for x in 0..n {
28                b.add_point(i, &[x as f64 / (n - 1) as f64, y as f64 / (n - 1) as f64]);
29                i += 1;
30            }
31        }
32
33        let mut i = 0;
34        for y in 0..n - 1 {
35            for x in 0..n - 1 {
36                let sw = n * y + x;
37                b.add_cell(i, &[sw, sw + 1, sw + n, sw + n + 1]);
38                i += 1;
39            }
40        }
41
42        // Distribute the mesh
43        // In this example, we use Scotch to partition the mesh into pieces to be handles by each process
44        b.create_parallel_mesh_root(&comm, GraphPartitioner::Scotch)
45    } else {
46        // receice the mesh
47        b.create_parallel_mesh(&comm, 0)
48    };
49
50    // Check that owned cells are sorted ahead of ghost cells
51    let cell_count_owned = mesh
52        .local_mesh()
53        .entity_iter(ReferenceCellType::Quadrilateral)
54        .filter(|entity| entity.is_owned())
55        .count();
56
57    // Now check that the first `cell_count_owned` entities are actually owned.
58    for cell in mesh
59        .local_mesh()
60        .entity_iter(ReferenceCellType::Quadrilateral)
61        .take(cell_count_owned)
62    {
63        assert!(cell.is_owned())
64    }
65
66    // Now make sure that the indices of the global cells are in consecutive order
67    for (cell_global_count, cell) in izip!(
68        mesh.cell_layout().local_range().0..,
69        mesh.local_mesh()
70            .entity_iter(ReferenceCellType::Quadrilateral)
71            .take(cell_count_owned)
72    ) {
73        assert_eq!(cell.global_index(), cell_global_count);
74    }
75
76    // Get the global indices
77    let global_vertices = mesh
78        .local_mesh()
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 = mesh
87        .local_mesh()
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    // Check that the total number of cells and vertices are correct
102    assert_eq!(total_cells, (n - 1) * (n - 1));
103    assert_eq!(total_vertices, n * n);
104}

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 MeshEntity<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