1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
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
47 ng = gen.shape[0]
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
55
56
57
58
59
60
61
62 ivl = find( isload(gen) & ((Qmin != 0) | (Qmax != 0)) )
63 nvl = ivl.shape[0]
64
65
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
71
72
73
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
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