OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
Gage.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
33
34#ifndef OPENSWMM_GAGE_HPP
35#define OPENSWMM_GAGE_HPP
36
38#include <cstddef>
39#include <vector>
40
41namespace openswmm {
42
44struct Table;
45
46namespace gage {
47
48// ============================================================================
49// Constants
50// ============================================================================
51
52constexpr double ONE_SECOND = 1.1574074e-5;
53constexpr int MAXPASTRAIN = 48;
54
55// ============================================================================
56// Rain type codes
57// ============================================================================
58
59enum class RainType : int {
61 VOLUME = 1,
63};
64
65// ============================================================================
66// Per-gage state
67// ============================================================================
68
69struct GageState {
70 double rainfall = 0.0;
71 double snowfall = 0.0;
72 double total_precip = 0.0;
73 double rain_accum = 0.0;
74 double api_rainfall = -1.0;
75 double snow_factor = 1.0;
76 double scale_factor = 1.0;
77 double units_factor = 1.0;
78 double adjust_factor = 1.0;
79 double rain_interval = 0.0;
81
82 double past_rain[MAXPASTRAIN] = {};
83 double past_rain_accum = 0.0;
84 double past_rain_time = 0.0;
85};
86
87// ============================================================================
88// Functions
89// ============================================================================
90
98double convertRainfall(double raw_value, GageState& state);
99
100// ---------------------------------------------------------------------------
101// Shared rainfall resolution
102// ---------------------------------------------------------------------------
103//
104// The sequence "pick the gage's series -> apply the rain-type transform ->
105// apply units factor -> apply scale factor" is needed by the routing update,
106// by report rainfall, and by the swmm_gage_get_rainfall_series C API. Three
107// private copies would drift, so the pieces that are genuinely common live
108// here. (getReportRainfall deliberately does NOT apply the CUMULATIVE delta —
109// see its comment — so it composes these itself rather than calling
110// convertGageValue.)
111
122const Table* gageRainSeries(const SimulationContext& ctx, int gage_idx);
123
136double gageUnitsFactor(const SimulationContext& ctx, int gage_idx);
137
152double convertGageValue(double raw, int rain_type, double interval_sec,
153 double& cumul_accum, double units_factor,
154 double scale_factor);
155
160 double rainfall = 0.0;
161 double snowfall = 0.0;
162};
163
187PrecipSplit splitPrecip(const SimulationContext& ctx, std::size_t sub);
188
195void updatePastRain(GageState& state, double current_time);
196
204double getPastRain(const GageState& state, int hours);
205
212void updateAllGages(SimulationContext& ctx, double current_time);
213
226double getReportRainfall(const SimulationContext& ctx, int gage_idx,
227 double report_date);
228
229} // namespace gage
230} // namespace openswmm
231
232#endif // OPENSWMM_GAGE_HPP
Structure-of-Arrays (SoA) storage for subcatchments.
Definition Gage.cpp:36
constexpr double ONE_SECOND
One second in days.
Definition Gage.hpp:52
double getReportRainfall(const SimulationContext &ctx, int gage_idx, double report_date)
Query a gage's rainfall at a specific report date.
Definition Gage.cpp:337
void updateAllGages(SimulationContext &ctx, double current_time)
Process all gages for one timestep.
Definition Gage.cpp:183
double getPastRain(const GageState &state, int hours)
Get past n-hour rainfall total.
Definition Gage.cpp:117
double gageUnitsFactor(const SimulationContext &ctx, int gage_idx)
The units factor the engine applies to a gage's raw values.
Definition Gage.cpp:145
double convertGageValue(double raw, int rain_type, double interval_sec, double &cumul_accum, double units_factor, double scale_factor)
Apply the rain-type transform, units factor and scale factor.
Definition Gage.cpp:161
void updatePastRain(GageState &state, double current_time)
Update past n-hour rainfall accumulation.
Definition Gage.cpp:101
RainType
Definition Gage.hpp:59
@ INTENSITY
Definition Gage.hpp:60
@ VOLUME
Definition Gage.hpp:61
@ CUMULATIVE
Definition Gage.hpp:62
PrecipSplit splitPrecip(const SimulationContext &ctx, std::size_t sub)
Split a subcatchment's gage precipitation into rain and snow.
Definition Gage.cpp:67
const Table * gageRainSeries(const SimulationContext &ctx, int gage_idx)
The rainfall table a gage actually reads.
Definition Gage.cpp:130
constexpr int MAXPASTRAIN
Max past hours tracked.
Definition Gage.hpp:53
double convertRainfall(double raw_value, GageState &state)
Convert raw rainfall value based on rain type.
Definition Gage.cpp:38
Definition NodeCoupling.cpp:16
Central, reentrant simulation context.
Definition SimulationContext.hpp:353
Definition TableData.hpp:138
Definition Gage.hpp:69
double past_rain_time
Time of last past-rain update.
Definition Gage.hpp:84
double rain_interval
Rain recording interval (seconds)
Definition Gage.hpp:79
double rainfall
Current rainfall intensity (project units/sec)
Definition Gage.hpp:70
double past_rain_accum
Accumulator for current hour.
Definition Gage.hpp:83
double scale_factor
Rainfall scaling factor (1.0 = no scaling)
Definition Gage.hpp:76
double snow_factor
Snow catch factor.
Definition Gage.hpp:75
double adjust_factor
Monthly/seasonal adjustment factor.
Definition Gage.hpp:78
double past_rain[MAXPASTRAIN]
Past hourly rainfall totals.
Definition Gage.hpp:82
double total_precip
rainfall + snowfall
Definition Gage.hpp:72
RainType rain_type
Definition Gage.hpp:80
double snowfall
Current snowfall intensity (project units/sec)
Definition Gage.hpp:71
double api_rainfall
API-overridden rainfall (-1 = no override)
Definition Gage.hpp:74
double rain_accum
Cumulative rain accumulator (for CUMULATIVE type)
Definition Gage.hpp:73
double units_factor
Unit conversion factor.
Definition Gage.hpp:77
Result of splitting a gage's precipitation for one subcatchment.
Definition Gage.hpp:159
double snowfall
Snowfall (ft/sec, internal units)
Definition Gage.hpp:161
double rainfall
Rainfall (ft/sec, internal units)
Definition Gage.hpp:160