OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches
NodeData.hpp
Go to the documentation of this file.
1
25#ifndef OPENSWMM_ENGINE_NODE_DATA_HPP
26#define OPENSWMM_ENGINE_NODE_DATA_HPP
27
28#include <vector>
29#include <cstdint>
30#include <string>
31
32namespace openswmm {
33
34// ============================================================================
35// Node type enumeration
36// ============================================================================
37
42enum class NodeType : int8_t {
43 JUNCTION = 0,
44 OUTFALL = 1,
45 DIVIDER = 2,
46 STORAGE = 3
47};
48
53enum class OutfallType : int8_t {
54 FREE = 0,
55 NORMAL = 1,
56 FIXED = 2,
57 TIDAL = 3,
58 TIMESERIES = 4
59};
60
65enum class DividerType : int8_t {
66 CUTOFF = 0,
67 OVERFLOW_DIV = 1,
68 TABULAR = 2,
69 WEIR = 3
70};
71
72// ============================================================================
73// NodeData — SoA layout
74// ============================================================================
75
89struct NodeData {
90
91 // -----------------------------------------------------------------------
92 // Static properties — set at parse time
93 // -----------------------------------------------------------------------
94
96 std::vector<NodeType> type;
97
102 std::vector<double> invert_elev;
103
108 std::vector<double> full_depth;
109
114 std::vector<double> init_depth;
115
120 std::vector<double> sur_depth;
121
126 std::vector<double> ponded_area;
127
128 // -----------------------------------------------------------------------
129 // Outfall-specific properties (valid when type[i] == OUTFALL)
130 // -----------------------------------------------------------------------
131
133 std::vector<OutfallType> outfall_type;
134
140 std::vector<double> outfall_param;
141
143 std::vector<bool> outfall_has_flap_gate;
144
145 // -----------------------------------------------------------------------
146 // Storage-specific properties (valid when type[i] == STORAGE)
147 // -----------------------------------------------------------------------
148
153 std::vector<int> storage_curve;
154
156 std::vector<std::string> storage_curve_name;
157
159 std::vector<double> storage_a;
161 std::vector<double> storage_b;
163 std::vector<double> storage_c;
164
166 std::vector<double> storage_seep_rate;
167
169 std::vector<double> exfil_suction;
171 std::vector<double> exfil_ksat;
173 std::vector<double> exfil_imd;
174
175 // -----------------------------------------------------------------------
176 // Divider-specific properties (valid when type[i] == DIVIDER)
177 // -----------------------------------------------------------------------
178
180 std::vector<DividerType> divider_type;
181
183 std::vector<double> divider_cutoff;
184
186 std::vector<double> divider_cd;
187
189 std::vector<double> divider_max_depth;
190
192 std::vector<int> divider_curve;
193
195 std::vector<int> divider_link;
196
198 std::vector<std::string> divider_link_name;
199
201 std::vector<std::string> divider_curve_name;
202
203 // -----------------------------------------------------------------------
204 // State variables — updated each timestep
205 // -----------------------------------------------------------------------
206
211 std::vector<double> depth;
212
217 std::vector<double> head;
218
223 std::vector<double> volume;
224
229 std::vector<double> lat_flow;
230
238 std::vector<double> user_lat_flow;
239
244 std::vector<double> inflow;
245
250 std::vector<double> outflow;
251
256 std::vector<double> overflow;
257
262 std::vector<double> losses;
263
268 std::vector<double> crown_elev;
269
274 std::vector<int> degree;
275
280 std::vector<double> old_net_inflow;
281
286 std::vector<double> full_volume;
287
288 // -----------------------------------------------------------------------
289 // Previous-step state (for output interpolation / CFL checks)
290 // -----------------------------------------------------------------------
291
293 std::vector<double> old_depth;
294
296 std::vector<double> old_volume;
297
299 std::vector<double> old_lat_flow;
300
301 // -----------------------------------------------------------------------
302 // Cumulative statistics
303 // -----------------------------------------------------------------------
304
309 std::vector<double> stat_vol_flooded;
310
315 std::vector<double> stat_time_flooded;
316
321 std::vector<double> stat_max_depth;
322
327 std::vector<double> stat_max_overflow;
328
333 std::vector<double> stat_outfall_avg_flow;
334
337 std::vector<double> stat_max_lat_inflow;
338
341 std::vector<double> stat_max_total_inflow;
342
345 std::vector<double> stat_lat_inflow_vol;
346
348 std::vector<double> stat_total_inflow_vol;
349
354 std::vector<double> stat_outfall_max_flow;
355
360 std::vector<long> stat_outfall_periods;
361
368 std::vector<double> stat_total_load;
370
371 // -----------------------------------------------------------------------
372 // Capacity management
373 // -----------------------------------------------------------------------
374
376 int count() const noexcept { return static_cast<int>(type.size()); }
377
385 void resize(int n) {
386 const auto un = static_cast<std::size_t>(n);
387 type.assign(un, NodeType::JUNCTION);
388 invert_elev.assign(un, 0.0);
389 full_depth.assign(un, 0.0);
390 init_depth.assign(un, 0.0);
391 sur_depth.assign(un, 0.0);
392 ponded_area.assign(un, 0.0);
393
395 outfall_param.assign(un, 0.0);
396 outfall_has_flap_gate.assign(un, false);
397
398 storage_curve.assign(un, -1);
399 storage_curve_name.resize(un);
400 storage_a.assign(un, 0.0);
401 storage_b.assign(un, 0.0);
402 storage_c.assign(un, 0.0);
403 storage_seep_rate.assign(un, 0.0);
404 exfil_suction.assign(un, 0.0);
405 exfil_ksat.assign(un, 0.0);
406 exfil_imd.assign(un, 0.0);
407
409 divider_cutoff.assign(un, 0.0);
410 divider_cd.assign(un, 0.0);
411 divider_max_depth.assign(un, 0.0);
412 divider_curve.assign(un, -1);
413 divider_link.assign(un, -1);
414 divider_link_name.resize(un);
415 divider_curve_name.resize(un);
416
417 depth.assign(un, 0.0);
418 head.assign(un, 0.0);
419 volume.assign(un, 0.0);
420 lat_flow.assign(un, 0.0);
421 user_lat_flow.assign(un, 0.0);
422 inflow.assign(un, 0.0);
423 outflow.assign(un, 0.0);
424 overflow.assign(un, 0.0);
425 losses.assign(un, 0.0);
426 crown_elev.assign(un, 0.0);
427 degree.assign(un, 0);
428 old_net_inflow.assign(un, 0.0);
429 full_volume.assign(un, 0.0);
430 old_depth.assign(un, 0.0);
431 old_volume.assign(un, 0.0);
432 old_lat_flow.assign(un, 0.0);
433
434 stat_vol_flooded.assign(un, 0.0);
435 stat_time_flooded.assign(un, 0.0);
436 stat_max_depth.assign(un, 0.0);
437 stat_max_overflow.assign(un, 0.0);
438 stat_max_lat_inflow.assign(un, 0.0);
439 stat_max_total_inflow.assign(un, 0.0);
440 stat_lat_inflow_vol.assign(un, 0.0);
441 stat_total_inflow_vol.assign(un, 0.0);
442 stat_outfall_avg_flow.assign(un, 0.0);
443 stat_outfall_max_flow.assign(un, 0.0);
444 stat_outfall_periods.assign(un, 0);
445 }
446
450 void resize_loads(int n_pollutants) {
451 stat_n_pollutants = n_pollutants;
452 if (n_pollutants > 0) {
453 auto total = static_cast<std::size_t>(count()) *
454 static_cast<std::size_t>(n_pollutants);
455 stat_total_load.assign(total, 0.0);
456 }
457 }
458
462 void save_state() noexcept {
466 // Save net inflow for trapezoidal averaging in next step
467 for (std::size_t i = 0; i < inflow.size(); ++i) {
468 old_net_inflow[i] = inflow[i] - outflow[i];
469 }
470 }
471
473 void reset_state() noexcept {
474 const auto n = depth.size();
475 std::fill(depth.begin(), depth.end(), 0.0);
476 std::fill(head.begin(), head.end(), 0.0);
477 std::fill(volume.begin(), volume.end(), 0.0);
478 std::fill(lat_flow.begin(), lat_flow.end(), 0.0);
479 std::fill(inflow.begin(), inflow.end(), 0.0);
480 std::fill(outflow.begin(), outflow.end(), 0.0);
481 std::fill(overflow.begin(), overflow.end(), 0.0);
482 std::fill(losses.begin(), losses.end(), 0.0);
483 std::fill(old_net_inflow.begin(), old_net_inflow.end(), 0.0);
484 std::fill(old_depth.begin(), old_depth.end(), 0.0);
485 std::fill(old_volume.begin(), old_volume.end(), 0.0);
486 std::fill(old_lat_flow.begin(), old_lat_flow.end(), 0.0);
487 (void)n;
488 }
489};
490
491} /* namespace openswmm */
492
493#endif /* OPENSWMM_ENGINE_NODE_DATA_HPP */
Definition Controls.cpp:24
OutfallType
Outfall boundary condition type.
Definition NodeData.hpp:53
NodeType
Node type codes.
Definition NodeData.hpp:42
DividerType
Flow divider type.
Definition NodeData.hpp:65
@ OVERFLOW_DIV
Renamed from OVERFLOW to avoid macOS math.h macro collision.
@ TIMESERIES
Data from an in-file [TIMESERIES].
Structure-of-Arrays storage for all nodes.
Definition NodeData.hpp:89
std::vector< double > stat_lat_inflow_vol
Definition NodeData.hpp:345
int count() const noexcept
Number of nodes.
Definition NodeData.hpp:376
std::vector< double > depth
Current water depth above invert (project length units).
Definition NodeData.hpp:211
std::vector< double > invert_elev
Invert elevation (project length units).
Definition NodeData.hpp:102
std::vector< double > exfil_imd
Green-Ampt initial moisture deficit for exfiltration (0-1).
Definition NodeData.hpp:173
std::vector< std::string > divider_link_name
Diversion link name (for deferred resolution).
Definition NodeData.hpp:198
std::vector< double > stat_vol_flooded
Total volume of water lost as overflow (project volume units).
Definition NodeData.hpp:309
std::vector< double > storage_b
Functional storage area parameter B.
Definition NodeData.hpp:161
std::vector< int > divider_curve
Diversion curve index for TABULAR dividers (-1 = none).
Definition NodeData.hpp:192
std::vector< std::string > divider_curve_name
Diversion curve name (for deferred resolution, TABULAR only).
Definition NodeData.hpp:201
std::vector< double > old_depth
Depth at the previous timestep.
Definition NodeData.hpp:293
void reset_state() noexcept
Zero all state variables (for a cold start).
Definition NodeData.hpp:473
std::vector< double > divider_cd
Weir discharge coefficient for WEIR dividers.
Definition NodeData.hpp:186
std::vector< double > old_volume
Volume at the previous timestep.
Definition NodeData.hpp:296
std::vector< double > exfil_suction
Green-Ampt suction head for exfiltration (in or mm, converted to ft).
Definition NodeData.hpp:169
std::vector< double > outfall_param
Fixed outfall stage or tidal curve / time series index.
Definition NodeData.hpp:140
std::vector< double > storage_a
Functional storage area parameter A (area = A * depth^B + C).
Definition NodeData.hpp:159
std::vector< double > stat_max_overflow
Maximum reported overflow rate (project flow units).
Definition NodeData.hpp:327
std::vector< int > divider_link
Diversion link index (-1 = not set).
Definition NodeData.hpp:195
std::vector< double > outflow
Current total outflow from the node (project flow units).
Definition NodeData.hpp:250
std::vector< double > overflow
Current overflow / ponded flow (project flow units).
Definition NodeData.hpp:256
std::vector< double > old_net_inflow
Net inflow from previous timestep (inflow - outflow) for averaging.
Definition NodeData.hpp:280
std::vector< double > stat_max_lat_inflow
Definition NodeData.hpp:337
std::vector< double > stat_outfall_max_flow
Outfall maximum flow (project flow units).
Definition NodeData.hpp:354
std::vector< double > volume
Current water volume (project volume units).
Definition NodeData.hpp:223
std::vector< double > lat_flow
Current lateral inflow (project flow units).
Definition NodeData.hpp:229
std::vector< double > ponded_area
Ponding area at the surface (sq project length units).
Definition NodeData.hpp:126
std::vector< double > stat_total_inflow_vol
Cumulative total inflow volume at each node (ft3).
Definition NodeData.hpp:348
std::vector< double > sur_depth
Maximum depth allowed at the node (ponding or surcharge limit).
Definition NodeData.hpp:120
std::vector< double > crown_elev
Crown elevation — top of highest connecting conduit (project length units).
Definition NodeData.hpp:268
std::vector< double > old_lat_flow
Lateral flow at the previous timestep.
Definition NodeData.hpp:299
std::vector< double > stat_outfall_avg_flow
Outfall cumulative average flow (flow units × reporting periods).
Definition NodeData.hpp:333
std::vector< double > inflow
Current total inflow to the node (project flow units).
Definition NodeData.hpp:244
void save_state() noexcept
Snapshot current state into old-step arrays before solving.
Definition NodeData.hpp:462
std::vector< double > stat_max_depth
Maximum reported depth (project length units).
Definition NodeData.hpp:321
std::vector< long > stat_outfall_periods
Outfall number of non-zero flow periods.
Definition NodeData.hpp:360
std::vector< int > storage_curve
Storage curve index into TableData (CURVE_STORAGE).
Definition NodeData.hpp:153
void resize_loads(int n_pollutants)
Resize pollutant load arrays after pollutant count is known.
Definition NodeData.hpp:450
std::vector< DividerType > divider_type
Divider method (DividerType enum value).
Definition NodeData.hpp:180
std::vector< double > divider_max_depth
Weir max depth for WEIR dividers.
Definition NodeData.hpp:189
std::vector< bool > outfall_has_flap_gate
True if the outfall has a gated flap.
Definition NodeData.hpp:143
std::vector< int > degree
Node degree — number of connecting links (+ve downstream, -ve upstream terminal).
Definition NodeData.hpp:274
std::vector< double > stat_time_flooded
Total duration the node was flooded (seconds).
Definition NodeData.hpp:315
std::vector< double > init_depth
Initial water depth (project length units).
Definition NodeData.hpp:114
std::vector< double > stat_total_load
Cumulative pollutant loads at each node.
Definition NodeData.hpp:368
void resize(int n)
Resize all arrays to hold exactly n nodes.
Definition NodeData.hpp:385
std::vector< double > storage_seep_rate
Seepage rate from storage node (project units/day).
Definition NodeData.hpp:166
std::vector< double > exfil_ksat
Green-Ampt saturated hydraulic conductivity for exfiltration (in/hr or mm/hr, converted to ft/sec).
Definition NodeData.hpp:171
std::vector< double > full_volume
Full volume at node (project volume units).
Definition NodeData.hpp:286
std::vector< std::string > storage_curve_name
Curve name for deferred resolution (populated during parsing).
Definition NodeData.hpp:156
std::vector< double > losses
Node losses (evaporation + seepage) (project flow units).
Definition NodeData.hpp:262
std::vector< NodeType > type
Node type for each node.
Definition NodeData.hpp:96
std::vector< double > full_depth
Full depth of the node (project length units).
Definition NodeData.hpp:108
std::vector< double > stat_max_total_inflow
Definition NodeData.hpp:341
std::vector< double > storage_c
Functional storage area parameter C (baseline area).
Definition NodeData.hpp:163
std::vector< double > head
Current water surface head (project length units = invert + depth).
Definition NodeData.hpp:217
std::vector< OutfallType > outfall_type
Outfall boundary condition type.
Definition NodeData.hpp:133
std::vector< double > divider_cutoff
Cutoff flow for CUTOFF dividers.
Definition NodeData.hpp:183
std::vector< double > user_lat_flow
User-forced lateral inflow set via the API (project flow units).
Definition NodeData.hpp:238
int stat_n_pollutants
Definition NodeData.hpp:369