ndgrid/traits/entity.rs
1//! Traits for a mesh entity
2use crate::traits::{Geometry, Topology};
3use crate::types::{Ownership, Scalar};
4use std::fmt::Debug;
5use std::hash::Hash;
6
7/// Definition of a grid entity
8///
9/// A grid entity can be a vertex, edge, face or cell. This trait
10/// provides a unified interface to any type of entity.
11pub trait Entity {
12 /// Scalar type
13 type T: Scalar;
14
15 /// Type used as identifier of different entity types.
16 /// In most cases this is given by [ReferenceCellType](ndelement::types::ReferenceCellType).
17 type EntityDescriptor: Debug + PartialEq + Eq + Clone + Copy + Hash;
18
19 /// Topology type
20 type Topology<'a>: Topology<EntityDescriptor = Self::EntityDescriptor>
21 where
22 Self: 'a;
23
24 /// Geometry type
25 type Geometry<'a>: Geometry<T = Self::T>
26 where
27 Self: 'a;
28
29 /// The entity type (eg triangle, quadrilateral) of this entity.
30 fn entity_type(&self) -> Self::EntityDescriptor;
31
32 /// The local index of this entity on the current process.
33 fn local_index(&self) -> usize;
34
35 /// The global index of this entity across all processes.
36 fn global_index(&self) -> usize;
37
38 /// The geometry of this entity.
39 fn geometry(&self) -> Self::Geometry<'_>;
40
41 /// The topology of this entity.
42 fn topology(&self) -> Self::Topology<'_>;
43
44 /// The ownership of this entity.
45 fn ownership(&self) -> Ownership;
46
47 /// Return true if the entity is owned.
48 fn is_owned(&self) -> bool {
49 matches!(self.ownership(), Ownership::Owned)
50 }
51
52 /// The insertion id of this entity.
53 ///
54 /// Return `None` if the entity has no insertion id.
55 fn id(&self) -> Option<usize>;
56}