Ejemplo n.º 1
0
def test_overloaded_lines():
    net = pp.create_empty_network()

    bus0 = pp.create_bus(net, vn_kv=.4)
    bus1 = pp.create_bus(net, vn_kv=.4)

    ext_grid0 = pp.create_ext_grid(net, bus0, vm_pu=4)

    line0 = pp.create_line(net,
                           bus0,
                           bus1,
                           length_km=1,
                           std_type="NAYY 4x50 SE")
    line1 = pp.create_line(net,
                           bus0,
                           bus1,
                           length_km=1,
                           std_type="NA2XS2Y 1x95 RM/25 12/20 kV")
    line2 = pp.create_line(net,
                           bus0,
                           bus1,
                           length_km=1,
                           std_type="15-AL1/3-ST1A 0.4")
    line3 = pp.create_line(net,
                           bus0,
                           bus1,
                           length_km=10,
                           std_type="149-AL1/24-ST1A 10.0")

    pp.runpp(net)

    # test the overloaded lines by default value of max_load=100
    overloaded_lines = tb.overloaded_lines(net, max_load=100)

    assert set(overloaded_lines) == set([line0, line1, line2])

    # test the overloaded lines by a self defined value of max_load=50
    overloaded_lines = tb.overloaded_lines(net, max_load=50)

    assert set(overloaded_lines) == set([line0, line1, line2, line3])
Ejemplo n.º 2
0
def test_get_costs():
    """ Testing a very simple network for the resulting cost value
    constraints with OPF """

    # boundaries:
    vm_max = 1.05
    vm_min = 0.95

    # create net
    net = pp.create_empty_network()
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=10.)
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=.4)
    pp.create_gen(net,
                  1,
                  p_mw=0.1,
                  controllable=True,
                  min_p_mw=0.05,
                  max_p_mw=0.15,
                  max_q_mvar=0.05,
                  min_q_mvar=-0.05)
    pp.create_ext_grid(net, 0)
    pp.create_load(net, 1, p_mw=0.02, controllable=False)
    pp.create_line_from_parameters(net,
                                   0,
                                   1,
                                   50,
                                   name="line2",
                                   r_ohm_per_km=0.876,
                                   c_nf_per_km=260.0,
                                   max_i_ka=0.123,
                                   x_ohm_per_km=0.1159876,
                                   max_loading_percent=100 * 690)

    pp.create_pwl_cost(net, 0, "gen", [[0, 150, 2]])
    # run OPF
    pp.runopp(net)

    assert net["OPF_converged"]
    assert net.res_gen.p_mw.values[0] - net.gen.min_p_mw.values[0] < 1e-2
    assert np.isclose(net.res_cost, 2 * net.res_gen.p_mw.values[0])
Ejemplo n.º 3
0
def panda_four_load_branch():
    """
    This function creates a simple six bus system with four radial low voltage nodes connected to \
    a medium voltage slack bus. At every low voltage node the same load is connected.

    OUTPUT:
         **net** - Returns the required four load system

    EXAMPLE:
         import pandapower.networks as pn

         net_four_load = pn.panda_four_load_branch()
    """
    net = pp.create_empty_network()

    busnr1 = pp.create_bus(net, name="bus1", vn_kv=10., geodata=[0, 0])
    busnr2 = pp.create_bus(net, name="bus2", vn_kv=.4, geodata=[0, -1])
    busnr3 = pp.create_bus(net, name="bus3", vn_kv=.4, geodata=[0, -2])
    busnr4 = pp.create_bus(net, name="bus4", vn_kv=.4, geodata=[0, -3])
    busnr5 = pp.create_bus(net, name="bus5", vn_kv=.4, geodata=[0, -4])
    busnr6 = pp.create_bus(net, name="bus6", vn_kv=.4, geodata=[0, -5])

    pp.create_ext_grid(net, busnr1)

    pp.create_transformer(net, busnr1, busnr2, std_type="0.25 MVA 10/0.4 kV")

    pp.create_line(net,  busnr2, busnr3, name="line1", length_km=0.05,
                   std_type="NAYY 4x120 SE")
    pp.create_line(net, busnr3, busnr4, name="line2", length_km=0.05,
                   std_type="NAYY 4x120 SE")
    pp.create_line(net, busnr4, busnr5, name="line3", length_km=0.05,
                   std_type="NAYY 4x120 SE")
    pp.create_line(net, busnr5, busnr6, name="line4", length_km=0.05,
                   std_type="NAYY 4x120 SE")

    pp.create_load(net, busnr3, 0.030, 0.010)
    pp.create_load(net, busnr4, 0.030, 0.010)
    pp.create_load(net, busnr5, 0.030, 0.010)
    pp.create_load(net, busnr6, 0.030, 0.010)
    return net
Ejemplo n.º 4
0
def test_cost_piecewise_linear_sgen_very_unsteady_slopes():
    """ Testing a very simple network for the resulting cost value
    constraints with OPF """

    # boundaries:
    vm_max = 1.5
    vm_min = 0.5

    # create net
    net = pp.create_empty_network()
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=10.)
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=.4)
    pp.create_sgen(net,
                   1,
                   p_mw=0.10,
                   controllable=True,
                   min_p_mw=0,
                   max_p_mw=1.50,
                   max_q_mvar=0.05,
                   min_q_mvar=-0.05)
    pp.create_ext_grid(net, 0)
    pp.create_load(net, 1, p_mw=0.02, controllable=False)
    pp.create_line_from_parameters(net,
                                   0,
                                   1,
                                   50,
                                   name="line2",
                                   r_ohm_per_km=0.876,
                                   c_nf_per_km=260.0,
                                   max_i_ka=0.123,
                                   x_ohm_per_km=0.1159876,
                                   max_loading_percent=100 * 690)

    pp.create_pwl_cost(net, 0, "sgen", [[0, 0.75, -1], [0.75, 1500, 2]])
    # run OPF
    pp.runopp(net)

    assert net["OPF_converged"]
    assert np.isclose(net.res_sgen.p_mw.values[0], .75, rtol=1e-2)
    assert np.isclose(net.res_sgen.p_mw.values[0], -net.res_cost, rtol=1e-2)
