Start simulation
This commit is contained in:
33
epanet/epanet.py
Normal file
33
epanet/epanet.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import ctypes
|
||||
import platform
|
||||
import os
|
||||
|
||||
_lib_core = None
|
||||
_lib_output = None
|
||||
|
||||
def load_epanet():
|
||||
_platform = platform.system()
|
||||
if _platform != "Windows":
|
||||
raise Exception(f'Platform {_platform} unsupported (not yet)')
|
||||
_lib_core = ctypes.CDLL("./epanet2.dll")
|
||||
#version = ctypes.c_int()
|
||||
#lib_core.EN_getversion(ctypes.byref(version))
|
||||
#print(f'Load EPANET {version}')
|
||||
_lib_output = ctypes.CDLL("./epanet-output.dll")
|
||||
|
||||
|
||||
# readable True => json, False => binary output
|
||||
def run_epanet(project: str, readable: bool = True) -> str:
|
||||
dir = os.path.dirname(os.getcwd())
|
||||
exe = os.path.join(os.path.join(dir, 'epanet'), 'runepanet.exe')
|
||||
inp = os.path.join(os.path.join(dir, 'inp'), project + '.inp')
|
||||
rpt = os.path.join(os.path.join(dir, 'temp'), project + '.rpt')
|
||||
opt = os.path.join(os.path.join(dir, 'temp'), project + '.opt')
|
||||
command = f'{exe} {inp} {rpt} {opt}'
|
||||
print(command)
|
||||
os.popen(command)
|
||||
return ''
|
||||
|
||||
if __name__ == '__main__':
|
||||
load_epanet()
|
||||
run_epanet('net3')
|
||||
Reference in New Issue
Block a user