Friday, February 10, 2023

SWMM 5.2 App Guide Pascal Code

 This code is written in Pascal and contains definitions for the SWMM 5 Application Programming Interface (API). It provides functions to run, open, start, step, end, report, and close the SWMM engine. The code also contains functions to retrieve information about the simulation, such as error messages, warnings, count of objects, names of objects, indices of objects, values of properties, and saved values of properties. The code also contains functions to set values of properties and to write lines of text to the output. The code requires the 'swmm5.dll' library to be present to work.


ConstantValue
swmm_GAGE0
swmm_SUBCATCH1
swmm_NODE2
swmm_LINK3
swmm_SYSTEM100
swmm_JUNCTION0
swmm_OUTFALL1
swmm_STORAGE2
swmm_DIVIDER3
swmm_CONDUIT0
swmm_PUMP1
swmm_ORIFICE2
swmm_WEIR3
swmm_OUTLET4
swmm_GAGE_RAINFALL100
swmm_SUBCATCH_AREA200
swmm_SUBCATCH_RAINGAGE201
swmm_SUBCATCH_RAINFALL202
swmm_SUBCATCH_EVAP203
swmm_SUBCATCH_INFIL204
swmm_SUBCATCH_RUNOFF205
swmm_SUBCATCH_RPTFLAG206
swmm_NODE_TYPE300
swmm_NODE_ELEV301
swmm_NODE_MAXDEPTH302
swmm_NODE_DEPTH303
swmm_NODE_HEAD304
swmm_NODE_VOLUME305
swmm_NODE_LATFLOW306
swmm_NODE_INFLOW307
swmm_NODE_OVERFLOW308
swmm_NODE_RPTFLAG309
swmm_LINK_TYPE400
swmm_LINK_NODE1401
swmm_LINK_NODE2402
swmm_LINK_LENGTH403
swmm_LINK_SLOPE404
swmm_LINK_FULLDEPTH405
swmm_LINK_FULLFLOW406
swmm_LINK_SETTING407
swmm_LINK_TIMEOPEN408
swmm_LINK_TIMECLOSED409
swmm_LINK_FLOW410
swmm_LINK_DEPTH411
swmm_LINK_VELOCITY412
swmm_LINK_TOPWIDTH413
swmm_LINK_RPTFLAG414
swmm_STARTDATE0
swmm_CURRENTDATE1
swmm_ELAPSEDTIME2
swmm_ROUTESTEP3
swmm_MAXROUTESTEP4
swmm_REPORTSTEP5
swmm_TOTALSTEPS6
swmm_NOREPORT7
swmm_FLOWUNITS8
swmm_CFS0
swmm_GPM1
swmm_MGD2
swmm_CMS3


