Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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")
_extract_results(net, ppc, ppc_0=None)
_clean_up(net)
_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)
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_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 _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)
_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)
# t5 = time.perf_counter()
pass
# writes res_bus.vm_pu / va_degree and res_line
_extract_results_se(net, ppc)
# restore backup of previous results
_rename_results(net)
# additionally, write bus power demand results (these are not written in _extract_results)
mapping_table = net["_pd2ppc_lookups"]["bus"]
net.res_bus_est.index = net.bus.index
net.res_bus_est.p_mw = get_values(ppc["bus"][:, 2], net.bus.index.values,
mapping_table)
net.res_bus_est.q_mvar = get_values(ppc["bus"][:, 3], net.bus.index.values,
mapping_table)
_clean_up(net)
# delete results which are not correctly calculated
for k in list(net.keys()):
if k.startswith("res_") and k.endswith("_est") and \
k not in ("res_bus_est", "res_line_est", "res_trafo_est", "res_trafo3w_est"):
del net[k]
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()
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)
# t5 = time.perf_counter()
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 _read_results_to_net(net, ppc, ppci, result_pm):
"""
reads power models results from result_pm to ppc / ppci and then to pandapower net
"""
# read power models results from result_pm to result (== ppc with results)
result, multinetwork = pm_results_to_ppc_results(net, ppc, ppci, result_pm)
net._pm_result = result_pm
success = ppc["success"]
if success:
if not multinetwork:
# results are extracted from a single time step to pandapower dataframes
_extract_results(net, result)
_clean_up(net)
net["OPF_converged"] = True
else:
_clean_up(net, res=False)
logger.warning("OPF did not converge!")