1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 """Partial derivatives of squared flow magnitudes w.r.t voltage.
18 """
19
20 from scipy.sparse import csr_matrix
21
22
23 -def dAbr_dV(dSf_dVa, dSf_dVm, dSt_dVa, dSt_dVm, Sf, St):
24 """Partial derivatives of squared flow magnitudes w.r.t voltage.
25
26 Returns four matrices containing partial derivatives of the square of
27 the branch flow magnitudes at "from" & "to" ends of each branch w.r.t
28 voltage magnitude and voltage angle respectively (for all buses), given
29 the flows and flow sensitivities. Flows could be complex current or
30 complex or real power. Notation below is based on complex power. The
31 following explains the expressions used to form the matrices:
32
33 Let Af refer to the square of the apparent power at the "from" end of
34 each branch::
35
36 Af = abs(Sf)**2
37 = Sf .* conj(Sf)
38 = Pf**2 + Qf**2
39
40 then ...
41
42 Partial w.r.t real power::
43 dAf/dPf = 2 * diag(Pf)
44
45 Partial w.r.t reactive power::
46 dAf/dQf = 2 * diag(Qf)
47
48 Partial w.r.t Vm & Va::
49 dAf/dVm = dAf/dPf * dPf/dVm + dAf/dQf * dQf/dVm
50 dAf/dVa = dAf/dPf * dPf/dVa + dAf/dQf * dQf/dVa
51
52 Derivations for "to" bus are similar.
53
54 For more details on the derivations behind the derivative code used
55 in PYPOWER information, see:
56
57 [TN2] R. D. Zimmerman, I{"AC Power Flows, Generalized OPF Costs and
58 their Derivatives using Complex Matrix Notation"}, MATPOWER
59 Technical Note 2, February 2010.
60 U{http://www.pserc.cornell.edu/matpower/TN2-OPF-Derivatives.pdf}
61
62 @return: The partial derivatives of the squared flow magnitudes w.r.t
63 voltage magnitude and voltage angle given the flows and flow
64 sensitivities. Flows could be complex current or complex or
65 real power.
66 @see: L{dIbr_dV}, L{dSbr_dV}
67
68 @author: Ray Zimmerman (PSERC Cornell)
69 @author: Richard Lincoln
70 """
71 il = range(len(Sf))
72
73 dAf_dPf = csr_matrix((2 * Sf.real, (il, il)))
74 dAf_dQf = csr_matrix((2 * Sf.imag, (il, il)))
75 dAt_dPt = csr_matrix((2 * St.real, (il, il)))
76 dAt_dQt = csr_matrix((2 * St.imag, (il, il)))
77
78
79
80 dAf_dVa = dAf_dPf * dSf_dVa.real + dAf_dQf * dSf_dVa.imag
81 dAt_dVa = dAt_dPt * dSt_dVa.real + dAt_dQt * dSt_dVa.imag
82
83
84 dAf_dVm = dAf_dPf * dSf_dVm.real + dAf_dQf * dSf_dVm.imag
85 dAt_dVm = dAt_dPt * dSt_dVm.real + dAt_dQt * dSt_dVm.imag
86
87 return dAf_dVa, dAf_dVm, dAt_dVa, dAt_dVm
88