Simulation#

class Simulation(inputfile, reportfile=None, outputfile=None, sim_preconfig=None)[source]#

Base class for a SWMM Simulation.

The model object provides several options to run a simulation.

Initialize the Simulation class.

Parameters:
  • inpfile (str) – Name of SWMM input file (default ‘’)

  • rptfile (str) – Report file to generate (default None)

  • binfile (str) – Optional binary output file (default None)

  • sim_preconfig (SimulationPreConfig) – Optional Pre Config (default None)

Examples:

Intialize using with statement. This automatically cleans up after a simulation

from pyswmm import Simulation

with Simulation('tests/data/model_weir_setting.inp') as sim:
    for step in sim:
        pass

Initialize the simulation and execute. This style does not allow the user to interact with the simulation. However, this approach tends to be the fastest.

from pyswmm import Simulation

sim = Simulation('tests/data/model_weir_setting.inp')
sim.execute()

Methods

add_after_close

Add callback function/method/object to execute after the simulation is closed.

add_after_end

Add callback function/method/object to execute after the simulation ends.

add_after_start

Add callback function/method/object to execute after a simlation start.

add_after_step

Add callback function/method/object to execute after a simlation step.

add_before_end

Add callback function/method/object to execute after the simulation ends.

add_before_start

Add callback function/method/object to execute before the simlation starts.

add_before_step

Add callback function/method/object to execute before a simlation step.

close

Intialize a simulation and iterate through a simulation.

execute

Open an input file, run SWMM, then close the file.

initial_conditions

Starting in PySWMM-v2 this method/function is set to be deprecated.

report

Writes to report file after simulation (no longer suggested for user).

save_hotstart

Save the current state of the model to a hotstart file.

start

Start Simulation (no longer suggested to user).

step_advance

Advances the model by X number of seconds instead of intervening at every routing step.

terminate_simulation

Inserts a request to stop a simulation and cleanly executing the callbacks.

use_hotstart

Use a hotstart file to initialize the simulation.

Attributes

current_time

Get Simulation Current Time.

end_time

Get/set Simulation end time.

engine_version

Retrieves the SWMM Engine Version.

flow_routing_error

Retrieves the Flow Routing Mass Balance Error.

flow_units

Get Simulation Units (CFS, GPM, MGD, CMS, LPS, MLD).

percent_complete

Get Simulation Percent Complete.

quality_error

Retrieves the Quality Routing Mass Balance Error.

report_start

Get/set Simulation report start time.

runoff_error

Retrieves the Runoff Mass Balance Error.

sim_is_open

Check is Model is Open

sim_is_started

Check is Simulation is Started

start_time

Get/set Simulation start time.

system_units

Get system units (US, SI).