OpenSWMM Engine  6.0.0-alpha.3
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.3)
Loading...
Searching...
No Matches
openswmm::HotStartManager Class Reference

Static utility class for hot start file operations. More...

#include <HotStartManager.hpp>

Collaboration diagram for openswmm::HotStartManager:

Public Member Functions

 HotStartManager ()=delete
 

Static Public Member Functions

static HotStartFilesave (const SimulationContext &ctx, const std::string &path)
 Capture current engine state and write to a hot start file (V1 format).
 
static HotStartFilesave (const SimulationContext &ctx, const runoff::RunoffSolver *runoff, const groundwater::GWSolver *gw, const std::string &path)
 Capture current engine state including infiltration and GW (V2 format).
 
static HotStartFileopen (const std::string &path)
 Read and validate a hot start file.
 
static int apply (HotStartFile &hs, SimulationContext &ctx, std::function< void(const std::string &)> warn_cb={})
 Apply hot start records to a simulation context.
 
static int apply (HotStartFile &hs, SimulationContext &ctx, runoff::RunoffSolver *runoff, groundwater::GWSolver *gw, std::function< void(const std::string &)> warn_cb={})
 Apply hot start records including infiltration and GW state.
 
static int apply_legacy_routing (const std::string &path, SimulationContext &ctx, std::function< void(const std::string &)> warn_cb={})
 Read a legacy EPA SWMM5 .hsf (USE HOTSTART) file and apply its routing state to the context, BY OBJECT INDEX (the legacy format stores node/link state in object order, no IDs).
 
static int save_legacy_routing (const std::string &path, const SimulationContext &ctx)
 Write the current routing state as a legacy EPA SWMM5 .hsf (SAVE HOTSTART), byte-format-compatible with legacy readRouting() and apply_legacy_routing() above.
 
static bool flush (HotStartFile &hs)
 If the file is dirty, rewrite it to disk.
 
static const std::string & last_io_error () noexcept
 Description of the most recent I/O error (empty = none).
 

Detailed Description

Static utility class for hot start file operations.

All operations on the binary file are handled here. The HotStartFile struct is the data carrier; HotStartManager provides the I/O logic.

Constructor & Destructor Documentation

◆ HotStartManager()

openswmm::HotStartManager::HotStartManager ( )
delete

Member Function Documentation

◆ apply() [1/2]

int openswmm::HotStartManager::apply ( HotStartFile & hs,
SimulationContext & ctx,
runoff::RunoffSolver * runoff,
groundwater::GWSolver * gw,
std::function< void(const std::string &)> warn_cb = {} )
static

Apply hot start records including infiltration and GW state.

Gap #54: extended apply that also restores infiltration model state and GW zone state when the file is V2 format.

Parameters
hsHot start file (from save() or open()).
ctxTarget simulation context (must be INITIALIZED).
runoffRunoffSolver to restore infiltration state into (may be nullptr).
gwGWSolver to restore GW zone state into (may be nullptr).
warn_cbOptional callback for per-missing-object warnings.
Returns
Number of missing-object warnings generated.
Here is the call graph for this function:

◆ apply() [2/2]

int openswmm::HotStartManager::apply ( HotStartFile & hs,
SimulationContext & ctx,
std::function< void(const std::string &)> warn_cb = {} )
static

Apply hot start records to a simulation context.

For each record in the hot start file, the matching object (by string ID) in ctx is updated. Objects in the hot start that are absent from ctx generate warnings — they do not fail.

Parameters
hsHot start file (from save() or open()).
ctxTarget simulation context (must be INITIALIZED).
warn_cbOptional callback for per-missing-object warnings.
Returns
Number of missing-object warnings generated (0 = perfect match).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ apply_legacy_routing()

int openswmm::HotStartManager::apply_legacy_routing ( const std::string & path,
SimulationContext & ctx,
std::function< void(const std::string &)> warn_cb = {} )
static

Read a legacy EPA SWMM5 .hsf (USE HOTSTART) file and apply its routing state to the context, BY OBJECT INDEX (the legacy format stores node/link state in object order, no IDs).

Mirrors legacy hotstart.c readRouting(): sets each node's depth + lateral inflow and each link's flow + depth + setting, all stored as float in internal units (ft, cfs). Supports file stamps SWMM5-HOTSTART1..4. Currently routing-only: returns a non-zero error if the file contains subcatchments (the runoff section is not yet parsed). Derived state (head, volumes, old-step values) is recomputed by the caller from the applied depths/flows.

Parameters
pathAbsolute path to the legacy .hsf file.
ctxTarget context (node/link counts must match the file).
warn_cbOptional warning callback.
Returns
0 on success; non-zero error code otherwise (description in last_io_error()).
Here is the call graph for this function:

◆ flush()

bool openswmm::HotStartManager::flush ( HotStartFile & hs)
static

If the file is dirty, rewrite it to disk.

Returns
true on success, false on I/O error.
Here is the caller graph for this function:

◆ last_io_error()

const std::string & openswmm::HotStartManager::last_io_error ( )
staticnoexcept

Description of the most recent I/O error (empty = none).

◆ open()

HotStartFile * openswmm::HotStartManager::open ( const std::string & path)
static

Read and validate a hot start file.

Validates magic, version, and CRC32. Loads all records into memory.

Parameters
pathFile path.
Returns
Heap-allocated HotStartFile* on success, nullptr on error.
Here is the caller graph for this function:

◆ save() [1/2]

HotStartFile * openswmm::HotStartManager::save ( const SimulationContext & ctx,
const runoff::RunoffSolver * runoff,
const groundwater::GWSolver * gw,
const std::string & path )
static

Capture current engine state including infiltration and GW (V2 format).

Gap #54: extends V1 save with per-subcatchment infiltration model state (6-element flat array) and GW zone state (theta, lower_depth). Writes version=2 header.

Parameters
ctxSimulation context (must be RUNNING or ENDED).
runoffRunoffSolver providing infiltration state (may be nullptr).
gwGWSolver providing GW zone state (may be nullptr).
pathOutput file path.
Here is the call graph for this function:

◆ save() [2/2]

HotStartFile * openswmm::HotStartManager::save ( const SimulationContext & ctx,
const std::string & path )
static

Capture current engine state and write to a hot start file (V1 format).

Parameters
ctxSimulation context (must be RUNNING or ENDED).
pathOutput file path.
Returns
Heap-allocated HotStartFile* on success (caller owns), or nullptr on I/O error (error description in last_io_error).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_legacy_routing()

int openswmm::HotStartManager::save_legacy_routing ( const std::string & path,
const SimulationContext & ctx )
static

Write the current routing state as a legacy EPA SWMM5 .hsf (SAVE HOTSTART), byte-format-compatible with legacy readRouting() and apply_legacy_routing() above.

Mirrors legacy hotstart.c saveHotstart()+saveRouting() for the "SWMM5-HOTSTART4" version: 15-char stamp + object counts (nSub, nLand, nNodes, nLinks, nPollut, flowUnits as int32), then per node depth, latFlow[, storage hrt], qual[] and per link flow, depth, setting, qual[] — all float, internal units (ft, cfs). Storage residence time (hrt) is written as 0 (the reader discards it; it does not affect hydraulic routing).

Parameters
pathAbsolute path for the .hsf file.
ctxSource context (final routing state).
Returns
0 on success; non-zero on file-open/write error (description in last_io_error()).
Here is the call graph for this function:

The documentation for this class was generated from the following files: