def populate(self, conf: ComponentConfig, node_types=[et.EN_JUNCTION], thresholds=(20, 40), motor_repair=25200, elec_repair=14400, pipe_repair=316800): for i in range(1, et.ENgetcount(et.EN_NODECOUNT)[1] + 1): self.nodes.append(Node(i)) # self.nodes.append(Node(i, # self.years, # thresholds[0], # thresholds[1])) for i in range(1, et.ENgetcount(et.EN_LINKCOUNT)[1] + 1): link_type = et.ENgetlinktype(i)[1] if link_type in [et.EN_PIPE, et.EN_CVPIPE]: rough = et.ENgetlinkvalue(i, et.EN_ROUGHNESS)[1] if rough > 140: self.pipes.append(Pipe(i, self.timestep, LinkType('iron'))) self.pipes[-1].exp = Exposure(*conf.exp_vals("iron", i)) else: self.pipes.append(Pipe(i, self.timestep, LinkType('pvc'))) self.pipes[-1].exp = Exposure(*conf.exp_vals("pvc", i)) self.pipes[-1].status = Status(pipe_repair) elif link_type == et.EN_PUMP: self.pumps.append(Pump(i, self.timestep, LinkType('pump'))) self.pumps[-1].exp_elec = Exposure(*conf.exp_vals("elec", i)) self.pumps[-1].exp_motor = Exposure(*conf.exp_vals("motor", i)) self.pumps[-1].status_elec = Status(elec_repair) self.pumps[-1].status_motor = Status(motor_repair)
def read_results_from_epanet(self): #### Returning the head solutions (for the first time step, the only one accessible at the moment) ret, no_nodes = epa.ENgetcount(epa.EN_NODECOUNT) print 'Number of NODES in results file', no_nodes for index in range(1, no_nodes + 1): ret, idx = epa.ENgetnodeid(index) ret, H0 = epa.ENgetnodevalue(index, epa.EN_HEAD) ret, P0 = epa.ENgetnodevalue(index, epa.EN_PRESSURE) ret, Demand = epa.ENgetnodevalue(index, epa.EN_DEMAND) try: #print Network.node_idx[idx].Name,idx #if self.node_idx[idx].type == 'Node': self.node_idx[idx].H_0 = float(H0) self.node_idx[idx].P_0 = float(P0) self.node_idx[idx].TranH = [float(H0)] self.node_idx[idx].demand = float(Demand) / 1000. except: print 'Problem getting Head for Node:', idx continue #### Returning the flow solutions (for the first time step, the only one accessible at the moment) ret, no_links = epa.ENgetcount(epa.EN_LINKCOUNT) print 'Number of LINKS in results file', no_links for index in range(1, no_links + 1): ret, idx = epa.ENgetlinkid(index) ret, Q0 = epa.ENgetlinkvalue(index, epa.EN_FLOW) ret, V0 = epa.ENgetlinkvalue(index, epa.EN_VELOCITY) ret, Headloss = epa.ENgetlinkvalue(index, epa.EN_HEADLOSS) ret, Length = epa.ENgetlinkvalue(index, epa.EN_LENGTH) ret, Diameter = epa.ENgetlinkvalue(index, epa.EN_DIAMETER) ret, Roughness = epa.ENgetlinkvalue(index, epa.EN_ROUGHNESS) #print Headloss,Length,Diameter,V0 #print 2*9.81*(Headloss/1000.)*Diameter / (Length * V0**2) try: self.link_idx[idx].Q_0 = float(Q0) / 1000. #Convert to m^3/s except: print 'Problem getting Flow or Velocity for link:', idx try: self.link_idx[idx].V_0 = float(V0) except: print 'Problem getting Velocity for link:', idx try: self.link_idx[idx].FF_0 = float(2 * 9.81 * (Headloss / 1000.) * Diameter / (Length * V0**2)) except: print 'Problem getting FF_0 for link:', idx try: self.link_idx[idx].roughness = Roughness except: print 'Problem getting Roughness for link:', idx try: self.link_idx[idx].headloss = Headloss except: print 'Problem getting Headloss for link:', idx
def Import_EPANet_Results(self): ret = epa.ENopen(self.filename, self.filename[:-3] + 'rep', self.filename[:-3] + 'out') #print ret #### Opening the hydraulics results ret = epa.ENopenH() #print ret ret = epa.ENinitH(0) #print ret #### Running the Hydraulics Solver epa.ENrunH() #### Returning the head solutions (for the first time step, the only one accessible at the moment) ## Only need to do this for the node elements at the moment as reservoirs don't change ret, no_nodes = epa.ENgetcount(epa.EN_NODECOUNT) print 'Number of NODES in results file', no_nodes for index in range(1, no_nodes + 1): ret, idx = epa.ENgetnodeid(index) ret, H0 = epa.ENgetnodevalue(index, epa.EN_HEAD) try: #print Network.node_idx[idx].Name,idx if self.node_idx[idx].type == 'Node': self.node_idx[idx].H_0 = float(H0) self.node_idx[idx].TranH = [float(H0)] except: print 'Problem getting Head for Node:', idx continue #### Returning the flow solutions (for the first time step, the only one accessible at the moment) ret, no_links = epa.ENgetcount(epa.EN_LINKCOUNT) print 'Number of LINKS in results file', no_links for index in range(1, no_links + 1): ret, idx = epa.ENgetlinkid(index) ret, Q0 = epa.ENgetlinkvalue(index, epa.EN_FLOW) ret, V0 = epa.ENgetlinkvalue(index, epa.EN_VELOCITY) ret, Headloss = epa.ENgetlinkvalue(index, epa.EN_HEADLOSS) ret, Length = epa.ENgetlinkvalue(index, epa.EN_LENGTH) ret, Diameter = epa.ENgetlinkvalue(index, epa.EN_DIAMETER) #print Headloss,Length,Diameter,V0 #print 2*9.81*(Headloss/1000.)*Diameter / (Length * V0**2) try: self.link_idx[idx].Q_0 = float(Q0) / 1000. #Convert to m^3/s self.link_idx[idx].V_0 = float(V0) self.link_idx[idx].FF_0 = float(2 * 9.81 * (Headloss / 1000.) * Diameter / (Length * V0**2)) #self.link_idx[idx].R = float((Headloss/1000.) / (np.pi*Diameter/4. * Length * V0)) except: print 'Problem getting Flow or Velocity for link:', idx continue
def getCount(network_object): # ! Sredjeno - TESTIRATI -> RADI """ :param network_object: string - 'node' ili 'link' :return : int - broj objekata(node ili link) u mrezi :info: node-objekti: junctions(cvorovi), reservoirs(izvori, ponori), tanks(rezervoari). link-objekti: pipes(cevi), pumps(pumpe), valves(zatvaraci) """ number_of_objects = { 'node': epa.ENgetcount(epa.EN_NODECOUNT)[1], 'link': epa.ENgetcount(epa.EN_LINKCOUNT)[1] } return number_of_objects[network_object]
def Import_EPANet_Results(inp_filename, Network=None): if Network == None: Network = Import_EPANet_Geom(inp_filename) ret = epa.ENopen(inp_filename, inp_filename[:-3] + 'rep', inp_filename[:-3] + 'out') #### Opening the hydraulics results err(epa.ENopenH()) err(epa.ENinitH(0)) #### Running the Hydraulics Solver epa.ENrunH() #### Returning the head solutions (for the first time step, the only one accessible at the moment) ret, no_nodes = epa.ENgetcount(epa.EN_NODECOUNT) for index in range(1, no_nodes): ret, idx = epa.ENgetnodeid(index) ret, H0 = epa.ENgetnodevalue(index, epa.EN_HEAD) try: #print Network.node_idx[idx].Name,idx Network.node_idx[idx].H_0 = H0 except: print 'Problem getting Head for Node:', idx continue #### Returning the flow solutions (for the first time step, the only one accessible at the moment) ret, no_links = epa.ENgetcount(epa.EN_LINKCOUNT) for index in range(1, no_nodes): ret, idx = epa.ENgetlinkid(index) ret, Q0 = epa.ENgetlinkvalue(index, epa.EN_FLOW) ret, V0 = epa.ENgetlinkvalue(index, epa.EN_VELOCITY) try: Network.link_idx[idx].Q_0 = Q0 Network.link_idx[idx].V_0 = V0 except: print 'Problem getting Flow or Velocity for link:', idx continue
import csv from epanettools.epanettools import EPANetSimulation, Node, Link, Network, Nodes,Links, Patterns, Pattern, Controls, Control from epanettools import epanet2 as et Directory = 'Projects/Xu_Leak_Detection/' # FileName = '250701 K709vs2-Export.inp' FileName = 'ExampleNetwork1.inp' FileName = 'LeakTestNet.inp' ret=et.ENopen(Directory+FileName,Directory + 'Temp.rpt',"") et.ENopenH() et.ENinitH(0) time=[] nodes={} ret,nnodes=et.ENgetcount(et.EN_NODECOUNT) for index in range(1,nnodes+1): ret,t=et.ENgetnodeid(index) nodes[t] = [] for index in range(1,nnodes): ret,d = et.ENgetnodevalue(index,et.EN_BASEDEMAND) if d == 0.0: Pete = np.random.randint(1, 6) #if Pete == 1: ret1 = et.ENsetnodevalue(index, et.EN_PATTERN, 1) ret2 = et.ENsetnodevalue(index,et.EN_BASEDEMAND,300.0) #Net = EPANetSimulation(Directory+FileName,pdd=False)
""" hidraulic simulation realm """ import os from epanettools import epanet2 as et from epanettools.examples import simple file = os.path.join(os.path.dirname(simple.__file__),'Net3.inp') ret=et.ENopen(file,"Net3.rpt","") #Basic properties of the network ret,result=et.ENgetcount(et.EN_LINKCOUNT) print(ret) print(result) ret,result=et.ENgetcount(et.EN_NODECOUNT) print(ret) print(result) node='10' ret,index=et.ENgetnodeindex(node) print(ret) print ("Node " + node + " has index : " + str(index)) #Get the list of nodes ret,nnodes=et.ENgetcount(et.EN_NODECOUNT) retl,nlinks=et.ENgetcount(et.EN_LINKCOUNT) links=[]
def getValue(network_object, object_property, object_index=''): # ! Sredjeno - TESTIRATI -> RADI """ :param network_object : string - 'node' ili 'link' :param object_property : parametar u vidu velicine koju trazimo, pogledaj dole listu parametara za oredjene objekte. :param object_index = '' : int - index objekta, ako ne unesemo broj index-a objekta, izbacuje vrednosti za sve objekte :return : vraca velicinu(e), u zaviasnosti od unetog `object_index` parametra, NODE-a ili LINK-a *node - properties* epa.EN_PRESSURE - pritisak u cvoru epa.EN_HEAD - piezometrijska kota epa.EN_ELEVATION - apsolutna kota cvora epa.EN_BASEDEMAND - potreba za vodom u cvoru itd. pogledaj EPANET-Toolkit-PDF-fajl *link - properties* epa.EN_FLOW - protok u cevi epa.EN_VELOCITY - brzina vode u cevi epa.EN_INITSTATUS - inicijalni status (Open ili Closed) epa.EN_DIAMETER - precnik cevi itd. pogledaj EPANET-Toolkit-PDF-fajl :info: Vremenski korak podesen je na 1h tj. 3600s !!! """ count_param = {'link': epa.EN_LINKCOUNT, 'node': epa.EN_NODECOUNT} # Provera da li smo ubacili index objekta. if type(object_index) == int: nobjects = 1 else: nobjects = epa.ENgetcount(count_param[network_object])[1] # Lista indeksa objekata u mrezi objects = [] object_value = [] id_fun = {'link': epa.ENgetlinkid, 'node': epa.ENgetnodeid} if type(object_index) == int: objects.append(object_index) else: for index in range(1, nobjects + 1): t = id_fun[network_object](index)[1] objects.append(t) object_value.append([]) value_fun = {'link': epa.ENgetlinkvalue, 'node': epa.ENgetnodevalue} # ** Hidraulicki Proracun ** # Hidraulicki proracun zapocinjemo ovim dvema f-jama. epa.ENopenH() epa.ENinitH(0) time = [] while True: t = epa.ENrunH()[1] # Ovaj deo je ubacen kao korekcija jer se javlja BUG u source_code-u # Ako je tstep != 3600, petlja ga preskoci, u suprotnom imamo visak podataka! if t % 3600 == 0: time.append(t) # Ako trazimo vrednosti samo jednog objekta if nobjects == 1: # Retrieve hydraulic results for time t # posto EPAnet broji od jedan moramo da uvecamo indeks za 1! p = value_fun[network_object](object_index, object_property)[1] object_value.append(p) # Vremenski Korak - u nasem slucaju svakih = 3600s tstep = epa.ENnextH()[1] # Ako trazimo vrednosti za celu mrezu else: # Retrieve hydraulic results for time t for i in range(0, len(objects)): # posto EPAnet broji od jedan moramo da uvecamo indeks za 1! p = value_fun[network_object](i + 1, object_property)[1] object_value[i].append(p) # Vremenski Korak - u nasem slucaju svakih = 3600s tstep = epa.ENnextH()[1] if tstep <= 0: break else: tstep = epa.ENnextH()[1] if tstep <= 0: break continue epa.ENcloseH() # Kraj Hidraulickog proracuna. return object_value
def argmax(Data): Max = max(Data) Directory = 'Projects/SafeStandOff/' ## File location FileName = 'Net2LPS.inp' ## File name FileName = str( input( "Enter EPANET .inp filename (please include full path i.e. /Directory/Filename.inp):" )) open_EPANET(Directory + FileName) ## Opening the file using the epanettools run_EPANET() ## initial run of the epanet file ret, no_nodes = epa.ENgetcount( epa.EN_NODECOUNT) ## Getting the number of nodes in the file Heads = {'Node': 'Head'} ##Initialising a dictionary to store the Head data in Pressures = { 'Node': 'Pressure' } ##Initialising a dictionary to store the Pressure data in Demands = { 'Node': 'Demand' } ##Initialising a dictionary to store the Demand data in for i in range(1, no_nodes + 1): ret, index = epa.ENgetnodeid(i) ## Getting the node name ret, H0 = epa.ENgetnodevalue( i, epa.EN_HEAD) ## getting the nodal head results ret, P0 = epa.ENgetnodevalue(
def test_basic(self): import os from epanettools import epanet2 as et from epanettools.examples import simple file = os.path.join(os.path.dirname(simple.__file__),'Net3.inp') ret=et.ENopen(file,"Net3.rpt","Net3.dat") self.err(et,ret) ret,result=et.ENgetcount(et.EN_LINKCOUNT) # #links assert (result==119) ret,result=et.ENgetcount(et.EN_NODECOUNT) # # nodes assert(result==97) node='105' ret,index=et.ENgetnodeindex(node) # index of node '105' assert(index==12) # print(et.ENgetlinknodes(55)) assert all([i==j for i,j in zip(et.ENgetlinknodes(55),[0,5,46])]) ret,nnodes=et.ENgetcount(et.EN_NODECOUNT) nodes=[] pres=[] time=[] for index in range(1,nnodes): ret,t=et.ENgetnodeid(index) nodes.append(t) t=[] pres.append(t) print(nodes) assert(nodes==['10', '15', '20', '35', '40', '50', '60', '601', '61', '101', '103', '105', '107', '109', '111', '113', '115', '117', '119', '120', '121', '123', '125', '127', '129', '131', '139', '141', '143', '145', '147', '149', '151', '153', '157', '159', '161', '163', '164', '166', '167', '169', '171', '173', '177', '179', '181', '183', '184', '185', '187', '189', '191', '193', '195', '197', '199', '201', '203', '204', '205', '206', '207', '208', '209', '211', '213', '215', '217', '219', '225', '229', '231', '237', '239', '241', '243', '247', '249', '251', '253', '255', '257', '259', '261', '263', '265', '267', '269', '271', '273', '275', 'River', 'Lake', '1', '2']) self.err(et,et.ENopenH()) self.err(et,et.ENinitH(0)) while True : ret,t=et.ENrunH() time.append(t) self.err(et,ret) # Retrieve hydraulic results for time t for i in range(0,len(nodes)): ret,p=et.ENgetnodevalue(i+1, et.EN_PRESSURE ) pres[i].append(p) ret,tstep=et.ENnextH() self.err(et,ret) if (tstep<=0): break ret=et.ENcloseH() print(pres[12]) diffs=[abs(i-j) for i,j in zip(pres[12], [54.085777282714844, 60.99293518066406, 63.03010940551758, 63.56983947753906, 66.80770874023438, 63.989463806152344, 63.49333190917969, 63.895835876464844, 63.440582275390625, 63.90030288696289, 63.43799591064453, 63.438758850097656, 63.03285598754883, 63.005157470703125, 63.1264533996582, 63.40403366088867, 56.72084045410156, 56.622596740722656, 56.47193908691406, 56.478843688964844, 56.27402114868164, 55.576839447021484, 55.0153923034668, 55.81755065917969, 55.200626373291016, 53.8864860534668, 55.024227142333984])] print([i for i in diffs]) assert all([i<1.e-5 for i in diffs])
def alter_epanet_friction_all_same(self, value): ret, no_links = epa.ENgetcount(epa.EN_LINKCOUNT) for index in range(1, no_links + 1): ret, epa.ENsetlinkvalue(index, epa.EN_ROUGHNESS, value)