Ejemplo n.º 5
0
def test_ext_grid_gen_order_in_ppc():
    net=pp.create_empty_network()

    for b in range(6):
        pp.create_bus(net,vn_kv=1., name=b)

    for l_bus in range(0,5,2):
        pp.create_line(net, from_bus=l_bus, to_bus=l_bus+1, length_km=1, std_type="48-AL1/8-ST1A 10.0")

    for slack_bus in [0,2,5]:
        pp.create_ext_grid(net, bus=slack_bus, vm_pu=1.)

    for gen_bus in [ 0, 1, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5]:
        pp.create_gen(net, bus=gen_bus, p_mw=1, vm_pu=1.)

    pp.rundcpp(net)
    assert all(net.res_gen.p_mw==net.gen.p_mw)
    assert all(net.res_ext_grid.p_mw<0)

    pp.runpp(net)
    assert all(net.res_gen.p_mw==net.gen.p_mw)
    assert all(net.res_ext_grid.p_mw<0)
Ejemplo n.º 6
0
def test_dc_with_ext_grid_at_one_bus():
    net = pp.create_empty_network()
    b1 = pp.create_bus(net, vn_kv=110)
    b2 = pp.create_bus(net, vn_kv=110)

    pp.create_ext_grid(net, b1, vm_pu=1.01)
    pp.create_ext_grid(net, b2, vm_pu=1.01)

    pp.create_dcline(net,
                     from_bus=b1,
                     to_bus=b2,
                     p_mw=10,
                     loss_percent=0,
                     loss_mw=0,
                     vm_from_pu=1.01,
                     vm_to_pu=1.01)

    pp.create_sgen(net, b1, p_mw=10)
    pp.create_load(net, b2, p_mw=10)

    runpp_with_consistency_checks(net)
    assert np.allclose(net.res_ext_grid.p_mw.values, [0, 0])
Ejemplo n.º 7
0
def test_runpp_init_auxiliary_buses():
    net = pp.create_empty_network()
    b1, b2, l1 = add_grid_connection(net, vn_kv=110.)
    b3 = pp.create_bus(net, vn_kv=20.)
    b4 = pp.create_bus(net, vn_kv=10.)
    tidx = pp.create_transformer3w(net,
                                   b2,
                                   b3,
                                   b4,
                                   std_type='63/25/38 MVA 110/20/10 kV')
    pp.create_load(net, b3, p_mw=5)
    pp.create_load(net, b4, p_mw=5)
    pp.create_xward(net,
                    b4,
                    ps_mw=1,
                    qs_mvar=1,
                    pz_mw=1,
                    qz_mvar=1,
                    r_ohm=0.1,
                    x_ohm=0.1,
                    vm_pu=1.0)
    net.trafo3w.shift_lv_degree.at[tidx] = 120
    net.trafo3w.shift_mv_degree.at[tidx] = 80
    pp.runpp(net)
    va = net.res_bus.va_degree.at[b2]
    pp.runpp(net, calculate_voltage_angles=True, init_va_degree="dc")
    assert np.allclose(va - net.trafo3w.shift_mv_degree.at[tidx],
                       net.res_bus.va_degree.at[b3],
                       atol=2)
    assert np.allclose(va - net.trafo3w.shift_lv_degree.at[tidx],
                       net.res_bus.va_degree.at[b4],
                       atol=2)
    pp.runpp(net, calculate_voltage_angles=True, init_va_degree="results")
    assert np.allclose(va - net.trafo3w.shift_mv_degree.at[tidx],
                       net.res_bus.va_degree.at[b3],
                       atol=2)
    assert np.allclose(va - net.trafo3w.shift_lv_degree.at[tidx],
                       net.res_bus.va_degree.at[b4],
                       atol=2)
Ejemplo n.º 8
0
def test_mixed_p_q_pol():
    vm_max = 1.05
    vm_min = 0.95

    # create net
    net = pp.create_empty_network()
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=10.)
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=.4)
    pp.create_gen(net, 1, p_mw=0.1, controllable=True, min_p_mw=0.005, max_p_mw=0.15, max_q_mvar=.05,
                  min_q_mvar=-.05)
    pp.create_ext_grid(net, 0)
    pp.create_load(net, 1, p_mw=0.02, controllable=False, max_q_mvar=.05, max_p_mw=0.1, min_p_mw=0.0050,
                   min_q_mvar=-.05)
    pp.create_line_from_parameters(net, 0, 1, 50, name="line2", r_ohm_per_km=0.876,
                                   c_nf_per_km=260.0, max_i_ka=0.123, x_ohm_per_km=0.1159876,
                                   max_loading_percent=100 * 690)

    # testing some combinations
    pp.create_poly_cost(net, 0, "gen", cp1_eur_per_mw=1, cq1_eur_per_mvar=1)
    pp.runopp(net)
    assert net["OPF_converged"]
    assert np.isclose(net.res_cost, (net.res_gen.p_mw.values + net.res_gen.q_mvar.values))
Ejemplo n.º 9
0
def recycle_net():
    net = pp.create_empty_network()
    b1, b2, ln = add_grid_connection(net)
    pl = 1.2
    ql = 1.1
    ps = 0.5
    u_set = 1.0

    b3 = pp.create_bus(net, vn_kv=.4)
    pp.create_bus(net, vn_kv=.4, in_service=False)
    pp.create_line_from_parameters(net,
                                   b2,
                                   b3,
                                   12.2,
                                   r_ohm_per_km=0.08,
                                   x_ohm_per_km=0.12,
                                   c_nf_per_km=300,
                                   max_i_ka=.2,
                                   df=.8)
    pp.create_load(net, b3, p_mw=pl, q_mvar=ql)
    pp.create_gen(net, b2, p_mw=ps, vm_pu=u_set)
    return net
