def convert_format(net): """ Converts old nets to new format to ensure consistency. The converted net is returned. """ from pandapower.toolbox import set_data_type_of_columns_to_default if isinstance( net.version, str) and version.parse(net.version) >= version.parse(__version__): return net _add_nominal_power(net) _add_missing_tables(net) _rename_columns(net) _add_missing_columns(net) _create_seperate_cost_tables(net) if isinstance(net.version, float) and net.version < 2: _convert_to_generation_system(net) _convert_costs(net) _convert_to_mw(net) _update_trafo_parameter_names(net) reset_results(net) if isinstance(net.version, float) and net.version < 1.6: set_data_type_of_columns_to_default(net) _convert_objects(net) net.version = __version__ return net
def _optimal_powerflow(net, verbose, suppress_warnings, **kwargs): ac = net["_options"]["ac"] ppopt = ppoption(VERBOSE=verbose, OPF_FLOW_LIM=2, PF_DC=not ac, **kwargs) net["OPF_converged"] = False net["converged"] = False _add_auxiliary_elements(net) reset_results(net) ppc, ppci = _pd2ppc(net) if not ac: ppci["bus"][:, VM] = 1.0 net["_ppc_opf"] = ppc if len(net.dcline) > 0: ppci = add_userfcn(ppci, 'formulation', _add_dcline_constraints, args=net) if suppress_warnings: with warnings.catch_warnings(): warnings.simplefilter("ignore") result = opf(ppci, ppopt) else: result = opf(ppci, ppopt) net["_ppc_opf"] = result if not result["success"]: raise OPFNotConverged("Optimal Power Flow did not converge!") # ppci doesn't contain out of service elements, but ppc does -> copy results accordingly mode = net["_options"]["mode"] result = _copy_results_ppci_to_ppc(result, ppc, mode=mode) net["_ppc_opf"] = result net["OPF_converged"] = True _extract_results_opf(net, result) _clean_up(net)
def convert_format(net, elements_to_deserialize=None): """ Converts old nets to new format to ensure consistency. The converted net is returned. """ from pandapower.toolbox import set_data_type_of_columns_to_default if isinstance( net.version, str) and version.parse(net.version) >= version.parse(__version__): return net _add_nominal_power(net) _add_missing_tables(net) _rename_columns(net, elements_to_deserialize) _add_missing_columns(net, elements_to_deserialize) _create_seperate_cost_tables(net, elements_to_deserialize) if version.parse(str(net.version)) < version.parse("2.4.0"): _convert_bus_pq_meas_to_load_reference(net, elements_to_deserialize) if isinstance(net.version, float) and net.version < 2: _convert_to_generation_system(net, elements_to_deserialize) _convert_costs(net) _convert_to_mw(net) _update_trafo_parameter_names(net, elements_to_deserialize) reset_results(net) if isinstance(net.version, float) and net.version < 1.6: set_data_type_of_columns_to_default(net) _convert_objects(net, elements_to_deserialize) correct_dtypes(net, error=False) net.version = __version__ return net
def _extract_single_results(net, ppc): reset_results(net, suffix="_sc") _get_single_bus_results(net, ppc) net["_options"]["ac"] = True net["_options"]["trafo_loading"] = "current" bus_lookup_aranged = _get_aranged_lookup(net) bus_pq = np.zeros(shape=(len(net["bus"].index), 2), dtype=np.float) _get_branch_results(net, ppc, bus_lookup_aranged, bus_pq, suffix="_sc")
def _powerflow(net, **kwargs): """ Gets called by runpp or rundcpp with different arguments. """ # get infos from options init_results = net["_options"]["init_results"] ac = net["_options"]["ac"] recycle = net["_options"]["recycle"] mode = net["_options"]["mode"] algorithm = net["_options"]["algorithm"] max_iteration = net["_options"]["max_iteration"] net["converged"] = False net["OPF_converged"] = False _add_auxiliary_elements(net) if not ac or init_results: verify_results(net) else: reset_results(net) # TODO remove this when zip loads are integrated for all PF algorithms if algorithm not in ['nr', 'bfsw']: net["_options"]["voltage_depend_loads"] = False if recycle["ppc"] and "_ppc" in net and net[ "_ppc"] is not None and "_pd2ppc_lookups" in net: # update the ppc from last cycle ppc, ppci = _update_ppc(net) else: # convert pandapower net to ppc ppc, ppci = _pd2ppc(net) # store variables net["_ppc"] = ppc if not "VERBOSE" in kwargs: kwargs["VERBOSE"] = 0 # ----- run the powerflow ----- result = _run_pf_algorithm(ppci, net["_options"], **kwargs) # ppci doesn't contain out of service elements, but ppc does -> copy results accordingly result = _copy_results_ppci_to_ppc(result, ppc, mode) # raise if PF was not successful. If DC -> success is always 1 if result["success"] != 1: _clean_up(net, res=False) raise LoadflowNotConverged("Power Flow {0} did not converge after " "{1} iterations!".format( algorithm, max_iteration)) else: net["_ppc"] = result net["converged"] = True _extract_results(net, result) _clean_up(net)
def _copy_power_flow_results(net): # copy old power flow results (if they exist) into res_*_power_flow tables for backup elements_to_init = ["bus", "ext_grid", "line", "load", "sgen", "trafo", "trafo3w", "shunt", "impedance", "gen", "ward", "xward", "dcline"] for element in elements_to_init: res_name = "res_" + element res_name_pf = res_name + "_power_flow" if res_name in net: net[res_name_pf] = (net[res_name]).copy() reset_results(net)
def _runpppf_dd(net, init, ac, calculate_voltage_angles, tolerance_kva, trafo_model, trafo_loading, enforce_q_lims, numba, recycle, **kwargs): """ Gets called by runpp or rundcpp with different arguments. """ net["converged"] = False if (ac and not init == "results") or not ac: reset_results(net) # select elements in service (time consuming, so we do it once) is_elems = _select_is_elements(net, recycle) if recycle["ppc"] and "_ppc" in net and net[ "_ppc"] is not None and "_bus_lookup" in net: # update the ppc from last cycle ppc, ppci, bus_lookup = _update_ppc(net, is_elems, recycle, calculate_voltage_angles, enforce_q_lims, trafo_model) else: # convert pandapower net to ppc ppc, ppci, bus_lookup = _pd2ppc(net, is_elems, calculate_voltage_angles, enforce_q_lims, trafo_model, init_results=(init == "results")) # store variables net["_ppc"] = ppc net["_bus_lookup"] = bus_lookup net["_is_elems"] = is_elems if not "VERBOSE" in kwargs: kwargs["VERBOSE"] = 0 # run the powerflow result = _run_fbsw(ppci, ppopt=ppoption(ENFORCE_Q_LIMS=enforce_q_lims, PF_TOL=tolerance_kva * 1e-3, **kwargs))[0] # ppci doesn't contain out of service elements, but ppc does -> copy results accordingly result = _copy_results_ppci_to_ppc(result, ppc, bus_lookup) # raise if PF was not successful. If DC -> success is always 1 if result["success"] != 1: raise LoadflowNotConverged("Loadflow did not converge!") else: net["_ppc"] = result net["converged"] = True _extract_results(net, result, is_elems, bus_lookup, trafo_loading, ac) _clean_up(net)
def convert_to_pm_structure(net): net["OPF_converged"] = False net["converged"] = False _add_auxiliary_elements(net) reset_results(net) ppc, ppci = _pd2ppc(net) ppci = build_ne_branch(net, ppci) net["_ppc_opf"] = ppci pm = ppc_to_pm(net, ppci) pm = add_pm_options(pm, net) net._pm = pm return net, pm, ppc, ppci
def _powerflow(net, **kwargs): """ Gets called by runpp or rundcpp with different arguments. """ # get infos from options init = net["_options"]["init"] ac = net["_options"]["ac"] recycle = net["_options"]["recycle"] mode = net["_options"]["mode"] net["converged"] = False _add_auxiliary_elements(net) if (ac and not init == "results") or not ac: reset_results(net) if recycle["ppc"] and "_ppc" in net and net[ "_ppc"] is not None and "_pd2ppc_lookups" in net: # update the ppc from last cycle ppc, ppci = _update_ppc(net) else: # convert pandapower net to ppc ppc, ppci = _pd2ppc(net) # store variables net["_ppc"] = ppc if not "VERBOSE" in kwargs: kwargs["VERBOSE"] = 0 # ----- run the powerflow ----- result = _run_pf_algorithm(ppci, net["_options"], **kwargs) # ppci doesn't contain out of service elements, but ppc does -> copy results accordingly result = _copy_results_ppci_to_ppc(result, ppc, mode) # raise if PF was not successful. If DC -> success is always 1 if result["success"] != 1: raise LoadflowNotConverged("Power Flow did not converge!") else: net["_ppc"] = result net["converged"] = True _extract_results(net, result) _clean_up(net)
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!")
def _runpm(net, julia_file=None, pp_to_pm_callback=None): net["OPF_converged"] = False net["converged"] = False _add_auxiliary_elements(net) reset_results(net) ppc, ppci = _pd2ppc(net) pm = ppc_to_pm(net, ppci) net._pm = pm if pp_to_pm_callback is not None: pp_to_pm_callback(net, ppci, pm) result_pm = _call_powermodels(pm, julia_file) net._result_pm = result_pm result = pm_results_to_ppc_results(net, ppc, ppci, result_pm) success = ppc["success"] net["_ppc_opf"] = ppci if success: _extract_results_opf(net, result) _clean_up(net) net["OPF_converged"] = True else: _clean_up(net) logger.warning("OPF did not converge!")
def _runpm(net): #pragma: no cover net["OPF_converged"] = False net["converged"] = False _add_auxiliary_elements(net) reset_results(net) ppc, ppci = _pd2ppc(net) net["_ppc_opf"] = ppci pm = ppc_to_pm(net, ppci) net._pm = pm if net._options["pp_to_pm_callback"] is not None: net._options["pp_to_pm_callback"](net, ppci, pm) result_pm = _call_powermodels(pm, net._options["julia_file"]) net._pm_res = result_pm result = pm_results_to_ppc_results(net, ppc, ppci, result_pm) net._pm_result = result_pm success = ppc["success"] if success: _extract_results(net, result) _clean_up(net) net["OPF_converged"] = True else: _clean_up(net, res=False) logger.warning("OPF did not converge!")
def _powerflow(net, **kwargs): """ Gets called by runpp or rundcpp with different arguments. """ # get infos from options init_results = net["_options"]["init_results"] ac = net["_options"]["ac"] algorithm = net["_options"]["algorithm"] net["converged"] = False net["OPF_converged"] = False _add_auxiliary_elements(net) if not ac or init_results: verify_results(net) else: reset_results(net, all_empty=False) # TODO remove this when zip loads are integrated for all PF algorithms if algorithm not in ['nr', 'bfsw']: net["_options"]["voltage_depend_loads"] = False # convert pandapower net to ppc ppc, ppci = _pd2ppc(net) # store variables net["_ppc"] = ppc if not "VERBOSE" in kwargs: kwargs["VERBOSE"] = 0 # ----- run the powerflow ----- result = _run_pf_algorithm(ppci, net["_options"], **kwargs) # read the results (=ppci with results) to net _ppci_to_net(result, net)
def _optimal_powerflow(net, verbose, suppress_warnings, **kwargs): ac = net["_options"]["ac"] init = net["_options"]["init"] ppopt = ppoption(VERBOSE=verbose, OPF_FLOW_LIM=2, PF_DC=not ac, INIT=init, **kwargs) net["OPF_converged"] = False net["converged"] = False _add_auxiliary_elements(net) reset_results(net, all_empty=False) ppc, ppci = _pd2ppc(net) if not ac: ppci["bus"][:, VM] = 1.0 net["_ppc_opf"] = ppci if len(net.dcline) > 0: ppci = add_userfcn(ppci, 'formulation', _add_dcline_constraints, args=net) if init == "pf": ppci = _run_pf_before_opf(net, ppci) if suppress_warnings: with warnings.catch_warnings(): warnings.simplefilter("ignore") result = opf(ppci, ppopt) else: result = opf(ppci, ppopt) # net["_ppc_opf"] = result if verbose: ppopt['OUT_ALL'] = 1 printpf(baseMVA=result["baseMVA"], bus=result["bus"], gen=result["gen"], fd=stdout, branch=result["branch"], success=result["success"], et=result["et"], ppopt=ppopt) if verbose: ppopt['OUT_ALL'] = 1 printpf(baseMVA=result["baseMVA"], bus=result["bus"], gen=result["gen"], fd=stdout, branch=result["branch"], success=result["success"], et=result["et"], ppopt=ppopt) if not result["success"]: raise OPFNotConverged("Optimal Power Flow did not converge!") # ppci doesn't contain out of service elements, but ppc does -> copy results accordingly mode = net["_options"]["mode"] result = _copy_results_ppci_to_ppc(result, ppc, mode=mode) # net["_ppc_opf"] = result net["OPF_converged"] = True _extract_results(net, result) _clean_up(net)
def runpp(self, net, max_iteration=10, need_reset=True, **kwargs): net_orig = copy.deepcopy(net) pp.runpp(net_orig) V_orig = net_orig._ppc["internal"]["V"] # ---------- pp.run.runpp() ----------------- t0_start = time() t0_options = time() passed_parameters = _passed_runpp_parameters(locals()) _init_runpp_options(net, algorithm="nr", calculate_voltage_angles="auto", init="auto", max_iteration=max_iteration, tolerance_mva=1e-8, trafo_model="t", trafo_loading="current", enforce_q_lims=False, check_connectivity=False, voltage_depend_loads=True, consider_line_temperature=False, passed_parameters=passed_parameters, numba=True, **kwargs) _check_bus_index_and_print_warning_if_high(net) _check_gen_index_and_print_warning_if_high(net) et_options = time() - t0_options # ---------- pp.powerflow._powerflow() ----------------- """ Gets called by runpp or rundcpp with different arguments. """ # get infos from options t0_early_init = time() init_results = net["_options"]["init_results"] ac = net["_options"]["ac"] algorithm = net["_options"]["algorithm"] net["converged"] = False net["OPF_converged"] = False _add_auxiliary_elements(net) if not ac or init_results: verify_results(net) else: reset_results(net, all_empty=False) # TODO remove this when zip loads are integrated for all PF algorithms if algorithm not in ['nr', 'bfsw']: net["_options"]["voltage_depend_loads"] = False _add_auxiliary_elements(net) # convert pandapower net to ppc ppc, self.ppci = _pd2ppc(net) # pdb.set_trace() # store variables net["_ppc"] = ppc if not "VERBOSE" in kwargs: kwargs["VERBOSE"] = 0 # ----- run the powerflow ----- options = net["_options"] et_early_init = time() - t0_early_init # ---------- pp.powerflow._run_pf_algorithm() ---------------- # ---------- pp.pf.run_newton_raphson_pf.run_newton_raphson_pf() ---------------- t0 = time() t0_init = t0 et_init_dc = 0. if need_reset: if isinstance(options["init_va_degree"], str) and options["init_va_degree"] == "dc": self.ppci = _run_dc_pf(self.ppci) et_init_dc = time() - t0 if options["enforce_q_lims"]: raise NotImplementedError("enforce_q_lims not yet implemented") t0_init = time() # ---------- pp.pf.run_newton_raphson_pf._run_ac_pf_without_qlims_enforced ---------- # ppci, success, iterations = _run_ac_pf_without_qlims_enforced(ppci, options) makeYbus, pfsoln = _get_numba_functions(self.ppci, options) self.baseMVA, self.bus, self.gen, self.branch, self.ref, self.pv, self.pq, _, _, V0, self.ref_gens = _get_pf_variables_from_ppci( self.ppci) self.ppci, self.Ybus, self.Yf, self.Yt = _get_Y_bus( self.ppci, options, makeYbus, self.baseMVA, self.bus, self.branch) # TODO i have a problem here for the order of the bus / id of bus tmp_bus_ind = np.argsort(net.bus.index) model = DataModel() # model.set_sn_mva(net.sn_mva) # model.set_f_hz(net.f_hz) # TODO set that elsewhere self.converter.set_sn_mva(net.sn_mva) self.converter.set_f_hz(net.f_hz) # init_but should be called first among all the rest model.init_bus(net.bus.iloc[tmp_bus_ind]["vn_kv"].values, net.line.shape[0], net.trafo.shape[0]) # init the shunts line_r, line_x, line_h = self.converter.get_line_param( net.line["r_ohm_per_km"].values * net.line["length_km"].values, net.line["x_ohm_per_km"].values * net.line["length_km"].values, net.line["c_nf_per_km"].values * net.line["length_km"].values, net.line["g_us_per_km"].values * net.line["length_km"].values, net.bus.loc[net.line["from_bus"]]["vn_kv"], net.bus.loc[net.line["to_bus"]]["vn_kv"]) model.init_powerlines(line_r, line_x, line_h, net.line["from_bus"].values, net.line["to_bus"].values) # init the shunts model.init_shunt(net.shunt["p_mw"].values, net.shunt["q_mvar"].values, net.shunt["bus"].values) # init trafo if net.trafo.shape[0]: trafo_r, trafo_x, trafo_b = self.converter.get_trafo_param( net.trafo["vn_hv_kv"].values, net.trafo["vn_lv_kv"].values, net.trafo["vk_percent"].values, net.trafo["vkr_percent"].values, net.trafo["sn_mva"].values, net.trafo["pfe_kw"].values, net.trafo["i0_percent"].values, net.bus.loc[net.trafo["lv_bus"]]["vn_kv"]) # trafo_branch = ppc["branch"][net.line.shape[0]:, :] tap_step_pct = net.trafo["tap_step_percent"].values tap_step_pct[~np.isfinite(tap_step_pct)] = 0. tap_pos = net.trafo["tap_pos"].values tap_pos[~np.isfinite(tap_pos)] = 0. is_tap_hv_side = net.trafo["tap_side"].values == "hv" is_tap_hv_side[~np.isfinite(tap_pos)] = True model.init_trafo(trafo_r, trafo_x, trafo_b, tap_step_pct, tap_pos, is_tap_hv_side, net.trafo["hv_bus"].values, net.trafo["lv_bus"].values) model.init_loads(net.load["p_mw"].values, net.load["q_mvar"].values, net.load["bus"].values) model.init_generators(net.gen["p_mw"].values, net.gen["vm_pu"].values, net.gen["bus"].values) # TODO better way here! model.add_slackbus(net.ext_grid["bus"].values) # model.init_Ybus() # Ybus = model.get_Ybus() # be careful, the order is not the same between this and pandapower, you need to change it # Ybus_proper_oder = Ybus[np.array([net.bus.index]).T, np.array([net.bus.index])] # self.Ybus_proper_oder = self.Ybus else: pass # TODO update self.ppci with new values of generation - load such that Sbus is properly udpated # compute complex bus power injections [generation - load] Sbus = _get_Sbus(self.ppci, False) # Sbus_me = model.get_Sbus() # pdb.set_trace() # Sbus_me_r = np.real(Sbus_me) # Va0 = np.full(net.bus.shape[0], fill_value=net["_options"]["init_vm_pu"], dtype=np.complex_) # Va0[net.ext_grid["bus"].values] = net.ext_grid["vm_pu"].values * np.exp(1j * net.ext_grid["va_degree"].values / 360. * 2 * np.pi) #dctheta = model.dc_pf(Sbus_me_r, Va0) # self.dctheta = V0[tmp_bus_ind] # self.dcYbus = self.ppci["internal"]['Bbus'][np.array([tmp_bus_ind]).T, np.array([tmp_bus_ind])] # tmpdc = np.abs(dcYbus - self.dcYbus) # pv_me = model.get_pv() # pq_me = model.get_pq() # pdb.set_trace() # run the newton power flow # ------------------- pp.pypower.newtonpf --------------------- max_it = options["max_iteration"] tol = options['tolerance_mva'] self.Ybus = sparse.csc_matrix(self.Ybus) et_init = time() - t0_init t0__ = time() if need_reset: # reset the solver self.solver.reset() self.V = 1.0 * copy.deepcopy(V0) else: # reuse previous voltages pass self.solver.solve(self.Ybus, self.V, Sbus, self.pv, self.pq, max_it, tol) et__ = time() - t0__ t0_ = time() Va = self.solver.get_Va() Vm = self.solver.get_Vm() self.V = Vm * np.exp(1j * Va) J = self.solver.get_J() success = self.solver.converged() iterations = self.solver.get_nb_iter() # timer_Fx_, timer_solve_, timer_initialize_, timer_check_, timer_dSbus_, timer_fillJ_, timer_total_nr_ timers = self.solver.get_timers() et_ = time() - t0_ # ---------------------- pp.pypower.newtonpf --------------------- self.ppci = _store_internal( self.ppci, { "J": J, "Vm_it": None, "Va_it": None, "bus": self.bus, "gen": self.gen, "branch": self.branch, "baseMVA": self.baseMVA, "V": self.V, "pv": self.pv, "pq": self.pq, "ref": self.ref, "Sbus": Sbus, "ref_gens": self.ref_gens, "Ybus": self.Ybus, "Yf": self.Yf, "Yt": self.Yt, "timers": timers, "time_get_res": et_, "time_solve": et__, "time_init": et_init, "time_init_dc": et_init_dc, "time_early_init": et_early_init, "time_options": et_options }) t0_ppci_to_pfsoln = time() # update data matrices with solution store in ppci # ---------- pp.pf.run_newton_raphson_pf._run_ac_pf_without_qlims_enforced ---------- self.bus, self.gen, self.branch = ppci_to_pfsoln(self.ppci, options) te_ppci_to_pfsoln = time() - t0_ppci_to_pfsoln # these are the values from pypower / matlab t0_store_res = time() et = t0_store_res - t0 result = _store_results_from_pf_in_ppci(self.ppci, self.bus, self.gen, self.branch, success, iterations, et) t0_to_net = time() et_store_res = t0_to_net - t0_store_res # ---------- pp.pf.run_newton_raphson_pf.run_newton_raphson_pf() ---------------- # ---------- pp.powerflow._run_pf_algorithm() ---------------- # read the results (=ppci with results) to net _ppci_to_net(result, net) et_to_net = time() - t0_to_net # ---------- pp.powerflow._powerflow() ---------------- # ---------- pp.run.runpp() ----------------- # added et_start = time() - t0_start self.ppci = _store_internal( self.ppci, { "time_store_res": et_store_res, "time_to_net": et_to_net, "time_all": et_start, "time_ppci_to_pfsoln": te_ppci_to_pfsoln }) has_conv = model.compute_newton(V0[tmp_bus_ind], max_it, tol) # check the results results_solver = np.max(np.abs(V_orig - self.V)) Ybus = model.get_Ybus() Ybus_proper_oder = Ybus self.Ybus_proper_oder = self.Ybus[np.array([tmp_bus_ind]).T, np.array([tmp_bus_ind])] tmp = np.abs(Ybus_proper_oder - self.Ybus_proper_oder) # > 1e-7 por, qor, vor, aor = model.get_lineor_res() pex, qex, vex, aex = model.get_lineex_res() load_p, load_q, load_v = model.get_loads_res() np.max(np.abs(por - net_orig.res_line["p_from_mw"])) np.max(np.abs(qor - net_orig.res_line["q_from_mvar"])) a_or_pp = np.sqrt(net.res_line["p_from_mw"].values**2 + net.res_line["q_from_mvar"].values**2) a_or_pp /= np.sqrt(3) * net.bus.loc[net.line["from_bus"].values][ "vn_kv"].values * net.res_line["vm_from_pu"].values np.max(np.abs(a_or_pp - aor)) np.max(np.abs(a_or_pp - net.res_line["i_from_ka"])) np.max(np.abs(a_or_pp - net.res_line["i_from_ka"])) Va_me2 = model.get_Va() Vm_me2 = model.get_Vm() res_vm = np.abs(Vm_me2 - Vm[tmp_bus_ind]) res_va = np.abs(Va_me2 - Va[tmp_bus_ind]) # check that if i start the solver on the data Sbus_me = model.get_Sbus() pv_me = model.get_pv() pq_me = model.get_pq() np.all(sorted(pv_me) == sorted(net.gen["bus"])) np.all(sorted(pq_me) == sorted(tmp_bus_ind[self.pq])) plv, qlv, vlv, alv = model.get_trafolv_res() phv, qhv, vhv, ahv = model.get_trafohv_res() res_trafo = np.abs(plv - net_orig.res_trafo["p_lv_mw"].values) res_trafo_q = np.abs(qlv - net_orig.res_trafo["q_lv_mvar"].values) # self.solver.reset() # self.solver.solve(Ybus, V0, Sbus, pv_me, pq_me, max_it, tol) # Va2 = self.solver.get_Va() # Vm2 = self.solver.get_Vm() pdb.set_trace()
def _runpppf(net, **kwargs): """ Gets called by runpp or rundcpp with different arguments. """ # get infos from options init = net["_options"]["init"] ac = net["_options"]["ac"] recycle = net["_options"]["recycle"] numba = net["_options"]["numba"] enforce_q_lims = net["_options"]["enforce_q_lims"] tolerance_kva = net["_options"]["tolerance_kva"] mode = net["_options"]["mode"] algorithm = net["_options"]["algorithm"] max_iteration = net["_options"]["max_iteration"] net["converged"] = False _add_auxiliary_elements(net) if (ac and not init == "results") or not ac: reset_results(net) # select elements in service (time consuming, so we do it once) net["_is_elems"] = _select_is_elements(net, recycle) if recycle["ppc"] and "_ppc" in net and net[ "_ppc"] is not None and "_pd2ppc_lookups" in net: # update the ppc from last cycle ppc, ppci = _update_ppc(net, recycle) else: # convert pandapower net to ppc ppc, ppci = _pd2ppc(net) # store variables net["_ppc"] = ppc if not "VERBOSE" in kwargs: kwargs["VERBOSE"] = 0 # run the powerflow # algorithms implemented within pypower algorithm_pypower_dict = {'nr': 1, 'fdBX': 2, 'fdXB': 3, 'gs': 4} if algorithm == 'fbsw': # foreward/backward sweep power flow algorithm result = _run_fbsw_ppc(ppci, ppopt=ppoption(ENFORCE_Q_LIMS=enforce_q_lims, PF_TOL=tolerance_kva * 1e-3, PF_MAX_IT_GS=max_iteration, **kwargs))[0] elif algorithm in algorithm_pypower_dict: ppopt = ppoption(**kwargs) ppopt['PF_ALG'] = algorithm_pypower_dict[algorithm] ppopt['ENFORCE_Q_LIMS'] = enforce_q_lims ppopt['PF_TOL'] = tolerance_kva if max_iteration is not None: if algorithm == 'nr': ppopt['PF_MAX_IT'] = max_iteration elif algorithm == 'gs': ppopt['PF_MAX_IT_GS'] = max_iteration else: ppopt['PF_MAX_IT_FD'] = max_iteration result = _runpf(ppci, init, ac, numba, recycle, ppopt=ppoption(ENFORCE_Q_LIMS=enforce_q_lims, PF_TOL=tolerance_kva * 1e-3, **kwargs))[0] else: AlgorithmUnknown("Algorithm {0} is unknown!".format(algorithm)) # ppci doesn't contain out of service elements, but ppc does -> copy results accordingly result = _copy_results_ppci_to_ppc(result, ppc, mode) # raise if PF was not successful. If DC -> success is always 1 if result["success"] != 1: raise LoadflowNotConverged("Loadflow did not converge!") else: net["_ppc"] = result net["converged"] = True _extract_results(net, result) _clean_up(net)