Esempio n. 1
0
def test_convenience_create_functions():
    net = pp.create_empty_network()
    b1 = pp.create_bus(net, 110.)
    b2 = pp.create_bus(net, 110.)
    pp.create_ext_grid(net, b1)
    pp.create_line_from_parameters(net, b1, b2, length_km=20., r_ohm_per_km=0.0487,
                                   x_ohm_per_km=0.1382301, c_nf_per_km=160., max_i_ka=0.664)

    l0 = pp.create_load_from_cosphi(net, b2, 10e3, 0.95, "ind", name="load")
    pp.runpp(net, init="flat")
    assert net.load.p_kw.at[l0] == 9.5e3
    assert net.load.q_kvar.at[l0] > 0
    assert np.sqrt(net.load.p_kw.at[l0]**2 +  net.load.q_kvar.at[l0]**2) == 10e3
    assert np.isclose(net.res_bus.vm_pu.at[b2], 0.99990833838)
    assert net.load.name.at[l0] == "load"

    sh0 = pp.create_shunt_as_condensator(net, b2, 10e3, loss_factor=0.01, name="shunt")
    pp.runpp(net, init="flat")
    assert np.isclose(net.res_shunt.q_kvar.at[sh0], -10,043934174e3)
    assert np.isclose(net.res_shunt.p_kw.at[sh0], 100.43933665)
    assert np.isclose(net.res_bus.vm_pu.at[b2], 1.0021942964)
    assert net.shunt.name.at[sh0] == "shunt"

    sg0 = pp.create_sgen_from_cosphi(net, b2, 5e3, 0.95, "cap", name="sgen")
    pp.runpp(net, init="flat")
    assert np.sqrt(net.sgen.p_kw.at[sg0]**2 +  net.sgen.q_kvar.at[sg0]**2) == 5e3
    assert net.sgen.p_kw.at[sg0] == -4.75e3
    assert net.sgen.q_kvar.at[sg0] < 0
    assert np.isclose(net.res_bus.vm_pu.at[b2], 1.0029376578)
    assert net.sgen.name.at[sg0] == "sgen"
Esempio n. 2
0
def test_convenience_create_functions():
    net = pp.create_empty_network()
    b1 = pp.create_bus(net, 110.)
    b2 = pp.create_bus(net, 110.)
    b3 = pp.create_bus(net, 20)
    pp.create_ext_grid(net, b1)
    pp.create_line_from_parameters(net, b1, b2, length_km=20., r_ohm_per_km=0.0487,
                                   x_ohm_per_km=0.1382301, c_nf_per_km=160., max_i_ka=0.664)

    l0 = pp.create_load_from_cosphi(net, b2, 10, 0.95, "underexcited", name="load")
    pp.runpp(net, init="flat")
    assert net.load.p_mw.at[l0] == 9.5
    assert net.load.q_mvar.at[l0] > 0
    assert np.sqrt(net.load.p_mw.at[l0] ** 2 + net.load.q_mvar.at[l0] ** 2) == 10
    assert np.isclose(net.res_bus.vm_pu.at[b2], 0.99990833838)
    assert net.load.name.at[l0] == "load"

    sh0 = pp.create_shunt_as_capacitor(net, b2, 10, loss_factor=0.01, name="shunt")
    pp.runpp(net, init="flat")
    assert np.isclose(net.res_shunt.q_mvar.at[sh0], -10.043934174)
    assert np.isclose(net.res_shunt.p_mw.at[sh0], 0.10043933665)
    assert np.isclose(net.res_bus.vm_pu.at[b2], 1.0021942964)
    assert net.shunt.name.at[sh0] == "shunt"

    sg0 = pp.create_sgen_from_cosphi(net, b2, 5, 0.95, "overexcited", name="sgen")
    pp.runpp(net, init="flat")
    assert np.sqrt(net.sgen.p_mw.at[sg0] ** 2 + net.sgen.q_mvar.at[sg0] ** 2) == 5
    assert net.sgen.p_mw.at[sg0] == 4.75
    assert net.sgen.q_mvar.at[sg0] > 0
    assert np.isclose(net.res_bus.vm_pu.at[b2], 1.0029376578)
    assert net.sgen.name.at[sg0] == "sgen"

    tol = 1e-6
    base_z = 110 ** 2 / 100
    sind = pp.create_series_reactor_as_impedance(net, b1, b2, r_ohm=100, x_ohm=200, sn_mva=100)
    assert net.impedance.at[sind, 'rft_pu'] - 100 / base_z < tol
    assert net.impedance.at[sind, 'xft_pu'] - 200 / base_z < tol

    tid = pp.create_transformer_from_parameters(net, hv_bus=b2, lv_bus=b3, sn_mva=0.1, vn_hv_kv=110,
                                                vn_lv_kv=20, vkr_percent=5, vk_percent=20,
                                                pfe_kw=1, i0_percent=1)
    pp.create_load(net, b3, 0.1)
    assert net.trafo.at[tid, 'df'] == 1
    pp.runpp(net)
    tr_l = net.res_trafo.at[tid, 'loading_percent']
    net.trafo.at[tid, 'df'] = 2
    pp.runpp(net)
    tr_l_2 = net.res_trafo.at[tid, 'loading_percent']
    assert tr_l == tr_l_2 * 2
    net.trafo.at[tid, 'df'] = 0
    with pytest.raises(UserWarning):
        pp.runpp(net)
