preCICE v3.1.2
Loading...
Searching...
No Matches
Polation.cpp
Go to the documentation of this file.
2#include <Eigen/src/Core/Matrix.h>
3#include "math/barycenter.hpp"
5
6namespace precice::mapping {
7
8Polation::Polation(const Eigen::VectorXd &location, const mesh::Vertex &element)
9{
10 _weightedElements.emplace_back(WeightedElement{element.getID(), 1.0});
11 // The projection in this case is simply the nearest point.
12 _distance = (location - element.getCoords()).norm();
13}
14
15Polation::Polation(const Eigen::VectorXd &location, const mesh::Edge &element)
16{
17 PRECICE_ASSERT(location.size() == element.getDimensions(), location.size(), element.getDimensions());
18 const auto &A = element.vertex(0);
19 const auto &B = element.vertex(1);
20
22 A.getCoords(),
23 B.getCoords(),
24 location);
25
26 _weightedElements.emplace_back(WeightedElement{A.getID(), bcoords(0)});
27 _weightedElements.emplace_back(WeightedElement{B.getID(), bcoords(1)});
28
29 Eigen::VectorXd projection = A.getCoords() * bcoords(0) +
30 B.getCoords() * bcoords(1);
31 _distance = (location - projection).norm();
32}
33
34Polation::Polation(const Eigen::VectorXd &location, const mesh::Triangle &element)
35{
36 PRECICE_ASSERT(location.size() == element.getDimensions(), location.size(), element.getDimensions());
37 auto &A = element.vertex(0);
38 auto &B = element.vertex(1);
39 auto &C = element.vertex(2);
40
42 A.getCoords(),
43 B.getCoords(),
44 C.getCoords(),
45 location);
46
47 _weightedElements.emplace_back(WeightedElement{A.getID(), bcoords(0)});
48 _weightedElements.emplace_back(WeightedElement{B.getID(), bcoords(1)});
49 _weightedElements.emplace_back(WeightedElement{C.getID(), bcoords(2)});
50
51 Eigen::VectorXd projection = A.getCoords() * bcoords(0) +
52 B.getCoords() * bcoords(1) +
53 C.getCoords() * bcoords(2);
54 _distance = (location - projection).norm();
55}
56
57Polation::Polation(const Eigen::VectorXd &location, const mesh::Tetrahedron &element)
58{
59 PRECICE_ASSERT(location.size() == element.getDimensions(), location.size(), element.getDimensions());
60 auto &A = element.vertex(0);
61 auto &B = element.vertex(1);
62 auto &C = element.vertex(2);
63 auto &D = element.vertex(3);
64
66 A.getCoords(),
67 B.getCoords(),
68 C.getCoords(),
69 D.getCoords(),
70 location);
71
72 _weightedElements.emplace_back(WeightedElement{A.getID(), bcoords(0)});
73 _weightedElements.emplace_back(WeightedElement{B.getID(), bcoords(1)});
74 _weightedElements.emplace_back(WeightedElement{C.getID(), bcoords(2)});
75 _weightedElements.emplace_back(WeightedElement{D.getID(), bcoords(3)});
76
77 // There is no projection happening, so the distance is always 0.
78 _distance = 0.0;
79}
80
85
87{
88 return std::all_of(_weightedElements.begin(), _weightedElements.end(), [](const mapping::WeightedElement &elem) { return precice::math::greaterEquals(elem.weight, 0.0); });
89}
90
91double Polation::distance() const
92{
93 return _distance;
94}
95
97{
98 return os << "(Vertex ID: " << w.vertexID << ", Weight: " << w.weight << ")";
99}
100
102{
103 os << "Polation: ";
104 for (const auto &elem : p.getWeightedElements()) {
105 os << elem;
106 }
107 return os;
108}
109
110} // namespace precice::mapping
T all_of(T... args)
#define PRECICE_ASSERT(...)
Definition assertion.hpp:87
Calculates the barycentric coordinates of a coordinate on the given vertex/edge/triangle and stores t...
Definition Polation.hpp:24
std::vector< WeightedElement > _weightedElements
Definition Polation.hpp:48
bool isInterpolation() const
Check whether all the weights are positive, which means it is interpolation.
Definition Polation.cpp:86
Polation(const Eigen::VectorXd &location, const mesh::Vertex &element)
Calculate projection to a vertex. Weight is always 1.0.
Definition Polation.cpp:8
double distance() const
Returns the projection distance.
Definition Polation.cpp:91
const std::vector< WeightedElement > & getWeightedElements() const
Get the weights and indices of the calculated interpolation.
Definition Polation.cpp:81
Linear edge of a mesh, defined by two Vertex objects.
Definition Edge.hpp:16
int getDimensions() const
Returns number of spatial dimensions (2 or 3) the edge is embedded to.
Definition Edge.hpp:91
Vertex & vertex(int i)
Returns the edge's vertex with index 0 or 1.
Definition Edge.hpp:77
Tetrahedron of a mesh, defined by 4 vertices.
Vertex & vertex(int i)
Returns tetrahedron vertex with index 0, 1, 2 or 3.
int getDimensions() const
Returns dimensionalty of space the Tetrahedron is embedded in.
Triangle of a mesh, defined by three vertices.
Definition Triangle.hpp:27
int getDimensions() const
Returns dimensionalty of space the triangle is embedded in.
Definition Triangle.cpp:84
Vertex & vertex(int i)
Returns triangle vertex with index 0, 1 or 2.
Definition Triangle.hpp:143
Vertex of a mesh.
Definition Vertex.hpp:16
VertexID getID() const
Returns the unique (among vertices of one mesh on one processor) ID of the vertex.
Definition Vertex.hpp:111
Eigen::VectorXd getCoords() const
Returns the coordinates of the vertex.
Definition Vertex.hpp:116
contains data mapping from points to meshes.
std::ostream & operator<<(std::ostream &out, Mapping::MeshRequirement val)
Definition Mapping.cpp:275
Eigen::Vector3d calcBarycentricCoordsForTriangle(const Eigen::VectorXd &a, const Eigen::VectorXd &b, const Eigen::VectorXd &c, const Eigen::VectorXd &u)
Eigen::Vector4d calcBarycentricCoordsForTetrahedron(const Eigen::VectorXd &a, const Eigen::VectorXd &b, const Eigen::VectorXd &c, const Eigen::VectorXd &d, const Eigen::VectorXd &u)
Eigen::Vector2d calcBarycentricCoordsForEdge(const Eigen::VectorXd &a, const Eigen::VectorXd &b, const Eigen::VectorXd &u)
Struct that contains weight and index of a vertex.
Definition Polation.hpp:15