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