1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
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
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':
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':
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