Home > matpower6.0 > t > t_pf.m

t_pf

PURPOSE ^

T_PF Tests for power flow solvers.

SYNOPSIS ^

function t_pf(quiet)

DESCRIPTION ^

T_PF  Tests for power flow solvers.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function t_pf(quiet)
0002 %T_PF  Tests for power flow solvers.
0003 
0004 %   MATPOWER
0005 %   Copyright (c) 2004-2016, Power Systems Engineering Research Center (PSERC)
0006 %   by Ray Zimmerman, PSERC Cornell
0007 %
0008 %   This file is part of MATPOWER.
0009 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0010 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0011 
0012 if nargin < 1
0013     quiet = 0;
0014 end
0015 
0016 t_begin(53, quiet);
0017 
0018 casefile = 't_case9_pf';
0019 if quiet
0020     verbose = 0;
0021 else
0022     verbose = 1;
0023 end
0024 if have_fcn('octave')
0025     if have_fcn('octave', 'vnum') >= 4
0026         file_in_path_warn_id = 'Octave:data-file-in-path';
0027     else
0028         file_in_path_warn_id = 'Octave:load-file-in-path';
0029     end
0030     s1 = warning('query', file_in_path_warn_id);
0031     warning('off', file_in_path_warn_id);
0032 end
0033 mpopt = mpoption('out.all', 0, 'verbose', verbose);
0034 
0035 %% define named indices into bus, gen, branch matrices
0036 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0037     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0038 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0039     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0040     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0041 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0042     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0043     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0044 
0045 %% get solved AC power flow case from MAT-file
0046 load soln9_pf;      %% defines bus_soln, gen_soln, branch_soln
0047 
0048 %% run Newton PF
0049 t = 'Newton PF : ';
0050 mpopt = mpoption(mpopt, 'pf.alg', 'NR');
0051 [baseMVA, bus, gen, branch, success, et] = runpf(casefile, mpopt);
0052 t_ok(success, [t 'success']);
0053 t_is(bus, bus_soln, 6, [t 'bus']);
0054 t_is(gen, gen_soln, 6, [t 'gen']);
0055 t_is(branch, branch_soln, 6, [t 'branch']);
0056 
0057 %% run fast-decoupled PF (XB version)
0058 t = 'Fast Decoupled (XB) PF : ';
0059 mpopt = mpoption(mpopt, 'pf.alg', 'FDXB');
0060 [baseMVA, bus, gen, branch, success, et] = runpf(casefile, mpopt);
0061 t_ok(success, [t 'success']);
0062 t_is(bus, bus_soln, 6, [t 'bus']);
0063 t_is(gen, gen_soln, 6, [t 'gen']);
0064 t_is(branch, branch_soln, 6, [t 'branch']);
0065 
0066 %% run fast-decoupled PF (BX version)
0067 t = 'Fast Decoupled (BX) PF : ';
0068 mpopt = mpoption(mpopt, 'pf.alg', 'FDBX');
0069 [baseMVA, bus, gen, branch, success, et] = runpf(casefile, mpopt);
0070 t_ok(success, [t 'success']);
0071 t_is(bus, bus_soln, 6, [t 'bus']);
0072 t_is(gen, gen_soln, 6, [t 'gen']);
0073 t_is(branch, branch_soln, 6, [t 'branch']);
0074 
0075 %% run Gauss-Seidel PF
0076 t = 'Gauss-Seidel PF : ';
0077 mpopt = mpoption(mpopt, 'pf.alg', 'GS');
0078 [baseMVA, bus, gen, branch, success, et] = runpf(casefile, mpopt);
0079 t_ok(success, [t 'success']);
0080 t_is(bus, bus_soln, 5, [t 'bus']);
0081 t_is(gen, gen_soln, 5, [t 'gen']);
0082 t_is(branch, branch_soln, 5, [t 'branch']);
0083 
0084 %% get solved AC power flow case from MAT-file
0085 load soln9_dcpf;        %% defines bus_soln, gen_soln, branch_soln
0086 
0087 %% run DC PF
0088 t = 'DC PF : ';
0089 [baseMVA, bus, gen, branch, success, et] = rundcpf(casefile, mpopt);
0090 t_ok(success, [t 'success']);
0091 t_is(bus, bus_soln, 6, [t 'bus']);
0092 t_is(gen, gen_soln, 6, [t 'gen']);
0093 t_is(branch, branch_soln, 6, [t 'branch']);
0094 
0095 %% check Qg distribution, when Qmin = Qmax
0096 t = 'check Qg : ';
0097 mpopt = mpoption(mpopt, 'pf.alg', 'NR', 'verbose', 0);
0098 mpc = loadcase(casefile);
0099 mpc.gen(1, [QMIN QMAX]) = [20 20];
0100 [baseMVA, bus, gen, branch, success, et] = runpf(mpc, mpopt);
0101 t_ok(success, [t 'success']);
0102 t_is(gen(1, QG), 24.07, 2, [t 'single gen, Qmin = Qmax']);
0103 
0104 mpc.gen = [mpc.gen(1, :); mpc.gen];
0105 mpc.gen(1, [QMIN QMAX]) = [10 10];
0106 mpc.gen(2, [QMIN QMAX]) = [0 50];
0107 [baseMVA, bus, gen, branch, success, et] = runpf(mpc, mpopt);
0108 t_ok(success, [t 'success']);
0109 t_is(gen(1:2, QG), [10; 14.07], 2, [t '2 gens, Qmin = Qmax for one']);
0110 
0111 mpc.gen(1, [QMIN QMAX]) = [10 10];
0112 mpc.gen(2, [QMIN QMAX]) = [-50 -50];
0113 [baseMVA, bus, gen, branch, success, et] = runpf(mpc, mpopt);
0114 t_ok(success, [t 'success']);
0115 t_is(gen(1:2, QG), [12.03; 12.03], 2, [t '2 gens, Qmin = Qmax for both']);
0116 
0117 mpc.gen(1, [QMIN QMAX]) = [0 50];
0118 mpc.gen(2, [QMIN QMAX]) = [0 100];
0119 [baseMVA, bus, gen, branch, success, et] = runpf(mpc, mpopt);
0120 t_ok(success, [t 'success']);
0121 t_is(gen(1:2, QG), [8.02; 16.05], 2, [t '2 gens, proportional']);
0122 
0123 mpc.gen(1, [QMIN QMAX]) = [-50 0];
0124 mpc.gen(2, [QMIN QMAX]) = [50 150];
0125 [baseMVA, bus, gen, branch, success, et] = runpf(mpc, mpopt);
0126 t_ok(success, [t 'success']);
0127 t_is(gen(1:2, QG), [-50+8.02; 50+16.05], 2, [t '2 gens, proportional']);
0128 
0129 t = 'reactive generation allocation : ';
0130 mpc = loadcase(casefile);
0131 %% generator data
0132 %    bus    Pg    Qg    Qmax    Qmin    Vg    mBase    status    Pmax    Pmin    Pc1    Pc2    Qc1min    Qc1max    Qc2min    Qc2max    ramp_agc    ramp_10    ramp_30    ramp_q    apf
0133 mpc.gen = [
0134     1    0    0    300    -300    1    100    1    250    10    0    0    0    0    0    0    0    0    0    0    0;
0135     2    54    0    0    -5    1    100    1    300    10    0    0    0    0    0    0    0    0    0    0    0;
0136     2    54    0    5    -5    1    100    1    300    10    0    0    0    0    0    0    0    0    0    0    0;
0137     2    55    0    25     10    1    100    1    300    10    0    0    0    0    0    0    0    0    0    0    0;
0138     30    25    1    300    -300    1    100    1    270    10    0    0    0    0    0    0    0    0    0    0    0;
0139     30    30    2    300    -300    1    100    1    270    10    0    0    0    0    0    0    0    0    0    0    0;
0140     30    30    -3    300    -300    1    100    1    270    10    0    0    0    0    0    0    0    0    0    0    0;
0141 ];
0142 mpc.bus(3, BUS_TYPE) = PQ;
0143 r = runpf(mpc, mpopt);
0144 t_ok(r.success, [t 'success']);
0145 t_is(r.gen(2:4, QG), [-5; -5; 10] + [1; 2; 3]*1.989129794, 8, [t 'PV bus']);
0146 t_is(r.gen(5:7, QG), [1; 2; -3], 8, [t 'PQ bus']);
0147 
0148 %% network with islands
0149 t = 'network w/islands : DC PF : ';
0150 mpc0 = loadcase(casefile);
0151 mpc0.gen(1, PG) = 60;
0152 mpc0.gen(1, [PMIN PMAX QMIN QMAX PG QG]) = mpc0.gen(1, [PMIN PMAX QMIN QMAX PG QG]) / 2;
0153 mpc0.gen = [mpc0.gen(1, :); mpc0.gen];
0154 mpc1 = mpc0;
0155 mpc  = mpc0;
0156 nb = size(mpc.bus, 1);
0157 mpc1.bus(:, BUS_I)      = mpc1.bus(:, BUS_I) + nb;
0158 mpc1.branch(:, F_BUS)   = mpc1.branch(:, F_BUS) + nb;
0159 mpc1.branch(:, T_BUS)   = mpc1.branch(:, T_BUS) + nb;
0160 mpc1.gen(:, GEN_BUS)    = mpc1.gen(:, GEN_BUS) + nb;
0161 mpc.bus         = [mpc.bus; mpc1.bus];
0162 mpc.branch      = [mpc.branch; mpc1.branch];
0163 mpc.gen         = [mpc.gen; mpc1.gen];
0164 %mpopt = mpoption(mpopt, 'out.bus', 1, 'out.gen', 1, 'out.all', -1, 'verbose', 2);
0165 mpopt = mpoption(mpopt, 'verbose', verbose);
0166 r = rundcpf(mpc, mpopt);
0167 t_ok(r.success, [t 'success']);
0168 t_is(r.bus( 1:9,  VA), bus_soln(:, VA), 8, [t 'voltage angles 1']);
0169 t_is(r.bus(10:18, VA), bus_soln(:, VA), 8, [t 'voltage angles 2']);
0170 Pg = [gen_soln(1, PG)-30; 30; gen_soln(2:3, PG)];
0171 t_is(r.gen(1:4, PG), Pg, 8, [t 'active power generation 1']);
0172 t_is(r.gen(5:8, PG), Pg, 8, [t 'active power generation 1']);
0173 
0174 t = 'network w/islands : AC PF : ';
0175 %% get solved AC power flow case from MAT-file
0176 load soln9_pf;      %% defines bus_soln, gen_soln, branch_soln
0177 r = runpf(mpc, mpopt);
0178 t_ok(r.success, [t 'success']);
0179 t_is(r.bus( 1:9,  VA), bus_soln(:, VA), 8, [t 'voltage angles 1']);
0180 t_is(r.bus(10:18, VA), bus_soln(:, VA), 8, [t 'voltage angles 2']);
0181 Pg = [gen_soln(1, PG)-30; 30; gen_soln(2:3, PG)];
0182 t_is(r.gen(1:4, PG), Pg, 8, [t 'active power generation 1']);
0183 t_is(r.gen(5:8, PG), Pg, 8, [t 'active power generation 1']);
0184 
0185 %% island without slack bus (catch singluar matrix?)
0186 t = 'network w/islands w/o slack : DC PF : ';
0187 k = find(mpc.bus(:, BUS_TYPE) == REF);
0188 mpc.bus(k(2), BUS_TYPE) = PV;
0189 warn_state = warning;
0190 warning('off', 'all');  %% turn of (near-)singular matrix warnings
0191 r = rundcpf(mpc, mpopt);
0192 warning(warn_state);
0193 t_ok(~r.success, [t 'success']);
0194 
0195 %% case 14 with Q limits
0196 t = 'pf.enforce_q_lims == 0 : ';
0197 mpc = loadcase('case14');
0198 mpc.gen(1, QMIN) = -10;
0199 mpc.gen(:, QMAX) = [10; 30; 29; 15; 15];
0200 bt0 = mpc.bus(:, BUS_TYPE);
0201 bt = bt0;
0202 mpopt = mpoption(mpopt, 'pf.enforce_q_lims', 0);
0203 r = runpf(mpc, mpopt);
0204 t_ok(r.success, [t 'success']);
0205 t_is(r.bus(:, BUS_TYPE), bt, 12, [t 'bus type']);
0206 t_is(r.gen(:, QG), [-16.549300542; 43.557100134; 25.075348495; 12.730944405; 17.623451366], 8, [t 'Qg']);
0207 
0208 t = 'pf.enforce_q_lims == 1 : ';
0209 mpopt = mpoption(mpopt, 'pf.enforce_q_lims', 1);
0210 r = runpf(mpc, mpopt);
0211 bt = bt0;
0212 bt([1 2 3 8]) = [PQ PQ REF PQ];
0213 t_ok(~r.success, [t '~success']);
0214 t_is(r.bus(:, BUS_TYPE), bt, 12, [t 'bus type']);
0215 t_is(r.gen(:, QG), [-10; 30; 31.608422873; 16.420423190; 15], 4, [t 'Qg']);
0216 
0217 t = 'pf.enforce_q_lims == 2 : ';
0218 mpopt = mpoption(mpopt, 'pf.enforce_q_lims', 2);
0219 r = runpf(mpc, mpopt);
0220 bt = bt0;
0221 bt([1 2 3 6 8]) = [REF PQ PQ PQ PQ];
0222 t_ok(r.success, [t 'success']);
0223 t_is(r.bus(:, BUS_TYPE), bt, 12, [t 'bus type']);
0224 t_is(r.gen(:, QG), [-6.30936644; 30; 29; 15; 15], 8, [t 'Qg']);
0225 
0226 t_end;
0227 
0228 if have_fcn('octave')
0229     warning(s1.state, file_in_path_warn_id);
0230 end

Generated on Fri 16-Dec-2016 12:45:37 by m2html © 2005