예제 #1
0
def test_to_ppc_and_mpc():
    # pypower cases to validate
    functions = [
        'case4gs', 'case6ww', 'case14', 'case30', 'case24_ieee_rts', 'case39'
    ]
    for fn in functions:
        # get pypower results
        pypower_module = __import__('pypower.' + fn)
        pypower_submodule = getattr(pypower_module, fn)
        pypower_function = getattr(pypower_submodule, fn)
        ppc_net = pypower_function()

        # get net from pandapower
        res_pypower, status_pypower = runpf(ppc_net,
                                            ppopt=ppoption(VERBOSE=0,
                                                           OUT_ALL=0))

        pandapower_module = __import__('pandapower', fromlist=['networks'])
        pandapower_function = getattr(pandapower_module.networks, fn)
        net = pandapower_function()
        reset_results(net)

        # convert to ppc
        ppc = cv.to_ppc(net)
        # convert to mpc
        mpc = cv.to_mpc(net)

        # runpf from converted ppc
        res_converted_pp, status_converted_pp = runpf(
            ppc, ppopt=ppoption(VERBOSE=0, OUT_ALL=0))

        if status_converted_pp and status_pypower:
            # get lookup pp2ppc
            bus_lookup = net["_pd2ppc_lookups"]["bus"]
            # check for equality in bus voltages
            pp_buses = bus_lookup[res_converted_pp['bus'][:,
                                                          BUS_I].astype(int)]
            assert np.allclose(res_converted_pp['bus'][pp_buses, VM:VA + 1],
                               res_pypower['bus'][:, VM:VA + 1])
            # ToDo: check equality of branch and gen values
            # pp_gen = bus_lookup[res_converted_pp['bus'][:, BUS_I].astype(int)]
            # assert np.allclose(res_pypower['gen'][res_pypower['order']['gen']['e2i'], PG:QG+1]
            #                    , res_converted_pp['gen'][:, PG:QG+1])
        else:
            raise LoadflowNotConverged("Loadflow did not converge!")
예제 #2
0
def test_case9_conversion():
    net = pn.case9()
    ppc = to_ppc(net)
    # correction because to_ppc do net export max_loading_percent:
    ppc["branch"][:, 5] = [250, 250, 150, 300, 150] + [250] * 4
    # correction because voltage limits are set to 1.0 at slack buses
    ppc["bus"][0, 11] = 0.9
    ppc["bus"][0, 12] = 1.1

    net2 = from_ppc(ppc)

    pp.runpp(net)
    pp.runpp(net2)
    assert pp.nets_equal(net, net2, check_only_results=True, tol=1e-10)

    pp.runopp(net)
    pp.runopp(net2)
    assert pp.nets_equal(net, net2, check_only_results=True, tol=1e-10)
예제 #3
0
def test_to_ppc_and_mpc():
    # pypower cases to validate
    functions = ['case4gs', 'case6ww', 'case30', 'case39']
    for fn in functions:
        # get pypower grids with results
        ppc_net = get_testgrids(fn, 'pypower_cases.p')

        # get pandapower grids
        pandapower_module = __import__('pandapower', fromlist=['networks'])
        pandapower_function = getattr(pandapower_module.networks, fn)
        net = pandapower_function()
        reset_results(net)

        # This should be reviewed
        pp.runpp(net)

        # convert pandapower grids to ppc
        ppc = cv.to_ppc(net)
        # convert pandapower grids to mpc (no result validation)
        mpc = cv.to_mpc(net)

        # validate voltage results of pandapower-to-ppc-converted grids vs. original pypower results
        net["_options"]['ac'] = True
        net["_options"]['numba'] = True
        net["_options"]['tolerance_mva'] = 1e-8
        net["_options"]['algorithm'] = "fdbx"
        net["_options"]['max_iteration'] = 30
        net["_options"]['enforce_q_lims'] = False
        net["_options"]['calculate_voltage_angles'] = True
        res_converted_pp, status_converted_pp = _runpf_pypower(
            ppc, net["_options"])

        if status_converted_pp:
            # get lookup pp2ppc
            bus_lookup = net["_pd2ppc_lookups"]["bus"]
            # check for equality in bus voltages
            pp_buses = bus_lookup[res_converted_pp['bus'][:,
                                                          BUS_I].astype(int)]
            res1 = res_converted_pp['bus'][pp_buses, VM:VA + 1]
            res2 = ppc_net['bus'][:, VM:VA + 1]
            assert np.allclose(res1, res2)
        else:
            raise LoadflowNotConverged("Loadflow did not converge!")
예제 #4
0
def test_case9_conversion():
    net = pn.case9()
    # set max_loading_percent to enable line limit conversion
    net.line["max_loading_percent"] = 100
    ppc = to_ppc(net, mode="opf")
    # correction because voltage limits are set to 1.0 at slack buses
    ppc["bus"][0, 12] = 0.9
    ppc["bus"][0, 11] = 1.1

    net2 = from_ppc(ppc, f_hz=net.f_hz)
    # again add max_loading_percent to enable valid comparison
    net2.line["max_loading_percent"] = 100

    # compare loadflow results
    pp.runpp(net)
    pp.runpp(net2)
    assert pp.nets_equal(net, net2, check_only_results=True, tol=1e-10)

    # compare optimal powerflow results
    pp.runopp(net)
    pp.runopp(net2)
    assert pp.nets_equal(net, net2, check_only_results=True, tol=1e-10)