e2nIEE / pandapower
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.
4

5 1
"""Computes 2nd derivatives of complex power flow w.r.t. voltage.
6
"""
7

8 1
from numpy import ones, conj
9 1
from scipy.sparse import csr_matrix
10

11

12 1
def d2Sbr_dV2(Cbr, Ybr, V, lam):
13
    """Computes 2nd derivatives of complex power flow w.r.t. voltage.
14

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.
20

21
    For more details on the derivations behind the derivative code used
22
    in PYPOWER information, see:
23

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}
28

29
    @author: Ray Zimmerman (PSERC Cornell)
30
    """
31 0
    nb = len(V)
32 0
    nl = len(lam)
33 0
    ib = range(nb)
34 0
    il = range(nl)
35

36 0
    diaglam = csr_matrix((lam, (il, il)))
37 0
    diagV = csr_matrix((V, (ib, ib)))
38

39 0
    A = Ybr.H * diaglam * Cbr
40 0
    B = conj(diagV) * A * diagV
41 0
    D = csr_matrix( ((A * V) * conj(V), (ib, ib)) )
42 0
    E = csr_matrix( ((A.T * conj(V) * V), (ib, ib)) )
43 0
    F = B + B.T
44 0
    G = csr_matrix((ones(nb) / abs(V), (ib, ib)))
45

46 0
    Haa = F - D - E
47 0
    Hva = 1j * G * (B - B.T - D + E)
48 0
    Hav = Hva.T
49 0
    Hvv = G * F * G
50

51 0
    return Haa, Hav, Hva, Hvv

Read our documentation on viewing source code .

Loading