def overhead_network():
    net = pp.create_empty_network()

    # LV Overhead 100mm
    pp.create_std_type(
        net,
        {
            "r_ohm_per_km": 0.270922,
            "x_ohm_per_km": (0.06416027 * 10**-3) * math.pi * 50,
            "c_nf_per_km": 0,
            "max_i_ka": 0.271,
            # "r0_ohm_per_km": 0.554544,
            # "x0_ohm_per_km": 1.030687,
            # "c0_nf_per_km": 0,
            "type": "ol",
            "temperature_degree_celsius": 20,
        },
        name="LV Overhead 100mm Al",
        element="line")
    # LV Overhead 50mm
    pp.create_std_type(
        net,
        {
            "r_ohm_per_km": 0.5419,
            "x_ohm_per_km": (0.06416027 * 10**-3) * math.pi * 50,
            "c_nf_per_km": 0,
            "max_i_ka": 0.181,
            # "r0_ohm_per_km": 0.554544,
            # "x0_ohm_per_km": 1.030687,
            # "c0_nf_per_km": 0,
            "type": "ol",
            "temperature_degree_celsius": 20,
        },
        name="LV Overhead 50mm Al",
        element="line")

    # LV Overhead 14mm
    pp.create_std_type(net, {
        "r_ohm_per_km": 1.273,
        "x_ohm_per_km": 0,
        "c_nf_per_km": 0,
        "max_i_ka": 0.099,
        "r0_ohm_per_km": 1.273,
        "x0_ohm_per_km": 0,
        "c0_nf_per_km": 0,
        "type": "ol",
        "temperature_degree_celsius": 20,
    },
                       name="LV Overhead 14mm",
                       element="line")

    # Substation buses
    SubstationMVbus = pp.create_bus(net,
                                    vn_kv=11,
                                    name="SubMV_Terminal",
                                    in_service=True)
    SubstationLVbus = pp.create_bus(net,
                                    vn_kv=0.4,
                                    name="SubLV_Terminal",
                                    in_service=True)

    # External Grid
    ExternalGrid = pp.create_ext_grid(net, bus=SubstationMVbus, vm_pu=1)

    # Transformer
    Transformer = pp.create_transformer_from_parameters(net,
                                                        hv_bus=SubstationMVbus,
                                                        lv_bus=SubstationLVbus,
                                                        name="Dyn11",
                                                        sn_mva=0.63,
                                                        vn_hv_kv=11,
                                                        vn_lv_kv=0.400,
                                                        vkr_percent=0.8571429,
                                                        vk_percent=4,
                                                        pfe_kw=5.4,
                                                        i0_percent=0,
                                                        vk0_percent=4,
                                                        vkr0_percent=0,
                                                        shift_degree=330,
                                                        tap_side="hv",
                                                        tap_step_percent=2.5,
                                                        tap_neutral=3,
                                                        tap_min=1,
                                                        tap_max=5,
                                                        tap_pos=3,
                                                        mag0_rx=4.558264,
                                                        mag0_percent=1.51942,
                                                        vector_group="Dyn")

    # Medium buses
    bus1 = pp.create_bus(net, vn_kv=0.4, name="Med_Bus1", in_service=True)
    bus2 = pp.create_bus(net, vn_kv=0.4, name="Med_Bus2", in_service=True)
    bus3 = pp.create_bus(net, vn_kv=0.4, name="Med_Bus3", in_service=True)
    bus4 = pp.create_bus(net, vn_kv=0.4, name="Med_Bus4", in_service=True)
    bus5 = pp.create_bus(net, vn_kv=0.4, name="Med_Bus5", in_service=True)
    bus6 = pp.create_bus(net, vn_kv=0.4, name="Med_Bus6", in_service=True)
    bus7 = pp.create_bus(net, vn_kv=0.4, name="Med_Bus7", in_service=True)
    bus8 = pp.create_bus(net, vn_kv=0.4, name="Med_Bus8", in_service=True)

    # Medium Lines
    LineM1 = pp.create_line(net,
                            from_bus=SubstationLVbus,
                            to_bus=bus1,
                            length_km=0.100,
                            std_type="LV Overhead 100mm Al",
                            name="LineM1",
                            in_service=True)
    #LineM1_B = pp.create_line(net, from_bus=SubstationLVbus, to_bus=bus1, length_km=0.100,
    #                       std_type="LV Overhead 100mm Al",
    #                      name="LineM1_B", in_service=True)
    LineM2 = pp.create_line(net,
                            from_bus=bus1,
                            to_bus=bus2,
                            length_km=0.05,
                            std_type="LV Overhead 100mm Al",
                            name="LineM2",
                            in_service=True)
    #LineM2_B = pp.create_line(net, from_bus=bus1, to_bus=bus2, length_km=0.05, std_type="LV Overhead 100mm Al",
    #                         name="LineM2_B",
    #                        in_service=True)
    LineM3 = pp.create_line(net,
                            from_bus=bus2,
                            to_bus=bus3,
                            length_km=0.025,
                            std_type="LV Overhead 100mm Al",
                            name="LineM3",
                            in_service=True)
    #LineM3_B = pp.create_line(net, from_bus=bus2, to_bus=bus3, length_km=0.025, std_type="LV Overhead 100mm Al",
    #                         name="LineM3_B", in_service=True)
    LineM4 = pp.create_line(net,
                            from_bus=bus3,
                            to_bus=bus4,
                            length_km=0.025,
                            std_type="LV Overhead 100mm Al",
                            name="LineM4",
                            in_service=True)
    #LineM4_B = pp.create_line(net, from_bus=bus3, to_bus=bus4, length_km=0.025, std_type="LV Overhead 100mm Al",
    #                         name="LineM4_B", in_service=True)
    LineM5 = pp.create_line(net,
                            from_bus=bus4,
                            to_bus=bus5,
                            length_km=0.100,
                            std_type="LV Overhead 100mm Al",
                            name="LineM5",
                            in_service=True)
    LineM6 = pp.create_line(net,
                            from_bus=bus5,
                            to_bus=bus6,
                            length_km=0.050,
                            std_type="LV Overhead 100mm Al",
                            name="LineM6",
                            in_service=True)
    LineM7 = pp.create_line(net,
                            from_bus=bus6,
                            to_bus=bus7,
                            length_km=0.025,
                            std_type="LV Overhead 100mm Al",
                            name="LineM7",
                            in_service=True)
    LineM8 = pp.create_line(net,
                            from_bus=bus7,
                            to_bus=bus8,
                            length_km=0.025,
                            std_type="LV Overhead 100mm Al",
                            name="LineM8",
                            in_service=True)
    """     Buses, lines and loads from BUS1    """
    # buses
    bus11 = pp.create_bus(net, vn_kv=0.4, name="bus11", in_service=True)
    bus11_1 = pp.create_bus(net, vn_kv=0.4, name="bus111", in_service=True)
    bus11_2 = pp.create_bus(net, vn_kv=0.4, name="bus112", in_service=True)
    bus112 = pp.create_bus(net, vn_kv=0.4, name="bus12", in_service=True)
    bus112_1 = pp.create_bus(net, vn_kv=0.4, name="bus121", in_service=True)
    bus112_2 = pp.create_bus(net, vn_kv=0.4, name="bus122", in_service=True)

    # Lines
    lineT11 = pp.create_line(net,
                             from_bus=bus1,
                             to_bus=bus11,
                             name="lineT11",
                             length_km=0.035,
                             std_type="LV Overhead 50mm Al",
                             in_service=True)
    lineT12 = pp.create_line(net,
                             from_bus=bus11,
                             to_bus=bus112,
                             name="lineT12",
                             length_km=0.035,
                             std_type="LV Overhead 50mm Al",
                             in_service=True)
    lineP1 = pp.create_line(net,
                            from_bus=bus11,
                            to_bus=bus11_1,
                            name="lineP1",
                            length_km=0.020,
                            std_type="LV Overhead 14mm",
                            in_service=True)
    lineP2 = pp.create_line(net,
                            from_bus=bus11,
                            to_bus=bus11_2,
                            name="lineP2",
                            length_km=0.020,
                            std_type="LV Overhead 14mm",
                            in_service=True)
    lineP3 = pp.create_line(net,
                            from_bus=bus112,
                            to_bus=bus112_1,
                            name="lineP3",
                            length_km=0.020,
                            std_type="LV Overhead 14mm",
                            in_service=True)
    lineP4 = pp.create_line(net,
                            from_bus=bus112,
                            to_bus=bus112_2,
                            name="lineP4",
                            length_km=0.020,
                            std_type="LV Overhead 14mm",
                            in_service=True)

    # Loads
    load26 = pp.create_load_from_cosphi(net,
                                        bus=bus11_1,
                                        sn_mva=0.002,
                                        cos_phi=0.85,
                                        mode="ind")
    load25 = pp.create_load_from_cosphi(net,
                                        bus=bus11_2,
                                        sn_mva=0.002,
                                        cos_phi=0.85,
                                        mode="ind")
    load24 = pp.create_load_from_cosphi(net,
                                        bus=bus112_1,
                                        sn_mva=0.002,
                                        cos_phi=0.85,
                                        mode="ind")
    load21 = pp.create_load_from_cosphi(net,
                                        bus=bus112_2,
                                        sn_mva=0.002,
                                        cos_phi=0.85,
                                        mode="ind")
    """     Buses, lines and loads from BUS2    """
    bus21 = pp.create_bus(net, vn_kv=0.4, name="bus21", in_service=True)
    bus22 = pp.create_bus(net, vn_kv=0.4, name="bus22", in_service=True)

    lineP5 = pp.create_line(net,
                            from_bus=bus2,
                            to_bus=bus21,
                            name="lineP5",
                            length_km=0.020,
                            std_type="LV Overhead 14mm",
                            in_service=True)
    lineP6 = pp.create_line(net,
                            from_bus=bus2,
                            to_bus=bus22,
                            name="lineP6",
                            length_km=0.020,
                            std_type="LV Overhead 14mm",
                            in_service=True)

    load2 = pp.create_load_from_cosphi(net,
                                       bus=bus21,
                                       sn_mva=0.002,
                                       cos_phi=0.85,
                                       mode="ind")
    load3 = pp.create_load_from_cosphi(net,
                                       bus=bus22,
                                       sn_mva=0.002,
                                       cos_phi=0.85,
                                       mode="ind")
    """     Buses, lines and loads from BUS3    """
    bus31 = pp.create_bus(net, vn_kv=0.4, name="bus31", in_service=True)
    bus32 = pp.create_bus(net, vn_kv=0.4, name="bus32", in_service=True)

    lineP7 = pp.create_line(net,
                            from_bus=bus3,
                            to_bus=bus31,
                            length_km=0.020,
                            name="lineP7",
                            std_type="LV Overhead 14mm",
                            in_service=True)
    lineP8 = pp.create_line(net,
                            from_bus=bus3,
                            to_bus=bus32,
                            length_km=0.020,
                            name="lineP8",
                            std_type="LV Overhead 14mm",
                            in_service=True)

    load27 = pp.create_load_from_cosphi(net,
                                        bus=bus31,
                                        sn_mva=0.002,
                                        cos_phi=0.85,
                                        mode="ind")
    load4 = pp.create_load_from_cosphi(net,
                                       bus=bus32,
                                       sn_mva=0.002,
                                       cos_phi=0.85,
                                       mode="ind")
    """     Buses, lines and loads from BUS4    """
    bus42 = pp.create_bus(net, vn_kv=0.4, name="bus42", in_service=True)
    bus41 = pp.create_bus(net, vn_kv=0.4, name="bus41", in_service=True)
    bus412 = pp.create_bus(net, vn_kv=0.4, name="bus412", in_service=True)
    bus41_2 = pp.create_bus(net, vn_kv=0.4, name="bus41_2", in_service=True)
    bus41_1 = pp.create_bus(net, vn_kv=0.4, name="bus41_1", in_service=True)

    lineP10 = pp.create_line(net,
                             from_bus=bus4,
                             to_bus=bus42,
                             name="lineP10",
                             length_km=0.020,
                             std_type="LV Overhead 14mm",
                             in_service=True)
    lineT21 = pp.create_line(net,
                             from_bus=bus4,
                             to_bus=bus41,
                             name="lineT21",
                             length_km=0.035,
                             std_type="LV Overhead 50mm Al",
                             in_service=True)
    lineT22 = pp.create_line(net,
                             from_bus=bus41,
                             to_bus=bus412,
                             name="lineT22",
                             length_km=0.035,
                             std_type="LV Overhead 50mm Al",
                             in_service=True)
    lineP11 = pp.create_line(net,
                             from_bus=bus41,
                             to_bus=bus41_1,
                             name="lineP11",
                             length_km=0.020,
                             std_type="LV Overhead 14mm",
                             in_service=True)
    lineP12 = pp.create_line(net,
                             from_bus=bus41,
                             to_bus=bus41_2,
                             name="lineP12",
                             length_km=0.020,
                             std_type="LV Overhead 14mm",
                             in_service=True)

    # Loads
    load5 = pp.create_load_from_cosphi(net,
                                       bus=bus42,
                                       sn_mva=0.002,
                                       cos_phi=0.85,
                                       mode="ind")
    load10 = pp.create_load_from_cosphi(net,
                                        bus=bus41_2,
                                        sn_mva=0.002,
                                        cos_phi=0.85,
                                        mode="ind")
    load11 = pp.create_load_from_cosphi(net,
                                        bus=bus41_1,
                                        sn_mva=0.002,
                                        cos_phi=0.85,
                                        mode="ind")
    load22 = pp.create_load_from_cosphi(net,
                                        bus=bus412,
                                        sn_mva=0.002,
                                        cos_phi=0.85,
                                        mode="ind")
    load23 = pp.create_load_from_cosphi(net,
                                        bus=bus412,
                                        sn_mva=0.002,
                                        cos_phi=0.85,
                                        mode="ind")
    """     Buses, lines and loads from BUS5    """
    # buses
    bus52 = pp.create_bus(net, vn_kv=0.4, name="bus53", in_service=True)
    bus51 = pp.create_bus(net, vn_kv=0.4, name="bus51", in_service=True)
    bus512 = pp.create_bus(net, vn_kv=0.4, name="bus512", in_service=True)

    bus51_1 = pp.create_bus(net, vn_kv=0.4, name="bus51_1", in_service=True)
    bus51_2 = pp.create_bus(net, vn_kv=0.4, name="bus51_2", in_service=True)
    bus512_1 = pp.create_bus(net, vn_kv=0.4, name="bus52_1", in_service=True)
    bus512_2 = pp.create_bus(net, vn_kv=0.4, name="bus52_2", in_service=True)

    # lines
    lineT31 = pp.create_line(net,
                             from_bus=bus5,
                             to_bus=bus51,
                             name="lineT31",
                             length_km=0.035,
                             std_type="LV Overhead 100mm Al",
                             in_service=True)
    lineT32 = pp.create_line(net,
                             from_bus=bus51,
                             to_bus=bus512,
                             name="lineT32",
                             length_km=0.035,
                             std_type="LV Overhead 50mm Al",
                             in_service=True)

    lineP15 = pp.create_line(net,
                             from_bus=bus5,
                             to_bus=bus52,
                             name="lineP15",
                             length_km=0.020,
                             std_type="LV Overhead 14mm",
                             in_service=True)
    lineP16 = pp.create_line(net,
                             from_bus=bus51,
                             to_bus=bus51_1,
                             name="lineP16",
                             length_km=0.020,
                             std_type="LV Overhead 14mm",
                             in_service=True)
    lineP17 = pp.create_line(net,
                             from_bus=bus51,
                             to_bus=bus51_2,
                             name="lineP17",
                             length_km=0.020,
                             std_type="LV Overhead 14mm",
                             in_service=True)
    lineP18 = pp.create_line(net,
                             from_bus=bus512,
                             to_bus=bus512_1,
                             name="lineP18",
                             length_km=0.020,
                             std_type="LV Overhead 14mm",
                             in_service=True)
    lineP19 = pp.create_line(net,
                             from_bus=bus512,
                             to_bus=bus512_2,
                             name="lineP19",
                             length_km=0.020,
                             std_type="LV Overhead 14mm",
                             in_service=True)

    # Loads
    load9 = pp.create_load_from_cosphi(net,
                                       bus=bus52,
                                       sn_mva=0.002,
                                       cos_phi=0.85,
                                       mode="ind")
    load13 = pp.create_load_from_cosphi(net,
                                        bus=bus51_1,
                                        sn_mva=0.002,
                                        cos_phi=0.85,
                                        mode="ind")
    load14 = pp.create_load_from_cosphi(net,
                                        bus=bus51_2,
                                        sn_mva=0.002,
                                        cos_phi=0.85,
                                        mode="ind")
    load12 = pp.create_load_from_cosphi(net,
                                        bus=bus512_1,
                                        sn_mva=0.002,
                                        cos_phi=0.85,
                                        mode="ind")
    load6 = pp.create_load_from_cosphi(net,
                                       bus=bus512_2,
                                       sn_mva=0.002,
                                       cos_phi=0.85,
                                       mode="ind")
    """     Buses, lines and loads from BUS6    """
    # buses
    bus61 = pp.create_bus(net, vn_kv=0.4, name="bus61", in_service=True)
    bus62 = pp.create_bus(net, vn_kv=0.4, name="bus62", in_service=True)

    # lines
    lineP20 = pp.create_line(net,
                             from_bus=bus6,
                             to_bus=bus61,
                             name="lineP20",
                             length_km=0.020,
                             std_type="LV Overhead 14mm",
                             in_service=True)
    lineP21 = pp.create_line(net,
                             from_bus=bus6,
                             to_bus=bus62,
                             name="lineP21",
                             length_km=0.020,
                             std_type="LV Overhead 14mm",
                             in_service=True)

    # Loads
    load7 = pp.create_load_from_cosphi(net,
                                       bus=bus62,
                                       sn_mva=0.002,
                                       cos_phi=0.85,
                                       mode="ind")
    load8 = pp.create_load_from_cosphi(net,
                                       bus=bus61,
                                       sn_mva=0.002,
                                       cos_phi=0.85,
                                       mode="ind")
    """     Buses, lines and loads from BUS7    """
    bus71 = pp.create_bus(net, vn_kv=0.4, name="bus71", in_service=True)
    lineP22 = pp.create_line(net,
                             from_bus=bus7,
                             to_bus=bus71,
                             name="lineP22",
                             length_km=0.020,
                             std_type="LV Overhead 14mm",
                             in_service=True)
    load1 = pp.create_load_from_cosphi(net,
                                       bus=bus71,
                                       sn_mva=0.002,
                                       cos_phi=0.85,
                                       mode="ind")
    """     Buses, lines and loads from BUS8    """
    # buses
    bus81 = pp.create_bus(net, vn_kv=0.4, name="bus81", in_service=True)
    bus82 = pp.create_bus(net, vn_kv=0.4, name="bus82", in_service=True)
    bus83 = pp.create_bus(net, vn_kv=0.4, name="bus83", in_service=True)
    bus834 = pp.create_bus(net, vn_kv=0.4, name="bus834", in_service=True)
    bus83_1 = pp.create_bus(net, vn_kv=0.4, name="bus83_1", in_service=True)
    bus83_2 = pp.create_bus(net, vn_kv=0.4, name="bus83_2", in_service=True)

    # lines
    lineP23 = pp.create_line(net,
                             from_bus=bus8,
                             to_bus=bus81,
                             name="lineP23",
                             length_km=0.020,
                             std_type="LV Overhead 14mm",
                             in_service=True)
    lineP24 = pp.create_line(net,
                             from_bus=bus8,
                             to_bus=bus82,
                             name="lineP24",
                             length_km=0.020,
                             std_type="LV Overhead 14mm",
                             in_service=True)
    lineP25 = pp.create_line(net,
                             from_bus=bus83,
                             to_bus=bus83_1,
                             name="lineP25",
                             length_km=0.020,
                             std_type="LV Overhead 14mm",
                             in_service=True)
    lineP26 = pp.create_line(net,
                             from_bus=bus83,
                             to_bus=bus83_2,
                             name="lineP26",
                             length_km=0.020,
                             std_type="LV Overhead 14mm",
                             in_service=True)
    lineT41 = pp.create_line(net,
                             from_bus=bus8,
                             to_bus=bus83,
                             name="lineT41",
                             length_km=0.035,
                             std_type="LV Overhead 50mm Al",
                             in_service=True)
    lineT42 = pp.create_line(net,
                             from_bus=bus83,
                             to_bus=bus834,
                             name="lineT42",
                             length_km=0.035,
                             std_type="LV Overhead 50mm Al",
                             in_service=True)

    # loads
    load15 = pp.create_load_from_cosphi(net,
                                        bus=bus81,
                                        sn_mva=0.002,
                                        cos_phi=0.85,
                                        mode="ind")
    load16 = pp.create_load_from_cosphi(net,
                                        bus=bus82,
                                        sn_mva=0.002,
                                        cos_phi=0.85,
                                        mode="ind")
    load19 = pp.create_load_from_cosphi(net,
                                        bus=bus83_1,
                                        sn_mva=0.002,
                                        cos_phi=0.85,
                                        mode="ind")
    load20 = pp.create_load_from_cosphi(net,
                                        bus=bus83_2,
                                        sn_mva=0.002,
                                        cos_phi=0.85,
                                        mode="ind")
    load17 = pp.create_load_from_cosphi(net,
                                        bus=bus834,
                                        sn_mva=0.002,
                                        cos_phi=0.85,
                                        mode="ind")
    load18 = pp.create_load_from_cosphi(net,
                                        bus=bus834,
                                        sn_mva=0.002,
                                        cos_phi=0.85,
                                        mode="ind")

    # Create PVs
    pp.create_sgens(net,
                    buses=net.load.bus,
                    p_mw=0.005,
                    q_mvar=0,
                    sn_mva=0.005)

    return net
