Package pypower :: Module makeBdc
[hide private]
[frames] | no frames]

Source Code for Module pypower.makeBdc

 1  # Copyright (C) 1996-2011 Power System Engineering Research Center (PSERC) 
 2  # Copyright (C) 2011 Richard Lincoln 
 3  # 
 4  # PYPOWER is free software: you can redistribute it and/or modify 
 5  # it under the terms of the GNU General Public License as published 
 6  # by the Free Software Foundation, either version 3 of the License, 
 7  # or (at your option) any later version. 
 8  # 
 9  # PYPOWER is distributed in the hope that it will be useful, 
10  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
11  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
12  # GNU General Public License for more details. 
13  # 
14  # You should have received a copy of the GNU General Public License 
15  # along with PYPOWER. If not, see <http://www.gnu.org/licenses/>. 
16   
17  """Builds the B matrices and phase shift injections for DC power flow. 
18  """ 
19   
20  from sys import stderr 
21   
22  from numpy import ones, r_, pi, flatnonzero as find 
23  from scipy.sparse import csr_matrix as sparse 
24   
25  from idx_bus import BUS_I 
26  from idx_brch import F_BUS, T_BUS, BR_X, TAP, SHIFT, BR_STATUS 
27   
28   
29 -def makeBdc(baseMVA, bus, branch):
30 """Builds the B matrices and phase shift injections for DC power flow. 31 32 Returns the B matrices and phase shift injection vectors needed for a 33 DC power flow. 34 The bus real power injections are related to bus voltage angles by:: 35 P = Bbus * Va + PBusinj 36 The real power flows at the from end the lines are related to the bus 37 voltage angles by:: 38 Pf = Bf * Va + Pfinj 39 Does appropriate conversions to p.u. 40 41 @see: L{dcpf} 42 43 @author: Carlos E. Murillo-Sanchez (PSERC Cornell & Universidad 44 Autonoma de Manizales) 45 @author: Ray Zimmerman (PSERC Cornell) 46 @author: Richard Lincoln 47 """ 48 ## constants 49 nb = bus.shape[0] ## number of buses 50 nl = branch.shape[0] ## number of lines 51 52 ## check that bus numbers are equal to indices to bus (one set of bus nums) 53 if any(bus[:, BUS_I] != range(nb)): 54 stderr.write('makeBdc: buses must be numbered consecutively in ' 55 'bus matrix\n') 56 57 ## for each branch, compute the elements of the branch B matrix and the phase 58 ## shift "quiescent" injections, where 59 ## 60 ## | Pf | | Bff Bft | | Vaf | | Pfinj | 61 ## | | = | | * | | + | | 62 ## | Pt | | Btf Btt | | Vat | | Ptinj | 63 ## 64 stat = branch[:, BR_STATUS] ## ones at in-service branches 65 b = stat / branch[:, BR_X] ## series susceptance 66 tap = ones(nl) ## default tap ratio = 1 67 i = find(branch[:, TAP]) ## indices of non-zero tap ratios 68 tap[i] = branch[i, TAP] ## assign non-zero tap ratios 69 b = b / tap 70 71 ## build connection matrix Cft = Cf - Ct for line and from - to buses 72 f = branch[:, F_BUS] ## list of "from" buses 73 t = branch[:, T_BUS] ## list of "to" buses 74 i = r_[range(nl), range(nl)] ## double set of row indices 75 ## connection matrix 76 Cft = sparse((r_[ones(nl), -ones(nl)], (i, r_[f, t])), (nl, nb)) 77 78 ## build Bf such that Bf * Va is the vector of real branch powers injected 79 ## at each branch's "from" bus 80 Bf = sparse((r_[b, -b], (i, r_[f, t])))## = spdiags(b, 0, nl, nl) * Cft 81 82 ## build Bbus 83 Bbus = Cft.T * Bf 84 85 ## build phase shift injection vectors 86 Pfinj = b * (-branch[:, SHIFT] * pi / 180) ## injected at the from bus ... 87 # Ptinj = -Pfinj ## and extracted at the to bus 88 Pbusinj = Cft.T * Pfinj ## Pbusinj = Cf * Pfinj + Ct * Ptinj 89 90 return Bbus, Bf, Pbusinj, Pfinj
91