Ejemplo n.º 10
0
def test_create_sgens_raise_except():
    net = pp.create_empty_network()
    # standard
    b1 = pp.create_bus(net, 110)
    b2 = pp.create_bus(net, 110)
    b3 = pp.create_bus(net, 110)

    with pytest.raises(UserWarning, match=r"Cannot attach to buses \{3, 4, 5\}, they do not exist"):
        pp.create_sgens(
            net, buses=[3, 4, 5], p_mw=[0, 0, 1], q_mwar=0., controllable=[True, False, False],
            max_p_mw=0.2, min_p_mw=[0, 0.1, 0], max_q_mvar=0.2, min_q_mvar=[0, 0.1, 0], k=1.3,
            rx=0.4, current_source=True)

    sg = pp.create_sgens(
        net, buses=[b1, b2, b3], p_mw=[0, 0, 1], q_mwar=0., controllable=[True, False, False],
        max_p_mw=0.2, min_p_mw=[0, 0.1, 0], max_q_mvar=0.2, min_q_mvar=[0, 0.1, 0], k=1.3, rx=0.4,
        current_source=True)
    with pytest.raises(UserWarning, match=r"Sgens with indexes \[0 1 2\] already exist"):
        pp.create_sgens(
            net, buses=[b1, b2, b3], p_mw=[0, 0, 1], q_mwar=0., controllable=[True, False, False],
            max_p_mw=0.2, min_p_mw=[0, 0.1, 0], max_q_mvar=0.2, min_q_mvar=[0, 0.1, 0], k=1.3,
            rx=0.4, current_source=True, index=sg)
Ejemplo n.º 11
0
def test_cost_piecewise_linear_eg():
    """ Testing a very simple network for the resulting cost value
    constraints with OPF """

    # boundaries:
    vm_max = 1.05
    vm_min = 0.95

    # create net
    net = pp.create_empty_network()
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=10.)
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=10)
    pp.create_ext_grid(net, 0, max_p_kw=0, min_p_kw=-50)
    pp.create_gen(net,
                  1,
                  p_kw=-10,
                  max_p_kw=0,
                  min_p_kw=-50,
                  controllable=True)
    # pp.create_ext_grid(net, 0)
    pp.create_load(net, 1, p_kw=20, controllable=False)
    pp.create_line_from_parameters(net,
                                   0,
                                   1,
                                   50,
                                   name="line2",
                                   r_ohm_per_km=0.876,
                                   c_nf_per_km=260.0,
                                   max_i_ka=0.123,
                                   x_ohm_per_km=0.1159876,
                                   max_loading_percent=100 * 690)

    pp.create_piecewise_linear_cost(net, 0, "ext_grid",
                                    np.array([[-50, -500], [0, 0]]))
    # run OPF
    pp.runopp(net, verbose=False)

    assert net["OPF_converged"]
    assert net.res_cost - -net.res_ext_grid.p_kw.values * 10 < 1e-3
def test_net_no_load():
    # Reference power in the s generator
    psg1 = 163
    psg2 = 85
    net = pp.create_empty_network()
    pp.set_user_pf_options(net,
                           init_vm_pu="flat",
                           init_va_degree="dc",
                           calculate_voltage_angles=True)

    b0 = pp.create_bus(net, p_mw=0, q_mw=0, vn_kv=110, name="bus0")
    b1 = pp.create_bus(net, p_mw=163, q_mw=0, vn_kv=110, name="bus1")
    b2 = pp.create_bus(net, p_mw=85, q_mw=0, vn_kv=110, name="bus2")
    b3 = pp.create_bus(net, vn_kv=110, name="bus3")
    b4 = pp.create_bus(net, p_mw=90, q_mw=30, vn_kv=110, name="bus4")
    b5 = pp.create_bus(net, vn_kv=110, name="bus5")
    b6 = pp.create_bus(net, p_mw=100, q_mw=35, vn_kv=110, name="bus6")
    b7 = pp.create_bus(net, vn_kv=110, name="bus7")
    b8 = pp.create_bus(net, p_mw=125, q_mw=50, vn_kv=110, name="bus8")

    pp.create_line(net, b0, b3, 10, "149-AL1/24-ST1A 110.0")
    pp.create_line(net, b1, b7, 10, "149-AL1/24-ST1A 110.0")
    pp.create_line(net, b3, b8, 10, "149-AL1/24-ST1A 110.0")
    pp.create_line(net, b7, b8, 10, "149-AL1/24-ST1A 110.0")
    pp.create_line(net, b3, b4, 10, "149-AL1/24-ST1A 110.0")
    pp.create_line(net, b7, b8, 10, "149-AL1/24-ST1A 110.0")
    pp.create_line(net, b5, b6, 10, "149-AL1/24-ST1A 110.0")
    pp.create_line(net, b5, b4, 10, "149-AL1/24-ST1A 110.0")
    pp.create_line(net, b2, b5, 10, "149-AL1/24-ST1A 110.0")

    pp.create_load(net, b4, p_mw=90, q_mvar=30, name='load1')
    #pp.create_load(net, b6, p_mw=125, q_mvar=50, name='load2')
    pp.create_load(net, b8, p_mw=100, q_mvar=35, name='load3')

    pp.create_gen(net, b0, p_mw=0, name='gen1', slack=True)
    pp.create_sgen(net, b1, p_mw=psg1, q_mvar=0, name='sgen1')
    pp.create_sgen(net, b2, p_mw=psg2, q_mvar=0, name='sgen2')

    return net
