Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
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)