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:

  1. Implementing FHWA HEC-22 inlet capture and implicit level-pool detention routing directly against published equations and SWMM 5.2.4's solver behavior.
  2. Exporting a ready-to-run EPA SWMM 5.2 .inp model 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 flow q1 and updated spread t, and then pass the remaining gutter flow onto the grate.
  • Edition toggle (Hec22Edition::Ed3_2009 vs. Ed4_2024): Besides matching SWMM 5.2.4's classic 3rd Edition curb length L_T = 0.6 · Q^(0.42) · S_L^(0.3) · (n · S_e)^(-0.6), curb_lt_ft also implements the HEC-22 4th Edition (2024, FHWA-HIF-24-006 Ch. 7 / FHWA-HRT-22-061) iterative curb capture formulation (α = 0.72 entry drawdown, profile factor K, side-weir coefficient M, 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 flow Q = 3.0 · P · d^(1.5) for d <= 1.79 · A_o / P, transitioning to orifice flow Q = 0.67 · A_o · sqrt(2 · g · d_i) above that threshold (with effective gutter-weighted width when d <= W_g · S_w).
  • Slotted drains: Weir flow Q = 2.48 · L · d^(1.5) for d <= 2.587 · W, orifice flow Q = 0.8 · L · W · sqrt(64.32 · d) otherwise.
  • Curb openings (sag_curb): Weir flow up to d_weir (h or h + a for depressed gutters), linear transition between d_weir and 1.4·h, and full orifice head adjusted by Throat orientation (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:

  1. 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_outlets halves the substep down to dt / 1024.0 to pinpoint the drain time, and at minimum step caps outflow cleanly at available water s + vin so continuity_error_pct stays near zero.
  2. 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. In Outlet::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):
  • 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 hydro CLI execution alias; users needing CLI batch verification or air-gapped .hykey licensing can use the standalone installer on our downloads page.

Links & Reproducibility