OpenSWMM Engine  6.0.0-alpha.3
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.3)
Loading...
Searching...
No Matches
Snow.hpp
Go to the documentation of this file.
1
23
24#ifndef OPENSWMM_SNOW_HPP
25#define OPENSWMM_SNOW_HPP
26
27#include <vector>
28
29namespace openswmm {
30
32
33namespace snow {
34
35// ============================================================================
36// Constants
37// ============================================================================
38
39constexpr int N_SUBAREAS = 3;
40constexpr int SNOW_PLOWABLE = 0;
41constexpr int SNOW_IMPERV = 1;
42constexpr int SNOW_PERV = 2;
43
44// ============================================================================
45// Per-subcatchment snowpack state (SoA for vectorization)
46// ============================================================================
47
48struct SnowSoA {
49 int n_subcatch = 0;
50
51 // Per subcatchment × 3 subareas = flat arrays [subcatch * 3 + subarea]
52 std::vector<double> wsnow;
53 std::vector<double> fw;
54 std::vector<double> coldc;
55 std::vector<double> ati;
56 std::vector<double> awe;
57 std::vector<double> imelt;
58
59 // Per subcatchment × 3 subareas: parameters
60 std::vector<double> tbase;
61 std::vector<double> dhm;
62 std::vector<double> dhmin;
63 std::vector<double> dhmax;
64 std::vector<double> fwfrac;
65
66 // Per subcatchment × 3 subareas: area fractions
67 std::vector<double> fArea;
68
69 // Per subcatchment × 3 subareas: areal depletion state
70 std::vector<double> si;
71 std::vector<double> sba;
72 std::vector<double> sbws;
73 std::vector<double> asc;
74
75 // Global ADC curves (shared by all subcatchments, 10 points each)
76 double adc_imperv[10] = {1,1,1,1,1,1,1,1,1,1};
77 double adc_perv[10] = {1,1,1,1,1,1,1,1,1,1};
78
79 // Per subcatchment: area fractions
80 std::vector<double> snn;
81
82 // Per subcatchment: plowing parameters
83 std::vector<double> weplow;
84 std::vector<double> sfrac;
87 std::vector<int> to_subcatch;
88
89 // Global parameters
90 double tipm = 0.5;
91 double rnm = 0.6;
92 double season = 0.0;
93 double removed = 0.0;
94
95 void resize(int n);
96};
97
98// ============================================================================
99// Snow solver
100// ============================================================================
101
103public:
104 void init(int n_subcatch);
105
129 void execute(SimulationContext& ctx, double dt,
130 double temp, double wind, const double* rainfall,
131 const double* snowfall,
132 double gamma = 0.0, double ea = 0.0);
133
138 void execute(SimulationContext& ctx, double dt,
139 double temp, double wind, double rainfall,
140 double snowfall = 0.0,
141 double gamma = 0.0, double ea = 0.0);
142
148 void setMeltCoeffs(int day_of_year);
149
159 void plowSnow(SimulationContext& ctx, double dt, const double* snowfall);
160
163 void plowSnow(SimulationContext& ctx, double dt, double snowfall);
164
165 SnowSoA& state() { return soa_; }
166 const SnowSoA& state() const { return soa_; }
167
168private:
169 SnowSoA soa_;
170
172 static double rainMeltRate(double temp, double wind, double gamma,
173 double ea, double rainfall);
174};
175
176} // namespace snow
177} // namespace openswmm
178
179#endif // OPENSWMM_SNOW_HPP
Definition Snow.hpp:102
const SnowSoA & state() const
Definition Snow.hpp:166
void execute(SimulationContext &ctx, double dt, double temp, double wind, const double *rainfall, const double *snowfall, double gamma=0.0, double ea=0.0)
Compute snowmelt for all subcatchments (batch).
Definition Snow.cpp:173
SnowSoA & state()
Definition Snow.hpp:165
void init(int n_subcatch)
Definition Snow.cpp:47
void setMeltCoeffs(int day_of_year)
Update seasonal melt coefficients based on day of year.
Definition Snow.cpp:325
void plowSnow(SimulationContext &ctx, double dt, const double *snowfall)
Snow accumulation + plowing — adds new snowfall to each pack and redistributes excess snow between su...
Definition Snow.cpp:354
Definition Snow.cpp:18
constexpr int SNOW_IMPERV
Definition Snow.hpp:41
constexpr int SNOW_PERV
Definition Snow.hpp:42
constexpr int N_SUBAREAS
Plowable, Impervious, Pervious.
Definition Snow.hpp:39
constexpr int SNOW_PLOWABLE
Definition Snow.hpp:40
Definition NodeCoupling.cpp:15
Central, reentrant simulation context.
Definition SimulationContext.hpp:292
Definition Snow.hpp:48
std::vector< double > sfrac
Definition Snow.hpp:84
std::vector< int > to_subcatch
Target subcatchment for plowed snow.
Definition Snow.hpp:87
std::vector< double > fwfrac
Free water capacity fraction.
Definition Snow.hpp:64
double removed
Cumulative snow plowed out of system (ft3)
Definition Snow.hpp:93
double adc_perv[10]
Definition Snow.hpp:77
std::vector< double > dhmin
Min melt coeff (winter solstice) (ft/deg-F/sec)
Definition Snow.hpp:62
std::vector< double > asc
Computed areal snow coverage (0–1), per subarea.
Definition Snow.hpp:73
std::vector< double > sbws
Snow water equiv at end of new-snow ADC.
Definition Snow.hpp:72
std::vector< double > coldc
Cold content (ft water equiv)
Definition Snow.hpp:54
std::vector< double > wsnow
Snow water equivalent (ft)
Definition Snow.hpp:52
double adc_imperv[10]
Definition Snow.hpp:76
std::vector< double > awe
Areal depletion index.
Definition Snow.hpp:56
double tipm
ATI weighting factor.
Definition Snow.hpp:90
int n_subcatch
Definition Snow.hpp:49
double rnm
Negative melt ratio.
Definition Snow.hpp:91
std::vector< double > tbase
Base melt temperature (deg F)
Definition Snow.hpp:60
std::vector< double > imelt
Melt rate output (ft/sec)
Definition Snow.hpp:57
std::vector< double > fArea
Fraction of total area for each subarea.
Definition Snow.hpp:67
std::vector< double > snn
Plowable fraction of impervious area.
Definition Snow.hpp:80
std::vector< double > si
Snow depth for 100% cover (ft)
Definition Snow.hpp:70
void resize(int n)
Definition Snow.cpp:20
double season
Current snowmelt season factor (-1 to +1)
Definition Snow.hpp:92
std::vector< double > fw
Free water in pack (ft)
Definition Snow.hpp:53
std::vector< double > sba
Snow coverage area at start of new-snow ADC.
Definition Snow.hpp:71
std::vector< double > dhmax
Max melt coeff (summer solstice) (ft/deg-F/sec)
Definition Snow.hpp:63
std::vector< double > ati
Antecedent temperature index (deg F)
Definition Snow.hpp:55
std::vector< double > dhm
Degree-day melt factor (ft/deg-F/sec)
Definition Snow.hpp:61
std::vector< double > weplow
Depth at which plowing begins (ft)
Definition Snow.hpp:83