-
Notifications
You must be signed in to change notification settings - Fork 149
/
d2Abr_dV2.m
68 lines (64 loc) · 2.67 KB
/
d2Abr_dV2.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
function [H11, H12, H21, H22] = d2Abr_dV2(d2F_dV2, dF_dV1, dF_dV2, F, V, mu)
% d2Abr_dV2 - Computes 2nd derivatives of ``|branch flow|^2`` w.r.t. V.
% ::
%
% The derivatives can be take with respect to polar or cartesian coordinates
% of voltage, depending on the first 3 arguments. Flows could be complex
% current or complex or real power. Notation below is based on complex power.
%
% [H11, H12, H21, H22] = D2ABR_DV2(D2F_DV2, DF_DV1, DF_DV2, F, V, MU)
%
% Returns 4 matrices containing the partial derivatives w.r.t. voltage
% components (angle, magnitude or real, imaginary) of the product of a
% vector MU with the 1st partial derivatives of the square of the magnitude
% of branch flows.
%
% Takes as inputs a handle to a function that evaluates the 2nd derivatives
% of the flows (with args V and mu only), sparse first derivative matrices
% of flow, flow vector, voltage vector V and nl x 1 vector of multipliers
% MU. Output matrices are sparse.
%
% Example:
% f = branch(:, F_BUS);
% Cf = sparse(1:nl, f, ones(nl, 1), nl, nb);
% [Ybus, Yf, Yt] = makeYbus(baseMVA, bus, branch);
% [dSf_dV1, dSf_dV2, dSt_dV1, dSt_dV2, Sf, St] = ...
% dSbr_dV(branch, Yf, Yt, V);
% dF_dV1 = dSf_dV1;
% dF_dV2 = dSf_dV2;
% F = Sf;
% d2F_dV2 = @(V, mu)d2Sbr_dV2(Cf, Yf, V, mu, 0);
% [H11, H12, H21, H22] = ...
% d2Abr_dV2(d2F_dV2, dF_dV1, dF_dV2, F, V, mu);
%
% Here the output matrices correspond to:
% H11 = d/dV1 (dAF_dV1.' * mu)
% H12 = d/dV2 (dAF_dV1.' * mu)
% H21 = d/dV1 (dAF_dV2.' * mu)
% H22 = d/dV2 (dAF_dV2.' * mu)
%
% See also dAbr_dV, dIbr_dV, dSbr_dV.
%
% For more details on the derivations behind the derivative code used
% in |MATPOWER| information, see::
%
% [TN2] R. D. Zimmerman, "AC Power Flows, Generalized OPF Costs and
% their Derivatives using Complex Matrix Notation", MATPOWER
% Technical Note 2, February 2010. [Online]. Available:
% https://matpower.org/docs/TN2-OPF-Derivatives.pdf
% doi: 10.5281/zenodo.3237866
% MATPOWER
% Copyright (c) 2008-2024, Power Systems Engineering Research Center (PSERC)
% by Ray Zimmerman, PSERC Cornell
%
% This file is part of MATPOWER.
% Covered by the 3-clause BSD License (see LICENSE file for details).
% See https://matpower.org for more info.
%% define
nl = length(mu);
diagmu = sparse(1:nl, 1:nl, mu, nl, nl);
[F11, F12, F21, F22] = d2F_dV2(V, conj(F) .* mu);
H11 = 2 * real( F11 + dF_dV1.' * diagmu * conj(dF_dV1) );
H21 = 2 * real( F21 + dF_dV2.' * diagmu * conj(dF_dV1) );
H12 = 2 * real( F12 + dF_dV1.' * diagmu * conj(dF_dV2) );
H22 = 2 * real( F22 + dF_dV2.' * diagmu * conj(dF_dV2) );