OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
SimulationSnapshot.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
41
42#ifndef OPENSWMM_SIMULATION_SNAPSHOT_HPP
43#define OPENSWMM_SIMULATION_SNAPSHOT_HPP
44
45#include <vector>
46#include <string>
47#include <cstdint>
48
49namespace openswmm {
50
51// NOTE ON UNITS: the 1D node / link / subcatchment / gage / system fields below
52// are delivered in PROJECT DISPLAY units (e.g. m, m³, CMS for an SI project;
53// ft, ft³, CFS for US). The engine applies a single conversion boundary
54// (convertSnapshotToDisplay) when building the snapshot, so output plugins
55// write values directly without re-applying Ucf/Qcf. Dimensionless fields
56// (capacity, soil moisture, pollutant concentrations) are unconverted. The 2D
57// surface_* arrays on SimulationSnapshot are the exception: they are SI-native
58// solver outputs and are NOT touched by the boundary.
59
65 std::vector<double> depth;
66 std::vector<double> head;
67 std::vector<double> volume;
68 std::vector<double> lateral_inflow;
69 std::vector<double> total_inflow;
70 std::vector<double> overflow;
71};
72
78 std::vector<double> flow;
79 std::vector<double> depth;
80 std::vector<double> velocity;
81 std::vector<double> volume;
82 std::vector<double> capacity;
83};
84
90 std::vector<double> rainfall;
91 std::vector<double> snow_depth;
92 std::vector<double> evap;
93 std::vector<double> infil;
94 std::vector<double> runoff;
95 std::vector<double> gw_flow;
96 std::vector<double> gw_elev;
97 std::vector<double> soil_moist;
98};
99
105 std::vector<double> rainfall;
106};
107
118 // -----------------------------------------------------------------------
119 // Timing
120 // -----------------------------------------------------------------------
121
123 double sim_time = 0.0;
124
126 std::int64_t wall_time_unix = 0;
127
130
131 // -----------------------------------------------------------------------
132 // Object counts
133 // -----------------------------------------------------------------------
134
135 int node_count = 0;
136 int link_count = 0;
138 int gage_count = 0;
139 int pollut_count = 0;
140
141 // -----------------------------------------------------------------------
142 // State arrays (parallel to the engine's SoA arrays)
143 // -----------------------------------------------------------------------
144
149
150 // -----------------------------------------------------------------------
151 // System-level results (for binary output file)
152 // -----------------------------------------------------------------------
153
154 double sys_temperature = 0.0;
155 double sys_rainfall = 0.0;
156 double sys_snow_depth = 0.0;
157 double sys_evap = 0.0;
158 double sys_infil = 0.0;
159 double sys_runoff = 0.0;
160 double sys_dw_inflow = 0.0;
161 double sys_gw_inflow = 0.0;
162 double sys_ii_inflow = 0.0;
163 double sys_ext_inflow = 0.0;
164 double sys_flooding = 0.0;
165 double sys_outflow = 0.0;
166 double sys_storage = 0.0;
167 double sys_pet = 0.0;
168
182 bool has_subcatchments = true;
183
184 // -----------------------------------------------------------------------
185 // Pollutant concentrations (optional; populated only if quality routing active)
186 // -----------------------------------------------------------------------
187
193 std::vector<double> node_quality;
194
199 std::vector<double> link_quality;
200
204 std::vector<double> subcatch_quality;
205
206 // -----------------------------------------------------------------------
207 // String tables (for plugins that need to label their output)
208 // -----------------------------------------------------------------------
209
211 const std::vector<std::string>* node_ids = nullptr;
212
214 const std::vector<std::string>* link_ids = nullptr;
215
217 const std::vector<std::string>* subcatch_ids = nullptr;
218
220 const std::vector<std::string>* gage_ids = nullptr;
221
223 const std::vector<std::string>* pollut_names = nullptr;
224
225 // -----------------------------------------------------------------------
226 // Unit information
227 // -----------------------------------------------------------------------
228
230 const char* flow_units = nullptr;
231
233 const char* length_units = nullptr;
234
237
238 // -----------------------------------------------------------------------
239 // 2D surface routing state (optional; populated only when the engine was
240 // built with OPENSWMM_BUILD_2D and the input file contains a 2D mesh)
241 //
242 // Layout: per-cell vectors are sized `surface_tri_count` (a "tri" is any
243 // cell — triangle or quadrilateral, triangles first); per-vertex vectors
244 // are sized `surface_vert_count`. `surface_edge_flux` is flat
245 // [cell * surface_edge_stride + edge] of size
246 // `surface_tri_count * surface_edge_stride`, where the stride is 3 for an
247 // all-triangle mesh (byte-compatible with pre-quad consumers) and 4 once
248 // any quad exists; padding slots of a triangle row are 0.
249 //
250 // Fields are deep-copied from `SurfaceRouter2D::state()` on the main
251 // simulation thread; consumers (Default2DOutputPlugin and any third-party
252 // 2D output plugins) read them through the IO-thread snapshot reference
253 // without further synchronization.
254 //
255 // Vectors are empty when 2D is inactive (either OPENSWMM_BUILD_2D=OFF or
256 // the input file contained no [2D_VERTICES] section). Plugins must check
257 // `surface_tri_count == 0` to skip 2D-specific work in that case.
258 // -----------------------------------------------------------------------
259
266 std::vector<uint8_t> surface_cell_nv;
267
268 std::vector<double> surface_depth;
269 std::vector<double> surface_head;
270 std::vector<double> surface_grad_hx;
271 std::vector<double> surface_grad_hy;
272 std::vector<double> surface_grad_hx_lim;
273 std::vector<double> surface_grad_hy_lim;
274 std::vector<double> surface_rainfall;
275 std::vector<double> surface_coupling_flux;
276 std::vector<double> surface_net_source;
277 std::vector<double> surface_infil_rate;
278 std::vector<double> surface_infil_cum;
279 std::vector<double> surface_rain_cum;
289 std::vector<double> surface_species_conc;
295 const std::vector<std::string>* surface_species_names = nullptr;
296 std::vector<double> surface_edge_flux;
297 std::vector<double> surface_vert_head;
298 std::vector<double> surface_vert_depth;
299 std::vector<double> surface_face_vx;
300 std::vector<double> surface_face_vy;
301 std::vector<double> surface_continuity_err;
302
303 // Cumulative rendering envelopes (SI-native, monotone over the run), per face.
304 // A snapshot of these at any time is the envelope up to that time; the 2D
305 // output plugin overwrites the fixed [nFace] envelope datasets in place.
306 std::vector<double> surface_stat_max_depth;
307 std::vector<double> surface_stat_max_velocity;
308 std::vector<double> surface_stat_max_cont_err;
309};
310
311} /* namespace openswmm */
312
313#endif /* OPENSWMM_SIMULATION_SNAPSHOT_HPP */
Definition NodeCoupling.cpp:16
Snapshot of rain gage state at an output time step.
Definition SimulationSnapshot.hpp:104
std::vector< double > rainfall
Current rainfall rate [project rate units].
Definition SimulationSnapshot.hpp:105
Snapshot of node state at an output time step.
Definition SimulationSnapshot.hpp:64
std::vector< double > volume
Stored volume [display volume units].
Definition SimulationSnapshot.hpp:67
std::vector< double > lateral_inflow
Lateral inflow [display flow units].
Definition SimulationSnapshot.hpp:68
std::vector< double > total_inflow
Total inflow [display flow units].
Definition SimulationSnapshot.hpp:69
std::vector< double > head
Hydraulic head [display length units].
Definition SimulationSnapshot.hpp:66
std::vector< double > overflow
Overflow / surcharge [display flow units].
Definition SimulationSnapshot.hpp:70
std::vector< double > depth
Water depth [display length units].
Definition SimulationSnapshot.hpp:65
Complete simulation state snapshot at one output time step.
Definition SimulationSnapshot.hpp:117
std::vector< double > subcatch_quality
Subcatchment pollutant loadings.
Definition SimulationSnapshot.hpp:204
const std::vector< std::string > * gage_ids
Gage IDs in index order.
Definition SimulationSnapshot.hpp:220
std::vector< double > surface_edge_flux
Normal flux through each edge, flat [tri*3+edge].
Definition SimulationSnapshot.hpp:296
SubcatchSnapshot subcatch
Subcatchment state.
Definition SimulationSnapshot.hpp:147
std::vector< double > surface_stat_max_depth
Max overland depth ψ_o (m), per face.
Definition SimulationSnapshot.hpp:306
LinkSnapshot links
Link state.
Definition SimulationSnapshot.hpp:146
GageSnapshot gages
Gage state.
Definition SimulationSnapshot.hpp:148
int surface_vert_count
Number of vertices (nodes)
Definition SimulationSnapshot.hpp:261
const char * flow_units
Flow unit string (e.g., "CFS", "LPS").
Definition SimulationSnapshot.hpp:230
double sys_gw_inflow
Total groundwater inflow.
Definition SimulationSnapshot.hpp:161
int surface_species_count
Definition SimulationSnapshot.hpp:290
double sys_ext_inflow
Total external inflow.
Definition SimulationSnapshot.hpp:163
std::vector< double > surface_grad_hy
Unlimited head gradient ∂h/∂y, per face.
Definition SimulationSnapshot.hpp:271
int link_count
Number of links.
Definition SimulationSnapshot.hpp:136
std::vector< double > surface_rainfall
Rainfall intensity (m/s), per face.
Definition SimulationSnapshot.hpp:274
double sys_pet
Potential evapotranspiration.
Definition SimulationSnapshot.hpp:167
double sys_outflow
Total outflow.
Definition SimulationSnapshot.hpp:165
std::vector< double > surface_face_vy
Cell-centred velocity Y (m/s), per face.
Definition SimulationSnapshot.hpp:300
int flow_units_code
Flow units code (FlowUnits enum value: 0=CFS, 3=CMS, etc.).
Definition SimulationSnapshot.hpp:236
double sim_time
Simulation date/time (SWMM DateTime: days since 12/31/1899).
Definition SimulationSnapshot.hpp:123
std::vector< double > surface_coupling_flux
Coupling flux to SWMM node (m/s, + = into 2D), per face.
Definition SimulationSnapshot.hpp:275
int gage_count
Number of rain gages.
Definition SimulationSnapshot.hpp:138
std::vector< double > surface_vert_depth
SIGNED vertex depth η_v − z_v (m) — wet-masked, wetted-contact-gated render reconstruction; > 0 where...
Definition SimulationSnapshot.hpp:298
std::vector< double > surface_infil_rate
Held infiltration loss rate (m/s, ≥ 0), per face — all zero when no [2D_INFILTRATION*] model resolved...
Definition SimulationSnapshot.hpp:277
std::vector< double > surface_grad_hy_lim
Slope-limited head gradient ∂h/∂y, per face.
Definition SimulationSnapshot.hpp:273
std::vector< double > surface_infil_cum
Cumulative infiltrated depth (m), per face.
Definition SimulationSnapshot.hpp:278
std::vector< double > surface_species_conc
2D surface species concentration (overland transport S1/S2).
Definition SimulationSnapshot.hpp:289
std::vector< double > surface_continuity_err
Per-cell continuity residual (m³/s), per face.
Definition SimulationSnapshot.hpp:301
std::vector< double > surface_net_source
Net source/sink (m/s), per face.
Definition SimulationSnapshot.hpp:276
double sys_storage
Total storage volume.
Definition SimulationSnapshot.hpp:166
std::vector< double > node_quality
Node pollutant concentrations.
Definition SimulationSnapshot.hpp:193
int subcatch_count
Number of subcatchments.
Definition SimulationSnapshot.hpp:137
int pollut_count
Number of pollutants.
Definition SimulationSnapshot.hpp:139
double sys_runoff
Total runoff flow.
Definition SimulationSnapshot.hpp:159
bool has_subcatchments
Whether the model has any subcatchments.
Definition SimulationSnapshot.hpp:182
std::vector< double > surface_face_vx
Cell-centred velocity X (m/s), per face.
Definition SimulationSnapshot.hpp:299
int output_step_index
Sequential output step index (0-based).
Definition SimulationSnapshot.hpp:129
int node_count
Number of nodes.
Definition SimulationSnapshot.hpp:135
std::vector< double > surface_depth
Overland flow depth ψ_o (m), per face.
Definition SimulationSnapshot.hpp:268
const std::vector< std::string > * link_ids
Link IDs in index order.
Definition SimulationSnapshot.hpp:214
std::int64_t wall_time_unix
Wall-clock Unix timestamp when snapshot was taken.
Definition SimulationSnapshot.hpp:126
double sys_evap
Total evaporation loss.
Definition SimulationSnapshot.hpp:157
std::vector< double > surface_rain_cum
Cumulative rainfall volume (m³), per face.
Definition SimulationSnapshot.hpp:279
const std::vector< std::string > * node_ids
Node IDs in index order. Pointer to engine-managed strings.
Definition SimulationSnapshot.hpp:211
int surface_edge_stride
Definition SimulationSnapshot.hpp:263
double sys_rainfall
Average rainfall over all gages.
Definition SimulationSnapshot.hpp:155
double sys_ii_inflow
Total RDII inflow.
Definition SimulationSnapshot.hpp:162
double sys_infil
Total infiltration loss.
Definition SimulationSnapshot.hpp:158
std::vector< double > surface_grad_hx
Unlimited head gradient ∂h/∂x, per face.
Definition SimulationSnapshot.hpp:270
std::vector< double > surface_stat_max_velocity
Max cell speed |v| (m/s), per face.
Definition SimulationSnapshot.hpp:307
const char * length_units
Length unit string (e.g., "FEET", "METERS").
Definition SimulationSnapshot.hpp:233
const std::vector< std::string > * pollut_names
Pollutant names in index order.
Definition SimulationSnapshot.hpp:223
std::vector< double > surface_grad_hx_lim
Slope-limited head gradient ∂h/∂x, per face.
Definition SimulationSnapshot.hpp:272
double sys_snow_depth
Total snow depth.
Definition SimulationSnapshot.hpp:156
std::vector< uint8_t > surface_cell_nv
Definition SimulationSnapshot.hpp:266
std::vector< double > surface_head
Total head h_o = z_s + ψ_o (m), per face.
Definition SimulationSnapshot.hpp:269
double sys_flooding
Total flooding.
Definition SimulationSnapshot.hpp:164
const std::vector< std::string > * surface_species_names
Definition SimulationSnapshot.hpp:295
const std::vector< std::string > * subcatch_ids
Subcatchment IDs in index order.
Definition SimulationSnapshot.hpp:217
int surface_quad_count
Number of quadrilateral cells (0 = all triangles)
Definition SimulationSnapshot.hpp:262
int surface_tri_count
Number of cells (faces): triangles + quads.
Definition SimulationSnapshot.hpp:260
double sys_temperature
Air temperature.
Definition SimulationSnapshot.hpp:154
NodeSnapshot nodes
Node state.
Definition SimulationSnapshot.hpp:145
std::vector< double > surface_stat_max_cont_err
Max |continuity residual| (m³/s), per face.
Definition SimulationSnapshot.hpp:308
std::vector< double > link_quality
Link pollutant concentrations.
Definition SimulationSnapshot.hpp:199
std::vector< double > surface_vert_head
Reconstructed head at vertices (m) — SOLVER field (dry-cell head = bed)
Definition SimulationSnapshot.hpp:297
double sys_dw_inflow
Total dry weather inflow.
Definition SimulationSnapshot.hpp:160
Snapshot of subcatchment state at an output time step.
Definition SimulationSnapshot.hpp:89
std::vector< double > soil_moist
Soil moisture [-].
Definition SimulationSnapshot.hpp:97
std::vector< double > rainfall
Rainfall rate [display rate units].
Definition SimulationSnapshot.hpp:90
std::vector< double > infil
Infiltration [display rate units].
Definition SimulationSnapshot.hpp:93
std::vector< double > runoff
Surface runoff [display flow units].
Definition SimulationSnapshot.hpp:94
std::vector< double > gw_flow
Groundwater outflow [display flow units].
Definition SimulationSnapshot.hpp:95
std::vector< double > evap
Evaporation [display rate units].
Definition SimulationSnapshot.hpp:92
std::vector< double > gw_elev
Groundwater elevation [display length units].
Definition SimulationSnapshot.hpp:96
std::vector< double > snow_depth
Snow depth [display depth units].
Definition SimulationSnapshot.hpp:91