Esempio n. 1
0
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)
Esempio n. 2
0
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)
    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)
Esempio n. 3
0
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)
Esempio n. 4
0
    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
Esempio n. 5
0
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}
Esempio n. 6
0
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)
Esempio n. 7
0
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!")