Package pypower :: Module d2Sbr_dV2
[hide private]
[frames] | no frames]

Source Code for Module pypower.d2Sbr_dV2

 1  # Copyright (C) 2008-2011 Power System Engineering Research Center (PSERC) 
 2  # Copyright (C) 2011 Richard Lincoln 
 3  # 
 4  # PYPOWER is free software: you can redistribute it and/or modify 
 5  # it under the terms of the GNU General Public License as published 
 6  # by the Free Software Foundation, either version 3 of the License, 
 7  # or (at your option) any later version. 
 8  # 
 9  # PYPOWER is distributed in the hope that it will be useful, 
10  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
11  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
12  # GNU General Public License for more details. 
13  # 
14  # You should have received a copy of the GNU General Public License 
15  # along with PYPOWER. If not, see <http://www.gnu.org/licenses/>. 
16   
17  """Computes 2nd derivatives of complex power flow w.r.t. voltage. 
18  """ 
19   
20  from numpy import ones, conj 
21  from scipy.sparse import csr_matrix 
22   
23   
24 -def d2Sbr_dV2(Cbr, Ybr, V, lam):
25 """Computes 2nd derivatives of complex power flow 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 branch power flows. Takes sparse connection 30 matrix C{Cbr}, sparse branch admittance matrix C{Ybr}, voltage vector C{V} 31 and C{nl x 1} vector of 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 nl = len(lam) 46 ib = range(nb) 47 il = range(nl) 48 49 diaglam = csr_matrix((lam, (il, il))) 50 diagV = csr_matrix((V, (ib, ib))) 51 52 A = Ybr.H * diaglam * Cbr 53 B = conj(diagV) * A * diagV 54 D = csr_matrix( ((A * V) * conj(V), (ib, ib)) ) 55 E = csr_matrix( ((A.T * conj(V) * V), (ib, ib)) ) 56 F = B + B.T 57 G = csr_matrix((ones(nb) / abs(V), (ib, ib))) 58 59 Haa = F - D - E 60 Hva = 1j * G * (B - B.T - D + E) 61 Hav = Hva.T 62 Hvv = G * F * G 63 64 return Haa, Hav, Hva, Hvv
65