0001 function t_pf(quiet)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 if nargin < 1
0015 quiet = 0;
0016 end
0017
0018 t_begin(35, quiet);
0019
0020 casefile = 't_case9_pf';
0021 if quiet
0022 verbose = 0;
0023 else
0024 verbose = 1;
0025 end
0026 if have_fcn('octave')
0027 if have_fcn('octave', 'vnum') >= 4
0028 file_in_path_warn_id = 'Octave:data-file-in-path';
0029 else
0030 file_in_path_warn_id = 'Octave:load-file-in-path';
0031 end
0032 s1 = warning('query', file_in_path_warn_id);
0033 warning('off', file_in_path_warn_id);
0034 end
0035 mpopt = mpoption('out.all', 0, 'verbose', verbose);
0036
0037
0038 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0039 VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0040 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0041 TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0042 ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0043 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0044 MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0045 QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0046
0047
0048 load soln9_pf;
0049
0050
0051 t = 'Newton PF : ';
0052 mpopt = mpoption(mpopt, 'pf.alg', 'NR');
0053 [baseMVA, bus, gen, branch, success, et] = runpf(casefile, mpopt);
0054 t_ok(success, [t 'success']);
0055 t_is(bus, bus_soln, 6, [t 'bus']);
0056 t_is(gen, gen_soln, 6, [t 'gen']);
0057 t_is(branch, branch_soln, 6, [t 'branch']);
0058
0059
0060 t = 'Fast Decoupled (XB) PF : ';
0061 mpopt = mpoption(mpopt, 'pf.alg', 'FDXB');
0062 [baseMVA, bus, gen, branch, success, et] = runpf(casefile, mpopt);
0063 t_ok(success, [t 'success']);
0064 t_is(bus, bus_soln, 6, [t 'bus']);
0065 t_is(gen, gen_soln, 6, [t 'gen']);
0066 t_is(branch, branch_soln, 6, [t 'branch']);
0067
0068
0069 t = 'Fast Decoupled (BX) PF : ';
0070 mpopt = mpoption(mpopt, 'pf.alg', 'FDBX');
0071 [baseMVA, bus, gen, branch, success, et] = runpf(casefile, mpopt);
0072 t_ok(success, [t 'success']);
0073 t_is(bus, bus_soln, 6, [t 'bus']);
0074 t_is(gen, gen_soln, 6, [t 'gen']);
0075 t_is(branch, branch_soln, 6, [t 'branch']);
0076
0077
0078 t = 'Gauss-Seidel PF : ';
0079 mpopt = mpoption(mpopt, 'pf.alg', 'GS');
0080 [baseMVA, bus, gen, branch, success, et] = runpf(casefile, mpopt);
0081 t_ok(success, [t 'success']);
0082 t_is(bus, bus_soln, 5, [t 'bus']);
0083 t_is(gen, gen_soln, 5, [t 'gen']);
0084 t_is(branch, branch_soln, 5, [t 'branch']);
0085
0086
0087 load soln9_dcpf;
0088
0089
0090 t = 'DC PF : ';
0091 [baseMVA, bus, gen, branch, success, et] = rundcpf(casefile, mpopt);
0092 t_ok(success, [t 'success']);
0093 t_is(bus, bus_soln, 6, [t 'bus']);
0094 t_is(gen, gen_soln, 6, [t 'gen']);
0095 t_is(branch, branch_soln, 6, [t 'branch']);
0096
0097
0098 t = 'check Qg : ';
0099 mpopt = mpoption(mpopt, 'pf.alg', 'NR', 'verbose', 0);
0100 mpc = loadcase(casefile);
0101 mpc.gen(1, [QMIN QMAX]) = [20 20];
0102 [baseMVA, bus, gen, branch, success, et] = runpf(mpc, mpopt);
0103 t_is(gen(1, QG), 24.07, 2, [t 'single gen, Qmin = Qmax']);
0104
0105 mpc.gen = [mpc.gen(1, :); mpc.gen];
0106 mpc.gen(1, [QMIN QMAX]) = [10 10];
0107 mpc.gen(2, [QMIN QMAX]) = [0 50];
0108 [baseMVA, bus, gen, branch, success, et] = runpf(mpc, mpopt);
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_is(gen(1:2, QG), [12.03; 12.03], 2, [t '2 gens, Qmin = Qmax for both']);
0115
0116 mpc.gen(1, [QMIN QMAX]) = [0 50];
0117 mpc.gen(2, [QMIN QMAX]) = [0 100];
0118 [baseMVA, bus, gen, branch, success, et] = runpf(mpc, mpopt);
0119 t_is(gen(1:2, QG), [8.02; 16.05], 2, [t '2 gens, proportional']);
0120
0121 mpc.gen(1, [QMIN QMAX]) = [-50 0];
0122 mpc.gen(2, [QMIN QMAX]) = [50 150];
0123 [baseMVA, bus, gen, branch, success, et] = runpf(mpc, mpopt);
0124 t_is(gen(1:2, QG), [-50+8.02; 50+16.05], 2, [t '2 gens, proportional']);
0125
0126 t = 'reactive generation allocation : ';
0127 mpc = loadcase(casefile);
0128
0129
0130 mpc.gen = [
0131 1 0 0 300 -300 1 100 1 250 10 0 0 0 0 0 0 0 0 0 0 0;
0132 2 54 0 0 -5 1 100 1 300 10 0 0 0 0 0 0 0 0 0 0 0;
0133 2 54 0 5 -5 1 100 1 300 10 0 0 0 0 0 0 0 0 0 0 0;
0134 2 55 0 25 10 1 100 1 300 10 0 0 0 0 0 0 0 0 0 0 0;
0135 30 25 1 300 -300 1 100 1 270 10 0 0 0 0 0 0 0 0 0 0 0;
0136 30 30 2 300 -300 1 100 1 270 10 0 0 0 0 0 0 0 0 0 0 0;
0137 30 30 -3 300 -300 1 100 1 270 10 0 0 0 0 0 0 0 0 0 0 0;
0138 ];
0139 mpc.bus(3, BUS_TYPE) = PQ;
0140 r = runpf(mpc, mpopt);
0141 t_is(r.gen(2:4, QG), [-5; -5; 10] + [1; 2; 3]*1.989129794, 8, [t 'PV bus']);
0142 t_is(r.gen(5:7, QG), [1; 2; -3], 8, [t 'PQ bus']);
0143
0144
0145 t = 'network w/islands : DC PF : ';
0146 mpc0 = loadcase(casefile);
0147 mpc0.gen(1, PG) = 60;
0148 mpc0.gen(1, [PMIN PMAX QMIN QMAX PG QG]) = mpc0.gen(1, [PMIN PMAX QMIN QMAX PG QG]) / 2;
0149 mpc0.gen = [mpc0.gen(1, :); mpc0.gen];
0150 mpc1 = mpc0;
0151 mpc = mpc0;
0152 nb = size(mpc.bus, 1);
0153 mpc1.bus(:, BUS_I) = mpc1.bus(:, BUS_I) + nb;
0154 mpc1.branch(:, F_BUS) = mpc1.branch(:, F_BUS) + nb;
0155 mpc1.branch(:, T_BUS) = mpc1.branch(:, T_BUS) + nb;
0156 mpc1.gen(:, GEN_BUS) = mpc1.gen(:, GEN_BUS) + nb;
0157 mpc.bus = [mpc.bus; mpc1.bus];
0158 mpc.branch = [mpc.branch; mpc1.branch];
0159 mpc.gen = [mpc.gen; mpc1.gen];
0160
0161 mpopt = mpoption(mpopt, 'verbose', verbose);
0162 r = rundcpf(mpc, mpopt);
0163 t_is(r.bus( 1:9, VA), bus_soln(:, VA), 8, [t 'voltage angles 1']);
0164 t_is(r.bus(10:18, VA), bus_soln(:, VA), 8, [t 'voltage angles 2']);
0165 Pg = [gen_soln(1, PG)-30; 30; gen_soln(2:3, PG)];
0166 t_is(r.gen(1:4, PG), Pg, 8, [t 'active power generation 1']);
0167 t_is(r.gen(5:8, PG), Pg, 8, [t 'active power generation 1']);
0168
0169 t = 'network w/islands : AC PF : ';
0170
0171 load soln9_pf;
0172 r = runpf(mpc, mpopt);
0173 t_is(r.bus( 1:9, VA), bus_soln(:, VA), 8, [t 'voltage angles 1']);
0174 t_is(r.bus(10:18, VA), bus_soln(:, VA), 8, [t 'voltage angles 2']);
0175 Pg = [gen_soln(1, PG)-30; 30; gen_soln(2:3, PG)];
0176 t_is(r.gen(1:4, PG), Pg, 8, [t 'active power generation 1']);
0177 t_is(r.gen(5:8, PG), Pg, 8, [t 'active power generation 1']);
0178
0179 t_end;
0180
0181 if have_fcn('octave')
0182 warning(s1.state, file_in_path_warn_id);
0183 end