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
169double getEo(double sr, double ts, double w);
170
183double getFlowSpread(const Geom& g, double Q);
184
195double getGutterFlowRatio(const Geom& g, double w);
196
209double getGutterAreaRatio(const Geom& g, double grate_width, double area);
210
221double getSplashOverVelocity(int grate_type, double grate_length);
222
238double getGrateInletCapture(const Design& d, Geom& g, double Q);
239
252double getCurbInletCapture(const Geom& g, double Q, double opening_length);
253
269double getOnGradeInletCapture(const Design& d, Geom& g, double Q, double depth);
270
288double getOnGradeCapturedFlow(const Design& d, const UsageParams& u, Geom& g, double q,
289 double depth);
290
308void findOnSagGrateFlows(const Design& d, const Geom& g, double depth, double* weir_flow,
309 double* orifice_flow);
310
330void findOnSagCurbFlows(const Design& d, const Geom& g, double depth, double opening_length,
331 double* weir_flow, double* orifice_flow);
332
345double getCurbOrificeFlow(double flow_depth, double opening_height, double opening_length,
346 int throat_angle);
347
359double getOnSagSlottedFlow(const Design& d, double depth);
360
375double getOnSagInletCapture(const Design& d, const Geom& g, double depth);
376
394double getOnSagCapturedFlow(const Design& d, const UsageParams& u, const Geom& g, double depth,
395 int nsides_prev);
396
418double getCustomCapturedFlow(const UsageParams& u, const Geom& g, const Table& curve,
419 int curve_kind, double q, double depth, double ucf_flow,
420 double ucf_len);
421
434double getInletArea(const Design& d, const UsageParams& u);
435
436// ============================================================================
437// Runtime SoA
438// ============================================================================
439
440struct InletSoA {
441 int count = 0;
442
443 // --- host / topology -----------------------------------------------------
444 std::vector<int> link_idx;
445 std::vector<int> host_node;
446 std::vector<int> node_idx;
447 std::vector<int> bypass_node;
448 std::vector<int> up_link;
449 std::vector<int> up_link2;
450 std::vector<uint8_t> two_inbound;
451
452 // --- design --------------------------------------------------------------
453 std::vector<int> inlet_type;
454 std::vector<int> grate_type;
455 std::vector<double> grate_length;
456 std::vector<double> grate_width;
457 std::vector<double> open_area;
458 std::vector<double> splash_veloc;
459 std::vector<double> curb_length;
460 std::vector<double> curb_height;
461 std::vector<int> curb_throat;
462 std::vector<double> slotted_length;
463 std::vector<double> slotted_width;
464 std::vector<int> curve_index;
465 std::vector<int> curve_kind;
466
467 // --- usage ---------------------------------------------------------------
468 std::vector<int> num_inlets;
469 std::vector<double> clog_factor;
470 std::vector<double> flow_limit;
471 std::vector<double> local_depress;
472 std::vector<double> local_width;
473 std::vector<int> placement;
474 std::vector<uint8_t> is_sag;
475
476 // --- street / conduit geometry (internal units) --------------------------
477 std::vector<double> sx;
478 std::vector<double> gutter_depression;
479 std::vector<double> gutter_width;
480 std::vector<double> road_roughness;
481 std::vector<double> t_crown;
482 std::vector<int> n_sides;
483 std::vector<double> slope;
484 std::vector<double> flow_factor;
485
486 // --- per-step results ----------------------------------------------------
487 std::vector<double> q_approach;
488 std::vector<double> flow_capture;
489 std::vector<double> backflow;
490 std::vector<double> backflow_ratio;
491
492 // --- legacy statistics (inlet.c:78-87, updateInletStats :985) ------------
493 std::vector<int> flow_periods;
494 std::vector<int> capture_periods;
495 std::vector<int> backflow_periods;
496 std::vector<double> peak_flow;
497 std::vector<double> peak_flow_capture;
498 std::vector<double> avg_flow_capture;
499 std::vector<double> bypass_freq;
500
501 // --- volume statistics (Gap #68 → InletUsageStore) -----------------------
502 std::vector<double> stat_capture_vol;
503 std::vector<double> stat_bypass_vol;
504 std::vector<double> stat_backflow_vol;
505 std::vector<double> stat_peak_flow;
506
515 void resize(int n);
516};
517
519public:
533 void init(SimulationContext& ctx);
534
550 void computeAll(SimulationContext& ctx, double dt);
551
565 void adjustQualInflows(SimulationContext& ctx, double dt);
566
579 void adjustFloodingTotals(SimulationContext& ctx, double dt) const;
580
591 void gatherStats(SimulationContext& ctx) const;
592
597 const InletSoA& soa() const noexcept { return soa_; }
602 bool hasInlets() const noexcept { return soa_.count > 0; }
603
604private:
605 InletSoA soa_;
606
610 std::vector<double> node_inlet_flow_;
611 std::vector<double> node_inflow_;
612
620 int nsides_prev_ = 0;
621
625 std::vector<uint8_t> is_capture_node_;
626
641 Geom geomOf(const SimulationContext& ctx, int ii, const XSectParams* xs) const;
648 Design designOf(int ii) const;
655 UsageParams usageOf(int ii) const;
656
668 void updateStats(int ii, double q);
669
679 void computeBackflowRatios();
680};
681
682} // namespace inlet
683} // namespace openswmm
684
685#endif // OPENSWMM_INLET_HPP
Definition Inlet.hpp:518
const InletSoA & soa() const noexcept
Borrow read-only resolved inlet/runtime/statistic columns.
Definition Inlet.hpp:597
void adjustQualInflows(SimulationContext &ctx, double dt)
Add pollutant inflow volume and mass-rate contributions for net inlet exchange.
Definition Inlet.cpp:1233
void computeAll(SimulationContext &ctx, double dt)
Evaluate capture/backflow and add inlet exchanges to node lateral flows.
Definition Inlet.cpp:950
bool hasInlets() const noexcept
Check whether any runtime usage rows are allocated.
Definition Inlet.hpp:602
void adjustFloodingTotals(SimulationContext &ctx, double dt) const
Credit current capture-node overflow returned to inlet corridors out of flooding ledgers.
Definition Inlet.cpp:1288
void init(SimulationContext &ctx)
Resolve inlet deployments into native geometry, topology, placement and backflow weights.
Definition Inlet.cpp:673
void gatherStats(SimulationContext &ctx) const
Publish retained inlet statistics to model usage and reporting stores.
Definition Inlet.cpp:1348
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)
Compute the active grate weir or orifice contribution for one sag inlet.
Definition Inlet.cpp:411
double getInletArea(const Design &d, const UsageParams &u)
Compute the usage's effective open inlet area for backflow weighting.
Definition Inlet.cpp:593
constexpr double INLET_FUDGE
Legacy FUDGE (consts.h:272).
Definition Inlet.hpp:98
double getOnSagInletCapture(const Design &d, const Geom &g, double depth)
Combine one sag inlet's grate, sweeper and curb-orifice contributions.
Definition Inlet.cpp:507
void findOnSagCurbFlows(const Design &d, const Geom &g, double depth, double L, double *Qw, double *Qo)
Compute sag curb-opening weir/orifice contributions with transition blending.
Definition Inlet.cpp:451
double getGutterAreaRatio(const Geom &g, double Wg, double A)
Compute the grate-width correction to depressed-gutter intercepted flow.
Definition Inlet.cpp:198
double getGutterFlowRatio(const Geom &g, double w)
Compute the fraction of street flow above a selected gutter width.
Definition Inlet.cpp:188
double getFlowSpread(const Geom &g, double Q)
Compute approach flow spread with crown limiting and depressed-gutter iteration.
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)
Compute a single on-grade inlet or combination sweeper/grate capture.
Definition Inlet.cpp:332
double getSplashOverVelocity(int grate_type, double L)
Evaluate the standard grate splash-over velocity polynomial.
Definition Inlet.cpp:211
double getCurbOrificeFlow(double di, double h, double L, int throat_angle)
Compute sag curb-opening orifice flow using throat-adjusted head.
Definition Inlet.cpp:441
double getOnSagCapturedFlow(const Design &d, const UsageParams &u, const Geom &g, double depth, int nsides_prev)
Scale sag capacity using usage factors and legacy carried-over street sides.
Definition Inlet.cpp:537
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 getCustomCapturedFlow(const UsageParams &u, const Geom &g, const Table &curve, int curve_kind, double q, double depth, double ucf_flow, double ucf_len)
Compute custom inlet capture from authored diversion or rating curves.
Definition Inlet.cpp:557
double getOnSagSlottedFlow(const Design &d, double depth)
Compute one sag slotted-drain weir or orifice capacity.
Definition Inlet.cpp:498
double getEo(double Sr, double Ts, double w)
Compute the depressed-gutter flow ratio using HEC-22 Eq4-4.
Definition Inlet.cpp:144
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
double getOnGradeCapturedFlow(const Design &d, const UsageParams &u, Geom &g, double q, double depth)
Compute series inlet capture across the current street sides.
Definition Inlet.cpp:378
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)
Compute one on-grade grate's frontal and side capture.
Definition Inlet.cpp:235
double getCurbInletCapture(const Geom &g, double Q, double L)
Compute on-grade curb-opening capture from equivalent cross slope.
Definition Inlet.cpp:306
Definition ExchangeLaw.hpp:60
@ Q
flow (cfs)
Definition ReactionTokens.hpp:43
Central, reentrant simulation context.
Definition SimulationContext.hpp:390
Definition TableData.hpp:154
Native cross-section geometry and borrowed optional normalized transect tables.
Definition XSectBatch.hpp:119
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:440
std::vector< double > q_approach
Approach flow seen this step (cfs)
Definition Inlet.hpp:487
std::vector< int > curve_kind
CUSTOM: inlet::CurveKind.
Definition Inlet.hpp:465
std::vector< int > up_link
Approach conduit (node host: node2 == host)
Definition Inlet.hpp:448
std::vector< double > peak_flow
Peak approach flow (cfs)
Definition Inlet.hpp:496
std::vector< double > flow_capture
Captured flow rate (cfs)
Definition Inlet.hpp:488
std::vector< int > grate_type
Definition Inlet.hpp:454
std::vector< double > slotted_width
ft
Definition Inlet.hpp:463
std::vector< double > local_width
ft
Definition Inlet.hpp:472
std::vector< double > local_depress
ft
Definition Inlet.hpp:471
std::vector< int > up_link2
Second inbound conduit at a sag node host (−1)
Definition Inlet.hpp:449
std::vector< int > inlet_type
Definition Inlet.hpp:453
std::vector< double > gutter_width
ft
Definition Inlet.hpp:479
std::vector< int > flow_periods
Definition Inlet.hpp:493
std::vector< double > bypass_freq
Definition Inlet.hpp:499
std::vector< double > peak_flow_capture
Capture efficiency at peak flow (%)
Definition Inlet.hpp:497
std::vector< double > grate_length
ft
Definition Inlet.hpp:455
std::vector< double > avg_flow_capture
Σ capture efficiency over capture periods.
Definition Inlet.hpp:498
std::vector< double > stat_peak_flow
Peak captured flow (cfs)
Definition Inlet.hpp:505
int count
Definition Inlet.hpp:441
std::vector< int > placement
as authored (inlet::Placement)
Definition Inlet.hpp:473
std::vector< int > num_inlets
Definition Inlet.hpp:468
std::vector< double > t_crown
ft
Definition Inlet.hpp:481
std::vector< int > bypass_node
Node the uncaptured flow stays at.
Definition Inlet.hpp:447
std::vector< double > curb_height
ft
Definition Inlet.hpp:460
std::vector< double > grate_width
ft
Definition Inlet.hpp:456
std::vector< double > slope
Host/approach conduit slope.
Definition Inlet.hpp:483
std::vector< double > backflow_ratio
inlet backflow / capture-node overflow
Definition Inlet.hpp:490
std::vector< double > sx
Cross slope (fraction)
Definition Inlet.hpp:477
std::vector< int > link_idx
Host conduit link index (−1 for a node host)
Definition Inlet.hpp:444
std::vector< double > splash_veloc
ft/s (GENERIC)
Definition Inlet.hpp:458
std::vector< double > stat_capture_vol
ft³
Definition Inlet.hpp:502
std::vector< double > slotted_length
ft
Definition Inlet.hpp:462
std::vector< int > n_sides
Definition Inlet.hpp:482
std::vector< double > curb_length
ft
Definition Inlet.hpp:459
std::vector< double > flow_limit
cfs per inlet (0 = unlimited)
Definition Inlet.hpp:470
std::vector< double > stat_bypass_vol
ft³
Definition Inlet.hpp:503
std::vector< double > backflow
Backflow from the capture node (cfs)
Definition Inlet.hpp:489
std::vector< uint8_t > two_inbound
1 when both attached conduits flow toward the host
Definition Inlet.hpp:450
std::vector< int > node_idx
Capture (receiving) node index.
Definition Inlet.hpp:446
std::vector< int > capture_periods
Definition Inlet.hpp:494
std::vector< double > stat_backflow_vol
ft³
Definition Inlet.hpp:504
std::vector< int > host_node
Host inlet-junction node (−1 for a conduit host)
Definition Inlet.hpp:445
std::vector< double > open_area
GENERIC open-area fraction.
Definition Inlet.hpp:457
std::vector< uint8_t > is_sag
resolved placement: 1 = ON_SAG
Definition Inlet.hpp:474
std::vector< double > road_roughness
Manning's n.
Definition Inlet.hpp:480
std::vector< double > flow_factor
Izzard f = (0.56/n)·√SL·Sx^1.67.
Definition Inlet.hpp:484
void resize(int n)
Reset every inlet runtime/design/statistic column to n rows.
Definition Inlet.cpp:78
std::vector< double > gutter_depression
ft
Definition Inlet.hpp:478
std::vector< double > clog_factor
Definition Inlet.hpp:469
std::vector< int > curb_throat
0=HORIZONTAL 1=INCLINED 2=VERTICAL
Definition Inlet.hpp:461
std::vector< int > curve_index
CUSTOM: index into ctx.tables.
Definition Inlet.hpp:464
std::vector< int > backflow_periods
Definition Inlet.hpp:495
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