OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
openswmm::twoD::RainfallInterpolator Class Reference

Builds and applies static rainfall-interpolation weights for the mesh. More...

#include <RainfallInterpolator.hpp>

Collaboration diagram for openswmm::twoD::RainfallInterpolator:

Classes

struct  Diagnostics
 

Public Types

enum class  Method {
  NaturalNeighbour ,
  NearestNeighbour
}
 
enum class  CellMethod : signed char {
  NaturalNeighbour = 0 ,
  InverseDistance = 1 ,
  Nearest = 2
}
 How build() weighted one cell (values match swmm_2d_get_rainfall_weights). More...
 

Public Member Functions

const Diagnostics & diagnostics () const noexcept
 Borrow diagnostics from the most recent interpolation build.
 
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.
 
bool ready () const noexcept
 True once build() produced usable weights (≥ 1 located gage).
 
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].
 
CellMethod cellMethod (int i) const
 Per-cell diagnostic: the method used and the contributing (global gage index, weight) pairs of cell i. Requires ready() and 0 ≤ i < cells.
 
void cellWeights (int i, std::vector< int > &gages, std::vector< double > &weights) const
 Copy one built cell's interpolation contributors.
 

Detailed Description

Builds and applies static rainfall-interpolation weights for the mesh.

Degenerate fallbacks handled by build():

  • 0 located gages → ready()==false (caller uses the SYSTEM mean).
  • 1 located gage → that gage everywhere.
  • 2 located / collinear → inverse-distance weighting everywhere.
  • ≥3 non-collinear → Laplace inside hull, IDW outside.

Member Enumeration Documentation

◆ CellMethod

enum class openswmm::twoD::RainfallInterpolator::CellMethod : signed char
strong

How build() weighted one cell (values match swmm_2d_get_rainfall_weights).

Enumerator
NaturalNeighbour 

Laplace weights inside the gage hull.

InverseDistance 

IDW: outside the hull, 2 sites, or degenerate.

Nearest 

One gage, weight 1 (nearest mode or 1 site).

◆ Method

Enumerator
NaturalNeighbour 
NearestNeighbour 

Member Function Documentation

◆ apply()

void openswmm::twoD::RainfallInterpolator::apply ( const std::vector< double > & rain,
std::vector< double > & out ) const

Map per-gage values onto per-cell values: out[i] = Σ w·rain[gage].

Parameters
[in]rainPer-gage value already in the desired output units (m/s), indexed by global gage index (size ≥ n_gages).
[out]outFilled with one value per cell; resized to n_triangles if its size does not already match.
Precondition
build() has initialized CSR offsets, and rain covers every retained global gage index. rain and out must be different vectors; no bounds or alias checks.
Postcondition
Replaces every output cell with a weighted sum in rain's units; no-ready built empty rows produce zero. Resizing out may allocate/throw.
Note
Read-only interpolator operation; concurrent calls need distinct output vectors and no concurrent build(). Caller retains both vectors.

◆ build()

void openswmm::twoD::RainfallInterpolator::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.

Parameters
[in]cx,cyMesh cell centroids (SI metres), size = n_triangles.
[in]gage_x,gage_yGage coordinates in project map units. An entry of exactly (0,0) marks an un-located gage (no [SYMBOLS] row) and is excluded from the interpolation.
[in]n_gagesNumber of gages (rainfall arrays are indexed 0..n_gages-1; the stored gage indices are these global indices).
[in]gage_scaleFactor applied to the gage coords to bring them into the SI mesh frame — the same FLOW_UNITS ft→m factor initialize() applies to the mesh (1.0 for SI projects).
[in]methodNaturalNeighbour selects Laplace with IDW fallback; NearestNeighbour selects one nearest located gage.
Precondition
n_gages is nonnegative; cx/cy have identical size and finite metre coordinates. gage_scale must be finite positive; missing gage coordinate entries are treated as zero.
Postcondition
Replaces CSR weights, method codes and diagnostic counts. Duplicate locations within 1e-6 m and invalid/unlocated gages are excluded. Empty gage/cell sets leave ready() false.
Exceptions
std::invalid_argumentFor invalid centroid dimensions/coordinates or scale.
std::runtime_errorIf a generated weight is nonfinite/negative or normalization fails.
Note
Allocation may also throw. ready() is cleared before validation; a failed rebuild is not transactional and the prior interpolation must not be used. All inputs are borrowed/copied; building requires exclusive access.

◆ cellMethod()

CellMethod openswmm::twoD::RainfallInterpolator::cellMethod ( int i) const
inline

Per-cell diagnostic: the method used and the contributing (global gage index, weight) pairs of cell i. Requires ready() and 0 ≤ i < cells.

Parameters
[in]iValid zero-based built cell index; no bounds/ready check.
Returns
Stored interpolation-method enum by value. No allocation or mutation; serialize with build().

◆ cellWeights()

void openswmm::twoD::RainfallInterpolator::cellWeights ( int i,
std::vector< int > & gages,
std::vector< double > & weights ) const

Copy one built cell's interpolation contributors.

Parameters
[in]iValid zero-based built cell index; requires ready() and valid CSR offsets.
[out]gagesReplaced with global gage indices in the built gather order.
[out]weightsReplaced with matching normalized dimensionless weights, summing to one.
Note
Output vectors are caller-owned and resized, potentially allocating. A failure after assigning gages may leave weights unchanged; no transactional guarantee. Interpolator remains read-only; serialize with build().

◆ diagnostics()

const Diagnostics & openswmm::twoD::RainfallInterpolator::diagnostics ( ) const
inlinenoexcept

Borrow diagnostics from the most recent interpolation build.

Returns
Const reference owned by this interpolator; invalid after object destruction and updated/replaced by the next build(). No allocation. Serialize reads with build().

◆ ready()

bool openswmm::twoD::RainfallInterpolator::ready ( ) const
inlinenoexcept

True once build() produced usable weights (≥ 1 located gage).

Returns
True after a successful build produced weights for at least one cell and located gage; false initially or after a failed/empty rebuild. Read-only; serialize with build().

The documentation for this class was generated from the following files: