OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
LID.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2//
3// Copyright 2026 Caleb Buahin
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
41
42#ifndef OPENSWMM_LID_HPP
43#define OPENSWMM_LID_HPP
44
45#include <vector>
46#include <cstddef>
47
48namespace openswmm {
49
51
52namespace lid {
53
54// ============================================================================
55// LID type codes
56// ============================================================================
57
68
69// ============================================================================
70// Layer state (per LID unit)
71// ============================================================================
72
73constexpr int SURF = 0;
74constexpr int SOIL = 1;
75constexpr int STOR = 2;
76constexpr int PAVE = 3;
77constexpr int N_LAYERS = 4;
78
79// ============================================================================
80// LID unit parameters (SoA for batch processing)
81// ============================================================================
82
85 int count = 0;
86
87 // Unit-conversion factors for the model's flow units (legacy UCF()).
88 // Layer parameters are converted to internal ft / ft-per-sec at init();
89 // these two factors also drive the underdrain head/rate conversion in
90 // getDrainRate(). Defaults are the US-customary values (issue #102).
91 double ucf_raindepth = 12.0;
92 double ucf_rainfall = 43200.0;
93
94 std::vector<int> subcatch_idx;
95 std::vector<int> control_idx;
96 std::vector<double> area;
97 std::vector<double> from_imperv;
98 std::vector<double> from_perv;
99 std::vector<int> to_perv;
100 std::vector<int> drain_node;
101 std::vector<int> drain_subcatch;
102 std::vector<double> inflow;
103 std::vector<double> evap_rate_unit;
104 std::vector<double> subcatch_rain;
105
106 // Surface layer
107 std::vector<double> surf_store;
108 std::vector<double> surf_rough;
109 std::vector<double> surf_slope;
110
111 // Soil layer
112 std::vector<double> soil_thick;
113 std::vector<double> soil_poros;
114 std::vector<double> soil_fc;
115 std::vector<double> soil_wp;
116 std::vector<double> soil_ksat;
117 std::vector<double> soil_kslope;
118 std::vector<double> soil_suction;
119
120 // Storage layer
121 std::vector<double> stor_thick;
122 std::vector<double> stor_void;
123 std::vector<double> stor_ksat;
124 std::vector<double> stor_clog;
125 std::vector<int> stor_covered;
126
127 // Drain
128 std::vector<double> drain_coeff;
129 std::vector<double> drain_expon;
130 std::vector<double> drain_offset;
131 std::vector<double> drain_delay;
132 std::vector<double> drain_hopen;
133 std::vector<double> drain_hclose;
134 std::vector<int> drain_open;
135
136 // Pavement layer (PERM_PAVEMENT)
137 std::vector<double> pave_thick;
138 std::vector<double> pave_void;
139 std::vector<double> pave_imperv_frac;
140 std::vector<double> pave_ksat;
141 std::vector<double> pave_clog_factor;
142 std::vector<double> pave_regen_days;
143 std::vector<double> pave_regen_deg;
144 std::vector<double> next_regen_day;
145
146 // Drainage mat layer (GREEN_ROOF)
147 std::vector<double> drainmat_thick;
148 std::vector<double> drainmat_void;
149 std::vector<double> drainmat_rough;
150
151 // Surface geometry (for Manning's outflow)
152 std::vector<double> surf_void_frac;
153 std::vector<double> surf_alpha;
154 std::vector<double> surf_side_slope;
155 std::vector<double> full_width;
156 std::vector<double> dry_time;
157
158 // State variables (updated each step)
159 std::vector<double> surf_depth;
160 std::vector<double> soil_moist;
161 std::vector<double> stor_depth;
162 std::vector<double> pave_depth;
163
164 // Outputs (per unit)
165 std::vector<double> surface_runoff;
166 std::vector<double> drain_flow;
167 std::vector<double> evap_loss;
168 std::vector<double> infil_loss;
169
170 // Pollutant drain removal fractions: drain_rmvl[unit * n_pollutants + pollutant]
171 std::vector<double> drain_rmvl;
172 int n_pollutants = 0;
173
174 // ---- A4: per-layer INFLOW rates (ft/sec of water per unit area) ----
175 // Each layer receives from exactly one place: the layer above it in the
176 // present stack, or externally for the topmost present layer. Every
177 // batch*Flux routine already computes these as locals (soil_infil,
178 // soil_perc, pavePerc, storageInflow, ...); they are published here
179 // because a complete-mix age needs the INFLOW and nothing else — the
180 // outflow leaves at the layer's own age.
181 //
182 // These are NOT the `f_old_*` below. Those are the Modified Puls
183 // time-weighting term: `f_old_surf` is the NET dx/dt of the surface
184 // layer, and the other three are never written at all. A net rate of
185 // change is exactly the quantity that made phase A3 report elapsed time
186 // instead of age.
187 std::vector<double> in_surf;
188 std::vector<double> in_pave;
189 std::vector<double> in_soil;
190 std::vector<double> in_stor;
191
192 // Previous flux rates (for Modified Puls time weighting)
193 std::vector<double> f_old_surf;
194 std::vector<double> f_old_soil;
195 std::vector<double> f_old_stor;
196 std::vector<double> f_old_pave;
197
198 // Water balance tracking (cumulative per unit)
199 std::vector<double> wb_inflow;
200 std::vector<double> wb_evap;
201 std::vector<double> wb_infil;
202 std::vector<double> wb_surf_flow;
203 std::vector<double> wb_drain_flow;
204 std::vector<double> wb_init_vol;
205 std::vector<double> wb_final_vol;
206 std::vector<double> vol_treated;
207
208 void resize(int n);
209};
210
211// ============================================================================
212// LID solver
213// ============================================================================
214
216public:
217 void init(SimulationContext& ctx);
218
220 LIDGroupSoA& group(int type_index) { return groups_[static_cast<size_t>(type_index)]; }
221 const LIDGroupSoA& group(int type_index) const { return groups_[static_cast<size_t>(type_index)]; }
222 int numGroups() const { return static_cast<int>(groups_.size()); }
223
227 double storedVolume() const;
228
241 double totalStoredVolume() const;
242 double totalInitVolume() const;
243 double totalInfilVolume() const;
244 double totalEvapVolume() const;
245
262 void execute(SimulationContext& ctx, double dt,
263 double rainfall, double evap_rate);
264
266 static void batchBioCellFlux(LIDGroupSoA& g, double rainfall,
267 const double* evap_rate, double dt);
268
270 static void batchBarrelFlux(LIDGroupSoA& g, double rainfall, double dt);
271
273 static void batchSwaleFlux(LIDGroupSoA& g, double rainfall,
274 const double* evap_rate, double dt);
275
277 static void batchGreenRoofFlux(LIDGroupSoA& g, double rainfall,
278 const double* evap_rate, double dt);
279
282 static void batchInfilTrenchFlux(LIDGroupSoA& g, double rainfall,
283 const double* evap_rate, double dt);
284
286 static void batchPavementFlux(LIDGroupSoA& g, double rainfall,
287 const double* evap_rate, double dt);
288
290 static void batchRoofDisconFlux(LIDGroupSoA& g, double rainfall,
291 const double* evap_rate, double dt);
292
295 static void batchSwaleModPuls(LIDGroupSoA& g, double rainfall,
296 const double* evap_rate, double dt);
297
298private:
299 std::vector<LIDGroupSoA> groups_;
300};
301
302} // namespace lid
303} // namespace openswmm
304
305#endif // OPENSWMM_LID_HPP
Definition LID.hpp:215
static void batchGreenRoofFlux(LIDGroupSoA &g, double rainfall, const double *evap_rate, double dt)
Batch green roof flux rates — VECTORISABLE.
Definition LID.cpp:968
int numGroups() const
Definition LID.hpp:222
void execute(SimulationContext &ctx, double dt, double rainfall, double evap_rate)
Compute LID performance for all units (batch by type).
Definition LID.cpp:1575
static void batchPavementFlux(LIDGroupSoA &g, double rainfall, const double *evap_rate, double dt)
Batch permeable pavement flux rates — VECTORISABLE.
Definition LID.cpp:1151
static void batchSwaleFlux(LIDGroupSoA &g, double rainfall, const double *evap_rate, double dt)
Batch vegetative swale flux rates — VECTORISABLE.
Definition LID.cpp:814
static void batchSwaleModPuls(LIDGroupSoA &g, double rainfall, const double *evap_rate, double dt)
Definition LID.cpp:872
LIDGroupSoA & group(int type_index)
Access a type group (for testing or external queries).
Definition LID.hpp:220
const LIDGroupSoA & group(int type_index) const
Definition LID.hpp:221
static void batchInfilTrenchFlux(LIDGroupSoA &g, double rainfall, const double *evap_rate, double dt)
Definition LID.cpp:695
double totalInfilVolume() const
Definition LID.cpp:1549
void init(SimulationContext &ctx)
Definition LID.cpp:193
double storedVolume() const
Definition LID.cpp:448
static void batchBioCellFlux(LIDGroupSoA &g, double rainfall, const double *evap_rate, double dt)
Batch bio-cell flux rates — VECTORISABLE.
Definition LID.cpp:471
double totalInitVolume() const
Definition LID.cpp:1538
static void batchBarrelFlux(LIDGroupSoA &g, double rainfall, double dt)
Batch rain barrel flux rates — VECTORISABLE (simplest)
Definition LID.cpp:605
double totalEvapVolume() const
Definition LID.cpp:1560
double totalStoredVolume() const
Definition LID.cpp:1527
static void batchRoofDisconFlux(LIDGroupSoA &g, double rainfall, const double *evap_rate, double dt)
Batch roof disconnection flux rates — VECTORISABLE.
Definition LID.cpp:1448
Definition LID.cpp:35
constexpr int STOR
Definition LID.hpp:75
constexpr int SOIL
Definition LID.hpp:74
constexpr int N_LAYERS
Definition LID.hpp:77
LIDType
Definition LID.hpp:58
@ ROOF_DISCON
Definition LID.hpp:66
@ INFIL_TRENCH
Definition LID.hpp:62
@ VEG_SWALE
Definition LID.hpp:65
@ RAIN_BARREL
Definition LID.hpp:64
@ BIO_CELL
Definition LID.hpp:59
@ RAIN_GARDEN
Definition LID.hpp:60
@ GREEN_ROOF
Definition LID.hpp:61
@ PERM_PAVEMENT
Definition LID.hpp:63
constexpr int PAVE
Definition LID.hpp:76
constexpr int SURF
Definition LID.hpp:73
Definition NodeCoupling.cpp:16
Central, reentrant simulation context.
Definition SimulationContext.hpp:353
Definition LID.hpp:83
std::vector< double > soil_wp
Soil wilting point.
Definition LID.hpp:115
double ucf_rainfall
ft/sec → in/hr|mm/hr (RAINFALL)
Definition LID.hpp:92
std::vector< double > pave_void
Pavement void fraction.
Definition LID.hpp:138
std::vector< double > pave_imperv_frac
Impervious fraction of pavement.
Definition LID.hpp:139
std::vector< double > surface_runoff
Definition LID.hpp:165
std::vector< double > soil_thick
Soil thickness (ft)
Definition LID.hpp:112
std::vector< double > wb_evap
Total evaporation volume (ft)
Definition LID.hpp:200
std::vector< int > control_idx
LID control index (into ctx.lid_controls)
Definition LID.hpp:95
std::vector< double > surf_alpha
Surface Manning alpha = sqrt(slope)/n.
Definition LID.hpp:153
std::vector< double > in_surf
External inflow onto the surface.
Definition LID.hpp:187
std::vector< double > pave_regen_days
Pavement regeneration interval (days)
Definition LID.hpp:142
std::vector< int > drain_subcatch
Resolved drain-to subcatch index (-1=none)
Definition LID.hpp:101
std::vector< double > drain_coeff
Drain coefficient.
Definition LID.hpp:128
std::vector< double > drain_hopen
Head to open drain valve (ft)
Definition LID.hpp:132
std::vector< int > drain_node
Resolved drain-to node index (-1=none)
Definition LID.hpp:100
std::vector< double > inflow
Per-unit inflow rate (ft/sec) — set before execute()
Definition LID.hpp:102
std::vector< int > drain_open
Current drain valve state (1=open, 0=closed)
Definition LID.hpp:134
std::vector< double > f_old_stor
Previous storage flux rate.
Definition LID.hpp:195
std::vector< double > drain_hclose
Head to close drain valve (ft)
Definition LID.hpp:133
std::vector< double > drain_expon
Drain exponent.
Definition LID.hpp:129
std::vector< double > wb_surf_flow
Total surface outflow volume (ft)
Definition LID.hpp:202
std::vector< double > pave_thick
Pavement thickness (ft)
Definition LID.hpp:137
std::vector< double > surf_depth
Current surface ponded depth.
Definition LID.hpp:159
std::vector< double > pave_ksat
Pavement saturated K (ft/sec)
Definition LID.hpp:140
std::vector< double > stor_ksat
Storage exfiltration K (ft/sec)
Definition LID.hpp:123
std::vector< double > surf_slope
Surface slope.
Definition LID.hpp:109
std::vector< double > stor_void
Storage void fraction.
Definition LID.hpp:122
std::vector< double > wb_final_vol
Final stored volume (ft)
Definition LID.hpp:205
std::vector< double > subcatch_rain
Parent subcatchment rainfall (ft/sec) — for the rain-barrel dry-time reset (legacy lid....
Definition LID.hpp:104
std::vector< double > soil_kslope
Conductivity slope.
Definition LID.hpp:117
int n_pollutants
Number of pollutants (for indexing drain_rmvl)
Definition LID.hpp:172
std::vector< double > soil_poros
Soil porosity.
Definition LID.hpp:113
std::vector< double > dry_time
Seconds since last rainfall.
Definition LID.hpp:156
std::vector< double > stor_thick
Storage thickness (ft)
Definition LID.hpp:121
std::vector< double > surf_store
Surface storage depth (ft)
Definition LID.hpp:107
std::vector< double > drainmat_thick
Drainage mat thickness (ft)
Definition LID.hpp:147
std::vector< double > soil_ksat
Soil saturated K (ft/sec)
Definition LID.hpp:116
std::vector< double > f_old_surf
Previous surface flux rate.
Definition LID.hpp:193
std::vector< double > drain_flow
Definition LID.hpp:166
std::vector< double > in_stor
Layer above → storage.
Definition LID.hpp:190
void resize(int n)
Definition LID.cpp:86
std::vector< double > wb_infil
Total exfiltration volume (ft)
Definition LID.hpp:201
std::vector< double > wb_init_vol
Initial stored volume (ft)
Definition LID.hpp:204
std::vector< double > f_old_pave
Previous pavement flux rate.
Definition LID.hpp:196
std::vector< double > surf_rough
Surface Manning's n.
Definition LID.hpp:108
std::vector< double > soil_suction
Suction head for Green-Ampt (ft)
Definition LID.hpp:118
std::vector< double > pave_regen_deg
Pavement regeneration degree (0-1)
Definition LID.hpp:143
std::vector< double > full_width
Full width for Manning's flow (ft)
Definition LID.hpp:155
std::vector< double > wb_inflow
Total inflow volume (ft)
Definition LID.hpp:199
std::vector< double > f_old_soil
Previous soil flux rate.
Definition LID.hpp:194
std::vector< double > pave_clog_factor
Pavement clog factor (ft of treated volume)
Definition LID.hpp:141
std::vector< int > stor_covered
1 if rain barrel is covered (blocks rainfall)
Definition LID.hpp:125
std::vector< double > wb_drain_flow
Total drain outflow volume (ft)
Definition LID.hpp:203
std::vector< double > drainmat_rough
Drainage mat Manning's roughness.
Definition LID.hpp:149
std::vector< int > subcatch_idx
Which subcatchment this unit belongs to.
Definition LID.hpp:94
std::vector< double > pave_depth
Current pavement depth.
Definition LID.hpp:162
std::vector< double > stor_depth
Current storage depth.
Definition LID.hpp:161
double ucf_raindepth
ft → in|mm (RAINDEPTH)
Definition LID.hpp:91
std::vector< double > infil_loss
Native infiltration loss this step (ft)
Definition LID.hpp:168
std::vector< double > surf_void_frac
Surface void fraction (default 1.0)
Definition LID.hpp:152
LIDType type
Definition LID.hpp:84
std::vector< double > evap_rate_unit
Per-unit effective PET rate (ft/sec) — filled by execute()
Definition LID.hpp:103
std::vector< double > in_pave
Surface → pavement.
Definition LID.hpp:188
std::vector< int > to_perv
Route surface outflow to pervious area (1=yes)
Definition LID.hpp:99
std::vector< double > drain_delay
Drain delay time (sec, rain barrel)
Definition LID.hpp:131
std::vector< double > area
Unit area (ft2)
Definition LID.hpp:96
std::vector< double > evap_loss
Evaporation loss this step (ft of depth)
Definition LID.hpp:167
int count
Definition LID.hpp:85
std::vector< double > from_perv
Fraction of pervious runoff treated (0-1)
Definition LID.hpp:98
std::vector< double > stor_clog
Storage clogging factor (ft)
Definition LID.hpp:124
std::vector< double > next_regen_day
Next day for pavement regeneration (OADate)
Definition LID.hpp:144
std::vector< double > soil_fc
Soil field capacity.
Definition LID.hpp:114
std::vector< double > in_soil
Layer above → soil.
Definition LID.hpp:189
std::vector< double > surf_side_slope
Swale side slope (run/rise)
Definition LID.hpp:154
std::vector< double > vol_treated
Cumulative volume treated (ft, for clog model)
Definition LID.hpp:206
std::vector< double > drainmat_void
Drainage mat void fraction.
Definition LID.hpp:148
std::vector< double > from_imperv
Fraction of impervious runoff treated (0-1)
Definition LID.hpp:97
std::vector< double > drain_rmvl
Removal fraction per unit per pollutant.
Definition LID.hpp:171
std::vector< double > drain_offset
Drain offset depth (ft)
Definition LID.hpp:130
std::vector< double > soil_moist
Current soil moisture (0-porosity)
Definition LID.hpp:160