Ejemplo n.º 1
0
    def run(self, pressure=True, failure=True, sql_yr_w=5):
        et.ENopenH()
        et.ENinitH(0)

        # Run for two days to create network equilibrium
        time = et.ENrunH()[1]
        while time < 172800:
            et.ENnextH()[1]
            time = et.ENrunH()[1]

        while True:
            if not self.iterate(pressure, failure, sql_yr_w=sql_yr_w):
                et.ENcloseH()
                et.ENclose()
                return
Ejemplo n.º 2
0
 def iterate(self, pressure, failure, sql_yr_w):
     time = et.ENrunH()[1]
     if (time % self.timestep == 0):
         self.current_time = time
         if (self.current_time % 86400 == 0):
             self.current_temp = self.tasmax.temp(self.current_time)
         for node_ in self.nodes:
             node_.save_pressure(self.current_time)
         if (time % (self.year * sql_yr_w)) == 0:
             print("{} year(s) done".format(str(time / self.year)))
             if pressure:
                 self.pressure_to_sql()
             if failure:
                 self.failures_to_sql()
         self.increment_population()
     if et.ENnextH()[1] <= 0:
         print("Simulation Complete.")
         return False
     return True
    ret1, t = et.ENrunH()
    time.append(t)
    # for index in range(1, nnodes+1):
    #     ret, node = et.ENgetnodeid(index)
    #     ret, h = et.ENgetnodevalue(index, et.EN_HEAD)
    #     nodes[node].append(h)

    for node in nodes:
        ret, index = et.ENgetnodeindex(node)
        ret, h = et.ENgetnodevalue(index, et.EN_HEAD)
        ret, p = et.ENgetnodevalue(index, et.EN_PRESSURE)
        nodes[node].append(p+np.random.normal(0,0.2))


    ret, tstep = et.ENnextH()


    # ret, index = et.ENgetnodeindex('C9QPT8LCD6')
    # ret, h = et.ENgetnodevalue(index, et.EN_HEAD)
    #print t,h
    if (tstep <= 0):
        break
ret=et.ENcloseH()

sensorList = ['C92ICY6VWN','CBDWGRJVVL','CAKIJ91SJ7','C9EQAVY4YU']

for node in sensorList:
    pp.plot(time,nodes[node])
pp.plot([LeakStartTime,LeakStartTime],[00,100],'k:')
pp.grid('on')
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
ret = et.ENopen(file_directory, "CTOWN.rpt", "")
es = EPANetSimulation(file_directory)
n = es.network.nodes

junction = 'J193'

pres = []
nodes = []
time = []

et.ENopenH()
et.ENinitH(0)
while True:
    ret, t = et.ENrunH()
    ret, p = et.ENgetnodevalue(n[junction].index, et.EN_PRESSURE)
    print t, p
    ret, t_step = et.ENnextH()
    if t % 3600 == 0:
        time.append(t / 3600)
        pres.append(p)
    if t_step <= 0:
        break

et.ENcloseH()

plt.plot(time, pres)
plt.grid()
plt.xlabel('Time (hr)')
plt.ylabel('Pressure (psi)')
plt.show()
Ejemplo n.º 6
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])