31 int effectiveCoordinate =
static_cast<std::underlying_type_t<MultiscaleType>
>(
_axis);
33 effectiveCoordinate ==
static_cast<std::underlying_type_t<MultiscaleType>
>(
MultiscaleAxis::Y) ||
34 effectiveCoordinate ==
static_cast<std::underlying_type_t<MultiscaleType>
>(
MultiscaleAxis::Z),
35 "Unknown multiscale axis type.");
41 Eigen::VectorXd axisMidpoints(inSize);
44 std::vector<size_t> ordered_vertex_indices(
input()->nVertices());
45 std::iota(ordered_vertex_indices.begin(), ordered_vertex_indices.end(), 0);
46 std::stable_sort(ordered_vertex_indices.begin(), ordered_vertex_indices.end(),
47 [effectiveCoordinate, &inputVerticesRef](
const size_t aindex,
const size_t bindex) {
48 return inputVerticesRef[aindex].coord(effectiveCoordinate) < inputVerticesRef[bindex].coord(effectiveCoordinate);
51 for (
size_t i = 0; i < (inSize - 1); i++) {
52 auto axisPositionCurrent = inputVerticesRef[ordered_vertex_indices[i]].coord(effectiveCoordinate);
53 auto axisPositionNext = inputVerticesRef[ordered_vertex_indices[i] + 1].coord(effectiveCoordinate);
54 axisMidpoints(i) = (axisPositionCurrent + axisPositionNext) / 2;
56 axisMidpoints(inSize - 1) = std::numeric_limits<double>::max();
64 for (
size_t i = 0; i < outSize; i++) {
67 while (vertexCoord > axisMidpoints(index)) {
81 Eigen::VectorXd axisMidpoints(outSize);
85 std::vector<size_t> ordered_vertex_indices(
output()->nVertices());
86 std::iota(ordered_vertex_indices.begin(), ordered_vertex_indices.end(), 0);
87 std::stable_sort(ordered_vertex_indices.begin(), ordered_vertex_indices.end(),
88 [effectiveCoordinate, &outputVerticesRef](
const size_t aindex,
const size_t bindex) {
89 return outputVerticesRef[aindex].coord(effectiveCoordinate) < outputVerticesRef[bindex].coord(effectiveCoordinate);
92 for (
size_t i = 0; i < (outSize - 1); i++) {
95 axisMidpoints(i) = (axisPositionCurrent + axisPositionNext) / 2;
97 axisMidpoints(outSize - 1) = std::numeric_limits<double>::max();
99 std::vector<size_t> counters(outSize);
104 for (
size_t i = 0; i < inSize; i++) {
107 while (vertexCoords > axisMidpoints(index)) {
112 counters[index] += 1;
115 for (
size_t i = 0; i < outSize; ++i) {
117 "Radial geometric multiscale mapping failed: output vertex {} has no contributing input vertices.",
149 const int inDataDimensions = inData.
dataDims;
150 const Eigen::VectorXd &inputValues = inData.
values;
151 Eigen::VectorXd &outputValues = outData;
157 auto outDataDimensions = outputValues.size() / outSize;
160 PRECICE_ASSERT((inputValues.size() /
static_cast<std::size_t
>(inDataDimensions) ==
input()->nVertices()),
161 inputValues.size(), inDataDimensions,
input()->nVertices());
163 outputValues.size(), outDataDimensions,
output()->nVertices());
166 PRECICE_ASSERT(
static_cast<std::size_t
>(inDataDimensions) == outDataDimensions);
171 for (
size_t i = 0; i < outSize; i++) {
181 for (
size_t i = 0; i < outSize; i++) {
182 outputValues(i * outDataDimensions) = 0;
185 for (
size_t i = 0; i < inSize; i++) {
188 for (
size_t i = 0; i < outSize; i++) {
189 outputValues(i * outDataDimensions) = outputValues(i * outDataDimensions) /
_vertexCounter[i];
222 return "radial-geomultiscale";
#define PRECICE_DEBUG(...)
#define PRECICE_TRACE(...)
#define PRECICE_CHECK(check,...)
#define PRECICE_ASSERT(...)
VertexContainer & vertices()
Returns modifieable container holding all vertices.
std::size_t nVertices() const
Returns the number of vertices.
Vertex & vertex(VertexID id)
Mutable access to a vertex by VertexID.
mesh::PtrMesh output() const
Returns pointer to output mesh.
Constraint
Specifies additional constraints for a mapping.
Mapping(Constraint constraint, int dimensions, bool requiresGradientData, InitialGuessRequirement initialGuessRequirement)
Constructor, takes mapping constraint.
mesh::PtrMesh input() const
Returns pointer to input mesh.
bool _hasComputedMapping
Flag to indicate whether computeMapping() has been called.
Constraint getConstraint() const
Returns the constraint (consistent/conservative) of the 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.
InitialGuessRequirement
Specifies whether the mapping requires an initial guess.
std::vector< size_t > _vertexIndicesCollect
MultiscaleType
Geometric multiscale type of the mapping (spread or collect).
RadialGeoMultiscaleMapping(Constraint constraint, int dimensions, MultiscaleType type, MultiscaleAxis axis)
Constructor.
std::vector< size_t > _vertexCounter
counts number of vertices between midpoints for averaging
MultiscaleAxis _axis
main axis along which radial geometric multiscale coupling happens
void tagMeshFirstRound() override
Method used by partition. Tags vertices that could be owned by this rank.
std::vector< size_t > _vertexIndicesSpread
computed vertex indices to map data from input vertices to output vertices and vice versa
std::string getName() const final override
Returns name of the mapping.
MultiscaleType _type
type of mapping, namely spread or collect
void clear() override
Removes a computed mapping.
void tagMeshSecondRound() override
Method used by partition. Tags vertices that can be filtered out.
void mapConservative(const time::Sample &inData, Eigen::VectorXd &outData) override
Maps data using a conservative constraint.
void computeMapping() override
Takes care of compute-heavy operations needed only once to set up the mapping.
void mapConsistent(const time::Sample &inData, Eigen::VectorXd &outData) override
Maps data using a consistent constraint.
double coord(int index) const
Returns a coordinate of a vertex.
contains data mapping from points to meshes.
constexpr auto get(span< E, S > s) -> decltype(s[N])
int dataDims
The dimensionality of the data.