Advanced Multi-Physics (AMP)
On-Line Documentation
MeshID.h
Go to the documentation of this file.
1#ifndef included_AMP_MeshID
2#define included_AMP_MeshID
3
4#include <cstdint>
5#include <memory>
6#include <string>
7
8namespace AMP::Mesh {
9
10
12enum class GeomType : uint8_t {
13 Vertex = 0,
14 Edge = 1,
15 Face = 2,
16 Cell = 3,
17 Polytope_4D = 4,
18 Polytope_5D = 5,
19 Nullity = 0xFF
20};
21
22
23struct MeshElementID;
24
25
31struct MeshID {
32
33public:
34 // Constructors used to initialize key values
35 constexpr MeshID() : data( 0xFFFFFFFFFFFFFFFF ) {}
36 constexpr MeshID( unsigned int root, unsigned int local_id )
37 : data( ( static_cast<uint64_t>( root ) << 32 ) + local_id )
38 {
39 }
40 constexpr MeshID( uint64_t id ) : data( id ) {}
41 constexpr uint64_t getData() const { return data; }
42 constexpr int getRoot() const { return data >> 32; }
43 constexpr int getLocalID() const { return data & 0xFFFFFFFF; }
44 // Hash the id
45 constexpr uint64_t getHash() const
46 {
47 uint64_t d1 = data & 0xFFFF;
48 uint64_t d2 = ( data >> 16 ) & 0xFFFF;
49 uint64_t d3 = ( data >> 32 ) & 0xFFFF;
50 uint64_t d4 = data >> 48;
51 uint64_t tmp = ( d1 << 48 ) | ( d3 << 32 ) | ( d2 << 16 ) | d4;
52 return 0xF958F86D61D1B36B ^ tmp;
53 }
54 // Overload key operators
55 constexpr bool operator==( const MeshID &rhs ) const { return data == rhs.data; }
56 constexpr bool operator!=( const MeshID &rhs ) const { return data != rhs.data; }
57 constexpr bool operator>=( const MeshID &rhs ) const { return data >= rhs.data; }
58 constexpr bool operator<=( const MeshID &rhs ) const { return data <= rhs.data; }
59 constexpr bool operator>( const MeshID &rhs ) const { return data > rhs.data; }
60 constexpr bool operator<( const MeshID &rhs ) const { return data < rhs.data; }
61 // Check if id is null
62 constexpr bool isNull() const { return data == 0xFFFFFFFFFFFFFFFF; }
63
64private:
65 // We will store the data as a 64-bit data type
66 // We do not want the user to get direct access to the data
67 uint64_t data;
68};
69
70
78struct ElementID {
79
80public:
81 // Constructors used to initialize key values
82 constexpr ElementID() : data( 0x000000FFFFFFFFFF ) {}
83 constexpr explicit ElementID( bool isLocal,
84 GeomType type_id,
85 uint32_t local_ID,
86 uint32_t owner_rank_id )
87 : data( 0 )
88 {
89 // Set the bit for is_local
90 uint32_t tmp = 0x00000000;
91 if ( isLocal )
92 tmp = 0x80000000;
93 // Add the owner_rank
94 tmp += ( 0x007FFFFF & owner_rank_id ) << 8;
95 // Add the type_id
96 tmp += static_cast<uint8_t>( type_id );
97 // Combine the above data with the local_ID
98 data = ( ( (uint64_t) tmp ) << 32 ) + ( (uint64_t) local_ID );
99 }
100 constexpr explicit ElementID( uint64_t id ) : data( id ) {}
101 // Overload key operators
102 constexpr bool operator==( const ElementID &rhs ) const
103 {
104 return ( ( data ^ rhs.data ) << 1 ) == 0;
105 }
106 constexpr bool operator!=( const ElementID &rhs ) const
107 {
108 return ( ( data ^ rhs.data ) << 1 ) != 0;
109 }
110 constexpr bool operator>=( const ElementID &rhs ) const
111 {
112 return ( data << 1 ) >= ( rhs.data << 1 );
113 }
114 constexpr bool operator<=( const ElementID &rhs ) const
115 {
116 return ( data << 1 ) <= ( rhs.data << 1 );
117 }
118 constexpr bool operator>( const ElementID &rhs ) const
119 {
120 return ( data << 1 ) > ( rhs.data << 1 );
121 }
122 constexpr bool operator<( const ElementID &rhs ) const
123 {
124 return ( data << 1 ) < ( rhs.data << 1 );
125 }
126 // Access local data
127 constexpr uint64_t getData() const { return data; }
128 constexpr bool is_local() const { return ( data >> 63 ) != 0; }
129 constexpr GeomType type() const { return static_cast<GeomType>( ( data >> 32 ) & 0x00FF ); }
130 constexpr unsigned int local_id() const { return data & 0x00000000FFFFFFFF; }
131 constexpr unsigned int owner_rank() const { return ( data >> 40 ) & 0x007FFFFF; }
132 constexpr bool isNull() const { return data == 0x000000FFFFFFFFFF; }
133 constexpr void set_is_local( bool isLocal )
134 {
135 if ( isLocal )
136 data |= 0x8000000000000000;
137 else
138 data &= 0x7FFFFFFFFFFFFFFF;
139 }
140
141private:
142 // We will store the data as a 64-bit unsigned integer
143 // The first bit refer to if the element is local
144 // The next 23 bits refer to the processor id
145 // The next 8 bits refer to the element type
146 // The next 32 bits refer to the local id
147 uint64_t data;
148};
149
150
157
158public:
159 // Constructors used to initialize key values
160 constexpr MeshElementID() {}
161 constexpr explicit MeshElementID(
162 bool isLocal, GeomType type, unsigned int local_ID, unsigned int rank, MeshID mesh_ID )
163 : meshId( mesh_ID ), elemId( isLocal, type, local_ID, rank )
164 {
165 }
166 constexpr explicit MeshElementID( MeshID mesh_ID, ElementID elem_id )
167 : meshId( mesh_ID ), elemId( elem_id )
168 {
169 }
170 constexpr void resetElemID( ElementID elem_id ) { elemId = elem_id; }
171 // Overload key operators
172 constexpr bool operator==( const MeshElementID &rhs ) const
173 {
174 return meshId == rhs.meshId && elemId == rhs.elemId;
175 }
176 constexpr bool operator!=( const MeshElementID &rhs ) const
177 {
178 return meshId != rhs.meshId || elemId != rhs.elemId;
179 }
180 constexpr bool operator>=( const MeshElementID &rhs ) const
181 {
182 if ( meshId != rhs.meshId )
183 return meshId > rhs.meshId;
184 return elemId >= rhs.elemId;
185 }
186 constexpr bool operator>( const MeshElementID &rhs ) const
187 {
188 if ( meshId != rhs.meshId )
189 return meshId > rhs.meshId;
190 return elemId > rhs.elemId;
191 }
192 constexpr bool operator<( const MeshElementID &rhs ) const
193 {
194 if ( meshId != rhs.meshId )
195 return meshId < rhs.meshId;
196 return elemId < rhs.elemId;
197 }
198 constexpr bool operator<=( const MeshElementID &rhs ) const
199 {
200 if ( meshId != rhs.meshId )
201 return meshId < rhs.meshId;
202 return elemId <= rhs.elemId;
203 }
204 // Access local data
205 constexpr bool is_local() const { return elemId.is_local(); }
206 constexpr GeomType type() const { return elemId.type(); }
207 constexpr unsigned int local_id() const { return elemId.local_id(); }
208 constexpr unsigned int owner_rank() const { return elemId.owner_rank(); }
209 constexpr MeshID meshID() const { return meshId; }
210 constexpr ElementID elemID() const { return elemId; }
211 constexpr void set_is_local( bool isLocal ) { elemId.set_is_local( isLocal ); }
212 constexpr bool isNull() const { return meshId.isNull() || elemId.isNull(); }
213
214private:
217};
218
219
220// Stream operators
221std::ostream &operator<<( std::ostream &out, GeomType x );
222std::ostream &operator<<( std::ostream &out, MeshID x );
223std::ostream &operator<<( std::ostream &out, ElementID x );
224std::ostream &operator<<( std::ostream &out, MeshElementID x );
225std::string to_string( GeomType x );
226
227
228// Arithmetic operators
229GeomType operator+( GeomType, int ) noexcept;
230GeomType operator-( GeomType, int ) noexcept;
231GeomType operator+( int, GeomType ) noexcept;
232GeomType operator-( int, GeomType ) noexcept;
233
234
235} // namespace AMP::Mesh
236
237
238#endif
std::string to_string(GeomType x)
GeomType
Enumeration for basic mesh-based quantities.
Definition MeshID.h:12
std::ostream & operator<<(std::ostream &out, GeomType x)
GeomType operator-(GeomType, int) noexcept
GeomType operator+(GeomType, int) noexcept
A structure used to identify an element within a mesh.
Definition MeshID.h:78
constexpr bool is_local() const
Definition MeshID.h:128
constexpr unsigned int owner_rank() const
Definition MeshID.h:131
constexpr GeomType type() const
Definition MeshID.h:129
constexpr bool operator==(const ElementID &rhs) const
Definition MeshID.h:102
constexpr bool operator<=(const ElementID &rhs) const
Definition MeshID.h:114
constexpr ElementID()
Definition MeshID.h:82
constexpr bool isNull() const
Definition MeshID.h:132
constexpr ElementID(uint64_t id)
Definition MeshID.h:100
constexpr unsigned int local_id() const
Definition MeshID.h:130
constexpr bool operator!=(const ElementID &rhs) const
Definition MeshID.h:106
constexpr uint64_t getData() const
Definition MeshID.h:127
constexpr void set_is_local(bool isLocal)
Definition MeshID.h:133
constexpr bool operator>=(const ElementID &rhs) const
Definition MeshID.h:110
constexpr bool operator<(const ElementID &rhs) const
Definition MeshID.h:122
constexpr ElementID(bool isLocal, GeomType type_id, uint32_t local_ID, uint32_t owner_rank_id)
Definition MeshID.h:83
constexpr bool operator>(const ElementID &rhs) const
Definition MeshID.h:118
A structure used to identify the mesh element.
Definition MeshID.h:156
constexpr bool is_local() const
Definition MeshID.h:205
constexpr bool operator==(const MeshElementID &rhs) const
Definition MeshID.h:172
constexpr bool operator<=(const MeshElementID &rhs) const
Definition MeshID.h:198
constexpr ElementID elemID() const
Definition MeshID.h:210
constexpr MeshElementID(MeshID mesh_ID, ElementID elem_id)
Definition MeshID.h:166
constexpr bool operator>=(const MeshElementID &rhs) const
Definition MeshID.h:180
constexpr void set_is_local(bool isLocal)
Definition MeshID.h:211
constexpr MeshElementID()
Definition MeshID.h:160
constexpr GeomType type() const
Definition MeshID.h:206
constexpr bool operator!=(const MeshElementID &rhs) const
Definition MeshID.h:176
constexpr MeshID meshID() const
Definition MeshID.h:209
constexpr bool operator>(const MeshElementID &rhs) const
Definition MeshID.h:186
constexpr unsigned int owner_rank() const
Definition MeshID.h:208
constexpr unsigned int local_id() const
Definition MeshID.h:207
constexpr bool isNull() const
Definition MeshID.h:212
constexpr bool operator<(const MeshElementID &rhs) const
Definition MeshID.h:192
constexpr void resetElemID(ElementID elem_id)
Definition MeshID.h:170
constexpr MeshElementID(bool isLocal, GeomType type, unsigned int local_ID, unsigned int rank, MeshID mesh_ID)
Definition MeshID.h:161
A structure used to identify the mesh.
Definition MeshID.h:31
constexpr bool operator<(const MeshID &rhs) const
Definition MeshID.h:60
constexpr MeshID(unsigned int root, unsigned int local_id)
Definition MeshID.h:36
constexpr bool isNull() const
Definition MeshID.h:62
constexpr bool operator==(const MeshID &rhs) const
Definition MeshID.h:55
constexpr MeshID(uint64_t id)
Definition MeshID.h:40
constexpr int getRoot() const
Definition MeshID.h:42
constexpr bool operator!=(const MeshID &rhs) const
Definition MeshID.h:56
constexpr uint64_t getData() const
Definition MeshID.h:41
constexpr MeshID()
Definition MeshID.h:35
constexpr bool operator>=(const MeshID &rhs) const
Definition MeshID.h:57
constexpr int getLocalID() const
Definition MeshID.h:43
constexpr bool operator<=(const MeshID &rhs) const
Definition MeshID.h:58
constexpr uint64_t getHash() const
Definition MeshID.h:45
constexpr bool operator>(const MeshID &rhs) const
Definition MeshID.h:59
uint64_t data
Definition MeshID.h:67



Advanced Multi-Physics (AMP)
Oak Ridge National Laboratory
Idaho National Laboratory
Los Alamos National Laboratory
This page automatically produced from the
source code by doxygen
Last updated: Tue Mar 10 2026 13:06:40.
Comments on this page