Home > matpower5.0 > makeBdc.m

makeBdc

PURPOSE ^

MAKEBDC Builds the B matrices and phase shift injections for DC power flow.

SYNOPSIS ^

function [Bbus, Bf, Pbusinj, Pfinj] = makeBdc(baseMVA, bus, branch)

DESCRIPTION ^

MAKEBDC   Builds the B matrices and phase shift injections for DC power flow.
   [BBUS, BF, PBUSINJ, PFINJ] = MAKEBDC(BASEMVA, BUS, BRANCH) returns the
   B matrices and phase shift injection vectors needed for a DC power flow.
   The bus real power injections are related to bus voltage angles by
       P = BBUS * Va + PBUSINJ
   The real power flows at the from end the lines are related to the bus
   voltage angles by
       Pf = BF * Va + PFINJ
   Does appropriate conversions to p.u.

   Example:
       [Bbus, Bf, Pbusinj, Pfinj] = makeBdc(baseMVA, bus, branch);

   See also DCPF.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [Bbus, Bf, Pbusinj, Pfinj] = makeBdc(baseMVA, bus, branch)
0002 %MAKEBDC   Builds the B matrices and phase shift injections for DC power flow.
0003 %   [BBUS, BF, PBUSINJ, PFINJ] = MAKEBDC(BASEMVA, BUS, BRANCH) returns the
0004 %   B matrices and phase shift injection vectors needed for a DC power flow.
0005 %   The bus real power injections are related to bus voltage angles by
0006 %       P = BBUS * Va + PBUSINJ
0007 %   The real power flows at the from end the lines are related to the bus
0008 %   voltage angles by
0009 %       Pf = BF * Va + PFINJ
0010 %   Does appropriate conversions to p.u.
0011 %
0012 %   Example:
0013 %       [Bbus, Bf, Pbusinj, Pfinj] = makeBdc(baseMVA, bus, branch);
0014 %
0015 %   See also DCPF.
0016 
0017 %   MATPOWER
0018 %   $Id: makeBdc.m 1635 2010-04-26 19:45:26Z ray $
0019 %   by Carlos E. Murillo-Sanchez, PSERC Cornell & Universidad Autonoma de Manizales
0020 %   and Ray Zimmerman, PSERC Cornell
0021 %   Copyright (c) 1996-2010 by Power System Engineering Research Center (PSERC)
0022 %
0023 %   This file is part of MATPOWER.
0024 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0025 %
0026 %   MATPOWER is free software: you can redistribute it and/or modify
0027 %   it under the terms of the GNU General Public License as published
0028 %   by the Free Software Foundation, either version 3 of the License,
0029 %   or (at your option) any later version.
0030 %
0031 %   MATPOWER is distributed in the hope that it will be useful,
0032 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0033 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0034 %   GNU General Public License for more details.
0035 %
0036 %   You should have received a copy of the GNU General Public License
0037 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0038 %
0039 %   Additional permission under GNU GPL version 3 section 7
0040 %
0041 %   If you modify MATPOWER, or any covered work, to interface with
0042 %   other modules (such as MATLAB code and MEX-files) available in a
0043 %   MATLAB(R) or comparable environment containing parts covered
0044 %   under other licensing terms, the licensors of MATPOWER grant
0045 %   you additional permission to convey the resulting work.
0046 
0047 %% constants
0048 nb = size(bus, 1);          %% number of buses
0049 nl = size(branch, 1);       %% number of lines
0050 
0051 %% define named indices into bus, branch matrices
0052 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0053     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0054 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0055     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0056     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0057 
0058 %% check that bus numbers are equal to indices to bus (one set of bus numbers)
0059 if any(bus(:, BUS_I) ~= (1:nb)')
0060     error('makeBdc: buses must be numbered consecutively in bus matrix')
0061 end
0062 
0063 %% for each branch, compute the elements of the branch B matrix and the phase
0064 %% shift "quiescent" injections, where
0065 %%
0066 %%      | Pf |   | Bff  Bft |   | Vaf |   | Pfinj |
0067 %%      |    | = |          | * |     | + |       |
0068 %%      | Pt |   | Btf  Btt |   | Vat |   | Ptinj |
0069 %%
0070 stat = branch(:, BR_STATUS);                    %% ones at in-service branches
0071 b = stat ./ branch(:, BR_X);                    %% series susceptance
0072 tap = ones(nl, 1);                              %% default tap ratio = 1
0073 i = find(branch(:, TAP));                       %% indices of non-zero tap ratios
0074 tap(i) = branch(i, TAP);                        %% assign non-zero tap ratios
0075 b = b ./ tap;
0076 
0077 %% build connection matrix Cft = Cf - Ct for line and from - to buses
0078 f = branch(:, F_BUS);                           %% list of "from" buses
0079 t = branch(:, T_BUS);                           %% list of "to" buses
0080 i = [(1:nl)'; (1:nl)'];                         %% double set of row indices
0081 Cft = sparse(i, [f;t], [ones(nl, 1); -ones(nl, 1)], nl, nb);    %% connection matrix
0082 
0083 %% build Bf such that Bf * Va is the vector of real branch powers injected
0084 %% at each branch's "from" bus
0085 Bf = sparse(i, [f; t], [b; -b]);    % = spdiags(b, 0, nl, nl) * Cft;
0086 
0087 %% build Bbus
0088 Bbus = Cft' * Bf;
0089 
0090 %% build phase shift injection vectors
0091 Pfinj = b .* (-branch(:, SHIFT) * pi/180);      %% injected at the from bus ...
0092     % Ptinj = -Pfinj;                           %% ... and extracted at the to bus
0093 Pbusinj = Cft' * Pfinj;                         %% Pbusinj = Cf * Pfinj + Ct * Ptinj;

Generated on Mon 26-Jan-2015 15:21:31 by m2html © 2005