OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches
Groundwater.hpp
Go to the documentation of this file.
1
26#ifndef OPENSWMM_GROUNDWATER_HPP
27#define OPENSWMM_GROUNDWATER_HPP
28
29#ifndef OPENSWMM_RESTRICT
30# if defined(_MSC_VER)
31# define OPENSWMM_RESTRICT __restrict
32# else
33# define OPENSWMM_RESTRICT __restrict__
34# endif
35#endif
36
37#include <vector>
38#include "../math/MathExpr.hpp"
39
40namespace openswmm {
41
42struct SimulationContext;
43
44namespace groundwater {
45
47enum GWVar : int {
48 GWV_HGW = 0,
49 GWV_HSW = 1,
50 GWV_HCB = 2,
51 GWV_HGS = 3,
52 GWV_KS = 4,
53 GWV_K = 5,
55 GWV_PHI = 7,
56 GWV_FI = 8,
57 GWV_FU = 9,
58 GWV_A = 10,
59 GWV_MAX = 11
60};
61
63static const char* GW_VAR_NAMES[] = {
64 "HGW", "HSW", "HCB", "HGS", "KS", "K",
65 "THETA", "PHI", "FI", "FU", "A"
66};
67
68// ============================================================================
69// Per-subcatchment GW state (SoA for vectorization)
70// ============================================================================
71
72struct GWSoA {
73 int n_subcatch = 0;
74
75 // Aquifer properties (set at init, constant during sim)
76 std::vector<double> porosity;
77 std::vector<double> field_cap;
78 std::vector<double> wilt_point;
79 std::vector<double> k_sat;
80 std::vector<double> k_slope;
81 std::vector<double> tension_slope;
82 std::vector<double> upper_evap_frac;
83 std::vector<int> upper_evap_pat;
84 std::vector<double> lower_evap_depth;
85 std::vector<double> lower_loss_coeff;
86 std::vector<double> total_depth;
87
88 // Lateral flow coefficients
89 std::vector<double> a1, b1;
90 std::vector<double> a2, b2;
91 std::vector<double> a3;
92 std::vector<double> h_star;
93
94 // State variables (updated each timestep)
95 std::vector<double> theta;
96 std::vector<double> lower_depth;
97
98 // State
99 std::vector<double> old_flow;
100
101 // Outputs
102 std::vector<double> gw_flow;
103 std::vector<double> upper_evap;
104 std::vector<double> lower_evap;
105 std::vector<double> deep_loss;
109 std::vector<double> max_infil_vol;
110
111 // Custom flow expressions (from [GWF] section)
113 std::vector<mathexpr::Expression> lateral_expr;
115 std::vector<mathexpr::Expression> deep_expr;
116
117 void resize(int n);
118};
119
120// ============================================================================
121// GW solver
122// ============================================================================
123
124class GWSolver {
125public:
126 void init(int n_subcatch);
127
146 void execute(SimulationContext& ctx, double dt, double max_evap,
147 const double* infil_rate, const double* sw_head,
148 const double* frac_perv, const double* perv_evap_rate);
149
150 GWSoA& state() { return soa_; }
151 const GWSoA& state() const { return soa_; }
152
153private:
154 GWSoA soa_;
155
157 static void batchUpperPerc(
158 const double* OPENSWMM_RESTRICT theta,
159 const double* OPENSWMM_RESTRICT field_cap,
160 const double* OPENSWMM_RESTRICT k_sat,
161 const double* OPENSWMM_RESTRICT k_slope,
162 double* OPENSWMM_RESTRICT perc,
163 int count
164 );
165
167 static void batchGWFlow(
168 const double* OPENSWMM_RESTRICT lower_depth,
169 const double* OPENSWMM_RESTRICT h_star,
170 const double* OPENSWMM_RESTRICT a1, const double* OPENSWMM_RESTRICT b1,
171 const double* OPENSWMM_RESTRICT a2, const double* OPENSWMM_RESTRICT b2,
172 const double* OPENSWMM_RESTRICT a3,
173 const double* OPENSWMM_RESTRICT sw_head,
174 double* OPENSWMM_RESTRICT gw_flow,
175 int count
176 );
177};
178
179} // namespace groundwater
180} // namespace openswmm
181
182#endif // OPENSWMM_GROUNDWATER_HPP
#define OPENSWMM_RESTRICT
Definition XSectBatch.hpp:41
Definition Groundwater.hpp:124
GWSoA & state()
Definition Groundwater.hpp:150
const GWSoA & state() const
Definition Groundwater.hpp:151
void execute(SimulationContext &ctx, double dt, double max_evap, const double *infil_rate, const double *sw_head, const double *frac_perv, const double *perv_evap_rate)
Compute groundwater for all subcatchments (batch).
Definition Groundwater.cpp:235
void init(int n_subcatch)
Definition Groundwater.cpp:62
GWVar
GW expression variable indices (matching legacy GWvariables enum).
Definition Groundwater.hpp:47
@ GWV_HSW
Surface water head.
Definition Groundwater.hpp:49
@ GWV_HCB
Channel bottom height (h_star)
Definition Groundwater.hpp:50
@ GWV_HGS
Ground surface height (total_depth)
Definition Groundwater.hpp:51
@ GWV_K
Unsaturated conductivity.
Definition Groundwater.hpp:53
@ GWV_FU
Upper zone percolation rate.
Definition Groundwater.hpp:57
@ GWV_A
Subcatchment area.
Definition Groundwater.hpp:58
@ GWV_PHI
Porosity.
Definition Groundwater.hpp:55
@ GWV_HGW
Water table height.
Definition Groundwater.hpp:48
@ GWV_MAX
Definition Groundwater.hpp:59
@ GWV_THETA
Upper zone moisture content.
Definition Groundwater.hpp:54
@ GWV_FI
Surface infiltration rate.
Definition Groundwater.hpp:56
@ GWV_KS
Saturated conductivity.
Definition Groundwater.hpp:52
Definition NodeCoupling.cpp:15
Central, reentrant simulation context.
Definition SimulationContext.hpp:274
Definition Groundwater.hpp:72
void resize(int n)
Definition Groundwater.cpp:27
std::vector< double > total_depth
Aquifer thickness (ft)
Definition Groundwater.hpp:86
std::vector< double > gw_flow
Lateral GW flow to node (cfs)
Definition Groundwater.hpp:102
std::vector< double > upper_evap
Upper zone evap (ft3/sec)
Definition Groundwater.hpp:103
std::vector< mathexpr::Expression > lateral_expr
Per-subcatch compiled lateral flow expression (added to standard formula).
Definition Groundwater.hpp:113
std::vector< double > lower_loss_coeff
Deep percolation coeff.
Definition Groundwater.hpp:85
std::vector< double > b2
Surface water interaction.
Definition Groundwater.hpp:90
std::vector< double > theta
Upper zone moisture content (0-φ)
Definition Groundwater.hpp:95
std::vector< double > tension_slope
Definition Groundwater.hpp:81
std::vector< double > porosity
Definition Groundwater.hpp:76
std::vector< double > old_flow
Previous step GW flow (for trapezoidal avg)
Definition Groundwater.hpp:99
std::vector< int > upper_evap_pat
Pattern index for monthly evap adjustment (-1 = none)
Definition Groundwater.hpp:83
std::vector< double > field_cap
Definition Groundwater.hpp:77
std::vector< double > max_infil_vol
Definition Groundwater.hpp:109
std::vector< double > lower_evap_depth
Definition Groundwater.hpp:84
std::vector< double > k_slope
Exponential decay slope.
Definition Groundwater.hpp:80
int n_subcatch
Definition Groundwater.hpp:73
std::vector< double > deep_loss
Definition Groundwater.hpp:105
std::vector< mathexpr::Expression > deep_expr
Per-subcatch compiled deep percolation expression (replaces standard formula).
Definition Groundwater.hpp:115
std::vector< double > b1
GW outflow.
Definition Groundwater.hpp:89
std::vector< double > wilt_point
Definition Groundwater.hpp:78
std::vector< double > a3
Cross-interaction.
Definition Groundwater.hpp:91
std::vector< double > upper_evap_frac
Definition Groundwater.hpp:82
std::vector< double > lower_depth
Lower zone depth (ft)
Definition Groundwater.hpp:96
std::vector< double > k_sat
Saturated conductivity (ft/sec)
Definition Groundwater.hpp:79
std::vector< double > a1
Definition Groundwater.hpp:89
std::vector< double > h_star
Threshold water table height (ft)
Definition Groundwater.hpp:92
std::vector< double > a2
Definition Groundwater.hpp:90
std::vector< double > lower_evap
Lower zone evap (ft3/sec)
Definition Groundwater.hpp:104