OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
MeshSnow.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2
11
12#pragma once
13#include "MeshSnowConfig.hpp"
14#include "UebHeld.hpp"
15#include "DegreeDaySnow.hpp"
16#include <array>
17namespace openswmm {
19}
20namespace openswmm::twoD {
22}
23namespace openswmm::surface {
25 std::string tag;
26 double area = 0, slope = 0, aspect = 0; // horizontal weather footprint m2; degrees
27};
30 stored = 0; // m3
32 stored_energy = 0; // kJ; geometry is UEB cover/depth remapping
33 double prescribed_ground_energy = 0, ground_contact_energy = 0; // kJ; signed positive into UEB
40
43 double residual() const { return initial + precipitation - liquid - sublimation - stored; }
44};
45// Point snow on the remaining mesh weather footprint. Named pack PERVIOUS
46// initial values seed each cell; UEB uses the project pervious ADC curve but
47// mesh snow does not inherit subcatch plowing or snow state.
54class MeshSnow {
55public:
74 std::string initialize(SimulationContext& context,
75 const std::vector<MeshSnowGeometry>& geometry);
93 std::string advance(SimulationContext& context, double start, double end,
94 const std::vector<double>& precipitation_ms,
95 const std::vector<double>& snow_catch);
101 std::string setGroundContactMask(const std::vector<unsigned char>& mask);
115 std::string applyGroundContactEnergy(int cell, double soil_j);
122 std::string saveCheckpoint() const;
137 std::string restoreCheckpoint(const std::string& bytes, bool seed = false);
141 bool active() const { return !active_cells_.empty(); }
145 bool hasUeb() const {
146 for (int cell : active_cells_)
147 if (kind_[cell] == SnowKind::Ueb)
148 return true;
149 return false;
150 }
151
154 bool owns(int cell) const { return cell >= 0 && cell < int(pack_.size()) && pack_[cell] >= 0; }
158 double completedEnd() const { return completed_; }
162 double lastSeconds() const { return last_seconds_; }
167 SnowKind kind(int cell) const { return kind_.at(cell); }
173 const std::array<double, 10>& depletionCurve() const { return depletion_curve_; }
179 const std::vector<double>& liquidRates() const { return liquid_rate_; }
185 const std::vector<double>& exposedFractions() const { return exposed_; }
186 // Hold accepted cover during a split source operator, without advancing it.
191 void useAcceptedExposure();
192 // Adopt only the driver's representable endpoint after an ulp-sized tail.
197 void reanchorCompletedEnd(double end);
203 const std::string& configurationIdentity() const { return identity_; }
209 const std::vector<MeshSnowGeometry>& geometry() const { return geometry_; }
215 const std::vector<SnowOutputs>& outputs() const { return output_; }
221 const std::vector<MeshSnowLedger>& ledgers() const { return ledger_; }
226 bool groundContactEnabled(int cell) const {
227 return cell >= 0 && std::size_t(cell) < ground_contact_.size() &&
228 ground_contact_[cell] != 0;
229 }
230 // Contact on the next thermal interval follows the accepted end-state
231 // cover. exposed_ is an interval average for the ET source, so using it
232 // here would retain contact after a melt-out at the interval boundary.
237 double groundContactFraction(int cell) const {
238 return groundContactEnabled(cell) ? output_.at(cell).cover_frac : 0.;
239 }
240
245 double groundContactSurfaceTemperature(int cell) const { return output_.at(cell).Ts_C; }
251 const std::vector<unsigned char>& groundContactMask() const { return ground_contact_; }
257 const std::vector<ueb::HeldState>& columns() const { return held_; }
258
259private:
261 // A nonnull configuration is the unchanged owner from which this private
262 // stage trial was copied. The stage discards this trial on any later refusal.
263 // Public advance passes null and retains its own runtime rollback copy.
264 std::string advanceTrial(SimulationContext& context, double start, double end,
265 const std::vector<double>& precipitation_ms,
266 const std::vector<double>& snow_catch,
267 const MeshSnow* configuration);
284 std::string advanceInPlace(const MeshSnow& configuration, SimulationContext& context,
285 double start, double end,
286 const std::vector<double>& precipitation_ms,
287 const std::vector<double>& snow_catch);
288 std::string identity_;
289 std::string legacy_identity_;
290 ueb::Parameters parameters_;
291 std::array<double, 10> depletion_curve_{};
292 std::array<double, 4> forcing_{};
293 double completed_ = 0, last_seconds_ = 0, step_ = 3600;
294 std::vector<int> active_cells_, pack_;
295 std::vector<SnowKind> kind_;
296 std::vector<MeshSnowGeometry> geometry_;
297 std::vector<ueb::Site> site_;
298 std::vector<ueb::HeldState> held_;
299 std::vector<double> precipitation_, catch_, liquid_rate_, exposed_;
300 std::vector<unsigned char> ground_contact_;
301 std::vector<SnowOutputs> output_;
302 std::vector<MeshSnowLedger> ledger_;
303 snow::DegreeDaySnow degree_day_;
304};
305} // namespace openswmm::surface
Snowmelt — degree-day and rain-on-snow methods.
Configuration and resolution of mesh snow packs and overrides.
Held forcing and state for Utah Energy Balance snow integration.
Definition DegreeDaySnow.hpp:177
Owned mixed degree-day/UEB snow on remaining mesh weather footprints. Geometry area is horizontal m2;...
Definition MeshSnow.hpp:54
bool groundContactEnabled(int cell) const
Test the stored per-cell reciprocal contact bit.
Definition MeshSnow.hpp:226
const std::array< double, 10 > & depletionCurve() const
Borrow owned snow metadata/state without copying it.
Definition MeshSnow.hpp:173
bool hasUeb() const
Scan active cells for at least one UEB model owner.
Definition MeshSnow.hpp:145
bool owns(int cell) const
Test resolved snowpack ownership for one indexed mesh cell.
Definition MeshSnow.hpp:154
bool active() const
Test whether any nonzero assigned snow weather footprint is owned.
Definition MeshSnow.hpp:141
const std::vector< MeshSnowGeometry > & geometry() const
Borrow owned snow metadata/state without copying it.
Definition MeshSnow.hpp:209
std::string advance(SimulationContext &context, double start, double end, const std::vector< double > &precipitation_ms, const std::vector< double > &snow_catch)
Trial a contiguous interval, publishing internal snow state only after success.
Definition MeshSnow.cpp:195
double completedEnd() const
Read the accepted snow-source frontier.
Definition MeshSnow.hpp:158
double groundContactFraction(int cell) const
Read accepted endpoint cover for the next reciprocal thermal interval.
Definition MeshSnow.hpp:237
double groundContactSurfaceTemperature(int cell) const
Read the latest stored cell snow surface temperature.
Definition MeshSnow.hpp:245
const std::vector< ueb::HeldState > & columns() const
Borrow owned snow metadata/state without copying it.
Definition MeshSnow.hpp:257
const std::vector< double > & exposedFractions() const
Borrow owned snow metadata/state without copying it.
Definition MeshSnow.hpp:185
std::string saveCheckpoint() const
Copy this owner and encode a native version-four accepted/predicted snapshot.
Definition MeshSnow.cpp:629
void reanchorCompletedEnd(double end)
Adopt only an ulp-sized driver endpoint change without advancing physics.
Definition MeshSnow.cpp:256
std::string initialize(SimulationContext &context, const std::vector< MeshSnowGeometry > &geometry)
Build a candidate mixed mesh snow owner from resolved authored assignment scopes.
Definition MeshSnow.cpp:41
const std::string & configurationIdentity() const
Borrow owned snow metadata/state without copying it.
Definition MeshSnow.hpp:203
const std::vector< SnowOutputs > & outputs() const
Borrow owned snow metadata/state without copying it.
Definition MeshSnow.hpp:215
SnowKind kind(int cell) const
Read stored model kind for one allocated cell row.
Definition MeshSnow.hpp:167
std::string restoreCheckpoint(const std::string &bytes, bool seed=false)
Validate a native mesh-snow archive into a private candidate then publish it.
Definition MeshSnow.cpp:642
std::string setGroundContactMask(const std::vector< unsigned char > &mask)
Install reciprocal ground-contact ownership for assigned UEB cells.
Definition MeshSnow.cpp:263
void useAcceptedExposure()
Replace ET exposure for active cells by one minus accepted endpoint cover. Does not advance snow or a...
Definition MeshSnow.cpp:252
const std::vector< double > & liquidRates() const
Borrow owned snow metadata/state without copying it.
Definition MeshSnow.hpp:179
double lastSeconds() const
Read the latest ordinary accepted advance duration.
Definition MeshSnow.hpp:162
const std::vector< unsigned char > & groundContactMask() const
Borrow owned snow metadata/state without copying it.
Definition MeshSnow.hpp:251
const std::vector< MeshSnowLedger > & ledgers() const
Borrow owned snow metadata/state without copying it.
Definition MeshSnow.hpp:221
std::string applyGroundContactEnergy(int cell, double soil_j)
Apply an accepted reciprocal soil energy receipt to one covered-point owner.
Definition MeshSnow.cpp:275
Definition CommonSourceStage.hpp:44
Definition GroundHeat.hpp:19
SnowKind
Definition UebConfig.hpp:22
@ Ueb
Definition UebConfig.hpp:22
Definition ExchangeLaw.hpp:60
Definition ExchangeLaw.hpp:60
Central, reentrant simulation context.
Definition SimulationContext.hpp:390
Definition MeshSnow.hpp:24
std::string tag
Definition MeshSnow.hpp:25
double slope
Definition MeshSnow.hpp:26
double aspect
Definition MeshSnow.hpp:26
double area
Definition MeshSnow.hpp:26
Definition MeshSnow.hpp:28
double raw_precipitation
Definition MeshSnow.hpp:29
double net_energy
Definition MeshSnow.hpp:31
double energyResidual() const
Compute signed cumulative represented-energy closure.
Definition MeshSnow.hpp:37
double geometry_energy
Definition MeshSnow.hpp:31
double sublimation
Definition MeshSnow.hpp:29
double liquid
Definition MeshSnow.hpp:29
double initial
Definition MeshSnow.hpp:29
double stored_energy
Definition MeshSnow.hpp:32
double stored
Definition MeshSnow.hpp:30
double prescribed_ground_energy
Definition MeshSnow.hpp:33
double initial_energy
Definition MeshSnow.hpp:31
double ground_contact_energy
Definition MeshSnow.hpp:33
double precipitation
Definition MeshSnow.hpp:29
double residual() const
Compute signed cumulative physical water closure.
Definition MeshSnow.hpp:43
Point UEB material, radiation and integration parameters. Temperatures are Celsius,...
Definition UebSnow.hpp:23