unit swmm5; { Pascal SWMM 5 Interface } interface const swmm_GAGE = 0; swmm_SUBCATCH = 1; swmm_NODE = 2; swmm_LINK = 3; swmm_SYSTEM = 100; swmm_JUNCTION = 0; swmm_OUTFALL = 1; swmm_STORAGE = 2; swmm_DIVIDER = 3; swmm_CONDUIT = 0; swmm_PUMP = 1; swmm_ORIFICE = 2; swmm_WEIR = 3; swmm_OUTLET = 4; swmm_GAGE_RAINFALL = 100; swmm_SUBCATCH_AREA = 200; swmm_SUBCATCH_RAINGAGE = 201; swmm_SUBCATCH_RAINFALL = 202; swmm_SUBCATCH_EVAP = 203; swmm_SUBCATCH_INFIL = 204; swmm_SUBCATCH_RUNOFF = 205; swmm_SUBCATCH_RPTFLAG = 206; swmm_NODE_TYPE = 300; swmm_NODE_ELEV = 301; swmm_NODE_MAXDEPTH = 302; swmm_NODE_DEPTH = 303; swmm_NODE_HEAD = 304; swmm_NODE_VOLUME = 305; swmm_NODE_LATFLOW = 306; swmm_NODE_INFLOW = 307; swmm_NODE_OVERFLOW = 308; swmm_NODE_RPTFLAG = 309; swmm_LINK_TYPE = 400; swmm_LINK_NODE1 = 401; swmm_LINK_NODE2 = 402; swmm_LINK_LENGTH = 403; swmm_LINK_SLOPE = 404; swmm_LINK_FULLDEPTH = 405; swmm_LINK_FULLFLOW = 406; swmm_LINK_SETTING = 407; swmm_LINK_TIMEOPEN = 408; swmm_LINK_TIMECLOSED = 409; swmm_LINK_FLOW = 410; swmm_LINK_DEPTH = 411; swmm_LINK_VELOCITY = 412; swmm_LINK_TOPWIDTH = 413; swmm_LINK_RPTFLAG = 414; swmm_STARTDATE = 0; swmm_CURRENTDATE = 1; swmm_ELAPSEDTIME = 2; swmm_ROUTESTEP = 3; swmm_MAXROUTESTEP = 4; swmm_REPORTSTEP = 5; swmm_TOTALSTEPS = 6; swmm_NOREPORT = 7; swmm_FLOWUNITS = 8; swmm_CFS = 0; swmm_GPM = 1; swmm_MGD = 2; swmm_CMS = 3; swmm_LPS = 4; swmm_MLD = 5; Swmm5Lib = 'swmm5.dll'; function swmm_run(F1: PAnsiChar; F2: PAnsiChar; F3: PAnsiChar): Integer; stdcall; external Swmm5Lib; function swmm_open(F1: PAnsiChar; F2: PAnsiChar; F3: PAnsiChar): Integer; stdcall; external Swmm5Lib; function swmm_start(SaveFlag: Integer): Integer; stdcall; external Swmm5Lib; function swmm_step(var ElapsedTime: Double): Integer; stdcall; external Swmm5Lib; function swmm_stride(StrideStep: Integer; var ElapsedTime: Double): Integer; stdcall; external Swmm5Lib; function swmm_end: Integer; stdcall; external Swmm5Lib; function swmm_report: Integer; stdcall; external Swmm5Lib; function swmm_close: Integer; stdcall; external Swmm5Lib; function swmm_getMassBalErr(var Erunoff: Single; var Eflow: Single; var Equal: Single): Integer; stdcall; external Swmm5Lib; function swmm_getVersion: Integer; stdcall; external Swmm5Lib; function swmm_getError(ErrMsg: PAnsiChar; MsgLen: Integer): Integer; stdcall; external Swmm5Lib; function swmm_getWarnings: Integer; stdcall; external Swmm5Lib; function swmm_getCount(ObjType: Integer): Integer; stdcall; external Swmm5Lib; procedure swmm_getName(ObjType: Integer; Index: Integer; Name: PAnsiChar; Size: Integer); stdcall; external Swmm5Lib; function swmm_getIndex(ObjType: Integer; Name: PAnsiChar): Integer; stdcall; external Swmm5Lib; function swmm_getValue(aProperty: Integer; Index: Integer): Double; stdcall; external Swmm5Lib; procedure swmm_setValue(aProperty: Integer; Index: Integer; Value: Double); stdcall; external Swmm5Lib; function swmm_getSavedValue(aProperty: Integer; Index: Integer; Period: Integer): Double; stdcall; external Swmm5Lib; procedure swmm_writeLine(Line: PAnsiChar); stdcall; external Swmm5Lib; procedure swmm_decodeDate(Date: Double; var Year: Integer; var Month: Integer; var Day: Integer; var Hour: Integer; var Minute: Integer; var Second: Integer; var DayOfWeek: Integer); stdcall; external Swmm5Lib; implementation end.


SWMM 5.2 App Python Code - Open, Run and Close Files

 This code is a Python interface for a SWMM library (_lib) using the ctypes module. It provides functions to run, open, start, step, stride, end, get mass balance error, report, and close a SWMM simulation. The functions take various arguments, such as filenames, save flags, time steps, and return values, such as elapsed time, mass balance error, and status codes. The ctypes module converts Python data types into C data types so they can be passed as arguments to the SWMM library.


def getVersion(): return _lib.swmm_getVersion() def run(f1, f2, f3 = ''): return _lib.swmm_run(ctypes.c_char_p(f1.encode()), ctypes.c_char_p(f2.encode()), ctypes.c_char_p(f3.encode())) def open(f1, f2, f3 = ''): return _lib.swmm_open(ctypes.c_char_p(f1.encode()), ctypes.c_char_p(f2.encode()), ctypes.c_char_p(f3.encode())) def start(saveFlag): return _lib.swmm_start(ctypes.c_int(saveFlag)) def step(): elapsed_time = ctypes.c_double() _lib.swmm_step(ctypes.byref(elapsed_time)) return elapsed_time.value def stride(strideStep): elapsed_time = ctypes.c_double() _lib.swmm_stride(ctypes.c_int(strideStep), ctypes.byref(elapsed_time)) return elapsed_time.value def end(): _lib.swmm_end() def getMassBalErr(): runoff = ctypes.c_float() flow = ctypes.c_float() qual = ctypes.c_float() _lib.swmm_getMassBalErr( ctypes.byref(runoff), ctypes.byref(flow), ctypes.byref(qual)) return runoff.value, flow.value, qual.value def report(): return _lib.swmm_report() def close(): _lib.swmm_close()



What does the Acronmym RAFTS In InfoWorks ICM Mean?

A method is presented to extend a single event urban rainfall/runoff model into a statistically based runoff frequency model by introducing a loss model which utilizes as input joint probability data to link the stochastic elements of rainfall and catchment antecedent soil moisture with the deterministic parts of the rainfall/runoff process. 

