40#ifndef OPENSWMM_ENGINE_LINK_DATA_HPP
41#define OPENSWMM_ENGINE_LINK_DATA_HPP
156 std::vector<double>
q0;
606 double edge = 0.5 * rs;
627 const auto u =
static_cast<std::size_t
>(j);
646 int count() const noexcept {
return static_cast<int>(
type.size()); }
661 const auto un =
static_cast<std::size_t
>(n);
664 node1.assign(un, -1);
665 node2.assign(un, -1);
695 dqdh.assign(un, 0.0);
698 flow.assign(un, 0.0);
700 depth.assign(un, 0.0);
715 tags.assign(un, std::string{});
765 const auto un =
static_cast<std::size_t
>(n);
766 auto g = [&](
auto& vec,
auto def) { vec.resize(un, def); };
815 tags.resize(un, std::string{});
879 const auto un =
static_cast<std::size_t
>(n);
880 if (
type.capacity() >= un)
882 auto r = [&](
auto& vec) { vec.reserve(un); };
974 const auto ui =
static_cast<std::size_t
>(idx);
975 auto e = [&](
auto& v) {
977 v.erase(v.begin() +
static_cast<std::ptrdiff_t
>(idx));
1060 const auto base = ui *
static_cast<std::size_t
>(
N_LSTEP_BINS);
1061 const auto end = base +
static_cast<std::size_t
>(
N_LSTEP_BINS);
1071 const auto end = base +
static_cast<std::size_t
>(
N_FLOW_CLASSES);
1080 const auto base = ui * np;
1081 auto erase2d = [&](
auto& v) {
1082 if (base + np <= v.size())
1083 v.erase(v.begin() +
static_cast<std::ptrdiff_t
>(base),
1084 v.begin() +
static_cast<std::ptrdiff_t
>(base + np));
1093 const auto base = ui * np;
1097 static_cast<std::ptrdiff_t
>(base + np));
1112 if (n_pollutants > 0) {
1113 auto total =
static_cast<std::size_t
>(
count()) *
static_cast<std::size_t
>(n_pollutants);
1130 if (n_pollutants > 0) {
1131 auto total =
static_cast<std::size_t
>(
count()) *
static_cast<std::size_t
>(n_pollutants);
1132 conc.assign(total, 0.0);
1141 type.shrink_to_fit();
1142 node1.shrink_to_fit();
1143 node2.shrink_to_fit();
1168 dqdh.shrink_to_fit();
1171 flow.shrink_to_fit();
1173 depth.shrink_to_fit();
1181 conc.shrink_to_fit();
1185 tags.shrink_to_fit();
1249 std::fill(
flow.begin(),
flow.end(), 0.0);
1258 std::fill(
conc.begin(),
conc.end(), 0.0);
Definition ExchangeLaw.hpp:60
LinkType
Link type codes.
Definition LinkData.hpp:58
@ CONDUIT
Definition LinkData.hpp:58
@ PUMP
Definition LinkData.hpp:58
@ WEIR
Definition LinkData.hpp:58
@ ORIFICE
Definition LinkData.hpp:58
@ OUTLET
Definition LinkData.hpp:58
FlowClass
Link flow state.
Definition LinkData.hpp:97
@ SUPERCRITICAL
Definition LinkData.hpp:102
@ DN_CRITICAL
Definition LinkData.hpp:104
@ SUBCRITICAL
Definition LinkData.hpp:101
@ UP_CRITICAL
Definition LinkData.hpp:103
@ DRY
Definition LinkData.hpp:98
@ UP_DRY
Definition LinkData.hpp:99
@ DN_DRY
Definition LinkData.hpp:100
XsectShape
Conduit cross-section shape code.
Definition LinkData.hpp:64
@ TRIANGULAR
Definition LinkData.hpp:70
@ RECT_CLOSED
Definition LinkData.hpp:67
@ ARCH
Arch pipe.
Definition LinkData.hpp:85
@ FORCE_MAIN
Circular force main (Hazen-Williams or D-W)
Definition LinkData.hpp:88
@ RECT_OPEN
Definition LinkData.hpp:68
@ BASKETHANDLE
Definition LinkData.hpp:79
@ STREET_XSECT
Street cross-section.
Definition LinkData.hpp:89
@ SEMICIRCULAR
Definition LinkData.hpp:80
@ IRREGULAR
User-supplied shape curve.
Definition LinkData.hpp:86
@ HORIZ_ELLIPSE
Horizontal elliptical pipe.
Definition LinkData.hpp:83
@ VERT_ELLIPSE
Vertical elliptical pipe.
Definition LinkData.hpp:84
@ CUSTOM
Shape from CURVE_SHAPE table.
Definition LinkData.hpp:87
@ RECT_ROUND
Rectangular-round bottom.
Definition LinkData.hpp:82
@ EGGSHAPED
Definition LinkData.hpp:74
@ SEMIELLIPTICAL
Definition LinkData.hpp:78
@ CATENARY
Definition LinkData.hpp:77
@ CIRCULAR
Definition LinkData.hpp:65
@ TRAPEZOIDAL
Definition LinkData.hpp:69
@ MODBASKETHANDLE
Definition LinkData.hpp:73
@ HORSESHOE
Definition LinkData.hpp:75
@ DUMMY
Dummy (no geometry)
Definition LinkData.hpp:90
@ PARABOLIC
Definition LinkData.hpp:71
@ POWER
Definition LinkData.hpp:72
@ RECT_TRIANG
Rectangular-triangular bottom.
Definition LinkData.hpp:81
@ FILLED_CIRCULAR
Definition LinkData.hpp:66
@ GOTHIC
Definition LinkData.hpp:76
Structure-of-Arrays storage for all links.
Definition LinkData.hpp:119
void resize(int n)
Replace the base link store with a requested row count.
Definition LinkData.hpp:660
std::vector< double > stat_time_full_upstream
Definition LinkData.hpp:501
void save_qual_state() noexcept
Legacy link_setOldQualState — every routing step.
Definition LinkData.hpp:1238
std::vector< double > stat_vol_flow
Total volume conveyed by this link (project volume units).
Definition LinkData.hpp:458
std::vector< int > stat_pump_cycles
Number of pump on→off + off→on transitions per pump.
Definition LinkData.hpp:529
int stat_n_pollutants
Definition LinkData.hpp:522
std::vector< double > dqdh
Derivative dQ/dH for inlet-controlled culvert flow.
Definition LinkData.hpp:321
std::vector< double > stat_total_load
Cumulative pollutant loads transported through each link.
Definition LinkData.hpp:521
std::vector< double > old_volume
Volume at the previous timestep.
Definition LinkData.hpp:404
std::vector< double > time_last_set
Absolute date (decimal days) when target_setting last crossed an open<->closed boundary....
Definition LinkData.hpp:286
std::vector< double > xsect_geom1
Raw [XSECTIONS] geometry parameters as supplied (display units), retained purely for lossless seriali...
Definition LinkData.hpp:195
std::vector< double > stat_time_slot_above
Time (s) the instantaneous slot share exceeded 1 %.
Definition LinkData.hpp:377
std::vector< double > old_depth
Depth at the previous timestep.
Definition LinkData.hpp:401
std::vector< long > stat_conv_steps
DW steps with both end nodes converged.
Definition LinkData.hpp:591
std::vector< char > rpt_flag
Whether this link is included in report/output (0=no, 1=yes).
Definition LinkData.hpp:448
std::vector< double > stat_vol_dt
∫ volume dt over the run (ft³·s) — the share denominator.
Definition LinkData.hpp:373
void reset_state() noexcept
Clear the link dynamic arrays visited here for a cold start.
Definition LinkData.hpp:1248
std::vector< double > froude
Current froude number (absolute).
Definition LinkData.hpp:383
std::vector< double > flow
Current flow rate (project flow units, +ve = node1→node2).
Definition LinkData.hpp:338
std::vector< double > xsect_geom4
Definition LinkData.hpp:198
std::vector< double > xsect_s_full
Full-pipe section factor.
Definition LinkData.hpp:220
std::vector< double > xsect_r_bot
Multi-purpose shape param: wall length (RECT_TRIANG), wetted perimeter (FILLED_CIRCULAR).
Definition LinkData.hpp:251
std::vector< int > node1
Upstream node index.
Definition LinkData.hpp:132
std::vector< double > stat_time_surcharged
Total duration of surcharge (seconds).
Definition LinkData.hpp:482
std::vector< std::string > comments
Object comment from the INP file (';'-prefixed lines immediately above this link's data row),...
Definition LinkData.hpp:432
std::vector< XsectShape > xsect_shape
Cross-section shape.
Definition LinkData.hpp:169
int count() const noexcept
Count link rows from the type column.
Definition LinkData.hpp:646
std::vector< double > stat_lstep_bin_time
Flat 2D [link * N_LSTEP_BINS + bin], duration.
Definition LinkData.hpp:590
std::vector< double > stat_max_filling
Maximum reported filling ratio (depth / full depth).
Definition LinkData.hpp:476
std::vector< double > stat_pump_on_time
Time pump was running (seconds).
Definition LinkData.hpp:532
std::vector< double > kw_inflow
Definition LinkData.hpp:342
std::vector< double > stat_lstep_max
Largest local step.
Definition LinkData.hpp:587
std::vector< double > q_limit
Maximum allowable flow rate (project flow units, 0 = unlimited).
Definition LinkData.hpp:162
void grow_to(int n)
Extend base link columns while preserving existing prefixes.
Definition LinkData.hpp:762
std::vector< int > stat_flow_turn_sign
Sign of previous flow change for flow-turn detection.
Definition LinkData.hpp:567
std::vector< long > stat_pump_periods
Count of active routing periods.
Definition LinkData.hpp:545
std::vector< FlowClass > flow_class
Current flow class (DRY, SUBCRITICAL, etc.).
Definition LinkData.hpp:386
std::vector< double > stat_max_flow
Maximum reported flow rate (project flow units).
Definition LinkData.hpp:464
void resize_quality(int n_pollutants)
Set the pollutant stride and replace positive-sized quality arrays.
Definition LinkData.hpp:1128
std::vector< double > q0
Initial flow rate (project flow units).
Definition LinkData.hpp:156
void save_state() noexcept
Snapshot both hydraulic and quality link state.
Definition LinkData.hpp:1220
std::vector< double > stat_time_full_both
Definition LinkData.hpp:509
std::vector< double > xsect_w_max
Full hydraulic width of cross-section.
Definition LinkData.hpp:178
std::vector< double > stat_time_capacity_limited
Definition LinkData.hpp:513
std::vector< double > stat_pump_sum_flow
Sum of active-period flows for legacy arithmetic mean (CFS).
Definition LinkData.hpp:544
std::vector< double > xsect_r_full
Full-pipe hydraulic radius.
Definition LinkData.hpp:214
void save_hyd_state() noexcept
Snapshot current link flow, depth and volume for a routed step.
Definition LinkData.hpp:1231
std::vector< double > xsect_a_bot
Bottom area for FILLED_CIRCULAR, RECT_TRIANG shapes.
Definition LinkData.hpp:238
std::vector< int > xsect_curve
Shape curve index (for IRREGULAR / CUSTOM shapes).
Definition LinkData.hpp:204
std::vector< double > xsect_yw_max
Depth at maximum width.
Definition LinkData.hpp:257
std::vector< double > xsect_geom2
Definition LinkData.hpp:196
std::vector< double > stat_inlet_ctrl
Seconds under inlet control (legacy timeInletControl)
Definition LinkData.hpp:493
std::vector< double > stat_max_veloc
Maximum reported flow velocity (project length/time units).
Definition LinkData.hpp:470
std::vector< double > stat_pump_off_curve_high
Active seconds above the pump curve range.
Definition LinkData.hpp:547
std::vector< double > stat_lstep_dt_time
Sum of step * duration.
Definition LinkData.hpp:588
std::vector< std::string > pump_curve_name
Pump curve name (for deferred resolution).
Definition LinkData.hpp:303
std::vector< double > stat_lstep_min
Smallest local step (0 = no sample)
Definition LinkData.hpp:586
std::vector< double > stat_pump_volume
Total volume pumped (ft³).
Definition LinkData.hpp:535
std::vector< double > xsect_geom3
Definition LinkData.hpp:197
void resize_loads(int n_pollutants)
Set the pollutant load stride and zero positive-sized load storage.
Definition LinkData.hpp:1110
std::vector< double > stat_pump_energy
Total pump energy consumed (kWh).
Definition LinkData.hpp:542
int conc_n_pollutants
Number of pollutants in the quality arrays.
Definition LinkData.hpp:421
std::vector< double > volume
Current full-flow volume (project volume units).
Definition LinkData.hpp:354
std::vector< LinkType > type
Link type.
Definition LinkData.hpp:126
static constexpr int N_LSTEP_BINS
Number of log2 step bins: (RS/2,RS], (RS/4,RS/2], ..., (0,RS/16].
Definition LinkData.hpp:584
std::vector< double > offset1
Link offset at upstream node (project length units above invert).
Definition LinkData.hpp:144
std::vector< double > offset2
Link offset at downstream node.
Definition LinkData.hpp:150
std::vector< double > conc
Current quality concentration in each link.
Definition LinkData.hpp:415
void reserve_to(int n)
Reserve capacity for n links without changing count().
Definition LinkData.hpp:876
std::vector< long > stat_conv_total
DW steps sampled for convergence.
Definition LinkData.hpp:592
std::vector< long > stat_flow_turns
Count of flow direction reversals per link.
Definition LinkData.hpp:559
std::vector< double > stat_lstep_time
Sum of duration.
Definition LinkData.hpp:589
std::vector< double > stat_time_full_dnstream
Definition LinkData.hpp:505
std::vector< double > conc_old
Previous-step quality in each link.
Definition LinkData.hpp:418
std::vector< double > target_setting
Target setting from control rules.
Definition LinkData.hpp:276
static int lstep_bin(double dt, double rs) noexcept
Classify a local routing duration into five relative log2 bins.
Definition LinkData.hpp:604
std::vector< double > xsect_s_bot
Multi-purpose shape param: side slope (RECT_TRIANG), C-factor (FORCE_MAIN), number of open sides (REC...
Definition LinkData.hpp:245
std::vector< uint8_t > has_flap_gate
Flap gate on this conduit (uint8_t: 0=no, 1=yes).
Definition LinkData.hpp:315
std::vector< double > stat_max_flow_date
Definition LinkData.hpp:497
std::vector< double > stat_peak_slot_share
Peak instantaneous slot share (slot_volume/volume, 0..1).
Definition LinkData.hpp:375
std::vector< double > slot_volume
Portion of volume held in the Preissmann slot (ft³).
Definition LinkData.hpp:363
std::vector< double > xsect_s_max
Maximum section factor (at depth of max conveyance).
Definition LinkData.hpp:226
std::vector< uint8_t > is_closed
True if the link is closed by a control rule (uint8_t: 0=no, 1=yes).
Definition LinkData.hpp:389
std::vector< int > node2
Downstream node index.
Definition LinkData.hpp:138
void shrink_to_fit()
Release excess vector capacity accumulated during parsing.
Definition LinkData.hpp:1140
void erase_at(int idx)
Erase one link row from the columns visited by this helper.
Definition LinkData.hpp:973
std::vector< double > xsect_a_full
Full-flow area of cross-section (sq project length units).
Definition LinkData.hpp:175
std::vector< int > direction
Flow direction: +1 = node1→node2, -1 = reversed.
Definition LinkData.hpp:292
std::vector< double > stat_pump_off_curve_low
Active seconds below the pump curve range.
Definition LinkData.hpp:546
std::vector< double > xsect_y_full
Full depth of cross-section (project length units).
Definition LinkData.hpp:172
std::vector< double > xsect_y_bot
Bottom depth for FILLED_CIRCULAR, RECT_TRIANG, RECT_ROUND shapes.
Definition LinkData.hpp:232
std::vector< std::string > tags
Per-object tag from the INP [TAGS] section.
Definition LinkData.hpp:440
static constexpr int N_FLOW_CLASSES
Per-link flow classification step counts.
Definition LinkData.hpp:490
void add_lstep_sample(int j, double dt, double dur, double rs) noexcept
Accumulate one link-local step sample weighted by simulated duration.
Definition LinkData.hpp:626
std::vector< int > xsect_batch_shape
Cached batch (XSectBatch) shape code, translated from XsectShape at init.
Definition LinkData.hpp:264
std::vector< double > stat_flow_class
Seconds in each flow class (legacy timeInFlowClass)
Definition LinkData.hpp:491
std::vector< double > depth
Current water depth at midpoint (project length units).
Definition LinkData.hpp:348
std::vector< bool > stat_pump_was_on
Previous pump state for cycle detection (true = on).
Definition LinkData.hpp:550
std::vector< double > stat_slot_vol_dt
∫ slot_volume dt over the run (ft³·s).
Definition LinkData.hpp:371
std::vector< double > old_flow
Flow at the previous timestep.
Definition LinkData.hpp:398
std::vector< double > stat_time_courant_critical
CFL time-step critical count per link.
Definition LinkData.hpp:575
std::vector< double > stat_norm_ltd
Seconds normal-flow limited (legacy timeNormalFlow)
Definition LinkData.hpp:492
std::vector< double > setting
Current link setting (0-1 for pumps/orifices/weirs, 1.0 default for conduits).
Definition LinkData.hpp:270