38#ifndef OPENSWMM_ENGINE_NODE_SUBTYPES_HPP
39#define OPENSWMM_ENGINE_NODE_SUBTYPES_HPP
68 std::vector<double>
a;
70 std::vector<double>
b;
72 std::vector<double>
c;
89 int count() const noexcept {
return static_cast<int>(
node_idx.size()); }
94 a.clear();
b.clear();
c.clear();
101 const auto un =
static_cast<std::size_t
>(n);
103 a.reserve(un);
b.reserve(un);
c.reserve(un);
113 const auto p =
static_cast<std::ptrdiff_t
>(
118 a.insert(
a.begin() + p, 0.0);
119 b.insert(
b.begin() + p, 0.0);
120 c.insert(
c.begin() + p, 0.0);
128 return static_cast<int>(p);
133 const auto p =
static_cast<std::ptrdiff_t
>(r);
137 a.erase(
a.begin() + p);
138 b.erase(
b.begin() + p);
139 c.erase(
c.begin() + p);
193 const auto un =
static_cast<std::size_t
>(n);
203 const auto p =
static_cast<std::ptrdiff_t
>(
214 return static_cast<int>(p);
219 const auto p =
static_cast<std::ptrdiff_t
>(r);
249 std::vector<double>
cd;
273 const auto un =
static_cast<std::size_t
>(n);
282 const auto p =
static_cast<std::ptrdiff_t
>(
287 cd.insert(
cd.begin() + p, 0.0);
293 return static_cast<int>(p);
298 const auto p =
static_cast<std::ptrdiff_t
>(r);
302 cd.erase(
cd.begin() + p);
350 subtype_row.assign(
static_cast<std::size_t
>(n_nodes), -1);
351 for (
int r = 0; r <
storages.count(); ++r)
353 for (
int r = 0; r <
outfalls.count(); ++r)
355 for (
int r = 0; r <
dividers.count(); ++r)
373 const auto ui =
static_cast<std::size_t
>(i);
375 subtype_row.resize(
static_cast<std::size_t
>(i) + 1, -1);
379 if (old == t && existing >= 0)
382 bool shifted =
false;
398 if (row !=
storages.count() - 1) shifted =
true;
break;
400 if (row !=
outfalls.count() - 1) shifted =
true;
break;
402 if (row !=
dividers.count() - 1) shifted =
true;
break;
422 auto drop = [i](
auto& tbl) ->
bool {
423 for (
int r = 0; r < tbl.count(); ++r)
424 if (tbl.node_idx[
static_cast<std::size_t
>(r)] == i) { tbl.erase_at(r);
return true; }
429 auto shift = [i](std::vector<int>& keys) {
430 for (
auto& k : keys)
if (k > i) --k;
442 if (i >= 0 && i <
static_cast<int>(
subtype_row.size())) {
443 const int r =
subtype_row[
static_cast<std::size_t
>(i)];
444 if (r >= 0 && r <
storages.count() &&
445 storages.node_idx[
static_cast<std::size_t
>(r)] == i)
454 if (i >= 0 && i <
static_cast<int>(
subtype_row.size())) {
455 const int r =
subtype_row[
static_cast<std::size_t
>(i)];
456 if (r >= 0 && r <
outfalls.count() &&
457 outfalls.node_idx[
static_cast<std::size_t
>(r)] == i)
466 if (i >= 0 && i <
static_cast<int>(
subtype_row.size())) {
467 const int r =
subtype_row[
static_cast<std::size_t
>(i)];
468 if (r >= 0 && r <
dividers.count() &&
469 dividers.node_idx[
static_cast<std::size_t
>(r)] == i)
Structure-of-Arrays (SoA) storage for all node types.
Definition NodeCoupling.cpp:15
@ FREE
Definition NodeData.hpp:55
NodeType
Node type codes.
Definition NodeData.hpp:43
@ JUNCTION
Definition NodeData.hpp:44
@ DIVIDER
Definition NodeData.hpp:46
@ STORAGE
Definition NodeData.hpp:47
@ OUTFALL
Definition NodeData.hpp:45
@ CUTOFF
Definition NodeData.hpp:67
Dense SoA for flow-divider properties (one row per DIVIDER node).
Definition NodeSubtypes.hpp:240
std::vector< double > cd
Weir discharge coefficient for WEIR dividers.
Definition NodeSubtypes.hpp:249
std::vector< std::string > link_name
Diversion link name (deferred resolution).
Definition NodeSubtypes.hpp:257
std::vector< int > curve
Diversion curve index for TABULAR dividers (-1 = none).
Definition NodeSubtypes.hpp:253
std::vector< double > cutoff
Cutoff flow for CUTOFF dividers.
Definition NodeSubtypes.hpp:247
void clear() noexcept
Drop all rows (capacity retained).
Definition NodeSubtypes.hpp:265
std::vector< DividerType > method
Diversion method (CUTOFF/OVERFLOW/TABULAR/WEIR).
Definition NodeSubtypes.hpp:245
int count() const noexcept
Number of divider rows.
Definition NodeSubtypes.hpp:262
int add_default(int i)
Insert a default divider row for base node i, keeping node_idx ascending; returns the inserted row in...
Definition NodeSubtypes.hpp:281
std::vector< double > max_depth
Weir max depth for WEIR dividers.
Definition NodeSubtypes.hpp:251
void reserve(int n)
Reserve capacity for n rows.
Definition NodeSubtypes.hpp:272
std::vector< int > link
Diversion link index (-1 = not set).
Definition NodeSubtypes.hpp:255
std::vector< std::string > curve_name
Diversion curve name (deferred resolution, TABULAR only).
Definition NodeSubtypes.hpp:259
void erase_at(int r)
Erase divider row r from every column.
Definition NodeSubtypes.hpp:297
std::vector< int > node_idx
Base NodeData index this row belongs to (the join key).
Definition NodeSubtypes.hpp:242
Structure-of-Arrays storage for all nodes.
Definition NodeData.hpp:90
int count() const noexcept
Number of nodes.
Definition NodeData.hpp:537
std::vector< NodeType > type
Node type for each node.
Definition NodeData.hpp:97
Owns the three node subtype side-tables plus the reverse index map.
Definition NodeSubtypes.hpp:323
int divider_row(int i) const noexcept
Divider side-table row for base node i, or -1 if not a divider (or the side-table is unbuilt)....
Definition NodeSubtypes.hpp:465
DividerData dividers
Definition NodeSubtypes.hpp:326
int storage_row(int i) const noexcept
Storage side-table row for base node i, or -1 if i is not a storage node (or the side-table is unbuil...
Definition NodeSubtypes.hpp:441
int set_node_type(NodeData &nodes, int i, NodeType t)
Set node i to t, creating/removing/moving its subtype row so the side-table stays the single source o...
Definition NodeSubtypes.hpp:372
void erase_node(int i, int n_after)
Drop node i's subtype row and renumber the join keys after a base node erase. Call after NodeData::er...
Definition NodeSubtypes.hpp:420
void rebuild_index(int n_nodes)
Recompute the reverse map (subtype_row) from the side-table rows.
Definition NodeSubtypes.hpp:349
void clear() noexcept
Drop all rows and the reverse map.
Definition NodeSubtypes.hpp:332
OutfallData outfalls
Definition NodeSubtypes.hpp:325
std::vector< int > subtype_row
base node index → row in its subtype table (-1 for junctions).
Definition NodeSubtypes.hpp:329
int outfall_row(int i) const noexcept
Outfall side-table row for base node i, or -1 if not an outfall (or the side-table is unbuilt)....
Definition NodeSubtypes.hpp:453
StorageData storages
Definition NodeSubtypes.hpp:324
Dense SoA for outfall boundary-condition properties (one row per OUTFALL).
Definition NodeSubtypes.hpp:158
std::vector< OutfallType > bc_type
Boundary condition type (FREE/NORMAL/FIXED/TIDAL/TIMESERIES).
Definition NodeSubtypes.hpp:163
void erase_at(int r)
Erase outfall row r from every column.
Definition NodeSubtypes.hpp:218
std::vector< int > link_idx
Cached connected-conduit index (-1 = none).
Definition NodeSubtypes.hpp:171
std::vector< uint8_t > has_flap_gate
Flap gate present (0/1).
Definition NodeSubtypes.hpp:167
void reserve(int n)
Reserve capacity for n rows.
Definition NodeSubtypes.hpp:192
std::vector< int > route_to
Subcatchment index to route discharge to (-1 = none).
Definition NodeSubtypes.hpp:169
int count() const noexcept
Number of outfall rows.
Definition NodeSubtypes.hpp:181
void clear() noexcept
Drop all rows (capacity retained).
Definition NodeSubtypes.hpp:184
std::vector< double > ramp_2d
Cached wet/dry ramp factor [0,1] for the 2D tailwater override (0 = dry → free discharge,...
Definition NodeSubtypes.hpp:178
int add_default(int i)
Insert a default outfall row for base node i, keeping node_idx ascending; returns the inserted row in...
Definition NodeSubtypes.hpp:202
std::vector< double > param
Fixed stage, or tidal/timeseries table index (per bc_type).
Definition NodeSubtypes.hpp:165
std::vector< double > head_2d
Cached 2D surface head at the coupling point (sentinel -1e30).
Definition NodeSubtypes.hpp:175
std::vector< double > link_offset
Conduit offset at the outfall end.
Definition NodeSubtypes.hpp:173
std::vector< int > node_idx
Base NodeData index this row belongs to (the join key).
Definition NodeSubtypes.hpp:160
Dense SoA for storage-unit properties (one row per STORAGE node).
Definition NodeSubtypes.hpp:59
void clear() noexcept
Drop all rows (capacity retained).
Definition NodeSubtypes.hpp:92
int add_default(int i)
Insert a default storage row for base node i, keeping node_idx ascending; returns the inserted row in...
Definition NodeSubtypes.hpp:112
int count() const noexcept
Number of storage rows.
Definition NodeSubtypes.hpp:89
void reserve(int n)
Reserve capacity for n rows.
Definition NodeSubtypes.hpp:100
std::vector< double > exfil_imd
Green-Ampt initial moisture deficit for exfiltration (0-1).
Definition NodeSubtypes.hpp:86
std::vector< double > evap_frac
Fraction of potential evaporation realized (0-1).
Definition NodeSubtypes.hpp:76
std::vector< double > exfil_suction
Green-Ampt suction head for exfiltration.
Definition NodeSubtypes.hpp:82
std::vector< double > a
Functional area parameter A.
Definition NodeSubtypes.hpp:68
std::vector< double > b
Functional area parameter B.
Definition NodeSubtypes.hpp:70
std::vector< double > seep_rate
Seepage rate (project units/day).
Definition NodeSubtypes.hpp:74
std::vector< int > node_idx
Base NodeData index this row belongs to (the join key).
Definition NodeSubtypes.hpp:61
std::vector< int > curve
Storage curve index into TableData (-1 = functional A·d^B + C).
Definition NodeSubtypes.hpp:64
std::vector< double > exfil_ksat
Green-Ampt saturated conductivity for exfiltration.
Definition NodeSubtypes.hpp:84
std::vector< double > c
Functional area parameter C (baseline area).
Definition NodeSubtypes.hpp:72
std::vector< std::string > curve_name
Curve name for deferred resolution.
Definition NodeSubtypes.hpp:66
std::vector< double > evap_loss
Evaporation loss this timestep (ft3).
Definition NodeSubtypes.hpp:78
std::vector< double > exfil_loss
Exfiltration loss this timestep (ft3).
Definition NodeSubtypes.hpp:80
void erase_at(int r)
Erase storage row r from every column.
Definition NodeSubtypes.hpp:132