OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches
GageData.hpp
Go to the documentation of this file.
1
22#ifndef OPENSWMM_ENGINE_GAGE_DATA_HPP
23#define OPENSWMM_ENGINE_GAGE_DATA_HPP
24
25#include <vector>
26#include <string>
27#include <cstdint>
28
29namespace openswmm {
30
31// ============================================================================
32// Rain source enumeration
33// ============================================================================
34
39enum class RainSource : int8_t {
40 TIMESERIES = 0,
41 FILE_RAIN = 1
42};
43
48enum class RainFileFormat : int8_t {
49 UNKNOWN = -1,
50 NWS_15 = 0,
51 NWS_HOURLY = 1,
52 DSI_3240 = 2,
53 DSI_3260 = 3,
54 HLY_PRCP = 4,
55 STAN_PRCP = 5,
56 USER_CSV = 6
57};
58
59// ============================================================================
60// GageData — SoA layout
61// ============================================================================
62
75struct GageData {
76
77 // -----------------------------------------------------------------------
78 // Static properties — set at parse time
79 // -----------------------------------------------------------------------
80
85 std::vector<int> rain_type;
86
88 std::vector<RainSource> source;
89
94 std::vector<int> ts_index;
95
100 std::vector<std::string> file_path;
101
105 std::vector<std::string> ts_name;
106
112 std::vector<std::string> col_name;
113
118 std::vector<RainFileFormat> file_format;
119
124 std::vector<int> interval_sec;
125
130 std::vector<double> snow_factor;
131
132 // -----------------------------------------------------------------------
133 // State variables — updated each timestep
134 // -----------------------------------------------------------------------
135
140 std::vector<double> rainfall;
141
146 std::vector<double> next_rainfall;
147
152 std::vector<double> api_rainfall;
153
158 std::vector<double> next_rain_date;
159
164 std::vector<bool> is_raining;
165
166 // -----------------------------------------------------------------------
167 // Past-rain history (for control rules — GAGE_RAIN_PAST)
168 // -----------------------------------------------------------------------
169
170 static constexpr int MAXPASTRAIN = 48;
171
173 std::vector<double> past_rain;
174
176 std::vector<double> past_rain_accum;
177
179 std::vector<double> past_rain_time;
180
187 std::vector<double> cumul_rain_accum;
188
194 std::vector<std::string> comments;
195
203 std::vector<int> co_gage_index;
204
205 // -----------------------------------------------------------------------
206 // Capacity management
207 // -----------------------------------------------------------------------
208
209 int count() const noexcept { return static_cast<int>(source.size()); }
210
211 void resize(int n) {
212 const auto un = static_cast<std::size_t>(n);
213
214 rain_type.assign(un, 0);
215 source.assign(un, RainSource::TIMESERIES);
216 ts_index.assign(un, -1);
217 ts_name.assign(un, std::string{});
218 file_path.assign(un, std::string{});
219 col_name.assign(un, std::string{});
221 interval_sec.assign(un, 3600);
222 snow_factor.assign(un, 1.0);
223
224 rainfall.assign(un, 0.0);
225 next_rainfall.assign(un, 0.0);
226 api_rainfall.assign(un, -1.0); // -1.0 means no API override
227 next_rain_date.assign(un, 0.0);
228 is_raining.assign(un, false);
229
230 past_rain.assign(un * MAXPASTRAIN, 0.0);
231 past_rain_accum.assign(un, 0.0);
232 past_rain_time.assign(un, 0.0);
233 cumul_rain_accum.assign(un, 0.0);
234 co_gage_index.assign(un, -1);
235 comments.assign(un, std::string{});
236 }
237
244 void grow_to(int n) {
245 if (n <= count()) return;
246 const auto un = static_cast<std::size_t>(n);
247 auto g = [&](auto& v, auto def) { v.resize(un, def); };
249 ts_name.resize(un, std::string{});
250 file_path.resize(un, std::string{});
251 col_name.resize(un, std::string{});
253 g(rainfall, 0.0); g(next_rainfall, 0.0);
254 g(api_rainfall, -1.0); g(next_rain_date, 0.0); g(is_raining, false);
255 // Flat 2D: [gage * MAXPASTRAIN + hour]
256 past_rain.resize(un * static_cast<std::size_t>(MAXPASTRAIN), 0.0);
257 g(past_rain_accum, 0.0); g(past_rain_time, 0.0); g(cumul_rain_accum, 0.0);
258 g(co_gage_index, -1);
259 comments.resize(un, std::string{});
260 }
261
269 void erase_at(int idx) {
270 const auto ui = static_cast<std::size_t>(idx);
271 auto e = [&](auto& v) { if (ui < v.size()) v.erase(v.begin() + static_cast<std::ptrdiff_t>(idx)); };
272
273 e(rain_type); e(source); e(ts_index); e(ts_name);
277 e(comments);
278
279 // Flat 2D past_rain: [gage * MAXPASTRAIN + hour]
280 const auto base = ui * static_cast<std::size_t>(MAXPASTRAIN);
281 const auto end = base + static_cast<std::size_t>(MAXPASTRAIN);
282 if (end <= past_rain.size())
283 past_rain.erase(past_rain.begin() + static_cast<std::ptrdiff_t>(base),
284 past_rain.begin() + static_cast<std::ptrdiff_t>(end));
285 }
286
291 rain_type.shrink_to_fit();
292 source.shrink_to_fit();
293 ts_index.shrink_to_fit();
294 ts_name.shrink_to_fit();
295 file_path.shrink_to_fit();
296 col_name.shrink_to_fit();
297 file_format.shrink_to_fit();
298 interval_sec.shrink_to_fit();
299 snow_factor.shrink_to_fit();
300
301 rainfall.shrink_to_fit();
302 next_rainfall.shrink_to_fit();
303 api_rainfall.shrink_to_fit();
304 next_rain_date.shrink_to_fit();
305 is_raining.shrink_to_fit();
306
307 past_rain.shrink_to_fit();
308 past_rain_accum.shrink_to_fit();
309 past_rain_time.shrink_to_fit();
310 cumul_rain_accum.shrink_to_fit();
311 co_gage_index.shrink_to_fit();
312 comments.shrink_to_fit();
313 }
314
315 void reset_state() noexcept {
316 std::fill(rainfall.begin(), rainfall.end(), 0.0);
317 std::fill(next_rainfall.begin(), next_rainfall.end(), 0.0);
318 std::fill(api_rainfall.begin(), api_rainfall.end(), -1.0); // -1 = no override
319 std::fill(is_raining.begin(), is_raining.end(), false);
320 std::fill(past_rain.begin(), past_rain.end(), 0.0);
321 std::fill(past_rain_accum.begin(), past_rain_accum.end(), 0.0);
322 std::fill(past_rain_time.begin(), past_rain_time.end(), 0.0);
323 std::fill(cumul_rain_accum.begin(), cumul_rain_accum.end(), 0.0);
324 // co_gage_index is static (set at parse time), not reset between runs
325 }
326};
327
328} /* namespace openswmm */
329
330#endif /* OPENSWMM_ENGINE_GAGE_DATA_HPP */
Definition NodeCoupling.cpp:15
RainFileFormat
Rain data format in an external file.
Definition GageData.hpp:48
@ HLY_PRCP
HLY_PRCP format.
@ STAN_PRCP
Standard SWMM rain file.
@ NWS_HOURLY
NWS hourly data.
@ USER_CSV
User-supplied multi-column CSV (new in 6.0.0, R08)
@ NWS_15
NWS 15-minute data.
@ DSI_3260
NCDC DSI 3260 15-minute.
@ DSI_3240
NCDC DSI 3240 hourly.
RainSource
Precipitation source type for a rain gage.
Definition GageData.hpp:39
@ FILE_RAIN
Data from an external rain file.
@ TIMESERIES
Data from an in-file [TIMESERIES].
Structure-of-Arrays storage for all rain gages.
Definition GageData.hpp:75
std::vector< double > api_rainfall
Current API (antecedent precipitation index) rainfall.
Definition GageData.hpp:152
std::vector< std::string > comments
Object comment from the INP file (';'-prefixed lines immediately above this gage's data row),...
Definition GageData.hpp:194
std::vector< bool > is_raining
Current state flag (0 = no rain, 1 = raining).
Definition GageData.hpp:164
std::vector< std::string > file_path
External rain file path (when source == FILE_RAIN).
Definition GageData.hpp:100
std::vector< double > snow_factor
Snow catch deficiency correction factor (1.0 = no correction).
Definition GageData.hpp:130
std::vector< int > ts_index
Time series index (when source == TIMESERIES).
Definition GageData.hpp:94
std::vector< std::string > col_name
Column name in the external CSV (when source == FILE_RAIN).
Definition GageData.hpp:112
static constexpr int MAXPASTRAIN
Max past hours tracked per gage.
Definition GageData.hpp:170
std::vector< double > past_rain_time
Per-gage time (seconds) of last past-rain shift.
Definition GageData.hpp:179
void reset_state() noexcept
Definition GageData.hpp:315
int count() const noexcept
Definition GageData.hpp:209
std::vector< double > next_rain_date
Simulation time of the next recorded value (decimal days).
Definition GageData.hpp:158
std::vector< std::string > ts_name
Timeseries name (for deferred resolution when TS parsed after gages).
Definition GageData.hpp:105
void grow_to(int n)
Append one new gage with defaults, preserving existing data.
Definition GageData.hpp:244
std::vector< int > co_gage_index
Gap #53: Co-gage index — index of the primary gage sharing the same timeseries, or -1 if this gage re...
Definition GageData.hpp:203
std::vector< int > interval_sec
Recording interval in seconds.
Definition GageData.hpp:124
std::vector< double > past_rain_accum
Per-gage accumulator for the current partial hour.
Definition GageData.hpp:176
std::vector< double > next_rainfall
Rainfall rate at the next recorded interval (for interpolation).
Definition GageData.hpp:146
void shrink_to_fit()
Release excess vector capacity accumulated during parsing.
Definition GageData.hpp:290
std::vector< RainFileFormat > file_format
Rain file format.
Definition GageData.hpp:118
std::vector< int > rain_type
Rain data type: 0=INTENSITY, 1=VOLUME, 2=CUMULATIVE.
Definition GageData.hpp:85
void erase_at(int idx)
Erase the rain gage at index idx from every parallel array.
Definition GageData.hpp:269
std::vector< double > cumul_rain_accum
Gap #31: Cumulative rainfall accumulator (project rain units).
Definition GageData.hpp:187
std::vector< double > rainfall
Current rainfall rate (project length/time units — inches or mm/hr).
Definition GageData.hpp:140
std::vector< RainSource > source
Precipitation source (TIMESERIES or FILE).
Definition GageData.hpp:88
void resize(int n)
Definition GageData.hpp:211
std::vector< double > past_rain
Flat 2D: [gage * MAXPASTRAIN + hour]. Hourly rain totals.
Definition GageData.hpp:173