OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches
ForcingData.hpp
Go to the documentation of this file.
1
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,
39 OVERRIDE = 1,
40 ADD = 2
41};
42
43enum class ForcingPersist : int8_t {
44 RESET = 0,
45 PERSIST = 1
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 // ------ Subcatchment forcing (sized to n_subcatches) --------------------
80
81 std::vector<ForcingMode> subcatch_rainfall_mode;
82 std::vector<double> subcatch_rainfall_value;
83 std::vector<ForcingPersist> subcatch_rainfall_persist;
84
85 std::vector<ForcingMode> subcatch_evap_mode;
86 std::vector<double> subcatch_evap_value;
87 std::vector<ForcingPersist> subcatch_evap_persist;
88
89 // ------ Gage forcing (sized to n_gages) ---------------------------------
90
91 std::vector<ForcingMode> gage_rainfall_mode;
92 std::vector<double> gage_rainfall_value;
93 std::vector<ForcingPersist> gage_rainfall_persist;
94
95 // ------ Counts (for iteration) ------------------------------------------
96
97 int n_nodes_ = 0;
98 int n_links_ = 0;
100 int n_gages_ = 0;
102
103 // ========================================================================
104 // Methods
105 // ========================================================================
106
110 void resize(int n_nodes, int n_links, int n_subcatches,
111 int n_gages, int n_pollutants) {
112 n_nodes_ = n_nodes;
113 n_links_ = n_links;
114 n_subcatches_ = n_subcatches;
115 n_gages_ = n_gages;
116 n_pollutants_ = n_pollutants;
117
118 auto un = static_cast<std::size_t>(n_nodes);
119 auto ul = static_cast<std::size_t>(n_links);
120 auto us = static_cast<std::size_t>(n_subcatches);
121 auto ug = static_cast<std::size_t>(n_gages);
122 auto unp = static_cast<std::size_t>(n_nodes) *
123 static_cast<std::size_t>(n_pollutants);
124
126 node_lat_inflow_value.assign(un, 0.0);
128
130 node_head_boundary_value.assign(un, 0.0);
132
134 node_quality_value.assign(unp, 0.0);
136
138 link_flow_value.assign(ul, 0.0);
140
142 link_setting_value.assign(ul, 0.0);
144
146 subcatch_rainfall_value.assign(us, 0.0);
148
150 subcatch_evap_value.assign(us, 0.0);
152
154 gage_rainfall_value.assign(ug, 0.0);
156 }
157
161 void clear_all() {
162 auto set_none = [](auto& mode_vec) {
163 for (auto& m : mode_vec) m = ForcingMode::NONE;
164 };
165 set_none(node_lat_inflow_mode);
166 set_none(node_head_boundary_mode);
167 set_none(node_quality_mode);
168 set_none(link_flow_mode);
169 set_none(link_setting_mode);
170 set_none(subcatch_rainfall_mode);
171 set_none(subcatch_evap_mode);
172 set_none(gage_rainfall_mode);
173 }
174
183 auto clear_resets = [](auto& mode_vec, const auto& persist_vec) {
184 for (std::size_t i = 0; i < mode_vec.size(); ++i) {
185 if (persist_vec[i] == ForcingPersist::RESET)
186 mode_vec[i] = ForcingMode::NONE;
187 }
188 };
192 clear_resets(link_flow_mode, link_flow_persist);
197 }
198};
199
200} // namespace openswmm
201
202#endif // OPENSWMM_FORCING_DATA_HPP
Definition Controls.cpp:24
ForcingPersist
Definition ForcingData.hpp:43
@ PERSIST
Keep until explicitly cleared.
@ RESET
Auto-clear after each timestep.
ForcingMode
Definition ForcingData.hpp:37
@ OVERRIDE
Replace computed value with user value.
@ ADD
Add user value to computed value.
@ NONE
Use model-computed value (no forcing)
Definition ForcingData.hpp:52
void clear_reset_entries()
Clear only RESET-persistence entries (called at end of each step).
Definition ForcingData.hpp:182
std::vector< double > subcatch_rainfall_value
user units (in/hr or mm/hr)
Definition ForcingData.hpp:82
std::vector< ForcingMode > node_lat_inflow_mode
Definition ForcingData.hpp:56
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:110
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:91
int n_pollutants_
Definition ForcingData.hpp:101
std::vector< ForcingPersist > subcatch_evap_persist
Definition ForcingData.hpp:87
void clear_all()
Reset ALL forcing modes to NONE (called on simulation restart).
Definition ForcingData.hpp:161
int n_links_
Definition ForcingData.hpp:98
std::vector< double > node_lat_inflow_value
Definition ForcingData.hpp:57
std::vector< ForcingMode > subcatch_rainfall_mode
Definition ForcingData.hpp:81
std::vector< double > subcatch_evap_value
ft/sec (internal units)
Definition ForcingData.hpp:86
int n_subcatches_
Definition ForcingData.hpp:99
std::vector< ForcingMode > link_setting_mode
Definition ForcingData.hpp:75
std::vector< ForcingMode > node_quality_mode
Definition ForcingData.hpp:65
std::vector< double > gage_rainfall_value
user units (in/hr or mm/hr)
Definition ForcingData.hpp:92
std::vector< ForcingPersist > gage_rainfall_persist
Definition ForcingData.hpp:93
std::vector< ForcingPersist > link_flow_persist
Definition ForcingData.hpp:73
std::vector< double > link_flow_value
Definition ForcingData.hpp:72
std::vector< ForcingPersist > node_lat_inflow_persist
Definition ForcingData.hpp:58
std::vector< ForcingMode > link_flow_mode
Definition ForcingData.hpp:71
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:83
std::vector< ForcingPersist > node_head_boundary_persist
Definition ForcingData.hpp:62
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:100
std::vector< ForcingMode > subcatch_evap_mode
Definition ForcingData.hpp:85
int n_nodes_
Definition ForcingData.hpp:97
std::vector< double > node_quality_value
mass rate (mass/sec)
Definition ForcingData.hpp:66