Esempio n. 1
0
def test_list_lid_units():
    with Simulation(MODEL_LIDS_PATH) as sim:
        sub_2_lid_units = LidGroups(sim)["2"]
        for i, lid_unit in enumerate(sub_2_lid_units):
            if i == 0:
                assert (lid_unit.subcatchment == '2')
                assert (lid_unit.lid_control == 'LID')
            if i == 1:
                assert (lid_unit.subcatchment == '2')
                assert (lid_unit.lid_control == 'LID')
            if i == 2:
                assert (lid_unit.subcatchment == '2')
                assert (lid_unit.lid_control == 'Green_LID')
Esempio n. 2
0
def test_lid_group_params():
    with Simulation(MODEL_LIDS_PATH) as sim:
        sub_2_lid_units = LidGroups(sim)["2"]
        sim.step_advance(900)
        for i, step in enumerate(sim):
            if i == 115:
                assert (sim.current_time.strftime('%Y-%m-%d %H:%M:%S') ==
                        '1998-01-02 05:00:00')
                assert (sub_2_lid_units.pervious_area == approx(
                    50000, rel=UT_PRECISION))
                assert (sub_2_lid_units.flow_to_pervious == approx(
                    0, rel=UT_PRECISION))
                assert (sub_2_lid_units.old_drain_flow == approx(
                    0.0008, rel=UT_PRECISION))
                assert (sub_2_lid_units.new_drain_flow == approx(
                    0.0008, rel=UT_PRECISION))
Esempio n. 3
0
def test_list_lid_groups():
    with Simulation(MODEL_LIDS_PATH) as sim:
        for i, group in enumerate(LidGroups(sim)):
            if i == 0:
                assert ('subcatchment {} has {} lid units'.format(
                    group, len(group)) == 'subcatchment 1 has 0 lid units')
            if i == 1:
                assert ('subcatchment {} has {} lid units'.format(
                    group, len(group)) == 'subcatchment 2 has 3 lid units')
            if i == 2:
                assert ('subcatchment {} has {} lid units'.format(
                    group, len(group)) == 'subcatchment 3 has 0 lid units')
            if i == 3:
                assert ('subcatchment {} has {} lid units'.format(
                    group, len(group)) == 'subcatchment 4 has 0 lid units')
            if i == 7:
                assert ('subcatchment {} has {} lid units'.format(
                    group, len(group)) == 'subcatchment 8 has 0 lid units')
Esempio n. 4
0
def test_lid_unit_params():
    with Simulation(MODEL_LIDS_PATH) as sim:
        sub_2_lid_units = LidGroups(sim)["2"]
        first_unit = sub_2_lid_units[0]
        assert (first_unit.unit_area == approx(10000, rel=UT_PRECISION))
        assert (first_unit.full_width == approx(20, rel=UT_PRECISION))
        assert (first_unit.initial_saturation == approx(0, rel=UT_PRECISION))
        assert (first_unit.from_impervious == approx(50, rel=UT_PRECISION))
        assert (first_unit.index == 0)
        assert (first_unit.number == 4)
        assert (first_unit.drain_subcatchment == -1)
        assert (first_unit.drain_node == 1)

        for i, step in enumerate(sim):
            if i == 2145:
                assert (first_unit.water_balance.inflow == approx(
                    8.9, rel=UT_PRECISION))
                assert (first_unit.water_balance.evaporation == approx(
                    0, rel=UT_PRECISION))
                assert (first_unit.water_balance.infiltration == approx(
                    0.014, rel=UT_PRECISION))
                assert (first_unit.water_balance.surface_flow == approx(
                    0, rel=UT_PRECISION))
                assert (first_unit.water_balance.drain_flow == approx(
                    3.35, rel=UT_PRECISION))
                assert (first_unit.water_balance.initial_volume == approx(
                    3, rel=UT_PRECISION))
                assert (first_unit.water_balance.final_volume == approx(
                    8.5, rel=UT_PRECISION))
                assert (first_unit.surface.depth == approx(0,
                                                           rel=UT_PRECISION))
                assert (first_unit.pavement.depth == approx(0,
                                                            rel=UT_PRECISION))
                assert (first_unit.soil.moisture == approx(0.2,
                                                           rel=UT_PRECISION))
                assert (first_unit.storage.depth == approx(6,
                                                           rel=UT_PRECISION))
                assert (first_unit.dry_time == approx(21600, rel=UT_PRECISION))
                assert (first_unit.old_drain_flow == approx(0.0005,
                                                            rel=UT_PRECISION))
                assert (first_unit.new_drain_flow == approx(0.0005,
                                                            rel=UT_PRECISION))
                assert (first_unit.surface.flux_rate == approx(
                    0, rel=UT_PRECISION))