The single event model briefly described has been known for nearly a decade as the Regional Stormwater Drainage Model (RSWM) but due to extensions and additions to its structure, including the loss model, which is known as the Stochastic/Deterministic Loss Model (SDLM), the rainfall/runoff model described in the paper is referred to as the Runoff Analysis Flow Training System (RAFTS).

Thursday, February 9, 2023

SWMM 5.2 App Python Code for the Interface

This code is a Python interface to the SWMM5 simulation engine. It provides functions to control and obtain information from the SWMM5 simulation engine using the SWMM5 API. The functions cover various aspects of the simulation, including opening and running the simulation, reporting the results, and accessing the properties of the simulation objects, such as nodes and links. The code also includes a function to decode the simulation date and time into a Python datetime object.


"""Python SWMM5 interface"""

import ctypes
import platform
import datetime

_plat= platform.system()
if _plat=='Linux':
    _lib = ctypes.CDLL("libswmm5.so")
elif _plat=='Windows':
    _lib = ctypes.WinDLL(".\swmm5.dll")
else:
    Exception('Platform '+ _plat +' unsupported')

def getVersion():
    return _lib.swmm_getVersion()

def run(f1, f2, f3 = ''):
    return _lib.swmm_run(ctypes.c_char_p(f1.encode()), 
                        ctypes.c_char_p(f2.encode()), 
                        ctypes.c_char_p(f3.encode()))

def open(f1, f2, f3 = ''):
    return _lib.swmm_open(ctypes.c_char_p(f1.encode()), 
                        ctypes.c_char_p(f2.encode()), 
                        ctypes.c_char_p(f3.encode()))

def start(saveFlag):
    return _lib.swmm_start(ctypes.c_int(saveFlag))

def step():
    elapsed_time = ctypes.c_double()
    _lib.swmm_step(ctypes.byref(elapsed_time))
    return elapsed_time.value

def stride(strideStep):
    elapsed_time = ctypes.c_double()
    _lib.swmm_stride(ctypes.c_int(strideStep), ctypes.byref(elapsed_time))
    return elapsed_time.value

def end():
    _lib.swmm_end()

def getMassBalErr():     
    runoff = ctypes.c_float()
    flow = ctypes.c_float()
    qual = ctypes.c_float()
    _lib.swmm_getMassBalErr(
        ctypes.byref(runoff), ctypes.byref(flow), ctypes.byref(qual))
    return runoff.value, flow.value, qual.value

def report():
    return _lib.swmm_report()

def close():
  _lib.swmm_close()

def getWarnings():
    return _lib.swmm_getWarnings()

def getError():
    errmsg = ctypes.create_string_buffer(240)
    _lib.swmm_getError(ctypes.byref(errmsg), ctypes.c_int(240))
    return errmsg.value.decode()

def getCount(objtype):
    return _lib.swmm_getCount(ctypes.c_int(objtype))

def getName(objtype, index, size):
    name = ctypes.create_string_buffer(size)
    _lib.swmm_getName(
        ctypes.c_int(objtype), ctypes.c_int(index), ctypes.byref(name), ctypes.c_int(size))
    return name.value.decode()

def getIndex(objtype, name):
    return _lib.swmm_getIndex(ctypes.c_int(objtype), ctypes.c_char_p(name.encode()))

def getValue(property, index):
    _lib.swmm_getValue.restype = ctypes.c_double   
    return _lib.swmm_getValue(ctypes.c_int(property), ctypes.c_int(index))

def getSavedValue(property, index, period):
    _lib.swmm_getSavedValue.restype = ctypes.c_double   
    return _lib.swmm_getSavedValue(
        ctypes.c_int(property), ctypes.c_int(index), ctypes.c_int(period))

def setValue(property, index, value):
    _lib.swmm_setValue(
        ctypes.c_int(property), ctypes.c_int(index), ctypes.c_double(value))

def writeLine(line):
    _lib.swmm_writeLine(ctypes.c_char_p(line.encode()))

def decodeDate(date):

    """  Decodes a SWMM DateTime value to a Python DateTime value. """
    """  Use Python's datetime.weekday()  method to get day of week """
    """  (where Monday = 0 and Sunday = 6) if needed. """

    year= ctypes.c_int()
    month= ctypes.c_int()
    day= ctypes.c_int()
    hour= ctypes.c_int()
    minute= ctypes.c_int()
    second= ctypes.c_int()
    dayofweek= ctypes.c_int()
    _lib.swmm_decodeDate(
        ctypes.c_double(date), ctypes.byref(year), ctypes.byref(month),
        ctypes.byref(day),  ctypes.byref(hour), ctypes.byref(minute),
        ctypes.byref(second), ctypes.byref(dayofweek))
    d = datetime.datetime(
        year.value, month.value, day.value, hour.value, minute.value, second.value)
    return d

AI Rivers of Wisdom about ICM SWMM

Here's the text "Rivers of Wisdom" formatted with one sentence per line: [Verse 1] 🌊 Beneath the ancient oak, where shadows p...