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!")
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!")