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

Source Code for Module pypower.makeAvl

 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  """Construct linear constraints for constant power factor var loads. 
18  """ 
19   
20  from sys import stderr 
21   
22  from numpy import array, zeros, arange, sin, cos, arctan2, r_ 
23  from numpy import flatnonzero as find 
24  from scipy.sparse import csr_matrix as sparse 
25   
26  from idx_gen import PG, QG, PMIN, QMIN, QMAX 
27   
28  from isload import isload 
29   
30   
31 -def makeAvl(baseMVA, gen):
32 """Construct linear constraints for constant power factor var loads. 33 34 Constructs parameters for the following linear constraint enforcing a 35 constant power factor constraint for dispatchable loads:: 36 37 lvl <= Avl * [Pg, Qg] <= uvl 38 39 C{ivl} is the vector of indices of generators representing variable loads. 40 41 @author: Ray Zimmerman (PSERC Cornell) 42 @author: Carlos E. Murillo-Sanchez (PSERC Cornell & Universidad 43 Autonoma de Manizales) 44 @author: Richard Lincoln 45 """ 46 ## data dimensions 47 ng = gen.shape[0] ## number of dispatchable injections 48 Pg = gen[:, PG] / baseMVA 49 Qg = gen[:, QG] / baseMVA 50 Pmin = gen[:, PMIN] / baseMVA 51 Qmin = gen[:, QMIN] / baseMVA 52 Qmax = gen[:, QMAX] / baseMVA 53 54 # Find out if any of these "generators" are actually dispatchable loads. 55 # (see 'help isload' for details on what constitutes a dispatchable load) 56 # Dispatchable loads are modeled as generators with an added constant 57 # power factor constraint. The power factor is derived from the original 58 # value of Pmin and either Qmin (for inductive loads) or Qmax (for 59 # capacitive loads). If both Qmin and Qmax are zero, this implies a unity 60 # power factor without the need for an additional constraint. 61 62 ivl = find( isload(gen) & ((Qmin != 0) | (Qmax != 0)) ) 63 nvl = ivl.shape[0] ## number of dispatchable loads 64 65 ## at least one of the Q limits must be zero (corresponding to Pmax == 0) 66 if any( (Qmin[ivl] != 0) & (Qmax[ivl] != 0) ): 67 stderr.write('makeAvl: either Qmin or Qmax must be equal to zero for ' 68 'each dispatchable load.\n') 69 70 # Initial values of PG and QG must be consistent with specified power 71 # factor This is to prevent a user from unknowingly using a case file which 72 # would have defined a different power factor constraint under a previous 73 # version which used PG and QG to define the power factor. 74 Qlim = (Qmin[ivl] == 0) * Qmax[ivl] + (Qmax[ivl] == 0) * Qmin[ivl] 75 if any( abs( Qg[ivl] - Pg[ivl] * Qlim / Pmin[ivl] ) > 1e-6 ): 76 stderr.write('makeAvl: For a dispatchable load, PG and QG must be ' 77 'consistent with the power factor defined by PMIN and ' 78 'the Q limits.\n') 79 80 # make Avl, lvl, uvl, for lvl <= Avl * [Pg Qg] <= uvl 81 if nvl > 0: 82 xx = Pmin[ivl] 83 yy = Qlim 84 pftheta = arctan2(yy, xx) 85 pc = sin(pftheta) 86 qc = -cos(pftheta) 87 ii = r_[ arange(nvl), arange(nvl) ] 88 jj = r_[ ivl, ivl + ng ] 89 Avl = sparse((r_[pc, qc], (ii, jj)), (nvl, 2 * ng)) 90 lvl = zeros(nvl) 91 uvl = lvl 92 else: 93 Avl = zeros((0, 2*ng)) 94 lvl = array([]) 95 uvl = array([]) 96 97 return Avl, lvl, uvl, ivl
98