Skip to content

Commit

Permalink
add the function loadMSXEPANETFile - msxname > MSXTempFile, add MSXFile
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariosmsk committed Jun 20, 2024
1 parent 0df4cc8 commit 7b9b336
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ If you want to contribute, please check out our [Code of Conduct](https://github
|initializeHydraulicAnalysis|Initializes storage tank levels, link status and settings, and the simulation clock time prior to running a hydraulic analysis
|initializeQualityAnalysis|Initializes water quality and the simulation clock time prior to running a water quality analysis
|loadEPANETFile|Load epanet file when use bin functions
|loadMSXEPANETFile|Re-Load EPANET MSX file - parfor
|nextHydraulicAnalysisStep|Determines the length of time until the next hydraulic event occurs in an extended period simulation
|nextQualityAnalysisStep|Advances the water quality simulation to the start of the next hydraulic time period
|openAnyInp|Open as on matlab editor any EPANET input file using built function open
Expand Down
34 changes: 23 additions & 11 deletions epyt/epanet.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,8 @@ def __init__(self, *argv, version=2.2, ph=False, loadfile=False, customlib=None,
warnings.simplefilter('always')
# Demand model types. DDA #0 Demand driven analysis,
# PDA #1 Pressure driven analysis.
self.msxname = None
self.MSXFile = None
self.MSXTempFile = None
self.DEMANDMODEL = ['DDA', 'PDA']
# Link types
self.TYPELINK = ['CVPIPE', 'PIPE', 'PUMP', 'PRV', 'PSV',
Expand Down Expand Up @@ -6503,8 +6504,18 @@ def loadEPANETFile(self, *argv):
else:
self.api.ENopen(argv[0], argv[1], argv[2])

def loadMSXEPANETFile(self, msxfile):
""" Load EPANET MSX file.

Example:

>>> d.loadMSXEPANETFile(d.MSXTempFile)
"""
err = self.msx.msx_lib.MSXopen(c_char_p(msxfile.encode('utf-8')))
return err

def max(self, value):
""" Retrieves the max value of numpy.array or numpy.mat """
""" Retrieves the smax value of numpy.array or numpy.mat """
return np.max(value)

def multiply_elements(self, arr1, arr2):
Expand Down Expand Up @@ -11243,9 +11254,10 @@ def loadMSXFile(self, msxname, customMSXlib=None, ignore_properties=False):
continue
break

self.msxname = msxname[:-4] + '_temp.msx'
copyfile(msxname, self.msxname)
self.msx = epanetmsxapi(self.msxname, customMSXlib=customMSXlib, display_msg=self.display_msg)
self.MSXFile = msxname[:-4]
self.MSXTempFile = msxname[:-4] + '_temp.msx'
copyfile(msxname, self.MSXTempFile)
self.msx = epanetmsxapi(self.MSXTempFile, customMSXlib=customMSXlib, display_msg=self.display_msg)

# Message to user if he uses ph with msx
if self.api._ph is not None:
Expand Down Expand Up @@ -11499,7 +11511,7 @@ def getMSXOptions(self):
in_options = False

# Open and read the file
with open(self.msxname, 'r') as file:
with open(self.MSXTempFile, 'r') as file:
for line in file:
# Check for [OPTIONS] section
if "[OPTIONS]" in line:
Expand Down Expand Up @@ -12040,7 +12052,7 @@ def getMSXSpeciesUnits(self, varagin=None):
return value

def getEquations(self):
msxname = self.msxname
msxname = self.MSXTempFile
Terms = {}
Pipes = {}
Tanks = {}
Expand Down Expand Up @@ -12409,8 +12421,8 @@ def changeMSXOptions(self, param, change):
f.truncate()

self.msx.MSXclose()
copyfile(options_section, self.msxname)
self.msx.MSXopen(self.msxname, reload = True)
copyfile(options_section, self.MSXTempFile)
self.loadMSXEPANETFile(self.MSXTempFile)

def setMSXAreaUnitsCM2(self):
""" Sets the area units to square centimeters.
Expand Down Expand Up @@ -16171,7 +16183,7 @@ def __init__(self, msxfile='', loadlib=True, ignore_msxfile=False, customMSXlib=
if not ignore_msxfile:
self.MSXopen(msxfile)

def MSXopen(self, msxfile, reload = False):
def MSXopen(self, msxfile):
"""
Open MSX file
filename - Arsenite.msx or use full path
Expand All @@ -16183,7 +16195,7 @@ def MSXopen(self, msxfile, reload = False):
if not os.path.exists(msxfile):
raise FileNotFoundError(f"File not found: {msxfile}")

if self.display_msg and not reload:
if self.display_msg:
print("Opening MSX file:", msxfile)
msxbasename = os.path.basename(msxfile)
err = self.msx_lib.MSXopen(c_char_p(msxfile.encode('utf-8')))
Expand Down
Binary file added sis4_5
Binary file not shown.

0 comments on commit 7b9b336

Please sign in to comment.