Ejemplo n.º 13
0
def motor_net():
    net = pp.create_empty_network(sn_mva=10)
    b1 = pp.create_bus(net, vn_kv=0.4)
    b2 = pp.create_bus(net, vn_kv=0.4)
    b3 = pp.create_bus(net, vn_kv=0.4)
    pp.create_ext_grid(net,
                       b1,
                       s_sc_max_mva=10.,
                       rx_max=0.1,
                       s_sc_min_mva=8.,
                       rx_min=0.1)
    pp.create_line_from_parameters(net,
                                   from_bus=b1,
                                   to_bus=b2,
                                   length_km=1.,
                                   r_ohm_per_km=0.32,
                                   c_nf_per_km=0,
                                   x_ohm_per_km=0.07,
                                   max_i_ka=1,
                                   endtemp_degree=80)
    pp.create_motor(net,
                    b2,
                    pn_mech_mw=0.5,
                    lrc_pu=7.,
                    vn_kv=0.45,
                    rx=0.4,
                    efficiency_n_percent=95,
                    cos_phi_n=0.9,
                    cos_phi=0.9)
    pp.create_line_from_parameters(net,
                                   from_bus=b2,
                                   to_bus=b3,
                                   length_km=2.,
                                   r_ohm_per_km=0.32,
                                   c_nf_per_km=0,
                                   x_ohm_per_km=0.07,
                                   max_i_ka=1,
                                   endtemp_degree=80)
    return net
Ejemplo n.º 14
0
def net():
    v_base = 110  # 110kV Base Voltage
    k_va_base = 100  # 100 MVA
    #    I_base = (kVA_base/V_base) * 1e-3           # in kA
    net = pp.create_empty_network(sn_mva=k_va_base)
    pp.create_bus(net, vn_kv=v_base, index=1)
    pp.create_bus(net, vn_kv=v_base, index=5)
    pp.create_ext_grid(net,
                       bus=1,
                       vm_pu=1.0,
                       s_sc_max_mva=5000,
                       rx_max=0.1,
                       r0x0_max=0.1,
                       x0x_max=1.0)
    pp.create_std_type(
        net, {
            "r0_ohm_per_km": 0.0848,
            "x0_ohm_per_km": 0.4649556,
            "c0_nf_per_km": 230.6,
            "max_i_ka": 0.963,
            "r_ohm_per_km": 0.0212,
            "x_ohm_per_km": 0.1162389,
            "c_nf_per_km": 230
        }, "example_type")
    pp.create_line(net,
                   from_bus=1,
                   to_bus=5,
                   length_km=50.0,
                   std_type="example_type")

    pp.create_asymmetric_load(net,
                              5,
                              p_a_mw=50,
                              q_a_mvar=50,
                              p_b_mw=10,
                              q_b_mvar=15,
                              p_c_mw=10,
                              q_c_mvar=5)
    return net
Ejemplo n.º 15
0
def _create_empty_network_with_transformer(trafotype, V_OS=10., V_US=0.4):
    """
    Creates a Network with transformer and infeeder. The reference bus on the \
    high-voltage side is called "Trafostation_OS". The bus on the low-voltage \
    side is called "main_busbar".
    The voltage levels can be set manually and the transformer parameter can \
    be set with "ti"
    """
    pd_net = pp.create_empty_network()
    NFA2X4x70 = {"c_nf_per_km": 0, "r_ohm_per_km": 0.443, "x_ohm_per_km": 0.069, "max_i_ka": 0.270,
                 "type": "ol", "q_mm2": 70}
    NAYY4x50 = {"c_nf_per_km": 670, "r_ohm_per_km": 0.6417, "x_ohm_per_km": 0.084823,
                "max_i_ka": 0.141, "type": "cs", "q_mm2": 50}
    NAYY4x150 = {"c_nf_per_km": 830, "r_ohm_per_km": 0.2067, "x_ohm_per_km": 0.08042478,
                 "max_i_ka": 0.275, "type": "cs", "q_mm2": 150}
    NAYY4x185 = {"c_nf_per_km": 830, "r_ohm_per_km": 0.165, "x_ohm_per_km": 0.08042478,
                 "max_i_ka": 0.313, "type": "cs", "q_mm2": 185}
    NYY4x35 = {"c_nf_per_km": 0, "r_ohm_per_km": 0.5240284, "x_ohm_per_km": 0.08513716,
               "max_i_ka": 0.156, "type": "cs", "q_mm2": 35}
    pp.create_std_type(net=pd_net, data=NFA2X4x70, name="NFA2X 4x70", element="line")
    pp.create_std_type(net=pd_net, data=NAYY4x50, name="NAYY 4x50", element="line")
    pp.create_std_type(net=pd_net, data=NAYY4x150, name="NAYY 4x150", element="line")
    pp.create_std_type(net=pd_net, data=NAYY4x185, name="NAYY 4x185", element="line")
    pp.create_std_type(net=pd_net, data=NYY4x35, name="NYY 4x35", element="line")
    T100kVA = {"sn_mva": 0.100, "vn_hv_kv": 10, "vn_lv_kv": 0.4, "vk_percent": 4,
               "vkr_percent": 1.2, "pfe_kw": 0.45, "i0_percent": 0.25, "shift_degree": 150,
               "vector_group": "Dyn5"}
    T160kVA = {"sn_mva": 0.160, "vn_hv_kv": 10, "vn_lv_kv": 0.4, "vk_percent": 4,
               "vkr_percent": 1.2, "pfe_kw": 0.38, "i0_percent": 0.26, "shift_degree": 150,
               "vector_group": "Dyn5"}
    pp.create_std_type(net=pd_net, data=T100kVA, name="0.1 MVA 10/0.4 kV", element="trafo")
    pp.create_std_type(net=pd_net, data=T160kVA, name="0.16 MVA 10/0.4 kV", element="trafo")

    busnr1 = pp.create_bus(pd_net, name="Trafostation_OS", vn_kv=V_OS)
    pp.create_ext_grid(pd_net, bus=busnr1)
    main_busbar_nr = pp.create_bus(pd_net, name="main_busbar", vn_kv=V_US, type="b")
    pp.create_transformer(pd_net, hv_bus=busnr1, lv_bus=main_busbar_nr, std_type=trafotype,
                          name="trafo 1")
    return pd_net, main_busbar_nr
