1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 """Computes 2nd derivatives of |complex power flow|**2 w.r.t. V.
18 """
19
20 from scipy.sparse import csr_matrix
21
22 from d2Sbr_dV2 import d2Sbr_dV2
23
24
25 -def d2ASbr_dV2(dSbr_dVa, dSbr_dVm, Sbr, Cbr, Ybr, V, lam):
26 """Computes 2nd derivatives of |complex power flow|**2 w.r.t. V.
27
28 Returns 4 matrices containing the partial derivatives w.r.t. voltage
29 angle and magnitude of the product of a vector C{lam} with the 1st partial
30 derivatives of the square of the magnitude of branch complex power flows.
31 Takes sparse first derivative matrices of complex flow, complex flow
32 vector, sparse connection matrix C{Cbr}, sparse branch admittance matrix
33 C{Ybr}, voltage vector C{V} and C{nl x 1} vector of multipliers C{lam}.
34 Output matrices are sparse.
35
36 For more details on the derivations behind the derivative code used
37 in PYPOWER information, see:
38
39 [TN2] R. D. Zimmerman, I{"AC Power Flows, Generalized OPF Costs and
40 their Derivatives using Complex Matrix Notation"}, MATPOWER
41 Technical Note 2, February 2010.
42 U{http://www.pserc.cornell.edu/matpower/TN2-OPF-Derivatives.pdf}
43
44 @see: L{dSbr_dV}
45
46 @author: Ray Zimmerman (PSERC Cornell)
47 @author: Richard Lincoln
48 """
49 il = range(len(lam))
50
51 diaglam = csr_matrix((lam, (il, il)))
52 diagSbr_conj = csr_matrix((Sbr.conj(), (il, il)))
53
54 Saa, Sav, Sva, Svv = d2Sbr_dV2(Cbr, Ybr, V, diagSbr_conj * lam)
55
56 Haa = 2 * ( Saa + dSbr_dVa.T * diaglam * dSbr_dVa.conj() ).real
57 Hva = 2 * ( Sva + dSbr_dVm.T * diaglam * dSbr_dVa.conj() ).real
58 Hav = 2 * ( Sav + dSbr_dVa.T * diaglam * dSbr_dVm.conj() ).real
59 Hvv = 2 * ( Svv + dSbr_dVm.T * diaglam * dSbr_dVm.conj() ).real
60
61 return Haa, Hav, Hva, Hvv
62