![]() |
OpenSWMM Engine
6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
|
Central, reentrant simulation context. More...
#include <SimulationContext.hpp>
Classes | |
| struct | ControlLogEntry |
| One entry per control rule action that changed a link setting. More... | |
| struct | Event |
| Event time periods for event-based analysis/reporting. More... | |
| struct | MassBalance |
| Cumulative mass balance totals for runoff and routing. More... | |
| struct | MassBalance2D |
| System mass-balance totals for the optional 2D surface domain. More... | |
| struct | MaxStats |
| Top-N element statistic entry (matching legacy TMaxStats). More... | |
| struct | RoutingStepStats |
| struct | TwoDModelIO |
| Non-owning pointers to the engine's 2D surface-routing model storage (mesh, solver options, boundary conditions, parse-time pending rows). More... | |
Public Member Functions | |
| void | finalize_max_stats () |
| Compute top-5 arrays for CFL-critical, flow turns, and non-convergence. | |
| void | reset () |
| Fully reset the context to a CREATED state. | |
| void | save_state () noexcept |
| Snapshot current state into old-step arrays before solving. | |
| void | reset_state () noexcept |
| Reset all state variables to initial conditions (cold start). | |
| void | allocate_objects () |
| Allocate all object arrays after input parsing is complete. | |
| void | shrink_all_to_fit () |
| Release excess vector capacity on all owned SoA data stores. | |
| int | n_nodes () const noexcept |
| Number of nodes. | |
| int | n_links () const noexcept |
| Number of links. | |
| int | n_subcatches () const noexcept |
| Number of subcatchments. | |
| int | n_gages () const noexcept |
| Number of rain gages. | |
| int | n_pollutants () const noexcept |
| Number of pollutants. | |
| int | n_landuses () const noexcept |
| int | n_tables () const noexcept |
| Number of tables (time series + curves). | |
Static Public Member Functions | |
| static void | updateMaxStats (MaxStats arr[], int obj_type, int idx, double value) |
| Insertion sort into a descending-by-absolute-value top-N array. | |
Public Attributes | |
| EngineState | state = EngineState::CREATED |
| Current lifecycle state of the engine. | |
| std::vector< std::string > | title_notes |
| Project title and notes (from [TITLE] section). | |
| SimulationOptions | options |
| Parsed simulation options (from [OPTIONS] section). | |
| climate::ClimateState | climate_state |
| Daily climate state — temperature, evaporation, wind, humidity. | |
| double | current_time = 0.0 |
| Current simulation time in SECONDS from start_date. | |
| double | current_date = 0.0 |
| Absolute current date/time (decimal days, OADate (days since 12/30/1899)). | |
| double | elapsed_ms = 0.0 |
| Elapsed routing time in MILLISECONDS from start_date. | |
| double | old_elapsed_ms = 0.0 |
| Elapsed routing time (ms) at the START of the current step. | |
| double | next_report_ms = 0.0 |
| Next report instant in MILLISECONDS from start_date. | |
| double | dt_controls_remaining = 0.0 |
| Time remaining until the next control rule event (seconds). | |
| NodeData | nodes |
| All node state and properties. | |
| NodeSubtypes | node_subtypes |
| Relational side-tables for node subtypes (storage/outfall/divider). | |
| LinkData | links |
| All link state and properties. | |
| LinkSubtypes | link_subtypes |
Relational per-subtype link side-tables (Phase 6) — the link analogue of node_subtypes. Authoritative store for conduit/pump/ orifice/weir/outlet config; shared fields (xsect_*, has_flap_gate, pump_curve_name) stay on links. | |
| SubcatchData | subcatches |
| All subcatchment state and properties. | |
| GageData | gages |
| All rain gage state and properties. | |
| PollutantData | pollutants |
| Pollutant definitions and per-object quality state. | |
| TableData | tables |
| All time series and rating curves. | |
| NameIndex | node_names |
| Node name → node index. | |
| NameIndex | link_names |
| Link name → link index. | |
| NameIndex | subcatch_names |
| Subcatchment name → subcatchment index. | |
| NameIndex | gage_names |
| Rain gage name → gage index. | |
| NameIndex | pollutant_names |
| Pollutant name → pollutant index. | |
| NameIndex | table_names |
| Time series / curve name → table index. | |
| NameIndex | landuse_names |
| LanduseData | landuses |
| BuildupData | buildup |
| WashoffData | washoff |
| TreatmentData | treatment |
| ExtInflowData | ext_inflows |
| DwfData | dwf_inflows |
| RDIIAssignData | rdii_assigns |
| UnitHydData | unit_hyds |
| Parsed [HYDROGRAPHS] data. | |
| RDIIDecayData | rdii_decay |
| Parsed [RDII_DECAY] data (exponential IA model) | |
| PatternData | patterns |
| TransectStore | transects |
| std::vector< transect::TransectData > | transect_tables |
| Built transect geometry tables (indexed same as transects). | |
| std::uint64_t | xsect_generation = 0 |
| bool | gpkg_units_internal = false |
| StreetStore | streets |
| InletStore | inlets |
| InletUsageStore | inlet_usages |
| ControlRuleStore | control_rules |
| std::vector< Event > | events |
| double | adjust_temp [12] = {0,0,0,0,0,0,0,0,0,0,0,0} |
| Monthly climate adjustment factors from [ADJUSTMENTS] section. | |
| double | adjust_evap [12] = {1,1,1,1,1,1,1,1,1,1,1,1} |
| double | adjust_rain [12] = {1,1,1,1,1,1,1,1,1,1,1,1} |
| double | adjust_hydcon [12] = {1,1,1,1,1,1,1,1,1,1,1,1} |
| std::vector< int > | subcatch_n_perv_pattern |
| Per-subcatchment pattern indices for N-PERV, DSTORE, INFIL adjustments. | |
| std::vector< int > | subcatch_d_store_pattern |
| std::vector< int > | subcatch_infil_pattern |
| std::vector< double > | base_n_perv |
| Base values for pattern-adjusted parameters (populated at init). | |
| std::vector< double > | base_ds_perv |
| bool | has_subcatch_adj_patterns = false |
| True if any pattern index >= 0. | |
| SnowpackStore | snowpacks |
| NameIndex | snowpack_names |
| AquiferStore | aquifers |
| NameIndex | aquifer_names |
| LidControlStore | lid_controls |
| NameIndex | lid_names |
| LidUsageStore | lid_usage |
| SpatialFrame | spatial |
| Coordinate reference system and georeferenced coordinates. | |
| UserFlags | user_flags |
| User-defined flags from [USER_FLAGS] section. | |
| ForcingData | forcing |
| Per-element runtime forcing state (lateral inflows, head boundaries, rainfall, evap, link settings, quality mass fluxes). | |
| std::vector< PluginSpec > | plugin_specs |
| Plugin library specs parsed from [PLUGINS]. | |
| FilesSpec | files |
| Secondary file references parsed from [FILES]. | |
| StateAccessors | state_accessors |
| Solver-neutral accessors for reading and writing solver-internal state at hot-start save/load time. | |
| struct openswmm::SimulationContext::TwoDModelIO | twod_io |
| int | error_code = 0 |
| Most recent error code (0 = no error). | |
| int | warning_code = 0 |
| Most recent warning code (0 = no warning). | |
| std::string | error_message |
| Human-readable message for the last error/warning. | |
| std::vector< std::string > | warnings |
| Accumulated warning messages written to report file. | |
| std::vector< std::string > | errors |
| Accumulated error messages written to report file. | |
| std::vector< std::uint8_t > | coupled_node |
| Per-node flag: 1 if the node is a 2D-coupled junction (a non-outfall coupling point), else 0. Empty when the 2D module is inactive. | |
| struct openswmm::SimulationContext::MassBalance | mass_balance |
| struct openswmm::SimulationContext::MassBalance2D | mass_balance_2d |
| MaxStats | max_courant_crit [MAX_STATS] = {} |
| Top-5 CFL time-step critical elements. | |
| MaxStats | max_flow_turns [MAX_STATS] = {} |
| Top-5 links with highest flow instability index. | |
| MaxStats | max_non_converged [MAX_STATS] = {} |
| Top-5 nodes with highest non-convergence frequency. | |
| MaxStats | max_mass_bal_errs [MAX_STATS] = {} |
| Top-5 nodes with highest continuity errors. | |
| struct openswmm::SimulationContext::RoutingStepStats | routing_stats |
| std::vector< ControlLogEntry > | control_log |
| Chronological log of all control actions taken during the simulation. | |
| std::string | inp_file_path |
| Path to the input .inp file (empty if not opened from a file). | |
Static Public Attributes | |
| static constexpr int | MAX_STATS = 5 |
Central, reentrant simulation context.
Owns all simulation data. Passed by (non-const) reference to every solver function. One context per concurrent simulation.
|
inline |
Allocate all object arrays after input parsing is complete.
Called by InputReader after all [JUNCTIONS], [CONDUITS], etc. sections have been parsed and the final object counts are known. Resizes SoA arrays and pollutant quality matrices.
|
inline |
Compute top-5 arrays for CFL-critical, flow turns, and non-convergence.
Called once at end of simulation before reporting (matching legacy stats_findMaxStats in stats.c).
|
inlinenoexcept |
Number of rain gages.
|
inlinenoexcept |
|
inlinenoexcept |
Number of links.
|
inlinenoexcept |
Number of nodes.
|
inlinenoexcept |
Number of pollutants.
|
inlinenoexcept |
Number of subcatchments.
|
inlinenoexcept |
Number of tables (time series + curves).
|
inline |
Fully reset the context to a CREATED state.
Clears all object data and name indices. Does NOT free the option structs (they are re-parsed from the input file). Call this before re-running or re-opening a simulation.
|
inlinenoexcept |
Reset all state variables to initial conditions (cold start).
Sets all current and old-step arrays to zero. Invert elevations and static properties are NOT changed.
|
inlinenoexcept |
Snapshot current state into old-step arrays before solving.
Must be called at the start of each timestep, before the hydraulic and quality solvers update the state.
|
inline |
Release excess vector capacity on all owned SoA data stores.
Called once after parsing and final sizing are complete. During incremental parsing, vectors grow via geometric capacity doubling. This method reclaims that excess by calling shrink_to_fit() on every data store.
|
inlinestatic |
Insertion sort into a descending-by-absolute-value top-N array.
Matches legacy stats_updateMaxStats() in stats.c.
| double openswmm::SimulationContext::adjust_evap[12] = {1,1,1,1,1,1,1,1,1,1,1,1} |
| double openswmm::SimulationContext::adjust_hydcon[12] = {1,1,1,1,1,1,1,1,1,1,1,1} |
| double openswmm::SimulationContext::adjust_rain[12] = {1,1,1,1,1,1,1,1,1,1,1,1} |
| double openswmm::SimulationContext::adjust_temp[12] = {0,0,0,0,0,0,0,0,0,0,0,0} |
Monthly climate adjustment factors from [ADJUSTMENTS] section.
Copied into ClimateState during initialize(). Stored here so that input parsing populates them without accessing SWMMEngine.
| NameIndex openswmm::SimulationContext::aquifer_names |
| AquiferStore openswmm::SimulationContext::aquifers |
| std::vector<double> openswmm::SimulationContext::base_ds_perv |
| std::vector<double> openswmm::SimulationContext::base_n_perv |
Base values for pattern-adjusted parameters (populated at init).
| BuildupData openswmm::SimulationContext::buildup |
| climate::ClimateState openswmm::SimulationContext::climate_state |
Daily climate state — temperature, evaporation, wind, humidity.
Scalar broadcast to all subcatchments; updated at the runoff step boundary by SWMMEngine. Lives on the context so that downstream solvers (RDII exponential IA, future models) can read it through ctx.climate_state without reaching into the engine.
| std::vector<ControlLogEntry> openswmm::SimulationContext::control_log |
Chronological log of all control actions taken during the simulation.
| ControlRuleStore openswmm::SimulationContext::control_rules |
| std::vector<std::uint8_t> openswmm::SimulationContext::coupled_node |
Per-node flag: 1 if the node is a 2D-coupled junction (a non-outfall coupling point), else 0. Empty when the 2D module is inactive.
Populated by SurfaceRouter2D::initialize from the coupling map. Lets the 1D dynamic-wave solver treat a coupled junction as pond-capable so its HGL can rise above the crown over the auto-assigned ponded_area (the 2D-cell footprint), regardless of the global ALLOW_PONDING option — which only governs ordinary (uncoupled) junctions. Outfall coupling uses a tailwater head BC instead, so outfalls are NOT flagged here.
| double openswmm::SimulationContext::current_date = 0.0 |
Absolute current date/time (decimal days, OADate (days since 12/30/1899)).
= options.start_date + current_time
| double openswmm::SimulationContext::current_time = 0.0 |
Current simulation time in SECONDS from start_date.
Updated by TimestepController::advance() with the routing step in seconds (TimestepController.cpp:88). The value 0.0 corresponds to options.start_date.
The companion field current_date is the OADate (decimal days since 12/30/1899) computed via datetime::addSeconds(start_date, current_time).
Callers that need elapsed time in decimal days (e.g. the control engine's SIM_TIME premise) must divide by constants::SEC_PER_DAY. Legacy ElapsedTime is in days; this field stores seconds.
| double openswmm::SimulationContext::dt_controls_remaining = 0.0 |
Time remaining until the next control rule event (seconds).
0.0 means no control step scheduled; updated by the control rule processor.
| DwfData openswmm::SimulationContext::dwf_inflows |
| double openswmm::SimulationContext::elapsed_ms = 0.0 |
Elapsed routing time in MILLISECONDS from start_date.
Legacy-parity clock: accumulated exactly as legacy NewRoutingTime = NewRoutingTime + 1000.0 * routingStep (swmm5.c / routing.c:309). Kept alongside current_time (seconds) because the two accumulations are NOT FP-identical; report scheduling and report datestamps must use this clock to match legacy bit-for-bit.
| int openswmm::SimulationContext::error_code = 0 |
| std::string openswmm::SimulationContext::error_message |
Human-readable message for the last error/warning.
| std::vector<std::string> openswmm::SimulationContext::errors |
Accumulated error messages written to report file.
Matches legacy behavior where errors are collected during parsing/validation and written to the .rpt file. Format: "ERROR NNN: description for ObjectID"
| std::vector<Event> openswmm::SimulationContext::events |
| ExtInflowData openswmm::SimulationContext::ext_inflows |
| FilesSpec openswmm::SimulationContext::files |
Secondary file references parsed from [FILES].
Mirrors legacy SWMM5's TFile struct array — rainfall, runoff, RDII, inflows, outflows, hotstart save/use. The simulation engine consults specific slots when the corresponding feature is requested (e.g. interfacing a routing run with a separately-saved runoff file).
| ForcingData openswmm::SimulationContext::forcing |
Per-element runtime forcing state (lateral inflows, head boundaries, rainfall, evap, link settings, quality mass fluxes).
Set via swmm_forcing_*() API. Applied by applyForcings() in the step loop. Auto-cleared by clear_reset_entries() at end of each step (for RESET-persistence entries).
| NameIndex openswmm::SimulationContext::gage_names |
Rain gage name → gage index.
| GageData openswmm::SimulationContext::gages |
| bool openswmm::SimulationContext::gpkg_units_internal = false |
True when the model was loaded from a GeoPackage, whose hydraulic fields are stored in CANONICAL internal units (feet/cfs/ft³) — NOT the display units a .inp uses. resolve_cross_references then SKIPS the display→ internal conversion (convert_inputs_to_internal) so the round-trip is bit-for-bit identical (no non-invertible ×0.3048). The GeoPackage reader converts only the cross-section raw geom1-4 (the lone display-unit fields it stores) itself. Left false for the .inp path.
| bool openswmm::SimulationContext::has_subcatch_adj_patterns = false |
True if any pattern index >= 0.
| InletUsageStore openswmm::SimulationContext::inlet_usages |
| InletStore openswmm::SimulationContext::inlets |
| std::string openswmm::SimulationContext::inp_file_path |
Path to the input .inp file (empty if not opened from a file).
| NameIndex openswmm::SimulationContext::landuse_names |
| LanduseData openswmm::SimulationContext::landuses |
| LidControlStore openswmm::SimulationContext::lid_controls |
| NameIndex openswmm::SimulationContext::lid_names |
| LidUsageStore openswmm::SimulationContext::lid_usage |
| NameIndex openswmm::SimulationContext::link_names |
Link name → link index.
| LinkSubtypes openswmm::SimulationContext::link_subtypes |
Relational per-subtype link side-tables (Phase 6) — the link analogue of node_subtypes. Authoritative store for conduit/pump/ orifice/weir/outlet config; shared fields (xsect_*, has_flap_gate, pump_curve_name) stay on links.
| LinkData openswmm::SimulationContext::links |
| struct openswmm::SimulationContext::MassBalance openswmm::SimulationContext::mass_balance |
| struct openswmm::SimulationContext::MassBalance2D openswmm::SimulationContext::mass_balance_2d |
Top-5 CFL time-step critical elements.
Top-5 links with highest flow instability index.
Top-5 nodes with highest continuity errors.
Top-5 nodes with highest non-convergence frequency.
|
staticconstexpr |
| double openswmm::SimulationContext::next_report_ms = 0.0 |
Next report instant in MILLISECONDS from start_date.
Legacy ReportTime: seeded to 1000*report_step at start and advanced by 1000*report_step per period (swmm5.c:721,1044). The grid is anchored at SIM start; periods whose datestamp falls before options.report_start are skipped (not written) but the grid still advances — exactly legacy output_saveResults() (output.c:481).
| NameIndex openswmm::SimulationContext::node_names |
Node name → node index.
| NodeSubtypes openswmm::SimulationContext::node_subtypes |
Relational side-tables for node subtypes (storage/outfall/divider).
Phase 1 (shadow) of the relational node refactor: built from nodes at hydraulics init and kept as an exact mirror of the wide subtype arrays. Not yet read by the solver. See docs/relational/RELATIONAL_NODE_REFACTOR_PLAN.md and src/engine/data/NodeSubtypes.hpp.
| NodeData openswmm::SimulationContext::nodes |
| double openswmm::SimulationContext::old_elapsed_ms = 0.0 |
Elapsed routing time (ms) at the START of the current step.
Legacy OldRoutingTime; with elapsed_ms brackets the report instant for interpolated output.
| SimulationOptions openswmm::SimulationContext::options |
Parsed simulation options (from [OPTIONS] section).
| PatternData openswmm::SimulationContext::patterns |
| std::vector<PluginSpec> openswmm::SimulationContext::plugin_specs |
Plugin library specs parsed from [PLUGINS].
Consumed by PluginFactory::load_plugins() during open(). New in 6.0.0 — no legacy equivalent.
| NameIndex openswmm::SimulationContext::pollutant_names |
Pollutant name → pollutant index.
| PollutantData openswmm::SimulationContext::pollutants |
| RDIIAssignData openswmm::SimulationContext::rdii_assigns |
| RDIIDecayData openswmm::SimulationContext::rdii_decay |
Parsed [RDII_DECAY] data (exponential IA model)
| struct openswmm::SimulationContext::RoutingStepStats openswmm::SimulationContext::routing_stats |
| NameIndex openswmm::SimulationContext::snowpack_names |
| SnowpackStore openswmm::SimulationContext::snowpacks |
| SpatialFrame openswmm::SimulationContext::spatial |
Coordinate reference system and georeferenced coordinates.
| EngineState openswmm::SimulationContext::state = EngineState::CREATED |
Current lifecycle state of the engine.
| StateAccessors openswmm::SimulationContext::state_accessors |
Solver-neutral accessors for reading and writing solver-internal state at hot-start save/load time.
Wired by SWMMEngine at open() time so state-IO plugins can access per-subcatchment infiltration and groundwater state without depending on solver types.
| StreetStore openswmm::SimulationContext::streets |
| std::vector<int> openswmm::SimulationContext::subcatch_d_store_pattern |
| std::vector<int> openswmm::SimulationContext::subcatch_infil_pattern |
| std::vector<int> openswmm::SimulationContext::subcatch_n_perv_pattern |
Per-subcatchment pattern indices for N-PERV, DSTORE, INFIL adjustments.
Index into ctx.table_names / pattern tables. -1 = no pattern.
| NameIndex openswmm::SimulationContext::subcatch_names |
Subcatchment name → subcatchment index.
| SubcatchData openswmm::SimulationContext::subcatches |
All subcatchment state and properties.
| NameIndex openswmm::SimulationContext::table_names |
Time series / curve name → table index.
| TableData openswmm::SimulationContext::tables |
| std::vector<std::string> openswmm::SimulationContext::title_notes |
| std::vector<transect::TransectData> openswmm::SimulationContext::transect_tables |
Built transect geometry tables (indexed same as transects).
| TransectStore openswmm::SimulationContext::transects |
| TreatmentData openswmm::SimulationContext::treatment |
| struct openswmm::SimulationContext::TwoDModelIO openswmm::SimulationContext::twod_io |
| UnitHydData openswmm::SimulationContext::unit_hyds |
Parsed [HYDROGRAPHS] data.
| UserFlags openswmm::SimulationContext::user_flags |
User-defined flags from [USER_FLAGS] section.
New in 6.0.0. No legacy equivalent.
| int openswmm::SimulationContext::warning_code = 0 |
Most recent warning code (0 = no warning).
| std::vector<std::string> openswmm::SimulationContext::warnings |
Accumulated warning messages written to report file.
Matches legacy behavior where warnings are collected during validation and written after the title section in the .rpt file. Format: "WARNING NN: description for ObjectID"
| WashoffData openswmm::SimulationContext::washoff |
| std::uint64_t openswmm::SimulationContext::xsect_generation = 0 |
Bumped whenever a link's cross-section/flow properties are recomputed mid-run (C-API setters via recompute_conduit_flow_properties), so consumers holding per-link XSectParams caches know to rebuild (e.g. SWMMEngine's reporting-path cache).