Ejemplo n.º 16
0
def test_cost_piecewise_linear_load_uneven_slopes():
    """ Testing a very simple network for the resulting cost value
    constraints with OPF """

    # boundaries:
    vm_max = 1.05
    vm_min = 0.95

    # create net
    net = pp.create_empty_network()
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=10.)
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=.4)
    pp.create_load(net,
                   1,
                   p_kw=100,
                   controllable=True,
                   max_p_kw=150,
                   min_p_kw=50,
                   max_q_kvar=0,
                   min_q_kvar=0)
    pp.create_ext_grid(net, 0)
    pp.create_line_from_parameters(net,
                                   0,
                                   1,
                                   50,
                                   name="line2",
                                   r_ohm_per_km=0.876,
                                   c_nf_per_km=260.0,
                                   max_i_ka=0.123,
                                   x_ohm_per_km=0.1159876,
                                   max_loading_percent=100 * 690)

    pp.create_piecewise_linear_cost(net, 0, "load",
                                    np.array([[0, 0], [75, 51], [150, 101]]))
    # run OPF
    with pytest.raises(OPFNotConverged):
        pp.runopp(net, verbose=False)
        assert net["OPF_converged"]
        assert abs(net.res_cost - net.res_load.p_kw.values / 1.5) < 1e-3
Ejemplo n.º 17
0
def test_cost_piecewise_linear_sgen_very_unsteady_slopes():
    """ Testing a very simple network for the resulting cost value
    constraints with OPF """

    # boundaries:
    vm_max = 1.5
    vm_min = 0.5

    # create net
    net = pp.create_empty_network()
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=10.)
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=.4)
    pp.create_sgen(net,
                   1,
                   p_kw=-1000,
                   controllable=True,
                   max_p_kw=0,
                   min_p_kw=-1500,
                   max_q_kvar=50,
                   min_q_kvar=-50)
    pp.create_ext_grid(net, 0)
    pp.create_load(net, 1, p_kw=20, controllable=False)
    pp.create_line_from_parameters(net,
                                   0,
                                   1,
                                   50,
                                   name="line2",
                                   r_ohm_per_km=0.876,
                                   c_nf_per_km=260.0,
                                   max_i_ka=0.123,
                                   x_ohm_per_km=0.1159876,
                                   max_loading_percent=100 * 690)

    pp.create_piecewise_linear_cost(net, 0, "sgen",
                                    np.array([[-1500, 2], [-750, 1], [0, 2]]))
    # run OPF
    pp.runopp(net, verbose=False)

    assert net["OPF_converged"]
Ejemplo n.º 18
0
def test_network_with_trafo3w_pq():
    net = pp.create_empty_network()

    bus_slack = pp.create_bus(net, vn_kv=110)
    pp.create_ext_grid(net, bus=bus_slack)

    bus_20_1 = pp.create_bus(net, vn_kv=20,name="b")
    pp.create_sgen(net, bus=bus_20_1, p_mw=0.03, q_mvar=0.02)

    bus_10_1 = pp.create_bus(net, vn_kv=10)
    pp.create_sgen(net, bus=bus_10_1, p_mw=0.02, q_mvar=0.02)

    bus_10_2 = pp.create_bus(net, vn_kv=10)
    pp.create_load(net, bus=bus_10_2, p_mw=0.06, q_mvar=0.01)
    pp.create_line(net, from_bus=bus_10_1, to_bus=bus_10_2, std_type="149-AL1/24-ST1A 10.0", length_km=2)

    pp.create_transformer3w(net, bus_slack, bus_20_1, bus_10_1, std_type="63/25/38 MVA 110/20/10 kV")

    pp.runpp(net)

    pp.create_measurement(net, "p", "line", net.res_line.p_from_mw[0], 0.001, 0, 'from')
    pp.create_measurement(net, "q", "line", net.res_line.q_from_mvar[0], 0.001, 0, 'from')
    pp.create_measurement(net, "p", "line", net.res_line.p_to_mw[0], 0.001, 0, 'to')
    pp.create_measurement(net, "q", "line", net.res_line.q_to_mvar[0], 0.001, 0, 'to')

    pp.create_measurement(net, "p", "trafo3w", net.res_trafo3w.p_hv_mw[0], 0.001, 0, 'hv')
    pp.create_measurement(net, "q", "trafo3w", net.res_trafo3w.q_hv_mvar[0], 0.001, 0, 'hv')
    pp.create_measurement(net, "p", "trafo3w", net.res_trafo3w.p_mv_mw[0], 0.002, 0, 'mv')
    pp.create_measurement(net, "q", "trafo3w", net.res_trafo3w.q_mv_mvar[0], 0.002, 0, 'mv')
    pp.create_measurement(net, "p", "trafo3w", net.res_trafo3w.p_lv_mw[0], 0.001, 0, 'lv')
    pp.create_measurement(net, "q", "trafo3w", net.res_trafo3w.q_lv_mvar[0], 0.001, 0, 'lv')

    pp.create_measurement(net, "v", "bus", net.res_bus.vm_pu[0], 0.01, 0)
    pp.create_measurement(net, "v", "bus", net.res_bus.vm_pu[1], 0.01, 1)

    success = estimate(net)
    assert success
    assert (np.nanmax(np.abs(net.res_bus.vm_pu.values - net.res_bus_est.vm_pu.values)) < 0.006)
    assert (np.nanmax(np.abs(net.res_bus.va_degree.values- net.res_bus_est.va_degree.values)) < 0.006)
