From 06075c05bfdfc9024d94cb05af1ba481c4ed8f02 Mon Sep 17 00:00:00 2001 From: Manuel Gil Date: Mon, 5 Oct 2020 14:02:44 -0500 Subject: [PATCH 1/4] some bugs solved in the epanet2.py file --- epynet/epanet2.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/epynet/epanet2.py b/epynet/epanet2.py index 2a5ea82..054d46e 100644 --- a/epynet/epanet2.py +++ b/epynet/epanet2.py @@ -381,7 +381,7 @@ def ENgetoption(self, optioncode): EN_TOLERANCE EN_EMITEXPON EN_DEMANDMULT""" - j= ctypes.c_int() + j= ctypes.c_float() #<--- solved: c_int() changed to c_float() ierr= self._lib.EN_getoption(self.ph, optioncode, ctypes.byref(j)) if ierr!=0: raise ENtoolkitError(self, ierr) return j.value @@ -617,7 +617,7 @@ def ENsettimeparam(self, paramcode, timevalue): if ierr!=0: raise ENtoolkitError(self, ierr) - def ENsetoption(self, optioncode, value): + def ENsetoption(self, paramcode, value): #<------------- solved: optioncode changed to paramcode """Sets the value of a particular analysis option. Arguments: From 2a659815da146a8f7f94d9ad8a6fce69117394c0 Mon Sep 17 00:00:00 2001 From: Manuel Gil Date: Wed, 12 May 2021 17:07:30 -0500 Subject: [PATCH 2/4] ENnextH modofied --- epynet/epanet2.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/epynet/epanet2.py b/epynet/epanet2.py index 054d46e..1712c2f 100644 --- a/epynet/epanet2.py +++ b/epynet/epanet2.py @@ -684,13 +684,19 @@ def ENsimtime(self): """retrieves the current simulation time t as datetime.timedelta instance""" return datetime.timedelta(seconds= self._current_simulation_time.value ) - def ENnextH(self): + def ENnextH(self,timestep): """Determines the length of time until the next hydraulic event occurs in an extended period simulation.""" + + sum_steps = 0 _deltat= ctypes.c_long() - ierr= self._lib.EN_nextH(self.ph, ctypes.byref(_deltat)) - if ierr!=0: raise ENtoolkitError(self, ierr) - return _deltat.value + while sum_steps < timestep: + ierr= self._lib.EN_nextH(self.ph, ctypes.byref(_deltat)) + if ierr!=0: + print(f"Error code {ierr}") + return None + sum_steps += _deltat.value + return sum_steps def ENcloseH(self): From 4eeced225e1c410b8bf79fa879cdb13860778121 Mon Sep 17 00:00:00 2001 From: Manuel Gil Date: Wed, 12 May 2021 17:13:21 -0500 Subject: [PATCH 3/4] The ENgetcontrol function is modified to pass parameters by reference using ctype.byref method. The parameters of the control rule are returned, if no errors has occurred. --- epynet/epanet2.py | 51 ++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/epynet/epanet2.py b/epynet/epanet2.py index 1712c2f..c37fec8 100644 --- a/epynet/epanet2.py +++ b/epynet/epanet2.py @@ -352,24 +352,31 @@ def ENgetqualtype(self, qualcode): #-------Retrieving other network information-------- - def ENgetcontrol(self, cindex, ctype, lindex, setting, nindex, level ): + def ENgetcontrol(self, cindex): """Retrieves the parameters of a simple control statement. Arguments: cindex: control statement index - ctype: control type code EN_LOWLEVEL (Low Level Control) - EN_HILEVEL (High Level Control) - EN_TIMER (Timer Control) - EN_TIMEOFDAY (Time-of-Day Control) - lindex: index of link being controlled - setting: value of the control setting - nindex: index of controlling node - level: value of controlling water level or pressure for level controls - or of time of control action (in seconds) for time-based controls""" - #int ENgetcontrol(int cindex, int* ctype, int* lindex, float* setting, int* nindex, float* level ) - ierr= self._lib.EN_getcontrol(self.ph, ctypes.c_int(cindex), ctypes.c_int(ctype), - ctypes.c_int(lindex), ctypes.c_float(setting), - ctypes.c_int(nindex), ctypes.c_float(level) ) - if ierr!=0: raise ENtoolkitError(self, ierr) + + returns ctype: control type code: + EN_LOWLEVEL (Low Level Control) + EN_HILEVEL (High Level Control) + EN_TIMER (Timer Control) + EN_TIMEOFDAY (Time-of-Day Control) + lindex: index of link being controlled + setting: value of the control setting + nindex: index of controlling node + level: value of controlling water level or pressure for level controls + or of time of control action (in seconds) for time-based controls + """ + type_ = ctypes.c_int() + lindex = ctypes.c_int() + setting = ctypes.c_float() + nindex = ctypes.c_int() + level = ctypes.c_float() + ierr = self._lib.EN_getcontrol(self.ph, ctypes.c_int(cindex), ctypes.byref(type_), ctypes.byref(lindex), + ctypes.byref(setting), ctypes.byref(nindex),ctypes.byref(level), ctypes.byref(level)) + if ierr!=0: raise ENtoolkitError(self,ierr) + return type_.value,lindex.value, setting.value, nindex.value, level.value def ENgetoption(self, optioncode): @@ -684,19 +691,13 @@ def ENsimtime(self): """retrieves the current simulation time t as datetime.timedelta instance""" return datetime.timedelta(seconds= self._current_simulation_time.value ) - def ENnextH(self,timestep): + def ENnextH(self): """Determines the length of time until the next hydraulic event occurs in an extended period simulation.""" - - sum_steps = 0 _deltat= ctypes.c_long() - while sum_steps < timestep: - ierr= self._lib.EN_nextH(self.ph, ctypes.byref(_deltat)) - if ierr!=0: - print(f"Error code {ierr}") - return None - sum_steps += _deltat.value - return sum_steps + ierr= self._lib.EN_nextH(self.ph, ctypes.byref(_deltat)) + if ierr!=0: raise ENtoolkitError(self, ierr) + return _deltat.value def ENcloseH(self): From c4f117ab1b655f4b583d61c868e0c89542c8afb1 Mon Sep 17 00:00:00 2001 From: Manuel Gil Date: Wed, 12 May 2021 17:25:40 -0500 Subject: [PATCH 4/4] Indentation issue fixed (accidentally produced) --- epynet/epanet2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/epynet/epanet2.py b/epynet/epanet2.py index c37fec8..d3f0a49 100644 --- a/epynet/epanet2.py +++ b/epynet/epanet2.py @@ -691,7 +691,7 @@ def ENsimtime(self): """retrieves the current simulation time t as datetime.timedelta instance""" return datetime.timedelta(seconds= self._current_simulation_time.value ) - def ENnextH(self): + def ENnextH(self): """Determines the length of time until the next hydraulic event occurs in an extended period simulation.""" _deltat= ctypes.c_long()