Exemplo n.º 1
0
def test_CSTR_steadystate():
    dict1 = {
        'Tank': {
            'pollutant': 0,
            'method': 'CSTR',
            'parameters': {
                'k': -0.2,
                'n': 1.0,
                'c0': 10.0
            }
        }
    }
    conc2 = []
    vol = []
    flow = []
    with Simulation("./tests/inps/tank_constantinflow_notreatment.inp") as sim:
        Tank = Nodes(sim)["Tank"]
        for index, step in enumerate(sim):
            v = Tank.volume
            vol.append(v)
            q = Tank.total_inflow
            flow.append(q)
    with Simulation("./tests/inps/tank_constantinflow_notreatment.inp") as sim:
        CS = waterQuality(sim, dict1)
        Tank = Nodes(sim)["Tank"]
        for index, step in enumerate(sim):
            CS.updateWQState_CSTR(index)
            c = Tank.pollut_quality
            conc2.append(c['P1'])
    C_steadystate = dict1['Tank']['parameters']['c0'] / (
        (1 -
         (dict1['Tank']['parameters']['k'] *
          (np.mean(vol) / np.mean(flow))))**dict1['Tank']['parameters']['n'])
    error = (C_steadystate - conc2[-1]) / C_steadystate
    assert error <= 0.03
Exemplo n.º 2
0
def test_EventMeanConc_load():
    dict1 = {
        'Tank': {
            'pollutant': 0,
            'method': 'EventMeanConc',
            'parameters': {
                'C': 5.0
            }
        }
    }
    conc = []
    conc1 = []
    flow = []
    flow1 = []
    with Simulation("./tests/inps/tank_variableinflow_notreatment.inp") as sim:
        EMC = waterQuality(sim, dict1)
        Outfall = Nodes(sim)["Outfall"]
        for step in sim:
            EMC.updateWQState()
            c = Outfall.pollut_quality
            conc.append(c['P1'])
            flow.append(sim._model.getNodeResult("Outfall", 0))
        load = [a * b for a, b in zip(conc, flow)]
        cum_load = np.cumsum(load)
    with Simulation("./tests/inps/tank_variableinflow_emc.inp") as sim:
        Outfall = Nodes(sim)["Outfall"]
        for step in sim:
            c = Outfall.pollut_quality
            conc1.append(c['P1'])
            flow1.append(sim._model.getNodeResult("Outfall", 0))
        load1 = [a * b for a, b in zip(conc1, flow1)]
        cum_load1 = np.cumsum(load1)
    error = (cum_load1[-1] / cum_load[-1]) / cum_load1[-1]
    print(error)
    assert error <= 0.03
Exemplo n.º 3
0
def test_ConstantRemoval_load():
    dict1 = {'Tank': {0: 0.5}}
    conc = []
    conc1 = []
    flow = []
    flow1 = []
    with Simulation("./inps/tank_variableinflow_notreatment.inp") as sim:
        CR = Node_Quality(sim, dict1)
        Outfall = Nodes(sim)["Outfall"]
        for step in sim:
            CR.ConstantRemoval()
            c = Outfall.pollut_quality
            conc.append(c['P1'])
            flow.append(sim._model.getNodeResult("Outfall", 0))
        load = [a * b for a, b in zip(conc, flow)]
        cum_load = np.cumsum(load)
    with Simulation("./inps/tank_variableinflow_constantremoval.inp") as sim:
        Outfall = Nodes(sim)["Outfall"]
        for step in sim:
            c = Outfall.pollut_quality
            conc1.append(c['P1'])
            flow1.append(sim._model.getNodeResult("Outfall", 0))
        load1 = [a * b for a, b in zip(conc1, flow1)]
        cum_load1 = np.cumsum(load1)
    error = (cum_load1[-1] / cum_load[-1]) / cum_load1[-1]
    print(error)
    assert error <= 0.03
