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
181 // -----------------------------------------------------------------------
182 // Capacity management
183 // -----------------------------------------------------------------------
184
185 int count() const noexcept { return static_cast<int>(source.size()); }
186
187 void resize(int n) {
188 const auto un = static_cast<std::size_t>(n);
189
190 rain_type.assign(un, 0);
191 source.assign(un, RainSource::TIMESERIES);
192 ts_index.assign(un, -1);
193 ts_name.assign(un, std::string{});
194 file_path.assign(un, std::string{});
195 col_name.assign(un, std::string{});
197 interval_sec.assign(un, 3600);
198 snow_factor.assign(un, 1.0);
199
200 rainfall.assign(un, 0.0);
201 next_rainfall.assign(un, 0.0);
202 api_rainfall.assign(un, -1.0); // -1.0 means no API override
203 next_rain_date.assign(un, 0.0);
204 is_raining.assign(un, false);
205
206 past_rain.assign(un * MAXPASTRAIN, 0.0);
207 past_rain_accum.assign(un, 0.0);
208 past_rain_time.assign(un, 0.0);
209 }
210
211 void reset_state() noexcept {
212 std::fill(rainfall.begin(), rainfall.end(), 0.0);
213 std::fill(next_rainfall.begin(), next_rainfall.end(), 0.0);
214 std::fill(api_rainfall.begin(), api_rainfall.end(), -1.0); // -1 = no override
215 std::fill(is_raining.begin(), is_raining.end(), false);
216 std::fill(past_rain.begin(), past_rain.end(), 0.0);
217 std::fill(past_rain_accum.begin(), past_rain_accum.end(), 0.0);
218 std::fill(past_rain_time.begin(), past_rain_time.end(), 0.0);
219 }
220};
221
222} /* namespace openswmm */
223
224#endif /* OPENSWMM_ENGINE_GAGE_DATA_HPP */
Definition Controls.cpp:24
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< 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:211
int count() const noexcept
Definition GageData.hpp:185
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
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
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
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:187
std::vector< double > past_rain
Flat 2D: [gage * MAXPASTRAIN + hour]. Hourly rain totals.
Definition GageData.hpp:173