Cross-Checking 142 FHWA HEC-22 Inlets and Level-Pool Detention Routing Against EPA SWMM 5.2.4 in Rust (Max Diff 0.019%)
Civil engineers often run into an annoying mismatch when checking urban drainage calculations: a quick browser or spreadsheet estimate disagrees with EPA SWMM 5.2, and there is no step-by-step equation trace or exported model to show why.
In HyGeoWorks (currently release 1.0.11, running the exact same Rust core on Windows desktop and in the browser via bare wasm32-unknown-unknown with <= 4.9e-16 parity against hy_ffi.dll), we solved this by keeping two pieces honest:
- Implementing FHWA HEC-22 inlet capture and implicit level-pool detention routing directly against published equations and SWMM 5.2.4's solver behavior.
- Exporting a ready-to-run EPA SWMM 5.2
.inpmodel right from our free browser detention calculator (no login required) so any reviewer can verify the routing in SWMM itself.
Here is how the Rust modules are structured, the numerical subtleties that matter in practice, and the exact benchmark differences we recorded against EPA SWMM 5.2.4.
Part 1: FHWA HEC-22 Inlet Capture in crates/hy-flood2d/src/inlet.rs
1. Why compute internally in ft and cfs?
Although our core domain types use SI (m, m³/s), EPA SWMM 5.2.4 (inlet.c) evaluates FHWA HEC-22 polynomial fits and empirical coefficients directly in US customary units. Rewriting those coefficients in SI introduces tiny rounding drift in cubic splash-over curves and transition depths.
Instead, inlet.rs converts street and inlet geometry once at the boundary (FT = 0.3048, CFS = 0.028316846592), computes spread, velocities, and capture in ft / ft/s / cfs, and converts the final captured flow back cleanly.
2. On-grade spread and splash-over interception
For an on-grade street gutter (uniform or composite with local gutter depression a over width W), spread T is solved via Izzard's flow equation:
Q = (0.56 / n) · S_L^(1/2) · S_x^(1.67) · T^(2.67) When gutter depression is present (a > 0) and flow spills beyond width W, flow_spread iterates up to 10 fixed-point updates on the composite gutter ratio E_o:
for _ in 1..11 { let e = eo(sr, ts1, g.w); ts2 = ((1.0 - e) * q / f).dpowf(0.375); if (ts2 - ts1).abs() < 0.01 { break; } ts1 = ts2; } For each standard HEC-22 grate (PBar50, PBar50x100, PBar30, CurvedVane, TiltBar45, TiltBar30, Reticuline), the splash-over velocity V_o uses the cubic Chart 5B regression polynomial in grate length L:
V_o = c_0 + c_1·L − c_2·L² + c_3·L³ Frontal flow interception R_f, side-flow interception R_s, and total grate efficiency E follow:
R_f = max(0, 1 − 0.09 · (V − V_o)) (for V > V_o) E = R_f · E_o + R_s · (1 − E_o) Notice two practical guards in on_grade_single:
- Combo inlets route the upstream curb sweeper section (
lsweep = L_curb - L_grate) first, recompute the reduced approach flowq1and updated spreadt, and then pass the remaining gutter flow onto the grate. - Edition toggle (
Hec22Edition::Ed3_2009vs.Ed4_2024): Besides matching SWMM 5.2.4's classic 3rd Edition curb lengthL_T = 0.6 · Q^(0.42) · S_L^(0.3) · (n · S_e)^(-0.6),curb_lt_ftalso implements the HEC-22 4th Edition (2024, FHWA-HIF-24-006 Ch. 7 / FHWA-HRT-22-061) iterative curb capture formulation (α = 0.72entry drawdown, profile factorK, side-weir coefficientM, slope adjustmentβ_S1, and 95% reliability factorγ_1 = 0.88).
3. On-sag weir-to-orifice transitions and throat geometry
In a sag, shallow ponding behaves as a weir while deep ponding behaves as an orifice:
- Grates (
sag_grate): Weir flowQ = 3.0 · P · d^(1.5)ford <= 1.79 · A_o / P, transitioning to orifice flowQ = 0.67 · A_o · sqrt(2 · g · d_i)above that threshold (with effective gutter-weighted width whend <= W_g · S_w). - Slotted drains: Weir flow
Q = 2.48 · L · d^(1.5)ford <= 2.587 · W, orifice flowQ = 0.8 · L · W · sqrt(64.32 · d)otherwise. - Curb openings (
sag_curb): Weir flow up tod_weir(horh + afor depressed gutters), linear transition betweend_weirand1.4·h, and full orifice head adjusted byThroatorientation (Vertical:d_i,Inclined:d_i − 0.7071·h/2,Horizontal:d_i − h/2).
4. Benchmark X-02: 142 cases vs. EPA SWMM 5.2.4
From EXTERNAL.md (X-02, tested against EPA SWMM 5.2.4 STREET cross-section + INLETS):
| Scenario | Matrix Size | Max Relative Difference vs. SWMM 5.2.4 |
|---|---|---|
| On grade | 128 cases (8 types × 2 streets × 2 longitudinal slopes × 4 flows) | 0.019% |
| In sag | 14 cases (7 types × 2 streets) | 0.000% |
Part 2: Level-Pool Detention Routing with Time-Varying Tailwater (crates/hy-detention)
1. Why we skipped precomputed 2S/Δt + O lookup tables
Textbook Modified Puls works only when outflow O depends purely on pond depth h. As soon as an orifice or weir discharges to a time-varying tailwater series TW(t), O(h, TW) changes every step and a single static storage-indication curve breaks down.
In crates/hy-detention/src/routing.rs, route_outlets solves the implicit trapezoidal continuity equation directly at each substep (substeps = 10 by default):
S(h₂) + (Δt / 2) · O(h₂, TW₂) = S₁ + (Δt / 2) · (I₁ + I₂ − O₁) Because S(h) and O(h, TW₂) are both monotonically non-decreasing in h, the root is guaranteed unique. Each substep simply brackets upward (bracket_upward) and solves to 1e-9 m depth tolerance with bisection (bisect).
2. Draining-step conservation & partial orifice submergence
Two subtle edge cases caused most discrepancies during early testing:
- Pond emptying within a substep (
g(0.0) >= 0.0): If the trapezoidal step would pull depth negative, naive root clamping destroys mass balance. Instead,route_outletshalves the substep down todt / 1024.0to pinpoint the drain time, and at minimum step caps outflow cleanly at available waters + vinsocontinuity_error_pctstays near zero. - Partially full orifices with submerged invert (
outlet.rs): When pond water sits below the orifice crown (y < h) while tailwater exceeds the orifice invert (dn > invert_elev), treating it purely by centroid head ignores submergence until tailwater passes mid-height. InOutlet::forward, partially full orifices apply Villemonte's submergence factor identically to rectangular weirs:
if y < h { let q = *count as f64 * cd * shape.wet_area(yw) * (2.0 * G * (up - centroid)).sqrt(); let h2 = dn - invert_elev; return if h2 <= 0.0 { q } else { q * (1.0 - (h2 / y).min(1.0).dpowf(1.5)).max(0.0).dpowf(0.385) }; } Circular orifices also evaluate exact wetted circular segment area (wet_area) via (d² / 8) · (θ − sin θ), and flap_gate prevents reverse inflow when TW > h_w.
3. Benchmarks X-03 & X-04 vs. EPA SWMM 5.2.4
Recorded in EXTERNAL.md:
| Benchmark | Setup | Comparison vs. EPA SWMM 5.2.4 |
|---|---|---|
| X-03 (Single pond) | Uniform pond, orifice + weir | Max depth +0.51%, peak outflow +0.37%, continuity error ≈ 0% |
| X-03 (Depth–area table) | Depth–area curve (200 → 4000 m²) | Max depth +0.25%, peak outflow −0.39%, both .inp run cleanly |
| X-04 (Multi-catchment network) | 3 ponds (series + parallel + overflow) | Max depths +0.00% / +0.02% / −0.01%, outlet peak +0.08%, continuity error 0.000% |
Honest Scope: Browser Calculators vs. Desktop Edition
- Free browser calculators (zero upload, no login):
- FHWA HEC-22 Curb & Grate Inlet Calculator (US Customary): Run on-grade and on-sag grate, curb, combo, and slotted inlets locally in WebAssembly.
- Detention Pond & Level-Pool Routing Calculator (US Customary): When you select an orifice or orifice + weir outlet, it runs full level-pool routing of a vertical-walled pond under a post-development triangular inflow with free outfall and lets you download the exact EPA SWMM 5.2
.inpfile (FLOW_UNITS CFSin US customary; SI in other markets) with zero registration.
- Desktop edition (HyGeoWorks on Microsoft Store): Multi-pond networks, arbitrary depth–area tables, time-varying tailwater hydrographs, full 1D dynamic-wave drainage coupled with 2D overland flood routing (
X-01, 16 scenarios vs. SWMM 5.2.4), and step-by-step Word (.docx) / Excel / AutoCAD DXF deliverables.- The Windows edition is published on the Microsoft Store (Microsoft-signed MSIX, zero SmartScreen warning, free trial without a serial number). Note that the Store package does not register the
hydroCLI execution alias; users needing CLI batch verification or air-gapped.hykeylicensing can use the standalone installer on our downloads page.
- The Windows edition is published on the Microsoft Store (Microsoft-signed MSIX, zero SmartScreen warning, free trial without a serial number). Note that the Store package does not register the
Links & Reproducibility
- HEC-22 Inlet Calculator (US): https://hygeoworks.com/us/tools/curb-inlet/
- Detention Pond Routing + Free SWMM
.inpExport (US): https://hygeoworks.com/us/tools/swc-detention-pond/ - Autodesk SSA Transition Guide: https://hygeoworks.com/us/guides/autodesk-ssa-transition/
- 69-Case Verification Benchmarks (Release 1.0.11, 69/69 Pass): https://hygeoworks.com/en/benchmarks/
- GitHub Benchmark Data (CC BY 4.0): https://github.com/hygeoworks/hygeoworks-benchmarks
- Zenodo Concept DOI: https://doi.org/10.5281/zenodo.24458320
- Microsoft Store (Windows Desktop Trial): https://apps.microsoft.com/detail/9NX6CS5WLBHW