Exemplo n.º 4
0
def test_NthOrderReaction_conc():
    dict1 = {
        'Tank': {
            'pollutant': 0,
            'method': 'NthOrderReaction',
            'parameters': {
                'k': 0.01,
                'n': 2.0
            }
        }
    }
    conc = []
    con = []
    with Simulation("./tests/inps/tank_variableinflow_notreatment.inp") as sim:
        NOR = waterQuality(sim, dict1)
        Tank = Nodes(sim)["Tank"]
        for step in sim:
            NOR.updateWQState()
            c = Tank.pollut_quality
            conc.append(c['P1'])
    with Simulation(
            "./tests/inps/tank_variableinflow_nthorderreaction.inp") as sim:
        Tank = Nodes(sim)["Tank"]
        for step in sim:
            co = Tank.pollut_quality
            con.append(co['P1'])
    error = mse(con, conc[1:])
    print(error)
    assert error <= 0.03
Exemplo n.º 5
0
def test_GravitySettling_conc():
    dict1 = {
        'Tank': {
            'pollutant': 0,
            'method': 'GravitySettling',
            'parameters': {
                'k': 0.01,
                'C_s': 10.0
            }
        }
    }
    conc = []
    con = []
    with Simulation("./tests/inps/tank_variableinflow_notreatment.inp") as sim:
        GS = waterQuality(sim, dict1)
        Tank = Nodes(sim)["Tank"]
        for step in sim:
            GS.updateWQState()
            c = Tank.pollut_quality
            conc.append(c['P1'])
    with Simulation(
            "./tests/inps/tank_variableinflow_gravsettling.inp") as sim:
        Tank = Nodes(sim)["Tank"]
        for step in sim:
            co = Tank.pollut_quality
            con.append(co['P1'])
        error = mse(con, conc[1:])
        print(error)
        assert error <= 0.03
Exemplo n.º 6
0
def test_ConstantRemoval_conc():
    dict1 = {
        'Tank': {
            'pollutant': 0,
            'method': 'ConstantRemoval',
            'parameters': {
                'R': 0.5
            }
        }
    }
    conc = []
    con = []
    with Simulation("./tests/inps/tank_variableinflow_notreatment.inp") as sim:
        CR = waterQuality(sim, dict1)
        Tank = Nodes(sim)["Tank"]
        for step in sim:
            CR.updateWQState()
            c = Tank.pollut_quality
            conc.append(c['P1'])
    with Simulation(
            "./tests/inps/tank_variableinflow_constantremoval.inp") as sim:
        Tank = Nodes(sim)["Tank"]
        for step in sim:
            co = Tank.pollut_quality
            con.append(co['P1'])
    error = mse(con, conc[1:])
    print(error)
    assert error <= 0.03
Exemplo n.º 7
0
def test_EventMeanConc_conc():
    dict1 = {
        'Tank': {
            'pollutant': 0,
            'method': 'EventMeanConc',
            'parameters': {
                'C': 5.0
            }
        }
    }
    conc = []
    con = []
    with Simulation("./tests/inps/tank_variableinflow_notreatment.inp") as sim:
        EMC = waterQuality(sim, dict1)
        Tank = Nodes(sim)["Tank"]
        for step in sim:
            EMC.updateWQState()
            c = Tank.pollut_quality
            conc.append(c['P1'])
    with Simulation("./tests/inps/tank_variableinflow_emc.inp") as sim:
        Tank = Nodes(sim)["Tank"]
        for step in sim:
            co = Tank.pollut_quality
            con.append(co['P1'])
    error = mse(con, conc)
    print(error)
    assert error <= 0.03