Ejemplo n.º 19
0
def test_two_oos_buses():
    net = pp.create_empty_network()

    b1 = pp.create_bus(net, vn_kv=0.4)
    b2 = pp.create_bus(net, vn_kv=0.4)
    b3 = pp.create_bus(net, vn_kv=0.4, in_service=False)
    b4 = pp.create_bus(net, vn_kv=0.4, in_service=False)

    pp.create_ext_grid(net, b1)
    l1 = pp.create_line(net, b1, b2, 0.5, std_type="NAYY 4x50 SE", index=4)
    l2 = pp.create_line(net, b2, b3, 0.5, std_type="NAYY 4x50 SE", index=2)
    l3 = pp.create_line(net, b3, b4, 0.5, std_type="NAYY 4x50 SE", index=7)

    pp.runpp(net)
    assert net.res_line.loading_percent.at[l1] > 0
    assert net.res_line.loading_percent.at[l2] > 0
    assert np.isnan(net.res_line.loading_percent.at[l3])

    net.line.drop(l2, inplace=True)
    pp.runpp(net)
    assert net.res_line.loading_percent.at[l1] > 0
    assert np.isnan(net.res_line.loading_percent.at[l3])
Ejemplo n.º 20
0
def gen_three_bus_example():
    net = pp.create_empty_network(sn_mva=2)
    b1 = pp.create_bus(net, vn_kv=10.)
    b2 = pp.create_bus(net, vn_kv=10.)
    b3 = pp.create_bus(net, vn_kv=10.)
    #pp.create_bus(net, vn_kv=0.4, in_service=False)
    pp.create_gen(net,
                  b2,
                  vn_kv=10.5,
                  xdss_pu=0.2,
                  rdss_pu=0.001,
                  cos_phi=0.8,
                  p_mw=0.1,
                  sn_mva=2.5)
    pp.create_line_from_parameters(net,
                                   b1,
                                   b2,
                                   length_km=1.0,
                                   max_i_ka=0.29,
                                   r_ohm_per_km=0.1548,
                                   x_ohm_per_km=0.0816814,
                                   c_nf_per_km=165)
    pp.create_line_from_parameters(net,
                                   b2,
                                   b3,
                                   length_km=1.0,
                                   max_i_ka=0.29,
                                   r_ohm_per_km=0.1548,
                                   x_ohm_per_km=0.0816814,
                                   c_nf_per_km=165)
    net.line["endtemp_degree"] = 165
    pp.create_ext_grid(net,
                       b1,
                       s_sc_max_mva=10.,
                       s_sc_min_mva=8.,
                       rx_min=0.4,
                       rx_max=0.4)
    #pp.create_switch(net, b3, b1, et="b")
    return net
Ejemplo n.º 21
0
def test_fuse_buses():

    net = pp.create_empty_network()
    b1 = pp.create_bus(net, vn_kv=1, name="b1")
    b2 = pp.create_bus(net, vn_kv=1.5, name="b2")

    line1 = pp.create_line(net, b2, b1, length_km=1, std_type="NAYY 4x50 SE")

    sw1 = pp.create_switch(net, b2, line1, et="l")
    sw2 = pp.create_switch(net, b1, b2, et="b")

    load1 = pp.create_load(net, b1, p_kw=6)
    load2 = pp.create_load(net, b2, p_kw=5)

    tb.fuse_buses(net, b1, b2, drop=True)

    # assertion: elements connected to b2 are given to b1 instead
    assert net["line"]["from_bus"].loc[0] == b1
    assert net["switch"]["bus"].loc[0] == b1
    assert net["load"]["bus"].loc[1] == b1
    # assertion: b2 not in net.bus table if drop=True
    assert b2 not in net.bus.index
Ejemplo n.º 22
0
def motor_net():
    net = pp.create_empty_network()
    b1 = pp.create_bus(net, vn_kv=0.4)
    b2 = pp.create_bus(net, vn_kv=0.4)
    pp.create_ext_grid(net, b1, s_sc_max_mva=10., rx_max=0.1)
    pp.create_line_from_parameters(net,
                                   from_bus=b1,
                                   to_bus=b2,
                                   length_km=1.,
                                   r_ohm_per_km=0.3211,
                                   x_ohm_per_km=0.06911504,
                                   c_nf_per_km=0,
                                   max_i_ka=1)
    pp.create_sgen(net,
                   b2,
                   p_mw=0.11,
                   sn_mva=0.5,
                   type="motor",
                   k=7,
                   rx=0.6,
                   current_source=False)
    return net
Ejemplo n.º 23
0
def feeder_network():
    net = pp.create_empty_network()
    b1 = pp.create_bus(net, 110)
    b2 = pp.create_bus(net, 110)
    b3 = pp.create_bus(net, 110)
    b4 = pp.create_bus(net, 110)
    b5 = pp.create_bus(net, 110)

    pp.create_ext_grid(net,
                       b1,
                       s_sc_max_mva=100.,
                       s_sc_min_mva=80.,
                       rx_min=0.4,
                       rx_max=0.4)
    pp.create_line(net,
                   b1,
                   b2,
                   std_type="305-AL1/39-ST1A 110.0",
                   length_km=20.)
    pp.create_line(net,
                   b2,
                   b3,
                   std_type="N2XS(FL)2Y 1x185 RM/35 64/110 kV",
                   length_km=15.)
    pp.create_line(net,
                   b1,
                   b4,
                   std_type="305-AL1/39-ST1A 110.0",
                   length_km=12.)
    pp.create_line(net,
                   b4,
                   b5,
                   std_type="N2XS(FL)2Y 1x185 RM/35 64/110 kV",
                   length_km=8.)
    net.line["endtemp_degree"] = 80
    for b in [b2, b3, b4, b5]:
        pp.create_sgen(net, b, sn_kva=2000, p_kw=0)
    net.sgen["k"] = 1.2
    return net
