Home > matpower7.0 > lib > pfsoln.m

pfsoln

PURPOSE ^

PFSOLN Updates bus, gen, branch data structures to match power flow soln.

SYNOPSIS ^

function [bus, gen, branch] = pfsoln(baseMVA, bus0, gen0, branch0, Ybus, Yf, Yt, V, ref, pv, pq, mpopt)

DESCRIPTION ^

PFSOLN  Updates bus, gen, branch data structures to match power flow soln.
   [BUS, GEN, BRANCH] = PFSOLN(BASEMVA, BUS0, GEN0, BRANCH0, ...
                                   YBUS, YF, YT, V, REF, PV, PQ, MPOPT)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [bus, gen, branch] = pfsoln(baseMVA, bus0, gen0, branch0, Ybus, Yf, Yt, V, ref, pv, pq, mpopt)
0002 %PFSOLN  Updates bus, gen, branch data structures to match power flow soln.
0003 %   [BUS, GEN, BRANCH] = PFSOLN(BASEMVA, BUS0, GEN0, BRANCH0, ...
0004 %                                   YBUS, YF, YT, V, REF, PV, PQ, MPOPT)
0005 
0006 %   MATPOWER
0007 %   Copyright (c) 1996-2016, Power Systems Engineering Research Center (PSERC)
0008 %   by Ray Zimmerman, PSERC Cornell
0009 %
0010 %   This file is part of MATPOWER.
0011 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0012 %   See https://matpower.org for more info.
0013 
0014 %% define named indices into bus, gen, branch matrices
0015 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0016     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0017 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0018     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0019     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0020 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0021     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0022     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0023 
0024 %% default options
0025 if nargin < 12
0026     mpopt = mpoption();
0027 end
0028 
0029 %% initialize return values
0030 bus     = bus0;
0031 gen     = gen0;
0032 branch  = branch0;
0033 
0034 %%----- update bus voltages -----
0035 bus(:, VM) = abs(V);
0036 bus(:, VA) = angle(V) * 180 / pi;
0037 
0038 %%----- update Qg for gens at PV/slack buses and Pg for slack bus(es) -----
0039 %% generator info
0040 on = find(gen(:, GEN_STATUS) > 0 & ...  %% which generators are on?
0041         bus(gen(:, GEN_BUS), BUS_TYPE) ~= PQ);  %% ... and not at PQ buses
0042 off = find(gen(:, GEN_STATUS) <= 0);    %% which generators are off?
0043 gbus = gen(on, GEN_BUS);                %% what buses are they at?
0044 
0045 %% compute total injected bus powers
0046 Sbus = V(gbus) .* conj(Ybus(gbus, :) * V);
0047 
0048 %% update Qg for generators at PV/slack buses
0049 gen(off, QG) = zeros(length(off), 1);   %% zero out off-line Qg
0050 %% don't touch the ones at PQ buses
0051 [Pd_gbus, Qd_gbus] = total_load(bus(gbus, :), [], 'bus', [], mpopt);
0052 gen(on, QG) = imag(Sbus) * baseMVA + Qd_gbus;   %% inj Q + local Qd
0053 %% ... at this point any buses with more than one generator will have
0054 %% the total Q dispatch for the bus assigned to each generator. This
0055 %% must be split between them. We do it first equally, then in proportion
0056 %% to the reactive range of the generator.
0057 
0058 if length(on) > 1
0059     %% build connection matrix, element i, j is 1 if gen on(i) at bus j is ON
0060     nb = size(bus, 1);
0061     ngon = size(on, 1);
0062     Cg = sparse((1:ngon)', gbus, ones(ngon, 1), ngon, nb);
0063 
0064     %% divide Qg by number of generators at the bus to distribute equally
0065     ngg = Cg * sum(Cg)';    %% ngon x 1, number of gens at this gen's bus
0066     gen(on, QG) = gen(on, QG) ./ ngg;
0067 
0068     %% set finite proxy M for infinite limits (for ~ proportional splitting)
0069     %% equal to sum over all gens at bus of abs(Qg) plus any finite Q limits
0070     Qmin = gen(on, QMIN);
0071     Qmax = gen(on, QMAX);
0072     M = abs(gen(on, QG));
0073     M(~isinf(Qmax)) = M(~isinf(Qmax)) + abs(Qmax(~isinf(Qmax)));
0074     M(~isinf(Qmin)) = M(~isinf(Qmin)) + abs(Qmin(~isinf(Qmin)));
0075     M = Cg * Cg' * M;   %% each gen gets sum over all gens at same bus
0076     %% replace +/- Inf limits with proxy +/- M
0077     Qmin(Qmin ==  Inf) =  M(Qmin ==  Inf);
0078     Qmin(Qmin == -Inf) = -M(Qmin == -Inf);
0079     Qmax(Qmax ==  Inf) =  M(Qmax ==  Inf);
0080     Qmax(Qmax == -Inf) = -M(Qmax == -Inf);
0081 
0082     %% divide proportionally
0083     Cmin = sparse((1:ngon)', gbus, Qmin, ngon, nb);
0084     Cmax = sparse((1:ngon)', gbus, Qmax, ngon, nb);
0085     Qg_tot = Cg' * gen(on, QG);     %% nb x 1 vector of total Qg at each bus
0086     Qg_min = sum(Cmin)';            %% nb x 1 vector of min total Qg at each bus
0087     Qg_max = sum(Cmax)';            %% nb x 1 vector of max total Qg at each bus
0088     gen(on, QG) = Qmin + ...
0089         (Cg * ((Qg_tot - Qg_min)./(Qg_max - Qg_min + eps))) .* ...
0090             (Qmax - Qmin);          %%                ^ avoid div by 0
0091 
0092     %% fix gens at buses with Qg range = 0 (use equal violation for all)
0093     ig = find(abs(Cg * (Qg_min - Qg_max)) < 10*eps);  %% gens at buses with Qg range = 0
0094     if ~isempty(ig)
0095         ib = find(sum(Cg(ig,:), 1)');   %% buses with Qg range = 0
0096         %% total mismatch @ bus div by number of gens
0097         mis = sparse(ib, 1, (Qg_tot(ib) - Qg_min(ib)) ./ sum(Cg(:, ib)', 2), nb, 1);
0098         gen(on(ig), QG) = Qmin(ig) + Cg(ig, :) * mis;
0099     end
0100 end                                             %% (terms are mult by 0 anyway)
0101 
0102 %% update Pg for slack gen(s)
0103 for k = 1:length(ref)
0104     refgen = find(gbus == ref(k));              %% which is(are) the reference gen(s)?
0105     Pd_refk = total_load(bus(ref(k), :), [], 'bus', [], mpopt);
0106     gen(on(refgen(1)), PG) = real(Sbus(refgen(1))) * baseMVA + Pd_refk; %% inj P + local Pd
0107     if length(refgen) > 1       %% more than one generator at this ref bus
0108         %% subtract off what is generated by other gens at this bus
0109         gen(on(refgen(1)), PG) = gen(on(refgen(1)), PG) ...
0110                                 - sum(gen(on(refgen(2:length(refgen))), PG));
0111     end
0112 end
0113 
0114 %%----- update/compute branch power flows -----
0115 out = find(branch(:, BR_STATUS) == 0);      %% out-of-service branches
0116 br = find(branch(:, BR_STATUS));            %% in-service branches
0117 Sf = V(branch(br, F_BUS)) .* conj(Yf(br, :) * V) * baseMVA; %% complex power at "from" bus
0118 St = V(branch(br, T_BUS)) .* conj(Yt(br, :) * V) * baseMVA; %% complex power injected at "to" bus
0119 branch(br, [PF, QF, PT, QT]) = [real(Sf) imag(Sf) real(St) imag(St)];
0120 branch(out, [PF, QF, PT, QT]) = zeros(length(out), 4);

Generated on Mon 24-Jun-2019 15:58:45 by m2html © 2005