def test_nexth():
    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)
    en.runH(ph=epanet_proj)
    res = en.nextH(ph=epanet_proj)
    en.close(ph=epanet_proj)
    assert res == 3600
    clean_dir()
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 test_inith_runh_nexth():
    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)
    tlist = []
    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
    en.closeH(ph=epanet_proj)
    en.close(ph=epanet_proj)
    assert tlist == timesteps
    clean_dir()
Exemple #4
0
    def simulate(self):
        # Increase duration to run infinite.
        cd = en.gettimeparam(ph=self.project, param=en.DURATION)
        step = en.gettimeparam(ph=self.project, param=en.HYDSTEP)
        en.settimeparam(ph=self.project, param=en.DURATION, value=cd+step)

        th = 1

        try:
            # Run simulation at given time/round.
            en.runH(ph=self.project)
            # Check time left.
            tH = en.nextH(ph=self.project)

        except Exception as e:
            # TODO: do stuff.
            logging.error(str(e))

        if tH <= 0:
            raise ProcessShutdown("Epanet hydraulic simulation shutdown. (Epanet internal time: " + str(ct) + "seconds)")

        # NOTE! Epanet starts at round zero.
        super().simulate()
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 runHydraulicAnalysis(self):
     en.runH(ph=self.epanet_proj)
Exemple #7
0
    print(f'Node count: {node_count}, link count: {link_count}')

    with contextlib.ExitStack() as ctx_stack:
        nodevalue_wrts = [
            ctx_stack.enter_context(NodeValueCSVWriter(fn, ph, nv))
            for nv, fn in nodevalue_filename_list
        ]
        linkvalue_wrts = [
            ctx_stack.enter_context(LinkValueCSVWriter(fn, ph, lv))
            for lv, fn in linkvalue_filename_list
        ]

        ## Simulation loop
        while True:
            t = en.runH(ph)
            #print(f'time after runH: {t}')

            #print_node_heads(ph, t, node_count)

            tq = en.runQ(ph)
            assert tq == t, f'time after en.runQ ({tq}) != en.runH ({t})'

            for nv_wrt in nodevalue_wrts:
                nv_wrt(t)
            for lv_wrt in linkvalue_wrts:
                lv_wrt(t)

            hstep = en.nextH(ph)
            qstep = en.nextQ(ph)
            #print(f'hstep after nextH: {hstep}')