1 # Copyright (c) 1996-2015 PSERC. All rights reserved.
2 # Use of this source code is governed by a BSD-style
3 # license that can be found in the LICENSE file.
5 """Computes 2nd derivatives of complex power flow w.r.t. voltage.
8 from numpy
import ones
, conj
9 from scipy
.sparse
import csr_matrix
12 def d2Sbr_dV2(Cbr
, Ybr
, V
, lam
):
13 """Computes 2nd derivatives of complex power flow w.r.t. voltage.
15 Returns 4 matrices containing the partial derivatives w.r.t. voltage angle
16 and magnitude of the product of a vector C{lam} with the 1st partial
17 derivatives of the complex branch power flows. Takes sparse connection
18 matrix C{Cbr}, sparse branch admittance matrix C{Ybr}, voltage vector C{V}
19 and C{nl x 1} vector of multipliers C{lam}. Output matrices are sparse.
21 For more details on the derivations behind the derivative code used
22 in PYPOWER information, see:
24 [TN2] R. D. Zimmerman, I{"AC Power Flows, Generalized OPF Costs and
25 their Derivatives using Complex Matrix Notation"}, MATPOWER
26 Technical Note 2, February 2010.
27 U{http://www.pserc.cornell.edu/matpower/TN2-OPF-Derivatives.pdf}
29 @author: Ray Zimmerman (PSERC Cornell)
36 diaglam
= csr_matrix((lam
, (il
, il
)))
37 diagV
= csr_matrix((V
, (ib
, ib
)))
39 A
= Ybr
.getH() * diaglam
* Cbr
40 B
= conj(diagV
) * A
* diagV
41 D
= csr_matrix( ((A
* V
) * conj(V
), (ib
, ib
)) )
42 E
= csr_matrix( ((A
.T
* conj(V
) * V
), (ib
, ib
)) )
44 G
= csr_matrix((ones(nb
) / abs(V
), (ib
, ib
)))
47 Hva
= 1j
* G
* (B
- B
.T
- D
+ E
)
51 return Haa
, Hav
, Hva
, Hvv