OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
Inlet.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
46
47#ifndef OPENSWMM_INLET_HPP
48#define OPENSWMM_INLET_HPP
49
50#include <cstdint>
51#include <vector>
52
53namespace openswmm {
54
56struct XSectParams;
57struct Table;
58
59namespace inlet {
60
63enum class InletType : int {
64 GRATE = 0,
65 CURB = 1,
66 COMBO = 2,
71};
72
84
87enum class Placement : int { AUTOMATIC = 0, ON_GRADE = 1, ON_SAG = 2 };
88
90enum class ThroatAngle : int { HORIZONTAL = 0, INCLINED = 1, VERTICAL = 2 };
91
93enum class CurveKind : int { UNRESOLVED = 0, DIVERSION = 1, RATING = 2 };
94
96inline constexpr double MIN_RUNOFF_FLOW = 0.001;
98inline constexpr double INLET_FUDGE = 0.0001;
100inline constexpr double INLET_BIG = 1.0e10;
101
102// ============================================================================
103// Kernel inputs — the legacy module-level shared variables, made explicit
104// ============================================================================
105
115struct Geom {
116 double sx = 0.01;
117 double sl = 0.0;
118 double sw = 0.01;
119 double a = 0.0;
120 double w = 0.0;
121 double t = 0.0;
122 double n = 0.016;
123 int nsides = 1;
124 double t_crown = 100.0;
125 double beta = 0.0;
126 double qfactor = 0.0;
127
130 const XSectParams* xs = nullptr;
131};
132
134struct Design {
135 int type = 0;
136 int grate_type = static_cast<int>(GrateType::GENERIC);
137 double grate_length = 0.0;
138 double grate_width = 0.0;
139 double frac_open_area = 0.0;
140 double splash_veloc = 0.0;
141 double curb_length = 0.0;
142 double curb_height = 0.0;
143 int curb_throat = static_cast<int>(ThroatAngle::VERTICAL);
144 double slotted_length = 0.0;
145 double slotted_width = 0.0;
146};
147
150 int num_inlets = 1;
151 double clog_factor = 1.0;
152 double flow_limit = 0.0;
153};
154
155// ============================================================================
156// Pure kernel — 1:1 ports of the legacy static functions
157// ============================================================================
158
160double getEo(double sr, double ts, double w);
161
163double getFlowSpread(const Geom& g, double Q);
164
166double getGutterFlowRatio(const Geom& g, double w);
167
170double getGutterAreaRatio(const Geom& g, double grate_width, double area);
171
174double getSplashOverVelocity(int grate_type, double grate_length);
175
178double getGrateInletCapture(const Design& d, Geom& g, double Q);
179
181double getCurbInletCapture(const Geom& g, double Q, double opening_length);
182
184double getOnGradeInletCapture(const Design& d, Geom& g, double Q, double depth);
185
187double getOnGradeCapturedFlow(const Design& d, const UsageParams& u, Geom& g,
188 double q, double depth);
189
191void findOnSagGrateFlows(const Design& d, const Geom& g, double depth,
192 double* weir_flow, double* orifice_flow);
193
196void findOnSagCurbFlows(const Design& d, const Geom& g, double depth,
197 double opening_length,
198 double* weir_flow, double* orifice_flow);
199
201double getCurbOrificeFlow(double flow_depth, double opening_height,
202 double opening_length, int throat_angle);
203
205double getOnSagSlottedFlow(const Design& d, double depth);
206
208double getOnSagInletCapture(const Design& d, const Geom& g, double depth);
209
211double getOnSagCapturedFlow(const Design& d, const UsageParams& u,
212 const Geom& g, double depth);
213
223double getCustomCapturedFlow(const UsageParams& u, const Geom& g,
224 const Table& curve, int curve_kind,
225 double q, double depth,
226 double ucf_flow, double ucf_len);
227
229double getInletArea(const Design& d, const UsageParams& u);
230
231// ============================================================================
232// Runtime SoA
233// ============================================================================
234
235struct InletSoA {
236 int count = 0;
237
238 // --- host / topology -----------------------------------------------------
239 std::vector<int> link_idx;
240 std::vector<int> host_node;
241 std::vector<int> node_idx;
242 std::vector<int> bypass_node;
243 std::vector<int> up_link;
244 std::vector<int> up_link2;
245 std::vector<uint8_t> two_inbound;
246
247 // --- design --------------------------------------------------------------
248 std::vector<int> inlet_type;
249 std::vector<int> grate_type;
250 std::vector<double> grate_length;
251 std::vector<double> grate_width;
252 std::vector<double> open_area;
253 std::vector<double> splash_veloc;
254 std::vector<double> curb_length;
255 std::vector<double> curb_height;
256 std::vector<int> curb_throat;
257 std::vector<double> slotted_length;
258 std::vector<double> slotted_width;
259 std::vector<int> curve_index;
260 std::vector<int> curve_kind;
261
262 // --- usage ---------------------------------------------------------------
263 std::vector<int> num_inlets;
264 std::vector<double> clog_factor;
265 std::vector<double> flow_limit;
266 std::vector<double> local_depress;
267 std::vector<double> local_width;
268 std::vector<int> placement;
269 std::vector<uint8_t> is_sag;
270
271 // --- street / conduit geometry (internal units) --------------------------
272 std::vector<double> sx;
273 std::vector<double> gutter_depression;
274 std::vector<double> gutter_width;
275 std::vector<double> road_roughness;
276 std::vector<double> t_crown;
277 std::vector<int> n_sides;
278 std::vector<double> slope;
279 std::vector<double> flow_factor;
280
281 // --- per-step results ----------------------------------------------------
282 std::vector<double> q_approach;
283 std::vector<double> flow_capture;
284 std::vector<double> backflow;
285 std::vector<double> backflow_ratio;
286
287 // --- legacy statistics (inlet.c:78-87, updateInletStats :985) ------------
288 std::vector<int> flow_periods;
289 std::vector<int> capture_periods;
290 std::vector<int> backflow_periods;
291 std::vector<double> peak_flow;
292 std::vector<double> peak_flow_capture;
293 std::vector<double> avg_flow_capture;
294 std::vector<double> bypass_freq;
295
296 // --- volume statistics (Gap #68 → InletUsageStore) -----------------------
297 std::vector<double> stat_capture_vol;
298 std::vector<double> stat_bypass_vol;
299 std::vector<double> stat_backflow_vol;
300 std::vector<double> stat_peak_flow;
301
302 void resize(int n);
303};
304
306public:
308 void init(SimulationContext& ctx);
309
320 void computeAll(SimulationContext& ctx, double dt);
321
329 void adjustQualInflows(SimulationContext& ctx, double dt);
330
334 void gatherStats(SimulationContext& ctx) const;
335
336 const InletSoA& soa() const noexcept { return soa_; }
337 bool hasInlets() const noexcept { return soa_.count > 0; }
338
339private:
340 InletSoA soa_;
341
345 std::vector<double> node_inlet_flow_;
346 std::vector<double> node_inflow_;
347
349 Geom geomOf(const SimulationContext& ctx, int ii,
350 const XSectParams* xs) const;
352 Design designOf(int ii) const;
354 UsageParams usageOf(int ii) const;
355
357 void updateStats(int ii, double q);
358
361 void computeBackflowRatios();
362};
363
364} // namespace inlet
365} // namespace openswmm
366
367#endif // OPENSWMM_INLET_HPP
Definition Inlet.hpp:305
const InletSoA & soa() const noexcept
Definition Inlet.hpp:336
void adjustQualInflows(SimulationContext &ctx, double dt)
Adjust quality inflows at the bypass and capture nodes.
Definition Inlet.cpp:1145
void computeAll(SimulationContext &ctx, double dt)
Compute capture + backflow and fold them into nodes.lat_flow.
Definition Inlet.cpp:876
bool hasInlets() const noexcept
Definition Inlet.hpp:337
void init(SimulationContext &ctx)
Resolve designs, street geometry, host topology and placement.
Definition Inlet.cpp:641
void gatherStats(SimulationContext &ctx) const
Definition Inlet.cpp:1198
Definition Inlet.cpp:40
Placement
Definition Inlet.hpp:87
@ AUTOMATIC
Definition Inlet.hpp:87
@ ON_SAG
Definition Inlet.hpp:87
@ ON_GRADE
Definition Inlet.hpp:87
void findOnSagGrateFlows(const Design &d, const Geom &g, double depth, double *Qw, double *Qo)
On-sag grate weir/orifice flows, Eq(4-26)/(4-27) (inlet.c:1644).
Definition Inlet.cpp:392
double getInletArea(const Design &d, const UsageParams &u)
Unclogged open area of one usage (ft²) — legacy getInletArea (inlet.c:1870).
Definition Inlet.cpp:562
constexpr double INLET_FUDGE
Legacy FUDGE (consts.h:272).
Definition Inlet.hpp:98
double getOnSagInletCapture(const Design &d, const Geom &g, double depth)
Capture of a single on-sag inlet (inlet.c:1610).
Definition Inlet.cpp:486
double getGutterFlowRatio(const Geom &g, double w)
Ratio of the flow over width w to the total street flow, Eq(4-16) (inlet.c:1518).
Definition Inlet.cpp:186
double getFlowSpread(const Geom &g, double Q)
Width of flow spread, HEC-22 Eq(4-2)/(4-6) (inlet.c:1200).
Definition Inlet.cpp:152
constexpr double MIN_RUNOFF_FLOW
Legacy MIN_RUNOFF_FLOW (consts.h:203) — cfs.
Definition Inlet.hpp:96
double getOnGradeInletCapture(const Design &d, Geom &g, double Q, double depth)
Capture of a single on-grade inlet — type dispatch + COMBO sweeper (inlet.c:1325).
Definition Inlet.cpp:318
double getCurbOrificeFlow(double di, double h, double L, int throat_angle)
Curb-opening orifice flow with the throat-angle head, Eq(4-31a) (inlet.c:1764).
Definition Inlet.cpp:422
CurveKind
InletStore::curve_kind codes for a CUSTOM design.
Definition Inlet.hpp:93
@ UNRESOLVED
Definition Inlet.hpp:93
@ DIVERSION
Definition Inlet.hpp:93
@ RATING
Definition Inlet.hpp:93
double getOnSagCapturedFlow(const Design &d, const UsageParams &u, const Geom &g, double depth)
Total capture of an on-sag usage: single inlet × nsides · num_inlets (inlet.c:1574).
Definition Inlet.cpp:512
double getCustomCapturedFlow(const UsageParams &u, const Geom &g, const Table &curve, int curve_kind, double q, double depth, double ucf_flow, double ucf_len)
Capture of a CUSTOM inlet from its diversion / rating curve (inlet.c:1902).
Definition Inlet.cpp:528
double getOnSagSlottedFlow(const Design &d, double depth)
On-sag slotted drain flow, Eq(4-32)/(4-33) (inlet.c:1785).
Definition Inlet.cpp:477
double getSplashOverVelocity(int grate_type, double L)
Definition Inlet.cpp:203
double getEo(double Sr, double Ts, double w)
HEC-22 Eq(4-4) solved for Eo with Ts/w substituted for (T/w)−1 (inlet.c:1248).
Definition Inlet.cpp:144
double getGutterAreaRatio(const Geom &g, double Wg, double A)
Definition Inlet.cpp:193
GrateType
Legacy enum GrateType (inlet.c:124-127).
Definition Inlet.hpp:74
@ P_BAR_50
Definition Inlet.hpp:75
@ P_BAR_50x100
Definition Inlet.hpp:76
@ P_BAR_30
Definition Inlet.hpp:77
@ GENERIC
Definition Inlet.hpp:82
@ CURVED_VANE
Definition Inlet.hpp:78
@ TILT_BAR_45
Definition Inlet.hpp:79
@ RETICULINE
Definition Inlet.hpp:81
@ TILT_BAR_30
Definition Inlet.hpp:80
InletType
Definition Inlet.hpp:63
@ DROP_GRATE
Definition Inlet.hpp:68
@ GRATE
Definition Inlet.hpp:64
@ DROP_CURB
Definition Inlet.hpp:69
@ CUSTOM
Definition Inlet.hpp:70
@ SLOTTED
Definition Inlet.hpp:67
@ COMBO
Definition Inlet.hpp:66
@ CURB
Definition Inlet.hpp:65
void findOnSagCurbFlows(const Design &d, const Geom &g, double depth, double L, double *Qw, double *Qo)
Definition Inlet.cpp:432
double getOnGradeCapturedFlow(const Design &d, const UsageParams &u, Geom &g, double q, double depth)
Total capture of an on-grade usage: num_inlets in series, both sides (inlet.c:1267).
Definition Inlet.cpp:363
constexpr double INLET_BIG
Legacy BIG (consts.h:118).
Definition Inlet.hpp:100
ThroatAngle
Legacy enum ThroatAngleType (inlet.c:131) — InletStore::curb_throat.
Definition Inlet.hpp:90
@ INCLINED
Definition Inlet.hpp:90
@ VERTICAL
Definition Inlet.hpp:90
@ HORIZONTAL
Definition Inlet.hpp:90
double getGrateInletCapture(const Design &d, Geom &g, double Q)
Definition Inlet.cpp:223
double getCurbInletCapture(const Geom &g, double Q, double L)
On-grade curb-opening capture, Eq(4-22a)/(4-23)/(4-24) (inlet.c:1477).
Definition Inlet.cpp:292
Definition NodeCoupling.cpp:16
@ Q
flow (cfs)
Definition ReactionTokens.hpp:43
Central, reentrant simulation context.
Definition SimulationContext.hpp:353
Definition TableData.hpp:138
Definition XSectBatch.hpp:110
One inlet design in INTERNAL units (legacy TInletDesign, inlet.c:66-74).
Definition Inlet.hpp:134
double slotted_length
ft (0 ⇒ not a slotted drain)
Definition Inlet.hpp:144
double splash_veloc
ft/s, GENERIC grates only
Definition Inlet.hpp:140
int curb_throat
Definition Inlet.hpp:143
double curb_height
ft
Definition Inlet.hpp:142
double grate_width
ft
Definition Inlet.hpp:138
int grate_type
Definition Inlet.hpp:136
double frac_open_area
GENERIC grates only.
Definition Inlet.hpp:139
double curb_length
ft (0 ⇒ no curb half)
Definition Inlet.hpp:141
int type
inlet::InletType
Definition Inlet.hpp:135
double slotted_width
ft
Definition Inlet.hpp:145
double grate_length
ft (0 ⇒ no grate half)
Definition Inlet.hpp:137
Street / channel geometry seen by one inlet, in INTERNAL units.
Definition Inlet.hpp:115
double sl
Conduit longitudinal slope (fraction)
Definition Inlet.hpp:117
double beta
1.486·√SL / n
Definition Inlet.hpp:125
double a
Gutter depression (ft)
Definition Inlet.hpp:119
double n
Manning's roughness.
Definition Inlet.hpp:122
double t_crown
Distance from curb to crown (ft)
Definition Inlet.hpp:124
double sx
Street cross slope (fraction)
Definition Inlet.hpp:116
double sw
Gutter + cross slope.
Definition Inlet.hpp:118
double w
Gutter width (ft)
Definition Inlet.hpp:120
double qfactor
Izzard's f in Q = f·T^2.67.
Definition Inlet.hpp:126
int nsides
1- or 2-sided street
Definition Inlet.hpp:123
const XSectParams * xs
Definition Inlet.hpp:130
double t
Top width of flow spread (ft) — set by getFlowSpread.
Definition Inlet.hpp:121
Definition Inlet.hpp:235
std::vector< double > q_approach
Approach flow seen this step (cfs)
Definition Inlet.hpp:282
std::vector< int > curve_kind
CUSTOM: inlet::CurveKind.
Definition Inlet.hpp:260
std::vector< int > up_link
Approach conduit (node host: node2 == host)
Definition Inlet.hpp:243
std::vector< double > peak_flow
Peak approach flow (cfs)
Definition Inlet.hpp:291
std::vector< double > flow_capture
Captured flow rate (cfs)
Definition Inlet.hpp:283
std::vector< int > grate_type
Definition Inlet.hpp:249
std::vector< double > slotted_width
ft
Definition Inlet.hpp:258
std::vector< double > local_width
ft
Definition Inlet.hpp:267
std::vector< double > local_depress
ft
Definition Inlet.hpp:266
std::vector< int > up_link2
Second inbound conduit at a sag node host (−1)
Definition Inlet.hpp:244
std::vector< int > inlet_type
Definition Inlet.hpp:248
std::vector< double > gutter_width
ft
Definition Inlet.hpp:274
std::vector< int > flow_periods
Definition Inlet.hpp:288
std::vector< double > bypass_freq
Definition Inlet.hpp:294
std::vector< double > peak_flow_capture
Capture efficiency at peak flow (%)
Definition Inlet.hpp:292
std::vector< double > grate_length
ft
Definition Inlet.hpp:250
std::vector< double > avg_flow_capture
Σ capture efficiency over capture periods.
Definition Inlet.hpp:293
std::vector< double > stat_peak_flow
Peak captured flow (cfs)
Definition Inlet.hpp:300
int count
Definition Inlet.hpp:236
std::vector< int > placement
as authored (inlet::Placement)
Definition Inlet.hpp:268
std::vector< int > num_inlets
Definition Inlet.hpp:263
std::vector< double > t_crown
ft
Definition Inlet.hpp:276
std::vector< int > bypass_node
Node the uncaptured flow stays at.
Definition Inlet.hpp:242
std::vector< double > curb_height
ft
Definition Inlet.hpp:255
std::vector< double > grate_width
ft
Definition Inlet.hpp:251
std::vector< double > slope
Host/approach conduit slope.
Definition Inlet.hpp:278
std::vector< double > backflow_ratio
inlet backflow / capture-node overflow
Definition Inlet.hpp:285
std::vector< double > sx
Cross slope (fraction)
Definition Inlet.hpp:272
std::vector< int > link_idx
Host conduit link index (−1 for a node host)
Definition Inlet.hpp:239
std::vector< double > splash_veloc
ft/s (GENERIC)
Definition Inlet.hpp:253
std::vector< double > stat_capture_vol
ft³
Definition Inlet.hpp:297
std::vector< double > slotted_length
ft
Definition Inlet.hpp:257
std::vector< int > n_sides
Definition Inlet.hpp:277
std::vector< double > curb_length
ft
Definition Inlet.hpp:254
std::vector< double > flow_limit
cfs per inlet (0 = unlimited)
Definition Inlet.hpp:265
std::vector< double > stat_bypass_vol
ft³
Definition Inlet.hpp:298
std::vector< double > backflow
Backflow from the capture node (cfs)
Definition Inlet.hpp:284
std::vector< uint8_t > two_inbound
1 when both attached conduits flow toward the host
Definition Inlet.hpp:245
std::vector< int > node_idx
Capture (receiving) node index.
Definition Inlet.hpp:241
std::vector< int > capture_periods
Definition Inlet.hpp:289
std::vector< double > stat_backflow_vol
ft³
Definition Inlet.hpp:299
std::vector< int > host_node
Host inlet-junction node (−1 for a conduit host)
Definition Inlet.hpp:240
std::vector< double > open_area
GENERIC open-area fraction.
Definition Inlet.hpp:252
std::vector< uint8_t > is_sag
resolved placement: 1 = ON_SAG
Definition Inlet.hpp:269
std::vector< double > road_roughness
Manning's n.
Definition Inlet.hpp:275
std::vector< double > flow_factor
Izzard f = (0.56/n)·√SL·Sx^1.67.
Definition Inlet.hpp:279
void resize(int n)
Definition Inlet.cpp:78
std::vector< double > gutter_depression
ft
Definition Inlet.hpp:273
std::vector< double > clog_factor
Definition Inlet.hpp:264
std::vector< int > curb_throat
0=HORIZONTAL 1=INCLINED 2=VERTICAL
Definition Inlet.hpp:256
std::vector< int > curve_index
CUSTOM: index into ctx.tables.
Definition Inlet.hpp:259
std::vector< int > backflow_periods
Definition Inlet.hpp:290
The per-placement half of one usage row (legacy TInlet fields).
Definition Inlet.hpp:149
int num_inlets
Definition Inlet.hpp:150
double flow_limit
cfs per inlet; 0 ⇒ unlimited
Definition Inlet.hpp:152
double clog_factor
1 − clog/100
Definition Inlet.hpp:151