Skip to content

Commit

Permalink
some changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariosmsk committed Apr 16, 2024
1 parent b078f5c commit 3f877b8
Showing 1 changed file with 48 additions and 55 deletions.
103 changes: 48 additions & 55 deletions epyt/epanet.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ def __init__(self, *argv, version=2.2, ph=False, loadfile=False, msx=False):
# Constants
# Demand model types. DDA #0 Demand driven analysis,
# PDA #1 Pressure driven analysis.
self.realmsx = ''
self.msxname = None
self.DEMANDMODEL = ['DDA', 'PDA']
# Link types
self.TYPELINK = ['CVPIPE', 'PIPE', 'PUMP', 'PRV', 'PSV',
Expand Down Expand Up @@ -11157,14 +11157,57 @@ def __setNodeDemandPattern(self, fun, propertyCode, value, *argv):

"""MSX Functions"""

def loadMSXFile(self, msxname):
def loadMSXFile(self, msxname, ignore_properties=False):
"""Loads an msx file
Example:
d.loadMSXFile('net2-cl2.msx')
"""
self.realmsx = msxname
self.msx = epanetmsxapi(ignore_msxfile=True)
self.MSXPythonSetup(msxname)
self.msxname = msxname[:-4] + '_temp.msx'
copyfile(msxname, self.msxname)
self.msx = epanetmsxapi(self.msxname, ignore_msxfile=True)

if ignore_properties:
self.MSXEquationsTerms = self.getMSXEquationsTerms()
self.MSXEquationsPipes = self.getMSXEquationsPipes()
self.MSXEquationsTanks = self.getMSXEquationsTanks()
self.MSXSpeciesCount = self.getMSXSpeciesCount()
self.MSXConstantsCount = self.getMSXConstantsCount()
self.MSXParametersCount = self.getMSXParametersCount()
self.MSXPatternsCount = self.getMSXPatternsCount()
self.MSXSpeciesIndex = self.getMSXSpeciesIndex()
self.MSXSpeciesNameID = self.getMSXSpeciesNameID()
self.MSXSpeciesType = self.getMSXSpeciesType()
self.MSXSpeciesUnits = self.getMSXSpeciesUnits()
self.MSXSpeciesATOL = self.getMSXSpeciesATOL()
self.MSXSpeciesRTOL = self.getMSXSpeciesRTOL()
self.MSXConstantsNameID = self.getMSXConstantsNameID()
self.MSXConstantsValue = self.getMSXConstantsValue()
self.MSXConstantsIndex = self.getMSXConstantsIndex()
self.MSXParametersNameID = self.getMSXParametersNameID()
self.MSXParametersIndex = self.getMSXParametersIndex()
self.MSXParametersTanksValue = self.getMSXParametersTanksValue()
self.MSXParametersPipesValue = self.getMSXParametersPipesValue()
self.MSXPatternsNameID = self.getMSXPatternsNameID()
self.MSXPatternsIndex = self.getMSXPatternsIndex()
self.MSXPatternsLengths = self.getMSXPatternsLengths()
self.MSXNodeInitqualValue = self.getMSXNodeInitqualValue()
self.MSXLinkInitqualValue = self.getMSXLinkInitqualValue()
self.MSXSources = self.getMSXSources()
self.MSXSourceType = self.getMSXSourceType()
self.MSXSourceLevel = self.getMSXSourceLevel()
self.MSXSourcePatternIndex = self.getMSXSourcePatternIndex()
self.MSXSourceNodeNameID = self.getMSXSourceNodeNameID()
self.MSXPattern = self.getMSXPattern()

# options
self.solver = self.getMSXSolver()
self.areaunits = self.getMSXAreaUnits()
self.rateunits = self.getMSXRateUnits()
self.rtol = self.getMSXRtol()
self.atol = self.getMSXAtol()
self.timestep = self.getMSXTimeStep()
self.coupling = self.getMSXCoupling()
self.compiler = self.getMSXCompiler()

def unloadMSX(self):
"""Unload library and close the MSX Toolkit system.
Expand Down Expand Up @@ -12265,55 +12308,6 @@ def getMSXSourceNodeNameID(self):
nodes.append(i)
return nodes

def MSXPythonSetup(self, msxname):

self.msxname = msxname[:-4] + '_temp.msx'
copyfile(msxname, self.msxname)

self.msx.MSXopen(self.msxname)

self.MSXEquationsTerms = self.getMSXEquationsTerms()
self.MSXEquationsPipes = self.getMSXEquationsPipes()
self.MSXEquationsTanks = self.getMSXEquationsTanks()
self.MSXSpeciesCount = self.getMSXSpeciesCount()
self.MSXConstantsCount = self.getMSXConstantsCount()
self.MSXParametersCount = self.getMSXParametersCount()
self.MSXPatternsCount = self.getMSXPatternsCount()
self.MSXSpeciesIndex = self.getMSXSpeciesIndex()
self.MSXSpeciesNameID = self.getMSXSpeciesNameID()
self.MSXSpeciesType = self.getMSXSpeciesType()
self.MSXSpeciesUnits = self.getMSXSpeciesUnits()
self.MSXSpeciesATOL = self.getMSXSpeciesATOL()
self.MSXSpeciesRTOL = self.getMSXSpeciesRTOL()
self.MSXConstantsNameID = self.getMSXConstantsNameID()
self.MSXConstantsValue = self.getMSXConstantsValue()
self.MSXConstantsIndex = self.getMSXConstantsIndex()
self.MSXParametersNameID = self.getMSXParametersNameID()
self.MSXParametersIndex = self.getMSXParametersIndex()
self.MSXParametersTanksValue = self.getMSXParametersTanksValue()
self.MSXParametersPipesValue = self.getMSXParametersPipesValue()
self.MSXPatternsNameID = self.getMSXPatternsNameID()
self.MSXPatternsIndex = self.getMSXPatternsIndex()
self.MSXPatternsLengths = self.getMSXPatternsLengths()
self.MSXNodeInitqualValue = self.getMSXNodeInitqualValue()
self.MSXLinkInitqualValue = self.getMSXLinkInitqualValue()
self.MSXSources = self.getMSXSources()
self.MSXSourceType = self.getMSXSourceType()
self.MSXSourceLevel = self.getMSXSourceLevel()
self.MSXSourcePatternIndex = self.getMSXSourcePatternIndex()
self.MSXSourceNodeNameID = self.getMSXSourceNodeNameID()
self.MSXPattern = self.getMSXPattern()

# options
self.solver = self.getMSXSolver()
self.areaunits = self.getMSXAreaUnits()
self.rateunits = self.getMSXRateUnits()
self.rtol = self.getMSXRtol()
self.atol = self.getMSXAtol()
self.timestep = self.getMSXTimeStep()
self.coupling = self.getMSXCoupling()
self.compiler = self.getMSXCompiler()

def setMSXOptions(self, *args):

for i in range(len(args) // 2):
Expand Down Expand Up @@ -15698,7 +15692,6 @@ def MSXopen(self, msxfile):
print("Error 503 may indicate a problem with the MSX file or the MSX library.")
else:
print(f"MSX file {msxbasename} loaded successfully.")
# msx open ends here

def MSXclose(self):
""" Close .msx file
Expand Down

0 comments on commit 3f877b8

Please sign in to comment.