Home > matpower5.0 > 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 %   $Id: get_losses.m 2473 2014-12-16 21:32:31Z ray $
0056 %   by Ray Zimmerman, PSERC Cornell
0057 %   Copyright (c) 1996-2014 by Power System Engineering Research Center (PSERC)
0058 %
0059 %   This file is part of MATPOWER.
0060 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0061 %
0062 %   MATPOWER is free software: you can redistribute it and/or modify
0063 %   it under the terms of the GNU General Public License as published
0064 %   by the Free Software Foundation, either version 3 of the License,
0065 %   or (at your option) any later version.
0066 %
0067 %   MATPOWER is distributed in the hope that it will be useful,
0068 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0069 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0070 %   GNU General Public License for more details.
0071 %
0072 %   You should have received a copy of the GNU General Public License
0073 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0074 %
0075 %   Additional permission under GNU GPL version 3 section 7
0076 %
0077 %   If you modify MATPOWER, or any covered work, to interface with
0078 %   other modules (such as MATLAB code and MEX-files) available in a
0079 %   MATLAB(R) or comparable environment containing parts covered
0080 %   under other licensing terms, the licensors of MATPOWER grant
0081 %   you additional permission to convey the resulting work.
0082 
0083 %% default arguments
0084 if isstruct(baseMVA)
0085     mpc = baseMVA;
0086     [baseMVA, bus, branch] = deal(mpc.baseMVA, mpc.bus, mpc.branch);
0087 end
0088 
0089 %% define named indices into bus, gen, branch matrices
0090 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0091     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0092 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0093     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0094     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0095 
0096 %% create map of external bus numbers to bus indices
0097 i2e = bus(:, BUS_I);
0098 e2i = sparse(max(i2e), 1);
0099 e2i(i2e) = (1:size(bus, 1))';
0100 out = find(branch(:, BR_STATUS) == 0);          %% out-of-service branches
0101 
0102 %% sizes of things
0103 nb = size(bus, 1);      %% number of buses
0104 nl = size(branch, 1);   %% number of branches
0105 
0106 %% construct complex bus voltage vector
0107 V = bus(:, VM) .* exp(sqrt(-1) * pi/180 * bus(:, VA));
0108 
0109 %% parameters
0110 Cf = sparse(1:nl, e2i(branch(:, F_BUS)), branch(:, BR_STATUS), nl, nb);
0111 Ct = sparse(1:nl, e2i(branch(:, T_BUS)), branch(:, BR_STATUS), nl, nb);
0112 tap = ones(nl, 1);                              %% default tap ratio = 1 for lines
0113 xfmr = find(branch(:, TAP));                    %% indices of transformers
0114 tap(xfmr) = branch(xfmr, TAP);                  %% include transformer tap ratios
0115 tap = tap .* exp(1j*pi/180 * branch(:, SHIFT)); %% add phase shifters
0116 A = spdiags(1 ./ tap, 0, nl, nl) * Cf - Ct;
0117 Ysc = 1 ./ (branch(:, BR_R) - 1j * branch(:, BR_X));
0118 Vdrop = A * V;      %% vector of voltage drop across series impedance element
0119 loss = baseMVA * Ysc .* Vdrop .* conj(Vdrop);
0120 % loss = baseMVA * abs(V(e2i(branch(:, F_BUS))) ./ tap - V(e2i(branch(:, T_BUS)))) .^ 2 ./ ...
0121 %             (branch(:, BR_R) - 1j * branch(:, BR_X));
0122 % loss(out) = 0;
0123 
0124 if nargout > 1
0125     Vf = Cf * V;
0126     Vt = Ct * V;
0127     fchg = real(baseMVA / 2 * branch(:, BR_B) .* Vf .* conj(Vf) ./ (tap .* conj(tap)));
0128     tchg = real(baseMVA / 2 * branch(:, BR_B) .* Vt .* conj(Vt));
0129 %     fchg = abs(V(e2i(branch(:, F_BUS))) ./ tap) .^ 2 .* branch(:, BR_B) * baseMVA / 2;
0130 %     tchg = abs(V(e2i(branch(:, T_BUS)))       ) .^ 2 .* branch(:, BR_B) * baseMVA / 2;
0131     fchg(out) = 0;
0132     tchg(out) = 0;
0133 
0134     if nargout == 2
0135         fchg = fchg + tchg;
0136     end
0137 end
0138 
0139 if nargout > 3
0140     B = spdiags(A * V, 0, nl, nl) * conj(A) * spdiags(conj(V), 0, nb, nb);
0141     dYsc = spdiags(Ysc, 0, nl, nl);
0142     dloss_dV = struct(...
0143         'a', -1j * baseMVA * dYsc * (B - conj(B)), ...
0144         'm',       baseMVA * dYsc * (B + conj(B)) * spdiags(1 ./ abs(V), 0, nb, nb) ...
0145     );
0146     if nargout > 4
0147         Bc = spdiags(branch(:, BR_B), 0, nl, nl);
0148         tt = spdiags(1 ./ (tap .* conj(tap)), 0, nl, nl);
0149         dchg_dVm = struct(...
0150             'f', baseMVA * Bc * tt * spdiags(Cf * bus(:, VM), 0, nb, nb) * Cf, ...
0151             't', baseMVA * Bc      * spdiags(Ct * bus(:, VM), 0, nb, nb) * Ct ...
0152         );
0153     end
0154 end

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