Exemplo n.º 8
0
def test_CoRemoval_load():
    dict1 = {'Tank': {'pollutant': 1, 'method': 'ConstantRemoval', 'parameters': {'R': 0.15}},\
        'Tank': {'pollutant': 0, 'method': 'CoRemoval', 'parameters': {'R1': 0.75, 'R2': 0.15}}}
    conc = []
    conc1 = []
    flow = []
    flow1 = []
    with Simulation("./tests/inps/tank_variableinflow_notreatment.inp") as sim:
        CO = waterQuality(sim, dict1)
        Outfall = Nodes(sim)["Outfall"]
        for step in sim:
            CO.updateWQState()
            c = Outfall.pollut_quality
            conc.append(c['P1'])
            flow.append(sim._model.getNodeResult("Outfall", 0))
        load = [a * b for a, b in zip(conc, flow)]
        cum_load = np.cumsum(load)
    with Simulation("./tests/inps/tank_variableinflow_coremoval.inp") as sim:
        Outfall = Nodes(sim)["Outfall"]
        for step in sim:
            c = Outfall.pollut_quality
            conc1.append(c['P1'])
            flow1.append(sim._model.getNodeResult("Outfall", 0))
        load1 = [a * b for a, b in zip(conc1, flow1)]
        cum_load1 = np.cumsum(load1)
    error = (cum_load1[-1] / cum_load[-1]) / cum_load1[-1]
    print(error)
    assert error <= 0.03
Exemplo n.º 9
0
def objectivefunctions(filelist, observationdatafile, distancefilename, root):
    """ This function does the same thing as Par_objectivefunctions() with the exception being that it accepts a list
    of strings as an argument and not a string.  This means it is not parallelizable, but still used in the cross-over
    operation to determine which of the guesses is better.

    :param filelist:
    :param observationdatafile:
    :param distancefilename:
    :param root:
    :return:
    """
    global hydrograph, simulation_timestep, sim_time, P_prime
    P_prime = []
    for trialfile in filelist:
        hydrograph = []
        sim_time = []
        with Simulation(trialfile) as sim:
            node_object = Nodes(sim)
            root_location = node_object[root]
            simulation_timestep = time_difference.total_seconds()
            sim.step_advance(simulation_timestep)
            for step in sim:
                sim_time.append(sim.current_time)
                hydrograph.append(root_location.total_inflow)
        objFunc = [
            normalizedpeakerror(),
            normalizedvolumeerror(),
            nashsutcliffe(),
            NED(trialfile)
        ]
        P_prime.append(objFunc)
    return objFunc
Exemplo n.º 10
0
    def __init__(self,depth=5):
        # initialize simulation
        self.sim = Simulation(swmm_inp)  # read input file
        self.control_time_step = 900  # control time step in seconds
        self.sim.step_advance(self.control_time_step)  # set control time step
        node_object = Nodes(self.sim)  # init node object
        self.St1 = node_object["St1"]
        self.St2 = node_object["St2"]
        self.J3 = node_object["J3"]
        self.depth = depth
        self.St1.full_depth = self.depth
        self.St2.full_depth = self.depth
        
        link_object = Links(self.sim)  # init link object
        self.R1 = link_object["R1"]
        self.R2 = link_object["R2"]
    
        self.sim.start()
        if self.sim.current_time == self.sim.start_time:
            self.R1.target_setting = 0.5
            self.R2.target_setting = 0.5
        sim_len = self.sim.end_time - self.sim.start_time
        self.T = int(sim_len.total_seconds()/self.control_time_step)
        self.t = 1
        #print('T=', self.T)        

        self.state = np.asarray([self.St1.depth, self.St2.depth, self.J3.depth, 
                                  self.St1.flooding, self.St2.flooding, self.J3.flooding])
         
        self.action_space = spaces.Box(low=np.array([0,0]),high=np.array([1,1]), dtype=np.float32)
        self.observation_space = spaces.Box(low=0, high = 1000, shape=(len(self.state),),dtype=np.float32)
Exemplo n.º 11
0
def test_links_2():
    with Simulation(MODEL_WEIR_SETTING_PATH) as sim:
        link_names = ["C1", "C1:C2", "C2", "C3"]
        for link in Links(sim):
            assert (link.linkid in link_names)
            link.flow_limit = 10
            assert (link.flow_limit == 10)
