A translation of the 1D engine of OpenSWMM 6 (HydroCouple/openswmm.engine, branch swmm6_rel, commit 88329d6)
into PHP, held to the same output as the C++ engine: the same binary .out file and the same .rpt
report, apart from the three clock lines. It is not SWMM6 and not a HydroCouple or EPA release; it is a
translation checked against SWMM6.
480 of 480 models byte-identical against the C++ reference engine built from the same commit and run on one thread
(OMP_NUM_THREADS=1), on the 480-model gate set (the one the SWMM5 ports were checked on), drawn from
1729-SWMM5-Models-2030. Gate runs
php6_c01, php6_c02, php6_c03, php6_c04, php6_c05, php6_c06a, php6_c06b; every result, with the SHA-256 of each .out and .rpt, is in gate/evidence/.
The same engine on the 452 extra decks: 450 of 452 extra decks byte-identical (2 did not finish within the time limit: legacy_small.inp, refactored_small.inp; untested, not failed). These are SWMM6's own tests, which the corpus cannot be:
the input files in the upstream repository's tests folder at 88329d6, and the synthetic decks of
swmm6-rust's gate, which probe the finite-volume solver, its
structure coupling, the newer hydrology and the input checks. Gate runs
php6_x01, php6_x02c, php6_x03, in gate/evidence/ with the same hashes.
Checked twice more. An independent rerun of all 480 corpus models, plus 40 extra decks drawn at random (seed 20261110), from a clean copy of the repository (git archive), with
the translator rebuilt there and the engine (php/gen/engine.php, with the translator's three reports) and php/cpp/primelist.php regenerated there, all byte-identical to the committed files (php/results/php6_v_build.txt); every status and every .out and .rpt hash equal to the first run's (php/results/php6_v_compare.txt): gate runs
php6_v1a, php6_v1b, php6_v2a, php6_v2b, php6_v3, php6_vx, 520 of 520 byte-identical. Then the main session's own check, from a
clean git clone: the translator rebuilt and the engine and primelist.php regenerated (identical again; php -l passes on every PHP file); and gate runs php6_main on 45 corpus models drawn at random (seed 20261110) plus the three decks that
SAVE and USE cho.txt (48 of 48 byte-identical) and php6_main_x on 12 extra decks drawn the same way
(12 of 12 byte-identical). The math's own tests are in php/results/libm_tests.txt.
The two that did not finish were stopped at the gate's 1,800-second limit, and no longer limit was tried. Every byte of .out each had written by then is identical to the reference (php/results/php6_x03_stopped.txt): legacy_small.inp 105,977,145 of 155,158,965 bytes (68.3%) and refactored_small.inp 106,170,501 of 155,158,965 (68.4%). The two corpus models that the Ruby port could not finish in that time finished here: SCANLON.inp in 531 s and 72_H&H_Elements(2).inp in 1,207 s.
Two of PHP's own optimizations had to be switched off, and php/runswmm6 says why. With the tracing JIT's register allocator on, the reaction integrator's step loop on initq_rxlid_nodes.inp never ended; with OPcache's CFG block pass on, ppr_custom_nan.inp crashed, because the pass turned !($x > 0.0) into $x <= 0.0, which is wrong for a NaN. So the engine runs with opcache.jit=1054 and opcache.optimization_level=0x7FFEBF6F. As those settings changed, the gate chunks ran on three commits (2aa50c2, c413190 and 4cca877); the translator and the generated engine did not change after 2aa50c2, and the full rerun was made on 4cca877. The runs those two decks replaced are in php/results (php6_x02, php6_x02b).
A model passes when its .out is byte-identical to the reference's (when the reference writes one), its .rpt is
identical after removing the lines "Analysis begun", "Analysis ended" and "Total elapsed time", and its exit code is
the same (the command line exits nonzero when a model stops on an input error).
The translations, all from the same C# and gated the same way: swmm6-csharp, swmm6-go, swmm6-java, swmm6-typescript, swmm6-fortran, swmm6-python, swmm6-kotlin, swmm6-groovy, swmm6-javascript, swmm6-fsharp, swmm6-hy, swmm6-ruby, swmm6-php, under SWMMBobSWMM6.
The C++ engine was translated to C# first, and the C# gated to 480 of 480. The other languages are translated
from that C#, not from the C++. tools/cs2x/Cs2Php.cs, begun as a copy of the Ruby back end, translates the verified C# engine (cs/gen) through Roslyn into one PHP file (php/gen/engine.php; the mapping is in tools/cs2x/PHP.md). php/cpp is the runtime library, written in PHP for this port. No math was translated: it is glibc's own, through PHP's built-in functions and, for cbrt, nextafter and remainder, through FFI; the exact functions (floor, ceil, trunc, round, copysign, and fmod of two NaNs) are about 80 lines in php/cpp/crtmisc.php. Nothing in php/ loads anything from the other ports.
Nothing in the generated engine is edited by hand. Where the output depends on the C library (printf's rounding,
strtod, sscanf, the order of a hash table's nodes, introsort's swaps), the runtime reproduces glibc and libstdc++
exactly; the checks in tests/ compare it with them case by case.
Needs PHP 8.3 CLI with OPcache and FFI (run here with 8.3.6) on x86-64 Linux with glibc; the .NET 8 SDK only to regenerate the engine. No build step. Then run a model the way the C++ command line runs it:
php/runswmm6 model.inp model.rpt model.out
To regenerate the engine: tools/cs2x/build_php.sh, then dotnet tools/cs2x/bin/cs2php.dll cs php/gen, then php/make_primelist.sh. The C# engine it starts from is regenerated from the C++ source with
tools/cpp2x (see the header of tools/cpp2x/emit_cs.py and cs/README.md), which needs the OpenSWMM source at
commit 88329d6 and libclang.
gate/make_ref.sh makes the reference outputs with the C++ engine (ref/runswmm6: build openswmm.engine at
88329d6 and run it single-threaded); gate/gate.py NAME "php/runswmm6" --resume runs this engine on every model in
gate/models_all.tsv (paths relative to the corpus; set SWMM_CORPUS) and compares; gate/cmp1.sh checks one
model. The extra decks are listed in gate/models_extra.tsv, with paths relative to a folder that holds clones of
openswmm.engine (at 88329d6) and swmm6-rust: make their references with
SWMM_CORPUS=FOLDER MODELS=gate/models_extra.tsv REF=$PWD/gate/ref_outputs_extra gate/make_ref.sh, then run
gate/gate.py NAME "php/runswmm6" --models gate/models_extra.tsv --ref gate/ref_outputs_extra --root FOLDER --resume.
The median time per model in the gate runs was 1.99 s (the C# engine's: 0.76 s, which includes .NET's start-up and JIT compilation). The times were measured on a shared two-core cloud machine while other runs were going, so they are a
rough guide, not a benchmark.
- Agreement on models outside the 480 and the 452. The two sets are broad (EPA's examples, the OWA EXTRAN set, hydrology, hydraulics, water quality, LID, RDII, controls, hot start, input errors, the FV solver and SWMM6's own tests), but a feature no gate model or deck uses is untested.
- The reference's parallel runs. Every parallel loop runs on one thread, in order, which is what the C++ engine does when it is held to one thread; results with OpenMP threads can differ in the last bits.
- The 2D and other modules of OpenSWMM 6 beyond the 1D engine the command line runs.
This repository is a translation of the OpenSWMM 6 engine.
OpenSWMM Engine — Copyright 2026 HydroCouple Developers, licensed under the Apache License, Version 2.0. See
LICENSE and NOTICE. Source: https://github.com/HydroCouple/openswmm.engine (branch
swmm6_rel, commit 88329d6).
Every generated engine file here is a modified, mechanically translated form of the OpenSWMM sources: its header
names what it was generated from, and each C# file in cs/gen names the OpenSWMM source file it came from.
Portions derive from the USEPA Storm Water Management Model, which is in the public domain under 17 USC § 105. The USEPA does not endorse this product, and neither does HydroCouple.
The translators, the runtime, the gate and the notes: Copyright 2026 Robert Dickinson, licensed under the Apache License, Version 2.0.
Made with Claude (Anthropic): the translators, the runtime, the gate and the notes are Claude's work, directed by Robert Dickinson; the engine itself is OpenSWMM's, translated mechanically. See AI-USE.md.