Advanced Multi-Physics (AMP)
On-Line Documentation
Mesh.h
Go to the documentation of this file.
1#ifndef included_AMP_Mesh
2#define included_AMP_Mesh
3
4#include "AMP/mesh/MeshID.h"
5#include "AMP/mesh/MeshIterator.h"
6#include "AMP/mesh/MeshParameters.h"
7#include "AMP/utils/AMP_MPI.h"
8#include "AMP/utils/Database.h"
9#include "AMP/utils/enable_shared_from_this.h"
10
11#include <iostream>
12#include <memory>
13
14
15// Forward declarations
16namespace AMP::Geometry {
17class Geometry;
18}
19namespace AMP::LinearAlgebra {
20class Vector;
21}
22namespace AMP::IO {
23class RestartManager;
24}
25
26
27namespace AMP::Mesh {
28
29
30class MeshElementVectorBase;
31
32
35
36
56class Mesh : public AMP::enable_shared_from_this<AMP::Mesh::Mesh>
57{
58public:
65 typedef std::function<std::shared_ptr<Mesh>( std::shared_ptr<const MeshParameters> )>
67
69 using MeshElementPtr = std::unique_ptr<MeshElement>;
71
73 enum class Movable : uint8_t { Fixed = 0, Displace = 1, Deform = 2 };
74
75
83 explicit Mesh( std::shared_ptr<const MeshParameters> params );
84
85
98 Mesh( const std::shared_ptr<Mesh> &old_mesh, MeshIterator &iterator );
99
100
106 inline auto getGeometry() { return d_geometry; }
107
108
114 inline auto getGeometry() const { return d_geometry; }
115
116
125 static size_t estimateMeshSize( std::shared_ptr<const MeshParameters> params );
126
127
134 static size_t maxProcs( std::shared_ptr<const MeshParameters> params );
135
136
138 virtual ~Mesh();
139
140
142 virtual std::unique_ptr<Mesh> clone() const = 0;
143
144
146 virtual std::string meshClass() const = 0;
147
148
157 virtual std::shared_ptr<Mesh> Subset( MeshID meshID ) const;
158
159
171 virtual std::shared_ptr<Mesh> Subset( std::string name ) const;
172
173
182 virtual std::shared_ptr<Mesh> Subset( const MeshIterator &iterator,
183 bool isGlobal = true ) const;
184
185
191 virtual std::shared_ptr<Mesh> Subset( Mesh &mesh ) const;
192
193
194 /* Return the number of local element of the given type
195 * \param type Geometric type
196 */
197 virtual size_t numLocalElements( const GeomType type ) const;
198
199
200 /* Return the global number of elements of the given type
201 * Note: depending on the mesh this routine may require global communication across the mesh.
202 * \param type Geometric type
203 */
204 virtual size_t numGlobalElements( const GeomType type ) const;
205
206
207 /* Return the number of ghost elements of the given type on the current processor
208 * \param type Geometric type
209 */
210 virtual size_t numGhostElements( const GeomType type, const int gcw ) const;
211
212
219 virtual MeshIterator getIterator( const GeomType type, const int gcw = 0 ) const;
220
221
228 virtual MeshIterator getSurfaceIterator( const GeomType type, const int gcw = 0 ) const;
229
230
236 virtual std::vector<int> getBoundaryIDs() const;
237
238
246 virtual MeshIterator
247 getBoundaryIDIterator( const GeomType type, const int id, const int gcw = 0 ) const;
248
254 virtual std::vector<int> getBlockIDs() const;
255
256
264 virtual MeshIterator
265 getBlockIDIterator( const GeomType type, const int id, const int gcw = 0 ) const;
266
267
280 static MeshIterator getIterator( SetOP OP, const MeshIterator &A, const MeshIterator &B );
284
285
292 virtual bool isMember( const MeshElementID &id ) const;
293
294
302 virtual MeshIterator isMember( const MeshIterator &it ) const;
303
304
314 virtual MeshElementPtr getElement( const MeshElementID &id ) const;
315
316
324 virtual ElementListPtr getElementParents( const MeshElement &elem, const GeomType type ) const;
325
326
328 inline GeomType getGeomType() const { return GeomDim; }
329
330
332 inline uint8_t getDim() const { return PhysicalDim; }
333
334
336 inline const AMP_MPI &getComm() const { return d_comm; }
337
338
340 inline uint8_t getMaxGhostWidth() const { return d_max_gcw; }
341
342
344 inline MeshID meshID() const { return d_meshID; }
345
346
348 virtual bool isBaseMesh() const;
349
350
352 virtual bool operator==( const Mesh &mesh ) const = 0;
353
354
356 inline bool operator!=( const Mesh &mesh ) const { return !operator==( mesh ); }
357
358
363 virtual std::vector<MeshID> getAllMeshIDs() const;
364
365
371 virtual std::vector<MeshID> getBaseMeshIDs() const;
372
373
378 virtual std::vector<MeshID> getLocalMeshIDs() const;
379
380
385 virtual std::vector<MeshID> getLocalBaseMeshIDs() const;
386
387
391 virtual bool containsElement( const MeshElementID &id ) const;
392
393
395 virtual inline std::string getName() const { return d_name; }
396
397
399 virtual inline void setName( std::string name ) { d_name = name; }
400
401
408 inline const auto &getBoundingBox() const { return d_box; }
409
410
417 inline const auto &getLocalBoundingBox() const { return d_box_local; }
418
419
425 virtual Movable isMeshMovable() const = 0;
426
427
437 virtual uint64_t positionHash() const = 0;
438
439
448 virtual void displaceMesh( const std::vector<double> &x ) = 0;
449
450
459 virtual void displaceMesh( std::shared_ptr<const AMP::LinearAlgebra::Vector> x ) = 0;
460
461
469 virtual std::shared_ptr<AMP::LinearAlgebra::Vector>
470 getPositionVector( std::string name, const int gcw = 0 ) const;
471
472
479 static std::shared_ptr<Mesh> createView( const Mesh &mesh, const AMP::Database &db );
480
481
483 static void printMeshHierarchy( const Mesh &mesh,
484 std::ostream &out = std::cout,
485 const std::string &prefix = "" );
486
487
488public:
491 bool equal;
492 bool nodes;
493 bool surface;
494 bool block;
495 bool domain;
496 bool geometry;
497 int result() const;
503 CompareResult( int state = 0 );
504 bool operator==( const CompareResult & ) const;
505 };
506
514 static CompareResult compare( const Mesh &a, const Mesh &b );
515
516
517public: // Write/read restart data
523 virtual void registerChildObjects( AMP::IO::RestartManager *manager ) const;
524
530 virtual void writeRestart( int64_t fid ) const;
531
532protected:
534 Mesh( int64_t fid, AMP::IO::RestartManager *manager );
535
537 static std::vector<double> reduceBox( const std::vector<double> &, const AMP_MPI & );
538
545 void setMeshID();
546
547protected:
550
551 // Private copy constructor
552 explicit Mesh( const Mesh &old );
553
554 // Private assigment operator
555 Mesh &operator=( const Mesh &old ) = delete;
556
557protected:
559 uint8_t PhysicalDim;
560 uint8_t d_max_gcw;
563 std::string d_name;
564 std::vector<double> d_box;
565 std::vector<double> d_box_local;
566 std::shared_ptr<Geometry::Geometry> d_geometry;
567};
568
569} // namespace AMP::Mesh
570
571#endif
Provides C++ wrapper around MPI routines.
Definition AMP_MPI.h:63
Class to a database.
Definition Database.h:111
Class to manage reading/writing restart data.
A pointer class to wrap a MeshElementVector.
A base class used to represent the end iterator.
A class used to iterate over elements in a Mesh.
A class used to abstract away mesh from an application.
Definition Mesh.h:57
const AMP_MPI & getComm() const
Get the communicator for the mesh.
Definition Mesh.h:336
std::string d_name
A name for the mesh.
Definition Mesh.h:563
std::function< std::shared_ptr< Mesh >(std::shared_ptr< const MeshParameters >)> generatorType
Generator for meshes.
Definition Mesh.h:66
const auto & getBoundingBox() const
Get the bounding box for the mesh.
Definition Mesh.h:408
virtual Movable isMeshMovable() const =0
Is the mesh movable.
std::vector< double > d_box_local
The bounding box for the mesh.
Definition Mesh.h:565
virtual std::vector< MeshID > getLocalMeshIDs() const
Mesh(std::shared_ptr< const MeshParameters > params)
Read in mesh files, partition domain, and prepare environment for simulation.
Mesh(int64_t fid, AMP::IO::RestartManager *manager)
Initialize the base class from file.
uint8_t d_max_gcw
The maximum ghost cell width.
Definition Mesh.h:560
virtual bool operator==(const Mesh &mesh) const =0
Check if two meshes are equal.
auto getGeometry() const
Return the geometry of the mesh.
Definition Mesh.h:114
virtual void displaceMesh(std::shared_ptr< const AMP::LinearAlgebra::Vector > x)=0
Displace the entire mesh.
static void printMeshHierarchy(const Mesh &mesh, std::ostream &out=std::cout, const std::string &prefix="")
Print the mesh hierarchy<iostream>
virtual MeshIterator isMember(const MeshIterator &it) const
Check if elements are in the mesh.
std::vector< double > d_box
The bounding box for the mesh.
Definition Mesh.h:564
static size_t maxProcs(std::shared_ptr< const MeshParameters > params)
Return the maximum number of processors that can be used with the mesh.
const auto & getLocalBoundingBox() const
Get the bounding box for the local part of the mesh.
Definition Mesh.h:417
virtual void displaceMesh(const std::vector< double > &x)=0
Displace the entire mesh.
bool operator!=(const Mesh &mesh) const
Check if two meshes are not equal.
Definition Mesh.h:356
uint8_t getDim() const
Get the physical dimension of the mesh.
Definition Mesh.h:332
virtual void registerChildObjects(AMP::IO::RestartManager *manager) const
Register child objects.
virtual MeshIterator getBlockIDIterator(const GeomType type, const int id, const int gcw=0) const
Return an MeshIterator over the given geometric objects on the given block ID set.
virtual std::vector< MeshID > getLocalBaseMeshIDs() const
static MeshIterator getIterator(SetOP OP, MeshIteratorEnd, MeshIteratorEnd)
virtual std::string getName() const
Get the mesh name.
Definition Mesh.h:395
virtual std::vector< int > getBlockIDs() const
Return the list of all boundary ID sets in the mesh.
virtual uint64_t positionHash() const =0
Identify if the position has moved.
AMP_MPI d_comm
The communicator over which the mesh is stored.
Definition Mesh.h:562
virtual void writeRestart(int64_t fid) const
Write restart data to file.
virtual bool isBaseMesh() const
Is the current mesh a base mesh.
GeomType getGeomType() const
Get the largest geometric type in the mesh.
Definition Mesh.h:328
virtual MeshIterator getIterator(const GeomType type, const int gcw=0) const
Return an MeshIterator over the given geometric objects.
uint8_t PhysicalDim
The physical dimension.
Definition Mesh.h:559
virtual std::unique_ptr< Mesh > clone() const =0
Virtual function to clone the mesh (allows us to properly copy the derived class)
std::unique_ptr< MeshElement > MeshElementPtr
Pointer to MeshElement and MeshElementVector.
Definition Mesh.h:69
Mesh(const Mesh &old)
static std::shared_ptr< Mesh > createView(const Mesh &mesh, const AMP::Database &db)
Create a view of existing mesh(s)
static MeshIterator getIterator(SetOP OP, const MeshIterator &A, const MeshIterator &B)
Return an MeshIterator constructed through a set operation of two other MeshIterators.
virtual std::vector< MeshID > getBaseMeshIDs() const
virtual ElementListPtr getElementParents(const MeshElement &elem, const GeomType type) const
Return the parent elements of the given mesh element.
static CompareResult compare(const Mesh &a, const Mesh &b)
Compare two meshes.
virtual std::vector< int > getBoundaryIDs() const
Return the list of all boundary ID sets in the mesh.
MeshID meshID() const
Get the mesh ID.
Definition Mesh.h:344
virtual std::string meshClass() const =0
Return a string with the mesh class name.
Mesh & operator=(const Mesh &old)=delete
virtual MeshIterator getSurfaceIterator(const GeomType type, const int gcw=0) const
Return an MeshIterator over the given geometric objects on the surface.
virtual MeshIterator getBoundaryIDIterator(const GeomType type, const int id, const int gcw=0) const
Iterate on the given boundary ID.
static std::vector< double > reduceBox(const std::vector< double > &, const AMP_MPI &)
Fill the domain box from the local box (requires communication)
static MeshIterator getIterator(SetOP OP, const MeshIterator &, MeshIteratorEnd)
virtual ~Mesh()
Deconstructor.
Movable
Enumeration for basic mesh-based quantities.
Definition Mesh.h:73
static MeshIterator getIterator(SetOP OP, MeshIteratorEnd, const MeshIterator &)
virtual std::shared_ptr< Mesh > Subset(std::string name) const
Subset a mesh given a mesh name.
virtual size_t numGhostElements(const GeomType type, const int gcw) const
virtual std::shared_ptr< Mesh > Subset(Mesh &mesh) const
Subset a mesh given another mesh.
std::shared_ptr< Geometry::Geometry > d_geometry
The geometry parameters.
Definition Mesh.h:566
uint8_t getMaxGhostWidth() const
Get the maximum ghost width.
Definition Mesh.h:340
virtual size_t numLocalElements(const GeomType type) const
virtual std::shared_ptr< AMP::LinearAlgebra::Vector > getPositionVector(std::string name, const int gcw=0) const
Get a vector of the coordinates of the nodes.
virtual bool isMember(const MeshElementID &id) const
Check if an element is in the mesh.
static size_t estimateMeshSize(std::shared_ptr< const MeshParameters > params)
Estimate the number of elements in the mesh.
virtual bool containsElement(const MeshElementID &id) const
Mesh(const std::shared_ptr< Mesh > &old_mesh, MeshIterator &iterator)
Construct a new mesh from an existing mesh.
Mesh()
Empty constructor for a mesh.
virtual std::vector< MeshID > getAllMeshIDs() const
MeshID d_meshID
A unique id for each mesh.
Definition Mesh.h:561
virtual size_t numGlobalElements(const GeomType type) const
virtual MeshElementPtr getElement(const MeshElementID &id) const
Return a mesh element given it's id.
virtual std::shared_ptr< Mesh > Subset(MeshID meshID) const
Subset a mesh given a MeshID.
GeomType GeomDim
The geometric dimension.
Definition Mesh.h:558
auto getGeometry()
Return the geometry of the mesh.
Definition Mesh.h:106
virtual std::shared_ptr< Mesh > Subset(const MeshIterator &iterator, bool isGlobal=true) const
Subset a mesh given a MeshIterator.
virtual void setName(std::string name)
Set the mesh name.
Definition Mesh.h:399
Enhancement of std::enable_shared_from_this.
GeomType
Enumeration for basic mesh-based quantities.
Definition MeshID.h:12
SetOP
Enumeration for basic mesh-based quantities.
Definition Mesh.h:34
A structure used to identify the mesh element.
Definition MeshID.h:156
A structure used to identify the mesh.
Definition MeshID.h:31
Structure used to compare matricies.
Definition Mesh.h:490
bool surface
surface ids match
Definition Mesh.h:493
bool domain
domain matches
Definition Mesh.h:495
bool nodes
Nodes match.
Definition Mesh.h:492
bool block
block ids match
Definition Mesh.h:494
bool operator==(const CompareResult &) const
bool geometry
geometries match
Definition Mesh.h:496
bool equal
Meshes are equal (operator==)
Definition Mesh.h:491



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