Friday, February 10, 2023

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



No comments:

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