Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
def _optimal_powerflow(net, verbose, suppress_warnings, **kwargs):
    ac = net["_options"]["ac"]
    init = net["_options"]["init"]

    if "OPF_FLOW_LIM" not in kwargs:
        kwargs["OPF_FLOW_LIM"] = 2

    if net["_options"]["voltage_depend_loads"] and not (
            allclose(net.load.const_z_percent.values, 0)
            and allclose(net.load.const_i_percent.values, 0)):
        logger.error(
            "pandapower optimal_powerflow does not support voltage depend loads."
        )

    ppopt = ppoption(VERBOSE=verbose, PF_DC=not ac, INIT=init, **kwargs)
    net["OPF_converged"] = False
    net["converged"] = False
    _add_auxiliary_elements(net)

    if not ac or net["_options"]["init_results"]:
        verify_results(net)
    else:
        init_results(net, "opf")

    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"],
                branch=result["branch"],
                f=result["f"],
                success=result["success"],
                et=result["et"],
                fd=stdout,
                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)