SWMMVis  6.0.0-alpha.4
Qt6/C++ GIS-based graphical user interface for the SWMMVis engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
SimulationRunner Class Reference

Runs a single SWMM simulation on a worker thread and emits live progress, warnings, and completion signals back to the GUI thread. More...

#include <simulationrunner.h>

Inheritance diagram for SimulationRunner:
Collaboration diagram for SimulationRunner:

Signals

void started (int jobId)
 
void simulationDatesKnown (int jobId, QDateTime start, QDateTime end)
 Emitted once the engine is initialised and its OPTIONS section has been parsed. Carries the engine-side simulation window as calendar QDateTime values. The GUI status model uses these to render readable start / end / current columns.
 
void progressChanged (int jobId, double fraction, QDateTime currentSimDate, double runoffErrFrac, double routingErrFrac, double avgTimestepSec, double twoDErrFrac)
 Per-tick progress signal emitted from the step loop.
 
void warningReceived (int jobId, int code, QString message)
 
void finished (int jobId, bool success, int errorCode, QString errorMessage, double runoffErrFrac, double routingErrFrac, double twoDErrFrac)
 
void twoDSolverStats (int jobId, QString backend, int momentum, int ltsTiers, qint64 steps, QVector< qint64 > tierCells)
 2D solver telemetry (swmm_2d_get_run_stats), emitted once after start and with every progress tick of a 2D run.
 
void twoDInitialized (int jobId, QString h5Path, QVector< double > vx, QVector< double > vy, QVector< double > vz, QVector< int > cellFlat)
 
void twoDDepthsAvailable (int jobId, QVector< float > depths, QDateTime simTime, double elapsedSec)
 
void twoDEdgeGeometryAvailable (int jobId, QVector< float > length, QVector< float > nx, QVector< float > ny)
 
void twoDFluxAvailable (int jobId, QVector< float > flux, QDateTime simTime, double elapsedSec)
 
void twoDRainfallAvailable (int jobId, QVector< float > rainfall, QVector< float > rainCum, QDateTime simTime, double elapsedSec)
 
void twoDVertexDepthsAvailable (int jobId, QVector< double > vdepths, QDateTime simTime, double elapsedSec)
 
void twoDHeadsAvailable (int jobId, QVector< float > heads, QDateTime simTime, double elapsedSec)
 
void twoDEnvelopesAvailable (int jobId, QVector< float > maxDepth, QVector< float > maxVel)
 

Public Member Functions

 SimulationRunner (int jobId, const QString &instanceName, const QString &inpPath, const QString &rptPath, const QString &outPath, const QString &engineVersion="6.0.0", QObject *parent=nullptr)
 
void start ()
 
void cancel ()
 Request early termination. Step-loop exits at the next iteration; swmm_engine_end + swmm_engine_report + swmm_engine_close STILL run so the partial .out and .rpt files are flushed to disk — Cancel saves whatever the engine has produced up to the moment of cancellation.
 
void setPaused (bool paused)
 
bool isPaused () const
 
int jobId () const
 
QString outPath () const
 
QString inpPath () const
 

Static Public Member Functions

static QString parseTwoDOutputFile (const QString &inpPath)
 Scan a .inp for [2D_OPTIONS] OUTPUT_FILE and return the resolved absolute path of the 2D HDF5 output file (or an empty string when the key is absent).
 
static QString parseTwoDOption (const QString &inpPath, const QString &key)
 Scan a .inp for a [2D_OPTIONS] key and return its value as a QString verbatim (empty when absent).
 

Detailed Description

Runs a single SWMM simulation on a worker thread and emits live progress, warnings, and completion signals back to the GUI thread.

The runner uses the full lifecycle (create → open → initialize → start → step-loop → end → report → close → destroy) so that both SWMM_ProgressCallback and SWMM_WarningCallback can be registered. Static C callbacks post back via QMetaObject::invokeMethod with Qt::QueuedConnection.

Ownership: created and destroyed on the GUI thread by SWMMVis. The runner self-deletes after emitting finished.

Constructor & Destructor Documentation

◆ SimulationRunner()

SimulationRunner::SimulationRunner ( int  jobId,
const QString &  instanceName,
const QString &  inpPath,
const QString &  rptPath,
const QString &  outPath,
const QString &  engineVersion = "6.0.0",
QObject *  parent = nullptr 
)
explicit

Member Function Documentation

◆ cancel()

void SimulationRunner::cancel ( )

Request early termination. Step-loop exits at the next iteration; swmm_engine_end + swmm_engine_report + swmm_engine_close STILL run so the partial .out and .rpt files are flushed to disk — Cancel saves whatever the engine has produced up to the moment of cancellation.

◆ finished

void SimulationRunner::finished ( int  jobId,
bool  success,
int  errorCode,
QString  errorMessage,
double  runoffErrFrac,
double  routingErrFrac,
double  twoDErrFrac 
)
signal
Parameters
runoffErrFracrunoff continuity error fraction (0.001 = 0.1 %)
routingErrFracrouting continuity error fraction
twoDErrFrac2D surface continuity error fraction; NaN when the run has no active 2D model
Here is the caller graph for this function:

◆ inpPath()

QString SimulationRunner::inpPath ( ) const
inline
Here is the caller graph for this function:

◆ isPaused()

bool SimulationRunner::isPaused ( ) const
inline

◆ jobId()

int SimulationRunner::jobId ( ) const
inline
Here is the caller graph for this function:

◆ outPath()

QString SimulationRunner::outPath ( ) const
inline

