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

Source Code for Module pypower.dIbr_dV

 1  # Copyright (C) 1996-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 partial derivatives of branch currents w.r.t. voltage. 
18  """ 
19   
20  from numpy import diag, asmatrix, asarray 
21  from scipy.sparse import issparse, csr_matrix as sparse 
22   
23   
24 -def dIbr_dV(branch, Yf, Yt, V):
25 """Computes partial derivatives of branch currents w.r.t. voltage. 26 27 Returns four matrices containing partial derivatives of the complex 28 branch currents at "from" and "to" ends of each branch w.r.t voltage 29 magnitude and voltage angle respectively (for all buses). If C{Yf} is a 30 sparse matrix, the partial derivative matrices will be as well. Optionally 31 returns vectors containing the currents themselves. The following 32 explains the expressions used to form the matrices:: 33 34 If = Yf * V 35 36 Partials of V, Vf & If w.r.t. voltage angles:: 37 dV/dVa = j * diag(V) 38 dVf/dVa = sparse(range(nl), f, j*V(f)) = j * sparse(range(nl), f, V(f)) 39 dIf/dVa = Yf * dV/dVa = Yf * j * diag(V) 40 41 Partials of V, Vf & If w.r.t. voltage magnitudes:: 42 dV/dVm = diag(V / abs(V)) 43 dVf/dVm = sparse(range(nl), f, V(f) / abs(V(f)) 44 dIf/dVm = Yf * dV/dVm = Yf * diag(V / abs(V)) 45 46 Derivations for "to" bus are similar. 47 48 @author: Ray Zimmerman (PSERC Cornell) 49 @author: Richard Lincoln 50 """ 51 i = range(len(V)) 52 53 Vnorm = V / abs(V) 54 55 if issparse(Yf): 56 diagV = sparse((V, (i, i))) 57 diagVnorm = sparse((Vnorm, (i, i))) 58 else: 59 diagV = asmatrix( diag(V) ) 60 diagVnorm = asmatrix( diag(Vnorm) ) 61 62 dIf_dVa = Yf * 1j * diagV 63 dIf_dVm = Yf * diagVnorm 64 dIt_dVa = Yt * 1j * diagV 65 dIt_dVm = Yt * diagVnorm 66 67 # Compute currents. 68 if issparse(Yf): 69 If = Yf * V 70 It = Yt * V 71 else: 72 If = asarray( Yf * asmatrix(V).T ).flatten() 73 It = asarray( Yt * asmatrix(V).T ).flatten() 74 75 return dIf_dVa, dIf_dVm, dIt_dVa, dIt_dVm, If, It
76