preCICE v3.1.2
Loading...
Searching...
No Matches
RadialBasisFctBaseMapping.hpp
Go to the documentation of this file.
1#pragma once
2
4#include "mapping/Mapping.hpp"
5#include "mesh/Filter.hpp"
7
8namespace precice {
9namespace mapping {
10
22template <typename RADIAL_BASIS_FUNCTION_T>
24public:
34 Constraint constraint,
35 int dimensions,
36 const RADIAL_BASIS_FUNCTION_T &function,
37 std::array<bool, 3> deadAxis,
38 InitialGuessRequirement mappingType);
39
40 virtual ~RadialBasisFctBaseMapping() = default;
41
42 // Methods, which need to be implemented in a derived class
43
45 virtual void computeMapping() = 0;
46
48 virtual void clear() = 0;
49
50 virtual void tagMeshFirstRound() final;
51
52 virtual void tagMeshSecondRound() final;
53
54protected:
56 RADIAL_BASIS_FUNCTION_T _basisFunction;
57
59 std::vector<bool> _deadAxis;
60
69
70private:
71 precice::logging::Logger _log{"mapping::RadialBasisFctBaseMapping"};
72
75};
76
77// --------------------------------------------------- HEADER IMPLEMENTATIONS
78
79template <typename RADIAL_BASIS_FUNCTION_T>
81 Constraint constraint,
82 int dimensions,
83 const RADIAL_BASIS_FUNCTION_T &function,
84 std::array<bool, 3> deadAxis,
85 InitialGuessRequirement mappingType)
86 : Mapping(constraint, dimensions, false, mappingType),
87 _basisFunction(function)
88{
89 if (isScaledConsistent()) {
92 } else {
95 }
96 setDeadAxis(deadAxis);
97}
98
99template <typename RADIAL_BASIS_FUNCTION_T>
101{
102 PRECICE_ASSERT(getDimensions() <= 3);
103 PRECICE_ASSERT(_deadAxis.empty());
104 std::copy_n(deadAxis.begin(), getDimensions(), std::back_inserter(_deadAxis));
105 PRECICE_WARN_IF(getDimensions() == 2 && deadAxis[2],
106 "Setting the z-axis to dead on a 2-dimensional problem has no effect. Please remove the respective mapping's \"z-dead\" attribute.");
107 PRECICE_CHECK(std::any_of(_deadAxis.begin(), _deadAxis.end(), [](const auto &ax) { return ax == false; }), "You cannot set all axes to dead for an RBF mapping. Please remove one of the respective mapping's \"x-dead\", \"y-dead\", or \"z-dead\" attributes.");
108}
109
110template <typename RADIAL_BASIS_FUNCTION_T>
112{
113 PRECICE_ASSERT(_deadAxis.size() > 0);
114 // Count the dead axis
115 const int deadDimensions = std::count(_deadAxis.begin(), _deadAxis.end(), true);
116 //Formula for the polynomial parameters
117 return 1 + getDimensions() - deadDimensions;
118}
119
120/*
121 * For the re-partitioning process with RBF mappings, also compare Figure 69 in Benjamin U's thesis (page 89).
122 * https://mediatum.ub.tum.de/doc/1320661/document.pdf
123 */
124template <typename RADIAL_BASIS_FUNCTION_T>
126{
128 mesh::PtrMesh filterMesh, otherMesh;
129 if (hasConstraint(CONSERVATIVE)) {
130 filterMesh = output(); // remote
131 otherMesh = input(); // local
132 } else {
133 filterMesh = input(); // remote
134 otherMesh = output(); // local
135 }
136
137 if (otherMesh->empty())
138 return; // Ranks not at the interface should never hold interface vertices
139
140 // Tags all vertices that are inside otherMesh's bounding box, enlarged by the support radius
141
142 if (_basisFunction.hasCompactSupport()) {
143 auto bb = otherMesh->getBoundingBox();
144 bb.expandBy(_basisFunction.getSupportRadius());
145
146 auto vertices = filterMesh->index().getVerticesInsideBox(bb);
147 std::for_each(vertices.begin(), vertices.end(), [&filterMesh](size_t v) { filterMesh->vertex(v).tag(); });
148 } else {
149 filterMesh->tagAll();
150 }
151}
152
153/*
154 * For the re-partitioning process with RBF mappings, also compare Figure 69 in Benjamin U's thesis (page 89).
155 * https://mediatum.ub.tum.de/doc/1320661/document.pdf
156 */
157template <typename RADIAL_BASIS_FUNCTION_T>
159{
161
162 if (not _basisFunction.hasCompactSupport())
163 return; // Tags should not be changed
164
165 mesh::PtrMesh mesh; // The mesh we want to filter
166
167 if (hasConstraint(CONSERVATIVE)) {
168 mesh = output();
169 } else {
170 mesh = input();
171 }
172
173 mesh::BoundingBox bb(mesh->getDimensions());
174
175 // Construct bounding box around all owned vertices
176 for (mesh::Vertex &v : mesh->vertices()) {
177 if (v.isOwner()) {
178 PRECICE_ASSERT(v.isTagged()); // Should be tagged from the first round
179 bb.expandBy(v);
180 }
181 }
182 // Enlarge bb by support radius
183 bb.expandBy(_basisFunction.getSupportRadius());
184 auto vertices = mesh->index().getVerticesInsideBox(bb);
185 std::for_each(vertices.begin(), vertices.end(), [&mesh](size_t v) { mesh->vertex(v).tag(); });
186}
187} // namespace mapping
188} // namespace precice
#define PRECICE_WARN_IF(condition,...)
Definition LogMacros.hpp:21
#define PRECICE_TRACE(...)
Definition LogMacros.hpp:95
#define PRECICE_CHECK(check,...)
Definition LogMacros.hpp:35
T any_of(T... args)
#define PRECICE_ASSERT(...)
Definition assertion.hpp:87
T back_inserter(T... args)
T begin(T... args)
Abstract base class for mapping of data from one mesh to another.
Definition Mapping.hpp:15
Constraint
Specifies additional constraints for a mapping.
Definition Mapping.hpp:29
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
InitialGuessRequirement
Specifies whether the mapping requires an initial guess.
Definition Mapping.hpp:63
virtual void computeMapping()=0
Computes the mapping coefficients from the in- and output mesh.
virtual void clear()=0
Removes a computed mapping.
RadialBasisFctBaseMapping(Constraint constraint, int dimensions, const RADIAL_BASIS_FUNCTION_T &function, std::array< bool, 3 > deadAxis, InitialGuessRequirement mappingType)
Constructor.
void setDeadAxis(std::array< bool, 3 > deadAxis)
converts the boolean switches to a boolean vector
virtual void tagMeshSecondRound() final
Method used by partition. Tags vertices that can be filtered out.
int getPolynomialParameters() const
Computes the number of polynomial degrees of freedom based on the problem dimension and the dead axis...
std::vector< bool > _deadAxis
true if the mapping along some axis should be ignored
virtual void tagMeshFirstRound() final
Method used by partition. Tags vertices that could be owned by this rank.
RADIAL_BASIS_FUNCTION_T _basisFunction
Radial basis function type used in interpolation.
An axis-aligned bounding box around a (partition of a) mesh.
void expandBy(const BoundingBox &otherBB)
Expand bounding box using another bounding box.
Vertex of a mesh.
Definition Vertex.hpp:16
T copy_n(T... args)
T count(T... args)
T for_each(T... args)
Main namespace of the precice library.
STL namespace.