1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
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
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