OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches
LID.hpp
Go to the documentation of this file.
1
26#ifndef OPENSWMM_LID_HPP
27#define OPENSWMM_LID_HPP
28
29#include <vector>
30#include <cstddef>
31
32namespace openswmm {
33
34struct SimulationContext;
35
36namespace lid {
37
38// ============================================================================
39// LID type codes
40// ============================================================================
41
42enum class LIDType : int {
43 BIO_CELL = 0,
44 RAIN_GARDEN = 1,
45 GREEN_ROOF = 2,
46 INFIL_TRENCH = 3,
47 PERM_PAVEMENT = 4,
48 RAIN_BARREL = 5,
49 VEG_SWALE = 6,
50 ROOF_DISCON = 7
51};
52
53// ============================================================================
54// Layer state (per LID unit)
55// ============================================================================
56
57constexpr int SURF = 0;
58constexpr int SOIL = 1;
59constexpr int STOR = 2;
60constexpr int PAVE = 3;
61constexpr int N_LAYERS = 4;
62
63// ============================================================================
64// LID unit parameters (SoA for batch processing)
65// ============================================================================
66
69 int count = 0;
70
71 std::vector<int> subcatch_idx;
72 std::vector<int> control_idx;
73 std::vector<double> area;
74 std::vector<double> from_imperv;
75 std::vector<double> from_perv;
76 std::vector<int> to_perv;
77 std::vector<int> drain_node;
78 std::vector<int> drain_subcatch;
79 std::vector<double> inflow;
80
81 // Surface layer
82 std::vector<double> surf_store;
83 std::vector<double> surf_rough;
84 std::vector<double> surf_slope;
85
86 // Soil layer
87 std::vector<double> soil_thick;
88 std::vector<double> soil_poros;
89 std::vector<double> soil_fc;
90 std::vector<double> soil_wp;
91 std::vector<double> soil_ksat;
92 std::vector<double> soil_kslope;
93 std::vector<double> soil_suction;
94
95 // Storage layer
96 std::vector<double> stor_thick;
97 std::vector<double> stor_void;
98 std::vector<double> stor_ksat;
99 std::vector<double> stor_clog;
100 std::vector<int> stor_covered;
101
102 // Drain
103 std::vector<double> drain_coeff;
104 std::vector<double> drain_expon;
105 std::vector<double> drain_offset;
106 std::vector<double> drain_delay;
107 std::vector<double> drain_hopen;
108 std::vector<double> drain_hclose;
109 std::vector<int> drain_open;
110
111 // Pavement layer (PERM_PAVEMENT)
112 std::vector<double> pave_thick;
113 std::vector<double> pave_void;
114 std::vector<double> pave_imperv_frac;
115 std::vector<double> pave_ksat;
116 std::vector<double> pave_clog_factor;
117 std::vector<double> pave_regen_days;
118 std::vector<double> pave_regen_deg;
119 std::vector<double> next_regen_day;
120
121 // Drainage mat layer (GREEN_ROOF)
122 std::vector<double> drainmat_thick;
123 std::vector<double> drainmat_void;
124 std::vector<double> drainmat_rough;
125
126 // Surface geometry (for Manning's outflow)
127 std::vector<double> surf_void_frac;
128 std::vector<double> surf_alpha;
129 std::vector<double> surf_side_slope;
130 std::vector<double> full_width;
131 std::vector<double> dry_time;
132
133 // State variables (updated each step)
134 std::vector<double> surf_depth;
135 std::vector<double> soil_moist;
136 std::vector<double> stor_depth;
137 std::vector<double> pave_depth;
138
139 // Outputs (per unit)
140 std::vector<double> surface_runoff;
141 std::vector<double> drain_flow;
142 std::vector<double> evap_loss;
143 std::vector<double> infil_loss;
144
145 // Pollutant drain removal fractions: drain_rmvl[unit * n_pollutants + pollutant]
146 std::vector<double> drain_rmvl;
147 int n_pollutants = 0;
148
149 // Previous flux rates (for Modified Puls time weighting)
150 std::vector<double> f_old_surf;
151 std::vector<double> f_old_soil;
152 std::vector<double> f_old_stor;
153 std::vector<double> f_old_pave;
154
155 // Water balance tracking (cumulative per unit)
156 std::vector<double> wb_inflow;
157 std::vector<double> wb_evap;
158 std::vector<double> wb_infil;
159 std::vector<double> wb_surf_flow;
160 std::vector<double> wb_drain_flow;
161 std::vector<double> wb_init_vol;
162 std::vector<double> wb_final_vol;
163 std::vector<double> vol_treated;
164
165 void resize(int n);
166};
167
168// ============================================================================
169// LID solver
170// ============================================================================
171
173public:
174 void init(SimulationContext& ctx);
175
177 LIDGroupSoA& group(int type_index) { return groups_[static_cast<size_t>(type_index)]; }
178 const LIDGroupSoA& group(int type_index) const { return groups_[static_cast<size_t>(type_index)]; }
179 int numGroups() const { return static_cast<int>(groups_.size()); }
180
195 void execute(SimulationContext& ctx, double dt,
196 double rainfall, double evap_rate);
197
199 static void batchBioCellFlux(LIDGroupSoA& g, double rainfall,
200 double evap_rate, double dt);
201
203 static void batchBarrelFlux(LIDGroupSoA& g, double rainfall, double dt);
204
206 static void batchSwaleFlux(LIDGroupSoA& g, double rainfall,
207 double evap_rate, double dt);
208
210 static void batchGreenRoofFlux(LIDGroupSoA& g, double rainfall,
211 double evap_rate, double dt);
212
215 static void batchInfilTrenchFlux(LIDGroupSoA& g, double rainfall,
216 double evap_rate, double dt);
217
219 static void batchPavementFlux(LIDGroupSoA& g, double rainfall,
220 double evap_rate, double dt);
221
223 static void batchRoofDisconFlux(LIDGroupSoA& g, double rainfall,
224 double evap_rate, double dt);
225
228 static void batchSwaleModPuls(LIDGroupSoA& g, double rainfall,
229 double evap_rate, double dt);
230
231private:
232 std::vector<LIDGroupSoA> groups_;
233};
234
235} // namespace lid
236} // namespace openswmm
237
238#endif // OPENSWMM_LID_HPP
Definition LID.hpp:172
int numGroups() const
Definition LID.hpp:179
static void batchPavementFlux(LIDGroupSoA &g, double rainfall, double evap_rate, double dt)
Batch permeable pavement flux rates — VECTORISABLE.
Definition LID.cpp:955
void execute(SimulationContext &ctx, double dt, double rainfall, double evap_rate)
Compute LID performance for all units (batch by type).
Definition LID.cpp:1313
static void batchGreenRoofFlux(LIDGroupSoA &g, double rainfall, double evap_rate, double dt)
Batch green roof flux rates — VECTORISABLE.
Definition LID.cpp:779
static void batchSwaleFlux(LIDGroupSoA &g, double rainfall, double evap_rate, double dt)
Batch vegetative swale flux rates — VECTORISABLE.
Definition LID.cpp:638
LIDGroupSoA & group(int type_index)
Access a type group (for testing or external queries).
Definition LID.hpp:177
static void batchRoofDisconFlux(LIDGroupSoA &g, double rainfall, double evap_rate, double dt)
Batch roof disconnection flux rates — VECTORISABLE.
Definition LID.cpp:1243
static void batchBioCellFlux(LIDGroupSoA &g, double rainfall, double evap_rate, double dt)
Batch bio-cell flux rates — VECTORISABLE.
Definition LID.cpp:382
const LIDGroupSoA & group(int type_index) const
Definition LID.hpp:178
static void batchSwaleModPuls(LIDGroupSoA &g, double rainfall, double evap_rate, double dt)
Definition LID.cpp:689
static void batchInfilTrenchFlux(LIDGroupSoA &g, double rainfall, double evap_rate, double dt)
Definition LID.cpp:527
void init(SimulationContext &ctx)
Definition LID.cpp:161
static void batchBarrelFlux(LIDGroupSoA &g, double rainfall, double dt)
Batch rain barrel flux rates — VECTORISABLE (simplest)
Definition LID.cpp:469
constexpr int STOR
Definition LID.hpp:59
constexpr int SOIL
Definition LID.hpp:58
constexpr int N_LAYERS
Definition LID.hpp:61
LIDType
Definition LID.hpp:42
constexpr int PAVE
Definition LID.hpp:60
constexpr int SURF
Definition LID.hpp:57
Definition NodeCoupling.cpp:15
Central, reentrant simulation context.
Definition SimulationContext.hpp:274
Definition LID.hpp:67
std::vector< double > soil_wp
Soil wilting point.
Definition LID.hpp:90
std::vector< double > pave_void
Pavement void fraction.
Definition LID.hpp:113
std::vector< double > pave_imperv_frac
Impervious fraction of pavement.
Definition LID.hpp:114
std::vector< double > surface_runoff
Definition LID.hpp:140
std::vector< double > soil_thick
Soil thickness (ft)
Definition LID.hpp:87
std::vector< double > wb_evap
Total evaporation volume (ft)
Definition LID.hpp:157
std::vector< int > control_idx
LID control index (into ctx.lid_controls)
Definition LID.hpp:72
std::vector< double > surf_alpha
Surface Manning alpha = sqrt(slope)/n.
Definition LID.hpp:128
std::vector< double > pave_regen_days
Pavement regeneration interval (days)
Definition LID.hpp:117
std::vector< int > drain_subcatch
Resolved drain-to subcatch index (-1=none)
Definition LID.hpp:78
std::vector< double > drain_coeff
Drain coefficient.
Definition LID.hpp:103
std::vector< double > drain_hopen
Head to open drain valve (ft)
Definition LID.hpp:107
std::vector< int > drain_node
Resolved drain-to node index (-1=none)
Definition LID.hpp:77
std::vector< double > inflow
Per-unit inflow rate (ft/sec) — set before execute()
Definition LID.hpp:79
std::vector< int > drain_open
Current drain valve state (1=open, 0=closed)
Definition LID.hpp:109
std::vector< double > f_old_stor
Previous storage flux rate.
Definition LID.hpp:152
std::vector< double > drain_hclose
Head to close drain valve (ft)
Definition LID.hpp:108
std::vector< double > drain_expon
Drain exponent.
Definition LID.hpp:104
std::vector< double > wb_surf_flow
Total surface outflow volume (ft)
Definition LID.hpp:159
std::vector< double > pave_thick
Pavement thickness (ft)
Definition LID.hpp:112
std::vector< double > surf_depth
Current surface ponded depth.
Definition LID.hpp:134
std::vector< double > pave_ksat
Pavement saturated K (ft/sec)
Definition LID.hpp:115
std::vector< double > stor_ksat
Storage exfiltration K (ft/sec)
Definition LID.hpp:98
std::vector< double > surf_slope
Surface slope.
Definition LID.hpp:84
std::vector< double > stor_void
Storage void fraction.
Definition LID.hpp:97
std::vector< double > wb_final_vol
Final stored volume (ft)
Definition LID.hpp:162
std::vector< double > soil_kslope
Conductivity slope.
Definition LID.hpp:92
int n_pollutants
Number of pollutants (for indexing drain_rmvl)
Definition LID.hpp:147
std::vector< double > soil_poros
Soil porosity.
Definition LID.hpp:88
std::vector< double > dry_time
Seconds since last rainfall.
Definition LID.hpp:131
std::vector< double > stor_thick
Storage thickness (ft)
Definition LID.hpp:96
std::vector< double > surf_store
Surface storage depth (ft)
Definition LID.hpp:82
std::vector< double > drainmat_thick
Drainage mat thickness (ft)
Definition LID.hpp:122
std::vector< double > soil_ksat
Soil saturated K (ft/sec)
Definition LID.hpp:91
std::vector< double > f_old_surf
Previous surface flux rate.
Definition LID.hpp:150
std::vector< double > drain_flow
Definition LID.hpp:141
void resize(int n)
Definition LID.cpp:61
std::vector< double > wb_infil
Total exfiltration volume (ft)
Definition LID.hpp:158
std::vector< double > wb_init_vol
Initial stored volume (ft)
Definition LID.hpp:161
std::vector< double > f_old_pave
Previous pavement flux rate.
Definition LID.hpp:153
std::vector< double > surf_rough
Surface Manning's n.
Definition LID.hpp:83
std::vector< double > soil_suction
Suction head for Green-Ampt (ft)
Definition LID.hpp:93
std::vector< double > pave_regen_deg
Pavement regeneration degree (0-1)
Definition LID.hpp:118
std::vector< double > full_width
Full width for Manning's flow (ft)
Definition LID.hpp:130
std::vector< double > wb_inflow
Total inflow volume (ft)
Definition LID.hpp:156
std::vector< double > f_old_soil
Previous soil flux rate.
Definition LID.hpp:151
std::vector< double > pave_clog_factor
Pavement clog factor (ft of treated volume)
Definition LID.hpp:116
std::vector< int > stor_covered
1 if rain barrel is covered (blocks rainfall)
Definition LID.hpp:100
std::vector< double > wb_drain_flow
Total drain outflow volume (ft)
Definition LID.hpp:160
std::vector< double > drainmat_rough
Drainage mat Manning's roughness.
Definition LID.hpp:124
std::vector< int > subcatch_idx
Which subcatchment this unit belongs to.
Definition LID.hpp:71
std::vector< double > pave_depth
Current pavement depth.
Definition LID.hpp:137
std::vector< double > stor_depth
Current storage depth.
Definition LID.hpp:136
std::vector< double > infil_loss
Definition LID.hpp:143
std::vector< double > surf_void_frac
Surface void fraction (default 1.0)
Definition LID.hpp:127
LIDType type
Definition LID.hpp:68
std::vector< int > to_perv
Route surface outflow to pervious area (1=yes)
Definition LID.hpp:76
std::vector< double > drain_delay
Drain delay time (sec, rain barrel)
Definition LID.hpp:106
std::vector< double > area
Unit area (ft2)
Definition LID.hpp:73
std::vector< double > evap_loss
Definition LID.hpp:142
int count
Definition LID.hpp:69
std::vector< double > from_perv
Fraction of pervious runoff treated (0-1)
Definition LID.hpp:75
std::vector< double > stor_clog
Storage clogging factor (ft)
Definition LID.hpp:99
std::vector< double > next_regen_day
Next day for pavement regeneration (OADate)
Definition LID.hpp:119
std::vector< double > soil_fc
Soil field capacity.
Definition LID.hpp:89
std::vector< double > surf_side_slope
Swale side slope (run/rise)
Definition LID.hpp:129
std::vector< double > vol_treated
Cumulative volume treated (ft, for clog model)
Definition LID.hpp:163
std::vector< double > drainmat_void
Drainage mat void fraction.
Definition LID.hpp:123
std::vector< double > from_imperv
Fraction of impervious runoff treated (0-1)
Definition LID.hpp:74
std::vector< double > drain_rmvl
Removal fraction per unit per pollutant.
Definition LID.hpp:146
std::vector< double > drain_offset
Drain offset depth (ft)
Definition LID.hpp:105
std::vector< double > soil_moist
Current soil moisture (0-porosity)
Definition LID.hpp:135