4#include <boost/container/flat_map.hpp>
117 _edges.emplace_back(vertexOne, vertexTwo);
130 _triangles.emplace_back(edgeOne, edgeTwo, edgeThree);
139 _triangles.emplace_back(vertexOne, vertexTwo, vertexThree);
149 _tetrahedra.emplace_back(vertexOne, vertexTwo, vertexThree, vertexFour);
154 const std::string &name,
162 "Data \"{}\" cannot be created twice for mesh \"{}\". "
163 "Please rename or remove one of the use-data tags with name \"{}\".",
167 std::vector<std::optional<double>> lowerBound = std::vector<std::optional<double>>(dimension);
168 std::vector<std::optional<double>> upperBound = std::vector<std::optional<double>>(dimension);
175 const std::string &name,
179 std::vector<std::optional<double>> lowerBound,
180 std::vector<std::optional<double>> upperBound)
185 "Data \"{}\" cannot be created twice for mesh \"{}\". "
186 "Please rename or remove one of the use-data tags with name \"{}\".",
202 auto iter = std::find_if(
_data.begin(),
_data.end(), [dataID](
const auto &dptr) {
203 return dptr->getID() == dataID;
205 return iter !=
_data.end();
210 auto iter = std::find_if(
_data.begin(),
_data.end(), [dataID](
const auto &dptr) {
211 return dptr->getID() == dataID;
219 auto iter = std::find_if(
_data.begin(),
_data.end(), [&dataName](
const auto &dptr) {
220 return dptr->getName() == dataName;
222 return iter !=
_data.end();
227 std::vector<std::string> names;
229 names.push_back(
data->getName());
236 auto iter = std::find_if(
_data.begin(),
_data.end(), [&dataName](
const auto &dptr) {
237 return dptr->getName() == dataName;
255 return (0 <= vertexID) && (
static_cast<size_t>(vertexID) <
nVertices());
261 const auto expectedCount =
_vertices.size();
263 data->allocateValues(expectedCount);
291 data->values().resize(0);
308 data->waveform().clear();
327 std::vector<double> ownedDataVector;
332 int valueDim = values.size() /
nVertices();
337 for (
int dim = 0; dim < valueDim; ++dim) {
338 ownedDataVector.push_back(values[
index * valueDim + dim]);
343 Eigen::Map<Eigen::VectorXd> ownedData(ownedDataVector.data(), ownedDataVector.size());
356 const Mesh &deltaMesh)
398 auto edgeCnt =
_edges.size();
400 auto lastEdge = std::unique(
_edges.begin(),
_edges.end());
403 PRECICE_DEBUG(
"Compression removed {} tetrahedra ({} to {}), {} triangles ({} to {}), and {} edges ({} to {})",
411template <
class Primitive,
int... Indices>
412auto sortedVertexPtrsForImpl(Primitive &p, std::integer_sequence<int, Indices...>)
414 std::array<Vertex *, Primitive::vertexCount> vs{&p.vertex(Indices)...};
415 std::sort(vs.begin(), vs.end());
416 return std::tuple_cat(vs);
427template <
class Primitive>
428auto sortedVertexPtrsFor(Primitive &p)
430 return sortedVertexPtrsForImpl(p, std::make_integer_sequence<int, Primitive::vertexCount>{});
448 using ExisitingTriangle = std::tuple<Vertex *, Vertex *, Vertex *>;
451 triangles.insert(sortedVertexPtrsFor(t));
463 auto [a, b, c, d] = sortedVertexPtrsFor(t);
465 createTriangleIfMissing(a, b, c);
466 createTriangleIfMissing(a, b, d);
467 createTriangleIfMissing(a, c, d);
468 createTriangleIfMissing(b, c, d);
473 using ExisitingEdge = std::tuple<Vertex *, Vertex *>;
474 std::set<ExisitingEdge>
edges;
476 edges.emplace(sortedVertexPtrsFor(e));
481 if (
edges.count({a, b}) == 0) {
487 auto [a, b, c] = sortedVertexPtrsFor(t);
489 createEdgeIfMissing(a, b);
490 createEdgeIfMissing(a, c);
491 createEdgeIfMissing(b, c);
494 PRECICE_DEBUG(
"Generated {} implicit triangles and {} implicit edges",
496 _edges.size() - explEdges);
513 return !(*
this == other);
519 os <<
"GEOMETRYCOLLECTION(\n";
520 const auto token =
", ";
521 const auto *sep =
"";
527 for (
auto &edge : m.
edges()) {
533 os << sep << triangle;
#define PRECICE_DEBUG(...)
#define PRECICE_TRACE(...)
#define PRECICE_CHECK(check,...)
#define PRECICE_ASSERT(...)
An axis-aligned bounding box around a (partition of a) mesh.
void expandBy(const BoundingBox &otherBB)
Expand bounding box using another bounding box.
Describes a set of data values belonging to the vertices of a mesh.
Linear edge of a mesh, defined by two Vertex objects.
bool connectedTo(const Edge &other) const
Checks whether both edges share a vertex.
Container and creator for meshes.
void expandBoundingBox(const BoundingBox &bounding_box)
Triangle & createTriangle(Edge &edgeOne, Edge &edgeTwo, Edge &edgeThree)
Creates and initializes a Triangle object.
MeshID _id
The ID of this mesh.
MeshID getID() const
Returns the base ID of the mesh.
std::string _name
Name of the mesh.
std::deque< Triangle > TriangleContainer
int _globalNumberOfVertices
Number of unique vertices for complete distributed mesh.
int getDimensions() const
VertexContainer & vertices()
Returns modifieable container holding all vertices.
void clearDataStamples()
Clears all data stamples.
std::vector< PtrData > DataContainer
bool hasDataID(DataID dataID) const
Returns whether Mesh has Data with the matchingID.
Eigen::VectorXd getOwnedVertexData(const Eigen::VectorXd &values)
void clear()
Removes all mesh elements and data values (does not remove data or the bounding boxes).
DataContainer _data
Data hold by the vertices of the mesh.
void addMesh(const Mesh &deltaMesh)
bool operator!=(const Mesh &other) const
std::vector< std::string > availableData() const
Returns the names of all available data.
const std::string & getName() const
Returns the name of the mesh, as set in the config file.
void removeDuplicates()
Removes all duplicate connectivity.
std::size_t nVertices() const
Returns the number of vertices.
VertexDistribution _vertexDistribution
Vertex distribution for the primary rank, holding for each secondary rank all vertex IDs it owns.
TetraContainer & tetrahedra()
Returns modifiable container holding all tetrahedra.
std::deque< Tetrahedron > TetraContainer
bool operator==(const Mesh &other) const
std::vector< Rank > _connectedRanks
each rank stores list of connected remote ranks. In the m2n package, this is used to create the initi...
bool _isJustInTime
for just-in-time mapping, we need an artificial mesh, which we can use
TetraContainer _tetrahedra
Vertex & vertex(VertexID id)
Mutable access to a vertex by VertexID.
bool isJustInTime() const
Mesh(std::string name, int dimensions, MeshID id, bool isJustInTime=false)
Constructor.
const query::Index & index() const
Call preprocess() before index() to ensure correct projection handling.
VertexContainer _vertices
Holds vertices, edges, triangles and tetrahedra.
bool hasDataName(std::string_view dataName) const
Returns whether Mesh has Data with the dataName.
std::deque< Edge > EdgeContainer
PtrData & createData(const std::string &name, int dimension, DataID id, int waveformDegree=time::Time::DEFAULT_WAVEFORM_DEGREE)
Create only data for vertex.
CommunicationMap _communicationMap
each rank stores list of connected ranks and corresponding vertex IDs here. In the m2n package,...
bool empty() const
Does the mesh contain any vertices?
void generateImplictPrimitives()
void clearPartitioning()
Clears the partitioning information.
void computeBoundingBox()
Computes the boundingBox for the vertices.
TriangleContainer _triangles
bool isPartitionEmpty(Rank rank) const
checks if the given ranks partition is empty
Tetrahedron & createTetrahedron(Vertex &vertexOne, Vertex &vertexTwo, Vertex &vertexThree, Vertex &vertexFour)
Creates and initializes a Tetrahedron object.
VertexOffsets _vertexOffsets
Holds the index of the last vertex for each rank.
bool isValidVertexID(VertexID vertexID) const
Returns true if the given vertexID is valid.
const DataContainer & data() const
Allows access to all data.
TriangleContainer & triangles()
Returns modifiable container holding all triangles.
const BoundingBox & getBoundingBox() const
Returns the bounding box of the mesh.
std::deque< Vertex > VertexContainer
Edge & createEdge(Vertex &vertexOne, Vertex &vertexTwo)
Creates and initializes an Edge object.
Vertex & createVertex(const Eigen::Ref< const Eigen::VectorXd > &coords)
Creates and initializes a Vertex object.
EdgeContainer & edges()
Returns modifiable container holding all edges.
void allocateDataValues()
Allocates memory for the vertex data values and corresponding gradient values.
int _dimensions
Dimension of mesh.
Tetrahedron of a mesh, defined by 4 vertices.
Triangle of a mesh, defined by three vertices.
provides Mesh, Data and primitives.
void filterMesh(Mesh &destination, const Mesh &source, UnaryPredicate &&p)
std::shared_ptr< Data > PtrData
std::ostream & operator<<(std::ostream &os, const BoundingBox &bb)