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 // Per-subcatchment: per-subarea runoff CFS from non-LID area (Gap #23)
86 // Used by SWMMEngine to compute LID unit inflow from impervious/pervious fractions.
87 std::vector<double> imperv_runoff_cfs;
88 std::vector<double> perv_runoff_cfs;
89
90 void resize(int n);
91 void computeAlpha();
92};
93
94// ============================================================================
95// Runoff solver
96// ============================================================================
97
99public:
100 void init(SimulationContext& ctx);
105 void execute(SimulationContext& ctx, double dt, double evap_rate = 0.0,
106 double infil_factor = 1.0, double recovery_factor = 1.0,
107 int month = -1);
108
109 const RunoffSoA& soa() const { return soa_; }
110
111 // -----------------------------------------------------------------------
112 // Hot start helpers — Gap #54
113 // -----------------------------------------------------------------------
114
127 void infil_get_state(int i, int& model, double state[6]) const noexcept;
128
139 void infil_set_state(int i, int model, const double state[6]) noexcept;
140
141private:
142 RunoffSoA soa_;
143
144 // Infiltration state (one per subcatchment)
145 std::vector<InfilModel> infil_models_;
146 std::vector<HortonState> horton_states_;
147 std::vector<GreenAmptState> grnampt_states_;
148 std::vector<CurveNumState> curvenum_states_;
149
150 // Working buffers (reused each step, sized to n_subcatch)
151 std::vector<double> precip_;
152 std::vector<double> evap_rate_;
153 std::vector<double> infil_rate_;
154
157 static void updatePondedDepth(double& depth, double inflow, double alpha,
158 double dStore, double dt);
159
161 static double getRunoffRate(double depth, double dStore, double alpha);
162};
163
164} // namespace runoff
165} // namespace openswmm
166
167#endif // OPENSWMM_RUNOFF_HPP
Infiltration models — Horton, Green-Ampt, SCS Curve Number.
Definition Runoff.hpp:98
void infil_set_state(int i, int model, const double state[6]) noexcept
Restore infiltration state for subcatchment i from a flat 6-element array.
Definition Runoff.cpp:603
void init(SimulationContext &ctx)
Definition Runoff.cpp:161
const RunoffSoA & soa() const
Definition Runoff.hpp:109
void infil_get_state(int i, int &model, double state[6]) const noexcept
Pack infiltration state for subcatchment i into a flat 6-element array.
Definition Runoff.cpp:562
void execute(SimulationContext &ctx, double dt, double evap_rate=0.0, double infil_factor=1.0, double recovery_factor=1.0, int month=-1)
Definition Runoff.cpp:234
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 NodeCoupling.cpp:15
Central, reentrant simulation context.
Definition SimulationContext.hpp:274
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
std::vector< double > imperv_runoff_cfs
Impervious subarea runoff (CFS, non-LID area)
Definition Runoff.hpp:87
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 > perv_runoff_cfs
Pervious subarea runoff (CFS, non-LID area)
Definition Runoff.hpp:88
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:78
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