Ejemplo n.º 24
0
def net():
    v_base = 20                     # 20kV Base Voltage
    mva_base = 100                      # 100 MVA
    Net = pp.create_empty_network(sn_mva=mva_base)
    
    bus0 = pp.create_bus(Net, vn_kv=v_base, name="Bus 0")
    
    pp.create_ext_grid(Net, bus=bus0, vm_pu=1.0, name="Grid Connection", s_sc_max_mva=5000, 
                           rx_max=0.1, r0x0_max=0.1, x0x_max=1.0)
    
    bus1 = pp.create_bus(Net, name="Bus1", vn_kv=20, type="b")
    
    #pp.add_zero_impedance_parameters(Net)
        
    pp.create_asymmetric_load(Net, bus1, p_a_mw=0.3, q_a_mvar=0.003, p_b_mw=0.2, q_b_mvar=0.002,
                                  p_c_mw=0.1, q_c_mvar=0.001, scaling=1.0, in_service=True, type='wye')
    
        
    pp.create_line_from_parameters(Net, from_bus=bus0, to_bus=bus1, length_km=2.0, r0_ohm_per_km=.789,
                                       x0_ohm_per_km=0.306, c0_nf_per_km=272.9, max_i_ka=0.496,
                                       r_ohm_per_km=0.184, x_ohm_per_km=0.1900664, c_nf_per_km=273)
    return Net
Ejemplo n.º 25
0
def test_power_station_unit():
    net = pp.create_empty_network()
    b1, b2, b3, b4 = pp.create_buses(net, 4, 20)
    b5 = pp.create_bus(net, 10)

    pp.create_ext_grid(net, b1, s_sc_max_mva=250, rx_max=0.1)

    pp.create_line(net, b1, b2, std_type="305-AL1/39-ST1A 110.0", length_km=10)
    pp.create_line(net, b2, b3, std_type="305-AL1/39-ST1A 110.0", length_km=10)
    pp.create_line(net, b3, b4, std_type="305-AL1/39-ST1A 110.0", length_km=50)

    pp.create_transformer_from_parameters(net, b4, b5, 25, 20, 10, 0.41104,
                                          10.3, 0.1, 0.1)
    pp.create_gen(net,
                  b5,
                  vn_kv=10,
                  xdss_pu=0.12,
                  cos_phi=0.8,
                  p_mw=0,
                  sn_mva=10)

    sc.calc_sc(net)
Ejemplo n.º 26
0
def test_generator_as_slack():
    net = pp.create_empty_network()
    b1 = pp.create_bus(net, 110.)
    pp.create_ext_grid(net, b1, vm_pu=1.02)
    b2 = pp.create_bus(net, 110.)
    pp.create_line(net,
                   b1,
                   b2,
                   length_km=70.,
                   std_type='149-AL1/24-ST1A 110.0')
    pp.create_load(net, b2, p_mw=2)
    pp.runpp(net)
    res_bus = net.res_bus.vm_pu.values

    pp.create_gen(net, b1, p_mw=0.1, vm_pu=1.02, slack=True)
    net.ext_grid.in_service.iloc[0] = False
    pp.runpp(net)
    assert np.allclose(res_bus, net.res_bus.vm_pu.values)

    net.gen.slack.iloc[0] = False
    with pytest.raises(UserWarning):
        pp.runpp(net)
Ejemplo n.º 27
0
def test_create_buses():
    net = pp.create_empty_network()
    # standard
    b1 = pp.create_buses(net, 3, 110)
    # with geodata
    b2 = pp.create_buses(net, 3, 110, geodata=(10, 20))
    # with geodata as array
    geodata = np.array([[10, 20], [20, 30], [30, 40]])
    b3 = pp.create_buses(net, 3, 110, geodata=geodata)

    assert len(net.bus) == 9
    assert len(net.bus_geodata) == 6

    for i in b2:
        assert net.bus_geodata.at[i, 'x'] == 10
        assert net.bus_geodata.at[i, 'y'] == 20

    assert (net.bus_geodata.loc[b3, ['x', 'y']].values == geodata).all()

    # no way of creating buses with not matching shape
    with pytest.raises(ValueError):
        pp.create_buses(net, 2, 110, geodata=geodata)
Ejemplo n.º 28
0
def test_recycle():
    # Note: Only calls recycle functions and tests if load and gen are updated.
    # Todo: To fully test the functionality, it must be checked if the recycle methods are being called
    # or alternatively if the "non-recycle" functions are not being called.
    net = pp.create_empty_network()
    b1, b2, ln = add_grid_connection(net)
    pl = 1200
    ql = 1100
    ps = -500
    u_set = 1.0

    b3 = pp.create_bus(net, vn_kv=.4)
    pp.create_line_from_parameters(net, b2, b3, 12.2, r_ohm_per_km=0.08, x_ohm_per_km=0.12,
                                   c_nf_per_km=300, max_i_ka=.2, df=.8)
    pp.create_load(net, b3, p_kw=pl, q_kvar=ql)
    pp.create_gen(net, b2, p_kw=ps, vm_pu=u_set)

    runpp_with_consistency_checks(net, recycle=dict(_is_elements=True, ppc=True, Ybus=True))

    # copy.deepcopy(net)

    # update values
    pl = 600
    ql = 550
    ps = -250
    u_set = 0.98

    net["load"].p_kw.iloc[0] = pl
    net["load"].q_kvar.iloc[0] = ql
    net["gen"].p_kw.iloc[0] = ps
    net["gen"].vm_pu.iloc[0] = u_set

    runpp_with_consistency_checks(net, recycle=dict(_is_elements=True, ppc=True, Ybus=True))

    assert np.allclose(net.res_load.p_kw.iloc[0], pl)
    assert np.allclose(net.res_load.q_kvar.iloc[0], ql)
    assert np.allclose(net.res_gen.p_kw.iloc[0], ps)
    assert np.allclose(net.res_gen.vm_pu.iloc[0], u_set)