Esempio n. 5
0
def test_lid_detailed_report():
    with Simulation(MODEL_LIDS_PATH) as sim:

        subLIDs = LidGroups(sim)

        sub_2_lids = subLIDs["2"]

        # first one defined in .inp
        first_LID_unit_on_sub_2 = sub_2_lids[0]
        # second one defined in .inp
        second_LID_unit_on_sub_2 = sub_2_lids[1]

        assert (first_LID_unit_on_sub_2.number == 4)
        assert (second_LID_unit_on_sub_2.number == 1)

        sim.step_advance(900)
        for i, step in enumerate(sim):
            if i == 20:
                assert (sim.current_time.strftime('%Y-%m-%d %H:%M:%S') ==
                        '1998-01-01 05:15:00')
                assert (first_LID_unit_on_sub_2.surface.inflow == approx(
                    0.47, rel=UT_PRECISION))
                assert (first_LID_unit_on_sub_2.evaporation == approx(
                    0, rel=UT_PRECISION))
                assert (first_LID_unit_on_sub_2.surface.infiltration == approx(
                    0.47, rel=UT_PRECISION))
                assert (first_LID_unit_on_sub_2.pavement.percolation == approx(
                    0.47, rel=UT_PRECISION))
                assert (first_LID_unit_on_sub_2.soil.percolation == approx(
                    0.615, rel=UT_PRECISION))
                assert (first_LID_unit_on_sub_2.storage.exfiltration == approx(
                    0, rel=UT_PRECISION))
                assert (first_LID_unit_on_sub_2.surface.outflow == approx(
                    0, rel=UT_PRECISION))
                assert (first_LID_unit_on_sub_2.storage.drain == approx(
                    0, rel=UT_PRECISION))
