preCICE v3.1.2
Loading...
Searching...
No Matches
LinearCellInterpolationMapping.cpp
Go to the documentation of this file.
3#include "profiling/Event.hpp"
4#include "query/Index.hpp"
5#include "utils/IntraComm.hpp"
7#include "utils/assertion.hpp"
8
9namespace precice::mapping {
10
12 Constraint constraint,
13 int dimensions)
14 : BarycentricBaseMapping(constraint, dimensions)
15{
16 if (constraint == CONSISTENT) {
19 } else if (constraint == CONSERVATIVE) {
22 } else {
26 }
27
28 PRECICE_CHECK(constraint != SCALED_CONSISTENT_SURFACE, "Volume mapping doesn't support scaled-consistent-surface mappings. Use \"scaled-consistent-volume\" instead.");
29}
30
32{
33 PRECICE_TRACE(input()->nVertices(), output()->nVertices());
34 const std::string baseEvent = "map.vci.computeMapping.From" + input()->getName() + "To" + output()->getName();
36
37 // Setup Direction of Mapping
38 mesh::PtrMesh origins, searchSpace;
40 PRECICE_DEBUG("Compute conservative mapping");
41 origins = input();
42 searchSpace = output();
43 } else {
44 PRECICE_DEBUG("Compute consistent mapping");
45 origins = output();
46 searchSpace = input();
47 }
48
49 const auto &fVertices = origins->vertices();
50 bool hasConnectivity = true;
51
52 if (getDimensions() == 2) {
53 if (!fVertices.empty() && searchSpace->triangles().empty()) {
54 const bool hasEdges = searchSpace->hasEdges();
55 PRECICE_WARN("2D Mesh \"{}\" does not contain triangles{} "
56 "Linear cell interpolation falls back to nearest-{} mapping.",
57 searchSpace->getName(), hasEdges ? "." : " or edges.", hasEdges ? "projection" : "neighbor");
58 hasConnectivity = false;
59 }
60 } else {
61 if (!fVertices.empty() && searchSpace->tetrahedra().empty()) {
62 const bool hasTriangles = searchSpace->hasTriangles();
63 const bool hasEdges = searchSpace->hasEdges();
64 PRECICE_WARN("3D Mesh \"{}\" does not contain tetrahedra{}{} "
65 "Linear cell interpolation falls back to nearest-{} mapping.",
66 searchSpace->getName(), hasEdges ? "" : ", edges", hasTriangles ? "." : " or triangles.", (hasTriangles || hasEdges) ? "projection" : "neighbor");
67 hasConnectivity = false;
68 }
69 }
70
71 // Amount of nearest elements to fetch for detailed comparison.
72 // This safety margin results in a candidate set which forms the base for the
73 // local nearest projection and counters the loss of detail due to bounding box generation.
74 // @TODO Add a configuration option for this factor
75 constexpr int nnearest = 4;
76
77 auto & index = searchSpace->index();
79
80 _interpolations.clear();
81 _interpolations.reserve(fVertices.size());
82
83 for (const auto &fVertex : fVertices) {
84 // Find tetrahedra (3D) or triangle (2D) or fall-back on NP
85 auto match = index.findCellOrProjection(fVertex.getCoords(), nnearest);
86 auto distance = match.polation.distance();
87 _interpolations.push_back(std::move(match.polation));
88 if (!math::equals(distance, 0.0)) {
89 // Only push when fall-back occurs, so the number of entries is the number of vertices outside the domain
90 fallbackStatistics(distance);
91 }
92 }
93
94 if (!fallbackStatistics.empty()) {
95 if (hasConnectivity) {
96 // We have the connectivity, but some fallbacks occurred
98 "Linear Cell Interpolation is used, but some points from {} don't lie in the domain defined by the {}. "
99 "These points have been projected on the domain boundary. This could come from non-matching discrete geometries or erroneous connectivity information."
100 "If distances seem too large, please check your mesh. "
101 "The fallback statistics are: {} ",
102 searchSpace->getName(), getDimensions() == 2 ? "triangles" : "tetrahedra",
103 fallbackStatistics);
104 } else {
105 // Fallback and no connectivity provided
106 PRECICE_INFO("Fallback mapping statistics: {}", fallbackStatistics);
107 }
108 } else {
109 if (!hasConnectivity) {
110 // Not all connectivity provided, but no fallback applied
111 PRECICE_INFO("All vertices are inside cells, no fallback required");
112 } else {
113 // No fallback and we have connectivity
114 PRECICE_ASSERT(hasConnectivity);
115 PRECICE_INFO("Successfully computed linear-cell-interpolation mapping.");
116 }
117 }
118
119 _hasComputedMapping = true;
120}
121
123{
124 return "linear-cell interpolation";
125}
126
127} // namespace precice::mapping
std::size_t distance
#define PRECICE_WARN(...)
Definition LogMacros.hpp:11
#define PRECICE_DEBUG(...)
Definition LogMacros.hpp:64
#define PRECICE_TRACE(...)
Definition LogMacros.hpp:95
#define PRECICE_INFO(...)
Definition LogMacros.hpp:13
#define PRECICE_CHECK(check,...)
Definition LogMacros.hpp:35
unsigned int index
#define PRECICE_ASSERT(...)
Definition assertion.hpp:87
Base class for interpolation based mappings, where mapping is done using a geometry-based linear comb...
void computeMapping() final override
Computes the projections and interpolation relations.
LinearCellInterpolationMapping(Constraint constraint, int dimensions)
Constructor, taking mapping constraint.
std::string getName() const final override
name of the lci mapping
mesh::PtrMesh output() const
Returns pointer to output mesh.
Definition Mapping.cpp:91
Constraint
Specifies additional constraints for a mapping.
Definition Mapping.hpp:29
mesh::PtrMesh input() const
Returns pointer to input mesh.
Definition Mapping.cpp:86
bool _hasComputedMapping
Flag to indicate whether computeMapping() has been called.
Definition Mapping.hpp:208
bool isScaledConsistent() const
Returns true if mapping is a form of scaled consistent mapping.
Definition Mapping.cpp:257
void setInputRequirement(MeshRequirement requirement)
Sets the mesh requirement for the input mesh.
Definition Mapping.cpp:96
void setOutputRequirement(MeshRequirement requirement)
Sets the mesh requirement for the output mesh.
Definition Mapping.cpp:102
virtual bool hasConstraint(const Constraint &constraint) const
Checks whether the mapping has the given constraint or not.
Definition Mapping.cpp:247
bool empty() const
Returns count == 0.
contains data mapping from points to meshes.
constexpr bool equals(const Eigen::MatrixBase< DerivedA > &A, const Eigen::MatrixBase< DerivedB > &B, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
Compares two Eigen::MatrixBase for equality up to tolerance.
static constexpr SynchronizeTag Synchronize
Convenience instance of the SynchronizeTag.
Definition Event.hpp:21