Replacing spsolve from SciPy (SuperLU) with pyrlu solver in pplinsolve.
[PYPOWER.git] / pypower / d2Sbr_dV2.py
blob1c7f046930a6cdc698e9f9857a57a23c6df9321a
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.
6 """
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)
30 """
31 nb = len(V)
32 nl = len(lam)
33 ib = range(nb)
34 il = range(nl)
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)) )
43 F = B + B.T
44 G = csr_matrix((ones(nb) / abs(V), (ib, ib)))
46 Haa = F - D - E
47 Hva = 1j * G * (B - B.T - D + E)
48 Hav = Hva.T
49 Hvv = G * F * G
51 return Haa, Hav, Hva, Hvv