Loading [MathJax]/extensions/tex2jax.js
MeshKernel
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages Concepts
SampleAveragingInterpolator.hpp
1//---- GPL ---------------------------------------------------------------------
2//
3// Copyright (C) Stichting Deltares, 2011-2024.
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation version 3.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16//
17// contact: delft3d.support@deltares.nl
18// Stichting Deltares
19// P.O. Box 177
20// 2600 MH Delft, The Netherlands
21//
22// All indications and logos of, and references to, "Delft3D" and "Deltares"
23// are registered trademarks of Stichting Deltares, and remain the property of
24// Stichting Deltares. All rights reserved.
25//
26//------------------------------------------------------------------------------
27
28#pragma once
29
30#include <map>
31#include <span>
32#include <string>
33#include <vector>
34
35#include "MeshKernel/AveragingInterpolation.hpp" // Only for the enum Method. should move to Definitions.hpp
36#include "MeshKernel/AveragingStrategies/AveragingStrategy.hpp"
37#include "MeshKernel/AveragingStrategies/AveragingStrategyFactory.hpp"
38#include "MeshKernel/Constants.hpp"
39#include "MeshKernel/Definitions.hpp"
40#include "MeshKernel/Entities.hpp"
41#include "MeshKernel/Exceptions.hpp"
42#include "MeshKernel/Mesh2D.hpp"
43#include "MeshKernel/MeshTriangulation.hpp"
44#include "MeshKernel/Operations.hpp"
45#include "MeshKernel/Point.hpp"
46#include "MeshKernel/SampleInterpolator.hpp"
47#include "MeshKernel/Utilities/RTreeFactory.hpp"
48
49namespace meshkernel
50{
51
70
73 {
74 public:
76 SampleAveragingInterpolator(const std::span<const double> xNodes,
77 const std::span<const double> yNodes,
78 const Projection projection,
79 const InterpolationParameters& interpolationParameters);
80
82 SampleAveragingInterpolator(const std::span<const Point> nodes,
83 const Projection projection,
84 const InterpolationParameters& interpolationParameters);
85
87 UInt Size() const override;
88
90 void Interpolate(const int propertyId, const std::span<const Point> iterpolationNodes, std::span<double> result) const override;
91
93 void Interpolate(const int propertyId, const Mesh2D& mesh, const Location location, std::span<double> result) const override;
94
99 double InterpolateValue(const int propertyId, const Point& evaluationPoint) const override;
100
101 private:
102 static constexpr UInt MaximumNumberOfEdgesPerNode = 16;
103
105 static std::vector<Point> CombineCoordinates(const std::span<const double> xNodes, const std::span<const double> yNodes);
106
108 double InterpolateOnElement(const UInt elementId, const Point& interpolationPoint, const std::vector<double>& sampleValues) const;
109
111 double ComputeOnPolygon(const int propertyId,
112 std::vector<Point>& polygon,
113 const Point& interpolationPoint,
114 const Projection projection,
115 std::vector<Sample>& sampleCache) const;
116
118 double GetSearchRadiusSquared(const std::vector<Point>& searchPolygon,
119 const Point& interpolationPoint,
120 const Projection projection) const;
121
123 void GenerateSearchPolygon(const double relativeSearchRadius,
124 const Point& interpolationPoint,
125 std::vector<Point>& polygon,
126 const Projection projection) const;
127
129 double GetSampleValueFromRTree(const int propertyId, const UInt index) const;
130
132 double ComputeInterpolationResultFromNeighbors(const int propertyId,
133 const Point& interpolationPoint,
134 const std::vector<Point>& searchPolygon,
135 const Projection projection,
136 std::vector<Sample>& sampleCache) const;
137
139 void InterpolateAtNodes(const int propertyId, const Mesh2D& mesh, std::span<double>& result) const;
140
142 void InterpolateAtEdgeCentres(const Mesh2D& mesh,
143 const std::span<double>& nodeResult,
144 std::span<double>& result) const;
145
147 void InterpolateAtFaces(const int propertyId, const Mesh2D& mesh, std::span<double>& result) const;
148
150 std::vector<Point> m_samplePoints;
151
152 // Should use the m_projection from the mesh in the interpolate function or
153 // needs to be passed to the interpolate function in the no mesh version
155 Projection m_projection = Projection::cartesian;
156
158 InterpolationParameters m_interpolationParameters;
159
161 std::unique_ptr<averaging::AveragingStrategy> m_strategy;
162
164 std::map<int, std::vector<double>> m_sampleData;
165
167 std::unique_ptr<RTreeBase> m_nodeRTree;
168 };
169
170} // namespace meshkernel
171
173{
174 return static_cast<UInt>(m_samplePoints.size());
175}
Method
Averaging methods.
Definition AveragingInterpolation.hpp:80
@ SimpleAveraging
Computes a simple mean.
A class derived from Mesh, which describes unstructures 2d meshes.
Definition Mesh2D.hpp:58
A struct describing a point in a two-dimensional space.
Definition Point.hpp:41
Interpolator for sample data using an averaging scheme.
Definition SampleAveragingInterpolator.hpp:73
SampleAveragingInterpolator(const std::span< const Point > nodes, const Projection projection, const InterpolationParameters &interpolationParameters)
Constructor.
double InterpolateValue(const int propertyId, const Point &evaluationPoint) const override
Interpolate the sample data set at a single interpolation point.
void Interpolate(const int propertyId, const Mesh2D &mesh, const Location location, std::span< double > result) const override
Interpolate the sample data set at the locationd defined.
SampleAveragingInterpolator(const std::span< const double > xNodes, const std::span< const double > yNodes, const Projection projection, const InterpolationParameters &interpolationParameters)
Constructor.
UInt Size() const override
Get the number of nodes of size of the sample data.
Definition SampleAveragingInterpolator.hpp:172
void Interpolate(const int propertyId, const std::span< const Point > iterpolationNodes, std::span< double > result) const override
Interpolate the sample data set at the interpolation nodes.
Interface for sample interpolation.
Definition SampleInterpolator.hpp:53
Contains the logic of the C++ static library.
Definition AveragingInterpolation.hpp:37
Projection
Enumerator describing the supported projections.
Definition Definitions.hpp:43
Location
Mesh locations enumeration.
Definition Definitions.hpp:76
std::uint32_t UInt
Integer type used when indexing mesh graph entities.
Definition Definitions.hpp:39
Parameters used by the averaging interpolation.
Definition SampleAveragingInterpolator.hpp:54
double m_relativeSearchRadius
The relative search radius.
Definition SampleAveragingInterpolator.hpp:62
UInt m_minimumNumberOfSamples
The minimum number of samples for several averaging methods.
Definition SampleAveragingInterpolator.hpp:68
AveragingInterpolation::Method m_method
Which averaging method should be used.
Definition SampleAveragingInterpolator.hpp:56
bool m_useClosestIfNoneFound
If no point is found in polygon then just used the closest point.
Definition SampleAveragingInterpolator.hpp:65
double m_absoluteSearchRadius
The absolute search radius.
Definition SampleAveragingInterpolator.hpp:59