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
59
60namespace hydstruct {
61
62// ============================================================================
63// Constants
64// ============================================================================
65
66constexpr double GRAVITY = 32.2;
67constexpr double FUDGE = 0.0001;
68
69// ============================================================================
70// Flap gates
71// ============================================================================
72
95bool flapGateBlocks(const SimulationContext& ctx, int j, int n1, int n2, double q);
96
97// ============================================================================
98// Per-type SoA groups (like XSectGroups but for structure types)
99// ============================================================================
100
101struct PumpGroup {
102 int count = 0;
103 std::vector<int> link_idx;
104 std::vector<int> curve_idx;
105 std::vector<int> curve_type;
106 std::vector<double> speed;
107 std::vector<double> y_on;
108 std::vector<double> y_off;
109 void resize(int n);
110};
111
113 int count = 0;
114 std::vector<int> link_idx;
115 std::vector<int> shape;
116 // No cached cOrif/cWeir/hCrit: legacy orifice_setSetting recomputes them
117 // from the CURRENT setting every step, so computeOrificeFlowK derives
118 // them inline per call (see the legacy-exact block there) — an init-time
119 // snapshot at full opening could only ever go stale.
120 // No cached flap-gate flag: the kernels read ctx.links.has_flap_gate (and
121 // flapGateBlocks) directly, so a stale init-time snapshot cannot diverge.
124 std::vector<double> surf_area;
128 std::vector<double> length_eff;
129 void resize(int n);
130};
131
132struct WeirGroup {
133 int count = 0;
134 std::vector<int> link_idx;
135 std::vector<int> weir_type;
136 std::vector<double> c_disch1;
137 std::vector<double> c_disch2;
138 std::vector<double> end_con;
139 std::vector<double> slope;
140 std::vector<int> cd_curve;
141 // No cached flap-gate flag — see the note on OrificeGroup.
145 std::vector<double> surf_area;
149 std::vector<double> length_eff;
153 std::vector<uint8_t> can_surcharge;
154 void resize(int n);
155};
156
158 int count = 0;
159 std::vector<int> link_idx;
160 std::vector<int> curve_idx;
161 std::vector<double> q_coeff;
162 std::vector<double> q_expon;
163 void resize(int n);
164};
165
166// ============================================================================
167// Structure flow solver
168// ============================================================================
169
171public:
172 void init(SimulationContext& ctx);
173
192 void computeAllFlows(SimulationContext& ctx, double dt,
193 double* node_new_surf_area = nullptr);
194
199
201 const std::vector<int>& nonConduitIndices() const noexcept { return nc_indices_; }
202
211 void computeNonConduitFlowOne(SimulationContext& ctx, double dt,
212 double* node_new_surf_area, int link_idx);
213
219 double* node_new_surf_area, int link_idx);
220
221private:
222 PumpGroup pumps_;
223 OrificeGroup orifices_;
224 WeirGroup weirs_;
225 OutletGroup outlets_;
226 std::vector<int> nc_indices_;
227 std::vector<int> nc_group_k_;
228
231 void computePumpFlows(SimulationContext& ctx, double dt,
232 const double* node_new_surf_area);
233
234 // Per-element bodies of the batch loops (k = row in the type group).
235 void computePumpFlowK(SimulationContext& ctx, double dt,
236 const double* node_new_surf_area, int k);
237 void computeOrificeFlowK(SimulationContext& ctx,
238 double* node_new_surf_area, int k);
239 void computeWeirFlowK(SimulationContext& ctx,
240 double* node_new_surf_area, int k);
241 void computeOutletFlowK(SimulationContext& ctx, int k);
242 void scatterOrificeSurfArea(SimulationContext& ctx,
243 double* node_new_surf_area,
244 std::size_t uk, std::size_t uj,
245 std::size_t un1, std::size_t un2);
246
252 void computeOrificeFlows(SimulationContext& ctx,
253 double* node_new_surf_area = nullptr);
254
259 void computeWeirFlows(SimulationContext& ctx,
260 double* node_new_surf_area = nullptr);
261
263 void computeOutletFlows(SimulationContext& ctx);
264};
265
266} // namespace hydstruct
267} // namespace openswmm
268
269#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:170
void computeNonConduitFlowOne(SimulationContext &ctx, double dt, double *node_new_surf_area, int link_idx)
Compute flow for ONE non-conduit link (per-link sequential path). PARITY: legacy findLinkFlows (dynwa...
Definition HydStructures.cpp:1204
void computeAllFlows(SimulationContext &ctx, double dt, double *node_new_surf_area=nullptr)
Compute flow for all non-conduit links (batch by type).
Definition HydStructures.cpp:1188
const std::vector< int > & nonConduitIndices() const noexcept
Get pre-built list of all non-conduit link indices.
Definition HydStructures.hpp:201
void scatterHeldSurfArea(SimulationContext &ctx, double *node_new_surf_area, int link_idx)
Scatter the HELD surface area of a bypassed non-conduit link (legacy updateNodeFlows runs for bypasse...
Definition HydStructures.cpp:1262
void updatePumpTargetSettings(SimulationContext &ctx)
Evaluate pump startup/shutoff depth hysteresis. Must be called ONCE per timestep BEFORE the DW iterat...
Definition HydStructures.cpp:259
void init(SimulationContext &ctx)
Definition HydStructures.cpp:92
Definition HydStructures.cpp:46
constexpr double FUDGE
Definition HydStructures.hpp:67
bool flapGateBlocks(const SimulationContext &ctx, int j, int n1, int n2, double q)
Is flow through link j blocked by a flap gate?
Definition HydStructures.cpp:67
constexpr double GRAVITY
Definition HydStructures.hpp:66
Definition NodeCoupling.cpp:16
Central, reentrant simulation context.
Definition SimulationContext.hpp:353
Definition HydStructures.hpp:112
std::vector< double > surf_area
Definition HydStructures.hpp:124
std::vector< int > shape
BOTTOM or SIDE.
Definition HydStructures.hpp:115
std::vector< double > length_eff
Definition HydStructures.hpp:128
int count
Definition HydStructures.hpp:113
void resize(int n)
Definition HydStructures.cpp:88
std::vector< int > link_idx
Definition HydStructures.hpp:114
Definition HydStructures.hpp:157
void resize(int n)
Definition HydStructures.cpp:90
std::vector< int > link_idx
Definition HydStructures.hpp:159
int count
Definition HydStructures.hpp:158
std::vector< int > curve_idx
Rating curve (-1 = power law)
Definition HydStructures.hpp:160
std::vector< double > q_expon
Power law exponent.
Definition HydStructures.hpp:162
std::vector< double > q_coeff
Power law coefficient.
Definition HydStructures.hpp:161
Definition HydStructures.hpp:101
int count
Definition HydStructures.hpp:102
std::vector< int > curve_type
Pump type (1-5, 6=ideal)
Definition HydStructures.hpp:105
std::vector< int > curve_idx
Pump curve table index.
Definition HydStructures.hpp:104
std::vector< int > link_idx
Global link index.
Definition HydStructures.hpp:103
std::vector< double > speed
Current speed setting [0-1].
Definition HydStructures.hpp:106
std::vector< double > y_on
Startup depth.
Definition HydStructures.hpp:107
void resize(int n)
Definition HydStructures.cpp:87
std::vector< double > y_off
Shutoff depth.
Definition HydStructures.hpp:108
Definition HydStructures.hpp:132
std::vector< int > cd_curve
Optional Cd(head) curve index.
Definition HydStructures.hpp:140
std::vector< double > slope
V-notch slope or trap slope.
Definition HydStructures.hpp:139
std::vector< double > end_con
End contraction factor.
Definition HydStructures.hpp:138
std::vector< double > length_eff
Definition HydStructures.hpp:149
std::vector< uint8_t > can_surcharge
Definition HydStructures.hpp:153
std::vector< double > surf_area
Definition HydStructures.hpp:145
void resize(int n)
Definition HydStructures.cpp:89
std::vector< double > c_disch2
End section coefficient (trapezoidal)
Definition HydStructures.hpp:137
std::vector< int > link_idx
Definition HydStructures.hpp:134
std::vector< int > weir_type
TRANSVERSE/SIDE/VNOTCH/TRAPEZOIDAL.
Definition HydStructures.hpp:135
std::vector< double > c_disch1
Main discharge coefficient.
Definition HydStructures.hpp:136
int count
Definition HydStructures.hpp:133