preCICE v3.1.2
Loading...
Searching...
No Matches
Mesh.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <Eigen/Core>
4#include <deque>
5#include <iosfwd>
6#include <list>
7#include <map>
8#include <string>
9#include <string_view>
10#include <vector>
11
12#include "logging/Logger.hpp"
13#include "mesh/BoundingBox.hpp"
14#include "mesh/Data.hpp"
15#include "mesh/Edge.hpp"
17#include "mesh/Tetrahedron.hpp"
18#include "mesh/Triangle.hpp"
19#include "mesh/Vertex.hpp"
21#include "query/Index.hpp"
23#include "utils/assertion.hpp"
24
25namespace precice {
26namespace mesh {
27
39class Mesh {
40public:
47
50
53 using ConnectionMap = CommunicationMap; // until we decide on a name
54
56
58 static constexpr MeshID MESH_ID_UNDEFINED{-1};
59
67 Mesh(
69 int dimensions,
70 MeshID id);
71
74
76 const Vertex &vertex(VertexID id) const;
77
80
82 const VertexContainer &vertices() const;
83
85 std::size_t nVertices() const;
86
88 bool empty() const
89 {
90 return _vertices.empty();
91 }
92
95
97 const EdgeContainer &edges() const;
98
99 bool hasEdges() const
100 {
101 return !_edges.empty();
102 }
103
106
108 const TriangleContainer &triangles() const;
109
110 bool hasTriangles() const
111 {
112 return !_triangles.empty();
113 }
114
117
119 const TetraContainer &tetrahedra() const;
120
121 bool hasTetrahedra() const
122 {
123 return !_tetrahedra.empty();
124 }
125
126 bool hasConnectivity() const
127 {
128 return hasEdges() || hasTriangles() || hasTetrahedra();
129 }
130
131 int getDimensions() const;
132
134 Vertex &createVertex(const Eigen::VectorXd &coords);
135
143 Vertex &vertexOne,
144 Vertex &vertexTwo);
145
154 Edge &edgeOne,
155 Edge &edgeTwo,
156 Edge &edgeThree);
157
166 Vertex &vertexOne,
167 Vertex &vertexTwo,
168 Vertex &vertexThree);
169
179 Vertex &vertexOne,
180 Vertex &vertexTwo,
181 Vertex &vertexThree,
182 Vertex &vertexFour);
183
186 int dimension,
187 DataID id,
188 int waveformDegree = time::Time::DEFAULT_WAVEFORM_DEGREE);
189
191 const DataContainer &data() const;
192
194 bool hasDataID(DataID dataID) const;
195
197 const PtrData &data(DataID dataID) const;
198
200 bool hasDataName(std::string_view dataName) const;
201
204
206 const PtrData &data(std::string_view dataName) const;
207
209 const std::string &getName() const;
210
212 MeshID getID() const;
213
215 bool isValidVertexID(VertexID vertexID) const;
216
218 void allocateDataValues(); //@todo Redesign mapping and remove this function. See https://github.com/precice/precice/issues/1651.
219
221 void computeBoundingBox();
222
231 void clear();
232
234 void clearPartitioning();
235
237 {
238 PRECICE_ASSERT(std::all_of(vd.begin(), vd.end(), [](const auto &p) { return std::is_sorted(p.second.begin(), p.second.end()); }));
239 _vertexDistribution = std::move(vd);
240 }
241
244 {
245 return _vertexDistribution;
246 }
247
249 {
250 return _vertexOffsets;
251 }
252
254 void setVertexOffsets(VertexOffsets vertexOffsets)
255 {
256 _vertexOffsets = std::move(vertexOffsets);
257 }
258
260 {
262 }
263
265 {
267 }
268
269 // Get the data of owned vertices for given data ID
270 Eigen::VectorXd getOwnedVertexData(const Eigen::VectorXd &values);
271
272 // Tag all the vertices
273 void tagAll();
274
277 {
278 return _connectedRanks;
279 }
280
283 {
284 _connectedRanks = std::move(ranks);
285 }
286
292
293 void addMesh(Mesh &deltaMesh);
294
306 const BoundingBox &getBoundingBox() const;
307
308 void expandBoundingBox(const BoundingBox &bounding_box);
309
310 bool operator==(const Mesh &other) const;
311
312 bool operator!=(const Mesh &other) const;
313
315 const query::Index &index() const
316 {
317 return _index;
318 }
319
322 {
323 return _index;
324 }
325
334 void preprocess();
335
336private:
337 mutable logging::Logger _log{"mesh::Mesh"};
338
341
344
347
353
356
363
365
370
377
383
389
391
393
395 void removeDuplicates();
396
402};
403
405
406} // namespace mesh
407} // namespace precice
std::string name
T all_of(T... args)
#define PRECICE_ASSERT(...)
Definition assertion.hpp:87
T begin(T... args)
This class provides a lightweight logger.
Definition Logger.hpp:16
An axis-aligned bounding box around a (partition of a) mesh.
Linear edge of a mesh, defined by two Vertex objects.
Definition Edge.hpp:16
Container and creator for meshes.
Definition Mesh.hpp:39
void expandBoundingBox(const BoundingBox &bounding_box)
Definition Mesh.cpp:370
Triangle & createTriangle(Edge &edgeOne, Edge &edgeTwo, Edge &edgeThree)
Creates and initializes a Triangle object.
Definition Mesh.cpp:119
void setGlobalNumberOfVertices(int num)
Definition Mesh.hpp:264
const VertexDistribution & getVertexDistribution() const
Returns a mapping from rank to used (not necessarily owned) vertex IDs.
Definition Mesh.hpp:243
MeshID _id
The ID of this mesh.
Definition Mesh.hpp:346
MeshID getID() const
Returns the base ID of the mesh.
Definition Mesh.cpp:223
int getGlobalNumberOfVertices() const
Definition Mesh.hpp:259
std::string _name
Name of the mesh.
Definition Mesh.hpp:340
std::map< Rank, std::vector< VertexID > > CommunicationMap
A mapping from remote local ranks to the IDs that must be communicated.
Definition Mesh.hpp:52
BoundingBox _boundingBox
Definition Mesh.hpp:390
std::deque< Triangle > TriangleContainer
Definition Mesh.hpp:43
bool hasTetrahedra() const
Definition Mesh.hpp:121
void setVertexDistribution(VertexDistribution vd)
Definition Mesh.hpp:236
int _globalNumberOfVertices
Number of unique vertices for complete distributed mesh.
Definition Mesh.hpp:376
int getDimensions() const
Definition Mesh.cpp:98
VertexContainer & vertices()
Returns modifieable container holding all vertices.
Definition Mesh.cpp:53
std::vector< PtrData > DataContainer
Definition Mesh.hpp:45
bool hasDataID(DataID dataID) const
Returns whether Mesh has Data with the matchingID.
Definition Mesh.cpp:175
Eigen::VectorXd getOwnedVertexData(const Eigen::VectorXd &values)
Definition Mesh.cpp:279
void clear()
Removes all mesh elements and data values (does not remove data or the bounding boxes).
Definition Mesh.cpp:256
DataContainer _data
Data hold by the vertices of the mesh.
Definition Mesh.hpp:355
bool hasEdges() const
Definition Mesh.hpp:99
void addMesh(Mesh &deltaMesh)
Definition Mesh.cpp:309
bool operator!=(const Mesh &other) const
Definition Mesh.cpp:509
std::vector< std::string > availableData() const
Returns the names of all available data.
Definition Mesh.cpp:200
const std::string & getName() const
Returns the name of the mesh, as set in the config file.
Definition Mesh.cpp:218
void removeDuplicates()
Removes all duplicate connectivity.
Definition Mesh.cpp:381
static constexpr MeshID MESH_ID_UNDEFINED
Use if the id of the mesh is not necessary.
Definition Mesh.hpp:58
std::size_t nVertices() const
Returns the number of vertices.
Definition Mesh.cpp:63
bool hasConnectivity() const
Definition Mesh.hpp:126
VertexDistribution _vertexDistribution
Vertex distribution for the primary rank, holding for each secondary rank all vertex IDs it owns.
Definition Mesh.hpp:362
CommunicationMap & getCommunicationMap()
Returns a mapping from remote local connected ranks to the corresponding vertex IDs.
Definition Mesh.hpp:288
TetraContainer & tetrahedra()
Returns modifiable container holding all tetrahedra.
Definition Mesh.cpp:93
std::deque< Tetrahedron > TetraContainer
Definition Mesh.hpp:44
bool operator==(const Mesh &other) const
Definition Mesh.cpp:497
logging::Logger _log
Definition Mesh.hpp:337
std::vector< Rank > _connectedRanks
each rank stores list of connected remote ranks. In the m2n package, this is used to create the initi...
Definition Mesh.hpp:382
TetraContainer _tetrahedra
Definition Mesh.hpp:352
Vertex & vertex(VertexID id)
Mutable access to a vertex by VertexID.
Definition Mesh.cpp:41
Mesh(std::string name, int dimensions, MeshID id)
Constructor.
Definition Mesh.cpp:27
const query::Index & index() const
Call preprocess() before index() to ensure correct projection handling.
Definition Mesh.hpp:315
query::Index _index
Definition Mesh.hpp:392
VertexContainer _vertices
Holds vertices, edges, triangles and tetrahedra.
Definition Mesh.hpp:349
bool hasDataName(std::string_view dataName) const
Returns whether Mesh has Data with the dataName.
Definition Mesh.cpp:192
std::deque< Edge > EdgeContainer
Definition Mesh.hpp:42
PtrData & createData(const std::string &name, int dimension, DataID id, int waveformDegree=time::Time::DEFAULT_WAVEFORM_DEGREE)
Create only data for vertex.
Definition Mesh.cpp:151
CommunicationMap _communicationMap
each rank stores list of connected ranks and corresponding vertex IDs here. In the m2n package,...
Definition Mesh.hpp:388
bool empty() const
Does the mesh contain any vertices?
Definition Mesh.hpp:88
void generateImplictPrimitives()
Definition Mesh.cpp:432
const std::vector< Rank > & getConnectedRanks() const
Returns a vector of connected ranks.
Definition Mesh.hpp:276
const VertexOffsets & getVertexOffsets() const
Definition Mesh.hpp:248
void clearPartitioning()
Clears the partitioning information.
Definition Mesh.cpp:270
void computeBoundingBox()
Computes the boundingBox for the vertices.
Definition Mesh.cpp:242
TriangleContainer _triangles
Definition Mesh.hpp:351
Tetrahedron & createTetrahedron(Vertex &vertexOne, Vertex &vertexTwo, Vertex &vertexThree, Vertex &vertexFour)
Creates and initializes a Tetrahedron object.
Definition Mesh.cpp:141
VertexOffsets _vertexOffsets
Holds the index of the last vertex for each rank.
Definition Mesh.hpp:369
void setVertexOffsets(VertexOffsets vertexOffsets)
Only used for tests.
Definition Mesh.hpp:254
bool isValidVertexID(VertexID vertexID) const
Returns true if the given vertexID is valid.
Definition Mesh.cpp:228
EdgeContainer _edges
Definition Mesh.hpp:350
void setConnectedRanks(std::vector< Rank > ranks)
Returns a vector of connected ranks.
Definition Mesh.hpp:282
const DataContainer & data() const
Allows access to all data.
Definition Mesh.cpp:170
TriangleContainer & triangles()
Returns modifiable container holding all triangles.
Definition Mesh.cpp:78
const BoundingBox & getBoundingBox() const
Returns the bounding box of the mesh.
Definition Mesh.cpp:365
query::Index & index()
Call preprocess() before index() to ensure correct projection handling.
Definition Mesh.hpp:321
std::deque< Vertex > VertexContainer
Definition Mesh.hpp:41
Edge & createEdge(Vertex &vertexOne, Vertex &vertexTwo)
Creates and initializes an Edge object.
Definition Mesh.cpp:111
EdgeContainer & edges()
Returns modifiable container holding all edges.
Definition Mesh.cpp:68
Vertex & createVertex(const Eigen::VectorXd &coords)
Creates and initializes a Vertex object.
Definition Mesh.cpp:103
void allocateDataValues()
Allocates memory for the vertex data values and corresponding gradient values.
Definition Mesh.cpp:233
bool hasTriangles() const
Definition Mesh.hpp:110
int _dimensions
Dimension of mesh.
Definition Mesh.hpp:343
Tetrahedron of a mesh, defined by 4 vertices.
Triangle of a mesh, defined by three vertices.
Definition Triangle.hpp:27
Vertex of a mesh.
Definition Vertex.hpp:16
Class to query the index trees of the mesh.
Definition Index.hpp:65
static const int DEFAULT_WAVEFORM_DEGREE
To be used, when the interpolation degree is not defined.
Definition Time.hpp:9
T empty(T... args)
T end(T... args)
std::ostream & operator<<(std::ostream &os, const BoundingBox &bb)
Main namespace of the precice library.
int MeshID
Definition Types.hpp:30
int VertexID
Definition Types.hpp:13
int DataID
Definition Types.hpp:25