55#ifndef OPENSWMM_ENGINE_LINK_SUBTYPES_HPP
56#define OPENSWMM_ENGINE_LINK_SUBTYPES_HPP
116 const auto un =
static_cast<std::size_t
>(n);
128 const auto p =
static_cast<std::ptrdiff_t
>(
150 return static_cast<int>(p);
154 const auto p =
static_cast<std::ptrdiff_t
>(r);
198 const auto un =
static_cast<std::size_t
>(n);
204 const auto p =
static_cast<std::ptrdiff_t
>(
212 return static_cast<int>(p);
216 const auto p =
static_cast<std::ptrdiff_t
>(r);
233 std::vector<double>
cd;
245 const auto un =
static_cast<std::size_t
>(n);
249 const auto p =
static_cast<std::ptrdiff_t
>(
253 cd.insert(
cd.begin() + p, 0.0);
255 return static_cast<int>(p);
258 const auto p =
static_cast<std::ptrdiff_t
>(r);
261 cd.erase(
cd.begin() + p);
273 std::vector<double>
cd;
287 const auto un =
static_cast<std::size_t
>(n);
293 const auto p =
static_cast<std::ptrdiff_t
>(
297 cd.insert(
cd.begin() + p, 0.0);
300 cd2.insert(
cd2.begin() + p, 0.0);
302 return static_cast<int>(p);
305 const auto p =
static_cast<std::ptrdiff_t
>(r);
308 cd.erase(
cd.begin() + p);
311 cd2.erase(
cd2.begin() + p);
337 const auto un =
static_cast<std::size_t
>(n);
342 const auto p =
static_cast<std::ptrdiff_t
>(
350 return static_cast<int>(p);
353 const auto p =
static_cast<std::ptrdiff_t
>(r);
392 const int n = L.
count();
393 for (
int i = 0; i < n; ++i) {
394 switch (L.
type[
static_cast<std::size_t
>(i)]) {
412 subtype_row.assign(
static_cast<std::size_t
>(n_links), -1);
413 auto idx = [&](
const std::vector<int>& keys) {
414 for (
int r = 0; r < static_cast<int>(keys.size()); ++r)
415 subtype_row[
static_cast<std::size_t
>(keys[
static_cast<std::size_t
>(r)])] = r;
425 const auto ui =
static_cast<std::size_t
>(i);
427 subtype_row.resize(
static_cast<std::size_t
>(i) + 1, -1);
431 if (old == t && existing >= 0)
434 bool shifted =
false;
451 if (row !=
conduits.count() - 1) shifted =
true;
break;
453 if (row !=
pumps.count() - 1) shifted =
true;
break;
455 if (row !=
orifices.count() - 1) shifted =
true;
break;
457 if (row !=
weirs.count() - 1) shifted =
true;
break;
459 if (row !=
outlets.count() - 1) shifted =
true;
break;
473 auto drop = [i](
auto& tbl) ->
bool {
474 for (
int r = 0; r < tbl.count(); ++r)
475 if (tbl.link_idx[
static_cast<std::size_t
>(r)] == i) { tbl.erase_at(r);
return true; }
480 auto shift = [i](std::vector<int>& keys) {
for (
auto& k : keys)
if (k > i) --k; };
495 int row_in(
int i,
const std::vector<int>& keys)
const noexcept {
496 if (i >= 0 && i <
static_cast<int>(
subtype_row.size())) {
497 const int r =
subtype_row[
static_cast<std::size_t
>(i)];
498 if (r >= 0 && r <
static_cast<int>(keys.size()) &&
499 keys[
static_cast<std::size_t
>(r)] == i)
Structure-of-Arrays (SoA) storage for all link types.
Definition NodeCoupling.cpp:16
LinkType
Link type codes.
Definition LinkData.hpp:58
@ CONDUIT
Definition LinkData.hpp:59
@ PUMP
Definition LinkData.hpp:60
@ WEIR
Definition LinkData.hpp:62
@ ORIFICE
Definition LinkData.hpp:61
@ OUTLET
Definition LinkData.hpp:63
Dense SoA for conduit-only properties (one row per CONDUIT link).
Definition LinkSubtypes.hpp:79
std::vector< int > link_idx
Base LinkData index (join key)
Definition LinkSubtypes.hpp:80
int add_default(int i)
Definition LinkSubtypes.hpp:127
void erase_at(int r)
Definition LinkSubtypes.hpp:153
void clear() noexcept
Definition LinkSubtypes.hpp:106
std::vector< double > evap_loss_rate
per-step evaporation loss
Definition LinkSubtypes.hpp:98
std::vector< double > beta
Definition LinkSubtypes.hpp:87
std::vector< double > roughness
Definition LinkSubtypes.hpp:82
std::vector< int > culvert_code
Definition LinkSubtypes.hpp:95
std::vector< double > rough_factor
Definition LinkSubtypes.hpp:88
std::vector< double > q_full
Definition LinkSubtypes.hpp:89
std::vector< double > mod_length
Definition LinkSubtypes.hpp:85
int count() const noexcept
Definition LinkSubtypes.hpp:104
std::vector< int8_t > full_state
per-step up/down full bitmask
Definition LinkSubtypes.hpp:102
std::vector< double > loss_outlet
Definition LinkSubtypes.hpp:92
std::vector< int > barrels
Definition LinkSubtypes.hpp:86
std::vector< double > loss_avg
Definition LinkSubtypes.hpp:93
std::vector< double > q_max
Definition LinkSubtypes.hpp:90
void reserve(int n)
Definition LinkSubtypes.hpp:115
std::vector< double > loss_inlet
Definition LinkSubtypes.hpp:91
std::vector< double > seep_loss_rate
per-step seepage loss
Definition LinkSubtypes.hpp:99
std::vector< uint8_t > normal_flow_limited
per-step flag (reset each step)
Definition LinkSubtypes.hpp:100
std::vector< double > slope
Definition LinkSubtypes.hpp:84
std::vector< double > length
Definition LinkSubtypes.hpp:83
std::vector< double > seep_rate
Definition LinkSubtypes.hpp:94
std::vector< uint8_t > inlet_control
per-step culvert inlet-control flag
Definition LinkSubtypes.hpp:101
Structure-of-Arrays storage for all links.
Definition LinkData.hpp:125
int count() const noexcept
Definition LinkData.hpp:578
std::vector< LinkType > type
Link type.
Definition LinkData.hpp:132
Owns the five link subtype side-tables plus the reverse index map.
Definition LinkSubtypes.hpp:373
WeirData weirs
Definition LinkSubtypes.hpp:377
int set_link_type(LinkData &links, int i, LinkType t)
Definition LinkSubtypes.hpp:424
OrificeData orifices
Definition LinkSubtypes.hpp:376
PumpData pumps
Definition LinkSubtypes.hpp:375
void clear() noexcept
Definition LinkSubtypes.hpp:405
int pump_row(int i) const noexcept
Definition LinkSubtypes.hpp:489
std::vector< int > subtype_row
base link index → row in its subtype table (-1 if unset).
Definition LinkSubtypes.hpp:381
void build_default_rows(const LinkData &L)
Create a fresh default subtype row for every link, keyed by links.type[i], and rebuild the reverse in...
Definition LinkSubtypes.hpp:390
OutletData outlets
Definition LinkSubtypes.hpp:378
int outlet_row(int i) const noexcept
Definition LinkSubtypes.hpp:492
ConduitData conduits
Definition LinkSubtypes.hpp:374
int conduit_row(int i) const noexcept
Definition LinkSubtypes.hpp:488
int weir_row(int i) const noexcept
Definition LinkSubtypes.hpp:491
int orifice_row(int i) const noexcept
Definition LinkSubtypes.hpp:490
void erase_link(int i, int n_after)
Definition LinkSubtypes.hpp:472
void rebuild_index(int n_links)
Recompute subtype_row from each table's link_idx (no row data touched).
Definition LinkSubtypes.hpp:411
Definition LinkSubtypes.hpp:230
void reserve(int n)
Definition LinkSubtypes.hpp:244
std::vector< double > orate
Definition LinkSubtypes.hpp:234
void erase_at(int r)
Definition LinkSubtypes.hpp:257
int count() const noexcept
Definition LinkSubtypes.hpp:239
std::vector< int > link_idx
Definition LinkSubtypes.hpp:231
std::vector< double > orifice_type
0 = BOTTOM, 1 = SIDE (legacy param1)
Definition LinkSubtypes.hpp:232
void clear() noexcept
Definition LinkSubtypes.hpp:241
int add_default(int i)
Definition LinkSubtypes.hpp:248
std::vector< double > cd
Discharge coefficient.
Definition LinkSubtypes.hpp:233
Definition LinkSubtypes.hpp:322
std::vector< double > crest_height
Offset/crest.
Definition LinkSubtypes.hpp:325
int count() const noexcept
Definition LinkSubtypes.hpp:330
std::vector< int > link_idx
Definition LinkSubtypes.hpp:323
void erase_at(int r)
Definition LinkSubtypes.hpp:352
void reserve(int n)
Definition LinkSubtypes.hpp:336
std::vector< double > expon
Functional C2 exponent (legacy param2)
Definition LinkSubtypes.hpp:327
std::vector< double > outlet_type
Rating type (legacy param1)
Definition LinkSubtypes.hpp:324
std::vector< double > coeff
Functional C1 (legacy cd)
Definition LinkSubtypes.hpp:326
void clear() noexcept
Definition LinkSubtypes.hpp:332
int add_default(int i)
Definition LinkSubtypes.hpp:341
std::vector< int > curve
TABULAR rating-curve index (legacy pump_curve reuse; -1 = functional)
Definition LinkSubtypes.hpp:328
Definition LinkSubtypes.hpp:182
void reserve(int n)
Definition LinkSubtypes.hpp:197
std::vector< int > curve_type
Pump curve type (1-5, 6=ideal; -1 unset)
Definition LinkSubtypes.hpp:188
std::vector< uint8_t > init_state
Initial on/off (was vector<bool>)
Definition LinkSubtypes.hpp:185
void erase_at(int r)
Definition LinkSubtypes.hpp:215
std::vector< double > shutoff
Shutoff depth.
Definition LinkSubtypes.hpp:187
std::vector< double > startup
Startup depth.
Definition LinkSubtypes.hpp:186
std::vector< int > link_idx
Definition LinkSubtypes.hpp:183
int add_default(int i)
Definition LinkSubtypes.hpp:203
int count() const noexcept
Definition LinkSubtypes.hpp:190
void clear() noexcept
Definition LinkSubtypes.hpp:192
std::vector< int > curve
Pump curve table index (-1 = ideal)
Definition LinkSubtypes.hpp:184
Definition LinkSubtypes.hpp:270
void reserve(int n)
Definition LinkSubtypes.hpp:286
void clear() noexcept
Definition LinkSubtypes.hpp:281
std::vector< double > crest_height
Definition LinkSubtypes.hpp:275
void erase_at(int r)
Definition LinkSubtypes.hpp:304
std::vector< double > cd2
End-section discharge coeff (legacy cDisch2)
Definition LinkSubtypes.hpp:276
std::vector< uint8_t > can_surcharge
Surcharge YES/NO (legacy Weir.canSurcharge, default YES)
Definition LinkSubtypes.hpp:277
std::vector< double > weir_type
TRANSVERSE/SIDEFLOW/V-NOTCH/TRAPEZOIDAL (legacy param1)
Definition LinkSubtypes.hpp:272
std::vector< double > cd
Discharge coefficient.
Definition LinkSubtypes.hpp:273
int add_default(int i)
Definition LinkSubtypes.hpp:292
std::vector< int > link_idx
Definition LinkSubtypes.hpp:271
std::vector< double > end_contractions
End contractions (legacy param2)
Definition LinkSubtypes.hpp:274
int count() const noexcept
Definition LinkSubtypes.hpp:279