e2nIEE / pandapower
1
# -*- coding: utf-8 -*-
2

3
# Copyright (c) 2016-2021 by University of Kassel and Fraunhofer Institute for Energy Economics
4
# and Energy System Technology (IEE), Kassel. All rights reserved.
5

6 1
import numpy as np
7

8 1
from pandapower.pypower.idx_bus import PD, QD
9 1
from pandapower.pf.ppci_variables import _get_pf_variables_from_ppci
10 1
from pandapower.pf.pfsoln_numba import pfsoln
11 1
from pandapower.results import _copy_results_ppci_to_ppc, _extract_results_se, init_results
12 1
from pandapower.auxiliary import get_values
13

14

15 1
def _calc_power_flow(ppci, V):
16
    # store results for all elements
17
    # calculate branch results (in ppc_i)
18 1
    baseMVA, bus, gen, branch, ref, pv, pq, _, _, _, ref_gens = _get_pf_variables_from_ppci(ppci)
19 1
    Ybus, Yf, Yt = ppci['internal']['Ybus'], ppci['internal']['Yf'], ppci['internal']['Yt']
20 1
    ppci['bus'], ppci['gen'], ppci['branch'] =\
21
        pfsoln(baseMVA, bus, gen, branch, Ybus, Yf, Yt, V, ref, ref_gens)
22

23
    # calculate bus power injections
24 1
    Sbus = np.multiply(V, np.conj(Ybus * V)) * baseMVA
25 1
    ppci["bus"][:, PD] = -Sbus.real  # saved in MW, injection -> demand
26 1
    ppci["bus"][:, QD] = -Sbus.imag  # saved in Mvar, injection -> demand
27 1
    return ppci
28

29

30 1
def _extract_result_ppci_to_pp(net, ppc, ppci):
31
    # convert to pandapower indices
32 1
    ppc = _copy_results_ppci_to_ppc(ppci, ppc, mode="se")
33

34
    # inits empty result tables
35 1
    init_results(net, mode="se")
36

37
    # writes res_bus.vm_pu / va_degree and branch res
38 1
    _extract_results_se(net, ppc)
39

40
    # additionally, write bus power demand results (these are not written in _extract_results)
41 1
    mapping_table = net["_pd2ppc_lookups"]["bus"]
42 1
    net.res_bus_est.index = net.bus.index
43 1
    net.res_bus_est.p_mw = get_values(ppc["bus"][:, 2], net.bus.index.values,
44
                                      mapping_table)
45 1
    net.res_bus_est.q_mvar = get_values(ppc["bus"][:, 3], net.bus.index.values,
46
                                        mapping_table)
47 1
    return net
48

49

50 1
def eppci2pp(net, ppc, eppci):
51
    # calculate the branch power flow and bus power injection based on the estimated voltage vector
52 1
    eppci = _calc_power_flow(eppci, eppci.V)
53

54
    # extract the result from ppci to ppc and pandpower network
55 1
    net = _extract_result_ppci_to_pp(net, ppc, eppci)
56 1
    return net

Read our documentation on viewing source code .

Loading