OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches
LinkData.hpp
Go to the documentation of this file.
1
24#ifndef OPENSWMM_ENGINE_LINK_DATA_HPP
25#define OPENSWMM_ENGINE_LINK_DATA_HPP
26
27#include <vector>
28#include <cstdint>
29
30namespace openswmm {
31
32// ============================================================================
33// Link type enumerations
34// ============================================================================
35
40enum class LinkType : int8_t {
41 CONDUIT = 0,
42 PUMP = 1,
43 ORIFICE = 2,
44 WEIR = 3,
45 OUTLET = 4
46};
47
52enum class XsectShape : int16_t {
53 CIRCULAR = 0,
55 RECT_CLOSED = 2,
56 RECT_OPEN = 3,
57 TRAPEZOIDAL = 4,
58 TRIANGULAR = 5,
59 PARABOLIC = 6,
60 POWER = 7,
62 EGGSHAPED = 9,
63 HORSESHOE = 10,
64 GOTHIC = 11,
65 CATENARY = 12,
66 SEMIELLIPTICAL = 13,
67 BASKETHANDLE = 14,
68 SEMICIRCULAR = 15,
69 RECT_TRIANG = 16,
70 RECT_ROUND = 17,
71 IRREGULAR = 18,
72 CUSTOM = 19,
73 FORCE_MAIN = 20,
74 STREET_XSECT = 21,
75 DUMMY = 22
76};
77
82enum class FlowClass : int8_t {
83 DRY = 0,
84 UP_DRY = 1,
85 DN_DRY = 2,
86 SUBCRITICAL = 3,
87 SUPERCRITICAL = 4,
88 UP_CRITICAL = 5,
89 DN_CRITICAL = 6
90};
91
92// ============================================================================
93// LinkData — SoA layout
94// ============================================================================
95
104struct LinkData {
105
106 // -----------------------------------------------------------------------
107 // Static connectivity — set at parse time
108 // -----------------------------------------------------------------------
109
111 std::vector<LinkType> type;
112
117 std::vector<int> node1;
118
123 std::vector<int> node2;
124
129 std::vector<double> offset1;
130
135 std::vector<double> offset2;
136
141 std::vector<double> q0;
142
147 std::vector<double> q_limit;
148
149 // -----------------------------------------------------------------------
150 // Conduit-specific properties (valid when type[i] == CONDUIT)
151 // -----------------------------------------------------------------------
152
154 std::vector<XsectShape> xsect_shape;
155
157 std::vector<double> xsect_y_full;
158
160 std::vector<double> xsect_a_full;
161
163 std::vector<double> xsect_w_max;
164
169 std::vector<int> xsect_curve;
170
172 std::vector<double> roughness;
173
175 std::vector<double> length;
176
178 std::vector<double> slope;
179
187 std::vector<double> mod_length;
188
190 std::vector<int> barrels;
191
197 std::vector<double> beta;
198
203 std::vector<double> rough_factor;
204
209 std::vector<double> q_full;
210
215 std::vector<double> xsect_r_full;
216
221 std::vector<double> xsect_s_full;
222
227 std::vector<double> xsect_s_max;
228
233 std::vector<double> q_max;
234
239 std::vector<double> xsect_y_bot;
240
245 std::vector<double> xsect_a_bot;
246
252 std::vector<double> xsect_s_bot;
253
258 std::vector<double> xsect_r_bot;
259
264 std::vector<double> xsect_yw_max;
265
270 std::vector<double> setting;
271
276 std::vector<double> target_setting;
277
282 std::vector<int> direction;
283
284 // -----------------------------------------------------------------------
285 // Pump-specific properties (valid when type[i] == PUMP)
286 // -----------------------------------------------------------------------
287
292 std::vector<int> pump_curve;
293
295 std::vector<bool> pump_init_state;
296
297 // -----------------------------------------------------------------------
298 // Conduit loss coefficients
299 // -----------------------------------------------------------------------
300
302 std::vector<double> loss_inlet;
304 std::vector<double> loss_outlet;
306 std::vector<double> loss_avg;
308 std::vector<bool> has_flap_gate;
310 std::vector<double> seep_rate;
311
316 std::vector<int> culvert_code;
317
320 std::vector<bool> normal_flow_limited;
321
326 std::vector<bool> inlet_control;
327
332 std::vector<double> dqdh;
333
334 // -----------------------------------------------------------------------
335 // Weir / Orifice / Outlet — shared geometric properties
336 // -----------------------------------------------------------------------
337
339 std::vector<double> crest_height;
340
342 std::vector<double> cd;
343
345 std::vector<double> param2;
346
352 std::vector<double> orate;
353
354 // -----------------------------------------------------------------------
355 // State variables — updated each timestep
356 // -----------------------------------------------------------------------
357
362 std::vector<double> flow;
363
368 std::vector<double> depth;
369
374 std::vector<double> volume;
375
380 std::vector<double> froude;
381
383 std::vector<FlowClass> flow_class;
384
386 std::vector<bool> is_closed;
387
388 // -----------------------------------------------------------------------
389 // Previous-step state
390 // -----------------------------------------------------------------------
391
393 std::vector<double> old_flow;
394
396 std::vector<double> old_depth;
397
399 std::vector<double> old_volume;
400
401 // -----------------------------------------------------------------------
402 // Cumulative statistics
403 // -----------------------------------------------------------------------
404
409 std::vector<double> stat_vol_flow;
410
415 std::vector<double> stat_max_flow;
416
421 std::vector<double> stat_max_veloc;
422
427 std::vector<double> stat_max_filling;
428
433 std::vector<double> stat_time_surcharged;
434
441 static constexpr int N_FLOW_CLASSES = 7;
442 std::vector<long> stat_flow_class;
443 std::vector<long> stat_norm_ltd;
444 std::vector<long> stat_inlet_ctrl;
445
452 std::vector<double> stat_total_load;
454
455 // -----------------------------------------------------------------------
456 // Capacity management
457 // -----------------------------------------------------------------------
458
459 int count() const noexcept { return static_cast<int>(type.size()); }
460
461 void resize(int n) {
462 const auto un = static_cast<std::size_t>(n);
463
464 type.assign(un, LinkType::CONDUIT);
465 node1.assign(un, -1);
466 node2.assign(un, -1);
467 offset1.assign(un, 0.0);
468 offset2.assign(un, 0.0);
469 q0.assign(un, 0.0);
470 q_limit.assign(un, 0.0);
471
473 xsect_y_full.assign(un, 0.0);
474 xsect_a_full.assign(un, 0.0);
475 xsect_w_max.assign(un, 0.0);
476 xsect_curve.assign(un, -1);
477 roughness.assign(un, 0.01);
478 length.assign(un, 0.0);
479 slope.assign(un, 0.0);
480 mod_length.assign(un, 0.0);
481 barrels.assign(un, 1);
482 beta.assign(un, 0.0);
483 rough_factor.assign(un, 0.0);
484 q_full.assign(un, 0.0);
485 xsect_r_full.assign(un, 0.0);
486 xsect_s_full.assign(un, 0.0);
487 xsect_s_max.assign(un, 0.0);
488 q_max.assign(un, 0.0);
489 xsect_y_bot.assign(un, 0.0);
490 xsect_a_bot.assign(un, 0.0);
491 xsect_s_bot.assign(un, 0.0);
492 xsect_r_bot.assign(un, 0.0);
493 xsect_yw_max.assign(un, 0.0);
494 setting.assign(un, 1.0);
495 target_setting.assign(un, 1.0);
496 direction.assign(un, 1);
497
498 loss_inlet.assign(un, 0.0);
499 loss_outlet.assign(un, 0.0);
500 loss_avg.assign(un, 0.0);
501 has_flap_gate.assign(un, false);
502 seep_rate.assign(un, 0.0);
503 culvert_code.assign(un, 0);
504 inlet_control.assign(un, false);
505 dqdh.assign(un, 0.0);
506
507 pump_curve.assign(un, -1);
508 pump_init_state.assign(un, false);
509
510 crest_height.assign(un, 0.0);
511 cd.assign(un, 0.0);
512 param2.assign(un, 0.0);
513 orate.assign(un, 0.0);
514
515 flow.assign(un, 0.0);
516 depth.assign(un, 0.0);
517 volume.assign(un, 0.0);
518 froude.assign(un, 0.0);
519 flow_class.assign(un, FlowClass::DRY);
520 is_closed.assign(un, false);
521 old_flow.assign(un, 0.0);
522 old_depth.assign(un, 0.0);
523 old_volume.assign(un, 0.0);
524
525 stat_vol_flow.assign(un, 0.0);
526 stat_max_flow.assign(un, 0.0);
527 stat_max_veloc.assign(un, 0.0);
528 stat_max_filling.assign(un, 0.0);
529 stat_time_surcharged.assign(un, 0.0);
530 stat_flow_class.assign(un * N_FLOW_CLASSES, 0L);
531 stat_norm_ltd.assign(un, 0L);
532 stat_inlet_ctrl.assign(un, 0L);
533 normal_flow_limited.assign(un, false);
534 }
535
539 void resize_loads(int n_pollutants) {
540 stat_n_pollutants = n_pollutants;
541 if (n_pollutants > 0) {
542 auto total = static_cast<std::size_t>(count()) *
543 static_cast<std::size_t>(n_pollutants);
544 stat_total_load.assign(total, 0.0);
545 }
546 }
547
548 void save_state() noexcept {
549 old_flow = flow;
552 }
553
554 void reset_state() noexcept {
555 std::fill(flow.begin(), flow.end(), 0.0);
556 std::fill(depth.begin(), depth.end(), 0.0);
557 std::fill(volume.begin(), volume.end(), 0.0);
558 std::fill(froude.begin(), froude.end(), 0.0);
559 std::fill(flow_class.begin(), flow_class.end(), FlowClass::DRY);
560 std::fill(old_flow.begin(), old_flow.end(), 0.0);
561 std::fill(old_depth.begin(), old_depth.end(), 0.0);
562 std::fill(old_volume.begin(), old_volume.end(), 0.0);
563 }
564};
565
566} /* namespace openswmm */
567
568#endif /* OPENSWMM_ENGINE_LINK_DATA_HPP */
Definition Controls.cpp:24
LinkType
Link type codes.
Definition LinkData.hpp:40
FlowClass
Link flow state.
Definition LinkData.hpp:82
XsectShape
Conduit cross-section shape code.
Definition LinkData.hpp:52
@ FORCE_MAIN
Circular force main (Hazen-Williams or D-W)
@ STREET_XSECT
Street cross-section.
@ IRREGULAR
User-supplied shape curve.
@ CUSTOM
Shape from CURVE_SHAPE table.
@ RECT_ROUND
Rectangular-round bottom.
@ DUMMY
Dummy (no geometry)
@ RECT_TRIANG
Rectangular-triangular bottom.