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

3
# Copyright 1996-2015 PSERC. All rights reserved.
4
# Use of this source code is governed by a BSD-style
5
# license that can be found in the LICENSE file.
6

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

10
# Builds the line outage distribution factor matrix.
11

12

13 1
from numpy import ones, diag, r_, arange
14 1
import numpy as np
15 1
from scipy.sparse import csr_matrix as sparse
16 1
try:
17 1
    from numba import jit
18
except ImportError: # pragma: no cover
19
    from pandapower.pf.no_numba import jit
20

21 1
from .idx_brch import F_BUS, T_BUS
22

23

24 1
@jit
25
def update_LODF_diag(LODF): # pragma: no cover
26
    for ix in range(LODF.shape[0]):
27
        # To preserve the data type of diagnol elments
28
        LODF[ix, ix] -= (LODF[ix, ix] + 1.)
29

30

31 1
def makeLODF(branch, PTDF):
32
    """Builds the line outage distribution factor matrix.
33

34
    Returns the DC line outage distribution factor matrix for a given PTDF.
35
    The matrix is C{nbr x nbr}, where C{nbr} is the number of branches.
36

37
    Example::
38
        H = makePTDF(baseMVA, bus, branch)
39
        LODF = makeLODF(branch, H)
40

41
    @see: L{makePTDF}
42

43
    @author: Ray Zimmerman (PSERC Cornell)
44
    """
45 1
    nl, nb = PTDF.shape
46 1
    f = np.real(branch[:, F_BUS])
47 1
    t = np.real(branch[:, T_BUS])
48 1
    Cft = sparse((r_[ones(nl), -ones(nl)],
49
                      (r_[f, t], r_[arange(nl), arange(nl)])), (nb, nl))
50

51 1
    H = PTDF * Cft
52 1
    h = diag(H, 0)
53
    # Avoid zero division error
54
    # Implies a N-1 contingency (No backup branch)
55 1
    den = (ones((nl, 1)) * h.T * -1 + 1.)
56

57
    # Silence warning caused by np.NaN
58 1
    with np.errstate(divide='ignore', invalid='ignore'):
59 1
        LODF = (H / den)
60

61
    # LODF = LODF - diag(diag(LODF)) - eye(nl, nl)
62 1
    update_LODF_diag(LODF)
63

64 1
    return LODF

Read our documentation on viewing source code .

Loading