-
Notifications
You must be signed in to change notification settings - Fork 0
/
makeYbus.m
executable file
·117 lines (107 loc) · 4.7 KB
/
makeYbus.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
function [Ybus, Yf, Yt] = makeYbus(baseMVA, bus, branch)
%MAKEYBUS Builds the bus admittance matrix and branch admittance matrices.
% [YBUS, YF, YT] = MAKEYBUS(MPC)
% [YBUS, YF, YT] = MAKEYBUS(BASEMVA, BUS, BRANCH)
%
% Returns the full bus admittance matrix (i.e. for all buses) and the
% matrices YF and YT which, when multiplied by a complex voltage vector,
% yield the vector currents injected into each line from the "from" and
% "to" buses respectively of each line. Does appropriate conversions to p.u.
% Inputs can be a MATPOWER case struct or individual BASEMVA, BUS and
% BRANCH values. Bus numbers must be consecutive beginning at 1 (internal
% ordering).
%
% See also MAKEJAC, MAKESBUS, EXT2INT.
% MATPOWER
% $Id: makeYbus.m,v 1.17 2010/06/25 17:37:40 ray Exp $
% by Ray Zimmerman, PSERC Cornell
% Copyright (c) 1996-2010 by Power System Engineering Research Center (PSERC)
%
% This file is part of MATPOWER.
% See http://www.pserc.cornell.edu/matpower/ for more info.
%
% MATPOWER is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published
% by the Free Software Foundation, either version 3 of the License,
% or (at your option) any later version.
%
% MATPOWER is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
%
% Additional permission under GNU GPL version 3 section 7
%
% If you modify MATPOWER, or any covered work, to interface with
% other modules (such as MATLAB code and MEX-files) available in a
% MATLAB(R) or comparable environment containing parts covered
% under other licensing terms, the licensors of MATPOWER grant
% you additional permission to convey the resulting work.
if nargin < 3
mpc = baseMVA;
baseMVA = mpc.baseMVA;
bus = mpc.bus;
branch = mpc.branch;
end
%% constants
nb = size(bus, 1); %% number of buses
nl = size(branch, 1); %% number of lines
%% define named indices into bus, branch matrices
% bus related indexes
BUS_I = 1;
GS = 5;
BS = 6;
% branch related indexes
F_BUS = 1;
T_BUS = 2;
BR_R = 3;
BR_X = 4;
BR_B = 5;
TAP = 9;
SHIFT = 10;
BR_STATUS = 11;
%% check that bus numbers are equal to indices to bus (one set of bus numbers)
if any(bus(:, BUS_I) ~= (1:nb)')
error('buses must appear in order by bus number')
end
%% for each branch, compute the elements of the branch admittance matrix where
%%
%% | If | | Yff Yft | | Vf |
%% | | = | | * | |
%% | It | | Ytf Ytt | | Vt |
%%
stat = branch(:, BR_STATUS); %% ones at in-service branches
Ys = stat ./ (branch(:, BR_R) + 1j * branch(:, BR_X)); %% series admittance
Bc = stat .* branch(:, BR_B); %% line charging susceptance
tap = ones(nl, 1); %% default tap ratio = 1
i = find(branch(:, TAP)); %% indices of non-zero tap ratios
tap(i) = branch(i, TAP); %% assign non-zero tap ratios
tap = tap .* exp(1j*pi/180 * branch(:, SHIFT)); %% add phase shifters
Ytt = Ys + 1j*Bc/2;
Yff = Ytt ./ (tap .* conj(tap));
Yft = - Ys ./ conj(tap);
Ytf = - Ys ./ tap;
%% compute shunt admittance
%% if Psh is the real power consumed by the shunt at V = 1.0 p.u.
%% and Qsh is the reactive power injected by the shunt at V = 1.0 p.u.
%% then Psh - j Qsh = V * conj(Ysh * V) = conj(Ysh) = Gs - j Bs,
%% i.e. Ysh = Psh + j Qsh, so ...
Ysh = (bus(:, GS) + 1j * bus(:, BS)) / baseMVA; %% vector of shunt admittances
%% build connection matrices
f = branch(:, F_BUS); %% list of "from" buses
t = branch(:, T_BUS); %% list of "to" buses
Cf = sparse(1:nl, f, ones(nl, 1), nl, nb); %% connection matrix for line & from buses
Ct = sparse(1:nl, t, ones(nl, 1), nl, nb); %% connection matrix for line & to buses
%% build Yf and Yt such that Yf * V is the vector of complex branch currents injected
%% at each branch's "from" bus, and Yt is the same for the "to" bus end
i = [1:nl; 1:nl]'; %% double set of row indices
Yf = sparse(i, [f; t], [Yff; Yft], nl, nb);
Yt = sparse(i, [f; t], [Ytf; Ytt], nl, nb);
% Yf = spdiags(Yff, 0, nl, nl) * Cf + spdiags(Yft, 0, nl, nl) * Ct;
% Yt = spdiags(Ytf, 0, nl, nl) * Cf + spdiags(Ytt, 0, nl, nl) * Ct;
%% build Ybus
Ybus = Cf' * Yf + Ct' * Yt + ... %% branch admittances
sparse(1:nb, 1:nb, Ysh, nb, nb); %% shunt admittance