Home > matpower7.1 > lib > 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(MPC)
   [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.
   Bus numbers must be consecutive beginning at 1 (i.e. internal ordering).

   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(MPC)
0004 %   [BBUS, BF, PBUSINJ, PFINJ] = MAKEBDC(BASEMVA, BUS, BRANCH)
0005 %
0006 %   Returns the B matrices and phase shift injection vectors needed for
0007 %   a DC power flow. The bus real power injections are related to bus
0008 %   voltage angles by
0009 %       P = BBUS * Va + PBUSINJ
0010 %   The real power flows at the from end the lines are related to the bus
0011 %   voltage angles by
0012 %       Pf = BF * Va + PFINJ
0013 %   Does appropriate conversions to p.u.
0014 %   Bus numbers must be consecutive beginning at 1 (i.e. internal ordering).
0015 %
0016 %   Example:
0017 %       [Bbus, Bf, Pbusinj, Pfinj] = makeBdc(baseMVA, bus, branch);
0018 %
0019 %   See also DCPF.
0020 
0021 %   MATPOWER
0022 %   Copyright (c) 1996-2016, Power Systems Engineering Research Center (PSERC)
0023 %   by Carlos E. Murillo-Sanchez, PSERC Cornell & Universidad Nacional de Colombia
0024 %   and Ray Zimmerman, PSERC Cornell
0025 %
0026 %   This file is part of MATPOWER.
0027 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0028 %   See https://matpower.org for more info.
0029 
0030 %% extract from MPC if necessary
0031 if nargin < 3
0032     mpc     = baseMVA;
0033     baseMVA = mpc.baseMVA;
0034     bus     = mpc.bus;
0035     branch  = mpc.branch;
0036 end
0037 
0038 %% constants
0039 nb = size(bus, 1);          %% number of buses
0040 nl = size(branch, 1);       %% number of lines
0041 
0042 %% define named indices into bus, branch matrices
0043 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0044     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0045 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0046     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0047     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0048 
0049 %% check that bus numbers are equal to indices to bus (one set of bus numbers)
0050 if any(bus(:, BUS_I) ~= (1:nb)')
0051     error('makeBdc: buses must be numbered consecutively in bus matrix; use ext2int() to convert to internal ordering')
0052 end
0053 
0054 %% for each branch, compute the elements of the branch B matrix and the phase
0055 %% shift "quiescent" injections, where
0056 %%
0057 %%      | Pf |   | Bff  Bft |   | Vaf |   | Pfinj |
0058 %%      |    | = |          | * |     | + |       |
0059 %%      | Pt |   | Btf  Btt |   | Vat |   | Ptinj |
0060 %%
0061 stat = branch(:, BR_STATUS);                    %% ones at in-service branches
0062 b = stat ./ branch(:, BR_X);                    %% series susceptance
0063 tap = ones(nl, 1);                              %% default tap ratio = 1
0064 i = find(branch(:, TAP));                       %% indices of non-zero tap ratios
0065 tap(i) = branch(i, TAP);                        %% assign non-zero tap ratios
0066 b = b ./ tap;
0067 
0068 %% build connection matrix Cft = Cf - Ct for line and from - to buses
0069 f = branch(:, F_BUS);                           %% list of "from" buses
0070 t = branch(:, T_BUS);                           %% list of "to" buses
0071 i = [(1:nl)'; (1:nl)'];                         %% double set of row indices
0072 Cft = sparse(i, [f;t], [ones(nl, 1); -ones(nl, 1)], nl, nb);    %% connection matrix
0073 
0074 %% build Bf such that Bf * Va is the vector of real branch powers injected
0075 %% at each branch's "from" bus
0076 Bf = sparse(i, [f; t], [b; -b], nl, nb);    % = spdiags(b, 0, nl, nl) * Cft;
0077 
0078 %% build Bbus
0079 Bbus = Cft' * Bf;
0080 
0081 %% build phase shift injection vectors
0082 Pfinj = b .* (-branch(:, SHIFT) * pi/180);      %% injected at the from bus ...
0083     % Ptinj = -Pfinj;                           %% ... and extracted at the to bus
0084 Pbusinj = Cft' * Pfinj;                         %% Pbusinj = Cf * Pfinj + Ct * Ptinj;

Generated on Fri 09-Oct-2020 11:21:31 by m2html © 2005