Exemplo n.º 12
0
def test_CSTR_load():
    dict1 = {'Tank': {0: [-0.2, 1.0, 0.0]}}
    conc = []
    conc1 = []
    flow = []
    flow1 = []
    with Simulation("./inps/tank_constantinflow_notreatment.inp") as sim:
        CS = Node_Quality(sim, dict1)
        Tank = Nodes(sim)["Tank"]
        Valve = Links(sim)["Valve"]
        for index, step in enumerate(sim):
            CS.CSTR_solver(index)
            c = Tank.pollut_quality
            conc.append(c['P1'])
            c1 = Valve.pollut_quality
            conc1.append(c1['P1'])
            flow.append(sim._model.getNodeResult("Tank", 0))
            flow1.append(sim._model.getLinkResult("Valve", 0))
        load = [a * b for a, b in zip(conc, flow)]
        cum_load = np.cumsum(load)
        load1 = [a * b for a, b in zip(conc1, flow1)]
        cum_load1 = np.cumsum(load1)
    error = (cum_load1[-1] / cum_load[-1]) / cum_load1[-1]
    print(error)
    assert error <= 0.03
Exemplo n.º 13
0
def test_nodes_2():
    with Simulation(MODEL_WEIR_SETTING_PATH) as sim:
        print("\n\n\nNODES\n")
        for node in Nodes(sim):
            assert ('J' in node.nodeid)
            node.invert_elevation = 10
            assert (node.invert_elevation == 10)
Exemplo n.º 14
0
def test_nodes_6():
    ''' pytest pyswmm/tests/test_nodes.py -k `test_nodes_6` '''
    sim = Simulation(MODEL_WEIR_SETTING_PATH)
    print("\n\n\nNODES\n")
    J5 = Nodes(sim)["J5"]

    for ind, step in enumerate(sim):
        pass
    
    assert(J5.statistics['peak_total_inflow'] >= 0.478)
    assert(J5.statistics['average_depth'] >= 0.00018)
    assert(J5.statistics['surcharge_duration'] >= 0.0)
    assert(J5.statistics['max_ponded_volume'] >= 0.0)
    assert(J5.statistics['courant_crit_duration'] >= 0.0)
    assert(J5.statistics['peak_lateral_inflowrate'] >= 0.0)
    assert(J5.statistics['flooding_duration'] >= 0.0)
    assert(J5.statistics['peak_flooding_rate'] >= 0.0)
    assert(J5.statistics['lateral_infow_vol'] >= 0.0)
    assert(J5.statistics['max_flooding_date'] >= 42309)
    assert(J5.statistics['max_depth_date'] >= 42309)
    assert(J5.statistics['max_inflow_date'] >= 42309)
    assert(J5.statistics['max_depth'] >= 0.0292)
    assert(J5.statistics['flooding_volume'] >= 0.0)
    assert(J5.statistics['max_report_depth'] >= 0.0286)
    sim.close()
Exemplo n.º 15
0
def test_simulation_1():
    sim = Simulation(MODEL_WEIR_SETTING_PATH)
    for ind, step in enumerate(sim):
        print(sim.current_time)
        sim.step_advance(randint(300, 900))

    sim.close()
Exemplo n.º 16
0
def Par_objectivefunctions(trialfile, root=FileSettings.settingsdict['root']):
    """ This function defines the PySWMM operations that occur for each "trialfile". "Hydrograph" list of floats is
    defined by calling the SWMM module and assigning the output at each time step to the list. Then each objective
    function is called and the values are put into a list "objFunc"

    This function is called in parallel by SWMMCALPY, each "trialfile" can be evaluated independently.

    :param trialfile:
    :param root: necessary to tell PySWMM where to read the total inflow output from
    :return objFunc: list of floats that gets mapped by the multiprocessing.Pool()
    """
    global hydrograph, simulation_timestep, sim_time
    hydrograph = []
    sim_time = []
    with Simulation(trialfile) as sim:
        node_object = Nodes(sim)
        root_location = node_object[root]
        simulation_timestep = time_difference.total_seconds()
        sim.step_advance(simulation_timestep)
        for step in sim:
            sim_time.append(sim.current_time)
            hydrograph.append(root_location.total_inflow)
    objFunc = [
        normalizedpeakerror(),
        normalizedvolumeerror(),
        nashsutcliffe(),
        NED(trialfile)
    ]
    # P_prime.append(objFunc)
    return objFunc
