Advanced Multi-Physics (AMP)
On-Line Documentation
TriangleMesh.h
Go to the documentation of this file.
1#ifndef included_AMP_TriangleMesh
2#define included_AMP_TriangleMesh
3
4#include "AMP/geometry/Geometry.h"
5#include "AMP/mesh/Mesh.h"
6#include "AMP/mesh/MeshID.h"
7#include "AMP/mesh/MeshIterator.h"
8
9#include <array>
10#include <map>
11#include <memory>
12#include <vector>
13
14
15namespace AMP::Mesh {
16
17
18template<uint8_t NG>
19class TriangleMeshIterator;
20template<uint8_t NG>
21class TriangleMeshElement;
22
23
24// Class to store vertex data
25template<class TYPE, size_t N>
26class StoreTriData final
27{
28public:
29 StoreTriData() = default;
30 StoreTriData( std::vector<std::array<TYPE, N>> x,
31 std::vector<int> offset,
32 int rank,
33 GeomType type );
34 inline int size() const { return d_x.size(); }
35 inline int start() const { return d_start; }
36 inline int end() const { return d_end; }
37 inline int start( int r ) const { return d_offset[r]; }
38 inline int end( int r ) const { return d_offset[r + 1]; }
39 int rank( int i ) const;
40 inline auto data() { return d_x.data(); }
41 inline const auto data() const { return d_x.data(); }
42 inline auto &offset() const { return d_offset; }
43 inline int index( const ElementID &id ) const
44 {
45 AMP_DEBUG_ASSERT( id.type() == d_type );
46 int rank = id.owner_rank();
47 return d_offset[rank] + id.local_id();
48 }
49 ElementID getID( int i ) const;
50 int find( const std::array<TYPE, N> &x ) const;
51 inline auto &operator[]( int i ) { return d_x[i]; }
52 inline auto &operator[]( int i ) const { return d_x[i]; }
53 inline auto &operator[]( const ElementID &id ) { return d_x[index( id )]; }
54 inline auto &operator[]( const ElementID &id ) const { return d_x[index( id )]; }
55 inline auto &operator()() { return d_x; }
56 inline const auto &operator()() const { return d_x; }
57
58private:
60 int d_start = 0;
61 int d_end = 0;
62 int d_rank = 0;
63 std::vector<int> d_offset;
64 std::vector<std::array<TYPE, N>> d_x;
65};
66
67
68// Class to store parent data
69template<class TYPE>
71{
72public:
74 inline StoreCompressedList( size_t N )
75 : StoreCompressedList( std::vector<std::vector<TYPE>>( N ) )
76 {
77 }
78 inline explicit StoreCompressedList( const std::vector<std::vector<TYPE>> &data )
79 {
80 size_t Nt = 0;
81 for ( size_t i = 0; i < data.size(); i++ )
82 Nt += data[i].size();
83 d_size.resize( data.size() );
84 d_offset.resize( data.size() );
85 d_data.resize( Nt );
86 for ( size_t i = 0, k = 0; i < data.size(); i++ ) {
87 d_size[i] = data[i].size();
88 d_offset[i] = k;
89 for ( size_t j = 0; j < d_size[i]; j++, k++ )
90 d_data[k] = data[i][j];
91 }
92 }
93 inline const ElementID *begin( size_t i ) const
94 {
95 if ( i >= d_size.size() )
96 return nullptr;
97 return &d_data[d_offset[i]];
98 }
99 inline const ElementID *end( size_t i ) const
100 {
101 if ( i >= d_size.size() )
102 return nullptr;
103 return &d_data[d_offset[i]] + d_size[i];
104 }
105
106private:
107 std::vector<size_t> d_size;
108 std::vector<size_t> d_offset;
109 std::vector<TYPE> d_data;
110};
111
112
117template<uint8_t NG>
119{
120public: // Convenience typedefs
121 static_assert( NG <= 3, "Not programmed for higher dimensions yet" );
122 typedef std::array<double, 3> Point;
123 typedef std::array<int, 2> Edge;
124 typedef std::array<int, 3> Face;
125 typedef std::array<int, NG + 1> TRI;
126 using IteratorSet = std::array<TriangleMeshIterator<NG>, NG + 1>;
128
129
130public:
145 explicit TriangleMesh( int NP,
146 std::vector<Point> vertices,
147 std::vector<TRI> triangles,
148 std::vector<TRI> tri_nab,
149 const AMP_MPI &comm,
150 std::shared_ptr<Geometry::Geometry> geom = {},
151 std::vector<int> block = {},
152 int max_gcw = 2 );
153
154
156 std::string meshClass() const override;
157
158
160 std::unique_ptr<Mesh> clone() const override final;
161
162
164 bool operator==( const Mesh &mesh ) const override;
165
166
167 // Copy/move constructors
169 TriangleMesh( TriangleMesh && ) = default;
170
171 TriangleMesh &operator=( const TriangleMesh & ) = delete;
172 TriangleMesh &operator=( TriangleMesh && ) = default;
173
174
176 virtual ~TriangleMesh();
177
178
179 /* Return the number of local element of the given type
180 * \param type Geometric type
181 */
182 size_t numLocalElements( const GeomType type ) const override final;
183
184
185 /* Return the global number of elements of the given type
186 * Note: depending on the mesh this routine may require global communication across the mesh.
187 * \param type Geometric type
188 */
189 size_t numGlobalElements( const GeomType type ) const override final;
190
191
192 /* Return the number of ghost elements of the given type on the current processor
193 * \param type Geometric type
194 */
195 size_t numGhostElements( const GeomType type, const int gcw ) const override final;
196
197
204 MeshIterator getIterator( const GeomType type, const int gcw = 0 ) const override final;
205
206
214 const int gcw = 0 ) const override final;
215
216
222 std::vector<int> getBoundaryIDs() const override final;
223
224
235 const int id,
236 const int gcw = 0 ) const override final;
237
243 std::vector<int> getBlockIDs() const override final;
244
245
253 virtual MeshIterator
254 getBlockIDIterator( const GeomType type, const int id, const int gcw = 0 ) const override final;
255
256
266 MeshElementPtr getElement( const MeshElementID &id ) const override final;
267
268
277 const GeomType type ) const override final;
278
284 Movable isMeshMovable() const override { return Movable::Deform; };
285
286
296 uint64_t positionHash() const override;
297
298
307 void displaceMesh( const std::vector<double> &x ) override;
308
309
318 void displaceMesh( std::shared_ptr<const AMP::LinearAlgebra::Vector> x ) override;
319
320
326 void writeRestart( int64_t fid ) const override;
327
328
329protected:
330 TriangleMesh() = default;
331 explicit TriangleMesh( std::shared_ptr<const MeshParameters> );
335 std::vector<IteratorSet> createBlockIterators( int block );
337
338
339public:
340 // Create an iterator from a list
342
343 // Return the IDs of the elements composing the current element
344 void getElementsIDs( const ElementID &id, const GeomType type, ElementID *IDs ) const;
345 void getVertexCoord( const ElementID &id, std::array<double, 3> *x ) const;
346
347 // Return the IDs of the neighboring elements
348 void getNeighborIDs( const ElementID &id, std::vector<ElementID> &IDs ) const;
349
350 // Return the IDs of the parent elements
351 std::pair<const ElementID *, const ElementID *> getElementParents( const ElementID &id,
352 const GeomType type ) const;
353
354 // Return a new element (user must delete)
356
357
358 // Check if the element is on the given boundry, block, etc
359 bool isOnSurface( const ElementID &elemID ) const;
360 bool isOnBoundary( const ElementID &elemID, int id ) const;
361 bool isInBlock( const ElementID &elemID, int id ) const;
362 static bool inIterator( const ElementID &id, const TriangleMeshIterator<NG> *it );
363
364 template<uint8_t TYPE>
365 std::array<int, TYPE + 1> getElem( const ElementID &id ) const;
366 template<uint8_t TYPE>
367 ElementID getID( const std::array<int, TYPE + 1> &id ) const;
368
369
370private:
371 void loadBalance( const std::vector<Point> &vertices,
372 const std::vector<TRI> &tri,
373 const std::vector<TRI> &tri_nab,
374 const std::vector<int> &block );
377 ElementList getParents( int childType, int parentType );
378
379
380private:
381 std::array<size_t, 4> d_N_global = { 0 };
384 std::vector<TRI> d_globalNab;
385 std::vector<int> d_blockID;
386 std::vector<std::vector<int>> d_remoteTri;
389 ElementList d_parents[NG + 1][NG + 1];
390 std::vector<int> d_block_ids;
391 std::vector<int> d_boundary_ids;
392 std::vector<bool> d_isSurface[NG + 1];
393 std::vector<IteratorSet> d_iterators;
394 std::vector<IteratorSet> d_surface_it;
395 std::vector<std::vector<IteratorSet>> d_boundary_it;
396 std::vector<std::vector<IteratorSet>> d_block_it;
397 uint64_t d_pos_hash = 0;
398};
399
400
401} // namespace AMP::Mesh
402
403
404#endif
Provides C++ wrapper around MPI routines.
Definition AMP_MPI.h:63
A pointer class to wrap a MeshElementVector.
A class used to iterate over elements in a Mesh.
A class used to abstract away mesh from an application.
Definition Mesh.h:57
std::unique_ptr< MeshElement > MeshElementPtr
Pointer to MeshElement and MeshElementVector.
Definition Mesh.h:69
Movable
Enumeration for basic mesh-based quantities.
Definition Mesh.h:73
const ElementID * begin(size_t i) const
std::vector< size_t > d_offset
const ElementID * end(size_t i) const
std::vector< size_t > d_size
StoreCompressedList(const std::vector< std::vector< TYPE > > &data)
int rank(int i) const
int start(int r) const
auto & operator[](const ElementID &id)
auto & offset() const
ElementID getID(int i) const
auto & operator[](const ElementID &id) const
const auto & operator()() const
std::vector< int > d_offset
const auto data() const
StoreTriData(std::vector< std::array< TYPE, N > > x, std::vector< int > offset, int rank, GeomType type)
int end(int r) const
std::vector< std::array< TYPE, N > > d_x
int find(const std::array< TYPE, N > &x) const
int index(const ElementID &id) const
auto & operator[](int i) const
auto & operator[](int i)
A class used to represent an unstructured mesh of Triangles/Tetrahedrals.
TriangleMesh(int NP, std::vector< Point > vertices, std::vector< TRI > triangles, std::vector< TRI > tri_nab, const AMP_MPI &comm, std::shared_ptr< Geometry::Geometry > geom={}, std::vector< int > block={}, int max_gcw=2)
Primary constructor.
ElementList d_parents[NG+1][NG+1]
Parent data.
std::array< size_t, 4 > d_N_global
The number of global elements.
static bool inIterator(const ElementID &id, const TriangleMeshIterator< NG > *it)
Movable isMeshMovable() const override
Is the mesh movable.
std::pair< const ElementID *, const ElementID * > getElementParents(const ElementID &id, const GeomType type) const
StoreTriData< int, 2 > d_childEdge
The list of local children edges.
std::unique_ptr< Mesh > clone() const override final
Virtual function to copy the mesh (allows use to proply copy the derived class)
std::vector< IteratorSet > createBlockIterators(int block)
void writeRestart(int64_t fid) const override
Write restart data to file.
virtual MeshIterator getSurfaceIterator(const GeomType type, const int gcw=0) const override final
Return an MeshIterator over the given geometric objects on the surface.
StoreCompressedList< ElementID > ElementList
std::vector< IteratorSet > d_iterators
[gcw][type]
MeshElement * getElement2(const MeshElementID &id) const
std::vector< std::vector< IteratorSet > > d_boundary_it
[id][gcw][type]
bool isOnSurface(const ElementID &elemID) const
TriangleMeshIterator< NG > createIterator(GeomType type, int gcw) const
ElementList computeNodeParents(int parentType)
std::array< TriangleMeshIterator< NG >, NG+1 > IteratorSet
std::array< int, TYPE+1 > getElem(const ElementID &id) const
virtual MeshIterator getBlockIDIterator(const GeomType type, const int id, const int gcw=0) const override final
Return an MeshIterator over the given geometric objects on the given block ID set.
std::vector< TRI > d_globalNab
Store the global triangle neighbors.
uint64_t positionHash() const override
Identify if the position has moved.
std::vector< std::vector< int > > d_remoteTri
The unique ghost triangles for each gcw.
ElementListPtr getElementParents(const MeshElement &elem, const GeomType type) const override final
Return the parent elements of the given mesh element.
void loadBalance(const std::vector< Point > &vertices, const std::vector< TRI > &tri, const std::vector< TRI > &tri_nab, const std::vector< int > &block)
void getElementsIDs(const ElementID &id, const GeomType type, ElementID *IDs) const
std::vector< int > d_boundary_ids
The global list of boundary ids.
size_t numGlobalElements(const GeomType type) const override final
std::vector< IteratorSet > d_surface_it
[gcw][type]
void displaceMesh(const std::vector< double > &x) override
Displace the entire mesh.
std::vector< int > getBoundaryIDs() const override final
Return the list of all boundary ID sets in the mesh.
void getNeighborIDs(const ElementID &id, std::vector< ElementID > &IDs) const
std::vector< std::vector< IteratorSet > > d_block_it
[id][gcw][type]
virtual MeshIterator getBoundaryIDIterator(const GeomType type, const int id, const int gcw=0) const override final
Return an MeshIterator over the given geometric objects on the given boundary ID set.
std::vector< bool > d_isSurface[NG+1]
Global list of surface elements.
std::string meshClass() const override
Return a string with the mesh class name.
std::array< int, 3 > Face
bool isOnBoundary(const ElementID &elemID, int id) const
ElementList getParents(int childType, int parentType)
MeshIterator getIterator(const GeomType type, const int gcw=0) const override final
Return an MeshIterator over the given geometric objects.
uint64_t d_pos_hash
Number of times position has changed.
std::vector< int > d_blockID
The block id index for each triangle.
StoreTriData< double, 3 > d_vertex
Store the global coordinates.
StoreTriData< int, 3 > d_childFace
The list of local children faces.
std::array< double, 3 > Point
size_t numLocalElements(const GeomType type) const override final
StoreTriData< int, NG+1 > d_globalTri
Store the global triangles.
void displaceMesh(std::shared_ptr< const AMP::LinearAlgebra::Vector > x) override
Displace the entire mesh.
size_t numGhostElements(const GeomType type, const int gcw) const override final
std::array< int, 2 > Edge
ElementID getID(const std::array< int, TYPE+1 > &id) const
bool isInBlock(const ElementID &elemID, int id) const
TriangleMesh(std::shared_ptr< const MeshParameters >)
std::array< int, NG+1 > TRI
void getVertexCoord(const ElementID &id, std::array< double, 3 > *x) const
std::vector< int > getBlockIDs() const override final
Return the list of all boundary ID sets in the mesh.
MeshElementPtr getElement(const MeshElementID &id) const override final
Return a mesh element given it's id.
std::vector< int > d_block_ids
The global list of block ids.
#define AMP_DEBUG_ASSERT(EXP)
Assert error (debug only)
GeomType
Enumeration for basic mesh-based quantities.
Definition MeshID.h:12
A structure used to identify an element within a mesh.
Definition MeshID.h:78
A structure used to identify the mesh element.
Definition MeshID.h:156



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:41.
Comments on this page