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);
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-2017, Power Systems Engineering Research Center (PSERC) 0056 % by Ray Zimmerman, PSERC Cornell 0057 % 0058 % This file is part of MATPOWER. 0059 % Covered by the 3-clause BSD License (see LICENSE file for details). 0060 % See https://matpower.org for more info. 0061 0062 %% default arguments 0063 if isstruct(baseMVA) 0064 mpc = baseMVA; 0065 [baseMVA, bus, branch] = deal(mpc.baseMVA, mpc.bus, mpc.branch); 0066 end 0067 0068 %% define named indices into bus, gen, branch matrices 0069 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ... 0070 VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus; 0071 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ... 0072 TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ... 0073 ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch; 0074 0075 %% create map of external bus numbers to bus indices 0076 i2e = bus(:, BUS_I); 0077 e2i = sparse(max(i2e), 1); 0078 e2i(i2e) = (1:size(bus, 1))'; 0079 out = find(branch(:, BR_STATUS) == 0); %% out-of-service branches 0080 0081 %% sizes of things 0082 nb = size(bus, 1); %% number of buses 0083 nl = size(branch, 1); %% number of branches 0084 0085 %% construct complex bus voltage vector 0086 V = bus(:, VM) .* exp(1j * pi/180 * bus(:, VA)); 0087 0088 %% parameters 0089 Cf = sparse(1:nl, e2i(branch(:, F_BUS)), branch(:, BR_STATUS), nl, nb); 0090 Ct = sparse(1:nl, e2i(branch(:, T_BUS)), branch(:, BR_STATUS), nl, nb); 0091 tap = ones(nl, 1); %% default tap ratio = 1 for lines 0092 xfmr = find(branch(:, TAP)); %% indices of transformers 0093 tap(xfmr) = branch(xfmr, TAP); %% include transformer tap ratios 0094 tap = tap .* exp(1j*pi/180 * branch(:, SHIFT)); %% add phase shifters 0095 A = spdiags(1 ./ tap, 0, nl, nl) * Cf - Ct; 0096 Ysc = 1 ./ (branch(:, BR_R) - 1j * branch(:, BR_X)); 0097 Vdrop = A * V; %% vector of voltage drop across series impedance element 0098 loss = baseMVA * Ysc .* Vdrop .* conj(Vdrop); 0099 % loss = baseMVA * abs(V(e2i(branch(:, F_BUS))) ./ tap - V(e2i(branch(:, T_BUS)))) .^ 2 ./ ... 0100 % (branch(:, BR_R) - 1j * branch(:, BR_X)); 0101 % loss(out) = 0; 0102 0103 if nargout > 1 0104 Vf = Cf * V; 0105 Vt = Ct * V; 0106 fchg = real(baseMVA / 2 * branch(:, BR_B) .* Vf .* conj(Vf) ./ (tap .* conj(tap))); 0107 tchg = real(baseMVA / 2 * branch(:, BR_B) .* Vt .* conj(Vt)); 0108 % fchg = abs(V(e2i(branch(:, F_BUS))) ./ tap) .^ 2 .* branch(:, BR_B) * baseMVA / 2; 0109 % tchg = abs(V(e2i(branch(:, T_BUS))) ) .^ 2 .* branch(:, BR_B) * baseMVA / 2; 0110 fchg(out) = 0; 0111 tchg(out) = 0; 0112 0113 if nargout == 2 0114 fchg = fchg + tchg; 0115 end 0116 end 0117 0118 if nargout > 3 0119 B = spdiags(A * V, 0, nl, nl) * conj(A) * spdiags(conj(V), 0, nb, nb); 0120 dYsc = spdiags(Ysc, 0, nl, nl); 0121 dloss_dV = struct(... 0122 'a', -1j * baseMVA * dYsc * (B - conj(B)), ... 0123 'm', baseMVA * dYsc * (B + conj(B)) * spdiags(1 ./ abs(V), 0, nb, nb) ... 0124 ); 0125 if nargout > 4 0126 Bc = spdiags(branch(:, BR_B), 0, nl, nl); 0127 tt = spdiags(1 ./ (tap .* conj(tap)), 0, nl, nl); 0128 dchg_dVm = struct(... 0129 'f', baseMVA * Bc * tt * spdiags(Cf * bus(:, VM), 0, nl, nl) * Cf, ... 0130 't', baseMVA * Bc * spdiags(Ct * bus(:, VM), 0, nl, nl) * Ct ... 0131 ); 0132 end 0133 end