def underground_network():
    net = pp.create_empty_network()

    # LV 300c AI 3,5-C
    pp.create_std_type(
        net,
        {
            "r_ohm_per_km": 0.0958,
            "x_ohm_per_km": 0.07,
            "c_nf_per_km": 330,  #0.33μF,330
            "max_i_ka": 0.42,
            "r0_ohm_per_km": 0.34838,
            "x0_ohm_per_km": 1.2328,
            "type": "cs",
            "temperature_degree_celsius": 20,
        },
        name="LV 300c",
        element="line")

    #  LV 100mm AI OH Line
    pp.create_std_type(net, {
        "r_ohm_per_km": 0.270922,
        "x_ohm_per_km": 0.257383,
        "c_nf_per_km": 0,
        "max_i_ka": 0.271,
        "r0_ohm_per_km": 0.554544,
        "x0_ohm_per_km": 1.030687,
        "c0_nf_per_km": 0,
        "type": "ol",
        "temperature_degree_celsius": 20,
    },
                       name="LV 100mm",
                       element="line")

    # LV 22mm AI O/H Service
    pp.create_std_type(net, {
        "r_ohm_per_km": 1.227056,
        "x_ohm_per_km": 0,
        "c_nf_per_km": 0,
        "max_i_ka": 0.155,
        "r0_ohm_per_km": 1.227056,
        "x0_ohm_per_km": 0,
        "c0_nf_per_km": 0,
        "type": "ol",
        "temperature_degree_celsius": 20,
    },
                       name="LV 22mm",
                       element="line")

    # Substation buses
    SubstationMVbus = pp.create_bus(net,
                                    vn_kv=11,
                                    name="SubMV_Terminal",
                                    in_service=True)
    SubstationLVbus = pp.create_bus(net,
                                    vn_kv=0.4,
                                    name="SubLV_Terminal",
                                    in_service=True)

    # External Grid
    ExternalGrid = pp.create_ext_grid(net, bus=SubstationMVbus, vm_pu=1)

    # Transformer
    Transformer = pp.create_transformer_from_parameters(
        net,
        hv_bus=SubstationMVbus,
        lv_bus=SubstationLVbus,
        name="Dyn11",
        sn_mva=0.63,
        vn_hv_kv=11,
        vn_lv_kv=0.400,
        vkr_percent=0.8571429,
        vk_percent=4,
        pfe_kw=5.4,
        i0_percent=0,
        vk0_percent=3,
        vkr0_percent=0,
        shift_degree=330,
        tap_side="hv",
        tap_step_percent=2.5,
        tap_neutral=3,
        tap_min=1,
        tap_max=5,
        tap_pos=3,
        mag0_rx=4.558264,
        mag0_percent=1.51942,
        vector_group="Dyn",
    )

    # Medium buses
    bus1 = pp.create_bus(net, vn_kv=0.4, name="Med_bus1", in_service=True)
    bus2 = pp.create_bus(net, vn_kv=0.4, name="Med_Bus2", in_service=True)
    bus3 = pp.create_bus(net, vn_kv=0.4, name="Med_Bus3", in_service=True)
    bus4 = pp.create_bus(net, vn_kv=0.4, name="Med_Bus4", in_service=True)
    bus5 = pp.create_bus(net, vn_kv=0.4, name="Med_Bus5", in_service=True)

    # Medium Lines
    LineM1 = pp.create_line(net,
                            from_bus=SubstationLVbus,
                            to_bus=bus1,
                            length_km=0.100,
                            std_type="LV 300c",
                            name="LineM1",
                            in_service=True)
    LineM2 = pp.create_line(net,
                            from_bus=bus1,
                            to_bus=bus2,
                            length_km=0.022,
                            std_type="LV 300c",
                            name="LineM2",
                            in_service=True)
    LineM3 = pp.create_line(net,
                            from_bus=bus2,
                            to_bus=bus3,
                            length_km=0.077,
                            std_type="LV 100mm",
                            name="LineM3",
                            in_service=True)
    LineM4 = pp.create_line(net,
                            from_bus=bus3,
                            to_bus=bus4,
                            length_km=0.070,
                            std_type="LV 100mm",
                            name="LineM4",
                            in_service=True)
    LineM5 = pp.create_line(net,
                            from_bus=bus4,
                            to_bus=bus5,
                            length_km=0.030,
                            std_type="LV 100mm",
                            name="LineM5",
                            in_service=True)
    """     Buses, lines and loads from BUS1    """
    # buses
    bus11 = pp.create_bus(net, vn_kv=0.4, name="bus11", in_service=True)
    bus12 = pp.create_bus(net, vn_kv=0.4, name="bus12", in_service=True)
    bus13 = pp.create_bus(net, vn_kv=0.4, name="bus13", in_service=True)
    bus12_1 = pp.create_bus(net, vn_kv=0.4, name="bus12_1", in_service=True)
    bus12_2 = pp.create_bus(net, vn_kv=0.4, name="bus12_2", in_service=True)
    bus13_1 = pp.create_bus(net, vn_kv=0.4, name="bus13_1", in_service=True)
    bus13_2 = pp.create_bus(net, vn_kv=0.4, name="bus13_2", in_service=True)

    # lines from bus to bus
    Line11 = pp.create_line(net,
                            from_bus=bus1,
                            to_bus=bus11,
                            length_km=0.014,
                            name="Line11",
                            std_type="LV 22mm",
                            in_service=True)
    Line12 = pp.create_line(net,
                            from_bus=bus1,
                            to_bus=bus12,
                            length_km=0.052,
                            name="Line12",
                            std_type="LV 100mm",
                            in_service=True)
    Line123 = pp.create_line(net,
                             from_bus=bus12,
                             to_bus=bus13,
                             length_km=0.052,
                             name="Line23",
                             std_type="LV 100mm",
                             in_service=True)

    # lines from bus12 to loads
    Line12_1 = pp.create_line(net,
                              from_bus=bus12,
                              to_bus=bus12_1,
                              length_km=0.014,
                              name="Line2_1",
                              std_type="LV 22mm",
                              in_service=True)
    Line12_2 = pp.create_line(net,
                              from_bus=bus12,
                              to_bus=bus12_2,
                              length_km=0.014,
                              name="Line2_2",
                              std_type="LV 22mm",
                              in_service=True)

    # lines from bus13 to loads
    Line13_1 = pp.create_line(net,
                              from_bus=bus13,
                              to_bus=bus13_1,
                              length_km=0.014,
                              name="Line3_1",
                              std_type="LV 22mm",
                              in_service=True)
    Line13_2 = pp.create_line(net,
                              from_bus=bus13,
                              to_bus=bus13_2,
                              length_km=0.014,
                              name="Line3_2",
                              std_type="LV 22mm",
                              in_service=True)

    # loads
    Load11 = pp.create_load_from_cosphi(net,
                                        bus=bus11,
                                        sn_mva=0.002,
                                        cos_phi=0.85,
                                        mode="ind")
    Load121 = pp.create_load_from_cosphi(net,
                                         bus=bus12_1,
                                         sn_mva=0.002,
                                         cos_phi=0.85,
                                         mode="ind")
    Load122 = pp.create_load_from_cosphi(net,
                                         bus=bus12_2,
                                         sn_mva=0.002,
                                         cos_phi=0.85,
                                         mode="ind")
    Load131 = pp.create_load_from_cosphi(net,
                                         bus=bus13_1,
                                         sn_mva=0.002,
                                         cos_phi=0.85,
                                         mode="ind")
    Load132 = pp.create_load_from_cosphi(net,
                                         bus=bus13_2,
                                         sn_mva=0.002,
                                         cos_phi=0.85,
                                         mode="ind")

    Load132_ = pp.create_load_from_cosphi(net,
                                          bus=bus13_1,
                                          sn_mva=0.002,
                                          cos_phi=0.85,
                                          mode="ind")
    """     Buses, lines and loads from BUS2    """
    # buses
    bus21 = pp.create_bus(net, vn_kv=0.4, name="bus21", in_service=True)
    bus22 = pp.create_bus(net, vn_kv=0.4, name="bus22", in_service=True)

    # lines
    Line21 = pp.create_line(net,
                            from_bus=bus2,
                            to_bus=bus21,
                            length_km=0.014,
                            std_type="LV 22mm",
                            name="Line21",
                            in_service=True)
    Line22 = pp.create_line(net,
                            from_bus=bus2,
                            to_bus=bus22,
                            length_km=0.014,
                            std_type="LV 22mm",
                            name="Line22",
                            in_service=True)

    # loads
    Load21 = pp.create_load_from_cosphi(net,
                                        bus=bus21,
                                        sn_mva=0.002,
                                        cos_phi=0.85,
                                        mode="ind")
    Load22 = pp.create_load_from_cosphi(net,
                                        bus=bus22,
                                        sn_mva=0.002,
                                        cos_phi=0.85,
                                        mode="ind")
    """     Buses, lines and loads from BUS3    """
    # buses
    bus31 = pp.create_bus(net, vn_kv=0.4, name="bus31", in_service=True)
    bus32 = pp.create_bus(net, vn_kv=0.4, name="bus32", in_service=True)
    bus33 = pp.create_bus(net, vn_kv=0.4, name="bus33", in_service=True)

    bus32_1 = pp.create_bus(net, vn_kv=0.4, name="bus32_1", in_service=True)
    bus32_2 = pp.create_bus(net, vn_kv=0.4, name="bus32_2", in_service=True)

    bus33_1 = pp.create_bus(net, vn_kv=0.4, name="bus33_1", in_service=True)
    bus33_2 = pp.create_bus(net, vn_kv=0.4, name="bus33_2", in_service=True)

    # lines from bus to bus
    Line32 = pp.create_line(net,
                            from_bus=bus3,
                            to_bus=bus32,
                            length_km=0.052,
                            std_type="LV 100mm",
                            name="Line32",
                            in_service=True)
    Line323 = pp.create_line(net,
                             from_bus=bus32,
                             to_bus=bus33,
                             length_km=0.052,
                             std_type="LV 100mm",
                             name="Line33",
                             in_service=True)

    #lines from buses to loads
    Line31 = pp.create_line(net,
                            from_bus=bus3,
                            to_bus=bus31,
                            length_km=0.014,
                            std_type="LV 22mm",
                            name="line31",
                            in_service=True)

    Line32_1 = pp.create_line(net,
                              from_bus=bus32,
                              to_bus=bus32_1,
                              length_km=0.014,
                              std_type="LV 22mm",
                              name="line32_1",
                              in_service=True)
    Line32_2 = pp.create_line(net,
                              from_bus=bus32,
                              to_bus=bus32_2,
                              length_km=0.014,
                              std_type="LV 22mm",
                              name="line32_2",
                              in_service=True)

    Line33_1 = pp.create_line(net,
                              from_bus=bus33,
                              to_bus=bus33_1,
                              length_km=0.014,
                              std_type="LV 22mm",
                              name="line33_1",
                              in_service=True)
    Line33_2 = pp.create_line(net,
                              from_bus=bus33,
                              to_bus=bus33_2,
                              length_km=0.014,
                              std_type="LV 22mm",
                              name="line33_2",
                              in_service=True)

    #loads
    Load31 = pp.create_load_from_cosphi(net,
                                        bus=bus31,
                                        sn_mva=0.002,
                                        cos_phi=0.85,
                                        mode="ind")

    Load321 = pp.create_load_from_cosphi(net,
                                         bus=bus32_1,
                                         sn_mva=0.002,
                                         cos_phi=0.85,
                                         mode="ind")
    Load322 = pp.create_load_from_cosphi(net,
                                         bus=bus32_2,
                                         sn_mva=0.002,
                                         cos_phi=0.85,
                                         mode="ind")
    Load331 = pp.create_load_from_cosphi(net,
                                         bus=bus33_1,
                                         sn_mva=0.002,
                                         cos_phi=0.85,
                                         mode="ind")
    Load332 = pp.create_load_from_cosphi(net,
                                         bus=bus33_2,
                                         sn_mva=0.002,
                                         cos_phi=0.85,
                                         mode="ind")

    Load332_ = pp.create_load_from_cosphi(net,
                                          bus=bus33_2,
                                          sn_mva=0.002,
                                          cos_phi=0.85,
                                          mode="ind")
    """     Buses, lines and loads from BUS4    """
    # buses
    bus41 = pp.create_bus(net, vn_kv=0.4, name="bus41", in_service=True)
    bus42 = pp.create_bus(net, vn_kv=0.4, name="bus42", in_service=True)

    # lines
    Line41 = pp.create_line(net,
                            from_bus=bus4,
                            to_bus=bus41,
                            length_km=0.014,
                            std_type="LV 22mm",
                            name="Line41",
                            in_service=True)
    Line42 = pp.create_line(net,
                            from_bus=bus4,
                            to_bus=bus42,
                            length_km=0.014,
                            std_type="LV 22mm",
                            name="Line42",
                            in_service=True)

    #loads
    Load41 = pp.create_load_from_cosphi(net,
                                        bus=bus41,
                                        sn_mva=0.002,
                                        cos_phi=0.85,
                                        mode="ind")
    Load42 = pp.create_load_from_cosphi(net,
                                        bus=bus42,
                                        sn_mva=0.002,
                                        cos_phi=0.85,
                                        mode="ind")
    """     Buses, lines and loads from BUS5    """
    #buses
    bus51 = pp.create_bus(net, vn_kv=0.4, name="bus51", in_service=True)
    bus52 = pp.create_bus(net, vn_kv=0.4, name="bus52", in_service=True)
    bus53 = pp.create_bus(net, vn_kv=0.4, name="bus53", in_service=True)

    bus52_1 = pp.create_bus(net, vn_kv=0.4, name="bus52_1", in_service=True)
    bus52_2 = pp.create_bus(net, vn_kv=0.4, name="bus52_2", in_service=True)
    bus53_1 = pp.create_bus(net, vn_kv=0.4, name="bus53_1", in_service=True)
    bus53_2 = pp.create_bus(net, vn_kv=0.4, name="bus53_2", in_service=True)

    #lines from bus to bus
    Line52 = pp.create_line(net,
                            from_bus=bus5,
                            to_bus=bus52,
                            length_km=0.052,
                            std_type="LV 100mm",
                            name="Line52",
                            in_service=True)
    Line523 = pp.create_line(net,
                             from_bus=bus52,
                             to_bus=bus53,
                             length_km=0.052,
                             std_type="LV 100mm",
                             name="Line53",
                             in_service=True)

    # lines from buses to loads
    Line51 = pp.create_line(net,
                            from_bus=bus5,
                            to_bus=bus51,
                            length_km=0.014,
                            std_type="LV 22mm",
                            name="Line51",
                            in_service=True)
    Line52_1 = pp.create_line(net,
                              from_bus=bus52,
                              to_bus=bus52_1,
                              length_km=0.014,
                              std_type="LV 22mm",
                              name="Line52_1",
                              in_service=True)
    Line52_2 = pp.create_line(net,
                              from_bus=bus52,
                              to_bus=bus52_2,
                              length_km=0.014,
                              std_type="LV 22mm",
                              name="Line52_2",
                              in_service=True)
    Line53_1 = pp.create_line(net,
                              from_bus=bus53,
                              to_bus=bus53_1,
                              length_km=0.014,
                              std_type="LV 22mm",
                              name="Line53_1",
                              in_service=True)
    Line53_2 = pp.create_line(net,
                              from_bus=bus53,
                              to_bus=bus53_2,
                              length_km=0.014,
                              std_type="LV 22mm",
                              name="Line53_2",
                              in_service=True)

    # loads
    Load51 = pp.create_load_from_cosphi(net,
                                        bus=bus51,
                                        sn_mva=0.002,
                                        cos_phi=0.85,
                                        mode="ind")

    Load521 = pp.create_load_from_cosphi(net,
                                         bus=bus52_1,
                                         sn_mva=0.002,
                                         cos_phi=0.85,
                                         mode="ind")
    Load522 = pp.create_load_from_cosphi(net,
                                         bus=bus52_2,
                                         sn_mva=0.002,
                                         cos_phi=0.85,
                                         mode="ind")
    Load531 = pp.create_load_from_cosphi(net,
                                         bus=bus53_1,
                                         sn_mva=0.002,
                                         cos_phi=0.85,
                                         mode="ind")
    Load532 = pp.create_load_from_cosphi(net,
                                         bus=bus53_2,
                                         sn_mva=0.002,
                                         cos_phi=0.85,
                                         mode="ind")

    Load532_ = pp.create_load_from_cosphi(net,
                                          bus=bus53_2,
                                          sn_mva=0.002,
                                          cos_phi=0.85,
                                          mode="ind")

    return net