From 9b13cdb31c3cdf81ae164ea07777110c8c07dbec Mon Sep 17 00:00:00 2001 From: ichrys03 <79056704+ichrys03@users.noreply.github.com> Date: Fri, 8 Mar 2024 03:22:42 +0200 Subject: [PATCH 1/3] fixed the struct types of some functions and also commented on those that produce results consistent with MATLAB' --- epyt/epanet.py | 483 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 463 insertions(+), 20 deletions(-) diff --git a/epyt/epanet.py b/epyt/epanet.py index 87a490f..24a1364 100644 --- a/epyt/epanet.py +++ b/epyt/epanet.py @@ -11134,25 +11134,72 @@ def __setNodeDemandPattern(self, fun, propertyCode, value, *argv): """MSX Funtions""" def loadMSXfile(self, msxname): + """Loads an msx file + Example: + d.loadMSXfile('net2-cl2.msx') + """ self.realmsx = msxname self.MSXPythonSetup(msxname) def unloadMSX(self): + """Unload library and close the MSX Toolkit system. + Example: + d.unloadMSX() + """ self.msx.MSXclose() def getMSXSpeciesCount(self): + """ Retrieves the number of species. + + Example: + d = epanet('Net3-NH2CL.inp'); + d.loadMSXFile('Net3-NH2CL.msx'); + d.getMSXSpeciesCount() + + See also getMSXSpeciesIndex, getMSXSpeciesNameID, getMSXSpeciesConcentration, + getMSXSpeciesType, getMSXSpeciesUnits, getMSXSpeciesATOL, + getMSXSpeciesRTOL.""" MSX_SPECIES = self.ToolkitConstants.MSX_SPECIES return self.msx.MSXgetcount(MSX_SPECIES) def getMSXConstantsCount(self): + """ Retrieves the number of constants. + + Example: + d = epanet('Net3-NH2CL.inp'); + d.loadMSXFile('Net3-NH2CL.msx'); + d.getMSXConstantsCount() + + See also getMSXConstantsIndex, getMSXConstantsValue, + getMSXConstantsNameID.""" MSX_CONSTANT = self.ToolkitConstants.MSX_CONSTANT return self.msx.MSXgetcount(MSX_CONSTANT) def getMSXParametersCount(self): + """ Retrieves the number of parameters. + + Example: + d = epanet('Net3-NH2CL.inp'); + d.loadMSXFile('Net3-NH2CL.msx'); + d.getMSXParametersCount() + + See also setMSXParametersTanksValue, setMSXParametersPipesValue, + getMSXParametersIndex, getMSXParametersTanksValue, + getMSXParametersPipesValue.""" MSX_PARAMETER = self.ToolkitConstants.MSX_PARAMETER return self.msx.MSXgetcount(MSX_PARAMETER) def getMSXPatternsCount(self): + """ Retrieves the number of patterns. + + Example: + d = epanet('net2-cl2.inp'); + d.loadMSXFile('net2-cl2.msx'); + d.addMSXPattern('P1', [1.0, 0.0 1.0]); + d.addMSXPattern('P2', [0.0, 0.0 2.0]); + d.getMSXPatternsCount() + + See also setMSXPattern, setMSXPatternValue, addMSXPattern.""" MSX_PATTERN = self.ToolkitConstants.MSX_PATTERN return self.msx.MSXgetcount(MSX_PATTERN) @@ -11163,9 +11210,25 @@ def saveMSXQualityFile(self, outfname): self.msx.MSXsaveoutfile(outfname) def solveMSXCompleteHydraulics(self): + """Solve complete hydraulic over the entire simulation period. + % + % Example: + % d = epanet('net2-cl2.inp'); + % d.loadMSXFile('net2-cl2.msx'); + % d.solveMSXCompleteHydraulics() + % + % See also solveMSXCompleteQuality.""" self.msx.MSXsolveH() def solveMSXCompleteQuality(self): + """Solve complete hydraulic over the entire simulation period. + + Example: + d = epanet('net2-cl2.inp'); + d.loadMSXFile('net2-cl2.msx'); + d.solveMSXCompleteQuality() + + See also solveMSXCompleteHydraulics.""" self.msx.MSXsolveQ() def writeMSXReport(self): @@ -11185,9 +11248,19 @@ def stepMSXQualityAnalysisTimeLeft(self): return t, tleft def getMSXError(self, code): + """ Retrieves the MSX erorr message for specific erorr code. + + Example: + d.getMSXError(510)""" self.msx.MSXgeterror(code) def getMSXOptions(self, param="", getall=False): + """ Retrieves all the options. + + Example: + d=epanet('net2-cl2.inp'); + d.loadMSXFile('net2-cl2.msx'); + d.getMSXOptions()""" msxname=self.msxname options = {} options["AREA_UNITS"] = "FT2" @@ -11243,30 +11316,121 @@ def getMSXOptions(self, param="", getall=False): return options def getMSXTimeStep(self): + """ Retrieves the time step. + + Example: + d=epanet('net2-cl2.inp'); + d.loadMSXFile('net2-cl2.msx'); + d.getMSXTimeStep() + + See also setMSXTimeStep.""" return self.getMSXOptions("TIMESTEP") def getMSXRateUnits(self): + """ Retrieves rate units. + Example: + d = epanet('net2-cl2.inp'); + d.loadMSXFile('net2-cl2.msx'); + d.getMSXRateUnits() + + See also setMSXRateUnits.""" return self.getMSXOptions("RATE_UNITS") def getMSXAreaUnits(self): + """ Retrieves Are units. + Example: + d = epanet('net2-cl2.inp'); + d.loadMSXFile('net2-cl2.msx'); + d.getMSXAreaUnits() + + See also setMSXAreaUnits.""" return self.getMSXOptions("AREA_UNITS") def getMSXCompiler(self): + """ Retrieves the chemistry function compiler code. + + Compiler Options: + NONE: no compiler (default option) + gc: MinGW or Gnu C++ compilers + vc: Visual C++ compiler + + Example: + d = epanet('net2-cl2.inp'); + d.loadMSXFile('net2-cl2.msx'); + d.getMSXCompiler() + + See also setMSXCompilerNONE, setMSXCompilerVC, + setMSXCompilerGC.""" return self.getMSXOptions("COMPILER") def getMSXCoupling(self): + """ Retrieves the degree of coupling for solving DAE's. + + Coupling Options: + NONE: The solution to the algebraic equations is only updated + at the end of each integration time step. + FULL: The updating is done whenever a new set of values for the + rate-dependent variables in the reaction + rate expressions is computed. + + Example: + d = epanet('net2-cl2.inp'); + d.loadMSXFile('net2-cl2.msx'); + d.getMSXCoupling() + + See also setMSXCouplingFULL, setMSXCouplingNONE.""" return self.getMSXOptions("COUPLING") def getMSXSolver(self): + """ Retrieves the solver method. + + Numerical integration methods: + EUL = standard Euler integrator + RK5 = Runge-Kutta 5th order integrator + ROS2 = 2nd order Rosenbrock integrator. + + Example: + d=epanet('net2-cl2.inp'); + d.loadMSXFile('net2-cl2.msx'); + d.getMSXSolver() + + See also setMSXSolverEUL, setMSXSolverRK5, setMSXSolverROS2.""" return self.getMSXOptions("SOLVER") def getMSXAtol(self): + """ Retrieves the absolute tolerance. + + Example: + d = epanet('net2-cl2.inp'); + d.loadMSXFile('net2-cl2.msx'); + d.getMSXAtol() + + See also getMSXRtol.""" return self.getMSXOptions("ATOL") def getMSXRtol(self): + """ Retrieves the relative accuracy level. + + Example: + d = epanet('net2-cl2.inp'); + d.loadMSXFile('net2-cl2.msx'); + d.getMSXRtol() + + See also getMSXAtol.""" return self.getMSXOptions("RTOL") def getMSXConstantsNameID(self, varagin=None): + """ Retrieves the constant's ID. + + Example: + d = epanet('Net3-NH2CL.inp'); + d.loadMSXFile('Net3-NH2CL.msx'); + d.getMSXConstantsNameID() Retrieves the IDs of all the constants. + d.getMSXConstantsNameID({1}) Retrieves the ID of the first constant. + d.getMSXConstantsNameID{[1,2]} Retrieves the IDs of the first two constants. + + See also getMSXConstantsCount, getMSXConstantsValue, + getMSXConstantsNameID.""" x = self.getMSXConstantsCount() value = {} if varagin is None: @@ -11278,9 +11442,21 @@ def getMSXConstantsNameID(self, varagin=None): for i in varagin: len = self.msx.MSXgetIDlen(MSX_CONSTANT, i) value[i] = self.msx.MSXgetID(MSX_CONSTANT, i, len) - return value + output = list(value.values()) + return output def getMSXParametersNameID(self, varagin=None): + """ Retrieves the parameter's ID. + + Example: + d = epanet('Net3-NH2CL.inp'); + d.loadMSXFile('Net3-NH2CL.msx'); + d.getMSXParametersNameID() % Retrieves the IDs of all the parameters. + d.getMSXParametersNameID(1) % Retrieves the ID of the first parameter. + d.getMSXParametersNameID([1:3]) % Retrieves the IDs of the first three parameters. + + See also getMSXParametersCount, getMSXParametersIndex, + getMSXParametersTanksValue, getMSXParametersPipesValue.""" x = self.getMSXParametersCount() value = {} if varagin is None: @@ -11292,9 +11468,25 @@ def getMSXParametersNameID(self, varagin=None): for i in varagin: len = self.msx.MSXgetIDlen(MSX_PARAMETER, i) value[i] = self.msx.MSXgetID(MSX_PARAMETER, i, len) - return value + output = list(value.values()) + return output def getMSXPatternsNameID(self, varagin=None): + """ Retrieves the patterns ID. + + Example: + d = epanet('net2-cl2.inp'); + d.loadMSXFile('net2-cl2.msx'); + d.addMSXPattern('P1', [1.0, 0.0 1.0]); + d.addMSXPattern('P2', [0.0, 0.0 2.0]); + d.addMSXPattern('P3', [0.0, 1.0 2.0]); + d.addMSXPattern('P4', [1.0, 1.0 2.0]); + d.getMSXPatternsNameID() Retrieves the IDs of all the patterns. + d.getMSXPatternsNameID(1) Retrieves the ID of the first pattern. + d.getMSXPatternsNameID(1:3) Retrieves the IDs of the first three patterns. + + See also getMSXPattern, getMSXPatternsIndex, getMSXPatternsLengths, + setMSXPattern, setMSXPatternMatrix, setMSXPatternValue.""" x = self.getMSXPatternsCount() value = {} if varagin is None: @@ -11306,9 +11498,22 @@ def getMSXPatternsNameID(self, varagin=None): for i in varagin: len = self.msx.MSXgetIDlen(MSX_PATTERN, i) value[i] = self.msx.MSXgetID(MSX_PATTERN, i, len) - return value + output = list(value.values()) + return output def getMSXSpeciesNameID(self, varagin=None): + """Retrieves the species' ID. + + Example: + d = epanet('Net3-NH2CL.inp'); + d.loadMSXFile('Net3-NH2CL.msx'); + d.getMSXSpeciesNameID() Retrieves the IDs of all the species. + d.getMSXSpeciesNameID(1) Retrieves the IDs of the first specie. + d.getMSXSpeciesNameID([1:3]) Retrieves the IDs of the first three species. + + See also getMSXSpeciesIndex, getMSXSpeciesCount, getMSXSpeciesConcentration, + getMSXSpeciesType, getMSXSpeciesUnits, getMSXSpeciesATOL, + getMSXSpeciesRTOL.""" x = self.getMSXSpeciesCount() value = {} if varagin is None: @@ -11320,69 +11525,134 @@ def getMSXSpeciesNameID(self, varagin=None): for i in varagin: len = self.msx.MSXgetIDlen(MSX_SPECIES, i) value[i] = self.msx.MSXgetID(MSX_SPECIES, i, len) - return value + output = list(value.values()) + return output def getMSXParametersIndex(self, varagin=None): + """ Retrieves the parameter's indices. + + Example: + d = epanet('Net3-NH2CL.inp'); + d.loadMSXFile('Net3-NH2CL.msx'); + d.getMSXParametersIndex() Retrieves the indices of all the parameters. + d.getMSXParametersIndex(['k1']) Retrieves the index of the first parameter. + d.getMSXParametersIndex(['k1', 'k3', 'kDOC1']) Retrieves the indices of the + parameters 'k1', 'k3' and 'kDOC1'. + + See also getMSXParametersCount, getMSXParametersIndex, + getMSXParametersTanksValue, getMSXParametersPipesValue.""" x = self.getMSXParametersCount() value = {} if varagin is None: varagin = {} varagin = self.getMSXParametersNameID() - y = [value for value in varagin.values()] + y = varagin else: y = varagin MSX_PARAMETER = self.ToolkitConstants.MSX_PARAMETER if x > 0: for i in y: value[i] = self.msx.MSXgetindex(MSX_PARAMETER, i) - return value + output = list(value.values()) + return output def getMSXSpeciesIndex(self, varagin=None): + """ Retrieves the species' index. + + Example: + d = epanet('Net3-NH2CL.inp'); + d.loadMSXFile('Net3-NH2CL.msx'); + d.getMSXSpeciesIndex() Retrieves the index of all the species. + d.getMSXSpeciesIndex(['Na']) Retrieves the index of the Na. + d.getMSXSpeciesIndex(['CL2', 'Nb', 'Na']) Retrieves the indices of CL2, Nb and Na. + + See also getMSXSpeciesUnits, getMSXSpeciesCount, getMSXSpeciesConcentration, + getMSXSpeciesType, getMSXSpeciesNameID, getMSXSpeciesRTOL, + getMSXSpeciesATOL.""" x = self.getMSXSpeciesCount() value = {} if varagin is None: varagin = {} varagin = self.getMSXSpeciesNameID() - y = [value for value in varagin.values()] + y = varagin else: y = varagin MSX_SPECIES = self.ToolkitConstants.MSX_SPECIES if x > 0: for i in y: value[i] = self.msx.MSXgetindex(MSX_SPECIES, i) - return value + output = list(value.values()) + return output def getMSXPatternsIndex(self, varagin=None): + """ Retrieves the patterns index. + + Example: + d = epanet('net2-cl2.inp'); + d.loadMSXFile('net2-cl2.msx'); + d.addMSXPattern('P1', [1.0, 0.0 1.0]); + d.addMSXPattern('P2', [0.0, 0.0 2.0]); + d.addMSXPattern('P3', [0.0, 1.0 2.0]); + d.addMSXPattern('P4', [1.0, 1.0 2.0]); + d.getMSXPatternsIndex() Retrieves the indices of all the patterns. + d.getMSXPatternsIndex(['P1']) Retrieves the index of the first pattern. + d.getMSXPatternsIndex(['P1', 'P2', 'P3']) Retrieves the indices of the first three patterns. + + See also getMSXPattern, getMSXPatternsNameID, getMSXPatternsLengths, + setMSXPattern, setMSXPatternMatrix, setMSXPatternValue.""" x = self.getMSXSpeciesCount() value = {} if varagin is None: varagin = {} varagin = self.getMSXPatternsNameID() - y = [value for value in varagin.values()] + y = varagin else: y = varagin MSX_PATTERN = self.ToolkitConstants.MSX_PATTERN if x > 0: for i in y: value[i] = self.msx.MSXgetindex(MSX_PATTERN, i) - return value + output = list(value.values()) + return output def getMSXConstantsIndex(self, varagin=None): + """ Retrieves the constant's index. + + Example: + d = epanet('Net3-NH2CL.inp'); + d.loadMSXFile('Net3-NH2CL.msx'); + d.getMSXConstantsIndex() Retrieves the index of all the species. + d.getMSXConstantsIndex(['S1']) Retrieves the index of S1. + + See also getMSXConstantsCount, getMSXConstantsValue, + getMSXConstantsNameID.""" x = self.getMSXConstantsCount() value = {} if varagin is None: varagin = {} varagin = self.getMSXConstantsNameID() - y = [value for value in varagin.values()] + y = varagin else: y = varagin MSX_CONSTANT = self.ToolkitConstants.MSX_CONSTANT if x > 0: for i in y: value[i] = self.msx.MSXgetindex(MSX_CONSTANT, i) - return value + output = list(value.values()) + return output def getMSXConstantsValue(self, varagin=None): + """ Retrieves the constant's value. + + Example: + d = epanet('net3-bio.inp'); + d.loadMSXFile('net3-bio.msx'); + d.getMSXConstantsValue Retrieves the values of all the constants. + d.getMSXConstantsValue{1} Retrieves the value of the first constant. + d.getMSXConstantsValue{[1,2]} Retrieves the values of the first two constants. + + See also setMSXConstantsValue, getMSXConstantsCount, + getMSXConstantsIndex, getMSXConstantsNameID""" x = self.getMSXConstantsCount() value = {} if varagin is None: @@ -11392,9 +11662,19 @@ def getMSXConstantsValue(self, varagin=None): if x > 0: for i in varagin: value[i] = self.msx.MSXgetconstant(i) - return value + output = list(value.values()) + return output def getMSXParametersPipesValue(self): + """ Retrieves the parameters pipes value. + + Example: + d = epanet('net2-cl2.inp'); + d.loadMSXFile('net2-cl2.msx'); + d.getMSXParametersPipesValue() + + See also setMSXParametersPipesValue, getMSXParametersTanksValue, + getMSXParametersCount, getMSXParametersIndex.""" x = self.getLinkPipeCount() y = self.getMSXParametersCount() value = [] @@ -11407,6 +11687,16 @@ def getMSXParametersPipesValue(self): return value def getMSXParametersTanksValue(self): + """ Retrieves the parameters tanks value. + + Example: + d = epanet('net2-cl2.inp'); + d.loadMSXFile('net2-cl2.msx'); + tankIndex = d.getNodeTankIndex + d.getMSXParametersTanksValue{tankIndex} Retrieves the value of the first tank. + + See also setMSXParametersTanksValue, getMSXParametersCount, + getMSXParametersIndex, getMSXParametersPipesValue.""" x = self.getNodeTankIndex() y = self.getMSXParametersCount() value = {} @@ -11415,9 +11705,23 @@ def getMSXParametersTanksValue(self): for j in range(1, y + 1): param = self.msx.MSXgetparameter(0, i, j) value[i].append(param) - return value - + output = list(value.values()) + return output def getMSXPatternsLengths(self, varagin=None): + """ Retrieves the pattern lengths. + + Example: + d = epanet('net2-cl2.inp'); + d.loadMSXFile('net2-cl2.msx'); + d.addMSXPattern('P1', [1.0, 0.0 1.0]); + d.addMSXPattern('P2', 1.0); + d.addMSXPattern('P3', [0.0, 1.0 2.0]); + d.addMSXPattern('P4', [1.0, 2.0]); + d.getMSXPatternsLengths() Retrieves the lengths of all the patterns. + d.getMSXPatternsLengths([]1) Retrieves the length of the first pattern. + x=d.getMSXPatternsLengths([1,2]) Retrieves the lengths of the first two patterns. + See also getMSXPattern, getMSXPatternsIndex, getMSXPatternsNameID, + setMSXPattern, setMSXPatternMatrix, setMSXPatternValue.""" x = self.getMSXPatternsCount() value = {} if varagin is None: @@ -11427,19 +11731,34 @@ def getMSXPatternsLengths(self, varagin=None): if x > 0: for i in varagin: value[i] = self.msx.MSXgetpatternlen(i) - return value + output = list(value.values()) + return output def getMSXPattern(self): + """ Retrieves the time patterns. + + Example: + d = epanet('net2-cl2.inp'); + d.loadMSXFile('net2-cl2.msx'); + d.addMSXPattern('P1', [1.0 0.0 1.0]); + d.addMSXPattern('P2', [1.0 0.0 1.0]); + d.addMSXPattern('P3', [0.0 1.0 2.0]); + d.addMSXPattern('P4', [1.0 2.0 2.5]); + patterns = d.getMSXPattern() Retrieves all the patterns. + + + See also setMSXPattern, setMSXPatternMatrix, setMSXPatternValue, + getMSXPatternsIndex, getMSXPatternsNameID,.""" z = self.getMSXPatternsCount() if z == 0 : return val = self.getMSXPatternsLengths() - y = [value for value in val.values()] + y = val tmpmaxlen = max(y) value = [[0]*tmpmaxlen for _ in range(self.getMSXPatternsCount())] for i in range(1, self.getMSXPatternsCount() + 1): z = self.getMSXPatternsLengths([i]) - tmplength = [value for value in z.values()] + tmplength = z for j in range(1, tmplength[0] +1): value[i-1][j-1] = self.msx.MSXgetpatternvalue(i, j) if tmplength[0] < tmpmaxlen: @@ -11449,6 +11768,18 @@ def getMSXPattern(self): return value def getMSXSpeciesType(self, varagin=None): + """ Retrieves the species' type. + + Example: + d = epanet('net3-bio.inp'); + d.loadMSXFile('net3-bio.msx'); + d.getMSXSpeciesType Retrieves the type of all the species. + d.getMSXSpeciesType{1} Retrieves the type of the first specie. + d.getMSXSpeciesType{[5,7]} Retrieves the type of the 5th and 7th specie. + + See also getMSXSpeciesIndex, getMSXSpeciesCount, getMSXSpeciesConcentration, + getMSXSpeciesnameID, getMSXSpeciesUnits, getMSXSpeciesATOL, + getMSXSpeciesRTOL.""" x = self.getMSXSpeciesCount() value = [] @@ -11465,6 +11796,19 @@ def getMSXSpeciesType(self, varagin=None): return value def getMSXSpeciesUnits(self, varagin=None): + """ Retrieves the species' units. + + Example: + d = epanet('net3-bio.inp'); + d.loadMSXFile('net3-bio.msx'); + d.getMSXSpeciesUnits Retrieves the units of all the species. + d.getMSXSpeciesUnits{1} Retrieves the units of the first specie. + d.getMSXSpeciesUnits{[1,16]} Retrieves the units of the species with + indices 1 and 16. + + See also getMSXSpeciesIndex, getMSXSpeciesCount, getMSXSpeciesConcentration, + getMSXSpeciesType, getMSXSpeciesNameID, getMSXSpeciesATOL, + getMSXSpeciesRTOL.""" x = self.getMSXSpeciesCount() value = [] @@ -11535,16 +11879,40 @@ def getEquations(self): return Terms, Pipes, Tanks def getMSXEquationsTerms(self): + """ Retrieves equation terms. + + Example: + d = epanet('net2-cl2.inp'); + d.loadMSXFile('net2-cl2.msx'); + d.getMSXEquationsTerms() + + See also getMSXEquationsPipes, getMSXEquationsTanks.""" x, y, z = self.getEquations() x = list(x.values()) return x def getMSXEquationsPipes(self): + """ Retrieves equation for pipes. + + Example: + d = epanet('net2-cl2.inp'); + d.loadMSXFile('net2-cl2.msx'); + d.getMSXEquationsPipes() + + See also getMSXEquationsTerms, getMSXEquationsTanks.""" x, y, z = self.getEquations() y = list(y.values()) return y def getMSXEquationsTanks(self): + """ Retrieves equation for tanks. + + Example: + d = epanet('net2-cl2.inp'); + d.loadMSXfile('net2-cl2.msx'); + d.getMSXEquationsTanks() + + See also getMSXEquationsTerms, getMSXEquationsPipes.""" x, y, z = self.getEquations() z = list(z.values()) return z @@ -11560,6 +11928,17 @@ def getMSXSources(self): return value def getMSXSourceType(self, varagin=None): + """ Retrieves the sources type. + + Example: + d = epanet('net2-cl2.inp'); + d.loadMSXFile('net2-cl2.msx'); + d.getMSXSourceType() Retrieves all the source types. + d.getMSXSourceType{1} Retrieves the first node source type. + d.getMSXSourceType{[1,2]} Retrieves the source type of nodes 1 and 2 + + See also getMSXSources, getMSXSourceNodeNameID + getMSXSourceLevel, getMSXSourcePatternIndex.""" value = [] if varagin == None: for i in range(1, self.getNodeCount() + 1): @@ -11581,6 +11960,18 @@ def getMSXSourceType(self, varagin=None): return source def getMSXSourceLevel(self, varagin=None): + """ Retrieves the sources level. + + Example: + d = epanet('net2-cl2.inp'); + d.loadMSXFile('net2-cl2.msx'); + d.getMSXSourceLevel() Retrieves all the source level. + d.getMSXSourceLevel({1}) Retrieves the first node source level. + d.getMSXSourceLevel([1,5]) Retrieves the source level + of nodes 1 and 5. + + See also getMSXSources, getMSXSourceNodeNameID + getMSXSourceType, getMSXSourcePatternIndex.""" value = [] if varagin == None: for i in range(1, self.getNodeCount() + 1): @@ -11602,6 +11993,17 @@ def getMSXSourceLevel(self, varagin=None): return sourcelevel def getMSXSourcePatternIndex(self, varagin=None): + """ Retrieves the sources pattern index. + + Example: + d = epanet('net2-cl2.inp'); + d.loadMSXFile('net2-cl2.msx'); + d.getMSXSourcePatternIndex() Retrieves all the source pattern index. + d.getMSXSourcePatternIndex({1} ) Retrieves the first node source pattern index. + d.getMSXSourcePatternIndex([1,5]]) Retrieves the source pattern index of nodes 1 and 5 + + See also getMSXSources, getMSXSourceNodeNameID + getMSXSourceType, getMSXSourceLevel.""" value = [] if varagin == None: for i in range(1, self.getNodeCount() + 1): @@ -11623,6 +12025,16 @@ def getMSXSourcePatternIndex(self, varagin=None): return sourcepatternindex def getMSXLinkInitqualValue(self, varagin=None): + """ Retrieves the links initial quality value. + + Example: + d = epanet('net2-cl2.inp'); + d.loadMSXFile('net2-cl2.msx'); + d.getMSXLinkInitqualValue() Retrieves the initial quality of all links. + d.getMSXLinkInitqualValue({1}) Retrieves the initial quality of the first link. + d.getMSXLinkInitqualValue([1,3]) Retrieves the initial quality of 1 and 3. + + See also setMSXLinkInitqualValue.""" value = [] if varagin == None: for i in range(1, self.getLinkCount() + 1): @@ -11641,6 +12053,16 @@ def getMSXLinkInitqualValue(self, varagin=None): return value def getMSXNodeInitqualValue(self, varagin=None): + """ Retrieves the nodes initial quality value. + + Example: + d = epanet('net2-cl2.inp'); + d.loadMSXFile('net2-cl2.msx'); + d.getMSXNodeInitqualValue() Retrieves the initial quality of all nodes. + d.getMSXNodeInitqualValue({1}) Retrieves the initial quality of the first node. + d.getMSXNodeInitqualValue([1,3]) Retrieves the initial quality of one and three. + + See also setMSXNodeInitqualValue.""" value = [] if varagin == None: for i in range(1, self.getNodeCount() + 1): @@ -11659,25 +12081,46 @@ def getMSXNodeInitqualValue(self, varagin=None): return value def getMSXSpeciesATOL(self): + """ Retrieves the species' absolute tolerance. + + Example: + d = epanet('net3-bio.inp'); + d.loadMSXFile('net3-bio.msx'); + d.getMSXSpeciesATOL() + + See also getMSXSpeciesIndex, getMSXSpeciesCount, getMSXSpeciesConcentration, + getMSXSpeciesType, getMSXSpeciesNameID, getMSXSpeciesUnits, + getMSXSpeciesRTOL.""" value = [] for i in range(1, self.getMSXSpeciesCount()): Atol = [] value.append(self.msx.MSXgetspecies(i)) Atol.append([item[2] for item in value]) - return Atol + return Atol[0] def getMSXSpeciesRTOL(self): + """ Retrieves the species' relative accuracy level. + + Example: + d = epanet('net3-bio.inp'); + d.loadMSXFile('net3-bio.msx'); + d.getMSXSpeciesRTOL() + + See also getMSXSpeciesIndex, getMSXSpeciesCount, getMSXSpeciesConcentration, + getMSXSpeciesType, getMSXSpeciesNameID, getMSXSpeciesUnits, + getMSXSpeciesATOL.""" value = [] for i in range(1, self.getMSXSpeciesCount()): Rtol = [] value.append(self.msx.MSXgetspecies(i)) Rtol.append([item[3] for item in value]) - return Rtol + return Rtol[0] def getMSXSpeciesConcentration(self, type, index, species): return self.msx.MSXgetqual(type, index, species) def getMSXSourceNodeNameID(self): + nodes = [] for i in range(1, self.getNodeCount() + 1): source = [] From 9adc57e687e3f989dbf39d4f1f041500db20a2b1 Mon Sep 17 00:00:00 2001 From: ichrys03 <79056704+ichrys03@users.noreply.github.com> Date: Fri, 8 Mar 2024 03:27:34 +0200 Subject: [PATCH 2/3] MSX functions with comments added to the README file --- README.md | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/README.md b/README.md index 5d9afa7..0438730 100644 --- a/README.md +++ b/README.md @@ -515,6 +515,49 @@ If you want to contribute, please check out our [Code of Conduct](https://github |useHydraulicFile|Uses the contents of the specified file as the current binary hydraulics file |writeLineInReportFile|Writes a line of text to the EPANET report file |writeReport|Writes a formatted text report on simulation results to the Report file +| MSX Functions +|loadMSXFile|Opens the EPANET-MSX toolkit system| +|unloadMSX|Closes the EPANET-MSX toolkit system| +|getMSXSourcePatternIndex|Retrieves the value of all node source pattern index| +|getMSXLinkInitqualValue|Retrieves the initial concentration of chemical species assigned to links of the pipe network| +|getMSXNodeInitqualValue|Retrieves the initial concentration of chemical species assigned to nodes| +|getMSXSourceLevel|Retrieves the value of all nodes source level| +|getMSXSourceType|Retrieves the value of all node source type| +|getMSXSpeciesCount|Retrieves the number of species| +|getMSXSpeciesNameID|Retrieves the species IDs| +|getMSXSpeciesIndex|Retrieves the indices of species| +|getMSXSpeciesType|Retrieves the type of all species (BULK/WALL)| +|getMSXSpeciesUnits|Retrieves the species mass units| +|getMSXSpeciesATOL|Retrieves the atol| +|getMSXSpeciesRTOL|Retrieves the rtol| +|getMSXConstantsCount|Retrieves the number of constants| +|getMSXConstantsNameID|Retrieves the ID name of constants (given its internal index number)| +|getMSXConstantsIndex|Retrieves the internal index number of constants (given its ID name)| +|getMSXPattern|Retrieves the multiplier factor for all patterns and all times| +|getMSXPatternsCount|Retrieves the number of patterns| +|getMSXPatternsNameID|Retrieves the patterns IDs| +|getMSXPatternsIndex|Retrieves the indices of patterns| +|getMSXPatternsLengths|Retrieves the number of time periods in all or some patterns| +|getMSXParametersCount|Retrieves the number of parameters| +|getMSXParametersNameID|Retrieves the ID name of parameters| +|getMSXParametersIndex|Retrieves the indices of parameters| +|getMSXParametersPipesValue|Retrieves the value of reaction parameters for pipes| +|getMSXParametersTanksValue|Retrieves the value of reaction parameters for tanks| +|solveMSXCompleteHydraulics|Solves for system hydraulics over the entire simulation period saving results to an internal scratch file| +|solveMSXCompleteQuality|Solves for water quality over the entire simulation period and saves the results to an internal scratch file| +|getMSXError|Returns the text for an error message given its error code| +|getMSXOptions|Retrieves all the msx option parameters| +|getMSXTimeStep|Retrieves the time step| +|getMSXRateUnits|Retrieves the rate/time units (SEC/MIN/HR/DAY)| +|getMSXAreaUnits|Retrieves the area units (FT2/M2/CM2)| +|getMSXCompiler|Retrieves the compiler (NONE/VC/GC)| +|getMSXCoupling|Retrieves the coupling (FULL/NONE)| +|getMSXAtol|Retrieves the absolute concentration tolerance| +|getMSXRtol|Retrieves the relative concentration tolerance| +|getMSXEquationsPipes|Retrieves the species dynamics in pipes| +|getMSXEquationsTanks|Retrieves the species dynamics in tanks| +|getMSXEquationsTerms|Retrieves the species dynamics in terms| + ## List of EPANET 2.2 Functions From 080ca2b8f0ce6ca7b0773ce667b79cc538977223 Mon Sep 17 00:00:00 2001 From: ichrys03 <79056704+ichrys03@users.noreply.github.com> Date: Fri, 15 Mar 2024 14:34:40 +0200 Subject: [PATCH 3/3] additional msx functions --- README.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/README.md b/README.md index 0438730..050a7d0 100644 --- a/README.md +++ b/README.md @@ -518,11 +518,16 @@ If you want to contribute, please check out our [Code of Conduct](https://github | MSX Functions |loadMSXFile|Opens the EPANET-MSX toolkit system| |unloadMSX|Closes the EPANET-MSX toolkit system| +|initializeMSXQualityAnalysis|Initializes the MSX system before solving for water quality results in step-wise fashion| +|stepMSXQualityAnalysisTimeLeft|Advances the water quality solution through a single water quality time step when performing a step-wise simulation| +|saveMSXFile|Saves the data associated with the current MSX project into a new MSX input file| +|saveMSXQualityFile|Saves water quality results computed for each node, link and reporting time period to a named binary file| |getMSXSourcePatternIndex|Retrieves the value of all node source pattern index| |getMSXLinkInitqualValue|Retrieves the initial concentration of chemical species assigned to links of the pipe network| |getMSXNodeInitqualValue|Retrieves the initial concentration of chemical species assigned to nodes| |getMSXSourceLevel|Retrieves the value of all nodes source level| |getMSXSourceType|Retrieves the value of all node source type| +|getMSXSourceNodeNameID|Retrieves the ID label of all nodes| |getMSXSpeciesCount|Retrieves the number of species| |getMSXSpeciesNameID|Retrieves the species IDs| |getMSXSpeciesIndex|Retrieves the indices of species| @@ -530,11 +535,13 @@ If you want to contribute, please check out our [Code of Conduct](https://github |getMSXSpeciesUnits|Retrieves the species mass units| |getMSXSpeciesATOL|Retrieves the atol| |getMSXSpeciesRTOL|Retrieves the rtol| +|getMSXSpeciesConcentration|Retrieves the concentration of chemical species for nodes and links| |getMSXConstantsCount|Retrieves the number of constants| |getMSXConstantsNameID|Retrieves the ID name of constants (given its internal index number)| |getMSXConstantsIndex|Retrieves the internal index number of constants (given its ID name)| |getMSXPattern|Retrieves the multiplier factor for all patterns and all times| |getMSXPatternsCount|Retrieves the number of patterns| +|getMSXPatternValue|Retrieves the multiplier at a specific time period for a given source time pattern| |getMSXPatternsNameID|Retrieves the patterns IDs| |getMSXPatternsIndex|Retrieves the indices of patterns| |getMSXPatternsLengths|Retrieves the number of time periods in all or some patterns| @@ -557,6 +564,28 @@ If you want to contribute, please check out our [Code of Conduct](https://github |getMSXEquationsPipes|Retrieves the species dynamics in pipes| |getMSXEquationsTanks|Retrieves the species dynamics in tanks| |getMSXEquationsTerms|Retrieves the species dynamics in terms| +|setMSXAreaUnitsCM2|Sets area units to CM2| +|setMSXAreaUnitsFT2|Sets area units to FT2| +|setMSXAreaUnitsM2|Sets area units to M2| +|setMSXAtol|Sets the value of Atol| +|setMSXRtol|Sets the value of Rtol| +|setMSXCompilerGC|Sets compilet to GC| +|setMSXCompilerNONE|Sets compiler to None| +|setMSXCompilerVC|Sets compiler to VC| +|setMSXCouplingFULL|Sets coupling option to FULL| +|setMSXCouplingNONE|Sets coupling option to NONE| +|setMSXRateUnitsDAY|Sets rate units to DAY| +|setMSXRateUnitsHR|Sets rate units to HR| +|setMSXRateUnitsMIN|Sets rate units to MIN| +|setMSXRateUnitsSEC|Sets rate units to SEC| +|setMSXSolverEUL|Sets solver to EUL (standard Euler integrator)| +|setMSXSolverRK5|Sets solver to RK5 (Runge-Kutta 5th order integrator)| +|setMSXSolverROS2|Sets solver to ROS2 (2nd order Rosenbrock integrator)| +|setMSXTimeStep|Sets time step| +|setMSXPatternValue|Assigns a new value to the multiplier for a specific time period in a given MSX source time pattern| +|setMSXPattern|Sets all of the multiplier factors for a specific time pattern| +|setMSXConstantsValue|Assigns a new value to a specific reaction constant| +|useMSXHydraulicFile|Uses a previously saved EPANET hydraulics file as the source of hydraulic information| ## List of EPANET 2.2 Functions