OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches

Central, reentrant simulation context. More...

#include <SimulationContext.hpp>

Collaboration diagram for openswmm::SimulationContext:

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  MaxStats
 Top-N element statistic entry (matching legacy TMaxStats). More...
 
struct  RoutingStepStats
 

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 dt_output_remaining = 0.0
 Time remaining until the next output boundary (seconds).
 
double dt_controls_remaining = 0.0
 Time remaining until the next control rule event (seconds).
 
NodeData nodes
 All node state and properties.
 
LinkData links
 All link state and properties.
 
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::TransectDatatransect_tables
 Built transect geometry tables (indexed same as transects).
 
StreetStore streets
 
InletStore inlets
 
InletUsageStore inlet_usages
 
ControlRuleStore control_rules
 
std::vector< Eventevents
 
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< PluginSpecplugin_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.
 
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.
 
struct openswmm::SimulationContext::MassBalance mass_balance
 
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< ControlLogEntrycontrol_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
 

Detailed Description

Central, reentrant simulation context.

Owns all simulation data. Passed by (non-const) reference to every solver function. One context per concurrent simulation.

Member Function Documentation

◆ allocate_objects()

void openswmm::SimulationContext::allocate_objects ( )
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.

Note
Name indices must already be populated (resize() uses node_names.size(), etc. to determine array length).
Here is the call graph for this function:

◆ finalize_max_stats()

void openswmm::SimulationContext::finalize_max_stats ( )
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).

Here is the call graph for this function:

◆ n_gages()

int openswmm::SimulationContext::n_gages ( ) const
inlinenoexcept

Number of rain gages.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ n_landuses()

int openswmm::SimulationContext::n_landuses ( ) const
inlinenoexcept
Here is the call graph for this function:
Here is the caller graph for this function:

◆ n_links()

int openswmm::SimulationContext::n_links ( ) const
inlinenoexcept

Number of links.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ n_nodes()

int openswmm::SimulationContext::n_nodes ( ) const
inlinenoexcept

Number of nodes.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ n_pollutants()

int openswmm::SimulationContext::n_pollutants ( ) const
inlinenoexcept

Number of pollutants.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ n_subcatches()

int openswmm::SimulationContext::n_subcatches ( ) const
inlinenoexcept

Number of subcatchments.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ n_tables()

int openswmm::SimulationContext::n_tables ( ) const
inlinenoexcept

Number of tables (time series + curves).

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset()

void openswmm::SimulationContext::reset ( )
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.

Here is the call graph for this function:

◆ reset_state()

void openswmm::SimulationContext::reset_state ( )
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.

Here is the call graph for this function:

◆ save_state()

void openswmm::SimulationContext::save_state ( )
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.

Here is the call graph for this function:

◆ shrink_all_to_fit()

void openswmm::SimulationContext::shrink_all_to_fit ( )
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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateMaxStats()

static void openswmm::SimulationContext::updateMaxStats ( MaxStats  arr[],
int  obj_type,
int  idx,
double  value 
)
inlinestatic

Insertion sort into a descending-by-absolute-value top-N array.

Matches legacy stats_updateMaxStats() in stats.c.

Here is the caller graph for this function:

Member Data Documentation

◆ adjust_evap

double openswmm::SimulationContext::adjust_evap[12] = {1,1,1,1,1,1,1,1,1,1,1,1}

◆ adjust_hydcon

double openswmm::SimulationContext::adjust_hydcon[12] = {1,1,1,1,1,1,1,1,1,1,1,1}

◆ adjust_rain

double openswmm::SimulationContext::adjust_rain[12] = {1,1,1,1,1,1,1,1,1,1,1,1}

◆ adjust_temp

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.

See also
Legacy: Adjust struct (temp[], evap[], rain[], hydcon[])

◆ aquifer_names

NameIndex openswmm::SimulationContext::aquifer_names

◆ aquifers

AquiferStore openswmm::SimulationContext::aquifers

◆ base_ds_perv

std::vector<double> openswmm::SimulationContext::base_ds_perv

◆ base_n_perv

std::vector<double> openswmm::SimulationContext::base_n_perv

Base values for pattern-adjusted parameters (populated at init).

◆ buildup

BuildupData openswmm::SimulationContext::buildup

◆ climate_state

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.

