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

Source Code for Module pypower.bustypes

 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 index lists of each type of bus. 
18  """ 
19   
20  from numpy import ones, flatnonzero as find 
21  from scipy.sparse import csr_matrix as sparse 
22   
23  from pypower.idx_bus import BUS_TYPE, REF, PV, PQ 
24  from pypower.idx_gen import GEN_BUS, GEN_STATUS 
25   
26   
27 -def bustypes(bus, gen):
28 """Builds index lists of each type of bus (C{REF}, C{PV}, C{PQ}). 29 30 Generators with "out-of-service" status are treated as L{PQ} buses with 31 zero generation (regardless of C{Pg}/C{Qg} values in gen). Expects C{bus} 32 and C{gen} have been converted to use internal consecutive bus numbering. 33 34 @param bus: bus data 35 @param gen: generator data 36 @return: index lists of each bus type 37 38 @author: Ray Zimmerman (PSERC Cornell) 39 @author: Richard Lincoln 40 """ 41 # get generator status 42 nb = bus.shape[0] 43 ng = gen.shape[0] 44 # gen connection matrix, element i, j is 1 if, generator j at bus i is ON 45 Cg = sparse((gen[:, GEN_STATUS] > 0, 46 (gen[:, GEN_BUS], range(ng))), (nb, ng)) 47 # number of generators at each bus that are ON 48 bus_gen_status = (Cg * ones(ng, int)).astype(bool) 49 50 # form index lists for slack, PV, and PQ buses 51 ref = find((bus[:, BUS_TYPE] == REF) & bus_gen_status) # ref bus index 52 pv = find((bus[:, BUS_TYPE] == PV) & bus_gen_status) # PV bus indices 53 pq = find((bus[:, BUS_TYPE] == PQ) | ~bus_gen_status) # PQ bus indices 54 55 # pick a new reference bus if for some reason there is none (may have been 56 # shut down) 57 if len(ref) == 0: 58 ref = pv[0] # use the first PV bus 59 pv = pv[1:] # take it off PV list 60 61 return ref, pv, pq
62