OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
RainfallInterpolator.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2//
3// Copyright 2026 Caleb Buahin
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
43
44#ifndef OPENSWMM_ENGINE_2D_RAINFALL_INTERPOLATOR_HPP
45#define OPENSWMM_ENGINE_2D_RAINFALL_INTERPOLATOR_HPP
46
47#include <vector>
48
49namespace openswmm::twoD {
50
61public:
64 enum class CellMethod : signed char {
68 };
69 struct Diagnostics {
70 int unlocated = 0;
71 int invalid = 0;
72 int duplicates = 0;
73 int idwCells = 0;
74 };
75
80 const Diagnostics& diagnostics() const noexcept { return diagnostics_; }
106 void build(const std::vector<double>& cx, const std::vector<double>& cy,
107 const std::vector<double>& gage_x, const std::vector<double>& gage_y, int n_gages,
108 double gage_scale, Method method = Method::NaturalNeighbour);
109
116 bool ready() const noexcept { return ready_; }
117
133 void apply(const std::vector<double>& rain, std::vector<double>& out) const;
134
143 CellMethod cellMethod(int i) const { return cell_method_[static_cast<std::size_t>(i)]; }
154 void cellWeights(int i, std::vector<int>& gages, std::vector<double>& weights) const;
155
156private:
157 Diagnostics diagnostics_;
158 std::vector<CellMethod> cell_method_;
159 bool ready_ = false;
160 int nt_ = 0;
161
162 // CSR weight store: cell i owns weights [w_ptr_[i], w_ptr_[i+1]); each slot
163 // pairs a global gage index (w_gage_) with a normalized weight (w_val_,
164 // sums to 1 per cell).
165 std::vector<int> w_ptr_;
166 std::vector<int> w_gage_;
167 std::vector<double> w_val_;
168};
169
170} // namespace openswmm::twoD
171
172#endif // OPENSWMM_ENGINE_2D_RAINFALL_INTERPOLATOR_HPP
Builds and applies static rainfall-interpolation weights for the mesh.
Definition RainfallInterpolator.hpp:60
Method
Definition RainfallInterpolator.hpp:62
@ NaturalNeighbour
Definition RainfallInterpolator.hpp:62
@ NearestNeighbour
Definition RainfallInterpolator.hpp:62
CellMethod cellMethod(int i) const
Per-cell diagnostic: the method used and the contributing (global gage index, weight) pairs of cell i...
Definition RainfallInterpolator.hpp:143
bool ready() const noexcept
True once build() produced usable weights (≥ 1 located gage).
Definition RainfallInterpolator.hpp:116
void build(const std::vector< double > &cx, const std::vector< double > &cy, const std::vector< double > &gage_x, const std::vector< double > &gage_y, int n_gages, double gage_scale, Method method=Method::NaturalNeighbour)
Precompute per-cell interpolation weights.
Definition RainfallInterpolator.cpp:341
void apply(const std::vector< double > &rain, std::vector< double > &out) const
Map per-gage values onto per-cell values: out[i] = Σ w·rain[gage].
Definition RainfallInterpolator.cpp:468
CellMethod
How build() weighted one cell (values match swmm_2d_get_rainfall_weights).
Definition RainfallInterpolator.hpp:64
@ InverseDistance
IDW: outside the hull, 2 sites, or degenerate.
Definition RainfallInterpolator.hpp:66
@ Nearest
One gage, weight 1 (nearest mode or 1 site).
Definition RainfallInterpolator.hpp:67
const Diagnostics & diagnostics() const noexcept
Borrow diagnostics from the most recent interpolation build.
Definition RainfallInterpolator.hpp:80
void cellWeights(int i, std::vector< int > &gages, std::vector< double > &weights) const
Copy one built cell's interpolation contributors.
Definition RainfallInterpolator.cpp:482
Definition ExchangeLaw.hpp:60
Definition RainfallInterpolator.hpp:69
int invalid
Definition RainfallInterpolator.hpp:71
int idwCells
Definition RainfallInterpolator.hpp:73
int unlocated
Definition RainfallInterpolator.hpp:70
int duplicates
Definition RainfallInterpolator.hpp:72