OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches
Runoff.hpp
Go to the documentation of this file.
1
22#ifndef OPENSWMM_RUNOFF_HPP
23#define OPENSWMM_RUNOFF_HPP
24
25#include "../data/SubcatchData.hpp"
26#include "Infiltration.hpp"
27#include <vector>
28
29namespace openswmm {
30
31struct SimulationContext;
32
33namespace runoff {
34
35// ============================================================================
36// Constants
37// ============================================================================
38
39constexpr double MEXP = 5.0 / 3.0;
40constexpr double ODETOL = 0.0001;
41constexpr double PHI = 1.486;
42
43// ============================================================================
44// Per-subcatchment subarea state (SoA for vectorization)
45// ============================================================================
46
47struct RunoffSoA {
48 int n_subcatch = 0;
49
50 // Per-subcatchment properties (set at init)
51 std::vector<double> area;
52 std::vector<double> width;
53 std::vector<double> slope;
54 std::vector<double> imperv_pct;
55 std::vector<double> imperv0_pct;
56
57 // Per-subarea SoA: alpha = runoff coefficient
58 std::vector<double> alpha_imperv;
59 std::vector<double> alpha_perv;
60
61 // Per-subarea SoA: depression storage (ft)
62 std::vector<double> ds_imperv;
63 std::vector<double> ds_perv;
64
65 // Per-subarea SoA: Manning's n
66 std::vector<double> n_imperv;
67 std::vector<double> n_perv;
68
69 // Per-subarea SoA: ponded depth (state, updated each step)
70 std::vector<double> depth_imperv0;
71 std::vector<double> depth_imperv1;
72 std::vector<double> depth_perv;
73
74 // Per-subarea SoA: previous-step runoff rates (ft/sec, area-averaged)
75 // Used for inter-subarea routing (legacy subcatch_getRunon)
76 std::vector<double> old_runoff_imperv0;
77 std::vector<double> old_runoff_imperv1;
78 std::vector<double> old_runoff_perv;
79
80 // Per-subcatchment: computed runoff (output)
81 std::vector<double> runoff;
82 std::vector<double> evap_loss;
83 std::vector<double> infil_loss;
84
85 void resize(int n);
86 void computeAlpha();
87};
88
89// ============================================================================
90// Runoff solver
91// ============================================================================
92
94public:
95 void init(SimulationContext& ctx);
100 void execute(SimulationContext& ctx, double dt, double evap_rate = 0.0,
101 double infil_factor = 1.0, double recovery_factor = 1.0);
102
103 const RunoffSoA& soa() const { return soa_; }
104
105private:
106 RunoffSoA soa_;
107
108 // Infiltration state (one per subcatchment)
109 InfilModel infil_model_ = InfilModel::HORTON;
110 std::vector<HortonState> horton_states_;
111 std::vector<GreenAmptState> grnampt_states_;
112 std::vector<CurveNumState> curvenum_states_;
113
114 // Working buffers (reused each step, sized to n_subcatch)
115 std::vector<double> precip_;
116 std::vector<double> evap_rate_;
117 std::vector<double> infil_rate_;
118
121 static void updatePondedDepth(double& depth, double inflow, double alpha,
122 double dStore, double dt);
123
125 static double getRunoffRate(double depth, double dStore, double alpha);
126};
127
128} // namespace runoff
129} // namespace openswmm
130
131#endif // OPENSWMM_RUNOFF_HPP
Infiltration models — Horton, Green-Ampt, SCS Curve Number.
Definition Runoff.hpp:93
void init(SimulationContext &ctx)
Definition Runoff.cpp:159
void execute(SimulationContext &ctx, double dt, double evap_rate=0.0, double infil_factor=1.0, double recovery_factor=1.0)
Definition Runoff.cpp:221
const RunoffSoA & soa() const
Definition Runoff.hpp:103
constexpr double PHI
Manning's US customary constant.
Definition Runoff.hpp:41
constexpr double ODETOL
ODE solver tolerance (matching legacy)
Definition Runoff.hpp:40
constexpr double MEXP
Manning's exponent.
Definition Runoff.hpp:39
Definition Controls.cpp:24
InfilModel
Definition Infiltration.hpp:29
Central, reentrant simulation context.
Definition SimulationContext.hpp:141
Definition Runoff.hpp:47
std::vector< double > depth_imperv0
Ponded depth, IMPERV0 (ft) — dStore=0.
Definition Runoff.hpp:70
std::vector< double > depth_perv
Ponded depth, PERV (ft)
Definition Runoff.hpp:72
int n_subcatch
Definition Runoff.hpp:48
std::vector< double > alpha_perv
Alpha for pervious subarea.
Definition Runoff.hpp:59
void resize(int n)
Definition Runoff.cpp:46
std::vector< double > ds_perv
Depression storage for PERV.
Definition Runoff.hpp:63
std::vector< double > ds_imperv
Depression storage for IMPERV1.
Definition Runoff.hpp:62
std::vector< double > old_runoff_imperv1
Previous IMPERV1 runoff (ft/sec)
Definition Runoff.hpp:77
std::vector< double > area
Subcatchment area (ft²)
Definition Runoff.hpp:51
std::vector< double > imperv_pct
Impervious fraction (0-1)
Definition Runoff.hpp:54
std::vector< double > slope
Average slope (ft/ft)
Definition Runoff.hpp:53
std::vector< double > old_runoff_imperv0
Previous IMPERV0 runoff (ft/sec)
Definition Runoff.hpp:76
std::vector< double > runoff
Total runoff rate (cfs)
Definition Runoff.hpp:81
std::vector< double > width
Subcatchment width (ft)
Definition Runoff.hpp:52
std::vector< double > depth_imperv1
Ponded depth, IMPERV1 (ft) — dStore>0.
Definition Runoff.hpp:71
std::vector< double > imperv0_pct
Fraction of imperv with zero dStore (0-1)
Definition Runoff.hpp:55
std::vector< double > infil_loss
Infiltration loss (ft3)
Definition Runoff.hpp:83
void computeAlpha()
Definition Runoff.cpp:76
std::vector< double > evap_loss
Evaporation loss (ft3)
Definition Runoff.hpp:82
std::vector< double > old_runoff_perv
Previous PERV runoff (ft/sec)
Definition Runoff.hpp:78
std::vector< double > n_imperv
Manning's n, impervious.
Definition Runoff.hpp:66
std::vector< double > n_perv
Manning's n, pervious.
Definition Runoff.hpp:67
std::vector< double > alpha_imperv
Alpha for impervious subareas.
Definition Runoff.hpp:58