See also
Legacy: Temp, Evap, Wind, Humidity in globals.h

◆ control_log

std::vector<ControlLogEntry> openswmm::SimulationContext::control_log

Chronological log of all control actions taken during the simulation.

◆ control_rules

ControlRuleStore openswmm::SimulationContext::control_rules

◆ current_date

double openswmm::SimulationContext::current_date = 0.0

Absolute current date/time (decimal days, OADate (days since 12/30/1899)).

= options.start_date + current_time

See also
Legacy: StartDateTime + ElapsedTime in globals.h

◆ 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.

See also
Legacy: ElapsedTime in globals.h (legacy is in days)

◆ dt_controls_remaining

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.

◆ dt_output_remaining

double openswmm::SimulationContext::dt_output_remaining = 0.0

Time remaining until the next output boundary (seconds).

Managed by TimestepController. Decremented each step; reset to options.report_step by reset_output_timer().

See also
TimestepController::advance(), TimestepController::output_due()

◆ dwf_inflows

DwfData openswmm::SimulationContext::dwf_inflows

◆ error_code

int openswmm::SimulationContext::error_code = 0

Most recent error code (0 = no error).

See also
Legacy: ErrorCode in globals.h

◆ error_message

std::string openswmm::SimulationContext::error_message

Human-readable message for the last error/warning.

◆ errors

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"

See also
Legacy: report_writeErrorMsg() in report.c

◆ events

std::vector<Event> openswmm::SimulationContext::events

◆ ext_inflows

ExtInflowData openswmm::SimulationContext::ext_inflows

◆ files

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).

◆ forcing

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).

See also
ForcingData.hpp, openswmm_forcing.h

◆ gage_names

NameIndex openswmm::SimulationContext::gage_names

Rain gage name → gage index.

See also
Legacy: project_findObject(GAGE, name) in project.c

◆ gages

GageData openswmm::SimulationContext::gages

All rain gage state and properties.

See also
Legacy: Gage[] in globals.h + TGage in objects.h

◆ has_subcatch_adj_patterns

bool openswmm::SimulationContext::has_subcatch_adj_patterns = false

True if any pattern index >= 0.

◆ inlet_usages

InletUsageStore openswmm::SimulationContext::inlet_usages

◆ inlets

InletStore openswmm::SimulationContext::inlets

◆ inp_file_path

std::string openswmm::SimulationContext::inp_file_path

Path to the input .inp file (empty if not opened from a file).

See also
Legacy: InpFile in globals.h

◆ landuse_names

NameIndex openswmm::SimulationContext::landuse_names

◆ landuses

LanduseData openswmm::SimulationContext::landuses

◆ lid_controls

LidControlStore openswmm::SimulationContext::lid_controls

◆ lid_names

NameIndex openswmm::SimulationContext::lid_names

◆ lid_usage

LidUsageStore openswmm::SimulationContext::lid_usage

◆ link_names

NameIndex openswmm::SimulationContext::link_names

Link name → link index.

See also
Legacy: project_findObject(LINK, name) in project.c

◆ links

LinkData openswmm::SimulationContext::links

All link state and properties.

See also
Legacy: Link[], LinkStats[] in globals.h + TLink in objects.h

◆ mass_balance

struct openswmm::SimulationContext::MassBalance openswmm::SimulationContext::mass_balance

◆ max_courant_crit

MaxStats openswmm::SimulationContext::max_courant_crit[MAX_STATS] = {}

Top-5 CFL time-step critical elements.

◆ max_flow_turns

MaxStats openswmm::SimulationContext::max_flow_turns[MAX_STATS] = {}

Top-5 links with highest flow instability index.

◆ max_mass_bal_errs

MaxStats openswmm::SimulationContext::max_mass_bal_errs[MAX_STATS] = {}

Top-5 nodes with highest continuity errors.

◆ max_non_converged

MaxStats openswmm::SimulationContext::max_non_converged[MAX_STATS] = {}

Top-5 nodes with highest non-convergence frequency.

◆ MAX_STATS

constexpr int openswmm::SimulationContext::MAX_STATS = 5
staticconstexpr

◆ node_names

NameIndex openswmm::SimulationContext::node_names

Node name → node index.

See also
Legacy: project_findObject(NODE, name) in project.c