Esempio n. 6
0
def swmm(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16,
         x17, x18, x19, x20, x21, x22, x23, x24, x25, x26, x27, x28, x29, x30,
         x31, x32, x33, x34, x35, x36, x37, x38, x39, x40):
    # from pyswmm import Simulation, SystemStats, LidControls, LidGroups, Subcatchments, Nodes
    # 输入SWMM的input文件(路径)——交互输入
    with Simulation(filename1) as sim:
        system_routing = SystemStats(sim)
        node_object = Nodes(sim)
        # 选择规模变化的LID设施——交互输入,比如Out1=xxx(xxx为SWMM模型中outfall的name),
        # lid1=Sn(Sn为LID规模变化的subcatchment的name),lid2=Sm....
        # 最好设计成可以用户添加的交互,比如用户可以添加一个LID,也可以添加多个
        Out1 = node_object["Out1"]
        lid1 = LidGroups(sim)["S1"]
        lid9 = LidGroups(sim)["S9"]
        lid13 = LidGroups(sim)["S13"]
        lid19 = LidGroups(sim)["S19"]
        lid22 = LidGroups(sim)["S22"]
        lid24 = LidGroups(sim)["S24"]
        lid25 = LidGroups(sim)["S25"]
        lid87 = LidGroups(sim)["S87"]
        lid92 = LidGroups(sim)["S92"]
        lid93 = LidGroups(sim)["S93"]
        lid94 = LidGroups(sim)["S94"]
        lid95 = LidGroups(sim)["S95"]
        lid96 = LidGroups(sim)["S96"]
        lid99 = LidGroups(sim)["S99"]
        lid130 = LidGroups(sim)["S130"]
        lid64 = LidGroups(sim)["S64"]
        lid66 = LidGroups(sim)["S66"]
        lid108 = LidGroups(sim)["S108"]
        lid106 = LidGroups(sim)["S106"]
        lid110 = LidGroups(sim)["S110"]
        lid60 = LidGroups(sim)["S60"]
        lid112 = LidGroups(sim)["S112"]
        lid100 = LidGroups(sim)["S100"]
        lid107 = LidGroups(sim)["S107"]
        lid109 = LidGroups(sim)["S109"]
        lid14 = LidGroups(sim)["S14"]
        lid81 = LidGroups(sim)["S81"]
        lid4 = LidGroups(sim)["S4"]
        lid91 = LidGroups(sim)["S91"]
        lid15 = LidGroups(sim)["S15"]
        lid17 = LidGroups(sim)["S17"]
        lid18 = LidGroups(sim)["S18"]
        lid6 = LidGroups(sim)["S6"]
        lid12 = LidGroups(sim)["S12"]
        lid16 = LidGroups(sim)["S16"]
        lid11 = LidGroups(sim)["S11"]
        lid117 = LidGroups(sim)["S117"]
        lid101 = LidGroups(sim)["S101"]
        lid86 = LidGroups(sim)["S86"]
        lid50 = LidGroups(sim)["S50"]

        # 定义每个可变规模的LID的面积——内部运算(基于上述输入的可变规模的LID)
        for lid in lid1:
            lid.unit_area = x1
        for lid in lid9:
            lid.unit_area = x2
        for lid in lid13:
            lid.unit_area = x3
        for lid in lid19:
            lid.unit_area = x4
        for lid in lid22:
            lid.unit_area = x5
        for lid in lid24:
            lid.unit_area = x6
        for lid in lid25:
            lid.unit_area = x7
        for lid in lid87:
            lid.unit_area = x8
        for lid in lid92:
            lid.unit_area = x9
        for lid in lid93:
            lid.unit_area = x10
        for lid in lid94:
            lid.unit_area = x11
        for lid in lid95:
            lid.unit_area = x12
        for lid in lid96:
            lid.unit_area = x13
        for lid in lid99:
            lid.unit_area = x14
        for lid in lid130:
            lid.unit_area = x15
        for lid in lid64:
            lid.unit_area = x16
        for lid in lid66:
            lid.unit_area = x17
        for lid in lid108:
            lid.unit_area = x18
        for lid in lid106:
            lid.unit_area = x19
        for lid in lid110:
            lid.unit_area = x20
        for lid in lid60:
            lid.unit_area = x21
        for lid in lid112:
            lid.unit_area = x22
        for lid in lid100:
            lid.unit_area = x23
        for lid in lid107:
            lid.unit_area = x24
        for lid in lid109:
            lid.unit_area = x25
        for lid in lid14:
            lid.unit_area = x26
        for lid in lid81:
            lid.unit_area = x27
        for lid in lid4:
            lid.unit_area = x28
        for lid in lid91:
            lid.unit_area = x29
        for lid in lid15:
            lid.unit_area = x30
        for lid in lid17:
            lid.unit_area = x31
        for lid in lid18:
            lid.unit_area = x32
        for lid in lid6:
            lid.unit_area = x33
        for lid in lid12:
            lid.unit_area = x34
        for lid in lid16:
            lid.unit_area = x35
        for lid in lid11:
            lid.unit_area = x36
        for lid in lid117:
            lid.unit_area = x37
        for lid in lid101:
            lid.unit_area = x38
        for lid in lid86:
            lid.unit_area = x39
        for lid in lid50:
            lid.unit_area = x40
        for step in sim:
            pass
        y = round((Out1.cumulative_inflow * 7.47 * 0.0037854 / 1261), 6)
    return y
