示例#1
0
def getID(network_object, object_index):  # ! Sredjeno - TESTIRATI -> RADI
    """
        :param  network_object: string - 'node' ili 'link'
        :param  object_index  : int - index objekta
        :return               : string - vraca ID objekta .

        :info:
        EPANET broji od 1(jedinice) ne kao Python od 0(nule),
        ovo je vazno ukoliko koristimo range f-ju, pisemo range(1,...),
        ne range(0,...).

        :Primer:
        Ukoliko hocemo da dobijemo listu `node` ID-eva, sledi code:
        map(lambda x: getID('node', x), lista_indeksa)
        ili
        [getID('node', i) for i in lista_indeksa]
        Isto je za `link` ID-eve.

    """
    object_id = {
        'node': epa.ENgetnodeid(object_index)[1],
        'link': epa.ENgetlinkid(object_index)[1]
    }

    return object_id[network_object]
示例#2
0
    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
示例#4
0
def generatePriorDist():
    PriorDist = priorDistributon()
    PriorDist.pred_values = 0
    PriorDist.pred_variance = 0
    PriorDist.prior_values = 0
    PriorDist.prior_variance = 100
    PriorDist.node_id = []
    errcode = et.ENopen(Inp, "BUFF.rpt", "")
    for i in range(DEMAND_NUM):
        [errcode, id] = et.ENgetnodeid(i + 1)
        PriorDist.node_id.append(id)
    errcode = et.ENclose()

    return PriorDist
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
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)
#h=Node.value_type['EN_HEAD']
LeakNodes = ['CA81W6J9C0','CBEA1QV88R','CAFPFW92WV','CADXK24N13']
示例#7
0
 def get_id(self):
     self.id_ = et.ENgetnodeid(self.index)[1]
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(
        i, epa.EN_PRESSURE)  ## getting the nodal pressure results
    ret, Demand = epa.ENgetnodevalue(
        i, epa.EN_DEMAND)  ## getting the nodal demand results

    Heads[
        index] = H0  ## putting the nodal head results into the heads dictionary
    Pressures[
        index] = P0  ## putting the nodal pressure results into the pressures dictionary
    Demands[
        index] = Demand  ## putting the nodal demand results into the demands dictionary
示例#9
0
 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])