◆ nodes

NodeData openswmm::SimulationContext::nodes

All node state and properties.

See also
Legacy: Node[], NodeStats[] in globals.h + TNode in objects.h

◆ options

SimulationOptions openswmm::SimulationContext::options

Parsed simulation options (from [OPTIONS] section).

See also
Legacy: FlowUnits, RouteModel, RouteStep, … in globals.h

◆ patterns

PatternData openswmm::SimulationContext::patterns

◆ plugin_specs

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.

◆ pollutant_names

NameIndex openswmm::SimulationContext::pollutant_names

Pollutant name → pollutant index.

See also
Legacy: project_findObject(POLLUT, name) in project.c

◆ pollutants

PollutantData openswmm::SimulationContext::pollutants

Pollutant definitions and per-object quality state.

See also
Legacy: Pollut[], node.newQual[], link.newQual[] in globals.h

◆ rdii_assigns

RDIIAssignData openswmm::SimulationContext::rdii_assigns

◆ rdii_decay

RDIIDecayData openswmm::SimulationContext::rdii_decay

Parsed [RDII_DECAY] data (exponential IA model)

◆ routing_stats

struct openswmm::SimulationContext::RoutingStepStats openswmm::SimulationContext::routing_stats

◆ snowpack_names

NameIndex openswmm::SimulationContext::snowpack_names

◆ snowpacks

SnowpackStore openswmm::SimulationContext::snowpacks

◆ spatial

SpatialFrame openswmm::SimulationContext::spatial

Coordinate reference system and georeferenced coordinates.

See also
Legacy: Coord[] in globals.h

◆ state

EngineState openswmm::SimulationContext::state = EngineState::CREATED

Current lifecycle state of the engine.

◆ state_accessors

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.

◆ streets

StreetStore openswmm::SimulationContext::streets

◆ subcatch_d_store_pattern

std::vector<int> openswmm::SimulationContext::subcatch_d_store_pattern

◆ subcatch_infil_pattern

std::vector<int> openswmm::SimulationContext::subcatch_infil_pattern

◆ subcatch_n_perv_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.

See also
Legacy: Subcatch[i].nPervPattern, dStorePattern, infilPattern

◆ subcatch_names

NameIndex openswmm::SimulationContext::subcatch_names

Subcatchment name → subcatchment index.

See also
Legacy: project_findObject(SUBCATCH, name) in project.c

◆ subcatches

SubcatchData openswmm::SimulationContext::subcatches

All subcatchment state and properties.

See also
Legacy: Subcatch[], SubcatchStats[] in globals.h + TSubcatch

◆ table_names

NameIndex openswmm::SimulationContext::table_names

Time series / curve name → table index.

See also
Legacy: project_findObject(TIMESERIES, name) in project.c

◆ tables

TableData openswmm::SimulationContext::tables

All time series and rating curves.

See also
Legacy: Tseries[], Curve[] in globals.h + TTable in objects.h

◆ title_notes

std::vector<std::string> openswmm::SimulationContext::title_notes

Project title and notes (from [TITLE] section).

Each entry is one line of free-form text from the [TITLE] section of the .inp file. Lines beginning with ";;" (comments) are stripped by the input reader before reaching the handler.

See also
Legacy: Title[MAXTITLE] in globals.h (limited to 3 lines)

◆ transect_tables

std::vector<transect::TransectData> openswmm::SimulationContext::transect_tables

Built transect geometry tables (indexed same as transects).

◆ transects

TransectStore openswmm::SimulationContext::transects

◆ treatment

TreatmentData openswmm::SimulationContext::treatment

◆ unit_hyds

UnitHydData openswmm::SimulationContext::unit_hyds

Parsed [HYDROGRAPHS] data.

◆ user_flags

UserFlags openswmm::SimulationContext::user_flags

User-defined flags from [USER_FLAGS] section.

New in 6.0.0. No legacy equivalent.

See also
UserFlags.hpp

◆ warning_code

int openswmm::SimulationContext::warning_code = 0

Most recent warning code (0 = no warning).

See also
Legacy: WarningCode in globals.h

◆ warnings

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"

See also
Legacy: report_writeWarningMsg() in report.c

◆ washoff

WashoffData openswmm::SimulationContext::washoff

The documentation for this struct was generated from the following file: