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

Source Code for Module pypower.hasPQcap

 1  # Copyright (C) 2005-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  """Checks for P-Q capability curve constraints. 
18  """ 
19   
20  from sys import stderr 
21   
22  from numpy import any, zeros, nonzero 
23   
24  from idx_gen import QMAX, QMIN, PMAX, PC1, PC2, QC1MIN, QC1MAX, QC2MIN, QC2MAX 
25   
26   
27 -def hasPQcap(gen, hilo='B'):
28 """Checks for P-Q capability curve constraints. 29 30 Returns a column vector of 1's and 0's. The 1's correspond to rows of 31 the C{gen} matrix which correspond to generators which have defined a 32 capability curve (with sloped upper and/or lower bound on Q) and require 33 that additional linear constraints be added to the OPF. 34 35 The C{gen} matrix in version 2 of the PYPOWER case format includes columns 36 for specifying a P-Q capability curve for a generator defined as the 37 intersection of two half-planes and the box constraints on P and Q. The 38 two half planes are defined respectively as the area below the line 39 connecting (Pc1, Qc1max) and (Pc2, Qc2max) and the area above the line 40 connecting (Pc1, Qc1min) and (Pc2, Qc2min). 41 42 If the optional 2nd argument is 'U' this function returns C{True} only for 43 rows corresponding to generators that require the upper constraint on Q. 44 If it is 'L', only for those requiring the lower constraint. If the 2nd 45 argument is not specified or has any other value it returns true for rows 46 corresponding to gens that require either or both of the constraints. 47 48 It is smart enough to return C{True} only if the corresponding linear 49 constraint is not redundant w.r.t the box constraints. 50 51 @author: Ray Zimmerman (PSERC Cornell) 52 @author: Richard Lincoln 53 """ 54 ## check for errors capability curve data 55 if any( gen[:, PC1] > gen[:, PC2] ): 56 stderr.write('hasPQcap: Pc1 > Pc2\n') 57 if any( gen[:, QC2MAX] > gen[:, QC1MAX] ): 58 stderr.write('hasPQcap: Qc2max > Qc1max\n') 59 if any( gen[:, QC2MIN] < gen[:, QC1MIN] ): 60 stderr.write('hasPQcap: Qc2min < Qc1min\n') 61 62 L = zeros(gen.shape[0], bool) 63 U = zeros(gen.shape[0], bool) 64 k = nonzero( gen[:, PC1] != gen[:, PC2] ) 65 66 if hilo != 'U': ## include lower constraint 67 Qmin_at_Pmax = gen[k, QC1MIN] + (gen[k, PMAX] - gen[k, PC1]) * \ 68 (gen[k, QC2MIN] - gen[k, QC1MIN]) / (gen[k, PC2] - gen[k, PC1]) 69 L[k] = Qmin_at_Pmax > gen[k, QMIN] 70 71 if hilo != 'L': ## include upper constraint 72 Qmax_at_Pmax = gen[k, QC1MAX] + (gen[k, PMAX] - gen[k, PC1]) * \ 73 (gen[k, QC2MAX] - gen[k, QC1MAX]) / (gen[k, PC2] - gen[k, PC1]) 74 U[k] = Qmax_at_Pmax < gen[k, QMAX] 75 76 return L | U
77