LOSS2BUS Accumulates branch real power losses at downstream buses. BUS_LOSS = LOSS2BUS(MPC) Takes a solved AC power flow case as input and returns an NB x 1 vector containing all branch active power losses accumulated to the bus at the downstream end of the branch.
0001 function bus_loss = loss2bus(mpc) 0002 %LOSS2BUS Accumulates branch real power losses at downstream buses. 0003 % 0004 % BUS_LOSS = LOSS2BUS(MPC) 0005 % 0006 % Takes a solved AC power flow case as input and returns an 0007 % NB x 1 vector containing all branch active power losses 0008 % accumulated to the bus at the downstream end of the branch. 0009 0010 % MATPOWER 0011 % Copyright (c) 2014-2015 by Power System Engineering Research Center (PSERC) 0012 % by Ray Zimmerman, PSERC Cornell 0013 % 0014 % $Id: loss2bus.m 2644 2015-03-11 19:34:22Z ray $ 0015 % 0016 % This file is part of MATPOWER. 0017 % Covered by the 3-clause BSD License (see LICENSE file for details). 0018 % See http://www.pserc.cornell.edu/matpower/ for more info. 0019 0020 define_constants; 0021 0022 %% create external to internal bus map 0023 nb = size(mpc.bus, 1); %% number of buses 0024 nl = size(mpc.branch, 1); %% number of branches 0025 mb = max(abs([mpc.bus(:, BUS_I); mpc.gen(:, GEN_BUS); ... 0026 mpc.branch(:, F_BUS); mpc.branch(:, T_BUS)])); 0027 e2i = sparse(mpc.bus(:, BUS_I), ones(nb, 1), 1:nb, mb, 1); 0028 0029 %% assign losses to downstream buses 0030 loss = mpc.branch(:, PF) + mpc.branch(:, PT); 0031 bus_loss = zeros(nb, 1); 0032 for j = 1:nl %% need to use loop to accumulate for multiple lines per bus 0033 if mpc.branch(j, PF) >= mpc.branch(j, PT) 0034 b = T_BUS; 0035 else 0036 b = F_BUS; 0037 end 0038 ib = e2i(mpc.branch(j, b)); 0039 bus_loss(ib) = bus_loss(ib) + loss(j); 0040 end