-
Notifications
You must be signed in to change notification settings - Fork 466
/
makeLODF.py
49 lines (36 loc) · 1.41 KB
/
makeLODF.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# -*- coding: utf-8 -*-
# Copyright 1996-2015 PSERC. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
# Copyright (c) 2016-2020 by University of Kassel and Fraunhofer Institute for Energy Economics
# and Energy System Technology (IEE), Kassel. All rights reserved.
"""Builds the line outage distribution factor matrix.
"""
from numpy import ones, diag, eye, r_, arange
import numpy as np
from scipy.sparse import csr_matrix as sparse
from .idx_brch import F_BUS, T_BUS
def makeLODF(branch, PTDF):
"""Builds the line outage distribution factor matrix.
Returns the DC line outage distribution factor matrix for a given PTDF.
The matrix is C{nbr x nbr}, where C{nbr} is the number of branches.
Example::
H = makePTDF(baseMVA, bus, branch)
LODF = makeLODF(branch, H)
@see: L{makePTDF}
@author: Ray Zimmerman (PSERC Cornell)
"""
nl, nb = PTDF.shape
f = np.real(branch[:, F_BUS])
t = np.real(branch[:, T_BUS])
Cft = sparse((r_[ones(nl), -ones(nl)],
(r_[f, t], r_[arange(nl), arange(nl)])), (nb, nl))
H = PTDF * Cft
h = diag(H, 0)
# Avoid zero division error
# Implies a N-1 contingency (No backup branch)
den = (ones((nl, nl)) - ones((nl, 1)) * h.T)
den[den == 0] = 1e-100
LODF = (H / den)
LODF = LODF - diag(diag(LODF)) - eye(nl, nl)
return LODF