Ejemplo n.º 29
0
def test_cost_piecewise_linear_load():
    """ Testing a very simple network for the resulting cost value
    constraints with OPF """

    # boundaries:
    vm_max = 1.05
    vm_min = 0.95

    # create net
    net = pp.create_empty_network()
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=10.)
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=.4)
    pp.create_load(net,
                   1,
                   p_mw=0.1,
                   controllable=True,
                   max_p_mw=0.15,
                   min_p_mw=0.050,
                   max_q_mvar=0,
                   min_q_mvar=0)
    pp.create_ext_grid(net, 0)
    pp.create_line_from_parameters(net,
                                   0,
                                   1,
                                   50,
                                   name="line2",
                                   r_ohm_per_km=0.876,
                                   c_nf_per_km=260.0,
                                   max_i_ka=0.123,
                                   x_ohm_per_km=0.1159876,
                                   max_loading_percent=100 * 690)

    pp.create_pwl_cost(net, 0, "load", [[0, 75, 1.5], [75, 150, 1.5]])

    pp.runopp(net)

    assert net["OPF_converged"]
    assert abs(net.res_cost - net.res_load.p_mw.values * 1.5) < 1e-3
Ejemplo n.º 30
0
def test_close_switch_at_line_with_two_open_switches():
    net = pp.create_empty_network()

    bus1 = pp.create_bus(net, vn_kv=.4)
    bus2 = pp.create_bus(net, vn_kv=.4)
    bus3 = pp.create_bus(net, vn_kv=.4)

    line1 = pp.create_line(net,
                           bus2,
                           bus3,
                           length_km=1.,
                           std_type="NAYY 4x50 SE")
    line2 = pp.create_line(net,
                           bus2,
                           bus3,
                           length_km=1.,
                           std_type="NAYY 4x50 SE")
    line3 = pp.create_line(net,
                           bus2,
                           bus3,
                           length_km=1.,
                           std_type="NAYY 4x50 SE")

    sw1 = pp.create_switch(net, bus1, bus2, et="b", closed=True)

    sw2 = pp.create_switch(net, bus2, line1, et="l", closed=False)
    sw3 = pp.create_switch(net, bus3, line1, et="l", closed=False)

    sw4 = pp.create_switch(net, bus2, line2, et="l", closed=True)
    sw5 = pp.create_switch(net, bus3, line2, et="l", closed=False)

    sw6 = pp.create_switch(net, bus3, line2, et="l", closed=True)
    sw7 = pp.create_switch(net, bus3, line2, et="l", closed=True)

    tb.close_switch_at_line_with_two_open_switches(net)

    # assertion: sw2 closed
    assert net.switch.closed.loc[1]
Ejemplo n.º 31
0
def test_pandapower_case():

    #more complicated examples like
    #net = pandapower.networks.example_simple()
    #can be used once the import of e.g. switches is perfected

    #create empty net
    net = pp.create_empty_network()

    #create buses
    b1 = pp.create_bus(net, vn_kv=20., name="Bus 1")
    b2 = pp.create_bus(net, vn_kv=0.4, name="Bus 2")
    b3 = pp.create_bus(net, vn_kv=0.4, name="Bus 3")

    #create bus elements
    pp.create_ext_grid(net, bus=b1, vm_pu=1.02, name="Grid Connection")
    pp.create_load(net, bus=b3, p_kw=100, q_kvar=50, name="Load")

    #create branch elements
    tid = pp.create_transformer(net, hv_bus=b1, lv_bus=b2, std_type="0.4 MVA 20/0.4 kV",
                                                            name="Trafo")
    pp.create_line(net, from_bus=b2, to_bus=b3, length_km=0.1, name="Line",
                                  std_type="NAYY 4x50 SE")

    #because of phase angles, need to init with DC
    pp.runpp(net,calculate_voltage_angles=True,init="dc")

    n = pypsa.Network()

    n.import_from_pandapower_net(net)

    #seed PF with LPF solution because of phase angle jumps
    n.lpf()
    n.pf(use_seed=True)

    #use same index for everything
    net.res_bus.index = net.bus.name.values
    net.res_line.index = net.line.name.values

    #compare bus angles
    np.testing.assert_array_almost_equal(n.buses_t.v_ang.loc["now"]*180/np.pi,net.res_bus.va_degree)

    #compare bus voltage magnitudes
    np.testing.assert_array_almost_equal(n.buses_t.v_mag_pu.loc["now"],net.res_bus.vm_pu)

    #compare bus active power (NB: pandapower uses load signs)
    np.testing.assert_array_almost_equal(n.buses_t.p.loc["now"],-net.res_bus.p_kw/1e3)

    #compare bus active power (NB: pandapower uses load signs)
    np.testing.assert_array_almost_equal(n.buses_t.q.loc["now"],-net.res_bus.q_kvar/1e3)

    #compare branch flows
    np.testing.assert_array_almost_equal(n.lines_t.p0.loc["now"],net.res_line.p_from_kw/1e3)
    np.testing.assert_array_almost_equal(n.lines_t.p1.loc["now"],net.res_line.p_to_kw/1e3)
    np.testing.assert_array_almost_equal(n.lines_t.q0.loc["now"],net.res_line.q_from_kvar/1e3)
    np.testing.assert_array_almost_equal(n.lines_t.q1.loc["now"],net.res_line.q_to_kvar/1e3)

    np.testing.assert_array_almost_equal(n.transformers_t.p0.loc["now"],net.res_trafo.p_hv_kw/1e3)
    np.testing.assert_array_almost_equal(n.transformers_t.p1.loc["now"],net.res_trafo.p_lv_kw/1e3)
    np.testing.assert_array_almost_equal(n.transformers_t.q0.loc["now"],net.res_trafo.q_hv_kvar/1e3)
    np.testing.assert_array_almost_equal(n.transformers_t.q1.loc["now"],net.res_trafo.q_lv_kvar/1e3)