preCICE v3.2.0
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::mapping {
9
21template <typename RADIAL_BASIS_FUNCTION_T>
23public:
33 Constraint constraint,
34 int dimensions,
35 const RADIAL_BASIS_FUNCTION_T &function,
36 std::array<bool, 3> deadAxis,
37 InitialGuessRequirement mappingType);
38
39 ~RadialBasisFctBaseMapping() override = default;
40
41 // Methods, which need to be implemented in a derived class
42
44 void computeMapping() override = 0;
45
47 void clear() override = 0;
48
49 void tagMeshFirstRound() final override;
50
51 void tagMeshSecondRound() final override;
52
53protected:
55 RADIAL_BASIS_FUNCTION_T _basisFunction;
56
59
68
69private:
70 precice::logging::Logger _log{"mapping::RadialBasisFctBaseMapping"};
71
74};
75
76// --------------------------------------------------- HEADER IMPLEMENTATIONS
77
78template <typename RADIAL_BASIS_FUNCTION_T>
80 Constraint constraint,
81 int dimensions,
82 const RADIAL_BASIS_FUNCTION_T &function,
83 std::array<bool, 3> deadAxis,
84 InitialGuessRequirement mappingType)
85 : Mapping(constraint, dimensions, false, mappingType),
86 _basisFunction(function)
87{
88 if (isScaledConsistent()) {
91 } else {
94 }
95 setDeadAxis(deadAxis);
96}
97
98template <typename RADIAL_BASIS_FUNCTION_T>
100{
102 PRECICE_ASSERT(_deadAxis.empty());
104 PRECICE_WARN_IF(getDimensions() == 2 && deadAxis[2],
105 "Setting the z-axis to dead on a 2-dimensional problem has no effect. Please remove the respective mapping's \"z-dead\" attribute.");
106 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.");
107}
108
109template <typename RADIAL_BASIS_FUNCTION_T>
111{
112 PRECICE_ASSERT(_deadAxis.size() > 0);
113 // Count the dead axis
114 const int deadDimensions = std::count(_deadAxis.begin(), _deadAxis.end(), true);
115 // Formula for the polynomial parameters
116 return 1 + getDimensions() - deadDimensions;
117}
118
119/*
120 * For the re-partitioning process with RBF mappings, also compare Figure 69 in Benjamin U's thesis (page 89).
121 * https://mediatum.ub.tum.de/doc/1320661/document.pdf
122 */
123template <typename RADIAL_BASIS_FUNCTION_T>
125{
127 mesh::PtrMesh filterMesh, otherMesh;
129 filterMesh = output(); // remote
130 otherMesh = input(); // local
131 } else {
132 filterMesh = input(); // remote
133 otherMesh = output(); // local
134 }
135
136 if (otherMesh->empty())
137 return; // Ranks not at the interface should never hold interface vertices
138
139 // Tags all vertices that are inside otherMesh's bounding box, enlarged by the support radius
140 if (_basisFunction.hasCompactSupport()) {
141 auto bb = otherMesh->getBoundingBox();
142 bb.expandBy(_basisFunction.getSupportRadius());
143
144 // We don't make use of the index tree here, because constructing the index tree on the
145 // (unfiltered) mesh is expensive
146 auto &vertices = filterMesh->vertices();
147 std::for_each(vertices.begin(), vertices.end(), [&bb](auto &v) {
148 if (bb.contains(v)) {
149 v.tag();
150 }
151 });
152 } else {
153 filterMesh->tagAll();
154 }
155}
156
157/*
158 * For the re-partitioning process with RBF mappings, also compare Figure 69 in Benjamin U's thesis (page 89).
159 * https://mediatum.ub.tum.de/doc/1320661/document.pdf
160 */
161template <typename RADIAL_BASIS_FUNCTION_T>
163{
165
166 if (not _basisFunction.hasCompactSupport())
167 return; // Tags should not be changed
168
169 mesh::PtrMesh mesh; // The mesh we want to filter
170
172 mesh = output();
173 } else {
174 mesh = input();
175 }
176
177 mesh::BoundingBox bb(mesh->getDimensions());
178
179 // Construct bounding box around all owned vertices
180 for (mesh::Vertex &v : mesh->vertices()) {
181 if (v.isOwner()) {
182 PRECICE_ASSERT(v.isTagged()); // Should be tagged from the first round
183 bb.expandBy(v);
184 }
185 }
186 // Enlarge bb by support radius
187 bb.expandBy(_basisFunction.getSupportRadius());
188 auto vertices = mesh->index().getVerticesInsideBox(bb);
189 std::for_each(vertices.begin(), vertices.end(), [&mesh](size_t v) { mesh->vertex(v).tag(); });
190}
191} // namespace precice::mapping
#define PRECICE_WARN_IF(condition,...)
Definition LogMacros.hpp:18
#define PRECICE_TRACE(...)
Definition LogMacros.hpp:92
#define PRECICE_CHECK(check,...)
Definition LogMacros.hpp:32
T any_of(T... args)
#define PRECICE_ASSERT(...)
Definition assertion.hpp:85
T back_inserter(T... args)
T begin(T... args)
mesh::PtrMesh output() const
Returns pointer to output mesh.
Definition Mapping.cpp:92
Constraint
Specifies additional constraints for a mapping.
Definition Mapping.hpp:30
Mapping(Constraint constraint, int dimensions, bool requiresGradientData, InitialGuessRequirement initialGuessRequirement)
Constructor, takes mapping constraint.
Definition Mapping.cpp:12
mesh::PtrMesh input() const
Returns pointer to input mesh.
Definition Mapping.cpp:87
bool isScaledConsistent() const
Returns true if mapping is a form of scaled consistent mapping.
Definition Mapping.cpp:258
void setInputRequirement(MeshRequirement requirement)
Sets the mesh requirement for the input mesh.
Definition Mapping.cpp:97
void setOutputRequirement(MeshRequirement requirement)
Sets the mesh requirement for the output mesh.
Definition Mapping.cpp:103
virtual bool hasConstraint(const Constraint &constraint) const
Checks whether the mapping has the given constraint or not.
Definition Mapping.cpp:248
InitialGuessRequirement
Specifies whether the mapping requires an initial guess.
Definition Mapping.hpp:64
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
void computeMapping() override=0
Computes the mapping coefficients from the in- and output mesh.
void tagMeshFirstRound() final override
Method used by partition. Tags vertices that could be owned by this rank.
std::vector< bool > _deadAxis
true if the mapping along some axis should be ignored
void clear() override=0
Removes a computed mapping.
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
STL class.
T copy_n(T... args)
T count(T... args)
T for_each(T... args)
contains the logging framework.
contains data mapping from points to meshes.
provides Mesh, Data and primitives.
std::shared_ptr< Mesh > PtrMesh
Main namespace of the precice library.
STL namespace.