Exemplo n.º 17
0
def simul_nodes(i,filename):
    '''
    Function to be iterated using parallelisation
    Filename needs to be changed every time that the storm is changed
    
    Input
    -----
    list of subcatchments where GI will be implemented

    Output
    ------
    resilience index pandas dataframe
    '''
    from pyswmm import Simulation
    
    area = 500
    
    LIDsubcat_area(filename,i)

    fin=filename+str(hash(''.join(i)))+f'area_{area}'

    sim=Simulation('Res_files/'+fin+'.inp')
    sim.execute()

    res=resilienceindex_nodes_sys(fin)
    print('Resilience Index Calculated')

    os.remove('Res_files/'+fin+'.inp')
    os.remove('Res_files/'+fin+'.out')
    os.remove('Res_files/'+fin+'.rpt')

    print('Files removed!')

    return res
Exemplo n.º 18
0
    def reset(self):
        self.sim.close()
        self.sim = Simulation(swmm_inp)
        self.sim.step_advance(self.control_time_step)  # set control time step
        node_object = Nodes(self.sim)  # init node object
        self.St1 = node_object["St1"]
        self.St2 = node_object["St2"]
        self.J1 = node_object["J1"]
        link_object = Links(self.sim)  # init link object
        self.R1 = link_object["R1"]
        self.R2 = link_object["R2"]
        self.St1.full_depth = self.depth
        self.St2.full_depth = self.depth
        self.sim.start()
        self.t = 1
        if self.sim.current_time == self.sim.start_time:

            self.R1.target_setting = 0.5
            self.R2.target_setting = 0.5

        self.state = np.asarray([
            self.St1.depth, self.St2.depth, self.J1.depth, self.St1.flooding,
            self.St2.flooding, self.J1.flooding
        ])
        return self.state
Exemplo n.º 19
0
def test_swmm_input_error_1():
    with pytest.raises(Exception) as e:
        with Simulation(MODEL_BAD_INPUT_PATH_1) as sim:
            for step in sim:
                pass
    assert (str(
        e.value).strip() == 'ERROR 200: one or more errors in input file.')
Exemplo n.º 20
0
def test_list_lid_controls():
    with Simulation(MODEL_LIDS_PATH) as sim:
        for i, control in enumerate(LidControls(sim)):
            if i == 0:
                assert (str(control) == 'LID')
            if i == 1:
                assert (str(control) == 'Green_LID')
Exemplo n.º 21
0
    def reset(self):
        """Reset state.
        """
        # state = np.random.random(size=(1,))

        self.sim.close()
        self.sim = Simulation(self.modelfile)
        self.sim.step_advance(self.controlstep)
        node_object = Nodes(self.sim)
        self.P1 = node_object["P1"]
        self.P2 = node_object["P2"]
        self.P1.depth = self.depth
        self.P2.depth = self.depth

        link_object = Links(self.sim)
        self.L8 = link_object["8"]
        self.L8.flow = self.flow
        self.sim.start()

        if self.sim.current_time == self.sim.start_time:
            self.L8.target_setting = 0

        self.state = np.concatenate([
            np.asarray([
                self.P1.depth, self.P2.depth, self.L8.flow, self.P1.flooding,
                self.P2.flooding, self.O1.current_setting,
                self.O2.current_setting
            ])
        ])

        return self.state
