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