Esempio n. 7
0
def pollutant(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15,
              x16, x17, x18, x19, x20, x21, x22, x23, x24, x25, x26, x27, x28,
              x29, x30, x31, x32, x33, x34, x35, x36, x37, x38, x39, x40):
    #from pyswmm import Simulation, SystemStats, LidControls, LidGroups, Subcatchments, Nodes
    #和上面是同一个路径的input文件
    with Simulation(filename1) as sim:
        system_routing = SystemStats(sim)
        node_object = Nodes(sim)
        #和上面同样定义的各个LID
        Out1 = node_object["Out1"]
        lid1 = LidGroups(sim)["S1"]
        lid9 = LidGroups(sim)["S9"]
        lid13 = LidGroups(sim)["S13"]
        lid19 = LidGroups(sim)["S19"]
        lid22 = LidGroups(sim)["S22"]
        lid24 = LidGroups(sim)["S24"]
        lid25 = LidGroups(sim)["S25"]
        lid87 = LidGroups(sim)["S87"]
        lid92 = LidGroups(sim)["S92"]
        lid93 = LidGroups(sim)["S93"]
        lid94 = LidGroups(sim)["S94"]
        lid95 = LidGroups(sim)["S95"]
        lid96 = LidGroups(sim)["S96"]
        lid99 = LidGroups(sim)["S99"]
        lid130 = LidGroups(sim)["S130"]
        lid64 = LidGroups(sim)["S64"]
        lid66 = LidGroups(sim)["S66"]
        lid108 = LidGroups(sim)["S108"]
        lid106 = LidGroups(sim)["S106"]
        lid110 = LidGroups(sim)["S110"]
        lid60 = LidGroups(sim)["S60"]
        lid112 = LidGroups(sim)["S112"]
        lid100 = LidGroups(sim)["S100"]
        lid107 = LidGroups(sim)["S107"]
        lid109 = LidGroups(sim)["S109"]
        lid14 = LidGroups(sim)["S14"]
        lid81 = LidGroups(sim)["S81"]
        lid4 = LidGroups(sim)["S4"]
        lid91 = LidGroups(sim)["S91"]
        lid15 = LidGroups(sim)["S15"]
        lid17 = LidGroups(sim)["S17"]
        lid18 = LidGroups(sim)["S18"]
        lid6 = LidGroups(sim)["S6"]
        lid12 = LidGroups(sim)["S12"]
        lid16 = LidGroups(sim)["S16"]
        lid11 = LidGroups(sim)["S11"]
        lid117 = LidGroups(sim)["S117"]
        lid101 = LidGroups(sim)["S101"]
        lid86 = LidGroups(sim)["S86"]
        lid50 = LidGroups(sim)["S50"]
        #根据上面输入的LID进行内部运算
        for lid in lid1:
            lid.unit_area = x1
        for lid in lid9:
            lid.unit_area = x2
        for lid in lid13:
            lid.unit_area = x3
        for lid in lid19:
            lid.unit_area = x4
        for lid in lid22:
            lid.unit_area = x5
        for lid in lid24:
            lid.unit_area = x6
        for lid in lid25:
            lid.unit_area = x7
        for lid in lid87:
            lid.unit_area = x8
        for lid in lid92:
            lid.unit_area = x9
        for lid in lid93:
            lid.unit_area = x10
        for lid in lid94:
            lid.unit_area = x11
        for lid in lid95:
            lid.unit_area = x12
        for lid in lid96:
            lid.unit_area = x13
        for lid in lid99:
            lid.unit_area = x14
        for lid in lid130:
            lid.unit_area = x15
        for lid in lid64:
            lid.unit_area = x16
        for lid in lid66:
            lid.unit_area = x17
        for lid in lid108:
            lid.unit_area = x18
        for lid in lid106:
            lid.unit_area = x19
        for lid in lid110:
            lid.unit_area = x20
        for lid in lid60:
            lid.unit_area = x21
        for lid in lid112:
            lid.unit_area = x22
        for lid in lid100:
            lid.unit_area = x23
        for lid in lid107:
            lid.unit_area = x24
        for lid in lid109:
            lid.unit_area = x25
        for lid in lid14:
            lid.unit_area = x26
        for lid in lid81:
            lid.unit_area = x27
        for lid in lid4:
            lid.unit_area = x28
        for lid in lid91:
            lid.unit_area = x29
        for lid in lid15:
            lid.unit_area = x30
        for lid in lid17:
            lid.unit_area = x31
        for lid in lid18:
            lid.unit_area = x32
        for lid in lid6:
            lid.unit_area = x33
        for lid in lid12:
            lid.unit_area = x34
        for lid in lid16:
            lid.unit_area = x35
        for lid in lid11:
            lid.unit_area = x36
        for lid in lid117:
            lid.unit_area = x37
        for lid in lid101:
            lid.unit_area = x38
        for lid in lid86:
            lid.unit_area = x39
        for lid in lid50:
            lid.unit_area = x40
        for step in sim:
            pass
        data = Out1.outfall_statistics
        a = data.get("pollutant_loading")
        data = a
        b = float(data["SS"])
        c = round(b / 13.9258, 6)
    return c