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

Source Code for Module pypower.makeSbus

 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 vector of complex bus power injections. 
18  """ 
19   
20  from numpy import ones, flatnonzero as find 
21  from scipy.sparse import csr_matrix as sparse 
22   
23  from idx_bus import PD, QD 
24  from idx_gen import GEN_BUS, PG, QG, GEN_STATUS 
25   
26   
27 -def makeSbus(baseMVA, bus, gen):
28 """Builds the vector of complex bus power injections. 29 30 Returns the vector of complex bus power injections, that is, generation 31 minus load. Power is expressed in per unit. 32 33 @see: L{makeYbus} 34 35 @author: Ray Zimmerman (PSERC Cornell) 36 @author: Richard Lincoln 37 """ 38 ## generator info 39 on = find(gen[:, GEN_STATUS] > 0) ## which generators are on? 40 gbus = gen[on, GEN_BUS] ## what buses are they at? 41 42 ## form net complex bus power injection vector 43 nb = bus.shape[0] 44 ngon = on.shape[0] 45 ## connection matrix, element i, j is 1 if gen on(j) at bus i is ON 46 Cg = sparse((ones(ngon), (gbus, range(ngon))), (nb, ngon)) 47 48 ## power injected by gens plus power injected by loads converted to p.u. 49 Sbus = ( Cg * (gen[on, PG] + 1j * gen[on, QG]) - 50 (bus[:, PD] + 1j * bus[:, QD]) ) / baseMVA 51 52 return Sbus
53