def get_state(self, parameter, element_id): """ get a state from the network simulation :param parameter: i.e., pressure, status, flow, level, head, etc... :param element_id: the name of the element :return: the state (real/double) """ node_states = { 'pressure': toolkit.PRESSURE, 'demand': toolkit.DEMAND, 'head': toolkit.HEAD, 'level': toolkit.TANKLEVEL, 'quality': toolkit.QUALITY, 'emitter': toolkit.EMITTER } link_states = {'flow': toolkit.FLOW, 'velocity': toolkit.VELOCITY} state = None if parameter in node_states: node_idx = toolkit.getnodeindex(self.ph, element_id) state = toolkit.getnodevalue(self.ph, node_idx, node_states[parameter]) elif parameter in link_states: link_idx = toolkit.getlinkindex(self.ph, element_id) state = toolkit.getlinkvalue(self.ph, link_idx, link_states[parameter]) return state
def getLinkFlow(self): Q = np.zeros(shape=self.LinkCount) for i in self.LinkIndex: flow = en.getlinkvalue(ph=self.epanet_proj, index=i, property=en.FLOW) Q[i - 1] = flow return Q
def set(self, key, value): k = key.key if isinstance(key, KeyPath) else key idx = toolkit.getlinkindex(self._p, self._l) toolkit.setlinkvalue(self._p, idx, LinkModifier.keys[k], value) if debug: print("set {} to {} -> epanet value is {}".format( key, value, toolkit.getlinkvalue(self._p, idx, LinkModifier.keys[k])))
def getLinkQuality(self): # finds chlorine concentration in links C = np.zeros(shape=self.LinkCount) for i in self.LinkIndex: # print(i) quality = en.getlinkvalue(ph=self.epanet_proj, index=i, property=en.LINKQUAL) # print(quality) C[i - 1] = quality return C
def test_water_quality(): epanet_proj = en.createproject() en.open(ph=epanet_proj, inpFile=example_1_path, rptFile='report.rpt', outFile='output.out') en.setqualtype(ph=epanet_proj, qualType=1, chemName='Chlorine', chemUnits='mg/L', traceNode=None) num_nodes = en.getcount(ph=epanet_proj, object=en.NODECOUNT) num_links = en.getcount(ph=epanet_proj, object=en.LINKCOUNT) tlist = [] node_cl_list = [] link_cl_list = [] en.openH(ph=epanet_proj) en.initH(ph=epanet_proj, initFlag=0) print('Printing hydraulic time step:') while True: en.runH(ph=epanet_proj) t = en.nextH(ph=epanet_proj) print(t) tlist.append(t) if t <= 0: break assert tlist == timesteps en.openQ(ph=epanet_proj) en.initQ(ph=epanet_proj, saveFlag=1) print('Printing chlorine concentration in nodes:') while True: en.runQ(ph=epanet_proj) t = en.nextQ(ph=epanet_proj) for i in range(1, num_nodes+1): node_qual = en.getnodevalue(ph=epanet_proj, index=i, property=en.QUALITY) print('Node %d: %5.2f' % (i, node_qual)) node_cl_list.append(node_qual) if t <= 0: break print('Printing chlorine concentration in links:') while True: en.runQ(ph=epanet_proj) t = en.nextQ(ph=epanet_proj) for i in range(1, num_links+1): link_qual = en.getlinkvalue(ph=epanet_proj, index=i, property=en.QUALITY) print('Node %d: %5.2f' % (i, link_qual)) link_cl_list.append(link_qual) if t <= 0: break en.closeH(ph=epanet_proj) en.closeQ(ph=epanet_proj) en.close(ph=epanet_proj) clean_dir()
def state(self): state = [] # Get number of nodes and links. nodeCount = en.getcount(ph=self.project, object=en.NODECOUNT) linkCount = en.getcount(ph=self.project, object=en.LINKCOUNT) # Enumerate all nodes. for index in range(1,nodeCount+1): # Create state from current values. state.append(en.getnodevalue(ph=self.project, index=index, property=en.TANKLEVEL)) state.append(en.getnodevalue(ph=self.project, index=index, property=en.HEAD)) state.append(en.getnodevalue(ph=self.project, index=index, property=en.DEMAND)) state.append(en.getnodevalue(ph=self.project, index=index, property=en.PRESSURE)) for index in range(1,linkCount+1): state.append(en.getlinkvalue(ph=self.project, index=index, property=en.FLOW)) state.append(en.getlinkvalue(ph=self.project, index=index, property=en.VELOCITY)) state.append(en.getlinkvalue(ph=self.project, index=index, property=en.HEADLOSS)) state.append(en.getlinkvalue(ph=self.project, index=index, property=en.STATUS)) state.append(en.getlinkvalue(ph=self.project, index=index, property=en.PUMP_STATE)) state.append(en.getlinkvalue(ph=self.project, index=index, property=en.ENERGY)) return state
def test_hydraulic(): epanet_proj = en.createproject() en.open(ph=epanet_proj, inpFile=example_1_path, rptFile='report.rpt', outFile='output.out') en.openH(ph=epanet_proj) en.initH(ph=epanet_proj, initFlag=0) num_nodes = en.getcount(ph=epanet_proj, object=en.NODECOUNT) num_links = en.getcount(ph=epanet_proj, object=en.LINKCOUNT) tlist = [] head_list = [] demand_list = [] flow_list = [] length_list = [] diam_list = [] vel_list = [] print('Printing hydraulic time step:') while True: en.runH(ph=epanet_proj) t = en.nextH(ph=epanet_proj) print(t) tlist.append(t) if t <= 0: break assert tlist == timesteps print('Printing demand in nodes:') for node_ind in range(1, num_nodes+1): en.runH(ph=epanet_proj) demand = en.getnodevalue(ph=epanet_proj, index=node_ind, property=en.BASEDEMAND) print('Node %d: %5.2f' % (node_ind, demand)) demand_list.append(demand) print('Printing head in nodes:') for node_ind in range(1, num_nodes+1): en.runH(ph=epanet_proj) head = en.getnodevalue(ph=epanet_proj, index=node_ind, property=en.HEAD) print('Node %d: %5.2f' % (node_ind, head)) head_list.append(head) print('Printing flowrate in links:') for link_ind in range(1, num_links+1): en.runH(ph=epanet_proj) flow = en.getlinkvalue(ph=epanet_proj, index=link_ind, property=en.FLOW) print('Link %d: %5.2f' % (link_ind, flow)) flow_list.append(flow) print('Printing length of links:') for link_ind in range(1, num_links+1): en.runH(ph=epanet_proj) length = en.getlinkvalue(ph=epanet_proj, index=link_ind, property=en.LENGTH) print('Link %d: %5.2f' % (link_ind, length)) length_list.append(length) print('Printing diameter of links:') for link_ind in range(1, num_links+1): en.runH(ph=epanet_proj) diam = en.getlinkvalue(ph=epanet_proj, index=link_ind, property=en.DIAMETER) print('Link %d: %5.2f' % (link_ind, diam)) diam_list.append(diam) print('Printing velocity in links:') for link_ind in range(1, num_links+1): en.runH(ph=epanet_proj) vel = en.getlinkvalue(ph=epanet_proj, index=link_ind, property=en.VELOCITY) print('Link %d: %5.2f' % (link_ind, vel)) vel_list.append(vel) en.closeH(ph=epanet_proj) en.close(ph=epanet_proj) clean_dir()
def __call__(self, time): self._cw.writerow([time] + [ en.getlinkvalue(self._ph, i, self._link_value) for i in self._link_range ])