def getIndex(network_object, id_objekta): # ! Sredjeno - TESTIRATI -> RADI """ :param network_object: string - 'node' ili 'link' :param id_objekta : string - ID objekta :return : int - vraca broj index-a . :info: EPANET broji od 1(jedinice) ne kao Python od 0(nule), ovo je vazno ukoliko koristimo npr. range f-ju u `Python`, pisemo range(1,...), ne range(0,...). :Primer: Ukoliko hocemo da dobijemo listu NODE-Index-a, sledi code: map(lambda x: getIndex('node', x), lista_id-eva) ili [getIndex('node', i) for i in lista_id-eva] Isto je za LINK-ove... """ object_index = { 'node': epa.ENgetnodeindex(id_objekta)[1], 'link': epa.ENgetlinkindex(id_objekta)[1] } return object_index[network_object]
def setDiameter(id,value): errcode=et.ENopen(Inp,"BUFF.rpt","") [errcode,index]=et.ENgetlinkindex(id) # [errcode,diameter]=et.ENgetlinkvalue(index,et.EN_DIAMETER) et.ENsetlinkvalue(index,et.EN_DIAMETER,value) errcode=et.ENsaveinpfile(InpCopy) errcode=et.ENclose()
def getResidulSqure_EPA(MeaData): errcode = et.ENopen(ResultInp, "BUFF.rpt", "") errcode = et.ENsolveH() ResidulSqure = {} ResidulSqure['Res'] = {} ResidulSqure['P'] = {} ResidulSqure['F'] = {} residul = [] for id in ResID: [errcode, index] = et.ENgetnodeindex(id) [errcode, value] = et.ENgetnodevalue(index, et.EN_DEMAND) ResidulSqure['Res'][id] = (value - MeaData.Data['Res'][id])**2 residul.append(value - MeaData.Data['Res'][id]) for id in PreID: [errcode, index] = et.ENgetnodeindex(id) [errcode, value] = et.ENgetnodevalue(index, et.EN_PRESSURE) ResidulSqure['P'][id] = (value - MeaData.Data['P'][id])**2 residul.append(value - MeaData.Data['P'][id]) for id in FloID: [errcode, index] = et.ENgetlinkindex(id) [errcode, value] = et.ENgetlinkvalue(index, et.EN_FLOW) ResidulSqure['F'][id] = (value - MeaData.Data['F'][id])**2 residul.append(value - MeaData.Data['F'][id]) errcode = et.ENclose() return [ResidulSqure, residul]
def updateResult(self): self.hyd_simulation() #########update the calibrated value at sensors######### Res = {} P = {} F = {} for id in self.sensorID_Res: [errcode, index] = et.ENgetnodeindex(id) [errcode, demand] = et.ENgetnodevalue(index, et.EN_DEMAND) Res[id] = demand for id in self.sensorID_P: [errcode, index] = et.ENgetnodeindex(id) [errcode, pressure] = et.ENgetnodevalue(index, et.EN_PRESSURE) P[id] = pressure for id in self.sensorID_F: [errcode, index] = et.ENgetlinkindex(id) [errcode, flow] = et.ENgetlinkvalue(index, et.EN_FLOW) F[id] = flow self.cali_sensor['Res'] = Res self.cali_sensor['P'] = P #Save the simulated sensor pressure self.cali_sensor['F'] = F #Save the simulated sensor flow #########update the calibrated nodal pressure and pipe flow rate######### for index in range(self.demand_dim): [errcode, pressure] = et.ENgetnodevalue(index + 1, et.EN_PRESSURE) self.cali_nodal_p.append(pressure) for index in range(Number_PIPES): [errcode, flow] = et.ENgetlinkvalue(index + 1, et.EN_FLOW) self.cali_pipe_f.append(flow) self.getResidul()
def getResidulSqure_EPA(MeaData): errcode = et.ENopen(ResultInp, "BUFF.rpt", "") errcode = et.ENsolveH() ResidulSqure = {} ResidulSqure['Res'] = {} ResidulSqure['P'] = {} ResidulSqure['F'] = {} print_R_RES = 0 print_R_Pre = 0 print_R_Flo = 0 residul = [] for id in MeaData.ResID: [errcode, index] = et.ENgetnodeindex(id) [errcode, value] = et.ENgetnodevalue(index, et.EN_DEMAND) ResidulSqure['Res'][id] = (value - MeaData.Data['Res'][id])**2 print_R_RES = print_R_RES + ResidulSqure['Res'][id] residul.append(value - MeaData.Data['Res'][id]) if (len(MeaData.ResID) > 0): print_R_RES = print_R_RES / len(MeaData.ResID) for id in MeaData.PreID: [errcode, index] = et.ENgetnodeindex(id) [errcode, value] = et.ENgetnodevalue(index, et.EN_PRESSURE) ResidulSqure['P'][id] = (value - MeaData.Data['P'][id])**2 print_R_Pre = print_R_Pre + ResidulSqure['P'][id] residul.append(value - MeaData.Data['P'][id]) if (len(MeaData.PreID) > 0): print_R_Pre = print_R_Pre / len(MeaData.PreID) for id in MeaData.FloID: [errcode, index] = et.ENgetlinkindex(id) [errcode, value] = et.ENgetlinkvalue(index, et.EN_FLOW) ResidulSqure['F'][id] = (value - MeaData.Data['F'][id])**2 print_R_Flo = print_R_Flo + ResidulSqure['F'][id] residul.append(value - MeaData.Data['F'][id]) if (len(MeaData.FloID) > 0): print_R_Flo = print_R_Flo / len(MeaData.FloID) errcode = et.ENclose() print('ave Squre error: Res Flo Pre') print(' ' + str(print_R_RES) + ' ' + str(print_R_Flo) + ' ' + str(print_R_Pre)) return [ResidulSqure, residul]
def getSensorValue(self): self.hyd_simulation() Res = {} P = {} F = {} for id in self.sensorID_Res: [errcode, index] = et.ENgetnodeindex(id) [errcode, demand] = et.ENgetnodevalue(index, et.EN_DEMAND) Res[id] = demand for id in self.sensorID_P: [errcode, index] = et.ENgetnodeindex(id) [errcode, pressure] = et.ENgetnodevalue(index, et.EN_PRESSURE) P[id] = pressure for id in self.sensorID_F: [errcode, index] = et.ENgetlinkindex(id) [errcode, flow] = et.ENgetlinkvalue(index, et.EN_FLOW) F[id] = flow self.measured_sim['Res'] = Res self.measured_sim['P'] = P #Save the simulated sensor pressure self.measured_sim['F'] = F #Save the simulated sensor flow
def updateResult(self, ResultInp): errcode = et.ENopen(ResultInp, 'r.rtp', '') errcode = et.ENsolveH() #########update the calibrated value at sensors######### Res = {} P = {} F = {} for id in self.sensorID_Res: [errcode, index] = et.ENgetnodeindex(id) [errcode, demand] = et.ENgetnodevalue(index, et.EN_DEMAND) Res[id] = demand for id in self.sensorID_P: [errcode, index] = et.ENgetnodeindex(id) [errcode, pressure] = et.ENgetnodevalue(index, et.EN_PRESSURE) P[id] = pressure for id in self.sensorID_F: [errcode, index] = et.ENgetlinkindex(id) [errcode, flow] = et.ENgetlinkvalue(index, et.EN_FLOW) F[id] = flow self.cali_sensor['Res'] = Res self.cali_sensor['P'] = P #Save the simulated sensor pressure self.cali_sensor['F'] = F #Save the simulated sensor flow #########update the calibrated nodal pressure and pipe flow rate######### self.cali_demand_values = [] self.cali_nodal_p = [] #需要初始化 self.cali_pipe_f = [] for index in range(self.demand_dim): [errcode, pressure] = et.ENgetnodevalue(index + 1, et.EN_PRESSURE) self.cali_nodal_p.append(pressure) [errcode, demand] = et.ENgetnodevalue(index + 1, et.EN_DEMAND) self.cali_demand_values.append(demand) for index in range(Number_PIPES): [errcode, flow] = et.ENgetlinkvalue(index + 1, et.EN_FLOW) self.cali_pipe_f.append(flow) errcode = et.ENclose()