1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 """Computes 2nd derivatives of power injection w.r.t. voltage.
18 """
19
20 from numpy import ones, conj, arange
21 from scipy.sparse import csr_matrix as sparse
22
23
25 """Computes 2nd derivatives of power injection w.r.t. voltage.
26
27 Returns 4 matrices containing the partial derivatives w.r.t. voltage angle
28 and magnitude of the product of a vector C{lam} with the 1st partial
29 derivatives of the complex bus power injections. Takes sparse bus
30 admittance matrix C{Ybus}, voltage vector C{V} and C{nb x 1} vector of
31 multipliers C{lam}. Output matrices are sparse.
32
33 For more details on the derivations behind the derivative code used
34 in PYPOWER information, see:
35
36 [TN2] R. D. Zimmerman, I{"AC Power Flows, Generalized OPF Costs and
37 their Derivatives using Complex Matrix Notation"}, MATPOWER
38 Technical Note 2, February 2010.
39 U{http://www.pserc.cornell.edu/matpower/TN2-OPF-Derivatives.pdf}
40
41 @author: Ray Zimmerman (PSERC Cornell)
42 @author: Richard Lincoln
43 """
44 nb = len(V)
45 ib = arange(nb)
46 Ibus = Ybus * V
47 diaglam = sparse((lam, (ib, ib)))
48 diagV = sparse((V, (ib, ib)))
49
50 A = sparse((lam * V, (ib, ib)))
51 B = Ybus * diagV
52 C = A * conj(B)
53 D = Ybus.H * diagV
54 E = diagV.conj() * (D * diaglam - sparse((D * lam, (ib, ib))))
55 F = C - A * sparse((conj(Ibus), (ib, ib)))
56 G = sparse((ones(nb) / abs(V), (ib, ib)))
57
58 Gaa = E + F
59 Gva = 1j * G * (E - F)
60 Gav = Gva.T
61 Gvv = G * (C + C.T) * G
62
63 return Gaa, Gav, Gva, Gvv
64