preCICE v3.1.2
Loading...
Searching...
No Matches
NearestNeighborMapping.cpp
Go to the documentation of this file.
2
3#include <Eigen/Core>
4#include <boost/container/flat_set.hpp>
5#include <functional>
7#include "profiling/Event.hpp"
10#include "utils/IntraComm.hpp"
11#include "utils/assertion.hpp"
12
13namespace precice::mapping {
14
28
29void NearestNeighborMapping::mapConservative(const time::Sample &inData, Eigen::VectorXd &outData)
30{
32 precice::profiling::Event e("map." + mappingNameShort + ".mapData.From" + input()->getName() + "To" + output()->getName(), profiling::Synchronize);
33 PRECICE_DEBUG("Map conservative using {}", getName());
34
35 const Eigen::VectorXd &inputValues = inData.values;
36 Eigen::VectorXd & outputValues = outData;
37
38 // Data dimensions (for scalar = 1, for vectors > 1)
39 const size_t inSize = input()->nVertices();
40 const int valueDimensions = inData.dataDims;
41
42 for (size_t i = 0; i < inSize; i++) {
43 int const outputIndex = _vertexIndices[i] * valueDimensions;
44
45 for (int dim = 0; dim < valueDimensions; dim++) {
46
47 const int mapOutputIndex = outputIndex + dim;
48 const int mapInputIndex = (i * valueDimensions) + dim;
49
50 outputValues(mapOutputIndex) += inputValues(mapInputIndex);
51 }
52 }
53 PRECICE_DEBUG("Mapped values = {}", utils::previewRange(3, outputValues));
54}
55
56void NearestNeighborMapping::mapConsistent(const time::Sample &inData, Eigen::VectorXd &outData)
57{
59 precice::profiling::Event e("map." + mappingNameShort + ".mapData.From" + input()->getName() + "To" + output()->getName(), profiling::Synchronize);
60 PRECICE_DEBUG("Map {} using {}", (hasConstraint(CONSISTENT) ? "consistent" : "scaled-consistent"), getName());
61
62 const Eigen::VectorXd &inputValues = inData.values;
63 Eigen::VectorXd & outputValues = outData;
64
65 // Data dimensions (for scalar = 1, for vectors > 1)
66 const size_t outSize = output()->nVertices();
67 const int valueDimensions = inData.dataDims;
68
69 for (size_t i = 0; i < outSize; i++) {
70 int inputIndex = _vertexIndices[i] * valueDimensions;
71
72 for (int dim = 0; dim < valueDimensions; dim++) {
73
74 const int mapOutputIndex = (i * valueDimensions) + dim;
75 const int mapInputIndex = inputIndex + dim;
76
77 outputValues(mapOutputIndex) = inputValues(mapInputIndex);
78 }
79 }
80 PRECICE_DEBUG("Mapped values = {}", utils::previewRange(3, outputValues));
81}
82
84{
85 return "nearest-neighbor";
86}
87
88} // namespace precice::mapping
#define PRECICE_DEBUG(...)
Definition LogMacros.hpp:64
#define PRECICE_TRACE(...)
Definition LogMacros.hpp:95
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 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
std::vector< int > _vertexIndices
Computed output vertex indices to map data from input vertices to.
std::string getName() const final override
name of the nn mapping
void mapConsistent(const time::Sample &inData, Eigen::VectorXd &outData) final override
Maps data using a consistent constraint.
NearestNeighborMapping(Constraint constraint, int dimensions)
Constructor.
void mapConservative(const time::Sample &inData, Eigen::VectorXd &outData) final override
Maps data using a conservative constraint.
contains data mapping from points to meshes.
static constexpr SynchronizeTag Synchronize
Convenience instance of the SynchronizeTag.
Definition Event.hpp:21
const RangePreview< Iter > previewRange(Size n, const Range &range)
int dataDims
The dimensionality of the data.
Definition Sample.hpp:45
Eigen::VectorXd values
Definition Sample.hpp:49