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/Parameters.hpp"
46#include "MeshKernel/Point.hpp"
47#include "MeshKernel/SampleInterpolator.hpp"
48#include "MeshKernel/Utilities/RTreeFactory.hpp"
49
50namespace meshkernel
51{
52
55 {
56 public:
58 SampleAveragingInterpolator(const std::span<const double> xNodes,
59 const std::span<const double> yNodes,
60 const Projection projection,
61 const InterpolationParameters& interpolationParameters);
62
64 SampleAveragingInterpolator(const std::span<const Point> nodes,
65 const Projection projection,
66 const InterpolationParameters& interpolationParameters);
67
69 UInt Size() const override;
70
72 void Interpolate(const int propertyId, const std::span<const Point> iterpolationNodes, std::span<double> result) const override;
73
75 void Interpolate(const int propertyId, const Mesh2D& mesh, const Location location, std::span<double> result) const override;
76
81 double InterpolateValue(const int propertyId, const Point& evaluationPoint) const override;
82
83 private:
84 static constexpr UInt MaximumNumberOfEdgesPerNode = 16;
85
87 static std::vector<Point> CombineCoordinates(const std::span<const double> xNodes, const std::span<const double> yNodes);
88
90 double InterpolateOnElement(const UInt elementId, const Point& interpolationPoint, const std::vector<double>& sampleValues) const;
91
93 double ComputeOnPolygon(const int propertyId,
94 std::vector<Point>& polygon,
95 const Point& interpolationPoint,
96 const Projection projection,
97 std::vector<Sample>& sampleCache) const;
98
100 double GetSearchRadiusSquared(const std::vector<Point>& searchPolygon,
101 const Point& interpolationPoint,
102 const Projection projection) const;
103
105 void GenerateSearchPolygon(const double relativeSearchRadius,
106 const Point& interpolationPoint,
107 std::vector<Point>& polygon,
108 const Projection projection) const;
109
111 double GetSampleValueFromRTree(const int propertyId, const UInt index) const;
112
114 double ComputeInterpolationResultFromNeighbors(const int propertyId,
115 const Point& interpolationPoint,
116 const std::vector<Point>& searchPolygon,
117 const Projection projection,
118 std::vector<Sample>& sampleCache) const;
119
121 void InterpolateAtNodes(const int propertyId, const Mesh2D& mesh, std::span<double>& result) const;
122
124 void InterpolateAtEdgeCentres(const Mesh2D& mesh,
125 const std::span<double>& nodeResult,
126 std::span<double>& result) const;
127
129 void InterpolateAtFaces(const int propertyId, const Mesh2D& mesh, std::span<double>& result) const;
130
132 std::vector<Point> m_samplePoints;
133
134 // Should use the m_projection from the mesh in the interpolate function or
135 // needs to be passed to the interpolate function in the no mesh version
137 Projection m_projection = Projection::cartesian;
138
140 InterpolationParameters m_interpolationParameters;
141
143 std::unique_ptr<averaging::AveragingStrategy> m_strategy;
144
146 std::map<int, std::vector<double>> m_sampleData;
147
149 std::unique_ptr<RTreeBase> m_nodeRTree;
150 };
151
152} // namespace meshkernel
153
155{
156 return static_cast<UInt>(m_samplePoints.size());
157}
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:55
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:154
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 sample interpolation.
Definition Parameters.hpp:270