Home > matpower6.0 > makeYbus.m

makeYbus

PURPOSE ^

MAKEYBUS Builds the bus admittance matrix and branch admittance matrices.

SYNOPSIS ^

function [Ybus, Yf, Yt] = makeYbus(baseMVA, bus, branch)

DESCRIPTION ^

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
   (i.e. internal ordering).

   See also MAKEJAC, MAKESBUS, EXT2INT.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [Ybus, Yf, Yt] = makeYbus(baseMVA, bus, branch)
0002 %MAKEYBUS   Builds the bus admittance matrix and branch admittance matrices.
0003 %   [YBUS, YF, YT] = MAKEYBUS(MPC)
0004 %   [YBUS, YF, YT] = MAKEYBUS(BASEMVA, BUS, BRANCH)
0005 %
0006 %   Returns the full bus admittance matrix (i.e. for all buses) and the
0007 %   matrices YF and YT which, when multiplied by a complex voltage vector,
0008 %   yield the vector currents injected into each line from the "from" and
0009 %   "to" buses respectively of each line. Does appropriate conversions to p.u.
0010 %   Inputs can be a MATPOWER case struct or individual BASEMVA, BUS and
0011 %   BRANCH values. Bus numbers must be consecutive beginning at 1
0012 %   (i.e. internal ordering).
0013 %
0014 %   See also MAKEJAC, MAKESBUS, EXT2INT.
0015 
0016 %   MATPOWER
0017 %   Copyright (c) 1996-2016, Power Systems Engineering Research Center (PSERC)
0018 %   by Ray Zimmerman, PSERC Cornell
0019 %
0020 %   This file is part of MATPOWER.
0021 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0022 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0023 
0024 %% extract from MPC if necessary
0025 if nargin < 3
0026     mpc     = baseMVA;
0027     baseMVA = mpc.baseMVA;
0028     bus     = mpc.bus;
0029     branch  = mpc.branch;
0030 end
0031 
0032 %% constants
0033 nb = size(bus, 1);          %% number of buses
0034 nl = size(branch, 1);       %% number of lines
0035 
0036 %% define named indices into bus, branch matrices
0037 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0038     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0039 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0040     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0041     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0042 
0043 %% check that bus numbers are equal to indices to bus (one set of bus numbers)
0044 if any(bus(:, BUS_I) ~= (1:nb)')
0045     error('makeYbus: buses must be numbered consecutively in bus matrix; use ext2int() to convert to internal ordering')
0046 end
0047 
0048 %% for each branch, compute the elements of the branch admittance matrix where
0049 %%
0050 %%      | If |   | Yff  Yft |   | Vf |
0051 %%      |    | = |          | * |    |
0052 %%      | It |   | Ytf  Ytt |   | Vt |
0053 %%
0054 stat = branch(:, BR_STATUS);                    %% ones at in-service branches
0055 Ys = stat ./ (branch(:, BR_R) + 1j * branch(:, BR_X));  %% series admittance
0056 Bc = stat .* branch(:, BR_B);                           %% line charging susceptance
0057 tap = ones(nl, 1);                              %% default tap ratio = 1
0058 i = find(branch(:, TAP));                       %% indices of non-zero tap ratios
0059 tap(i) = branch(i, TAP);                        %% assign non-zero tap ratios
0060 tap = tap .* exp(1j*pi/180 * branch(:, SHIFT)); %% add phase shifters
0061 Ytt = Ys + 1j*Bc/2;
0062 Yff = Ytt ./ (tap .* conj(tap));
0063 Yft = - Ys ./ conj(tap);
0064 Ytf = - Ys ./ tap;
0065 
0066 %% compute shunt admittance
0067 %% if Psh is the real power consumed by the shunt at V = 1.0 p.u.
0068 %% and Qsh is the reactive power injected by the shunt at V = 1.0 p.u.
0069 %% then Psh - j Qsh = V * conj(Ysh * V) = conj(Ysh) = Gs - j Bs,
0070 %% i.e. Ysh = Psh + j Qsh, so ...
0071 Ysh = (bus(:, GS) + 1j * bus(:, BS)) / baseMVA; %% vector of shunt admittances
0072 
0073 %% build connection matrices
0074 f = branch(:, F_BUS);                           %% list of "from" buses
0075 t = branch(:, T_BUS);                           %% list of "to" buses
0076 Cf = sparse(1:nl, f, ones(nl, 1), nl, nb);      %% connection matrix for line & from buses
0077 Ct = sparse(1:nl, t, ones(nl, 1), nl, nb);      %% connection matrix for line & to buses
0078 
0079 %% build Yf and Yt such that Yf * V is the vector of complex branch currents injected
0080 %% at each branch's "from" bus, and Yt is the same for the "to" bus end
0081 i = [1:nl; 1:nl]';                              %% double set of row indices
0082 Yf = sparse(i, [f; t], [Yff; Yft], nl, nb);
0083 Yt = sparse(i, [f; t], [Ytf; Ytt], nl, nb);
0084 % Yf = spdiags(Yff, 0, nl, nl) * Cf + spdiags(Yft, 0, nl, nl) * Ct;
0085 % Yt = spdiags(Ytf, 0, nl, nl) * Cf + spdiags(Ytt, 0, nl, nl) * Ct;
0086 
0087 %% build Ybus
0088 Ybus = Cf' * Yf + Ct' * Yt + ...                %% branch admittances
0089         sparse(1:nb, 1:nb, Ysh, nb, nb);        %% shunt admittance

Generated on Fri 16-Dec-2016 12:45:37 by m2html © 2005