def test_case5_pm_pd2ppc(): # load net net = case5_pm_matfile_I() # run pd2ppc with ext_grid controllable = False pp.runpp(net) assert "controllable" not in net.ext_grid net["_options"]["mode"] = "opf" ppc = _pd2ppc(net) # check which one is the ref bus in ppc ref_idx = int(ppc[0]["bus"][:, BUS_I][ppc[0]["bus"][:, BUS_TYPE] == REF]) vmax = ppc[0]["bus"][ref_idx, VMAX] vmin = ppc[0]["bus"][ref_idx, VMIN] assert net.ext_grid.vm_pu[0] == vmin assert net.ext_grid.vm_pu[0] == vmax # run pd2ppc with ext_grd controllable = True net.ext_grid["controllable"] = True ppc = _pd2ppc(net) ref_idx = int(ppc[0]["bus"][:, BUS_I][ppc[0]["bus"][:, BUS_TYPE] == REF]) vmax = ppc[0]["bus"][ref_idx, VMAX] vmin = ppc[0]["bus"][ref_idx, VMIN] assert net.bus.min_vm_pu[net.ext_grid.bus].values[0] == vmin assert net.bus.max_vm_pu[net.ext_grid.bus].values[0] == vmax assert net.ext_grid["in_service"].values.dtype == bool assert net.ext_grid["bus"].values.dtype == "uint32" pp.create_ext_grid(net, bus=4, vm_pu=net.res_bus.vm_pu.loc[4]) assert net.ext_grid["bus"].values.dtype == "uint32" assert net.ext_grid["in_service"].values.dtype == bool ppc = _pd2ppc(net) ref_idx = int(ppc[0]["bus"][:, BUS_I][ppc[0]["bus"][:, BUS_TYPE] == REF]) bus2 = net._pd2ppc_lookups["bus"][net.ext_grid.bus[1]] vmax0 = ppc[0]["bus"][ref_idx, VMAX] vmin0 = ppc[0]["bus"][ref_idx, VMIN] vmax1 = ppc[0]["bus"][bus2, VMAX] vmin1 = ppc[0]["bus"][bus2, VMIN] assert net.bus.min_vm_pu[net.ext_grid.bus].values[0] == vmin0 assert net.bus.max_vm_pu[net.ext_grid.bus].values[0] == vmax0 assert net.ext_grid.vm_pu.values[1] == vmin1 assert net.ext_grid.vm_pu.values[1] == vmax1
def _calc_sc(net, bus): _add_auxiliary_elements(net) ppc, ppci = _pd2ppc(net) _calc_ybus(ppci) if net["_options"]["inverse_y"]: _calc_zbus(net, ppci) else: # Factorization Ybus once ppci["internal"]["ybus_fact"] = factorized(ppci["internal"]["Ybus"]) _calc_rx(net, ppci, bus) # kappa required inverse of Zbus, which is optimized if net["_options"]["kappa"]: _add_kappa_to_ppc(net, ppci) _calc_ikss(net, ppci, bus) if net["_options"]["ip"]: _calc_ip(net, ppci) if net["_options"]["ith"]: _calc_ith(net, ppci) if net._options["branch_results"]: _calc_branch_currents(net, ppci, bus) ppc = _copy_results_ppci_to_ppc(ppci, ppc, "sc") _extract_results(net, ppc, ppc_0=None, bus=bus) _clean_up(net) if "ybus_fact" in ppci["internal"]: # Delete factorization object ppci["internal"].pop("ybus_fact")
def _calc_sc_1ph(net, bus): """ calculation method for single phase to ground short-circuit currents """ _add_auxiliary_elements(net) # pos. seq bus impedance ppc, ppci = _pd2ppc(net) _calc_ybus(ppci) # zero seq bus impedance ppc_0, ppci_0 = _pd2ppc_zero(net) _calc_ybus(ppci_0) if net["_options"]["inverse_y"]: _calc_zbus(net, ppci) _calc_zbus(net, ppci_0) else: # Factorization Ybus once ppci["internal"]["ybus_fact"] = factorized(ppci["internal"]["Ybus"]) ppci_0["internal"]["ybus_fact"] = factorized( ppci_0["internal"]["Ybus"]) _calc_rx(net, ppci, bus=bus) _add_kappa_to_ppc(net, ppci) _calc_rx(net, ppci_0, bus=bus) _calc_ikss_1ph(net, ppci, ppci_0, bus=bus) if net._options["branch_results"]: _calc_branch_currents(net, ppci, bus=bus) ppc_0 = _copy_results_ppci_to_ppc(ppci_0, ppc_0, "sc") ppc = _copy_results_ppci_to_ppc(ppci, ppc, "sc") _extract_results(net, ppc, ppc_0, bus=bus) _clean_up(net)
def _init_ppc_logging(self, table, variable, index, eval_function, eval_name): var_name = self._get_output_name(table, variable) ppc = self.net["_ppc"] if ppc is None: # if no ppc is in net-> create one options = dict(algorithm='nr', calculate_voltage_angles="auto", init="auto", max_iteration="auto", tolerance_mva=1e-8, trafo_model="t", trafo_loading="current", enforce_q_lims=False, check_connectivity=True, voltage_depend_loads=True, consider_line_temperature=False) _init_runpp_options(self.net, **options) ppc, _ = _pd2ppc(self.net) self.net["_ppc"] = ppc index = list(range(sum(ppc['bus'][:, BUS_TYPE] != NONE))) self._append_output_list(table, variable, index, eval_function, eval_name, var_name, func=self._log_ppc) return index
def _init_ppc(net, v_start, delta_start, calculate_voltage_angles): # initialize ppc voltages net.res_bus.vm_pu = v_start net.res_bus.vm_pu[net.bus.index[net.bus.in_service == False]] = np.nan net.res_bus.va_degree = delta_start # select elements in service and convert pandapower ppc to ppc net._options = {} _add_ppc_options(net, check_connectivity=False, init_vm_pu="results", init_va_degree="results", trafo_model="t", copy_constraints_to_ppc=False, mode="pf", enforce_q_lims=False, calculate_voltage_angles=calculate_voltage_angles, r_switch=0.0, recycle=dict(_is_elements=False, ppc=False, Ybus=False)) net["_is_elements"] = _select_is_elements_numba(net) ppc, ppci = _pd2ppc(net) # do dc power flow for phase shifting transformers if np.any(net.trafo.shift_degree): vm_backup = ppci["bus"][:, 7].copy() ppci["bus"][:, [2, 3]] = 0. ppci = _run_dc_pf(ppci) ppci["bus"][:, 7] = vm_backup return ppc, ppci
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 _init_ppc(net, v_start, delta_start, calculate_voltage_angles): # select elements in service and convert pandapower ppc to ppc net._options = {} _add_ppc_options(net, check_connectivity=False, init_vm_pu=v_start, init_va_degree=delta_start, trafo_model="pi", mode="pf", enforce_q_lims=False, calculate_voltage_angles=calculate_voltage_angles, switch_rx_ratio=2, recycle=dict(_is_elements=False, ppc=False, Ybus=False)) net["_is_elements"] = _select_is_elements_numba(net) _add_auxiliary_elements(net) ppc, ppci = _pd2ppc(net) # do dc power flow for phase shifting transformers if np.any(net.trafo.shift_degree): vm_backup = ppci["bus"][:, 7].copy() ppci["bus"][:, [2, 3]] = 0. ppci = _run_dc_pf(ppci) ppci["bus"][:, 7] = vm_backup return ppc, ppci
def _calc_sc(net): # t0 = time.perf_counter() _add_auxiliary_elements(net) ppc, ppci = _pd2ppc(net) # t1 = time.perf_counter() _calc_ybus(ppci) # t2 = time.perf_counter() try: _calc_zbus(ppci) except Exception as e: _clean_up(net, res=False) raise(e) _calc_rx(net, ppci) # t3 = time.perf_counter() _add_kappa_to_ppc(net, ppci) # t4 = time.perf_counter() _calc_ikss(net, ppci) if net["_options"]["ip"]: _calc_ip(net, ppci) if net["_options"]["ith"]: _calc_ith(net, ppci) if net._options["branch_results"]: _calc_branch_currents(net, ppci) ppc = _copy_results_ppci_to_ppc(ppci, ppc, "sc") _extract_results(net, ppc, ppc_0=None) _clean_up(net)
def test_PTDF(): net = nw.case9() pp.rundcpp(net) _, ppci = _pd2ppc(net) ptdf = makePTDF(ppci["baseMVA"], ppci["bus"], ppci["branch"], using_sparse_solver=False) _ = makePTDF(ppci["baseMVA"], ppci["bus"], ppci["branch"], result_side=1, using_sparse_solver=False) ptdf_sparse = makePTDF(ppci["baseMVA"], ppci["bus"], ppci["branch"], using_sparse_solver=True) if not np.allclose(ptdf, ptdf_sparse): raise AssertionError( "Sparse PTDF has differenct result against dense PTDF") if not ptdf.shape == (ppci["bus"].shape[0], ppci["branch"].shape[0]): raise AssertionError("PTDF has wrong dimension") if not np.all(~np.isnan(ptdf)): raise AssertionError("PTDF has NaN value")
def _calc_sc_1ph(net): """ calculation method for single phase to ground short-circuit currents """ _add_auxiliary_elements(net) # pos. seq bus impedance ppc, ppci = _pd2ppc(net) _calc_ybus(ppci) try: _calc_zbus(ppci) except Exception as e: _clean_up(net, res=False) raise (e) _calc_rx(net, ppci) _add_kappa_to_ppc(net, ppci) # zero seq bus impedance ppc_0, ppci_0 = _pd2ppc_zero(net) _calc_ybus(ppci_0) try: _calc_zbus(ppci_0) except Exception as e: _clean_up(net, res=False) raise (e) _calc_rx(net, ppci_0) _calc_ikss_1ph(net, ppci, ppci_0) if net._options["branch_results"]: _calc_branch_currents(net, ppci) ppc_0 = _copy_results_ppci_to_ppc(ppci_0, ppc_0, "sc") ppc = _copy_results_ppci_to_ppc(ppci, ppc, "sc") _extract_results(net, ppc, ppc_0) _clean_up(net)
def _calc_sc(net): _add_auxiliary_elements(net) ppc, ppci = _pd2ppc(net) _calc_ybus(ppci) try: _calc_zbus(ppci) except Exception as e: _clean_up(net, res=False) raise (e) _calc_rx(net, ppci) _add_kappa_to_ppc(net, ppci) _calc_ikss(net, ppci) if net["_options"]["ip"]: _calc_ip(net, ppci) if net["_options"]["ith"]: _calc_ith(net, ppci) if net._options["branch_results"]: _calc_branch_currents(net, ppci) ppc = _copy_results_ppci_to_ppc(ppci, ppc, "sc") if net["_options"]["return_all_currents"]: _extract_results(net, ppc, ppc_0=None) else: _extract_results(net, ppc, ppc_0=None) _clean_up(net)
def init_timeseries_newton(self): """ This function is called in the first iteration and variables needed in every loop are stored (Ybus, ppci...) @param net: @return: """ self.init_newton_variables() net = self.net # get ppc and ppci # pp.runpp(net, init_vm_pu="flat", init_va_degree="dc") # pp.runpp(net, init_vm_pu="results", init_va_degree="results") pp.runpp(net, init="dc") pp.runpp(net, init="results") net._options["init_results"] = True net._options["init_vm_pu"] = "results" net._options["init_va_degree"] = "results" options = net._options _add_auxiliary_elements(net) self.ppc, self.ppci = _pd2ppc(net) net["_ppc"] = self.ppc self.baseMVA, bus, gen, branch, self.ref, self.pv, self.pq, _, _, self.V, self.ref_gens = \ nr_pf._get_pf_variables_from_ppci(self.ppci) self.ppci, self.Ybus, self.Yf, self.Yt = \ nr_pf._get_Y_bus(self.ppci, options, nr_pf.makeYbus_numba, self.baseMVA, bus, branch) self.Ibus = zeros(len(self.V), dtype=complex128) # self.Cg = _get_Cg(gen, bus) # assumes that all gens are on! if "controller" in net: self.get_update_ctrl() return net
def _calc_sc(net): # t0 = time.perf_counter() _add_auxiliary_elements(net) ppc, ppci = _pd2ppc(net) # t1 = time.perf_counter() _calc_ybus(ppci) # t2 = time.perf_counter() _calc_zbus(ppci) _calc_rx(net, ppci) # t3 = time.perf_counter() _add_kappa_to_ppc(net, ppci) # t4 = time.perf_counter() _calc_ikss(net, ppci) if net["_options"]["ip"]: _calc_ip(net, ppci) if net["_options"]["ith"]: _calc_ith(net, ppci) if net._options["branch_results"]: _calc_branch_currents(net, ppci) ppc = _copy_results_ppci_to_ppc(ppci, ppc, "sc") _extract_results(net, ppc) _clean_up(net) # t5 = time.perf_counter() # net._et = {"sum": t5-t0, "model": t1-t0, "ybus": t2-t1, "zbus": t3-t2, "kappa": t4-t3, # "currents": t5-t4}
def get_isolated(net): net._options = {} _add_ppc_options(net, calculate_voltage_angles=False, trafo_model="t", check_connectivity=False, mode="pf", r_switch=0.0, init="flat", enforce_q_lims=False, recycle=None) ppc, ppci = _pd2ppc(net) return _check_connectivity(ppc)
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 test_LODF(): net = nw.case9() pp.rundcpp(net) _, ppci = _pd2ppc(net) ptdf = makePTDF(ppci["baseMVA"], ppci["bus"], ppci["branch"]) lodf = makeLODF(ppci["branch"], ptdf) if not lodf.shape == (ppci["branch"].shape[0], ppci["branch"].shape[0]): raise AssertionError("LODF has wrong dimension")
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 _calc_sc(net): # net["_is_elements"] = _select_is_elements(net) _add_auxiliary_elements(net) ppc, ppci = _pd2ppc(net) _calc_equiv_sc_impedance(net, ppci) _add_kappa_to_ppc(net, ppci) _calc_ikss(net, ppci) _calc_ip(ppci) _calc_ith(net, ppci) ppc = _copy_results_ppci_to_ppc(ppci, ppc, "sc") _extract_results(net, ppc) _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 _init_ppc(net, v_start, delta_start, calculate_voltage_angles): # initialize ppc voltages net.res_bus.vm_pu = v_start net.res_bus.vm_pu[net.bus.index[net.bus.in_service == False]] = np.nan net.res_bus.va_degree = delta_start # select elements in service and convert pandapower ppc to ppc net._options = {} _add_ppc_options(net, check_connectivity=False, init="results", trafo_model="t", copy_constraints_to_ppc=False, mode="pf", enforce_q_lims=False, calculate_voltage_angles=calculate_voltage_angles, r_switch=0.0, recycle=dict(_is_elements=False, ppc=False, Ybus=False)) net["_is_elements"] = _select_is_elements(net) ppc, ppci = _pd2ppc(net) return ppc, ppci
def _calc_sc_single(net, bus): _add_auxiliary_elements(net) ppc, ppci = _pd2ppc(net) _calc_ybus(ppci) try: _calc_zbus(ppci) except Exception as e: _clean_up(net, res=False) raise (e) _calc_rx(net, ppci) _calc_ikss(net, ppci) _calc_single_bus_sc(net, ppci, bus) ppc = _copy_results_ppci_to_ppc(ppci, ppc, "sc") _extract_single_results(net, ppc) _clean_up(net)
def _init_ppc(net, v_start, delta_start, calculate_voltage_angles): # select elements in service and convert pandapower ppc to ppc _init_runse_options(net, v_start=v_start, delta_start=delta_start, calculate_voltage_angles=calculate_voltage_angles) ppc, ppci = _pd2ppc(net) # do dc power flow for phase shifting transformers if np.any(net.trafo.shift_degree): vm_backup = ppci["bus"][:, 7].copy() pq_backup = ppci["bus"][:, [2, 3]].copy() ppci["bus"][:, [2, 3]] = 0. ppci = _run_dc_pf(ppci) ppci["bus"][:, 7] = vm_backup ppci["bus"][:, [2, 3]] = pq_backup return ppc, ppci
def _powerflow(net, **kwargs): """ Gets called by runpp or rundcpp with different arguments. """ # get infos from options ac = net["_options"]["ac"] algorithm = net["_options"]["algorithm"] net["converged"] = False net["OPF_converged"] = False _add_auxiliary_elements(net) if not ac or net["_options"]["init_results"]: verify_results(net) else: init_results(net) if net["_options"]["voltage_depend_loads"] and algorithm not in [ 'nr', 'bfsw' ] and not (allclose(net.load.const_z_percent.values, 0) and allclose(net.load.const_i_percent.values, 0)): logger.error(( "pandapower powerflow does not support voltage depend loads for algorithm " "'%s'!") % algorithm) # clear lookups net._pd2ppc_lookups = { "bus": array([], dtype=int), "ext_grid": array([], dtype=int), "gen": array([], dtype=int), "branch": array([], dtype=int) } # convert pandapower net to ppc ppc, ppci = _pd2ppc(net) # store variables net["_ppc"] = ppc if "VERBOSE" not 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 _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 _init_ppc(net): _check_sc_data_integrity(net) _add_auxiliary_elements(net) ppc, _ = _pd2ppc(net) # Init the required columns to nan ppc["bus"][:, [K_G, K_SG, V_G, PS_TRAFO_IX, GS_P, BS_P,]] = np.nan ppc["branch"][:, [K_T, K_ST]] = np.nan # Add parameter K into ppc _add_kt(net, ppc) _add_gen_sc_z_kg_ks(net, ppc) _add_xward_sc_z(net, ppc) ppci = _ppc2ppci(ppc, net) return ppc, ppci
def _powerflow(net, **kwargs): """ Gets called by runpp or rundcpp with different arguments. """ # get infos from options ac = net["_options"]["ac"] algorithm = net["_options"]["algorithm"] net["converged"] = False net["OPF_converged"] = False _add_auxiliary_elements(net) if not ac or net["_options"]["init_results"]: verify_results(net) else: init_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 # clear lookups net._pd2ppc_lookups = { "bus": array([], dtype=int), "ext_grid": array([], dtype=int), "gen": array([], dtype=int), "branch": array([], dtype=int) } # 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 convert_to_pm_structure(net, opf_flow_lim="S"): if net["_options"]["voltage_depend_loads"] and not ( np.allclose(net.load.const_z_percent.values, 0) and np.allclose(net.load.const_i_percent.values, 0)): logger.error( "pandapower optimal_powerflow does not support voltage depend loads." ) net["OPF_converged"] = False net["converged"] = False _add_auxiliary_elements(net) init_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) pm = add_params_to_pm(net, pm) net._pm = pm return net, pm, ppc, ppci
def make_GSF(ppn, verify=True, using_sparse_solver=False): """ Build the Generation Shift Factor matrix of a pandapower net. Parameters ---------- ppn : pandapower.network.Network Pandapower network verify : bool True to verify the GSF with that from DC power flow using_sparse_solver : bool True to use a sparse solver for pandapower maktPTDF Returns ------- np.ndarray The GSF array """ from pandapower.pypower.makePTDF import makePTDF from pandapower.pd2ppc import _pd2ppc # --- run DCPF --- pp.rundcpp(ppn) # --- compute PTDF --- _, ppci = _pd2ppc(ppn) ptdf = makePTDF(ppci["baseMVA"], ppci["bus"], ppci["branch"], using_sparse_solver=using_sparse_solver) # --- get the gsf --- line_size = ppn.line.shape[0] gsf = ptdf[0:line_size, :] if verify: _verifyGSF(ppn, gsf) return gsf
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 test_get_internal(): net = example_simple() # for Newton raphson pp.runpp(net) J_intern = net._ppc["internal"]["J"] ppc = net._ppc V_mag = ppc["bus"][:, 7][:-2] V_ang = ppc["bus"][:, 8][:-2] V = V_mag * np.exp(1j * V_ang / 180 * np.pi) # Get stored Ybus in ppc Ybus = ppc["internal"]["Ybus"] _, ppci = _pd2ppc(net) baseMVA, bus, gen, branch, ref, pv, pq, _, _, V0, _ = _get_pf_variables_from_ppci(ppci) pvpq = np.r_[pv, pq] J = _create_J_without_numba(Ybus, V, pvpq, pq) assert sum(sum(abs(abs(J.toarray()) - abs(J_intern.toarray())))) < 0.05