Exemplo n.º 22
0
def test_CSTR_load():
    dict1 = {
        'Tank': {
            'pollutant': 0,
            'method': 'CSTR',
            'parameters': {
                'k': -0.2,
                'n': 1.0,
                'c0': 10.0
            }
        }
    }
    conc = []
    conc1 = []
    flow = []
    flow1 = []
    with Simulation("./tests/inps/tank_constantinflow_notreatment.inp") as sim:
        CS = waterQuality(sim, dict1)
        Tank = Nodes(sim)["Tank"]
        Valve = Links(sim)["Valve"]
        for index, step in enumerate(sim):
            CS.updateWQState_CSTR(index)
            c = Tank.pollut_quality
            conc.append(c['P1'])
            c1 = Valve.pollut_quality
            conc1.append(c1['P1'])
            flow.append(sim._model.getNodeResult("Tank", 0))
            flow1.append(sim._model.getLinkResult("Valve", 0))
        load = [a * b for a, b in zip(conc, flow)]
        cum_load = np.cumsum(load)
        load1 = [a * b for a, b in zip(conc1, flow1)]
        cum_load1 = np.cumsum(load1)
    error = (cum_load1[-1] / cum_load[-1]) / cum_load1[-1]
    print(error)
    assert error <= 0.03
Exemplo n.º 23
0
 def __init__(self, inp_file, fcst_file, depth=4.61):
     # initialize simulation
     self.input_file = inp_file
     self.sim = Simulation(self.input_file)  # read input file
     self.fcst_file = fcst_file
     self.fcst = np.genfromtxt(self.fcst_file, delimiter=',')  # read forecast file as array
     self.control_time_step = 900  # control time step in seconds
     self.sim.step_advance(self.control_time_step)  # set control time step
     node_object = Nodes(self.sim)  # init node object
     self.St1 = node_object["St1"]
     self.St2 = node_object["St2"]
     self.J1 = node_object["J1"]
     self.depth = depth
     self.St1.full_depth = self.depth
     self.St2.full_depth = self.depth
     
     link_object = Links(self.sim)  # init link object
     self.R1 = link_object["R1"]
     self.R2 = link_object["R2"]
 
     self.sim.start()
     if self.sim.current_time == self.sim.start_time:
         self.R1.target_setting = 0.5
         self.R2.target_setting = 0.5
     sim_len = self.sim.end_time - self.sim.start_time
     self.T = int(sim_len.total_seconds()/self.control_time_step)
     self.t = 1
     self.state = np.concatenate([np.asarray([self.St1.depth, self.St2.depth, self.J1.depth,
                                              self.St1.flooding, self.St2.flooding, self.J1.flooding,
                                              self.R1.current_setting, self.R2.current_setting]), self.fcst[self.t]])
     self.action_space = spaces.Box(low=np.array([0, 0]), high=np.array([1, 1]), dtype=np.float32)
     self.observation_space = spaces.Box(low=0, high=1000, shape=(len(self.state),), dtype=np.float32)
Exemplo n.º 24
0
def test_CoRemoval_load():
    dict1 = {'Culvert': {'pollutant': 1, 'method': 'ConstantRemoval', 'parameters': {'R': 0.15}},\
        'Culvert': {'pollutant': 0, 'method': 'CoRemoval', 'parameters': {'R1': 0.75, 'R2': 0.15}},
        }
    conc = []
    conc1 = []
    flow = []
    flow1 = []
    with Simulation("./tests/inps/LinkTest_variableinflow2.inp") as sim:
        CR = waterQuality(sim, dict1)
        culvert = Links(sim)["Culvert"]
        outlet = Nodes(sim)["Outlet"]
        for step in sim:
            CR.updateWQState()
            c = culvert.pollut_quality
            conc.append(c['P1'])
            c1 = outlet.pollut_quality
            conc1.append(c1['P1'])
            flow.append(sim._model.getLinkResult("Culvert", 0))
            flow1.append(sim._model.getNodeResult("Outlet", 0))
        load = [a * b for a, b in zip(conc, flow)]
        cum_load = np.cumsum(load)
        load1 = [a * b for a, b in zip(conc1, flow1)]
        cum_load1 = np.cumsum(load1)
    error = (cum_load1[-1] / cum_load[-1]) / cum_load1[-1]
    print(error)
    assert error <= 0.03
    def reset(self):
        self.sim.close()
        self.sim = Simulation(self.input_file)
        self.fcst = np.genfromtxt(self.fcst_file,
                                  delimiter=',')  # read forecast file as array
        self.sim.step_advance(self.control_time_step)  # set control time step
        node_object = Nodes(self.sim)  # init node object
        self.St1 = node_object["St1"]
        self.St2 = node_object["St2"]
        self.J1 = node_object["J1"]
        link_object = Links(self.sim)  # init link object
        self.R1 = link_object["R1"]
        self.R2 = link_object["R2"]
        self.St1.full_depth = self.depth
        self.St2.full_depth = self.depth
        self.sim.start()
        self.t = 1
        if self.sim.current_time == self.sim.start_time:

            self.R1.target_setting = 0.5
            self.R2.target_setting = 0.5

        self.state = np.concatenate([
            np.asarray([
                self.St1.depth, self.St2.depth, self.J1.depth,
                self.St1.flooding, self.St2.flooding, self.J1.flooding,
                self.R1.current_setting, self.R2.current_setting
            ]), self.fcst[self.t]
        ])
        return self.state
