OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
SubsurfaceData.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
48
49#ifndef OPENSWMM_ENGINE_2D_SUBSURFACE_DATA_HPP
50#define OPENSWMM_ENGINE_2D_SUBSURFACE_DATA_HPP
51
52#include <cstdint>
53#include <string>
54#include <vector>
55#include "SurfaceOwnership.hpp"
56
57namespace openswmm::twoD {
58
62enum class SoilChar : int8_t {
63 RUSSO = 0,
64 GARDNER = 1,
67};
68
70enum class GwClosure : int8_t {
71 AUTO = -1,
74 SIGMA = 2
75};
76
79struct GwNodeBed {
80 int node = -1;
81 int cell = -1;
82 double Kc = 0.0;
83 double dC = 0.0;
84 double area = 0.0;
87 bool locate = false;
91 bool exchange = true;
94 bool automatic = false;
95};
96
103enum class GwLinkMode : int8_t { NONE = 0, AUTO = 1, TWO_WAY = 2, DEFAULT = 3 };
104
107struct GwLinkRow {
108 int link = -1;
109 double Kc = 0.0;
110 double dC = 0.0;
111 bool exchange = true;
112};
113
120 int link = -1;
121 int cell = -1;
122 double weight = 0.0;
123 struct Contact {
124 double weight, begin, end;
125 };
126 std::vector<Contact> contacts;
127};
128
136 int subcatch = -1;
137 int cell = -1;
138 double weight = 0.0;
139};
140
142struct GwOptions {
145 int m_layers = 8;
146 bool capillary_diff = false;
147 double c_gw = 0.5;
148 double c_col = 0.9;
149 bool force_closed_form = false;
153 bool per_subcatch = false;
157 bool dunne = true;
160 std::string gw_et = "AUTO";
161 double wilting_suction = 150.0;
168 bool node_auto = true;
180 bool authored = false;
181};
182
186 int scope = 0;
187 std::string tag;
188 int cell = -1;
189
190 double Ks = 1.0e-5;
191 double zs = 5.0;
192 double theta_s = 0.45;
193 double theta_r = 0.10;
194 double alpha = 2.0;
196 double psi_b = 0.20;
197 double lambda = 0.40;
199 double vg_n = 1.6;
200 double vg_L = 0.5;
202 double c_loss = 0.0;
204 double hg0 = -1.0;
205
208 int m_layers = -1;
209 bool soil_char_set = false, closure_set = false;
210};
211
220 int n_cells = 0;
221 int m_layers = 0;
222
223 // ---- resolved parameters (per cell) ---------------------------------
224 std::vector<double> Ks, zs, theta_s, theta_r, alpha;
225 std::vector<double> psi_b, lambda, vg_n, vg_L, c_loss;
226 std::vector<int8_t> soil_char;
227 std::vector<int8_t> closure;
228 std::vector<double> area;
229 std::vector<double> z_bed;
230
231 // ---- state ----------------------------------------------------------
232 std::vector<double> hg;
233 std::vector<double> hu;
237 std::vector<double> theta_sigma;
238
239 // ---- per-firing diagnostics + transport donors ------------------------
240 std::vector<double> q0_last;
241 std::vector<double> qnode_last;
242 std::vector<double> qlat_last;
243 std::vector<double> qdeep_last;
244 std::vector<double> qet_last;
245 std::vector<double> dunne_last;
246 std::vector<double> qplus_last;
249 std::vector<double> dunne_cumulative;
250 // R3: atmospheric demand is integrated at the surface cadence, in m3.
254 std::vector<double> qlink_last;
255
256 // ---- LTS ------------------------------------------------------------
257 std::vector<double> dt_cell;
258 std::vector<uint8_t> tier;
263 std::vector<double> eacc_L, eacc_R;
266 std::vector<double> xacc_from_surface;
269 std::vector<double> xacc_to_surface;
272 std::vector<double> nacc;
277 std::vector<double> lacc;
278
279 // ---- ledger (m³, cumulative) ----------------------------------------
280 double led_recharge = 0.0;
281 double led_lateral = 0.0;
282 double led_deep = 0.0;
283 double led_node = 0.0;
284 double led_reject = 0.0;
285 double led_dunne = 0.0;
286 double led_caprise = 0.0;
287 double led_et = 0.0;
288 double led_infil_in = 0.0;
289 double led_link = 0.0;
293 double led_subcatch_in = 0.0;
294 double led_init_storage = 0.0;
295 double led_final_storage = 0.0;
296 double led_source_in = 0.0,
298
299 double led_boundary_in = 0,
301 bool active = false;
315 void resize(int n, int m);
325 double storage() const noexcept;
337 double liveStorage() const noexcept;
347 double ledgeredStorage() const noexcept;
360 double continuityResidual() const noexcept;
361};
362
375 double length = 1.0;
376 double rate = 1.0;
377 double inv_len = 1.0;
378 double area = 1.0;
379};
380
384 int cell = -1, edge = -1;
385 bool head = false;
386 double value = 0.0;
387 std::string series;
388};
389
393 std::vector<GwAquiferRow> rows;
394 std::vector<GwNodeBed> node_beds;
395 std::vector<GwBoundaryRow> boundaries;
396 std::vector<GwLinkRow> link_rows;
397 std::vector<SurfaceOwnerRecord> surface_owners;
405 bool empty() const noexcept {
406 return !options.authored && rows.empty() && node_beds.empty() && link_rows.empty() &&
407 boundaries.empty();
408 }
409
414 void clear() { *this = SubsurfaceConfig{}; }
415};
416
422const char* soilCharToken(SoilChar s) noexcept;
433bool parseSoilChar(const std::string& t, SoilChar& s) noexcept;
439const char* gwClosureToken(GwClosure c) noexcept;
449bool parseGwClosure(const std::string& t, GwClosure& c) noexcept;
450
451} // namespace openswmm::twoD
452
453#endif // OPENSWMM_ENGINE_2D_SUBSURFACE_DATA_HPP
Surface ownership assignments, review states, and validation.
Definition ExchangeLaw.hpp:60
bool parseSoilChar(const std::string &t, SoilChar &s) noexcept
Parse a groundwater token after removing whitespace and folding case.
Definition SubsurfaceData.cpp:189
@ NONE
Definition SolverOptions2D.hpp:116
const char * soilCharToken(SoilChar s) noexcept
Return the canonical token for a soil-characteristic law.
Definition SubsurfaceData.cpp:175
const char * gwClosureToken(GwClosure c) noexcept
Return the canonical token for an unsaturated-zone closure.
Definition SubsurfaceData.cpp:210
SoilChar
Definition SubsurfaceData.hpp:62
@ GARDNER
K = Ks·e^(αψ); the closed form of eq. 22.
Definition SubsurfaceData.hpp:64
@ RUSSO
default; Mualem-consistent, same α slot as Gardner
Definition SubsurfaceData.hpp:63
@ BROOKS_COREY
piecewise about the air-entry pressure
Definition SubsurfaceData.hpp:65
@ VAN_GENUCHTEN
Rosetta/UNSODA parameter databases.
Definition SubsurfaceData.hpp:66
bool parseGwClosure(const std::string &t, GwClosure &c) noexcept
Parse a groundwater token after removing whitespace and folding case.
Definition SubsurfaceData.cpp:224
GwClosure
Unsaturated-zone closure, resolved per cell from AUTO at initialize.
Definition SubsurfaceData.hpp:70
@ CLOSED_FORM
closure A: bulk hu + quasi-steady recharge
Definition SubsurfaceData.hpp:72
@ SIGMA
closure B: explicit σ column of m layers
Definition SubsurfaceData.hpp:74
@ ENSLAVED
closure A reduced: hu algebraic in hg (eq. 39)
Definition SubsurfaceData.hpp:73
@ AUTO
select from αL at initialize (never stored per cell)
Definition SubsurfaceData.hpp:71
GwLinkMode
Definition SubsurfaceData.hpp:103
@ DEFAULT
Definition SubsurfaceData.hpp:103
@ TWO_WAY
Definition SubsurfaceData.hpp:103
@ AUTO
Default: plugins above their size floors, else CPU.
Definition SolverOptions2D.hpp:173
Definition SubsurfaceData.hpp:185
int scope
0 GLOBAL, 1 TAG, 2 CELL (mirrors GwScope)
Definition SubsurfaceData.hpp:186
bool soil_char_set
Definition SubsurfaceData.hpp:209
double theta_r
residual water content
Definition SubsurfaceData.hpp:193
GwClosure closure
Definition SubsurfaceData.hpp:207
int m_layers
< 0 ⇒ the global M_LAYERS
Definition SubsurfaceData.hpp:208
double vg_L
Definition SubsurfaceData.hpp:200
double Ks
saturated hydraulic conductivity (m/s)
Definition SubsurfaceData.hpp:190
double theta_s
porosity / saturated water content
Definition SubsurfaceData.hpp:192
double psi_b
Brooks–Corey: psi_b air-entry head (m, positive) and lambda shape.
Definition SubsurfaceData.hpp:196
double alpha
Definition SubsurfaceData.hpp:194
double hg0
Initial saturated thickness (m). < 0 ⇒ the option default seeds it.
Definition SubsurfaceData.hpp:204
double vg_n
van Genuchten: n (m = 1 − 1/n) and the Mualem exponent L.
Definition SubsurfaceData.hpp:199
std::string tag
Definition SubsurfaceData.hpp:187
double lambda
Definition SubsurfaceData.hpp:197
int cell
0-based
Definition SubsurfaceData.hpp:188
SoilChar soil_char
Definition SubsurfaceData.hpp:206
double c_loss
Deep-loss coefficient (m/s at full saturation): q⁻ = c_loss·hg/zs.
Definition SubsurfaceData.hpp:202
double zs
soil column thickness, bottom→surface (m)
Definition SubsurfaceData.hpp:191
bool closure_set
Definition SubsurfaceData.hpp:209
Definition SubsurfaceData.hpp:383
int edge
Definition SubsurfaceData.hpp:384
bool head
Definition SubsurfaceData.hpp:385
int cell
Definition SubsurfaceData.hpp:384
std::string series
Definition SubsurfaceData.hpp:387
double value
Definition SubsurfaceData.hpp:386
Definition SubsurfaceData.hpp:79
double area
Definition SubsurfaceData.hpp:84
int cell
containing mesh cell, resolved at initialize
Definition SubsurfaceData.hpp:81
bool automatic
Definition SubsurfaceData.hpp:94
int node
1D node index
Definition SubsurfaceData.hpp:80
double Kc
semi-confining bed conductivity (m/s); 0 = direct
Definition SubsurfaceData.hpp:82
double dC
bed thickness (m)
Definition SubsurfaceData.hpp:83
bool exchange
Definition SubsurfaceData.hpp:91
bool locate
Definition SubsurfaceData.hpp:87
[2D_AQUIFER_OPTIONS]. Defaults are the plan's starred values.
Definition SubsurfaceData.hpp:142
SoilChar soil_char
Definition SubsurfaceData.hpp:143
GwLinkMode link_seepage
Definition SubsurfaceData.hpp:178
double c_col
column stability safety factor
Definition SubsurfaceData.hpp:148
std::string gw_et
Definition SubsurfaceData.hpp:160
bool capillary_diff
closure B optional diffusive term (D-N3: OFF)
Definition SubsurfaceData.hpp:146
bool dunne
Definition SubsurfaceData.hpp:157
bool per_subcatch
Definition SubsurfaceData.hpp:153
bool authored
True once any [2D_AQUIFER*] row was authored.
Definition SubsurfaceData.hpp:180
bool wilting_suction_set
Definition SubsurfaceData.hpp:162
double wilting_suction
automatic SI default; authored values are project lengths
Definition SubsurfaceData.hpp:161
int m_layers
σ layers under closure B (global default)
Definition SubsurfaceData.hpp:145
GwClosure closure
Definition SubsurfaceData.hpp:144
double c_gw
saturated stability safety factor
Definition SubsurfaceData.hpp:147
bool node_auto
Definition SubsurfaceData.hpp:168
bool force_closed_form
Definition SubsurfaceData.hpp:149
Definition SubsurfaceData.hpp:135
int subcatch
1D subcatchment index
Definition SubsurfaceData.hpp:136
int cell
mesh cell
Definition SubsurfaceData.hpp:137
double weight
area fraction in (0, 1]
Definition SubsurfaceData.hpp:138
Project-unit → SI multipliers for the four kinds of aquifer number.
Definition SubsurfaceData.hpp:374
double inv_len
1/ft → 1/m, or 1/m → 1/m
Definition SubsurfaceData.hpp:377
double length
ft → m, or m → m
Definition SubsurfaceData.hpp:375
double area
ft² → m², or m² → m²
Definition SubsurfaceData.hpp:378
double rate
in/hr → m/s, or mm/hr → m/s
Definition SubsurfaceData.hpp:376
Everything the parser fills, before resolution onto cells.
Definition SubsurfaceData.hpp:391
bool empty() const noexcept
< Explicit SUBCATCH UNIFORM records; not aquifer activation.
Definition SubsurfaceData.hpp:405
std::vector< GwLinkRow > link_rows
G-X4: [2D_AQUIFER_LINKS].
Definition SubsurfaceData.hpp:396
GwOptions options
Definition SubsurfaceData.hpp:392
void clear()
Replace authored groundwater configuration with its default-constructed state.
Definition SubsurfaceData.hpp:414
std::vector< GwNodeBed > node_beds
Definition SubsurfaceData.hpp:394
std::vector< SurfaceOwnerRecord > surface_owners
Definition SubsurfaceData.hpp:397
std::vector< GwBoundaryRow > boundaries
Definition SubsurfaceData.hpp:395
std::vector< GwAquiferRow > rows
Definition SubsurfaceData.hpp:393
Per-cell resolved parameters and state (SoA).
Definition SubsurfaceData.hpp:219
std::vector< double > et_refresh
Definition SubsurfaceData.hpp:253
double led_recharge
unsat → sat (negative = capillary rise)
Definition SubsurfaceData.hpp:280
double liveStorage() const noexcept
G-O: everything the aquifer HOLDS now, including water parked in a side accumulator (in flight betwee...
Definition SubsurfaceData.cpp:124
double led_lateral
net lateral Darcy across the domain edge
Definition SubsurfaceData.hpp:281
std::vector< double > xacc_from_surface
Definition SubsurfaceData.hpp:266
std::vector< double > dt_cell
min(Δt_g, Δt_u) per cell (s)
Definition SubsurfaceData.hpp:257
void resize(int n, int m)
< the kernel ran this simulation
Definition SubsurfaceData.cpp:38
bool active
Definition SubsurfaceData.hpp:301
std::vector< double > et_pending
Definition SubsurfaceData.hpp:251
std::vector< double > infil_capacity
Definition SubsurfaceData.hpp:247
double led_infil_in
q⁺ delivered from the surface
Definition SubsurfaceData.hpp:288
std::vector< double > hg
saturated thickness (m)
Definition SubsurfaceData.hpp:232
std::vector< double > infil_remaining
Definition SubsurfaceData.hpp:247
std::vector< double > eacc_R
Definition SubsurfaceData.hpp:263
std::vector< double > et_soil_cumulative
Definition SubsurfaceData.hpp:252
std::vector< double > et_surface_cumulative
Definition SubsurfaceData.hpp:251
std::vector< double > infil_refresh
Definition SubsurfaceData.hpp:247
double led_link
Definition SubsurfaceData.hpp:289
std::vector< double > nacc
Definition SubsurfaceData.hpp:272
double led_source_in
Definition SubsurfaceData.hpp:296
std::vector< int8_t > closure
GwClosure, AUTO already resolved.
Definition SubsurfaceData.hpp:227
std::vector< double > theta_r
Definition SubsurfaceData.hpp:224
std::vector< uint8_t > tier
Definition SubsurfaceData.hpp:258
int m_layers
σ layers per closure-B column (fixed)
Definition SubsurfaceData.hpp:221
std::vector< double > et_stress
Definition SubsurfaceData.hpp:253
std::vector< double > hu
Definition SubsurfaceData.hpp:233
std::vector< double > et_potential_cumulative
Definition SubsurfaceData.hpp:251
std::vector< double > zs
Definition SubsurfaceData.hpp:224
std::vector< double > vg_n
Definition SubsurfaceData.hpp:225
std::vector< double > theta_sigma
Definition SubsurfaceData.hpp:237
double led_source_out
wells, m3; separate from node/link exchange
Definition SubsurfaceData.hpp:297
double led_boundary_out
gross split of led_lateral; not counted twice
Definition SubsurfaceData.hpp:300
std::vector< double > et_surface_last
Definition SubsurfaceData.hpp:253
std::vector< double > c_loss
Definition SubsurfaceData.hpp:225
double led_init_storage
Definition SubsurfaceData.hpp:294
std::vector< double > psi_b
Definition SubsurfaceData.hpp:225
std::vector< double > xacc_to_surface
Definition SubsurfaceData.hpp:269
std::vector< double > reject_cumulative
Definition SubsurfaceData.hpp:248
double led_subcatch_in
Definition SubsurfaceData.hpp:293
std::vector< double > area
cell planimetric area (m²)
Definition SubsurfaceData.hpp:228
std::vector< double > theta_s
Definition SubsurfaceData.hpp:224
std::vector< double > qlink_last
G-X3: conduit seepage delivered in (m³/s)
Definition SubsurfaceData.hpp:254
std::vector< double > z_bed
aquifer bottom elevation (m) = cell z − zs
Definition SubsurfaceData.hpp:229
std::vector< double > vg_L
Definition SubsurfaceData.hpp:225
std::vector< double > dunne_last
saturation-excess to the surface (m³/s)
Definition SubsurfaceData.hpp:245
std::vector< double > qnode_last
node exchange (m³/s), + into the pipe
Definition SubsurfaceData.hpp:241
double led_caprise
capillary rise (the negative recharge share)
Definition SubsurfaceData.hpp:286
std::vector< double > et_potential_last
Definition SubsurfaceData.hpp:253
double led_boundary_in
Definition SubsurfaceData.hpp:299
std::vector< double > lambda
Definition SubsurfaceData.hpp:225
std::vector< double > qplus_last
infiltration delivered in (m/s)
Definition SubsurfaceData.hpp:246
std::vector< double > qlat_last
net lateral Darcy into the cell (m³/s)
Definition SubsurfaceData.hpp:242
std::vector< double > q0_last
recharge (m/s), + down, − capillary rise
Definition SubsurfaceData.hpp:240
std::vector< double > alpha
Definition SubsurfaceData.hpp:224
std::vector< double > Ks
Definition SubsurfaceData.hpp:224
double ledgeredStorage() const noexcept
G-O: the storage the LEDGER can account for — holdings less the two surface accumulators,...
Definition SubsurfaceData.cpp:139
std::vector< int8_t > soil_char
SoilChar.
Definition SubsurfaceData.hpp:226
std::vector< double > lacc
Definition SubsurfaceData.hpp:277
double led_deep
deep percolation out
Definition SubsurfaceData.hpp:282
std::vector< double > qdeep_last
deep loss (m/s)
Definition SubsurfaceData.hpp:243
double continuityResidual() const noexcept
G-O: ledgeredStorage − led_init_storage − (in − out) with in = infil_in + lateral.
Definition SubsurfaceData.cpp:148
std::vector< double > eacc_L
Definition SubsurfaceData.hpp:263
double led_et
subsurface ET out
Definition SubsurfaceData.hpp:287
std::vector< double > dunne_cumulative
Definition SubsurfaceData.hpp:249
std::vector< double > reject_last
Definition SubsurfaceData.hpp:248
double storage() const noexcept
Total water in both zones (m³) — the continuity check's storage term.
Definition SubsurfaceData.cpp:98
double led_final_storage
Definition SubsurfaceData.hpp:295
std::vector< double > infil_interval
Definition SubsurfaceData.hpp:247
double led_reject
rejected top-interface delivery returned to surface
Definition SubsurfaceData.hpp:284
std::vector< double > qet_last
subsurface ET (m/s, ≥ 0 out)
Definition SubsurfaceData.hpp:244
int n_cells
Definition SubsurfaceData.hpp:220
double led_node
node exchange, + out of the aquifer
Definition SubsurfaceData.hpp:283
std::vector< double > et_unused_cumulative
Definition SubsurfaceData.hpp:252
std::vector< double > wetting_front
Definition SubsurfaceData.hpp:248
double led_dunne
saturation excess to the surface
Definition SubsurfaceData.hpp:285