Home > matpower5.1 > get_losses.m

get_losses

PURPOSE ^

GET_LOSSES Returns series losses (and reactive injections) per branch.

SYNOPSIS ^

function [loss, fchg, tchg, dloss_dV, dchg_dVm] = get_losses(baseMVA, bus, branch)

DESCRIPTION ^

GET_LOSSES   Returns series losses (and reactive injections) per branch.

   LOSS = GET_LOSSES(RESULTS)
   LOSS = GET_LOSSES(BASEMVA, BUS, BRANCH)

   [LOSS, CHG] = GET_LOSSES(RESULTS)
   [LOSS, FCHG, TCHG] = GET_LOSSES(RESULTS)
   [LOSS, FCHG, TCHG, DLOSS_DV] = GET_LOSSES(RESULTS)
   [LOSS, FCHG, TCHG, DLOSS_DV, DCHG_DVM] = GET_LOSSES(RESULTS)

   Computes branch series losses, and optionally reactive injections from
   line charging, as functions of bus voltages and branch parameters, using the
   following formulae:

       loss = abs( Vf / tau - Vt ) ^ 2 / (Rs - j Xs)
       fchg = abs( Vf / tau ) ^ 2 * Bc / 2
       tchg = abs( Vt ) ^ 2 * Bc / 2

   Optionally, computes the partial derivatives of the line losses with
   respect to voltage angles and magnitudes.

   Input:
       RESULTS - a MATPOWER case struct with bus voltages corresponding to
                 a valid power flow solution.
                 (Can optionally be specified as individual fields BASEMVA,
                  BUS, and BRANCH.)

   Output(s):
       LOSS - complex NL x 1 vector of losses (in MW), where NL is the number
              of branches in the system, representing only the losses in the
              series impedance element of the PI model for each branch.
       CHG -  NL x 1 vector of total reactive injection for each line
              (in MVAr), representing the line charging injections of both
              of the shunt elements of PI model for each branch.
       FCHG - Same as CHG, but for the element at the "from" end of the
              branch only.
       TCHG - Same as CHG, but for the element at the "to" end of the branch.
       DLOSS_DV - Struct with partial derivatives of LOSS with respect to bus
              voltages, with fields:
           .a  - Partial with respect to bus voltage angles.
           .m  - Partial with respect to bus voltage magnitudes.
       DCHG_DVM - Struct with partial derivatives of FCHG and TCHG with
              respect to bus voltage magnitudes, with fields:
           .f  - Partial of FCHG with respect to bus voltage magnitudes.
           .t  - Partial of TCHG with respect to bus voltage magnitudes.

   Example:
       results = runpf(mycase);
       total_system_real_losses = sum(real(get_losses(results)));

       [loss, fchg, tchg, dloss_dV] = get_losses(results);

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [loss, fchg, tchg, dloss_dV, dchg_dVm] = get_losses(baseMVA, bus, branch)
0002 %GET_LOSSES   Returns series losses (and reactive injections) per branch.
0003 %
0004 %   LOSS = GET_LOSSES(RESULTS)
0005 %   LOSS = GET_LOSSES(BASEMVA, BUS, BRANCH)
0006 %
0007 %   [LOSS, CHG] = GET_LOSSES(RESULTS)
0008 %   [LOSS, FCHG, TCHG] = GET_LOSSES(RESULTS)
0009 %   [LOSS, FCHG, TCHG, DLOSS_DV] = GET_LOSSES(RESULTS)
0010 %   [LOSS, FCHG, TCHG, DLOSS_DV, DCHG_DVM] = GET_LOSSES(RESULTS)
0011 %
0012 %   Computes branch series losses, and optionally reactive injections from
0013 %   line charging, as functions of bus voltages and branch parameters, using the
0014 %   following formulae:
0015 %
0016 %       loss = abs( Vf / tau - Vt ) ^ 2 / (Rs - j Xs)
0017 %       fchg = abs( Vf / tau ) ^ 2 * Bc / 2
0018 %       tchg = abs( Vt ) ^ 2 * Bc / 2
0019 %
0020 %   Optionally, computes the partial derivatives of the line losses with
0021 %   respect to voltage angles and magnitudes.
0022 %
0023 %   Input:
0024 %       RESULTS - a MATPOWER case struct with bus voltages corresponding to
0025 %                 a valid power flow solution.
0026 %                 (Can optionally be specified as individual fields BASEMVA,
0027 %                  BUS, and BRANCH.)
0028 %
0029 %   Output(s):
0030 %       LOSS - complex NL x 1 vector of losses (in MW), where NL is the number
0031 %              of branches in the system, representing only the losses in the
0032 %              series impedance element of the PI model for each branch.
0033 %       CHG -  NL x 1 vector of total reactive injection for each line
0034 %              (in MVAr), representing the line charging injections of both
0035 %              of the shunt elements of PI model for each branch.
0036 %       FCHG - Same as CHG, but for the element at the "from" end of the
0037 %              branch only.
0038 %       TCHG - Same as CHG, but for the element at the "to" end of the branch.
0039 %       DLOSS_DV - Struct with partial derivatives of LOSS with respect to bus
0040 %              voltages, with fields:
0041 %           .a  - Partial with respect to bus voltage angles.
0042 %           .m  - Partial with respect to bus voltage magnitudes.
0043 %       DCHG_DVM - Struct with partial derivatives of FCHG and TCHG with
0044 %              respect to bus voltage magnitudes, with fields:
0045 %           .f  - Partial of FCHG with respect to bus voltage magnitudes.
0046 %           .t  - Partial of TCHG with respect to bus voltage magnitudes.
0047 %
0048 %   Example:
0049 %       results = runpf(mycase);
0050 %       total_system_real_losses = sum(real(get_losses(results)));
0051 %
0052 %       [loss, fchg, tchg, dloss_dV] = get_losses(results);
0053 
0054 %   MATPOWER
0055 %   Copyright (c) 1996-2015 by Power System Engineering Research Center (PSERC)
0056 %   by Ray Zimmerman, PSERC Cornell
0057 %
0058 %   $Id: get_losses.m 2644 2015-03-11 19:34:22Z ray $
0059 %
0060 %   This file is part of MATPOWER.
0061 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0062 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0063 
0064 %% default arguments
0065 if isstruct(baseMVA)
0066     mpc = baseMVA;
0067     [baseMVA, bus, branch] = deal(mpc.baseMVA, mpc.bus, mpc.branch);
0068 end
0069 
0070 %% define named indices into bus, gen, branch matrices
0071 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0072     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0073 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0074     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0075     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0076 
0077 %% create map of external bus numbers to bus indices
0078 i2e = bus(:, BUS_I);
0079 e2i = sparse(max(i2e), 1);
0080 e2i(i2e) = (1:size(bus, 1))';
0081 out = find(branch(:, BR_STATUS) == 0);          %% out-of-service branches
0082 
0083 %% sizes of things
0084 nb = size(bus, 1);      %% number of buses
0085 nl = size(branch, 1);   %% number of branches
0086 
0087 %% construct complex bus voltage vector
0088 V = bus(:, VM) .* exp(sqrt(-1) * pi/180 * bus(:, VA));
0089 
0090 %% parameters
0091 Cf = sparse(1:nl, e2i(branch(:, F_BUS)), branch(:, BR_STATUS), nl, nb);
0092 Ct = sparse(1:nl, e2i(branch(:, T_BUS)), branch(:, BR_STATUS), nl, nb);
0093 tap = ones(nl, 1);                              %% default tap ratio = 1 for lines
0094 xfmr = find(branch(:, TAP));                    %% indices of transformers
0095 tap(xfmr) = branch(xfmr, TAP);                  %% include transformer tap ratios
0096 tap = tap .* exp(1j*pi/180 * branch(:, SHIFT)); %% add phase shifters
0097 A = spdiags(1 ./ tap, 0, nl, nl) * Cf - Ct;
0098 Ysc = 1 ./ (branch(:, BR_R) - 1j * branch(:, BR_X));
0099 Vdrop = A * V;      %% vector of voltage drop across series impedance element
0100 loss = baseMVA * Ysc .* Vdrop .* conj(Vdrop);
0101 % loss = baseMVA * abs(V(e2i(branch(:, F_BUS))) ./ tap - V(e2i(branch(:, T_BUS)))) .^ 2 ./ ...
0102 %             (branch(:, BR_R) - 1j * branch(:, BR_X));
0103 % loss(out) = 0;
0104 
0105 if nargout > 1
0106     Vf = Cf * V;
0107     Vt = Ct * V;
0108     fchg = real(baseMVA / 2 * branch(:, BR_B) .* Vf .* conj(Vf) ./ (tap .* conj(tap)));
0109     tchg = real(baseMVA / 2 * branch(:, BR_B) .* Vt .* conj(Vt));
0110 %     fchg = abs(V(e2i(branch(:, F_BUS))) ./ tap) .^ 2 .* branch(:, BR_B) * baseMVA / 2;
0111 %     tchg = abs(V(e2i(branch(:, T_BUS)))       ) .^ 2 .* branch(:, BR_B) * baseMVA / 2;
0112     fchg(out) = 0;
0113     tchg(out) = 0;
0114 
0115     if nargout == 2
0116         fchg = fchg + tchg;
0117     end
0118 end
0119 
0120 if nargout > 3
0121     B = spdiags(A * V, 0, nl, nl) * conj(A) * spdiags(conj(V), 0, nb, nb);
0122     dYsc = spdiags(Ysc, 0, nl, nl);
0123     dloss_dV = struct(...
0124         'a', -1j * baseMVA * dYsc * (B - conj(B)), ...
0125         'm',       baseMVA * dYsc * (B + conj(B)) * spdiags(1 ./ abs(V), 0, nb, nb) ...
0126     );
0127     if nargout > 4
0128         Bc = spdiags(branch(:, BR_B), 0, nl, nl);
0129         tt = spdiags(1 ./ (tap .* conj(tap)), 0, nl, nl);
0130         dchg_dVm = struct(...
0131             'f', baseMVA * Bc * tt * spdiags(Cf * bus(:, VM), 0, nb, nb) * Cf, ...
0132             't', baseMVA * Bc      * spdiags(Ct * bus(:, VM), 0, nb, nb) * Ct ...
0133         );
0134     end
0135 end

Generated on Fri 20-Mar-2015 18:23:34 by m2html © 2005