OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches
Snow.hpp
Go to the documentation of this file.
1
24#ifndef OPENSWMM_SNOW_HPP
25#define OPENSWMM_SNOW_HPP
26
27#include <vector>
28
29namespace openswmm {
30
31struct SimulationContext;
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: area fractions
70 std::vector<double> snn;
71
72 // Per subcatchment: plowing parameters
73 std::vector<double> weplow;
74 std::vector<double> sfrac;
77 std::vector<int> to_subcatch;
78
79 // Global parameters
80 double tipm = 0.5;
81 double rnm = 0.6;
82
83 void resize(int n);
84};
85
86// ============================================================================
87// Snow solver
88// ============================================================================
89
91public:
92 void init(int n_subcatch);
93
114 void execute(SimulationContext& ctx, double dt,
115 double temp, double wind, double rainfall,
116 double gamma = 0.0, double ea = 0.0);
117
123 void setMeltCoeffs(int day_of_year);
124
132 void plowSnow(SimulationContext& ctx, double dt, double snowfall);
133
134 SnowSoA& state() { return soa_; }
135
136private:
137 SnowSoA soa_;
138
140 static void batchATIUpdate(double* ati, double temp, double tipm,
141 double dt, int count);
142
144 static void batchDegreeDayMelt(const double* dhm, const double* tbase,
145 double temp, double* melt, int count);
146
148 static void batchRainOnSnowMelt(double temp, double wind, double gamma,
149 double ea, double rainfall,
150 double* melt, int count);
151
153 static void batchAccumulate(double* wsnow, double snowfall, double dt, int count);
154};
155
156} // namespace snow
157} // namespace openswmm
158
159#endif // OPENSWMM_SNOW_HPP
Definition Snow.hpp:90
SnowSoA & state()
Definition Snow.hpp:134
void execute(SimulationContext &ctx, double dt, double temp, double wind, double rainfall, double gamma=0.0, double ea=0.0)
Compute snowmelt for all subcatchments (batch).
Definition Snow.cpp:115
void init(int n_subcatch)
Definition Snow.cpp:42
void setMeltCoeffs(int day_of_year)
Update seasonal melt coefficients based on day of year.
Definition Snow.cpp:226
void plowSnow(SimulationContext &ctx, double dt, double snowfall)
Snow plowing — redistribute excess snow between subareas.
Definition Snow.cpp:247
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 Controls.cpp:24
Central, reentrant simulation context.
Definition SimulationContext.hpp:141
Definition Snow.hpp:48
std::vector< double > sfrac
Definition Snow.hpp:74
std::vector< int > to_subcatch
Target subcatchment for plowed snow.
Definition Snow.hpp:77
std::vector< double > fwfrac
Free water capacity fraction.
Definition Snow.hpp:64
std::vector< double > dhmin
Min melt coeff (winter solstice) (ft/deg-F/sec)
Definition Snow.hpp:62
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
std::vector< double > awe
Areal depletion index.
Definition Snow.hpp:56
double tipm
ATI weighting factor.
Definition Snow.hpp:80
int n_subcatch
Definition Snow.hpp:49
double rnm
Negative melt ratio.
Definition Snow.hpp:81
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:70
void resize(int n)
Definition Snow.cpp:19
std::vector< double > fw
Free water in pack (ft)
Definition Snow.hpp:53
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:73