5#include <boost/container/flat_set.hpp>
32template <
typename RADIAL_BASIS_FUNCTION_T>
55 RADIAL_BASIS_FUNCTION_T function,
64 void computeCacheData(
const Eigen::Ref<const Eigen::MatrixXd> &globalIn, Eigen::MatrixXd &polyOut, Eigen::MatrixXd &coefficientsOut)
const;
94 void initializeCacheData(Eigen::MatrixXd &polynomial, Eigen::MatrixXd &coeffs,
const int nComponents);
138template <
typename RADIAL_BASIS_FUNCTION_T>
142 RADIAL_BASIS_FUNCTION_T function,
146 : _center(center), _radius(radius), _polynomial(polynomial), _function(function), _weightingFunction(radius)
157 auto inIDs = inputMesh->index().getVerticesInsideBox(center, radius);
161 _inputIDs.insert(inIDs.begin(), inIDs.end());
162 _outputIDs.insert(outIDs.begin(), outIDs.end());
169 PRECICE_DEBUG(
"SphericalVertexCluster input size: {}", inIDs.size());
170 PRECICE_DEBUG(
"SphericalVertexCluster output size: {}", outIDs.size());
184template <
typename RADIAL_BASIS_FUNCTION_T>
191 if (_normalizedWeights.size() == 0)
192 _normalizedWeights.resize(_outputIDs.size());
195 auto localID = _outputIDs.index_of(_outputIDs.find(
id));
197 PRECICE_ASSERT(
static_cast<Eigen::Index
>(localID) < _normalizedWeights.size(), localID, _normalizedWeights.size());
198 _normalizedWeights[localID] = normalizedWeight;
201template <
typename RADIAL_BASIS_FUNCTION_T>
207 PRECICE_ASSERT(_normalizedWeights.size() ==
static_cast<Eigen::Index
>(_outputIDs.size()));
210 const unsigned int nComponents = inData.
dataDims;
211 const auto &localInData = inData.
values;
214 Eigen::VectorXd in(_rbfSolver.getOutputSize());
217 for (
unsigned int c = 0; c < nComponents; ++c) {
220 for (
unsigned int i = 0; i < _outputIDs.size(); ++i) {
221 const auto dataIndex = *(_outputIDs.nth(i));
222 PRECICE_ASSERT(dataIndex * nComponents + c < localInData.size(), dataIndex * nComponents + c, localInData.size());
223 PRECICE_ASSERT(_normalizedWeights[i] > 0, _normalizedWeights[i], i);
225 in[i] = localInData[dataIndex * nComponents + c] * _normalizedWeights[i];
229 auto result = _rbfSolver.solveConservative(in, _polynomial);
230 PRECICE_ASSERT(result.size() ==
static_cast<Eigen::Index
>(_inputIDs.size()));
233 for (
unsigned int i = 0; i < _inputIDs.size(); ++i) {
234 const auto dataIndex = *(_inputIDs.nth(i));
235 PRECICE_ASSERT(dataIndex * nComponents + c < outData.size(), dataIndex * nComponents + c, outData.size());
236 outData[dataIndex * nComponents + c] += result(i);
241template <
typename RADIAL_BASIS_FUNCTION_T>
244 Eigen::MatrixXd localIn(_inputIDs.size(), Au.cols());
245 _rbfSolver.evaluateConservativeCache(epsilon, Au, localIn);
247 for (
std::size_t i = 0; i < _inputIDs.size(); ++i) {
248 const auto dataIndex = *(_inputIDs.nth(i));
250 out.col(dataIndex) += localIn.row(i);
254template <
typename RADIAL_BASIS_FUNCTION_T>
258 Eigen::MatrixXd in(_rbfSolver.getInputSize(), globalIn.rows());
261 for (
std::size_t i = 0; i < _inputIDs.size(); i++) {
262 const auto dataIndex = *(_inputIDs.nth(i));
264 in.row(i) = globalIn.col(dataIndex);
267 _rbfSolver.computeCacheData(in, _polynomial, polyOut, coeffOut);
270template <
typename RADIAL_BASIS_FUNCTION_T>
274 return _rbfSolver.interpolateAt(v, poly, coeffs, _function, _inputIDs, inMesh);
277template <
typename RADIAL_BASIS_FUNCTION_T>
279 Eigen::MatrixXd &epsilon, Eigen::MatrixXd &Au,
283 _rbfSolver.addWriteDataToCache(v, load, epsilon, Au, _function, _inputIDs, inMesh);
286template <
typename RADIAL_BASIS_FUNCTION_T>
290 poly.resize(_rbfSolver.getNumberOfPolynomials(), nComponents);
292 coeffs.resize(_inputIDs.size(), nComponents);
295template <
typename RADIAL_BASIS_FUNCTION_T>
301 PRECICE_ASSERT(_normalizedWeights.size() ==
static_cast<Eigen::Index
>(_outputIDs.size()));
304 const unsigned int nComponents = inData.
dataDims;
305 const auto &localInData = inData.
values;
307 Eigen::VectorXd in(_rbfSolver.getInputSize());
310 for (
unsigned int c = 0; c < nComponents; ++c) {
313 for (
unsigned int i = 0; i < _inputIDs.size(); i++) {
314 const auto dataIndex = *(_inputIDs.nth(i));
315 PRECICE_ASSERT(dataIndex * nComponents + c < localInData.size(), dataIndex * nComponents + c, localInData.size());
316 in[i] = localInData[dataIndex * nComponents + c];
320 auto result = _rbfSolver.solveConsistent(in, _polynomial);
321 PRECICE_ASSERT(
static_cast<Eigen::Index
>(_outputIDs.size()) == result.size());
324 for (
unsigned int i = 0; i < _outputIDs.size(); ++i) {
325 const auto dataIndex = *(_outputIDs.nth(i));
326 PRECICE_ASSERT(dataIndex * nComponents + c < outData.size(), dataIndex * nComponents + c, outData.size());
329 outData[dataIndex * nComponents + c] += result(i) * _normalizedWeights[i];
334template <
typename RADIAL_BASIS_FUNCTION_T>
340 return _weightingFunction.evaluate(
std::sqrt(res));
343template <
typename RADIAL_BASIS_FUNCTION_T>
346 return _inputIDs.size();
349template <
typename RADIAL_BASIS_FUNCTION_T>
352 return _center.rawCoords();
355template <
typename RADIAL_BASIS_FUNCTION_T>
358 return _inputIDs.size() == 0;
361template <
typename RADIAL_BASIS_FUNCTION_T>
368 _hasComputedMapping =
false;
#define PRECICE_DEBUG(...)
#define PRECICE_TRACE(...)
#define PRECICE_ASSERT(...)
This class provides a lightweight logger.
Wendland radial basis function with compact support.
boost::container::flat_set< VertexID > _outputIDs
Global VertexIDs associated to the output mesh (see constructor)
void computeCacheData(const Eigen::Ref< const Eigen::MatrixXd > &globalIn, Eigen::MatrixXd &polyOut, Eigen::MatrixXd &coefficientsOut) const
Computes and saves the RBF coefficients.
unsigned int getNumberOfInputVertices() const
Number of input vertices this partition operates on.
Eigen::VectorXd _normalizedWeights
mesh::Vertex _center
center vertex of the cluster
const double _radius
radius of the vertex cluster
std::array< double, 3 > getCenterCoords() const
The center coordinate of this cluster.
double computeWeight(const mesh::Vertex &v) const
Compute the weight for a given vertex.
void initializeCacheData(Eigen::MatrixXd &polynomial, Eigen::MatrixXd &coeffs, const int nComponents)
bool _hasComputedMapping
Boolean switch in order to indicate that a mapping was computed.
CompactPolynomialC2 _weightingFunction
The weighting function.
Eigen::VectorXd interpolateAt(const mesh::Vertex &v, const Eigen::MatrixXd &poly, const Eigen::MatrixXd &coeffs, const mesh::Mesh &inMesh) const
void setNormalizedWeight(double normalizedWeight, VertexID vertexID)
Set the normalized weight for the given vertexID in the outputMesh.
Polynomial _polynomial
Polynomial treatment in the RBF solver.
RadialBasisFctSolver< RADIAL_BASIS_FUNCTION_T > _rbfSolver
The RBF solver.
void mapConsistent(const time::Sample &inData, Eigen::VectorXd &outData) const
Evaluates a consistent mapping and agglomerates the result in the given output data.
void clear()
Invalidates and erases data structures the cluster holds.
void evaluateConservativeCache(Eigen::MatrixXd &epsilon, const Eigen::MatrixXd &Au, Eigen::Ref< Eigen::MatrixXd > out)
SphericalVertexCluster(mesh::Vertex center, double radius, RADIAL_BASIS_FUNCTION_T function, Polynomial polynomial, mesh::PtrMesh inputMesh, mesh::PtrMesh outputMesh)
boost::container::flat_set< VertexID > _inputIDs
Global VertexIDs associated to the input mesh (see constructor)
void mapConservative(const time::Sample &inData, Eigen::VectorXd &outData) const
Evaluates a conservative mapping and agglomerates the result in the given output data.
RADIAL_BASIS_FUNCTION_T _function
precice::logging::Logger _log
logger, as usual
void addWriteDataToCache(const mesh::Vertex &v, const Eigen::VectorXd &load, Eigen::MatrixXd &epsilon, Eigen::MatrixXd &Au, const mesh::Mesh &inMesh)
Container and creator for meshes.
const RawCoords & rawCoords() const
Direct access to the coordinates.
Eigen::VectorXd getCoords() const
Returns the coordinates of the vertex.
void stop()
Stops a running event.
contains data mapping from points to meshes.
double computeSquaredDifference(const std::array< double, 3 > &u, std::array< double, 3 > v, const std::array< bool, 3 > &activeAxis={{true, true, true}})
Deletes all dead directions from fullVector and returns a vector of reduced dimensionality.
Polynomial
How to handle the polynomial?
constexpr double NUMERICAL_ZERO_DIFFERENCE
int dataDims
The dimensionality of the data.