OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
Snow.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
39
40#ifndef OPENSWMM_SNOW_HPP
41#define OPENSWMM_SNOW_HPP
42
43#include <vector>
44
45namespace openswmm {
46
48
49namespace snow {
50
51// ============================================================================
52// Constants
53// ============================================================================
54
55constexpr int N_SUBAREAS = 3;
56constexpr int SNOW_PLOWABLE = 0;
57constexpr int SNOW_IMPERV = 1;
58constexpr int SNOW_PERV = 2;
59
60// ============================================================================
61// Per-subcatchment snowpack state (SoA for vectorization)
62// ============================================================================
63
64struct SnowSoA {
65 int n_subcatch = 0;
66
67 // Per subcatchment × 3 subareas = flat arrays [subcatch * 3 + subarea]
68 std::vector<double> wsnow;
69 std::vector<double> fw;
70 std::vector<double> coldc;
71 std::vector<double> ati;
72 std::vector<double> awe;
73 std::vector<double> imelt;
74
75 // Per subcatchment × 3 subareas: parameters
76 std::vector<double> tbase;
77 std::vector<double> dhm;
78 std::vector<double> dhmin;
79 std::vector<double> dhmax;
80 std::vector<double> fwfrac;
81
82 // Per subcatchment × 3 subareas: area fractions
83 std::vector<double> fArea;
84
100 std::vector<double> age;
109 std::vector<double> out_age;
110
111 // Per subcatchment × 3 subareas: areal depletion state
112 std::vector<double> si;
113 std::vector<double> sba;
114 std::vector<double> sbws;
115 std::vector<double> asc;
116
117 // Global ADC curves (shared by all subcatchments, 10 points each)
118 double adc_imperv[10] = {1,1,1,1,1,1,1,1,1,1};
119 double adc_perv[10] = {1,1,1,1,1,1,1,1,1,1};
120
121 // Per subcatchment: area fractions
122 std::vector<double> snn;
123
124 // Per subcatchment: plowing parameters
125 std::vector<double> weplow;
126 std::vector<double> sfrac;
129 std::vector<int> to_subcatch;
130
131 // Global parameters
132 double tipm = 0.5;
133 double rnm = 0.6;
134 double season = 0.0;
135 double removed = 0.0;
136
143 double precip_age = 0.0;
150 bool track_age = false;
151
152 void resize(int n);
153};
154
155// ============================================================================
156// Snow solver
157// ============================================================================
158
160public:
161 void init(int n_subcatch);
162
186 void execute(SimulationContext& ctx, double dt,
187 double temp, double wind, const double* rainfall,
188 const double* snowfall,
189 double gamma = 0.0, double ea = 0.0);
190
195 void execute(SimulationContext& ctx, double dt,
196 double temp, double wind, double rainfall,
197 double snowfall = 0.0,
198 double gamma = 0.0, double ea = 0.0);
199
205 void setMeltCoeffs(int day_of_year);
206
216 void plowSnow(SimulationContext& ctx, double dt, const double* snowfall);
217
220 void plowSnow(SimulationContext& ctx, double dt, double snowfall);
221
222 SnowSoA& state() { return soa_; }
223 const SnowSoA& state() const { return soa_; }
224
225private:
226 SnowSoA soa_;
227
229 static double rainMeltRate(double temp, double wind, double gamma,
230 double ea, double rainfall);
231};
232
233} // namespace snow
234} // namespace openswmm
235
236#endif // OPENSWMM_SNOW_HPP
Definition Snow.hpp:159
const SnowSoA & state() const
Definition Snow.hpp:223
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:225
SnowSoA & state()
Definition Snow.hpp:222
void init(int n_subcatch)
Definition Snow.cpp:74
void setMeltCoeffs(int day_of_year)
Update seasonal melt coefficients based on day of year.
Definition Snow.cpp:449
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:487
Definition Snow.cpp:35
constexpr int SNOW_IMPERV
Definition Snow.hpp:57
constexpr int SNOW_PERV
Definition Snow.hpp:58
constexpr int N_SUBAREAS
Plowable, Impervious, Pervious.
Definition Snow.hpp:55
constexpr int SNOW_PLOWABLE
Definition Snow.hpp:56
Definition NodeCoupling.cpp:16
Central, reentrant simulation context.
Definition SimulationContext.hpp:353
Definition Snow.hpp:64
std::vector< double > sfrac
Definition Snow.hpp:126
double precip_age
Definition Snow.hpp:143
std::vector< int > to_subcatch
Target subcatchment for plowed snow.
Definition Snow.hpp:129
std::vector< double > fwfrac
Free water capacity fraction.
Definition Snow.hpp:80
double removed
Cumulative snow plowed out of system (ft3)
Definition Snow.hpp:135
double adc_perv[10]
Definition Snow.hpp:119
std::vector< double > dhmin
Min melt coeff (winter solstice) (ft/deg-F/sec)
Definition Snow.hpp:78
std::vector< double > asc
Computed areal snow coverage (0–1), per subarea.
Definition Snow.hpp:115
std::vector< double > sbws
Snow water equiv at end of new-snow ADC.
Definition Snow.hpp:114
std::vector< double > coldc
Cold content (ft water equiv)
Definition Snow.hpp:70
std::vector< double > wsnow
Snow water equivalent (ft)
Definition Snow.hpp:68
double adc_imperv[10]
Definition Snow.hpp:118
std::vector< double > age
Definition Snow.hpp:100
std::vector< double > awe
Areal depletion index.
Definition Snow.hpp:72
double tipm
ATI weighting factor.
Definition Snow.hpp:132
int n_subcatch
Definition Snow.hpp:65
double rnm
Negative melt ratio.
Definition Snow.hpp:133
std::vector< double > tbase
Base melt temperature (deg F)
Definition Snow.hpp:76
std::vector< double > imelt
Melt rate output (ft/sec)
Definition Snow.hpp:73
std::vector< double > fArea
Fraction of total area for each subarea.
Definition Snow.hpp:83
std::vector< double > out_age
Definition Snow.hpp:109
std::vector< double > snn
Plowable fraction of impervious area.
Definition Snow.hpp:122
std::vector< double > si
Snow depth for 100% cover (ft)
Definition Snow.hpp:112
void resize(int n)
Definition Snow.cpp:37
double season
Current snowmelt season factor (-1 to +1)
Definition Snow.hpp:134
std::vector< double > fw
Free water in pack (ft)
Definition Snow.hpp:69
std::vector< double > sba
Snow coverage area at start of new-snow ADC.
Definition Snow.hpp:113
bool track_age
Definition Snow.hpp:150
std::vector< double > dhmax
Max melt coeff (summer solstice) (ft/deg-F/sec)
Definition Snow.hpp:79
std::vector< double > ati
Antecedent temperature index (deg F)
Definition Snow.hpp:71
std::vector< double > dhm
Degree-day melt factor (ft/deg-F/sec)
Definition Snow.hpp:77
std::vector< double > weplow
Depth at which plowing begins (ft)
Definition Snow.hpp:125