◆ parseTwoDOption()

QString SimulationRunner::parseTwoDOption ( const QString &  inpPath,
const QString &  key 
)
static

Scan a .inp for a [2D_OPTIONS] key and return its value as a QString verbatim (empty when absent).

Used by the GUI to honour engine-side settings — e.g. matching the render dry-cell threshold to the engine's DRY_DEPTH so shallow inundation runs aren't clipped.

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

◆ parseTwoDOutputFile()

QString SimulationRunner::parseTwoDOutputFile ( const QString &  inpPath)
static

Scan a .inp for [2D_OPTIONS] OUTPUT_FILE and return the resolved absolute path of the 2D HDF5 output file (or an empty string when the key is absent).

The engine's parser fills SolverOptions2D::output_file from the same key, but openswmm_2d.h has no accessor, so this helper exists as a parallel scan callers can use to predict where the engine will write — useful both at open time (to look for an existing file from a previous run) and at finished time (to swap in an HDF5Mesh2DSource for scrubbing).

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

◆ progressChanged

void SimulationRunner::progressChanged ( int  jobId,
double  fraction,
QDateTime  currentSimDate,
double  runoffErrFrac,
double  routingErrFrac,
double  avgTimestepSec,
double  twoDErrFrac 
)
signal

Per-tick progress signal emitted from the step loop.

Parameters
fraction0.0–1.0 sim-time progress
currentSimDateengine "current time" converted from the SWMM OADate to a calendar QDateTime — lets the status model assign it verbatim without re-deriving from start + offset (which can drift across DST boundaries).
runoffErrFraccumulative runoff continuity error so far
routingErrFraccumulative routing continuity error so far
twoDErrFraccumulative 2D surface continuity error so far; NaN when the run has no active 2D model
Here is the caller graph for this function:

◆ setPaused()

void SimulationRunner::setPaused ( bool  paused)

Request pause — the step-loop parks in a short sleep until setPaused(false) is called. Safe to call from the GUI thread.

◆ simulationDatesKnown

void SimulationRunner::simulationDatesKnown ( int  jobId,
QDateTime  start,
QDateTime  end 
)
signal

Emitted once the engine is initialised and its OPTIONS section has been parsed. Carries the engine-side simulation window as calendar QDateTime values. The GUI status model uses these to render readable start / end / current columns.

Here is the caller graph for this function:

◆ start()

void SimulationRunner::start ( )

Launch the simulation on a worker thread via QtConcurrent::run.

Here is the call graph for this function:

◆ started

void SimulationRunner::started ( int  jobId)
signal
Here is the caller graph for this function:

◆ twoDDepthsAvailable

void SimulationRunner::twoDDepthsAvailable ( int  jobId,
QVector< float >  depths,
QDateTime  simTime,
double  elapsedSec 
)
signal
Here is the caller graph for this function:

◆ twoDEdgeGeometryAvailable

void SimulationRunner::twoDEdgeGeometryAvailable ( int  jobId,
QVector< float >  length,
QVector< float >  nx,
QVector< float >  ny 
)
signal
Here is the caller graph for this function:

◆ twoDEnvelopesAvailable

void SimulationRunner::twoDEnvelopesAvailable ( int  jobId,
QVector< float >  maxDepth,
QVector< float >  maxVel 
)
signal
Here is the caller graph for this function:

◆ twoDFluxAvailable

void SimulationRunner::twoDFluxAvailable ( int  jobId,
QVector< float >  flux,
QDateTime  simTime,
double  elapsedSec 
)
signal
Here is the caller graph for this function:

◆ twoDHeadsAvailable

void SimulationRunner::twoDHeadsAvailable ( int  jobId,
QVector< float >  heads,
QDateTime  simTime,
double  elapsedSec 
)
signal
Here is the caller graph for this function:

◆ twoDInitialized

void SimulationRunner::twoDInitialized ( int  jobId,
QString  h5Path,
QVector< double vx,
QVector< double vy,
QVector< double vz,
QVector< int >  cellFlat 
)
signal
Here is the caller graph for this function:

◆ twoDRainfallAvailable

void SimulationRunner::twoDRainfallAvailable ( int  jobId,
QVector< float >  rainfall,
QVector< float >  rainCum,
QDateTime  simTime,
double  elapsedSec 
)
signal
Here is the caller graph for this function:

◆ twoDSolverStats

void SimulationRunner::twoDSolverStats ( int  jobId,
QString  backend,
int  momentum,
int  ltsTiers,
qint64  steps,
QVector< qint64 >  tierCells 
)
signal

2D solver telemetry (swmm_2d_get_run_stats), emitted once after start and with every progress tick of a 2D run.

Parameters
backendsolver label chosen at initialize, e.g. "cpu (explicit marcher)" or "omp (Kokkos OpenMP …)"
momentum0 LOCAL_INERTIAL, 1 FULL_SWE, 2 DIFFUSIVE_WAVE
ltsTiersconfigured [2D_OPTIONS] LTS_TIERS
stepscumulative marcher substeps so far
tierCellsrebuild-sampled cells per LTS tier (empty until the first rebuild)

◆ twoDVertexDepthsAvailable

void SimulationRunner::twoDVertexDepthsAvailable ( int  jobId,
QVector< double vdepths,
QDateTime  simTime,
double  elapsedSec 
)
signal
Here is the caller graph for this function:

◆ warningReceived

void SimulationRunner::warningReceived ( int  jobId,
int  code,
QString  message 
)
signal
Here is the caller graph for this function:

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