Exemplo n.º 26
0
def test_CoRemoval_load():
    dict1 = {'Culvert': {0: [0.75, 0.15]}}
    dict2 = {'Culvert': {1: 0.15}}
    conc = []
    conc1 = []
    flow = []
    flow1 = []
    with Simulation("./inps/LinkTest_variableinflow2.inp") as sim:
        CR = Link_Quality(sim, dict1)
        culvert = Links(sim)["Culvert"]
        outlet = Nodes(sim)["Outlet"]
        for step in sim:
            CR.CoRemoval()
            c = culvert.pollut_quality
            conc.append(c['P1'])
            c1 = outlet.pollut_quality
            conc1.append(c1['P1'])
            flow.append(sim._model.getLinkResult("Culvert", 0))
            flow1.append(sim._model.getNodeResult("Outlet", 0))
        load = [a * b for a, b in zip(conc, flow)]
        cum_load = np.cumsum(load)
        load1 = [a * b for a, b in zip(conc1, flow1)]
        cum_load1 = np.cumsum(load1)
    error = (cum_load1[-1] / cum_load[-1]) / cum_load1[-1]
    print(error)
    assert error <= 0.03
Exemplo n.º 27
0
def test_GravitySettling_load():
    dict1 = {
        'Culvert': {
            'pollutant': 0,
            'method': 'GravitySettling',
            'parameters': {
                'k': 0.01,
                'C_s': 10.0
            }
        }
    }
    conc = []
    conc1 = []
    flow = []
    flow1 = []
    with Simulation("./tests/inps/LinkTest_variableinflow.inp") as sim:
        GS = waterQuality(sim, dict1)
        culvert = Links(sim)["Culvert"]
        outlet = Nodes(sim)["Outlet"]
        for step in sim:
            GS.updateWQState()
            c = culvert.pollut_quality
            conc.append(c['P1'])
            c1 = outlet.pollut_quality
            conc1.append(c1['P1'])
            flow.append(sim._model.getLinkResult("Culvert", 0))
            flow1.append(sim._model.getNodeResult("Outlet", 0))
        load = [a * b for a, b in zip(conc, flow)]
        cum_load = np.cumsum(load)
        load1 = [a * b for a, b in zip(conc1, flow1)]
        cum_load1 = np.cumsum(load1)
    error = (cum_load1[-1] / cum_load[-1]) / cum_load1[-1]
    print(error)
    assert error <= 0.03
