OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
SimulationContext.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
75
76#ifndef OPENSWMM_ENGINE_SIMULATION_CONTEXT_HPP
77#define OPENSWMM_ENGINE_SIMULATION_CONTEXT_HPP
78
79#include <cmath>
80#include <ctime>
81#include <functional>
82#include "FilePathPair.hpp"
86#include "../data/GageData.hpp"
87#include "../data/HeatData.hpp"
90#include "../data/LinkData.hpp"
91#include "../data/NameIndex.hpp"
92#include "../data/NodeData.hpp"
99#include "../data/TableData.hpp"
100#include "SimulationOptions.hpp"
101#include "SpatialFrame.hpp"
102#include "UserFlags.hpp"
105#include "../data/InflowData.hpp"
106#include "../data/InfraData.hpp"
112
113#include <algorithm>
114#include <array>
115#include <cstdint>
116#include <map>
117#include <string>
118#include <utility>
119#include <vector>
120
121namespace openswmm {
122
123// ============================================================================
124// Plugin specification (from [PLUGINS] section)
125// ============================================================================
126
137 std::string path;
138 std::vector<std::string> init_args;
139};
140
141// ============================================================================
142// [PROCESS_COMPONENTS] section spec — process-component registrations
143// ============================================================================
144
159 std::string id;
160 std::string config_path;
161 std::vector<std::pair<std::string, std::string>> args;
162
168};
169
170// ============================================================================
171// [FILES] section spec — secondary file references
172// ============================================================================
173
183enum class FileMode { NONE, SAVE, USE };
184
188enum class HotstartFormat { AUTO = 0, LEGACY = 1, NATIVE = 2 };
189
218
257
258// ============================================================================
259// Engine state enumeration
260// ============================================================================
261
270enum class EngineState : int32_t {
272 OPENED = 1,
275 PAUSED = 4,
276 ENDED = 5,
278 CLOSED = 7,
281};
282
283// ============================================================================
284// StateAccessors
285// ============================================================================
286
305 std::function<bool()> has_fv_retained_dry_mass;
306 std::function<std::string()> get_fv_dry_state;
307 std::function<std::string(const std::string&,bool)> set_fv_dry_state;
308 std::function<std::vector<double>()> get_fv_retained_pollutant_mass;
309 std::function<std::vector<double>()> get_fv_retained_species_mass;
310 std::function<std::vector<ChannelThermalRegion>()> get_channel_thermal_regions;
311 // Each region appears once. Validate the complete batch before mutation.
312 std::function<std::string(const std::vector<ChannelThermalIncrement>&)>
314 std::function<std::vector<ChannelSpeciesRegion>()> get_channel_species_regions;
315 std::function<std::string(const std::vector<ChannelSpeciesIncrement>&)>
317 std::function<std::string()> get_snow_state;
318 // Empty result means valid; false validates without publishing.
319 std::function<std::string(const std::string&, bool)> set_snow_state;
325 std::function<std::string()> get_surface_state;
326 std::function<std::string(const std::string&, bool)> set_surface_state;
329 std::function<bool(int subcatch_index, int& out_model, double* out_infil)> get_infil_state;
330
333 std::function<bool(int subcatch_index, int model, const double* infil)> set_infil_state;
334
336 std::function<bool(int subcatch_index, double& out_theta, double& out_lower_depth)>
338
340 std::function<bool(int subcatch_index, double theta, double lower_depth)> set_gw_state;
341
343 bool can_read() const noexcept {
344 return static_cast<bool>(get_infil_state) || static_cast<bool>(get_gw_state);
345 }
346
348 bool can_write() const noexcept {
349 return static_cast<bool>(set_infil_state) || static_cast<bool>(set_gw_state);
350 }
351};
352
353// ============================================================================
354// 2D model-IO bridge (forward declarations)
355// ============================================================================
356
357// Plain 2D data structs (all header-only and define-free; see
358// src/engine/2d/data/). Forward-declared so SimulationContext can carry
359// non-owning pointers without pulling the 2D module into every TU.
360namespace twoD {
361struct MeshData;
362struct SolverOptions2D;
363struct BoundaryData;
364class Infil2D;
365class SurfaceRouter2D;
366struct PendingBoundaryRow;
367struct PendingEdgeConveyanceRow;
368struct PendingInitialQualityRow;
369struct PendingInitialBedQualityRow;
370struct PendingBoundaryQualityRow;
371struct GwTransportData;
372class SurfaceQuality2D; // S7 (2026-09-19)
373struct SubsurfaceConfig; // G1: the [2D_AQUIFER*] rows
374struct SubsurfaceState; // G1: the running two-zone kernel state
375struct SubsurfaceTransportState; // T7.5: and what is dissolved in it
376} // namespace twoD
377
378// ============================================================================
379// SimulationContext
380// ============================================================================
381
391
392 // =========================================================================
393 // Engine state
394 // =========================================================================
395
398
410 std::time_t wall_start = 0;
411
412 // =========================================================================
413 // Project title / notes
414 // =========================================================================
415
425 std::vector<std::string> title_notes;
426
442 std::map<std::string, std::vector<std::string>> passthrough_sections;
443
444 // =========================================================================
445 // Options & configuration
446 // =========================================================================
447
453
466
467 // =========================================================================
468 // Simulation clock
469 // =========================================================================
470
489 double current_time = 0.0;
490
498 double current_date = 0.0;
499
512 double elapsed_ms = 0.0;
513
520 double old_elapsed_ms = 0.0;
521
532 double next_report_ms = 0.0;
533
545 double runoff_interp_f = 1.0;
546
554
555 // =========================================================================
556 // Object data stores (Structure-of-Arrays)
557 // =========================================================================
558
564
575
581
589
595
601
607
617
625
633
641
648
657
669
685 std::vector<std::string> reported_species_names;
686
690 for (int p = 0; p < n_pollutants(); ++p)
691 reported_species_names.push_back(pollutant_names.name_of(p));
692 if (options.water_age)
693 reported_species_names.push_back("__WATER_AGE__");
694 if (options.heat_transport)
695 reported_species_names.push_back("__TEMPERATURE__");
696 reactions.reported_species.clear();
697 for (int m = 0; m < reactions.n_species(); ++m) {
698 if (!reactions.report_enabled.empty() && !reactions.report_enabled[m])
699 continue;
700 reactions.reported_species.push_back(m);
701 reported_species_names.push_back(reactions.species_name[m]);
702 }
703 }
704
706 int n_reported_species() const noexcept {
707 return static_cast<int>(reported_species_names.size());
708 }
709
715
716 // =========================================================================
717 // Name-to-index lookup (O(1))
718 // =========================================================================
719
725
731
737
743
749
750 // NOTE: there is deliberately NO shared name registry for tables.
751 // Legacy keeps TSERIES and CURVE in separate hash tables, so a curve and
752 // a timeseries may legally share one name; ctx.tables is the authority
753 // (each row stores id + type) and lookups are kind-aware via
754 // find_timeseries() / find_curve() below.
755
756 // =========================================================================
757 // Quality data (landuse, buildup, washoff, treatment)
758 // =========================================================================
759
765
774
775 // =========================================================================
776 // Inflow data (external, DWF, RDII, patterns)
777 // =========================================================================
778
785
786 // =========================================================================
787 // Infrastructure data (transects, streets, inlets, controls)
788 // =========================================================================
789
792 std::vector<transect::TransectData> transect_tables;
797 std::uint64_t xsect_generation = 0;
798
807
812
813 // =========================================================================
814 // Events (from [EVENTS] section)
815 // =========================================================================
816
822 struct Event {
823 double start = 0.0;
824 double end = 0.0;
825 };
826 std::vector<Event> events;
827
828 // =========================================================================
829 // Subcatchment adjustment patterns (from [ADJUSTMENTS] section)
830 // =========================================================================
831
838 double adjust_temp[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
839 double adjust_evap[12] = {
840 0, 0, 0, 0, 0, 0, 0,
841 0, 0, 0, 0, 0};
842 double adjust_rain[12] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
843 double adjust_hydcon[12] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
844
850 std::vector<int> subcatch_n_perv_pattern;
851 std::vector<int> subcatch_d_store_pattern;
852 std::vector<int> subcatch_infil_pattern;
853
855 std::vector<double> base_n_perv;
856 std::vector<double> base_ds_perv;
858
859 // =========================================================================
860 // Hydrology data (snowpacks, aquifers, LID)
861 // =========================================================================
862
868 std::vector<LidNodeOutlet> lid_node_outlets;
871
872 // =========================================================================
873 // Transient deferred-resolution capture lists (input loading only)
874 // =========================================================================
875 // Sections whose referenced objects may be defined later in the .inp store
876 // the raw name here so PostParseResolver can re-resolve after every section
877 // has been parsed. Cleared by the resolver; empty outside input loading, so
878 // they can never desync with the editing APIs.
879
882 std::vector<std::pair<int, std::string>> pending_gw_nodes;
883
886 std::vector<std::pair<int, std::string>> pending_gw_aquifers;
887
891 std::vector<std::pair<int, std::pair<std::string, std::string>>> pending_link_nodes;
892
893 // =========================================================================
894 // Spatial data
895 // =========================================================================
896
902
903 // =========================================================================
904 // User-defined flags
905 // =========================================================================
906
913
914 // =========================================================================
915 // Object tags (from [TAGS] section)
916 // =========================================================================
917
918 // Tags from the [TAGS] section now live per-index on
919 // NodeData::tags / LinkData::tags / SubcatchData::tags. Storing
920 // them name-keyed here was a latent rename bug — a tagged node
921 // would lose its tag the moment `swmm_node_rename` was called.
922
923 // =========================================================================
924 // Runtime forcing data
925 // =========================================================================
926
936
937 // =========================================================================
938 // Plugin specifications (from [PLUGINS] section)
939 // =========================================================================
940
946 std::vector<PluginSpec> plugin_specs;
947
955 std::vector<ProcessComponentSpec> process_component_specs;
956
964 std::vector<std::pair<std::string, std::vector<std::string>>> embedded_component_sections;
965
975
985
1010 std::vector<twoD::PendingBoundaryRow>* pending_bc = nullptr;
1011 std::vector<twoD::PendingEdgeConveyanceRow>* pending_ec = nullptr;
1014 std::vector<twoD::PendingInitialQualityRow>* pending_iq = nullptr;
1015 std::vector<twoD::PendingInitialBedQualityRow>* pending_ibq = nullptr;
1016 std::vector<twoD::PendingBoundaryQualityRow>* pending_bq = nullptr;
1039 std::vector<std::string>* aquifer_nodes = nullptr;
1042 std::vector<std::string>* aquifer_links = nullptr;
1054
1070 std::vector<std::pair<std::string, std::string>> deferred_section_rows;
1071
1077 std::vector<std::pair<std::string, long>> unknown_section_headers;
1078
1079 // =========================================================================
1080 // Error / warning tracking
1081 // =========================================================================
1082
1087 int error_code = 0;
1088
1094
1098 std::string error_message;
1099
1107 std::vector<std::string> warnings;
1108
1116 std::vector<std::string> errors;
1117
1126
1138 std::vector<std::uint8_t> coupled_node;
1139
1149 std::vector<double> coupled_pond_area;
1150 std::vector<double> coupled_pond_band;
1151
1166
1167 // =========================================================================
1168 // Mass balance accumulators (SoA — vectorisable batch updates)
1169 // =========================================================================
1170
1180 // One row per node, booked at the same committed seam as routing totals.
1181 // Read-only external coupling accounting; never a second withdrawal.
1185
1187 // Runoff totals
1188 double runoff_rainfall = 0.0;
1189 double runoff_runon = 0.0;
1190 double runoff_evap = 0.0;
1191 double runoff_infil = 0.0;
1192 double runoff_runoff = 0.0;
1194 0.0;
1195 double runoff_snowremov = 0.0;
1196 double runoff_init_store = 0.0;
1197 double runoff_final_store = 0.0;
1201 double runoff_init_snow = 0.0;
1211 double runoff_final_snow = 0.0;
1212
1213 // RDII generation totals (ft3), distinct from routed RDII and runoff
1214 // rainfall: sewer service areas need not equal subcatchment areas.
1215 double rdii_rainfall = 0.0;
1216 double rdii_produced = 0.0;
1217
1218 // Routing totals
1221 double routing_gw_inflow = 0.0;
1229 double routing_rdii = 0.0;
1230 double routing_external = 0.0;
1231 double routing_flooding = 0.0;
1248 double routing_outflow = 0.0;
1249 double routing_evap_loss = 0.0;
1250 double routing_seep_loss = 0.0;
1253
1261 std::array<double, 11> routing_report{};
1262
1263 // User-forced volumes (diagnostic — subset of routing_external)
1265
1266 // User-forced quality mass (diagnostic — cumulative mass injected via user_conc_mass_flux)
1267 std::vector<double>
1269
1270 // Groundwater mass balance totals (all in feet — depth per unit area)
1271 // Matches legacy TGwaterTotals
1272 double gw_infil = 0.0;
1273 double gw_upper_evap = 0.0;
1274 double gw_lower_evap = 0.0;
1275 double gw_lower_perc = 0.0;
1276 double gw_lateral_flow = 0.0;
1277 double gw_init_storage = 0.0;
1278 double gw_final_storage = 0.0;
1289
1290 // Per-step accumulators (reset each step for reporting)
1291 double step_flooding = 0.0;
1292 double step_outflow = 0.0;
1293 double step_dw_inflow = 0.0;
1294 double step_gw_inflow = 0.0;
1295 double step_rdii_inflow = 0.0;
1296 double step_ext_inflow = 0.0;
1307
1308 // Quality mass balance (per-pollutant, in mass units)
1309 std::vector<double> qual_init_buildup;
1310 std::vector<double> qual_final_buildup;
1311 std::vector<double>
1313 std::vector<double> qual_surface_buildup;
1314 std::vector<double> qual_wet_deposition;
1315 std::vector<double> qual_sweeping;
1316 std::vector<double> qual_bmp_removal;
1317 std::vector<double> qual_infil_loss;
1318 std::vector<double> qual_runoff_load;
1319 std::vector<double> qual_routing_wet;
1320 std::vector<double> qual_routing_outflow;
1321 std::vector<double> qual_routing_flood;
1322 std::vector<double> qual_routing_init;
1323 std::vector<double> qual_routing_final;
1324 std::vector<double> qual_routing_reacted;
1325 std::vector<double> qual_routing_ii_in;
1326 std::vector<double> qual_routing_dw_in;
1327 std::vector<double> qual_routing_gw_in;
1328 std::vector<double> qual_routing_ex_in;
1329 std::vector<double> qual_routing_seep;
1330 std::vector<double> qual_routing_evap;
1336 std::vector<double> qual_routing_final_dry;
1337
1348 auto np = static_cast<std::size_t>(n_pollutants);
1349 qual_init_buildup.assign(np, 0.0);
1350 qual_final_buildup.assign(np, 0.0);
1351 qual_ponded_lost.assign(np, 0.0);
1352 qual_surface_buildup.assign(np, 0.0);
1353 qual_wet_deposition.assign(np, 0.0);
1354 qual_sweeping.assign(np, 0.0);
1355 qual_bmp_removal.assign(np, 0.0);
1356 qual_infil_loss.assign(np, 0.0);
1357 qual_runoff_load.assign(np, 0.0);
1358 qual_routing_wet.assign(np, 0.0);
1359 qual_routing_outflow.assign(np, 0.0);
1360 qual_routing_flood.assign(np, 0.0);
1361 qual_routing_init.assign(np, 0.0);
1362 qual_routing_final.assign(np, 0.0);
1363 qual_routing_reacted.assign(np, 0.0);
1364 qual_routing_ii_in.assign(np, 0.0);
1365 qual_routing_dw_in.assign(np, 0.0);
1366 qual_routing_gw_in.assign(np, 0.0);
1367 qual_routing_ex_in.assign(np, 0.0);
1368 qual_routing_seep.assign(np, 0.0);
1369 qual_routing_evap.assign(np, 0.0);
1370 qual_routing_final_dry.assign(np, 0.0);
1371 routing_forcing_qual_inflow.assign(np, 0.0);
1372 }
1373
1381 void reset() {
1382 // Save quality vectors, reset scalars, restore vectors
1383 auto qi = std::move(qual_init_buildup);
1384 auto qf = std::move(qual_final_buildup);
1385 auto qpl = std::move(qual_ponded_lost);
1386 auto qsb = std::move(qual_surface_buildup);
1387 auto qwd = std::move(qual_wet_deposition);
1388 auto qsw = std::move(qual_sweeping);
1389 auto qbmp = std::move(qual_bmp_removal);
1390 auto qil = std::move(qual_infil_loss);
1391 auto qrl = std::move(qual_runoff_load);
1392 auto qrw = std::move(qual_routing_wet);
1393 auto qro = std::move(qual_routing_outflow);
1394 auto qrf = std::move(qual_routing_flood);
1395 auto qri = std::move(qual_routing_init);
1396 auto qrfi = std::move(qual_routing_final);
1397 auto qrr = std::move(qual_routing_reacted);
1398 auto qrii = std::move(qual_routing_ii_in);
1399 auto qrdw = std::move(qual_routing_dw_in);
1400 auto qrgw = std::move(qual_routing_gw_in);
1401 auto qrex = std::move(qual_routing_ex_in);
1402 auto qrseep = std::move(qual_routing_seep);
1403 auto qrevap = std::move(qual_routing_evap);
1404 auto qrfd = std::move(qual_routing_final_dry);
1405 auto qrfqi = std::move(routing_forcing_qual_inflow);
1406 *this = MassBalance{};
1407 qual_init_buildup = std::move(qi);
1408 qual_final_buildup = std::move(qf);
1409 qual_ponded_lost = std::move(qpl);
1410 qual_surface_buildup = std::move(qsb);
1411 qual_wet_deposition = std::move(qwd);
1412 qual_sweeping = std::move(qsw);
1413 qual_bmp_removal = std::move(qbmp);
1414 qual_infil_loss = std::move(qil);
1415 qual_runoff_load = std::move(qrl);
1416 qual_routing_wet = std::move(qrw);
1417 qual_routing_outflow = std::move(qro);
1418 qual_routing_flood = std::move(qrf);
1419 qual_routing_init = std::move(qri);
1420 qual_routing_final = std::move(qrfi);
1421 qual_routing_reacted = std::move(qrr);
1422 qual_routing_ii_in = std::move(qrii);
1423 qual_routing_dw_in = std::move(qrdw);
1424 qual_routing_gw_in = std::move(qrgw);
1425 qual_routing_ex_in = std::move(qrex);
1426 qual_routing_seep = std::move(qrseep);
1427 qual_routing_evap = std::move(qrevap);
1428 qual_routing_final_dry = std::move(qrfd);
1429 routing_forcing_qual_inflow = std::move(qrfqi);
1430 // Zero out the quality vectors (except init_buildup which is
1431 // computed once during initQuality and must survive reset)
1432 for (auto* v : {&qual_final_buildup, &qual_ponded_lost,
1443 std::fill(v->begin(), v->end(), 0.0);
1444 }
1445 }
1446
1448 double runoff_error() const {
1449 // Snow is a STORE on both sides, and snow ploughed out of the
1450 // system is a loss — matching legacy massbal.c:685-692. A pack
1451 // present at the start is water the model was given; a pack still
1452 // standing at the end is water it still holds.
1454 double total_out = runoff_evap + runoff_infil + runoff_runoff + runoff_lid_drain +
1456 return (total_in > 0.0) ? (total_in - total_out) / total_in : 0.0;
1457 }
1458
1460 double routing_error() const {
1462 routing_link_gw_inflow + // G-X4
1466 return (total_in > 0.0) ? (total_in - total_out) / total_in : 0.0;
1467 }
1468
1470 double gw_error() const {
1471 double total_in = gw_infil + gw_init_storage;
1472 double total_out =
1474 return (total_in > 0.0) ? (total_in - total_out) / total_in : 0.0;
1475 }
1477
1507
1518 // Per-incident-link surface donation limit (ft³/s), indexed by node.
1519 // Empty for ordinary models; infinity for nodes without a surface outfall.
1520 std::vector<double> surface_outfall_link_limit;
1521
1530 std::vector<double> vol, mass, msx, age_vol, temp_vol;
1531 bool any = false;
1544 void ensure(int nn, int np, int ns) {
1545 const auto un = static_cast<std::size_t>(nn > 0 ? nn : 0);
1546 if (vol.size() != un) {
1547 vol.assign(un, 0.0);
1548 age_vol.assign(un, 0.0);
1549 temp_vol.assign(un, 0.0);
1550 }
1551 if (mass.size() != un * static_cast<std::size_t>(np > 0 ? np : 0))
1552 mass.assign(un * static_cast<std::size_t>(np > 0 ? np : 0), 0.0);
1553 if (msx.size() != un * static_cast<std::size_t>(ns > 0 ? ns : 0))
1554 msx.assign(un * static_cast<std::size_t>(ns > 0 ? ns : 0), 0.0);
1555 }
1556
1561 void clear() {
1562 for (auto* v : {&vol, &mass, &msx, &age_vol, &temp_vol})
1563 std::fill(v->begin(), v->end(), 0.0);
1564 any = false;
1565 }
1566 };
1569
1572 double init_storage = 0.0;
1573 double final_storage = 0.0;
1574 double external_in = 0.0, external_out = 0.0;
1575 double rainfall_in = 0.0;
1578 double outfall_in = 0.0;
1579 double outfall_out = 0.0;
1580 double boundary_in = 0.0;
1581 double boundary_out = 0.0;
1582 double evap_out = 0.0;
1587 double infil_out = 0.0;
1594 double infil_to_aquifer = 0.0;
1609 double aquifer_in = 0.0;
1610 bool active = false;
1611
1612 // Cumulative marcher statistics (published by SurfaceRouter2D at
1613 // finalize from ISurfaceSolver::run_stats). Printed as the "2D Solver
1614 // Statistics" report block. -1 = not populated.
1615 long solver_nsteps = -1;
1616 long solver_nrhs = 0;
1617 double solver_avg_h = 0.0;
1618 double solver_last_h = 0.0;
1619
1620 // Marcher telemetry (guarded by n_tiers > 0 / non-negative fractions).
1621 double solver_active_min = -1.0;
1622 double solver_active_mean = -1.0;
1623 double solver_active_max = -1.0;
1624 long solver_tier_cells[8] = {0};
1626
1628 double error() const {
1629 double total_in = rainfall_in + coupling_1d_to_2d_in + outfall_in + boundary_in +
1631 double total_out = coupling_2d_to_1d_out + outfall_out + boundary_out + evap_out +
1633 return (total_in > 0.0) ? (total_in - total_out) / total_in : 0.0;
1634 }
1636
1637 // =========================================================================
1638 // Routing time-step statistics
1639 // =========================================================================
1640
1642 struct MaxStats {
1643 int obj_type = -1;
1644 int index = -1;
1645 double value = 0.0;
1646 };
1647
1648 static constexpr int MAX_STATS = 5;
1649
1658
1660 double min_step = 1.0e30;
1661 double max_step = 0.0;
1662 double sum_step = 0.0;
1663 long n_steps = 0;
1664 double steady_pct = 0.0;
1665 double steady_time = 0.0;
1666 long report_steps = 0;
1667 double report_time = 0.0;
1669 0.0;
1670
1672 static constexpr int N_TIME_BINS = 5;
1673 long step_counts[N_TIME_BINS + 1] = {};
1674 double step_intervals[N_TIME_BINS + 1] = {};
1675
1678 double sum_iterations = 0.0;
1679 double max_courant = 0.0;
1680
1688 void update(double dt) {
1689 min_step = std::min(min_step, dt);
1690 max_step = std::max(max_step, dt);
1691 sum_step += dt;
1692 ++n_steps;
1693 }
1694
1707 void record_step(double dt, bool steady, bool first_step) {
1708 if (steady) {
1709 steady_time += dt;
1710 return;
1711 }
1712 if (!first_step) {
1713 min_step = std::min(min_step, dt);
1714 for (int i = 0; i < N_TIME_BINS; ++i)
1715 if (dt >= step_intervals[i + 1]) {
1716 step_counts[i]++;
1717 break;
1718 }
1719 }
1720 max_step = std::max(max_step, dt);
1721 sum_step += dt;
1722 ++n_steps;
1723 }
1724
1734 void update_iterations(int iters, bool converged) {
1735 sum_iterations += iters;
1736 if (!converged)
1738 }
1739
1751 void init_histogram(double route_step, double min_route_step) {
1752 if (route_step <= 0.0)
1753 return;
1754 if (min_route_step <= 0.0)
1755 min_route_step = route_step;
1756 double log_hi = std::log10(route_step);
1757 double log_lo = std::log10(min_route_step);
1758 double delta = (log_hi - log_lo) / static_cast<double>(N_TIME_BINS);
1759 step_intervals[0] = route_step;
1760 for (int i = 1; i <= N_TIME_BINS; ++i)
1761 step_intervals[i] = std::pow(10.0, log_hi - i * delta);
1762 step_intervals[N_TIME_BINS] = min_route_step;
1763 }
1764
1772 if (n_steps == 0 || max_step <= 0.0)
1773 return;
1774 double hi = max_step;
1775 double lo = (min_step < 1.0e30) ? min_step : 0.0;
1776 if (lo <= 0.0)
1777 lo = hi;
1778 init_histogram(hi, lo);
1779 }
1780
1790 void record_step_bin(double dt) {
1791 for (int i = 0; i < N_TIME_BINS; ++i) {
1792 if (dt >= step_intervals[i + 1]) {
1793 step_counts[i]++;
1794 return;
1795 }
1796 }
1797 step_counts[N_TIME_BINS - 1]++;
1798 }
1799
1804 double avg_step() const {
1805 return (n_steps > 0) ? sum_step / static_cast<double>(n_steps) : 0.0;
1806 }
1807
1814 double pct_non_converged() const {
1815 return (n_steps > 0)
1816 ? 100.0 * static_cast<double>(n_non_converged) / static_cast<double>(n_steps)
1817 : 0.0;
1818 }
1819
1827 return (n_steps > 0) ? sum_iterations / static_cast<double>(n_steps) : 0.0;
1828 }
1829
1830 // ---------------------------------------------------------------
1831 // FV 1D solver statistics (published by SWMMEngine::end() from
1832 // INetworkSolver::run_stats, printed as the "FV Solver Statistics"
1833 // report block). The 1D counterpart of mass_balance_2d.solver_*.
1834 //
1835 // -1 = not populated: the run was not FLOW_ROUTING FV, or a backend
1836 // that carries no counters was selected. The report block is skipped
1837 // on the sentinel rather than printing a row of zeros, which would
1838 // read as "the solver did nothing" instead of "nobody counted".
1839 // ---------------------------------------------------------------
1840 // Slot-storage share (FV slot program R0). Peak instantaneous
1841 // system share slot/stored and the time that share exceeded 1 %;
1842 // the run-level integrated share is Σ links.stat_slot_vol_dt /
1843 // Σ links.stat_vol_dt, summed at report time. 0 under DW.
1844 double slot_peak_share = 0.0;
1845 double slot_time_above_s = 0.0;
1846
1847 long fv_nsteps = -1;
1848 long fv_nflux = 0;
1849 double fv_avg_h = 0.0;
1850 double fv_last_h = 0.0;
1851 double fv_min_h = 0.0;
1852 double fv_active_min = -1.0;
1853 double fv_active_mean = -1.0;
1854 double fv_active_max = -1.0;
1855 long fv_tier_cells[8] = {0};
1856 int fv_n_tiers = 0;
1857
1858 // dt-argmin attribution (slot program R0): who owned the binding
1859 // CFL element, counted per census / re-tier.
1864
1865 // LTS macro cycles that ran / were rejected. Distinguishes "tiering
1866 // never engaged" from "tiering did not help" (the tier histogram
1867 // alone cannot).
1870
1874 int lstep_mode = 0;
1876
1877 // =========================================================================
1878 // Virtual-junction diagnostics (refactored engine only)
1879 // =========================================================================
1880
1889 struct VJDiag {
1890 std::vector<int> node_idx;
1891 std::vector<int> up_link;
1892 std::vector<int> dn_link;
1893 std::vector<double> resid_max;
1894 std::vector<double> resid_sum;
1895 std::vector<long long> resid_n;
1902 void clear() {
1903 node_idx.clear();
1904 up_link.clear();
1905 dn_link.clear();
1906 resid_max.clear();
1907 resid_sum.clear();
1908 resid_n.clear();
1909 }
1911
1912 // =========================================================================
1913 // Street inlet performance diagnostics
1914 // =========================================================================
1915
1926 struct InletDiag {
1927 std::vector<int> host_node;
1928 std::vector<int> up_link;
1929 std::vector<uint8_t> is_sag;
1930 std::vector<int> num_inlets;
1931 std::vector<int> flow_periods;
1932 std::vector<int> capture_periods;
1933 std::vector<int> backflow_periods;
1934 std::vector<double> peak_flow;
1935 std::vector<double> peak_flow_capture;
1936 std::vector<double> avg_flow_capture;
1937 std::vector<double> bypass_freq;
1938
1943 int count() const { return static_cast<int>(host_node.size()); }
1944
1953 void resize(int n) {
1954 auto un = static_cast<std::size_t>(n);
1955 host_node.assign(un, -1);
1956 up_link.assign(un, -1);
1957 is_sag.assign(un, static_cast<uint8_t>(0));
1958 num_inlets.assign(un, 1);
1959 flow_periods.assign(un, 0);
1960 capture_periods.assign(un, 0);
1961 backflow_periods.assign(un, 0);
1962 peak_flow.assign(un, 0.0);
1963 peak_flow_capture.assign(un, 0.0);
1964 avg_flow_capture.assign(un, 0.0);
1965 bypass_freq.assign(un, 0.0);
1966 }
1967
1974 void clear() {
1975 host_node.clear();
1976 up_link.clear();
1977 is_sag.clear();
1978 num_inlets.clear();
1979 flow_periods.clear();
1980 capture_periods.clear();
1981 backflow_periods.clear();
1982 peak_flow.clear();
1983 peak_flow_capture.clear();
1984 avg_flow_capture.clear();
1985 bypass_freq.clear();
1986 }
1988
1989 // =========================================================================
1990 // Control action log — Gap #67
1991 // Populated by ControlEngine::applyPendingActions() when rpt_controls is on.
1992 // =========================================================================
1993
2002 double date;
2003 };
2004
2007 std::vector<ControlLogEntry> control_log;
2009 std::vector<std::string> control_rule_names;
2011 std::size_t control_log_dropped = 0;
2012 static constexpr std::size_t kMaxControlLog = 1'000'000;
2013
2024 if (control_log.size() >= kMaxControlLog) {
2026 return;
2027 }
2028 control_log.push_back(e);
2029 }
2030
2031 // =========================================================================
2032 // Input file path (for model write / hot start)
2033 // =========================================================================
2034
2039 std::string inp_file_path;
2040
2041 // =========================================================================
2042 // Context-level operations
2043 // =========================================================================
2044
2058 static void updateMaxStats(MaxStats arr[], int obj_type, int idx, double value) {
2059 MaxStats candidate;
2060 candidate.obj_type = obj_type;
2061 candidate.index = idx;
2062 candidate.value = value;
2063 for (int k = 0; k < MAX_STATS; ++k) {
2064 if (std::fabs(candidate.value) > std::fabs(arr[k].value)) {
2065 MaxStats tmp = arr[k];
2066 arr[k] = candidate;
2067 candidate = tmp;
2068 }
2069 }
2070 }
2071
2078 // legacy stats_findMaxStats (stats.c): the slots start at -1.0 (time-
2079 // step critical, flow turns) or 0.0 (non-convergence), so a value
2080 // must exceed that magnitude to enter.
2081 for (int k = 0; k < MAX_STATS; ++k) {
2082 max_courant_crit[k] = MaxStats{0, -1, -1.0};
2083 max_flow_turns[k] = MaxStats{1, -1, -1.0};
2084 max_non_converged[k] = MaxStats{0, -1, 0.0};
2085 }
2086
2087 // Flow instability over the steps after the report start.
2088 const long rpt_steps = routing_stats.report_steps;
2089 if (rpt_steps > 2) {
2090 double z = 100.0 / (2.0 / 3.0 * static_cast<double>(rpt_steps - 2));
2091 for (int j = 0; j < n_links(); ++j) {
2092 double x =
2093 static_cast<double>(links.stat_flow_turns[static_cast<std::size_t>(j)]) * z;
2095 }
2096 }
2097
2098 // The rest are over all routed (non-steady) steps.
2099 const long step_count = routing_stats.n_steps;
2100 const bool dw = options.routing_model == RoutingModel::DYNWAVE;
2101 if (dw) {
2102 for (int j = 0; j < n_nodes(); ++j)
2104 static_cast<double>(
2105 nodes.stat_non_converged_count[static_cast<std::size_t>(j)]) /
2106 static_cast<double>(step_count));
2107 }
2108 if (!dw || options.variable_step == 0.0 || step_count == 0)
2109 return;
2110 const double inv_steps = 1.0 / static_cast<double>(step_count);
2111 for (int j = 0; j < n_nodes(); ++j) {
2112 double x = nodes.stat_time_courant_critical[static_cast<std::size_t>(j)] * inv_steps;
2113 updateMaxStats(max_courant_crit, 0, j, 100.0 * x);
2114 }
2115 for (int j = 0; j < n_links(); ++j) {
2116 double x = links.stat_time_courant_critical[static_cast<std::size_t>(j)] * inv_steps;
2117 updateMaxStats(max_courant_crit, 1, j, 100.0 * x);
2118 }
2119 }
2120
2128 void reset() {
2130 runtime_coupling_used = false;
2133 link_gain_quality = {};
2135 control_log.clear();
2136 control_rule_names.clear();
2138 current_time = 0.0;
2139 current_date = 0.0;
2141 elapsed_ms = 0.0;
2142 old_elapsed_ms = 0.0;
2143 next_report_ms = 0.0;
2144 error_code = 0;
2145 warning_code = 0;
2146 error_message.clear();
2147 warnings.clear();
2148 errors.clear();
2149 title_notes.clear();
2150 deferred_section_rows.clear();
2152 pending_gw_nodes.clear();
2153 pending_gw_aquifers.clear();
2154 pending_link_nodes.clear();
2155
2156 // Clear SoA stores
2157 nodes = NodeData{};
2158 links = LinkData{};
2159 // Reopening a rain-rule model must not reuse the previous subtype
2160 // join rows or append its rules to the freshly parsed rule store.
2161 node_subtypes.clear();
2162 link_subtypes.clear();
2163 node_coupling_2d.clear();
2166 gages = GageData{};
2168 tables = TableData{};
2170
2171 // Clear name indices
2172 node_names.clear();
2173 link_names.clear();
2174 subcatch_names.clear();
2175 gage_names.clear();
2176 pollutant_names.clear();
2177 snowpack_names.clear();
2178
2179 // Clear inflow-related stores that aren't reset by their owning solvers
2181
2182 // E3: transport.ard component config — its apply hook resets it, but
2183 // a reopen WITHOUT the component would otherwise inherit the previous
2184 // model's dispersion.
2186
2187 // A1a: same stale-on-reopen hygiene for water age.
2189 water_age_state.clear();
2190
2191 // H1: and for heat.
2193 heat_state.clear();
2194 lid_layer_state.clear();
2195 bed_state.clear(); // H6b
2196
2197 // Virtual-junction diagnostics
2198 vj_diag.clear();
2199 inlet_diag.clear();
2200
2201 // Clear daily climate state (re-initialized by SWMMEngine on next run)
2203
2204 // Clear spatial, flags, events, and forcing. Per-object tags
2205 // are owned by NodeData/LinkData/SubcatchData and cleared when
2206 // those SoAs are resized/cleared by the wider reset path.
2208 user_flags.clear();
2209 events.clear();
2210 std::fill(std::begin(adjust_temp), std::end(adjust_temp), 0.0);
2211 std::fill(std::begin(adjust_evap), std::end(adjust_evap), 0.0);
2212 std::fill(std::begin(adjust_rain), std::end(adjust_rain), 1.0);
2213 std::fill(std::begin(adjust_hydcon), std::end(adjust_hydcon), 1.0);
2216 subcatch_infil_pattern.clear();
2217 base_n_perv.clear();
2218 base_ds_perv.clear();
2220 forcing = ForcingData{};
2221 }
2222
2229 void save_state() noexcept {
2230 nodes.save_state();
2231 links.save_state();
2232 // (SWMMEngine::step rolls the two halves separately — see
2233 // save_lat_qual_state / save_hyd_state.)
2234 // NOTE: subcatches.save_state() is intentionally NOT called here.
2235 // Subcatchment old-state (old_runoff/old_runon/conc_old) is the
2236 // runoff-step snapshot used to linearly interpolate lateral inflow
2237 // between runoff evaluations (legacy subcatch_setOldState, called
2238 // ONLY inside runoff_execute — i.e. per WET/DRY step, not per routing
2239 // step). Saving it here, every routing step, clobbered old_runoff with
2240 // the current value so old==new and the lateral inflow jumped to the
2241 // full new runoff instantly instead of ramping. It is now saved in the
2242 // runoff-advance loop in SWMMEngine::stepRunoff().
2243 }
2244
2252 void save_lat_qual_state() noexcept {
2253 nodes.save_lat_qual_state();
2254 links.save_qual_state();
2255 }
2256
2263 void save_hyd_state() noexcept {
2264 nodes.save_hyd_state();
2265 links.save_hyd_state();
2266 }
2267
2274 void reset_state() noexcept {
2275 runtime_coupling_used = false;
2276 nodes.reset_state();
2277 links.reset_state();
2278 subcatches.reset_state();
2279 gages.reset_state();
2280 tables.reset_cursors();
2281 current_time = 0.0;
2282 current_date = options.start_date;
2284 elapsed_ms = 0.0;
2285 old_elapsed_ms = 0.0;
2286 // Legacy swmm5.c:721 — ReportTime = 1000 * ReportStep (ms from SIM start)
2287 next_report_ms = 1000.0 * options.report_step;
2288 }
2289
2301 nodes.resize(node_names.size());
2302 links.resize(link_names.size());
2303 subcatches.resize(subcatch_names.size());
2304 gages.resize(gage_names.size());
2305 pollutants.resize_pollutants(pollutant_names.size());
2306 int np = static_cast<int>(pollutant_names.size());
2307 nodes.resize_quality(np);
2308 links.resize_quality(np);
2309 subcatches.resize_quality(np);
2310
2311 // Resize spatial coordinate arrays
2312 spatial.node_x.assign(static_cast<std::size_t>(node_names.size()), 0.0);
2313 spatial.node_y.assign(static_cast<std::size_t>(node_names.size()), 0.0);
2314 spatial.node_has_xy.assign(static_cast<std::size_t>(node_names.size()), 0); // G-X2
2315 spatial.link_x.assign(static_cast<std::size_t>(link_names.size()), 0.0);
2316 spatial.link_y.assign(static_cast<std::size_t>(link_names.size()), 0.0);
2317 spatial.subcatch_x.assign(static_cast<std::size_t>(subcatch_names.size()), 0.0);
2318 spatial.subcatch_y.assign(static_cast<std::size_t>(subcatch_names.size()), 0.0);
2319
2320 // Resize link vertex and subcatchment polygon arrays
2321 spatial.link_vertices_x.resize(static_cast<std::size_t>(link_names.size()));
2322 spatial.link_vertices_y.resize(static_cast<std::size_t>(link_names.size()));
2323 spatial.subcatch_polygon_x.resize(static_cast<std::size_t>(subcatch_names.size()));
2324 spatial.subcatch_polygon_y.resize(static_cast<std::size_t>(subcatch_names.size()));
2325
2326 // Resize gage coordinates
2327 spatial.gage_x.assign(static_cast<std::size_t>(gage_names.size()), 0.0);
2328 spatial.gage_y.assign(static_cast<std::size_t>(gage_names.size()), 0.0);
2329 }
2330
2340 nodes.shrink_to_fit();
2341 links.shrink_to_fit();
2342 subcatches.shrink_to_fit();
2343 gages.shrink_to_fit();
2344 pollutants.shrink_to_fit();
2345 landuses.shrink_to_fit();
2346 buildup.shrink_to_fit();
2347 washoff.shrink_to_fit();
2348 treatment.shrink_to_fit();
2349 spatial.shrink_to_fit();
2350 }
2351
2352 // =========================================================================
2353 // Convenience accessors
2354 // =========================================================================
2355
2357 int n_nodes() const noexcept { return node_names.size(); }
2358
2360 int n_links() const noexcept { return link_names.size(); }
2361
2363 int n_subcatches() const noexcept { return subcatch_names.size(); }
2364
2366 int n_gages() const noexcept { return gage_names.size(); }
2367
2369 int n_pollutants() const noexcept { return pollutant_names.size(); }
2374 int n_landuses() const noexcept { return landuse_names.size(); }
2375
2377 int n_tables() const noexcept { return static_cast<int>(tables.count()); }
2378
2379 // =========================================================================
2380 // Kind-aware table lookups (case-insensitive, legacy hash.c parity).
2381 // Legacy keeps TSERIES and CURVE in separate hash tables, so the same
2382 // name may denote both a curve and a timeseries; every consumer knows
2383 // which kind it wants.
2384 // =========================================================================
2385
2394 int find_timeseries(std::string_view name) const noexcept {
2395 return tables.find_by_kind(name, /*want_timeseries=*/true);
2396 }
2397
2406 int find_curve(std::string_view name) const noexcept {
2407 return tables.find_by_kind(name, /*want_timeseries=*/false);
2408 }
2409
2419 int find_table_any(std::string_view name) const noexcept {
2420 const int ts = find_timeseries(name);
2421 if (ts >= 0)
2422 return ts;
2423 return find_curve(name);
2424 }
2425};
2426
2427} /* namespace openswmm */
2428
2429#endif /* OPENSWMM_ENGINE_SIMULATION_CONTEXT_HPP */
Parsed configuration of the Eulerian ARD transport component (org.hydrocouple.openswmm....
Plan H6b — the bed / hyporheic transient-storage zone.
Thermal state and geometry associated with routed channels.
Climate processing — evaporation, temperature, wind.
Carrier for an external file reference in a SWMM model.
Per-element runtime forcing state — SoA layout.
Structure-of-Arrays (SoA) storage for rain gages.
Heat-transport data (heat plan §1, §3; phase H1).
SoA stores for snowpacks, aquifers, LID controls, and LID usage.
SoA stores for external inflows, DWF, RDII, and time patterns.
SoA stores for transects, streets, inlets, and control rules.
SoA store for [INITIAL_QUALITY] per-element initial concentrations.
Phase A4 — per-(LID unit, layer, species) transported state.
O(1) name-to-index lookup for SWMM objects.
Per-node 1D↔2D coupling structure rows ([2D_NODE_COUPLING]).
Structure-of-Arrays (SoA) storage for all node types.
Relational (normalized) Structure-of-Arrays side-tables for node subtypes.
Structure-of-Arrays (SoA) storage for pollutants and water quality.
SoA stores for land uses, buildup, washoff, and treatment.
Multispecies reaction system data (EPANET-MSX conventions) — SoA, hot/cold split per LARD plan §16 D-...
Simulation options parsed from the [OPTIONS] section.
Spatial frame — CRS specification and coordinate data for nodes/links.
Single source of truth for all transported constituents (Unified Transport master plan §4....
Structure-of-Arrays (SoA) storage for subcatchments.
Time series and rating curve data with bidirectional cursor.
Irregular transect cross-section geometry (HEC-2 style).
User-defined model flags (InfoWorks ICM-style, two-section design).
Water-age tracking data (water age plan §1–§2, phase A1a).
Bidirectional name↔index registry for SWMM objects.
Definition NameIndex.hpp:71
Definition SpeciesRegistry.hpp:61
Stores the full user-flags data: schema definitions + per-object values.
Definition UserFlags.hpp:146
Owns per-cell infiltration parameters, kernel state and held rates.
Definition Infil2D.hpp:175
The S7 store: authored rows, resolved per-cell coverages and state, and the per-species ledgers.
Definition SurfaceQuality2D.hpp:125
Top-level orchestrator for the 2D surface routing module.
Definition SurfaceRouter2D.hpp:86
FileMode
Mode keyword for one [FILES] row — SAVE or USE.
Definition SimulationContext.hpp:183
EngineState
High-level engine lifecycle state.
Definition SimulationContext.hpp:270
@ USE
Definition SimulationContext.hpp:183
@ NONE
Definition SimulationContext.hpp:183
@ SAVE
Definition SimulationContext.hpp:183
@ CLOSED
Resources released.
Definition SimulationContext.hpp:278
@ ENDED
Simulation loop completed.
Definition SimulationContext.hpp:276
@ ERROR_STATE
Fatal error; call swmm_engine_last_error()
Definition SimulationContext.hpp:279
@ RUNNING
Simulation loop in progress.
Definition SimulationContext.hpp:274
@ REPORTED
Summary report written.
Definition SimulationContext.hpp:277
@ BUILDING
Programmatic model construction in progress (no .inp)
Definition SimulationContext.hpp:280
@ CREATED
Context allocated, no input loaded.
Definition SimulationContext.hpp:271
@ PAUSED
Simulation paused (future hot-swap support)
Definition SimulationContext.hpp:275
@ INITIALIZED
Initial conditions applied.
Definition SimulationContext.hpp:273
@ OPENED
Input file parsed, objects allocated.
Definition SimulationContext.hpp:272
Native infiltration kernels with caller-managed accepted-step state. These methods mutate the supplie...
Definition Infiltration.cpp:34
Definition ExchangeLaw.hpp:60
HotstartFormat
Definition SimulationContext.hpp:188
@ LEGACY
Definition SimulationContext.hpp:188
@ AUTO
Definition SimulationContext.hpp:188
@ NATIVE
Definition SimulationContext.hpp:188
@ DYNWAVE
Dynamic wave (full Saint-Venant, implicit Picard)
Definition SimulationOptions.hpp:80
SoA storage for aquifer parameter sets.
Definition HydrologyData.hpp:101
Parsed model.ard state consumed by ArdEngine::init (phase E3).
Definition ArdConfigData.hpp:97
Runtime bed state, one entry per LINK.
Definition BedZoneData.hpp:169
Definition QualityData.hpp:97
Definition InfraData.hpp:350
Dry-weather-flow authoring rows stored in aligned columns.
Definition InflowData.hpp:136
External inflow authoring rows stored in aligned columns.
Definition InflowData.hpp:52
Two-string carrier for any external file path that appears in a SWMM .inp file.
Definition FilePathPair.hpp:63
Definition SimulationContext.hpp:219
FileMode runoff_mode
Definition SimulationContext.hpp:223
FilePathPair hotstart_use_path
Legacy semantics: USE — single hot-start input file.
Definition SimulationContext.hpp:236
FilePathPair rainfall_path
Definition SimulationContext.hpp:221
FileMode rainfall_mode
Definition SimulationContext.hpp:220
FilePathPair outflows_path
Legacy semantics: SAVE only.
Definition SimulationContext.hpp:233
FilePathPair runoff_path
Definition SimulationContext.hpp:224
std::vector< HotstartSaveEntry > hotstart_saves
Definition SimulationContext.hpp:241
bool has_any() const noexcept
Test whether an interface-file operation is configured.
Definition SimulationContext.hpp:251
FilePathPair rdii_path
Definition SimulationContext.hpp:227
FilePathPair inflows_path
Legacy semantics: USE only.
Definition SimulationContext.hpp:230
FileMode rdii_mode
Definition SimulationContext.hpp:226
Definition ForcingData.hpp:70
Structure-of-Arrays storage for all rain gages.
Definition GageData.hpp:95
Parsed model.heat state (heat component, phase H1).
Definition HeatData.hpp:324
Runtime heat state shared by the engines (phase H1).
Definition HeatData.hpp:427
Configuration parsed from the [FILES] section.
Definition SimulationContext.hpp:210
double datetime
Definition SimulationContext.hpp:214
HotstartFormat format
Optional trailing LEGACY / NATIVE keyword on the row.
Definition SimulationContext.hpp:216
FilePathPair path
Definition SimulationContext.hpp:211
Definition InitialQualityData.hpp:47
Definition InfraData.hpp:114
Definition InfraData.hpp:204
Definition QualityData.hpp:45
SoA storage for LID control type definitions.
Definition HydrologyData.hpp:138
Per-(unit, layer, species) state for every LID unit in the model.
Definition LidLayerSpeciesData.hpp:71
SoA storage for LID usage assignments to subcatchments.
Definition HydrologyData.hpp:192
Sparse [2D_NODE_COUPLING] rows (one per authored node).
Definition NodeCoupling2DData.hpp:91
Structure-of-Arrays storage for all nodes.
Definition NodeData.hpp:125
Owns the three node subtype side-tables plus the reverse index map.
Definition NodeSubtypes.hpp:535
Time-pattern authoring names, types and multiplier vectors.
Definition InflowData.hpp:404
One plugin entry from the [PLUGINS] section.
Definition SimulationContext.hpp:136
std::string path
Shared library path.
Definition SimulationContext.hpp:137
std::vector< std::string > init_args
Extra tokens from the [PLUGINS] row.
Definition SimulationContext.hpp:138
Static properties for each pollutant species.
Definition PollutantData.hpp:71
One row of [PROCESS_COMPONENTS] (Unified Transport suite, D-UT8).
Definition SimulationContext.hpp:158
std::string config_path
config="…" argument (may be empty)
Definition SimulationContext.hpp:160
std::vector< std::pair< std::string, std::string > > args
other key/value args
Definition SimulationContext.hpp:161
std::string id
Component id (or library path — HC2)
Definition SimulationContext.hpp:159
std::string resolved_config_path
Definition SimulationContext.hpp:167
Node-to-hydrograph authoring assignments stored in aligned columns.
Definition InflowData.hpp:216
Exponential IA-decay authoring rows keyed by group and response.
Definition InflowData.hpp:372
Definition ReactionData.hpp:58
Definition SimulationContext.hpp:1998
double new_setting
The new target setting value (0-1)
Definition SimulationContext.hpp:2001
double date
OADate when the change occurred.
Definition SimulationContext.hpp:2002
int link_idx
Index of the link whose setting changed.
Definition SimulationContext.hpp:1999
int rule_idx
Index into control_rule_names; -1 = unknown ("Rule?")
Definition SimulationContext.hpp:2000
double end
Event end (DateTime decimal days)
Definition SimulationContext.hpp:824
double start
Event start (DateTime decimal days)
Definition SimulationContext.hpp:823
std::vector< int > num_inlets
Definition SimulationContext.hpp:1930
void resize(int n)
Replace all inlet diagnostic columns with default rows.
Definition SimulationContext.hpp:1953
std::vector< int > host_node
inlet-junction node (−1 = conduit host)
Definition SimulationContext.hpp:1927
std::vector< int > backflow_periods
Definition SimulationContext.hpp:1933
std::vector< int > up_link
approach conduit (−1 = none)
Definition SimulationContext.hpp:1928
std::vector< int > flow_periods
Definition SimulationContext.hpp:1931
std::vector< int > capture_periods
Definition SimulationContext.hpp:1932
std::vector< double > peak_flow
peak approach flow (cfs)
Definition SimulationContext.hpp:1934
std::vector< double > avg_flow_capture
Σ capture efficiency over capture periods.
Definition SimulationContext.hpp:1936
int count() const
Count inlet diagnostic rows from the host-node column.
Definition SimulationContext.hpp:1943
std::vector< uint8_t > is_sag
resolved placement: 1 = ON_SAG
Definition SimulationContext.hpp:1929
void clear()
Erase every inlet diagnostic column.
Definition SimulationContext.hpp:1974
std::vector< double > peak_flow_capture
capture efficiency at peak flow (%)
Definition SimulationContext.hpp:1935
std::vector< double > bypass_freq
Definition SimulationContext.hpp:1937
double boundary_in
Cumulative boundary inflow (m³)
Definition SimulationContext.hpp:1580
double external_in
Definition SimulationContext.hpp:1574
double solver_active_max
max active-cell fraction
Definition SimulationContext.hpp:1623
double evap_out
Definition SimulationContext.hpp:1582
double outfall_in
Cumulative 1D outfall discharge into 2D (m³)
Definition SimulationContext.hpp:1578
double boundary_out
Cumulative boundary outflow (m³)
Definition SimulationContext.hpp:1581
double coupling_2d_to_1d_out
Cumulative 2D→1D drainage out (m³)
Definition SimulationContext.hpp:1577
double solver_avg_h
mean accepted internal step (s)
Definition SimulationContext.hpp:1617
double external_out
Runtime external source volumes (m³)
Definition SimulationContext.hpp:1574
long solver_tier_cells[8]
cumulative cells per LTS tier
Definition SimulationContext.hpp:1624
double solver_active_mean
mean active-cell fraction
Definition SimulationContext.hpp:1622
double final_storage
Latest surface storage (m³)
Definition SimulationContext.hpp:1573
double init_storage
Initial surface storage (m³)
Definition SimulationContext.hpp:1572
double solver_active_min
min active-cell fraction
Definition SimulationContext.hpp:1621
double solver_last_h
last accepted internal step (s)
Definition SimulationContext.hpp:1618
double infil_aquifer_pending
Definition SimulationContext.hpp:1601
double infil_to_aquifer
Definition SimulationContext.hpp:1594
double error() const
2D surface continuity error (fraction).
Definition SimulationContext.hpp:1628
double outfall_out
Cumulative 2D→pipe withdrawal at submerged outfalls (m³)
Definition SimulationContext.hpp:1579
double aquifer_in
Definition SimulationContext.hpp:1609
long solver_nsteps
internal (marcher) substeps
Definition SimulationContext.hpp:1615
long solver_nrhs
face-kernel evaluations
Definition SimulationContext.hpp:1616
int solver_n_tiers
populated tier count
Definition SimulationContext.hpp:1625
double infil_out
Definition SimulationContext.hpp:1587
bool active
True if the 2D module ran.
Definition SimulationContext.hpp:1610
double rainfall_in
Cumulative rainfall volume (m³)
Definition SimulationContext.hpp:1575
double coupling_1d_to_2d_in
Cumulative 1D→2D spill into 2D (m³)
Definition SimulationContext.hpp:1576
Definition SimulationContext.hpp:1186
double routing_rdii
Definition SimulationContext.hpp:1229
double rdii_rainfall
Definition SimulationContext.hpp:1215
std::vector< double > qual_routing_ex_in
External (interface file) quality mass inflow.
Definition SimulationContext.hpp:1328
double gw_infil
Cumulative infiltration to GW (ft)
Definition SimulationContext.hpp:1272
double routing_gw_inflow
Definition SimulationContext.hpp:1221
double runoff_runon
Outfall-routed runon volume (ft3), legacy RUNOFF_RUNON.
Definition SimulationContext.hpp:1189
double routing_init_storage
Definition SimulationContext.hpp:1251
double routing_evap_loss
Definition SimulationContext.hpp:1249
double rdii_produced
Definition SimulationContext.hpp:1216
std::vector< double > qual_surface_buildup
Accumulated buildup during sim.
Definition SimulationContext.hpp:1313
std::vector< double > qual_ponded_lost
Ponded mass written off when a surface dried (legacy FINAL_LOAD)
Definition SimulationContext.hpp:1312
double routing_dry_weather
Definition SimulationContext.hpp:1219
std::vector< double > qual_routing_final
Final stored quality mass.
Definition SimulationContext.hpp:1323
double runoff_runoff
Total surface runoff volume (ft3)
Definition SimulationContext.hpp:1192
std::vector< double > qual_init_buildup
Initial buildup mass.
Definition SimulationContext.hpp:1309
std::vector< double > qual_routing_init
Initial stored quality mass.
Definition SimulationContext.hpp:1322
std::vector< double > qual_runoff_load
Mass load in surface runoff.
Definition SimulationContext.hpp:1318
double last_step_flow_error
Definition SimulationContext.hpp:1301
std::vector< double > qual_final_buildup
Final buildup mass.
Definition SimulationContext.hpp:1310
double routing_final_storage
Definition SimulationContext.hpp:1252
double runoff_init_store
Initial surface storage (ft3)
Definition SimulationContext.hpp:1196
double gw_lower_perc
Cumulative deep percolation (ft)
Definition SimulationContext.hpp:1275
double gw_infil_2d_recharge
Definition SimulationContext.hpp:1288
double routing_seep_loss
Definition SimulationContext.hpp:1250
std::vector< double > qual_routing_flood
Quality mass lost to flooding.
Definition SimulationContext.hpp:1321
double routing_link_gw_inflow
Definition SimulationContext.hpp:1228
double runoff_snowremov
Total snow removal volume (ft3)
Definition SimulationContext.hpp:1195
std::vector< double > qual_routing_final_dry
Definition SimulationContext.hpp:1336
std::vector< double > qual_routing_dw_in
Dry weather quality mass inflow.
Definition SimulationContext.hpp:1326
double gw_upper_evap
Cumulative upper zone evaporation (ft)
Definition SimulationContext.hpp:1273
double routing_external
Definition SimulationContext.hpp:1230
std::vector< double > qual_infil_loss
Mass lost to infiltration.
Definition SimulationContext.hpp:1317
double runoff_final_store
Definition SimulationContext.hpp:1197
std::vector< double > qual_routing_reacted
Quality mass lost to decay.
Definition SimulationContext.hpp:1324
double routing_wet_weather
Definition SimulationContext.hpp:1220
std::array< double, 11 > routing_report
Definition SimulationContext.hpp:1261
std::vector< double > qual_wet_deposition
Wet deposition mass.
Definition SimulationContext.hpp:1314
double step_ext_withdrawal
Definition SimulationContext.hpp:1306
double gw_final_storage
Definition SimulationContext.hpp:1278
std::vector< double > qual_routing_seep
Quality mass lost to seepage.
Definition SimulationContext.hpp:1329
double step_gw_inflow
Definition SimulationContext.hpp:1294
double runoff_rainfall
Total rainfall volume (ft3)
Definition SimulationContext.hpp:1188
void reset()
Reset continuity totals while retaining pollutant array sizes and initial buildup.
Definition SimulationContext.hpp:1381
double gw_lateral_flow
Cumulative lateral GW flow (ft)
Definition SimulationContext.hpp:1276
std::vector< double > qual_routing_ii_in
RDII quality mass inflow.
Definition SimulationContext.hpp:1325
double routing_flooding
Definition SimulationContext.hpp:1231
void resize_quality(int n_pollutants)
Resize and zero all pollutant continuity arrays.
Definition SimulationContext.hpp:1347
double gw_error() const
Groundwater continuity error (fraction). Gap #72.
Definition SimulationContext.hpp:1470
double runoff_evap
Total evaporation volume (ft3)
Definition SimulationContext.hpp:1190
double gw_init_storage
Initial GW storage (ft)
Definition SimulationContext.hpp:1277
std::vector< double > qual_routing_gw_in
Groundwater quality mass inflow.
Definition SimulationContext.hpp:1327
double step_flooding
Definition SimulationContext.hpp:1291
std::vector< double > qual_sweeping
Mass removed by sweeping.
Definition SimulationContext.hpp:1315
std::vector< double > routing_forcing_qual_inflow
Per-pollutant cumulative user-forced quality mass.
Definition SimulationContext.hpp:1268
double routing_error() const
Routing continuity error (fraction).
Definition SimulationContext.hpp:1460
double gw_lower_evap
Cumulative lower zone evaporation (ft)
Definition SimulationContext.hpp:1274
std::vector< double > qual_routing_outflow
Quality mass leaving at outfalls.
Definition SimulationContext.hpp:1320
double runoff_final_snow
Definition SimulationContext.hpp:1211
double routing_forcing_inflow
Cumulative user-forced lateral inflow (ft3)
Definition SimulationContext.hpp:1264
double routing_coupling_out
Definition SimulationContext.hpp:1247
double step_rdii_inflow
Definition SimulationContext.hpp:1295
double runoff_infil
Total infiltration volume (ft3)
Definition SimulationContext.hpp:1191
double step_outflow
Definition SimulationContext.hpp:1292
std::vector< double > qual_bmp_removal
BMP treatment removal.
Definition SimulationContext.hpp:1316
double routing_outflow
Definition SimulationContext.hpp:1248
double runoff_lid_drain
LID drain-to-node outflow (ft3), legacy RUNOFF_DRAINS / VlidDrain.
Definition SimulationContext.hpp:1193
double runoff_error() const
Runoff continuity error (fraction).
Definition SimulationContext.hpp:1448
std::vector< double > qual_routing_wet
Wet weather quality inflow to routing.
Definition SimulationContext.hpp:1319
std::vector< double > qual_routing_evap
Definition SimulationContext.hpp:1330
double step_dw_inflow
Definition SimulationContext.hpp:1293
double step_ext_inflow
Definition SimulationContext.hpp:1296
double runoff_init_snow
Definition SimulationContext.hpp:1201
Top-N element statistic entry (matching legacy TMaxStats).
Definition SimulationContext.hpp:1642
int index
element index (-1 = unused slot)
Definition SimulationContext.hpp:1644
int obj_type
0 = NODE, 1 = LINK
Definition SimulationContext.hpp:1643
double value
statistic value (percentage or index)
Definition SimulationContext.hpp:1645
D-NS1 negative-source clamp bookkeeping (subplan §3.1, X6).
Definition SimulationContext.hpp:1488
bool api_warned
first negative API mass flux
Definition SimulationContext.hpp:1499
int first_node
Definition SimulationContext.hpp:1492
void reset()
Clear extraction-clamp diagnostics for a new run.
Definition SimulationContext.hpp:1505
double shortfall_mass
unmet extraction, internal units
Definition SimulationContext.hpp:1490
long clamp_events
pollutant clamps, all engines
Definition SimulationContext.hpp:1489
bool first_clamp_recorded
Definition SimulationContext.hpp:1498
long age_clamp_events
age-row clamps
Definition SimulationContext.hpp:1491
Cumulative mass balance totals for runoff and routing.
Definition SimulationContext.hpp:1182
std::vector< double > water_m3
Definition SimulationContext.hpp:1183
std::vector< double > heat_j
Definition SimulationContext.hpp:1183
std::vector< double > pollutant_amounts
Definition SimulationContext.hpp:1183
std::vector< double > reverse_m3
Definition SimulationContext.hpp:1183
Definition SimulationContext.hpp:1529
void clear()
Zero accumulated inflow and clear the pending-data flag.
Definition SimulationContext.hpp:1561
std::vector< double > mass
Definition SimulationContext.hpp:1530
std::vector< double > vol
Definition SimulationContext.hpp:1530
std::vector< double > msx
Definition SimulationContext.hpp:1530
void ensure(int nn, int np, int ns)
Ensure node and flattened species accumulator dimensions.
Definition SimulationContext.hpp:1544
std::vector< double > age_vol
Definition SimulationContext.hpp:1530
std::vector< double > temp_vol
Definition SimulationContext.hpp:1530
bool any
Definition SimulationContext.hpp:1531
void record_step(double dt, bool steady, bool first_step)
Record a step using legacy steady-state and first-step rules.
Definition SimulationContext.hpp:1707
void update_iterations(int iters, bool converged)
Accumulate routing iterations and non-convergence events.
Definition SimulationContext.hpp:1734
double sum_step
Sum of all routing time steps (sec)
Definition SimulationContext.hpp:1662
double sum_iterations
Sum of iterations for averaging.
Definition SimulationContext.hpp:1678
static constexpr int N_TIME_BINS
Number of time step histogram bins (matching legacy TIMELEVELS=5).
Definition SimulationContext.hpp:1672
long n_steps
Total number of routing steps.
Definition SimulationContext.hpp:1663
long report_steps
Flow-stat steps after report start (legacy ReportStepCount)
Definition SimulationContext.hpp:1666
double max_outfall_flow
Peak of the summed outfall inflow, cfs (legacy MaxOutfallFlow)
Definition SimulationContext.hpp:1668
long fv_macro_rejected
Definition SimulationContext.hpp:1869
long fv_macro_cycles
Definition SimulationContext.hpp:1868
double fv_active_min
min active-face fraction
Definition SimulationContext.hpp:1852
double avg_step() const
Compute the mean duration of counted routing steps.
Definition SimulationContext.hpp:1804
void init_histogram(double route_step, double min_route_step)
Set descending logarithmic time-step histogram edges.
Definition SimulationContext.hpp:1751
double max_step
Maximum routing time step used (sec)
Definition SimulationContext.hpp:1661
double min_step
Minimum routing time step used (sec)
Definition SimulationContext.hpp:1660
void update(double dt)
Accumulate a step into minimum, maximum, sum and count.
Definition SimulationContext.hpp:1688
double steady_pct
Percent of time in steady state.
Definition SimulationContext.hpp:1664
double fv_last_h
last substep (s)
Definition SimulationContext.hpp:1850
double step_intervals[N_TIME_BINS+1]
Histogram bin edges.
Definition SimulationContext.hpp:1674
void record_step_bin(double dt)
Count one duration in the current histogram.
Definition SimulationContext.hpp:1790
long step_counts[N_TIME_BINS+1]
Histogram bin counts.
Definition SimulationContext.hpp:1673
long fv_nsteps
explicit substeps over the run
Definition SimulationContext.hpp:1847
long fv_tier_cells[8]
rebuild-sampled cells per LTS tier
Definition SimulationContext.hpp:1855
long fv_dt_argmin_band
Definition SimulationContext.hpp:1861
double fv_active_max
max active-face fraction
Definition SimulationContext.hpp:1854
double fv_avg_h
mean substep (s)
Definition SimulationContext.hpp:1849
double fv_min_h
smallest substep taken (s)
Definition SimulationContext.hpp:1851
double max_courant
Maximum Courant number observed.
Definition SimulationContext.hpp:1679
int fv_n_tiers
populated tier count
Definition SimulationContext.hpp:1856
double fv_active_mean
mean active-face fraction
Definition SimulationContext.hpp:1853
double pct_non_converged() const
Compute non-converged steps as a percentage of counted steps.
Definition SimulationContext.hpp:1814
double slot_peak_share
Definition SimulationContext.hpp:1844
double slot_time_above_s
Definition SimulationContext.hpp:1845
double report_time
Their total time, sec (legacy RoutingTimeSpan)
Definition SimulationContext.hpp:1667
void build_histogram()
Derive histogram edges from recorded extrema.
Definition SimulationContext.hpp:1771
long fv_nflux
face flux evaluations
Definition SimulationContext.hpp:1848
long n_non_converged
Non-convergence and iteration tracking.
Definition SimulationContext.hpp:1677
int lstep_mode
Definition SimulationContext.hpp:1874
long fv_dt_argmin_pressurized
Definition SimulationContext.hpp:1860
long fv_dt_argmin_node
Definition SimulationContext.hpp:1863
double steady_time
Time skipped as steady state (sec)
Definition SimulationContext.hpp:1665
double computed_avg_iterations() const
Compute mean routing iterations per counted step.
Definition SimulationContext.hpp:1826
long fv_dt_argmin_free
Definition SimulationContext.hpp:1862
twoD::SurfaceRouter2D * surface_router
Definition SimulationContext.hpp:1049
std::vector< twoD::PendingBoundaryRow > * pending_bc
Definition SimulationContext.hpp:1010
std::vector< std::string > * aquifer_links
Definition SimulationContext.hpp:1042
twoD::SubsurfaceState * aquifer_state
Definition SimulationContext.hpp:1048
twoD::MeshData * mesh
Definition SimulationContext.hpp:1007
twoD::GwTransportData * gw
Definition SimulationContext.hpp:1026
twoD::SubsurfaceConfig * aquifer
Definition SimulationContext.hpp:1035
std::vector< twoD::PendingBoundaryQualityRow > * pending_bq
Definition SimulationContext.hpp:1016
std::vector< twoD::PendingEdgeConveyanceRow > * pending_ec
Definition SimulationContext.hpp:1011
std::vector< twoD::PendingInitialQualityRow > * pending_iq
Definition SimulationContext.hpp:1014
std::vector< twoD::PendingInitialBedQualityRow > * pending_ibq
Definition SimulationContext.hpp:1015
std::vector< std::string > * aquifer_nodes
Definition SimulationContext.hpp:1039
twoD::BoundaryData * boundary
Definition SimulationContext.hpp:1009
twoD::Infil2D * infil
Definition SimulationContext.hpp:1021
twoD::SolverOptions2D * options
Definition SimulationContext.hpp:1008
twoD::SubsurfaceTransportState * aquifer_transport
Definition SimulationContext.hpp:1052
twoD::SurfaceQuality2D * surface_quality
Definition SimulationContext.hpp:1030
std::vector< int > up_link
upstream conduit (through orientation, -1 sag/peak)
Definition SimulationContext.hpp:1891
std::vector< int > dn_link
downstream conduit (-1 sag/peak)
Definition SimulationContext.hpp:1892
void clear()
Erase all virtual-junction diagnostic rows.
Definition SimulationContext.hpp:1902
std::vector< long long > resid_n
number of accumulated steps
Definition SimulationContext.hpp:1895
std::vector< int > node_idx
virtual junction node index
Definition SimulationContext.hpp:1890
std::vector< double > resid_max
max |R_j| over the run (cfs·ft/s)
Definition SimulationContext.hpp:1893
std::vector< double > resid_sum
Σ|R_j| for mean reporting.
Definition SimulationContext.hpp:1894
std::vector< std::pair< std::string, std::string > > deferred_section_rows
Section rows whose target object had not been parsed yet.
Definition SimulationContext.hpp:1070
void save_hyd_state() noexcept
Roll node and link hydraulic values to old-step arrays.
Definition SimulationContext.hpp:2263
struct openswmm::SimulationContext::MassBalance mass_balance
NameIndex aquifer_names
Definition SimulationContext.hpp:866
std::vector< double > coupled_pond_band
Definition SimulationContext.hpp:1150
std::map< std::string, std::vector< std::string > > passthrough_sections
Sections the solver never reads, kept verbatim so a save does not delete them: [LABELS],...
Definition SimulationContext.hpp:442
TransectStore transects
Definition SimulationContext.hpp:790
struct openswmm::SimulationContext::VJDiag vj_diag
UserFlags user_flags
User-defined flags from [USER_FLAGS] section.
Definition SimulationContext.hpp:912
LinkSubtypes link_subtypes
Relational per-subtype link side-tables (Phase 6) — the link analogue of node_subtypes....
Definition SimulationContext.hpp:588
struct openswmm::SimulationContext::OutfallExports outfall_exports
void save_state() noexcept
Snapshot current state into old-step arrays before solving.
Definition SimulationContext.hpp:2229
double old_elapsed_ms
Elapsed routing time (ms) at the START of the current step.
Definition SimulationContext.hpp:520
NameIndex subcatch_names
Subcatchment name → subcatchment index.
Definition SimulationContext.hpp:736
NameIndex node_names
Node name → node index.
Definition SimulationContext.hpp:724
SpeciesRegistry species_registry
Species registry — the single source of truth for transported constituents (master plan §4....
Definition SimulationContext.hpp:616
std::vector< double > coupled_pond_area
Above-rim pond of each 2D-coupled junction under dynamic wave (2D_OPTIONS COUPLING_POND_MODE / COUPLI...
Definition SimulationContext.hpp:1149
ReactionData reactions
Multispecies reaction system (EPANET-MSX conventions), parsed from the reactions component's config f...
Definition SimulationContext.hpp:624
InletUsageStore inlet_usages
Definition SimulationContext.hpp:810
MaxStats max_courant_crit[MAX_STATS]
Top-5 CFL time-step critical elements.
Definition SimulationContext.hpp:1651
int n_nodes() const noexcept
Number of nodes.
Definition SimulationContext.hpp:2357
ExtInflowData ext_inflows
Definition SimulationContext.hpp:779
static void updateMaxStats(MaxStats arr[], int obj_type, int idx, double value)
Insert a candidate into a fixed top-five array by absolute magnitude.
Definition SimulationContext.hpp:2058
std::vector< double > surface_outfall_link_limit
System mass-balance totals for the optional 2D surface domain.
Definition SimulationContext.hpp:1520
NodeData nodes
All node state and properties.
Definition SimulationContext.hpp:563
std::uint64_t xsect_generation
Definition SimulationContext.hpp:797
double adjust_rain[12]
Definition SimulationContext.hpp:842
MaxStats max_non_converged[MAX_STATS]
Top-5 nodes with highest non-convergence frequency.
Definition SimulationContext.hpp:1655
static constexpr std::size_t kMaxControlLog
Definition SimulationContext.hpp:2012
TableData tables
All time series and rating curves.
Definition SimulationContext.hpp:714
struct openswmm::SimulationContext::NegativeSourceStats negsrc
std::vector< std::pair< std::string, long > > unknown_section_headers
Every unknown section header read, as (token as written, 1-based line number), in file order — legacy...
Definition SimulationContext.hpp:1077
double adjust_temp[12]
Monthly climate adjustment factors from [ADJUSTMENTS] section.
Definition SimulationContext.hpp:838
MaxStats max_mass_bal_errs[MAX_STATS]
Top-5 nodes with highest continuity errors.
Definition SimulationContext.hpp:1657
int error_code
Most recent error code (0 = no error).
Definition SimulationContext.hpp:1087
RDIIAssignData rdii_assigns
Definition SimulationContext.hpp:781
QualityOnlyInflow surface_outfall_quality
D2: booked as external inflow.
Definition SimulationContext.hpp:1567
AquiferStore aquifers
Definition SimulationContext.hpp:865
bool runtime_coupling_used
Runtime prescriptions require a future restart format.
Definition SimulationContext.hpp:1570
BedZoneState bed_state
The bed / hyporheic transient-storage zone (phase H6b).
Definition SimulationContext.hpp:668
NameIndex snowpack_names
Definition SimulationContext.hpp:864
std::vector< int > subcatch_d_store_pattern
Definition SimulationContext.hpp:851
InletStore inlets
Definition SimulationContext.hpp:809
GageData gages
All rain gage state and properties.
Definition SimulationContext.hpp:600
FilesSpec files
Secondary file references parsed from [FILES].
Definition SimulationContext.hpp:974
std::vector< ControlLogEntry > control_log
Definition SimulationContext.hpp:2007
DwfData dwf_inflows
Definition SimulationContext.hpp:780
struct openswmm::SimulationContext::InletDiag inlet_diag
NameIndex gage_names
Rain gage name → gage index.
Definition SimulationContext.hpp:742
BuildupData buildup
Definition SimulationContext.hpp:762
std::vector< std::pair< int, std::string > > pending_gw_nodes
Definition SimulationContext.hpp:882
int n_gages() const noexcept
Number of rain gages.
Definition SimulationContext.hpp:2366
std::string inp_file_path
Path to the input .inp file (empty if not opened from a file).
Definition SimulationContext.hpp:2039
std::vector< std::uint8_t > coupled_node
Per-node flag: 1 if the node is a 2D-coupled junction (a non-outfall coupling point),...
Definition SimulationContext.hpp:1138
NodeSubtypes node_subtypes
Relational side-tables for node subtypes (storage/outfall/divider).
Definition SimulationContext.hpp:574
bool gpkg_units_internal
Definition SimulationContext.hpp:806
std::vector< std::string > errors
Accumulated error messages written to report file.
Definition SimulationContext.hpp:1116
WaterAgeState water_age_state
Definition SimulationContext.hpp:640
RDIIDecayData rdii_decay
Parsed [RDII_DECAY] data (exponential IA model)
Definition SimulationContext.hpp:783
EngineState state
Current lifecycle state of the engine.
Definition SimulationContext.hpp:397
WashoffData washoff
Definition SimulationContext.hpp:763
NodeCoupling2DRows node_coupling_2d
[2D_NODE_COUPLING] rows: per-node coupling structure type and its authored parameters (model data,...
Definition SimulationContext.hpp:1125
int warning_code
Most recent warning code (0 = no warning).
Definition SimulationContext.hpp:1093
NameIndex landuse_names
Definition SimulationContext.hpp:760
int n_tables() const noexcept
Number of tables (time series + curves).
Definition SimulationContext.hpp:2377
struct openswmm::SimulationContext::RoutingStepStats routing_stats
LidControlStore lid_controls
Definition SimulationContext.hpp:867
std::vector< int > subcatch_infil_pattern
Definition SimulationContext.hpp:852
double adjust_hydcon[12]
Definition SimulationContext.hpp:843
std::vector< std::string > title_notes
Project title and notes (from [TITLE] section).
Definition SimulationContext.hpp:425
std::vector< std::string > warnings
Accumulated warning messages written to report file.
Definition SimulationContext.hpp:1107
std::vector< std::string > control_rule_names
Rule names by rule index, interned by ControlEngine as actions are logged.
Definition SimulationContext.hpp:2009
ControlRuleStore control_rules
Definition SimulationContext.hpp:811
struct openswmm::SimulationContext::MassBalance2D mass_balance_2d
int find_curve(std::string_view name) const noexcept
Find the lowest-index matching curve table.
Definition SimulationContext.hpp:2406
std::time_t wall_start
Wall-clock time stamped at the start of SWMMEngine::open().
Definition SimulationContext.hpp:410
TreatmentData treatment
Definition SimulationContext.hpp:764
bool has_subcatch_adj_patterns
True if any pattern index >= 0.
Definition SimulationContext.hpp:857
void save_lat_qual_state() noexcept
Roll node lateral inflows and node/link quality to their old-step arrays.
Definition SimulationContext.hpp:2252
WaterAgeConfigData water_age_config
Water-age tracking (phase A1a): per-source initial ages parsed from the waterage component (model....
Definition SimulationContext.hpp:639
ArdConfigData ard_config
Eulerian ARD transport component configuration, parsed from the model.ard config file registered via ...
Definition SimulationContext.hpp:632
void finalize_max_stats()
Compute top-5 arrays for CFL-critical, flow turns, and non-convergence.
Definition SimulationContext.hpp:2077
LinkData links
All link state and properties.
Definition SimulationContext.hpp:580
UnitHydData unit_hyds
Parsed [HYDROGRAPHS] data.
Definition SimulationContext.hpp:782
std::vector< std::pair< int, std::pair< std::string, std::string > > > pending_link_nodes
Definition SimulationContext.hpp:891
double dt_controls_remaining
Time remaining until the next control rule event (seconds).
Definition SimulationContext.hpp:553
void reset()
Fully reset the context to a CREATED state.
Definition SimulationContext.hpp:2128
int n_pollutants() const noexcept
Number of pollutants.
Definition SimulationContext.hpp:2369
std::vector< ProcessComponentSpec > process_component_specs
Process-component registrations parsed from [PROCESS_COMPONENTS].
Definition SimulationContext.hpp:955
void logControlAction(const ControlLogEntry &e)
Append a control action or count it as dropped at the log cap.
Definition SimulationContext.hpp:2023
LidUsageStore lid_usage
Definition SimulationContext.hpp:870
double next_report_ms
Next report instant in MILLISECONDS from start_date.
Definition SimulationContext.hpp:532
LidLayerSpeciesState lid_layer_state
A4: per-(LID unit, layer, species) transported state.
Definition SimulationContext.hpp:647
InitialQualityData initial_quality
Per-element initial quality rows from [INITIAL_QUALITY].
Definition SimulationContext.hpp:773
climate::ClimateState climate_state
Daily climate state — temperature, evaporation, wind, humidity.
Definition SimulationContext.hpp:465
MaxStats max_flow_turns[MAX_STATS]
Top-5 links with highest flow instability index.
Definition SimulationContext.hpp:1653
std::vector< std::pair< std::string, std::vector< std::string > > > embedded_component_sections
Embedded component sections found in the legacy .inp ([REACTION_*] today; other component families as...
Definition SimulationContext.hpp:964
void allocate_objects()
Allocate all object arrays after input parsing is complete.
Definition SimulationContext.hpp:2300
QualityOnlyInflow link_gain_quality
gaining conduits: groundwater inflow
Definition SimulationContext.hpp:1568
StateAccessors state_accessors
Solver-neutral accessors for reading and writing solver-internal state at hot-start save/load time.
Definition SimulationContext.hpp:984
std::vector< std::string > reported_species_names
Species names as REPORTED (phase A2b): the pollutant names, then __WATER_AGE__ when [OPTIONS] WATER_A...
Definition SimulationContext.hpp:685
int n_subcatches() const noexcept
Number of subcatchments.
Definition SimulationContext.hpp:2363
int n_links() const noexcept
Number of links.
Definition SimulationContext.hpp:2360
std::vector< double > base_ds_perv
Definition SimulationContext.hpp:856
NameIndex link_names
Link name → link index.
Definition SimulationContext.hpp:730
std::vector< PluginSpec > plugin_specs
Plugin library specs parsed from [PLUGINS].
Definition SimulationContext.hpp:946
StreetStore streets
Definition SimulationContext.hpp:808
double coupling_delivery_remaining
Remaining seconds of the current 1D↔2D coupling delivery window.
Definition SimulationContext.hpp:1165
double current_time
Current simulation time in SECONDS from start_date.
Definition SimulationContext.hpp:489
void refreshReportedSpecies()
Rebuild derived output columns after pre-initialization reaction edits.
Definition SimulationContext.hpp:688
struct openswmm::SimulationContext::TwoDModelIO twod_io
double elapsed_ms
Elapsed routing time in MILLISECONDS from start_date.
Definition SimulationContext.hpp:512
int find_table_any(std::string_view name) const noexcept
Find a named table with time-series precedence.
Definition SimulationContext.hpp:2419
ForcingData forcing
Per-element runtime forcing state (lateral inflows, head boundaries, rainfall, evap,...
Definition SimulationContext.hpp:935
int n_landuses() const noexcept
Count registered land-use names.
Definition SimulationContext.hpp:2374
std::vector< double > base_n_perv
Base values for pattern-adjusted parameters (populated at init).
Definition SimulationContext.hpp:855
double adjust_evap[12]
[ADJUSTMENTS] EVAP: ADDED to the evaporation rate (in/day or mm/day), legacy Adjust....
Definition SimulationContext.hpp:839
HeatState heat_state
Definition SimulationContext.hpp:656
int n_reported_species() const noexcept
Length of reported_species_names (pollutants + age when enabled).
Definition SimulationContext.hpp:706
std::string error_message
Human-readable message for the last error/warning.
Definition SimulationContext.hpp:1098
std::size_t control_log_dropped
Actions NOT logged because the cap was reached; the report says so once.
Definition SimulationContext.hpp:2011
SpatialFrame spatial
Coordinate reference system and georeferenced coordinates.
Definition SimulationContext.hpp:901
std::vector< std::pair< int, std::string > > pending_gw_aquifers
Definition SimulationContext.hpp:886
std::vector< transect::TransectData > transect_tables
Built transect geometry tables (indexed same as transects).
Definition SimulationContext.hpp:792
SnowpackStore snowpacks
Definition SimulationContext.hpp:863
int find_timeseries(std::string_view name) const noexcept
Find the lowest-index matching time-series table.
Definition SimulationContext.hpp:2394
std::vector< int > subcatch_n_perv_pattern
Per-subcatchment pattern indices for N-PERV, DSTORE, INFIL adjustments.
Definition SimulationContext.hpp:850
PatternData patterns
Definition SimulationContext.hpp:784
static constexpr int MAX_STATS
Definition SimulationContext.hpp:1648
NameIndex lid_names
Definition SimulationContext.hpp:869
HeatConfigData heat_config
Heat transport (phase H1): per-source inlet temperatures parsed from the heat component (model....
Definition SimulationContext.hpp:655
NameIndex pollutant_names
Pollutant name → pollutant index.
Definition SimulationContext.hpp:748
void shrink_all_to_fit()
Release excess vector capacity on all owned SoA data stores.
Definition SimulationContext.hpp:2339
void reset_state() noexcept
Reset all state variables to initial conditions (cold start).
Definition SimulationContext.hpp:2274
std::vector< Event > events
Definition SimulationContext.hpp:826
SubcatchData subcatches
All subcatchment state and properties.
Definition SimulationContext.hpp:594
LanduseData landuses
Definition SimulationContext.hpp:761
double runoff_interp_f
Where this routing instant falls between the two runoff times.
Definition SimulationContext.hpp:545
SimulationOptions options
Parsed simulation options (from [OPTIONS] section).
Definition SimulationContext.hpp:452
std::vector< LidNodeOutlet > lid_node_outlets
Definition SimulationContext.hpp:868
PollutantData pollutants
Pollutant definitions and per-object quality state.
Definition SimulationContext.hpp:606
double current_date
Absolute current date/time (decimal days, OADate (days since 12/30/1899)).
Definition SimulationContext.hpp:498
All SWMM simulation options parsed from [OPTIONS] section.
Definition SimulationOptions.hpp:168
SoA storage for snowpack parameter sets.
Definition HydrologyData.hpp:59
Spatial frame containing CRS and georeferenced coordinates.
Definition SpatialFrame.hpp:123
Solver-neutral hooks for reading and writing solver-internal state (infiltration, groundwater) at hot...
Definition SimulationContext.hpp:303
std::function< bool(int subcatch_index, int model, const double *infil)> set_infil_state
Definition SimulationContext.hpp:333
std::function< bool()> has_fv_retained_dry_mass
Guard saves when a caller has no FV dry-inventory accessor.
Definition SimulationContext.hpp:305
std::function< std::vector< ChannelThermalRegion >()> get_channel_thermal_regions
Definition SimulationContext.hpp:310
std::function< std::string()> get_snow_state
Definition SimulationContext.hpp:317
std::function< bool(int subcatch_index, int &out_model, double *out_infil)> get_infil_state
Definition SimulationContext.hpp:329
std::function< std::vector< ChannelSpeciesRegion >()> get_channel_species_regions
Definition SimulationContext.hpp:314
std::function< std::string()> get_fv_dry_state
Definition SimulationContext.hpp:306
bool can_write() const noexcept
True iff the write-side accessors are wired.
Definition SimulationContext.hpp:348
std::function< bool(int subcatch_index, double theta, double lower_depth)> set_gw_state
Apply groundwater zone state to a subcatchment.
Definition SimulationContext.hpp:340
std::function< std::string(const std::string &, bool)> set_surface_state
Definition SimulationContext.hpp:326
std::function< std::string(const std::string &, bool)> set_snow_state
Definition SimulationContext.hpp:319
std::function< bool(int subcatch_index, double &out_theta, double &out_lower_depth)> get_gw_state
Read groundwater zone state (upper-zone moisture and lower-zone depth).
Definition SimulationContext.hpp:337
std::function< std::string(const std::vector< ChannelSpeciesIncrement > &)> apply_channel_species_increments
Definition SimulationContext.hpp:316
std::function< std::string()> get_surface_state
Definition SimulationContext.hpp:325
std::function< std::vector< double >()> get_fv_retained_pollutant_mass
Definition SimulationContext.hpp:308
bool can_read() const noexcept
True iff the read-side accessors are wired.
Definition SimulationContext.hpp:343
std::function< std::string(const std::string &, bool)> set_fv_dry_state
Definition SimulationContext.hpp:307
std::function< std::vector< double >()> get_fv_retained_species_mass
Definition SimulationContext.hpp:309
std::function< std::string(const std::vector< ChannelThermalIncrement > &)> apply_channel_thermal_increments
Definition SimulationContext.hpp:313
Definition InfraData.hpp:76
Structure-of-Arrays storage for all subcatchments.
Definition SubcatchData.hpp:57
SoA collection of all time series and curves in the model.
Definition TableData.hpp:741
Definition InfraData.hpp:42
Definition QualityData.hpp:197
Hydrograph parameter rows and independent group-to-gage assignments.
Definition InflowData.hpp:291
Definition QualityData.hpp:147
Parsed model.age state (waterage component, phase A1a).
Definition WaterAgeData.hpp:72
Definition WaterAgeData.hpp:118
Definition Climate.hpp:97
Definition SimulationContext.hpp:1998
Event time periods for event-based analysis/reporting.
Definition SimulationContext.hpp:822
Per-inlet-usage performance block for the .rpt street tables.
Definition SimulationContext.hpp:1926
Definition SimulationContext.hpp:1571
Definition SimulationContext.hpp:1186
Top-N element statistic entry (matching legacy TMaxStats).
Definition SimulationContext.hpp:1642
D-NS1 negative-source clamp bookkeeping (subplan §3.1, X6).
Definition SimulationContext.hpp:1488
Cumulative mass balance totals for runoff and routing.
Definition SimulationContext.hpp:1182
Definition SimulationContext.hpp:1529
Definition SimulationContext.hpp:1659
Non-owning pointers to the engine's 2D surface-routing model storage (mesh, solver options,...
Definition SimulationContext.hpp:1006
Per-virtual-junction momentum-residual accumulators.
Definition SimulationContext.hpp:1889
Central, reentrant simulation context.
Definition SimulationContext.hpp:390
SoA storage for per-edge boundary conditions.
Definition BoundaryData.hpp:73
Every [GW_*] authoring row of one model.
Definition GwTransportData.hpp:187
SoA storage for 2D mixed triangle/quad mesh geometry and topology.
Definition MeshData.hpp:65
Definition SolverOptions2D.hpp:257
Everything the parser fills, before resolution onto cells.
Definition SubsurfaceData.hpp:391
Per-cell resolved parameters and state (SoA).
Definition SubsurfaceData.hpp:219
Species mass in both aquifer zones, and where mass crossed a boundary.
Definition SubsurfaceTransportState.hpp:69