4#include <Eigen/src/Core/Matrix.h>
5#include <boost/container/flat_set.hpp>
25 "The scaled-consistent mapping hasn't been specifically tested with nearest-neighbor-gradient. Please avoid using it or choose another mapping method. ");
45 const auto &matchedVertexCoords = searchSpace->vertex(
_vertexIndices[i]).getCoords();
46 const auto &sourceVertexCoords = origins->vertex(i).getCoords();
61 "Mesh \"{}\" does not contain gradient data. Using Nearest Neighbor Gradient mapping requires gradient data.",
67 const int valueDimensions = inData.
dataDims;
68 const Eigen::VectorXd &inputValues = inData.
values;
69 Eigen::VectorXd & outputValues = outData;
70 const Eigen::MatrixXd &gradients = inData.
gradients;
74 const size_t outSize =
output()->nVertices();
76 for (
size_t i = 0; i < outSize; i++) {
79 for (
int dim = 0; dim < valueDimensions; dim++) {
81 const int mapOutputIndex = (i * valueDimensions) + dim;
82 const int mapInputIndex = inputIndex + dim;
84 outputValues(mapOutputIndex) = inputValues(mapInputIndex) +
_offsetsMatched[i].transpose() * gradients.col(mapInputIndex);
98 return "nearest-neighbor-gradient";
#define PRECICE_WARN_IF(condition,...)
#define PRECICE_DEBUG(...)
#define PRECICE_TRACE(...)
#define PRECICE_ASSERT(...)
mesh::PtrMesh output() const
Returns pointer to output mesh.
Constraint
Specifies additional constraints for a mapping.
mesh::PtrMesh input() const
Returns pointer to input mesh.
bool isScaledConsistent() const
Returns true if mapping is a form of scaled consistent mapping.
void setInputRequirement(MeshRequirement requirement)
Sets the mesh requirement for the input mesh.
void setOutputRequirement(MeshRequirement requirement)
Sets the mesh requirement for the output mesh.
virtual bool hasConstraint(const Constraint &constraint) const
Checks whether the mapping has the given constraint or not.
std::vector< Eigen::VectorXd > _offsetsMatched
std::string mappingNameShort
nn or nng
std::vector< int > _vertexIndices
Computed output vertex indices to map data from input vertices to.
NearestNeighborGradientMapping(Constraint constraint, int dimensions)
Constructor.
void mapConservative(const time::Sample &inData, Eigen::VectorXd &outData) final override
Maps data using a conservative constraint.
void onMappingComputed(mesh::PtrMesh origins, mesh::PtrMesh searchSpace) final override
Calculates the offsets needed for the gradient mappings after calculating the matched vertices.
void mapConsistent(const time::Sample &inData, Eigen::VectorXd &outData) final override
Maps data using a consistent constraint.
std::string getName() const final override
name of the nng mapping
contains data mapping from points to meshes.
static constexpr SynchronizeTag Synchronize
Convenience instance of the SynchronizeTag.
const RangePreview< Iter > previewRange(Size n, const Range &range)
Eigen::MatrixXd gradients
The gradients of the data. Use gradients.col(i) to get the gradient at vertex i.
int dataDims
The dimensionality of the data.