OpenSWMM Engine  6.0.0-alpha.3
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.3)
Loading...
Searching...
No Matches
GageData.hpp
Go to the documentation of this file.
1
21
22#ifndef OPENSWMM_ENGINE_GAGE_DATA_HPP
23#define OPENSWMM_ENGINE_GAGE_DATA_HPP
24
26#include "TableData.hpp"
27#include <vector>
28#include <string>
29#include <cstdint>
30
31namespace openswmm {
32
33// ============================================================================
34// Rain source enumeration
35// ============================================================================
36
41enum class RainSource : int8_t {
44};
45
50enum class RainFileFormat : int8_t {
51 UNKNOWN = -1,
52 NWS_15 = 0,
59};
60
61// ============================================================================
62// GageData — SoA layout
63// ============================================================================
64
77struct GageData {
78
79 // -----------------------------------------------------------------------
80 // Static properties — set at parse time
81 // -----------------------------------------------------------------------
82
87 std::vector<int> rain_type;
88
90 std::vector<RainSource> source;
91
96 std::vector<int> ts_index;
97
105 std::vector<FilePathPair> file_path;
106
110 std::vector<std::string> ts_name;
111
117 std::vector<std::string> col_name;
118
127 std::vector<std::string> station_id;
128
135 std::vector<int> rain_units;
136
137 // -----------------------------------------------------------------------
138 // Rainfall-file summary statistics (for the "Rainfall File Summary"
139 // report section). Populated by load_external_rain_files() while it
140 // scans the external file; meaningful only when source == FILE_RAIN.
141 // -----------------------------------------------------------------------
142
144 std::vector<double> file_first_date;
145
147 std::vector<double> file_last_date;
148
150 std::vector<long> file_periods_precip;
151
161 std::vector<Table> rain_series;
162
167 std::vector<RainFileFormat> file_format;
168
173 std::vector<int> interval_sec;
174
179 std::vector<double> snow_factor;
180
192 std::vector<double> scale_factor;
193
194 // -----------------------------------------------------------------------
195 // State variables — updated each timestep
196 // -----------------------------------------------------------------------
197
202 std::vector<double> rainfall;
203
208 std::vector<double> next_rainfall;
209
214 std::vector<double> api_rainfall;
215
220 std::vector<double> next_rain_date;
221
226 std::vector<bool> is_raining;
227
228 // -----------------------------------------------------------------------
229 // Past-rain history (for control rules — GAGE_RAIN_PAST)
230 // -----------------------------------------------------------------------
231
232 static constexpr int MAXPASTRAIN = 48;
233
235 std::vector<double> past_rain;
236
238 std::vector<double> past_rain_accum;
239
241 std::vector<double> past_rain_time;
242
249 std::vector<double> cumul_rain_accum;
250
256 std::vector<std::string> comments;
257
265 std::vector<int> co_gage_index;
266
267 // -----------------------------------------------------------------------
268 // Capacity management
269 // -----------------------------------------------------------------------
270
271 int count() const noexcept { return static_cast<int>(source.size()); }
272
273 void resize(int n) {
274 const auto un = static_cast<std::size_t>(n);
275
276 rain_type.assign(un, 0);
277 source.assign(un, RainSource::TIMESERIES);
278 ts_index.assign(un, -1);
279 ts_name.assign(un, std::string{});
280 file_path.assign(un, std::string{});
281 col_name.assign(un, std::string{});
282 station_id.assign(un, std::string{});
283 rain_units.assign(un, 0);
284 file_first_date.assign(un, 0.0);
285 file_last_date.assign(un, 0.0);
286 file_periods_precip.assign(un, 0L);
287 rain_series.assign(un, Table{});
289 interval_sec.assign(un, 3600);
290 snow_factor.assign(un, 1.0);
291 scale_factor.assign(un, 1.0);
292
293 rainfall.assign(un, 0.0);
294 next_rainfall.assign(un, 0.0);
295 api_rainfall.assign(un, -1.0); // -1.0 means no API override
296 next_rain_date.assign(un, 0.0);
297 is_raining.assign(un, false);
298
299 past_rain.assign(un * MAXPASTRAIN, 0.0);
300 past_rain_accum.assign(un, 0.0);
301 past_rain_time.assign(un, 0.0);
302 cumul_rain_accum.assign(un, 0.0);
303 co_gage_index.assign(un, -1);
304 comments.assign(un, std::string{});
305 }
306
313 void grow_to(int n) {
314 if (n <= count()) return;
315 const auto un = static_cast<std::size_t>(n);
316 auto g = [&](auto& v, auto def) { v.resize(un, def); };
318 ts_name.resize(un, std::string{});
319 file_path.resize(un, std::string{});
320 col_name.resize(un, std::string{});
321 station_id.resize(un, std::string{});
322 g(rain_units, 0);
323 g(file_first_date, 0.0); g(file_last_date, 0.0); g(file_periods_precip, 0L);
324 rain_series.resize(un, Table{});
326 g(scale_factor, 1.0);
327 g(rainfall, 0.0); g(next_rainfall, 0.0);
328 g(api_rainfall, -1.0); g(next_rain_date, 0.0); g(is_raining, false);
329 // Flat 2D: [gage * MAXPASTRAIN + hour]
330 past_rain.resize(un * static_cast<std::size_t>(MAXPASTRAIN), 0.0);
331 g(past_rain_accum, 0.0); g(past_rain_time, 0.0); g(cumul_rain_accum, 0.0);
332 g(co_gage_index, -1);
333 comments.resize(un, std::string{});
334 }
335
343 void erase_at(int idx) {
344 const auto ui = static_cast<std::size_t>(idx);
345 auto e = [&](auto& v) { if (ui < v.size()) v.erase(v.begin() + static_cast<std::ptrdiff_t>(idx)); };
346
347 e(rain_type); e(source); e(ts_index); e(ts_name);
349 e(scale_factor);
352 e(comments);
353
354 // Flat 2D past_rain: [gage * MAXPASTRAIN + hour]
355 const auto base = ui * static_cast<std::size_t>(MAXPASTRAIN);
356 const auto end = base + static_cast<std::size_t>(MAXPASTRAIN);
357 if (end <= past_rain.size())
358 past_rain.erase(past_rain.begin() + static_cast<std::ptrdiff_t>(base),
359 past_rain.begin() + static_cast<std::ptrdiff_t>(end));
360 }
361
366 rain_type.shrink_to_fit();
367 source.shrink_to_fit();
368 ts_index.shrink_to_fit();
369 ts_name.shrink_to_fit();
370 file_path.shrink_to_fit();
371 col_name.shrink_to_fit();
372 file_format.shrink_to_fit();
373 interval_sec.shrink_to_fit();
374 snow_factor.shrink_to_fit();
375 scale_factor.shrink_to_fit();
376
377 rainfall.shrink_to_fit();
378 next_rainfall.shrink_to_fit();
379 api_rainfall.shrink_to_fit();
380 next_rain_date.shrink_to_fit();
381 is_raining.shrink_to_fit();
382
383 past_rain.shrink_to_fit();
384 past_rain_accum.shrink_to_fit();
385 past_rain_time.shrink_to_fit();
386 cumul_rain_accum.shrink_to_fit();
387 co_gage_index.shrink_to_fit();
388 comments.shrink_to_fit();
389 }
390
391 void reset_state() noexcept {
392 std::fill(rainfall.begin(), rainfall.end(), 0.0);
393 std::fill(next_rainfall.begin(), next_rainfall.end(), 0.0);
394 std::fill(api_rainfall.begin(), api_rainfall.end(), -1.0); // -1 = no override
395 std::fill(is_raining.begin(), is_raining.end(), false);
396 std::fill(past_rain.begin(), past_rain.end(), 0.0);
397 std::fill(past_rain_accum.begin(), past_rain_accum.end(), 0.0);
398 std::fill(past_rain_time.begin(), past_rain_time.end(), 0.0);
399 std::fill(cumul_rain_accum.begin(), cumul_rain_accum.end(), 0.0);
400 // co_gage_index is static (set at parse time), not reset between runs
401 }
402};
403
404} /* namespace openswmm */
405
406#endif /* OPENSWMM_ENGINE_GAGE_DATA_HPP */
Carrier for an external file reference in a SWMM model.
Time series and rating curve data with bidirectional cursor.
Definition NodeCoupling.cpp:15
RainFileFormat
Rain data format in an external file.
Definition GageData.hpp:50
@ HLY_PRCP
HLY_PRCP format.
Definition GageData.hpp:56
@ STAN_PRCP
Standard SWMM rain file.
Definition GageData.hpp:57
@ NWS_HOURLY
NWS hourly data.
Definition GageData.hpp:53
@ USER_CSV
User-supplied multi-column CSV (new in 6.0.0, R08)
Definition GageData.hpp:58
@ UNKNOWN
Definition GageData.hpp:51
@ NWS_15
NWS 15-minute data.
Definition GageData.hpp:52
@ DSI_3260
NCDC DSI 3260 15-minute.
Definition GageData.hpp:55
@ DSI_3240
NCDC DSI 3240 hourly.
Definition GageData.hpp:54
RainSource
Precipitation source type for a rain gage.
Definition GageData.hpp:41
@ FILE_RAIN
Data from an external rain file.
Definition GageData.hpp:43
@ TIMESERIES
Data from an in-file [TIMESERIES].
Definition GageData.hpp:42
Structure-of-Arrays storage for all rain gages.
Definition GageData.hpp:77
std::vector< double > api_rainfall
Current API (antecedent precipitation index) rainfall.
Definition GageData.hpp:214
std::vector< int > rain_units
Rain depth units declared in the [RAINGAGES] FILE row: 0 = IN, 1 = MM.
Definition GageData.hpp:135
std::vector< double > file_first_date
First record date found for this gage's station (OADate, 0 = none).
Definition GageData.hpp:144
std::vector< std::string > comments
Object comment from the INP file (';'-prefixed lines immediately above this gage's data row),...
Definition GageData.hpp:256
std::vector< double > file_last_date
Last record date found for this gage's station (OADate, 0 = none).
Definition GageData.hpp:147
std::vector< bool > is_raining
Current state flag (0 = no rain, 1 = raining).
Definition GageData.hpp:226
std::vector< double > snow_factor
Snow catch deficiency correction factor (1.0 = no correction).
Definition GageData.hpp:179
std::vector< int > ts_index
Time series index (when source == TIMESERIES).
Definition GageData.hpp:96
std::vector< std::string > col_name
Column name in the external CSV (when source == FILE_RAIN).
Definition GageData.hpp:117
static constexpr int MAXPASTRAIN
Max past hours tracked per gage.
Definition GageData.hpp:232
std::vector< FilePathPair > file_path
External rain file path (when source == FILE_RAIN).
Definition GageData.hpp:105
std::vector< Table > rain_series
Resolved rainfall series for a FILE_RAIN gage (windowed to the run).
Definition GageData.hpp:161
std::vector< double > past_rain_time
Per-gage time (seconds) of last past-rain shift.
Definition GageData.hpp:241
void reset_state() noexcept
Definition GageData.hpp:391
int count() const noexcept
Definition GageData.hpp:271
std::vector< double > next_rain_date
Simulation time of the next recorded value (decimal days).
Definition GageData.hpp:220
std::vector< std::string > ts_name
Timeseries name (for deferred resolution when TS parsed after gages).
Definition GageData.hpp:110
void grow_to(int n)
Append one new gage with defaults, preserving existing data.
Definition GageData.hpp:313
std::vector< double > scale_factor
Rainfall scaling factor (1.0 = no scaling).
Definition GageData.hpp:192
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:265
std::vector< int > interval_sec
Recording interval in seconds.
Definition GageData.hpp:173
std::vector< double > past_rain_accum
Per-gage accumulator for the current partial hour.
Definition GageData.hpp:238
std::vector< double > next_rainfall
Rainfall rate at the next recorded interval (for interpolation).
Definition GageData.hpp:208
void shrink_to_fit()
Release excess vector capacity accumulated during parsing.
Definition GageData.hpp:365
std::vector< long > file_periods_precip
Number of records with precipitation > 0 for this station.
Definition GageData.hpp:150
std::vector< RainFileFormat > file_format
Rain file format.
Definition GageData.hpp:167
std::vector< int > rain_type
Rain data type: 0=INTENSITY, 1=VOLUME, 2=CUMULATIVE.
Definition GageData.hpp:87
void erase_at(int idx)
Erase the rain gage at index idx from every parallel array.
Definition GageData.hpp:343
std::vector< std::string > station_id
Station ID for a standard SWMM rain file (when source == FILE_RAIN).
Definition GageData.hpp:127
std::vector< double > cumul_rain_accum
Gap #31: Cumulative rainfall accumulator (project rain units).
Definition GageData.hpp:249
std::vector< double > rainfall
Current rainfall rate (project length/time units — inches or mm/hr).
Definition GageData.hpp:202
std::vector< RainSource > source
Precipitation source (TIMESERIES or FILE).
Definition GageData.hpp:90
void resize(int n)
Definition GageData.hpp:273
std::vector< double > past_rain
Flat 2D: [gage * MAXPASTRAIN + hour]. Hourly rain totals.
Definition GageData.hpp:235
Definition TableData.hpp:120