Exemplo n.º 28
0
def test_outfalls_8_mgd():
    ''' pytest pyswmm/tests/test_nodes.py -k `test_outfalls_8_mgd` '''
    sim = Simulation(MODEL_STORAGE_PUMP_MGD)
    print("\n\n\nOUTFALL\n")
    outfall = Nodes(sim)["J3"]
    storage = Nodes(sim)["SU1"]
    junction = Nodes(sim)["J2"]

    for ind, step in enumerate(sim):
        pass
    stats = outfall.outfall_statistics
    outfall_cuinflow = outfall.cumulative_inflow
    sim.close()

    assert (stats['total_periods'] == approx(208796, rel=UT_PRECISION))
    assert (stats['pollutant_loading']['test'] == approx(1305.25,
                                                         rel=UT_PRECISION))
    assert (stats['pollutant_loading']['test'] == approx(1305.75,
                                                         rel=UT_PRECISION))
    assert (stats['average_flowrate'] == approx(4.3, rel=UT_PRECISION))
    assert (stats['average_flowrate'] == approx(4.32, rel=UT_PRECISION))
    assert (stats['peak_flowrate'] == approx(4.33, rel=UT_PRECISION))
    assert (stats['peak_flowrate'] == approx(4.34, rel=UT_PRECISION))
    assert (outfall_cuinflow == approx(1395293, rel=UT_PRECISION))
    assert (outfall_cuinflow == approx(1395299, rel=UT_PRECISION)
            and outfall_cuinflow == approx(1395350, rel=UT_PRECISION))
Exemplo n.º 29
0
def run_simulation(simul_config, data_df, complete_sys_model, disturb_manager):

    if simul_config["sim_type"] == SimType.CUSTOM_MODEL:
        custom_model.run_custom_model_simulation(
            complete_sys_model, simul_config["prediction_horizon"])

    with Simulation(simul_config["network_name"]) as sim:

        if simul_config["sim_type"] == SimType.EULER:
            data_df = euler_model.run_euler_model_simulation(
                simul_config["sim_step_size"], complete_sys_model,
                simul_config["prediction_horizon"], sim, simul_config["pumps"],
                simul_config["tanks"], simul_config["junctions"], data_df,
                disturb_manager, simul_config["num_plot_steps"],
                simul_config["steps_between_plots"])

        elif simul_config["sim_type"] == SimType.PREISMANN:
            data_df = preismann_model.run_preismann_model_simulation(
                simul_config["sim_step_size"], complete_sys_model,
                simul_config["prediction_horizon"], sim, simul_config["pumps"],
                simul_config["tanks"], simul_config["junctions"], data_df,
                disturb_manager, simul_config["num_plot_steps"])

        elif simul_config["sim_type"] == SimType.LOCAL_MODEL:
            data_df = local_model.run_local_model_simulation(
                simul_config["sim_step_size"], sim, simul_config["pumps"],
                simul_config["tanks"], simul_config["junctions"], data_df,
                disturb_manager, simul_config["num_plot_steps"])

        else:
            # There is no other type of simulation, you should probably make sure you selected the correct one.
            print("No simulation is selected.")
            pass

    return data_df
Exemplo n.º 30
0
def test_Erosion_load():
    dict1 = {'Channel': {0: [10.0, 0.001, 2.68, 0.7]}}
    conc = []
    conc1 = []
    flow = []
    flow1 = []
    with Simulation("./inps/LinkTest_variableinflow.inp") as sim:
        ER = Link_Quality(sim, dict1)
        channel = Links(sim)["Channel"]
        tailwater = Nodes(sim)["TailWater"]
        for step in sim:
            ER.Erosion()
            c = channel.pollut_quality
            conc.append(c['P1'])
            c1 = tailwater.pollut_quality
            conc1.append(c1['P1'])
            flow.append(sim._model.getLinkResult("Channel", 0))
            flow1.append(sim._model.getNodeResult("Tailwater", 0))
        load = [a * b for a, b in zip(conc, flow)]
        cum_load = np.cumsum(load)
        load1 = [a * b for a, b in zip(conc1, flow1)]
        cum_load1 = np.cumsum(load1)
    error = (cum_load1[-1] / cum_load[-1]) / cum_load1[-1]
    print(error)
    assert error <= 0.03