OpenSWMM Engine  6.0.0-alpha.3
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.3)
Loading...
Searching...
No Matches
ForcingData.hpp
Go to the documentation of this file.
1
24
25#ifndef OPENSWMM_FORCING_DATA_HPP
26#define OPENSWMM_FORCING_DATA_HPP
27
28#include <cstdint>
29#include <vector>
30
31namespace openswmm {
32
33// ============================================================================
34// Forcing enums (C++ scoped — mirrors C API enums in openswmm_forcing.h)
35// ============================================================================
36
37enum class ForcingMode : int8_t {
38 NONE = 0,
40 ADD = 2
41};
42
43enum class ForcingPersist : int8_t {
44 RESET = 0,
46};
47
48// ============================================================================
49// ForcingData — SoA storage for all forcing channels
50// ============================================================================
51
53
54 // ------ Node forcing (sized to n_nodes) ---------------------------------
55
56 std::vector<ForcingMode> node_lat_inflow_mode;
57 std::vector<double> node_lat_inflow_value;
58 std::vector<ForcingPersist> node_lat_inflow_persist;
59
60 std::vector<ForcingMode> node_head_boundary_mode;
61 std::vector<double> node_head_boundary_value;
62 std::vector<ForcingPersist> node_head_boundary_persist;
63
64 // Node quality: flat 2D [node_idx * n_pollutants + pollutant_idx]
65 std::vector<ForcingMode> node_quality_mode;
66 std::vector<double> node_quality_value;
67 std::vector<ForcingPersist> node_quality_persist;
68
69 // ------ Link forcing (sized to n_links) ---------------------------------
70
71 std::vector<ForcingMode> link_flow_mode;
72 std::vector<double> link_flow_value;
73 std::vector<ForcingPersist> link_flow_persist;
74
75 std::vector<ForcingMode> link_setting_mode;
76 std::vector<double> link_setting_value;
77 std::vector<ForcingPersist> link_setting_persist;
78
79 std::vector<ForcingMode> link_quality_mode;
80 std::vector<double> link_quality_value;
81 std::vector<ForcingPersist> link_quality_persist;
82
83 // ------ Subcatchment forcing (sized to n_subcatches) --------------------
84
85 std::vector<ForcingMode> subcatch_rainfall_mode;
86 std::vector<double> subcatch_rainfall_value;
87 std::vector<ForcingPersist> subcatch_rainfall_persist;
88
89 std::vector<ForcingMode> subcatch_evap_mode;
90 std::vector<double> subcatch_evap_value;
91 std::vector<ForcingPersist> subcatch_evap_persist;
92
93 std::vector<ForcingMode> subcatch_snowfall_mode;
94 std::vector<double> subcatch_snowfall_value;
95 std::vector<ForcingPersist> subcatch_snowfall_persist;
96
97 // ------ Gage forcing (sized to n_gages) ---------------------------------
98
99 std::vector<ForcingMode> gage_rainfall_mode;
100 std::vector<double> gage_rainfall_value;
101 std::vector<ForcingPersist> gage_rainfall_persist;
102
103 // ------ Climate forcing (scalar — system-wide) ---------------------------
104
108
110 double climate_wind_value = 0.0;
112
114 double climate_evap_value = 0.0;
116
117 // ------ Counts (for iteration) ------------------------------------------
118
119 int n_nodes_ = 0;
120 int n_links_ = 0;
122 int n_gages_ = 0;
124
125 // ========================================================================
126 // Methods
127 // ========================================================================
128
132 void resize(int n_nodes, int n_links, int n_subcatches,
133 int n_gages, int n_pollutants) {
134 n_nodes_ = n_nodes;
135 n_links_ = n_links;
136 n_subcatches_ = n_subcatches;
137 n_gages_ = n_gages;
138 n_pollutants_ = n_pollutants;
139
140 auto un = static_cast<std::size_t>(n_nodes);
141 auto ul = static_cast<std::size_t>(n_links);
142 auto us = static_cast<std::size_t>(n_subcatches);
143 auto ug = static_cast<std::size_t>(n_gages);
144 auto unp = static_cast<std::size_t>(n_nodes) *
145 static_cast<std::size_t>(n_pollutants);
146
148 node_lat_inflow_value.assign(un, 0.0);
150
152 node_head_boundary_value.assign(un, 0.0);
154
156 node_quality_value.assign(unp, 0.0);
158
160 link_flow_value.assign(ul, 0.0);
162
164 link_setting_value.assign(ul, 0.0);
166
167 auto ulp = static_cast<std::size_t>(n_links) *
168 static_cast<std::size_t>(n_pollutants);
170 link_quality_value.assign(ulp, 0.0);
172
174 subcatch_rainfall_value.assign(us, 0.0);
176
178 subcatch_evap_value.assign(us, 0.0);
180
182 subcatch_snowfall_value.assign(us, 0.0);
184
186 gage_rainfall_value.assign(ug, 0.0);
188 }
189
193 void clear_all() {
194 auto set_none = [](auto& mode_vec) {
195 for (auto& m : mode_vec) m = ForcingMode::NONE;
196 };
197 set_none(node_lat_inflow_mode);
198 set_none(node_head_boundary_mode);
199 set_none(node_quality_mode);
200 set_none(link_flow_mode);
201 set_none(link_setting_mode);
202 set_none(link_quality_mode);
203 set_none(subcatch_rainfall_mode);
204 set_none(subcatch_evap_mode);
205 set_none(subcatch_snowfall_mode);
206 set_none(gage_rainfall_mode);
210 }
211
220 auto clear_resets = [](auto& mode_vec, const auto& persist_vec) {
221 for (std::size_t i = 0; i < mode_vec.size(); ++i) {
222 if (persist_vec[i] == ForcingPersist::RESET)
223 mode_vec[i] = ForcingMode::NONE;
224 }
225 };
229 clear_resets(link_flow_mode, link_flow_persist);
242 }
243
250 double effective_temperature(double broadcast) const noexcept {
251 switch (climate_temperature_mode) {
253 case ForcingMode::ADD: return broadcast + climate_temperature_value;
254 default: return broadcast;
255 }
256 }
257
264 double effective_wind(double broadcast) const noexcept {
265 switch (climate_wind_mode) {
267 case ForcingMode::ADD: return broadcast + climate_wind_value;
268 default: return broadcast;
269 }
270 }
271
283 double effective_rainfall(std::size_t ui, double gage_rainfall) const noexcept {
284 if (ui >= subcatch_rainfall_mode.size()) return gage_rainfall;
285 switch (subcatch_rainfall_mode[ui]) {
287 case ForcingMode::ADD: return gage_rainfall + subcatch_rainfall_value[ui];
288 default: return gage_rainfall;
289 }
290 }
291
298 double effective_climate_evap(double broadcast) const noexcept {
299 switch (climate_evap_mode) {
301 case ForcingMode::ADD: return broadcast + climate_evap_value;
302 default: return broadcast;
303 }
304 }
305
316 double effective_snowfall(std::size_t ui, double gage_snowfall) const noexcept {
317 if (ui >= subcatch_snowfall_mode.size()) return gage_snowfall;
318 switch (subcatch_snowfall_mode[ui]) {
320 case ForcingMode::ADD: return gage_snowfall + subcatch_snowfall_value[ui];
321 default: return gage_snowfall;
322 }
323 }
324
338 double effective_evap_rate(std::size_t ui, double broadcast_rate) const noexcept {
339 // Total over unallocated forcing: callers (Runoff, Groundwater, LID)
340 // run against hand-built / partially-initialized contexts in tests
341 // and via the builder API before the forcing arrays are sized.
342 if (ui >= subcatch_evap_mode.size()) return broadcast_rate;
343 switch (subcatch_evap_mode[ui]) {
345 case ForcingMode::ADD: return broadcast_rate + subcatch_evap_value[ui];
346 default: return broadcast_rate;
347 }
348 }
349};
350
351} // namespace openswmm
352
353#endif // OPENSWMM_FORCING_DATA_HPP
@ NONE
Definition SimulationContext.hpp:125
Definition NodeCoupling.cpp:15
ForcingPersist
Definition ForcingData.hpp:43
@ PERSIST
Keep until explicitly cleared.
Definition ForcingData.hpp:45
@ RESET
Auto-clear after each timestep.
Definition ForcingData.hpp:44
ForcingMode
Definition ForcingData.hpp:37
@ OVERRIDE
Replace computed value with user value.
Definition ForcingData.hpp:39
@ ADD
Add user value to computed value.
Definition ForcingData.hpp:40
@ NONE
Use model-computed value (no forcing)
Definition ForcingData.hpp:38
Definition ForcingData.hpp:52
void clear_reset_entries()
Clear only RESET-persistence entries (called at end of each step).
Definition ForcingData.hpp:219
std::vector< double > subcatch_rainfall_value
user units (in/hr or mm/hr)
Definition ForcingData.hpp:86
std::vector< ForcingMode > node_lat_inflow_mode
Definition ForcingData.hpp:56
double effective_wind(double broadcast) const noexcept
Resolve the effective wind speed (mph internal).
Definition ForcingData.hpp:264
ForcingMode climate_evap_mode
Definition ForcingData.hpp:113
void resize(int n_nodes, int n_links, int n_subcatches, int n_gages, int n_pollutants)
Allocate all arrays and initialise to NONE / 0 / RESET.
Definition ForcingData.hpp:132
double climate_evap_value
ft/sec (internal; converted from in/day or mm/day at the C API boundary)
Definition ForcingData.hpp:114
std::vector< double > link_setting_value
0.0–1.0 for pump/orifice/weir
Definition ForcingData.hpp:76
std::vector< ForcingMode > gage_rainfall_mode
Definition ForcingData.hpp:99
int n_pollutants_
Definition ForcingData.hpp:123
std::vector< ForcingPersist > subcatch_evap_persist
Definition ForcingData.hpp:91
std::vector< ForcingMode > link_quality_mode
flattened link × pollutant
Definition ForcingData.hpp:79
void clear_all()
Reset ALL forcing modes to NONE (called on simulation restart).
Definition ForcingData.hpp:193
std::vector< ForcingMode > subcatch_snowfall_mode
Definition ForcingData.hpp:93
int n_links_
Definition ForcingData.hpp:120
ForcingMode climate_wind_mode
Definition ForcingData.hpp:109
std::vector< double > node_lat_inflow_value
Definition ForcingData.hpp:57
std::vector< ForcingMode > subcatch_rainfall_mode
Definition ForcingData.hpp:85
std::vector< double > link_quality_value
OVERRIDE: concentration; ADD: mass rate (mass/sec)
Definition ForcingData.hpp:80
std::vector< double > subcatch_evap_value
prescribed PET rate, ft/sec (internal units; converted from in/day or mm/day at the C API boundary)
Definition ForcingData.hpp:90
int n_subcatches_
Definition ForcingData.hpp:121
double climate_temperature_value
deg F (internal; converted from deg C at the C API boundary for SI)
Definition ForcingData.hpp:106
double effective_temperature(double broadcast) const noexcept
Resolve the effective air temperature (deg F internal).
Definition ForcingData.hpp:250
std::vector< ForcingMode > link_setting_mode
Definition ForcingData.hpp:75
double effective_snowfall(std::size_t ui, double gage_snowfall) const noexcept
Resolve the effective snowfall for a subcatchment (ft/sec).
Definition ForcingData.hpp:316
std::vector< ForcingMode > node_quality_mode
Definition ForcingData.hpp:65
std::vector< ForcingPersist > subcatch_snowfall_persist
Definition ForcingData.hpp:95
double climate_wind_value
mph (internal; converted from km/hr at the C API boundary for SI)
Definition ForcingData.hpp:110
std::vector< double > subcatch_snowfall_value
ft/sec (internal; converted from in/hr or mm/hr at the C API boundary)
Definition ForcingData.hpp:94
std::vector< double > gage_rainfall_value
user units (in/hr or mm/hr)
Definition ForcingData.hpp:100
std::vector< ForcingPersist > gage_rainfall_persist
Definition ForcingData.hpp:101
double effective_rainfall(std::size_t ui, double gage_rainfall) const noexcept
Resolve the effective rainfall for a subcatchment.
Definition ForcingData.hpp:283
std::vector< ForcingPersist > link_quality_persist
Definition ForcingData.hpp:81
std::vector< ForcingPersist > link_flow_persist
Definition ForcingData.hpp:73
ForcingPersist climate_wind_persist
Definition ForcingData.hpp:111
ForcingMode climate_temperature_mode
Definition ForcingData.hpp:105
std::vector< double > link_flow_value
Definition ForcingData.hpp:72
std::vector< ForcingPersist > node_lat_inflow_persist
Definition ForcingData.hpp:58
double effective_climate_evap(double broadcast) const noexcept
Resolve the effective system-wide evaporation rate (ft/sec).
Definition ForcingData.hpp:298
std::vector< ForcingMode > link_flow_mode
Definition ForcingData.hpp:71
ForcingPersist climate_temperature_persist
Definition ForcingData.hpp:107
std::vector< ForcingMode > node_head_boundary_mode
Definition ForcingData.hpp:60
std::vector< ForcingPersist > node_quality_persist
Definition ForcingData.hpp:67
std::vector< ForcingPersist > subcatch_rainfall_persist
Definition ForcingData.hpp:87
double effective_evap_rate(std::size_t ui, double broadcast_rate) const noexcept
Resolve the effective evaporation rate for a subcatchment.
Definition ForcingData.hpp:338
std::vector< ForcingPersist > node_head_boundary_persist
Definition ForcingData.hpp:62
ForcingPersist climate_evap_persist
Definition ForcingData.hpp:115
std::vector< ForcingPersist > link_setting_persist
Definition ForcingData.hpp:77
std::vector< double > node_head_boundary_value
Definition ForcingData.hpp:61
int n_gages_
Definition ForcingData.hpp:122
std::vector< ForcingMode > subcatch_evap_mode
Definition ForcingData.hpp:89
int n_nodes_
Definition ForcingData.hpp:119
std::vector< double > node_quality_value
mass rate (mass/sec)
Definition ForcingData.hpp:66