preCICE v3.1.2
Loading...
Searching...
No Matches
Index.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <vector>
5
6#include "logging/Logger.hpp"
9#include "mesh/Edge.hpp"
11#include "mesh/Tetrahedron.hpp"
12#include "mesh/Triangle.hpp"
13#include "mesh/Vertex.hpp"
15
16namespace precice {
17namespace query {
18
20using MatchID = int;
21
22constexpr MatchID NO_MATCH{-1};
23
25using Distance = double;
26constexpr double INVALID_DISTANCE{-1};
27
29template <class Tag>
30struct MatchType {
32 MatchType() = default;
33 explicit MatchType(MatchID i)
34 : index(i){};
35};
36
43
50
51 ProjectionMatch(const ProjectionMatch &other) = default;
52 ProjectionMatch(ProjectionMatch &&other) = default;
53 ProjectionMatch &operator=(const ProjectionMatch &other) = default;
55
57
58 bool operator<(ProjectionMatch const &other) const
59 {
60 return polation.distance() < other.polation.distance();
61 };
62};
63
65class Index {
66
67public:
68 Index(mesh::PtrMesh mesh);
69 Index(mesh::Mesh &mesh);
71
73 VertexMatch getClosestVertex(const Eigen::VectorXd &sourceCoord);
74
76 std::vector<VertexID> getClosestVertices(const Eigen::VectorXd &sourceCoord, int n);
77
79 std::vector<EdgeMatch> getClosestEdges(const Eigen::VectorXd &sourceCoord, int n);
80
82 std::vector<TriangleMatch> getClosestTriangles(const Eigen::VectorXd &sourceCoord, int n);
83
85 std::vector<VertexID> getVerticesInsideBox(const mesh::Vertex &centerVertex, double radius);
86
89
91 bool isAnyVertexInsideBox(const mesh::Vertex &centerVertex, double radius);
92
94 std::vector<TetrahedronID> getEnclosingTetrahedra(const Eigen::VectorXd &location);
95
106 ProjectionMatch findNearestProjection(const Eigen::VectorXd &location, int n);
107
108 ProjectionMatch findCellOrProjection(const Eigen::VectorXd &location, int n);
109
110 // Index tree, bounds
112
114 void clear();
115
116private:
117 class IndexImpl;
119
122
124
126 ProjectionMatch findVertexProjection(const Eigen::VectorXd &location);
127
129 ProjectionMatch findEdgeProjection(const Eigen::VectorXd &location, int n, ProjectionMatch closestVertex);
130
132 ProjectionMatch findTriangleProjection(const Eigen::VectorXd &location, int n, ProjectionMatch closestVertex);
133};
134
135} // namespace query
136} // namespace precice
This class provides a lightweight logger.
Definition Logger.hpp:16
Calculates the barycentric coordinates of a coordinate on the given vertex/edge/triangle and stores t...
Definition Polation.hpp:24
double distance() const
Returns the projection distance.
Definition Polation.cpp:91
An axis-aligned bounding box around a (partition of a) mesh.
Container and creator for meshes.
Definition Mesh.hpp:39
Vertex of a mesh.
Definition Vertex.hpp:16
Class to query the index trees of the mesh.
Definition Index.hpp:65
mesh::BoundingBox getRtreeBounds()
Definition Index.cpp:367
std::vector< TetrahedronID > getEnclosingTetrahedra(const Eigen::VectorXd &location)
Return all the tetrahedra whose axis-aligned bounding box contains a vertex.
Definition Index.cpp:263
mesh::Mesh * _mesh
The indexed Mesh.
Definition Index.hpp:121
ProjectionMatch findCellOrProjection(const Eigen::VectorXd &location, int n)
Definition Index.cpp:284
VertexMatch getClosestVertex(const Eigen::VectorXd &sourceCoord)
Get the closest vertex to the given vertex.
Definition Index.cpp:171
ProjectionMatch findNearestProjection(const Eigen::VectorXd &location, int n)
Find the closest interpolation element to the given location. If exists, triangle or edge projection ...
Definition Index.cpp:275
bool isAnyVertexInsideBox(const mesh::Vertex &centerVertex, double radius)
Returns.
Definition Index.cpp:238
std::unique_ptr< IndexImpl > _pimpl
Definition Index.hpp:118
std::vector< TriangleMatch > getClosestTriangles(const Eigen::VectorXd &sourceCoord, int n)
Get n number of closest triangles to the given vertex.
Definition Index.cpp:210
std::vector< VertexID > getVerticesInsideBox(const mesh::Vertex &centerVertex, double radius)
Return all the vertices inside the box formed by vertex and radius (boundary exclusive)
Definition Index.cpp:223
void clear()
Clear the index.
Definition Index.cpp:391
ProjectionMatch findEdgeProjection(const Eigen::VectorXd &location, int n, ProjectionMatch closestVertex)
Find closest edge interpolation element. If cannot be found, it falls back to vertex projection.
Definition Index.cpp:318
ProjectionMatch findVertexProjection(const Eigen::VectorXd &location)
Closest vertex projection element is always the nearest neighbor.
Definition Index.cpp:312
Index(mesh::PtrMesh mesh)
Definition Index.cpp:156
std::vector< VertexID > getClosestVertices(const Eigen::VectorXd &sourceCoord, int n)
Get n number of closest vertices to the given vertex.
Definition Index.cpp:184
ProjectionMatch findTriangleProjection(const Eigen::VectorXd &location, int n, ProjectionMatch closestVertex)
Find closest face interpolation element. If cannot be found, it falls back to first edge interpolatio...
Definition Index.cpp:342
std::vector< EdgeMatch > getClosestEdges(const Eigen::VectorXd &sourceCoord, int n)
Get n number of closest edges to the given vertex.
Definition Index.cpp:197
static precice::logging::Logger _log
Definition Index.hpp:123
double Distance
Type used for the distance of a match to the queried point.
Definition Index.hpp:25
int MatchID
Type used for the IDs of matching entities.
Definition Index.hpp:20
constexpr double INVALID_DISTANCE
Definition Index.hpp:26
constexpr MatchID NO_MATCH
Definition Index.hpp:22
Main namespace of the precice library.
STL namespace.
Struct to hold the index of a primitive match.
Definition Index.hpp:30
Struct representing a projection match.
Definition Index.hpp:45
mapping::Polation polation
Definition Index.hpp:56
ProjectionMatch(mapping::Polation &&p)
Definition Index.hpp:48
ProjectionMatch(const ProjectionMatch &other)=default
bool operator<(ProjectionMatch const &other) const
Definition Index.hpp:58
ProjectionMatch & operator=(ProjectionMatch &&other)=default
ProjectionMatch(ProjectionMatch &&other)=default
ProjectionMatch(const mapping::Polation &p)
Definition Index.hpp:46
ProjectionMatch & operator=(const ProjectionMatch &other)=default