OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
DegreeDaySnow.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 <cstddef>
44#include <vector>
45#include "SnowModel.hpp"
46
47namespace openswmm {
48
50
51namespace snow {
52
53// ============================================================================
54// Constants
55// ============================================================================
56
57constexpr int N_SUBAREAS = 3;
58constexpr int SNOW_PLOWABLE = 0;
59constexpr int SNOW_IMPERV = 1;
60constexpr int SNOW_PERV = 2;
61
62// ============================================================================
63// Per-subcatchment snowpack state (SoA for vectorization)
64// ============================================================================
65
66struct SnowSoA {
67 int n_subcatch = 0;
68 // Native UEB columns publish into the reporting arrays below, but their
69 // water must never also be advanced by the degree-day solver.
70 std::vector<bool> external;
71 std::vector<double> external_net;
72
73 // Per subcatchment × 3 subareas = flat arrays [subcatch * 3 + subarea]
74 std::vector<double> wsnow;
75 std::vector<double> fw;
76 std::vector<double> coldc;
77 std::vector<double> ati;
78 std::vector<double> awe;
79 std::vector<double> imelt;
80
81 // Per subcatchment × 3 subareas: parameters
82 std::vector<double> tbase;
83 std::vector<double> dhm;
84 std::vector<double> dhmin;
85 std::vector<double> dhmax;
86 std::vector<double> fwfrac;
87
88 // Per subcatchment × 3 subareas: area fractions
89 std::vector<double> fArea;
90
106 std::vector<double> age;
107 std::vector<double>
108 ueb_transfer_energy; // pending DD-to-UEB plow heat, kJ/m2 of receiving subarea
109 std::vector<unsigned char> enabled; // driver ownership mask, true by default
111 false; // completed source footprints use actual donor/receiver areas
120 std::vector<double> out_age;
121
122 // Per subcatchment × 3 subareas: areal depletion state
123 std::vector<double> si;
124 std::vector<double> sba;
125 std::vector<double> sbws;
126 std::vector<double> asc;
127
128 // Global ADC curves (shared by all subcatchments, 10 points each)
129 double adc_imperv[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
130 double adc_perv[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
131
132 // Per subcatchment: area fractions
133 std::vector<double> snn;
134
135 // Per subcatchment: plowing parameters
136 std::vector<double> weplow;
137 std::vector<double> sfrac;
140 std::vector<int> to_subcatch;
141
142 // Global parameters
143 double tipm = 0.5;
144 double rnm = 0.6;
145 double season = 0.0;
146 double removed = 0.0;
147
154 double precip_age = 0.0;
161 bool track_age = false;
162
170 void resize(int n);
171};
172
173// ============================================================================
174// Snow solver
175// ============================================================================
176
178public:
183 void init(int n_subcatch);
189 void initializeElements(int n) override { init((n + N_SUBAREAS - 1) / N_SUBAREAS); }
202 void step(int e, const surface::SnowInputs& input, surface::SnowOutputs& output) override;
206 int stateSize() const override { return 12; }
213 void pack(int e, double* output) const override;
219 void unpack(int e, const double* input) override;
220
235 void execute(SimulationContext& ctx, double dt, double temp, double wind,
236 const double* rainfall, const double* snowfall, double gamma = 0.0,
237 double ea = 0.0) override;
238
250 void execute(SimulationContext& ctx, double dt, double temp, double wind, double rainfall,
251 double snowfall = 0.0, double gamma = 0.0, double ea = 0.0);
252
258 void setMeltCoeffs(int day_of_year);
259
275 void plowSnow(SimulationContext& ctx, double dt, const double* snowfall) override;
276
283 void plowSnow(SimulationContext& ctx, double dt, double snowfall);
284
289 SnowSoA& state() { return soa_; }
294 const SnowSoA& state() const { return soa_; }
295
296private:
297 SnowSoA soa_;
310 void meltElement(std::size_t ui, int subarea, double dt, double temp, double rain, double snow,
311 double rmelt);
312
321 static double rainMeltRate(double temp, double wind, double gamma, double ea, double rainfall);
322};
323
325} // namespace snow
326} // namespace openswmm
327
328namespace openswmm::surface {
330}
331
332#endif // OPENSWMM_SNOW_HPP
Shared snow model contracts and state types.
Definition DegreeDaySnow.hpp:177
SnowSoA & state()
Borrow mutable native geometry, controls, ownership and pack history.
Definition DegreeDaySnow.hpp:289
const SnowSoA & state() const
Borrow immutable current native snow state and liquid-flux outputs.
Definition DegreeDaySnow.hpp:294
void step(int e, const surface::SnowInputs &input, surface::SnowOutputs &output) override
Accumulate and melt one SI point element without batch plowing.
Definition DegreeDaySnow.cpp:458
void initializeElements(int n) override
Allocate native storage rounded up to whole three-element packs.
Definition DegreeDaySnow.hpp:189
int stateSize() const override
Read the fixed native per-element payload size.
Definition DegreeDaySnow.hpp:206
void unpack(int e, const double *input) override
Assign twelve native element history fields from a matching payload.
Definition DegreeDaySnow.cpp:495
void init(int n_subcatch)
Reset native three-subarea storage through SnowSoA::resize().
Definition DegreeDaySnow.cpp:79
void plowSnow(SimulationContext &ctx, double dt, const double *snowfall) override
Add native snowfall once, age packs, then redistribute plowable solid snow.
Definition DegreeDaySnow.cpp:546
void pack(int e, double *output) const override
Copy twelve native element history values without validating the buffer.
Definition DegreeDaySnow.cpp:488
void setMeltCoeffs(int day_of_year)
Update every native subarea's seasonal degree-day coefficient.
Definition DegreeDaySnow.cpp:508
void execute(SimulationContext &ctx, double dt, double temp, double wind, const double *rainfall, const double *snowfall, double gamma=0.0, double ea=0.0) override
Melt every enabled native-owned batch pack after snowfall/plowing preparation.
Definition DegreeDaySnow.cpp:368
Polymorphic point and native-batch snow boundary. One owner serializes state mutation and buffer use....
Definition SnowModel.hpp:44
Definition CatchmentHandler.cpp:70
Definition DegreeDaySnow.cpp:36
constexpr int SNOW_IMPERV
Definition DegreeDaySnow.hpp:59
constexpr int SNOW_PERV
Definition DegreeDaySnow.hpp:60
DegreeDaySnow SnowSolver
Definition DegreeDaySnow.hpp:324
constexpr int N_SUBAREAS
Plowable, Impervious, Pervious.
Definition DegreeDaySnow.hpp:57
constexpr int SNOW_PLOWABLE
Definition DegreeDaySnow.hpp:58
Definition GroundHeat.hpp:19
snow::DegreeDaySnow DegreeDaySnow
Definition DegreeDaySnow.hpp:329
Definition ExchangeLaw.hpp:60
Central, reentrant simulation context.
Definition SimulationContext.hpp:390
Definition DegreeDaySnow.hpp:66
std::vector< double > sfrac
Definition DegreeDaySnow.hpp:137
double precip_age
Definition DegreeDaySnow.hpp:154
std::vector< unsigned char > enabled
Definition DegreeDaySnow.hpp:109
std::vector< int > to_subcatch
Target subcatchment for plowed snow.
Definition DegreeDaySnow.hpp:140
std::vector< double > fwfrac
Free water capacity fraction.
Definition DegreeDaySnow.hpp:86
double removed
Cumulative snow plowed out of system (ft3)
Definition DegreeDaySnow.hpp:146
double adc_perv[10]
Definition DegreeDaySnow.hpp:130
std::vector< double > dhmin
Min melt coeff (winter solstice) (ft/deg-F/sec)
Definition DegreeDaySnow.hpp:84
std::vector< double > asc
Computed areal snow coverage (0–1), per subarea.
Definition DegreeDaySnow.hpp:126
std::vector< double > sbws
Snow water equiv at end of new-snow ADC.
Definition DegreeDaySnow.hpp:125
std::vector< double > external_net
UEB melt plus throughfall, ft/s.
Definition DegreeDaySnow.hpp:71
std::vector< double > coldc
Cold content (ft water equiv)
Definition DegreeDaySnow.hpp:76
std::vector< double > wsnow
Snow water equivalent (ft)
Definition DegreeDaySnow.hpp:74
std::vector< double > ueb_transfer_energy
Definition DegreeDaySnow.hpp:108
double adc_imperv[10]
Definition DegreeDaySnow.hpp:129
std::vector< double > age
Definition DegreeDaySnow.hpp:106
std::vector< double > awe
Areal depletion index.
Definition DegreeDaySnow.hpp:78
double tipm
ATI weighting factor.
Definition DegreeDaySnow.hpp:143
int n_subcatch
Definition DegreeDaySnow.hpp:67
double rnm
Negative melt ratio.
Definition DegreeDaySnow.hpp:144
std::vector< double > tbase
Base melt temperature (deg F)
Definition DegreeDaySnow.hpp:82
std::vector< double > imelt
Melt rate output (ft/sec)
Definition DegreeDaySnow.hpp:79
std::vector< double > fArea
Fraction of total area for each subarea.
Definition DegreeDaySnow.hpp:89
std::vector< double > out_age
Definition DegreeDaySnow.hpp:120
std::vector< double > snn
Plowable fraction of impervious area.
Definition DegreeDaySnow.hpp:133
std::vector< double > si
Snow depth for 100% cover (ft)
Definition DegreeDaySnow.hpp:123
bool conservative_plowing
Definition DegreeDaySnow.hpp:110
void resize(int n)
Reset/rescale all per-source/per-surface arrays for n three-surface packs.
Definition DegreeDaySnow.cpp:38
std::vector< bool > external
Definition DegreeDaySnow.hpp:70
double season
Current snowmelt season factor (-1 to +1)
Definition DegreeDaySnow.hpp:145
std::vector< double > fw
Free water in pack (ft)
Definition DegreeDaySnow.hpp:75
std::vector< double > sba
Snow coverage area at start of new-snow ADC.
Definition DegreeDaySnow.hpp:124
bool track_age
Definition DegreeDaySnow.hpp:161
std::vector< double > dhmax
Max melt coeff (summer solstice) (ft/deg-F/sec)
Definition DegreeDaySnow.hpp:85
std::vector< double > ati
Antecedent temperature index (deg F)
Definition DegreeDaySnow.hpp:77
std::vector< double > dhm
Degree-day melt factor (ft/deg-F/sec)
Definition DegreeDaySnow.hpp:83
std::vector< double > weplow
Depth at which plowing begins (ft)
Definition DegreeDaySnow.hpp:136
One element's interval weather, with SI point-input units. dt_s is seconds; rain_m/snow_m are interva...
Definition SnowModel.hpp:23
Point snow results: interval depths metres and model-specific thermal state. melt_m can include pack ...
Definition SnowModel.hpp:35