OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
HydStructures.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2//
3// Copyright 2026 Caleb Buahin
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
47
48#ifndef OPENSWMM_HYD_STRUCTURES_HPP
49#define OPENSWMM_HYD_STRUCTURES_HPP
50
51#include "../data/LinkData.hpp"
52#include "../data/NodeData.hpp"
53#include "../data/TableData.hpp"
54#include <vector>
55
56namespace openswmm {
57
59class SWMMEngine;
60
61namespace hydstruct {
62
63// ============================================================================
64// Constants
65// ============================================================================
66
67constexpr double GRAVITY = 32.2;
68constexpr double FUDGE = 0.0001;
69
70// ============================================================================
71// Flap gates
72// ============================================================================
73
88bool flapGateBlocks(const SimulationContext& ctx, int j, int n1, int n2, double q);
89
90// ============================================================================
91// Per-type SoA groups (like XSectGroups but for structure types)
92// ============================================================================
93
94struct PumpGroup {
95 int count = 0;
96 std::vector<int> link_idx;
97 std::vector<int> curve_idx;
98 std::vector<int> curve_type;
99 std::vector<double> speed;
100 std::vector<double> y_on;
101 std::vector<double> y_off;
111 void resize(int n);
112};
113
115 int count = 0;
116 std::vector<int> link_idx;
117 std::vector<int> shape;
118 // No cached cOrif/cWeir/hCrit: legacy orifice_setSetting recomputes them
119 // from the CURRENT setting every step, so computeOrificeFlowK derives
120 // them inline per call (see the legacy-exact block there) — an init-time
121 // snapshot at full opening could only ever go stale.
122 // No cached flap-gate flag: the kernels read ctx.links.has_flap_gate (and
123 // flapGateBlocks) directly, so a stale init-time snapshot cannot diverge.
126 std::vector<double> surf_area;
130 std::vector<double> length_eff;
140 void resize(int n);
141};
142
143struct WeirGroup {
144 int count = 0;
145 std::vector<int> link_idx;
146 std::vector<int> weir_type;
147 std::vector<double> c_disch1;
148 std::vector<double> c_disch2;
149 std::vector<double> end_con;
150 std::vector<double> slope;
151 std::vector<int> cd_curve;
152 std::vector<double> road_width;
153 std::vector<int> road_surface;
154 // No cached flap-gate flag — see the note on OrificeGroup.
158 std::vector<double> surf_area;
162 std::vector<double> length_eff;
166 std::vector<uint8_t> can_surcharge;
176 void resize(int n);
177};
178
180 int count = 0;
181 std::vector<int> link_idx;
182 std::vector<int> curve_idx;
183 std::vector<double> q_coeff;
184 std::vector<double> q_expon;
194 void resize(int n);
195};
196
197// ============================================================================
198// Structure flow solver
199// ============================================================================
200
202public:
215 void init(SimulationContext& ctx);
216
231 void computeAllFlows(SimulationContext& ctx, double dt, double* node_new_surf_area = nullptr);
232
244
246 const std::vector<int>& nonConduitIndices() const noexcept { return nc_indices_; }
247
264 void computeNonConduitFlowOne(SimulationContext& ctx, double dt, double* node_new_surf_area,
265 int link_idx);
266
279 void scatterHeldSurfArea(SimulationContext& ctx, double* node_new_surf_area, int link_idx);
280
281private:
283 PumpGroup pumps_;
284 OrificeGroup orifices_;
285 WeirGroup weirs_;
286 OutletGroup outlets_;
287 std::vector<int> nc_indices_;
288 std::vector<int> nc_group_k_;
289
302 void computePumpFlows(SimulationContext& ctx, double dt, const double* node_new_surf_area);
303
304 // Per-element bodies of the batch loops (k = row in the type group).
321 void computePumpFlowK(SimulationContext& ctx, double dt, const double* node_new_surf_area,
322 int k);
338 void computeOrificeFlowK(SimulationContext& ctx, double* node_new_surf_area, int k);
353 void computeWeirFlowK(SimulationContext& ctx, double* node_new_surf_area, int k);
366 void computeOutletFlowK(SimulationContext& ctx, int k);
380 void scatterOrificeSurfArea(SimulationContext& ctx, double* node_new_surf_area, std::size_t uk,
381 std::size_t uj, std::size_t un1, std::size_t un2);
382
394 void computeOrificeFlows(SimulationContext& ctx, double* node_new_surf_area = nullptr);
395
407 void computeWeirFlows(SimulationContext& ctx, double* node_new_surf_area = nullptr);
408
418 void computeOutletFlows(SimulationContext& ctx);
419};
420
421} // namespace hydstruct
422} // namespace openswmm
423
424#endif // OPENSWMM_HYD_STRUCTURES_HPP
Structure-of-Arrays (SoA) storage for all node types.
Time series and rating curve data with bidirectional cursor.
Definition HydStructures.hpp:201
void computeNonConduitFlowOne(SimulationContext &ctx, double dt, double *node_new_surf_area, int link_idx)
Evaluate one sequential nonconduit or DUMMY link using current node accumulators.
Definition HydStructures.cpp:1439
void computeAllFlows(SimulationContext &ctx, double dt, double *node_new_surf_area=nullptr)
Evaluate grouped pumps, orifices, weirs and outlets in type order.
Definition HydStructures.cpp:1419
const std::vector< int > & nonConduitIndices() const noexcept
Get pre-built list of all non-conduit link indices.
Definition HydStructures.hpp:246
void scatterHeldSurfArea(SimulationContext &ctx, double *node_new_surf_area, int link_idx)
Scatter a bypassed orifice's retained area using current flow classification.
Definition HydStructures.cpp:1499
void updatePumpTargetSettings(SimulationContext &ctx)
Apply pump startup/shutoff hysteresis once before step iterations.
Definition HydStructures.cpp:323
void init(SimulationContext &ctx)
Build per-type structure groups and global sequential-dispatch maps.
Definition HydStructures.cpp:143
friend class openswmm::SWMMEngine
Definition HydStructures.hpp:282
Definition HydStructures.cpp:48
constexpr double FUDGE
Definition HydStructures.hpp:68
bool flapGateBlocks(const SimulationContext &ctx, int j, int n1, int n2, double q)
Test reverse flow against the link gate and its donor outfall gate.
Definition HydStructures.cpp:78
constexpr double GRAVITY
Definition HydStructures.hpp:67
Definition ExchangeLaw.hpp:60
Central, reentrant simulation context.
Definition SimulationContext.hpp:390
Definition HydStructures.hpp:114
std::vector< double > surf_area
Definition HydStructures.hpp:126
std::vector< int > shape
BOTTOM or SIDE.
Definition HydStructures.hpp:117
std::vector< double > length_eff
Definition HydStructures.hpp:130
int count
Definition HydStructures.hpp:115
void resize(int n)
Resize OrificeGroup columns while preserving existing row prefixes.
Definition HydStructures.cpp:110
std::vector< int > link_idx
Definition HydStructures.hpp:116
Definition HydStructures.hpp:179
void resize(int n)
Resize OutletGroup columns while preserving existing row prefixes.
Definition HydStructures.cpp:134
std::vector< int > link_idx
Definition HydStructures.hpp:181
int count
Definition HydStructures.hpp:180
std::vector< int > curve_idx
Rating curve (-1 = power law)
Definition HydStructures.hpp:182
std::vector< double > q_expon
Power law exponent.
Definition HydStructures.hpp:184
std::vector< double > q_coeff
Power law coefficient.
Definition HydStructures.hpp:183
Definition HydStructures.hpp:94
int count
Definition HydStructures.hpp:95
std::vector< int > curve_type
Pump type (1-5, 6=ideal)
Definition HydStructures.hpp:98
std::vector< int > curve_idx
Pump curve table index.
Definition HydStructures.hpp:97
std::vector< int > link_idx
Global link index.
Definition HydStructures.hpp:96
std::vector< double > speed
Current speed setting [0-1].
Definition HydStructures.hpp:99
std::vector< double > y_on
Startup depth.
Definition HydStructures.hpp:100
void resize(int n)
Resize PumpGroup columns while preserving existing row prefixes.
Definition HydStructures.cpp:100
std::vector< double > y_off
Shutoff depth.
Definition HydStructures.hpp:101
Definition HydStructures.hpp:143
std::vector< int > cd_curve
Optional Cd(head) curve index (legacy Weir.cdCurve), -1 none.
Definition HydStructures.hpp:151
std::vector< double > slope
V-notch slope or trap slope.
Definition HydStructures.hpp:150
std::vector< double > end_con
End contraction factor.
Definition HydStructures.hpp:149
std::vector< double > length_eff
Definition HydStructures.hpp:162
std::vector< uint8_t > can_surcharge
Definition HydStructures.hpp:166
std::vector< double > surf_area
Definition HydStructures.hpp:158
void resize(int n)
Resize WeirGroup columns while preserving existing row prefixes.
Definition HydStructures.cpp:118
std::vector< double > road_width
ROADWAY weir road width (ft, legacy Weir.roadWidth)
Definition HydStructures.hpp:152
std::vector< int > road_surface
ROADWAY weir surface: 0 none, 1 PAVED, 2 GRAVEL.
Definition HydStructures.hpp:153
std::vector< double > c_disch2
End section coefficient (trapezoidal)
Definition HydStructures.hpp:148
std::vector< int > link_idx
Definition HydStructures.hpp:145
std::vector< int > weir_type
TRANSVERSE/SIDE/VNOTCH/TRAPEZOIDAL/ROADWAY (0..4)
Definition HydStructures.hpp:146
std::vector< double > c_disch1
Main discharge coefficient.
Definition HydStructures.hpp:147
int count
Definition HydStructures.hpp:144