Home > matpower5.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 %   $Id: t_pf.m 2398 2014-10-18 01:54:35Z ray $
0006 %   by Ray Zimmerman, PSERC Cornell
0007 %   Copyright (c) 2004-2010 by Power System Engineering Research Center (PSERC)
0008 %
0009 %   This file is part of MATPOWER.
0010 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0011 %
0012 %   MATPOWER is free software: you can redistribute it and/or modify
0013 %   it under the terms of the GNU General Public License as published
0014 %   by the Free Software Foundation, either version 3 of the License,
0015 %   or (at your option) any later version.
0016 %
0017 %   MATPOWER is distributed in the hope that it will be useful,
0018 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0019 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0020 %   GNU General Public License for more details.
0021 %
0022 %   You should have received a copy of the GNU General Public License
0023 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0024 %
0025 %   Additional permission under GNU GPL version 3 section 7
0026 %
0027 %   If you modify MATPOWER, or any covered work, to interface with
0028 %   other modules (such as MATLAB code and MEX-files) available in a
0029 %   MATLAB(R) or comparable environment containing parts covered
0030 %   under other licensing terms, the licensors of MATPOWER grant
0031 %   you additional permission to convey the resulting work.
0032 
0033 if nargin < 1
0034     quiet = 0;
0035 end
0036 
0037 t_begin(35, quiet);
0038 
0039 casefile = 't_case9_pf';
0040 if quiet
0041     verbose = 0;
0042 else
0043     verbose = 1;
0044 end
0045 if have_fcn('octave')
0046     s1 = warning('query', 'Octave:load-file-in-path');
0047     warning('off', 'Octave:load-file-in-path');
0048 end
0049 mpopt = mpoption('out.all', 0, 'verbose', verbose);
0050 
0051 %% define named indices into bus, gen, branch matrices
0052 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0053     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0054 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0055     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0056     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0057 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0058     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0059     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0060 
0061 %% get solved AC power flow case from MAT-file
0062 load soln9_pf;      %% defines bus_soln, gen_soln, branch_soln
0063 
0064 %% run Newton PF
0065 t = 'Newton PF : ';
0066 mpopt = mpoption(mpopt, 'pf.alg', 'NR');
0067 [baseMVA, bus, gen, branch, success, et] = runpf(casefile, mpopt);
0068 t_ok(success, [t 'success']);
0069 t_is(bus, bus_soln, 6, [t 'bus']);
0070 t_is(gen, gen_soln, 6, [t 'gen']);
0071 t_is(branch, branch_soln, 6, [t 'branch']);
0072 
0073 %% run fast-decoupled PF (XB version)
0074 t = 'Fast Decoupled (XB) PF : ';
0075 mpopt = mpoption(mpopt, 'pf.alg', 'FDXB');
0076 [baseMVA, bus, gen, branch, success, et] = runpf(casefile, mpopt);
0077 t_ok(success, [t 'success']);
0078 t_is(bus, bus_soln, 6, [t 'bus']);
0079 t_is(gen, gen_soln, 6, [t 'gen']);
0080 t_is(branch, branch_soln, 6, [t 'branch']);
0081 
0082 %% run fast-decoupled PF (BX version)
0083 t = 'Fast Decoupled (BX) PF : ';
0084 mpopt = mpoption(mpopt, 'pf.alg', 'FDBX');
0085 [baseMVA, bus, gen, branch, success, et] = runpf(casefile, mpopt);
0086 t_ok(success, [t 'success']);
0087 t_is(bus, bus_soln, 6, [t 'bus']);
0088 t_is(gen, gen_soln, 6, [t 'gen']);
0089 t_is(branch, branch_soln, 6, [t 'branch']);
0090 
0091 %% run Gauss-Seidel PF
0092 t = 'Gauss-Seidel PF : ';
0093 mpopt = mpoption(mpopt, 'pf.alg', 'GS');
0094 [baseMVA, bus, gen, branch, success, et] = runpf(casefile, mpopt);
0095 t_ok(success, [t 'success']);
0096 t_is(bus, bus_soln, 5, [t 'bus']);
0097 t_is(gen, gen_soln, 5, [t 'gen']);
0098 t_is(branch, branch_soln, 5, [t 'branch']);
0099 
0100 %% get solved AC power flow case from MAT-file
0101 load soln9_dcpf;        %% defines bus_soln, gen_soln, branch_soln
0102 
0103 %% run DC PF
0104 t = 'DC PF : ';
0105 [baseMVA, bus, gen, branch, success, et] = rundcpf(casefile, mpopt);
0106 t_ok(success, [t 'success']);
0107 t_is(bus, bus_soln, 6, [t 'bus']);
0108 t_is(gen, gen_soln, 6, [t 'gen']);
0109 t_is(branch, branch_soln, 6, [t 'branch']);
0110 
0111 %% check Qg distribution, when Qmin = Qmax
0112 t = 'check Qg : ';
0113 mpopt = mpoption(mpopt, 'pf.alg', 'NR', 'verbose', 0);
0114 mpc = loadcase(casefile);
0115 mpc.gen(1, [QMIN QMAX]) = [20 20];
0116 [baseMVA, bus, gen, branch, success, et] = runpf(mpc, mpopt);
0117 t_is(gen(1, QG), 24.07, 2, [t 'single gen, Qmin = Qmax']);
0118 
0119 mpc.gen = [mpc.gen(1, :); mpc.gen];
0120 mpc.gen(1, [QMIN QMAX]) = [10 10];
0121 mpc.gen(2, [QMIN QMAX]) = [0 50];
0122 [baseMVA, bus, gen, branch, success, et] = runpf(mpc, mpopt);
0123 t_is(gen(1:2, QG), [10; 14.07], 2, [t '2 gens, Qmin = Qmax for one']);
0124 
0125 mpc.gen(1, [QMIN QMAX]) = [10 10];
0126 mpc.gen(2, [QMIN QMAX]) = [-50 -50];
0127 [baseMVA, bus, gen, branch, success, et] = runpf(mpc, mpopt);
0128 t_is(gen(1:2, QG), [12.03; 12.03], 2, [t '2 gens, Qmin = Qmax for both']);
0129 
0130 mpc.gen(1, [QMIN QMAX]) = [0 50];
0131 mpc.gen(2, [QMIN QMAX]) = [0 100];
0132 [baseMVA, bus, gen, branch, success, et] = runpf(mpc, mpopt);
0133 t_is(gen(1:2, QG), [8.02; 16.05], 2, [t '2 gens, proportional']);
0134 
0135 mpc.gen(1, [QMIN QMAX]) = [-50 0];
0136 mpc.gen(2, [QMIN QMAX]) = [50 150];
0137 [baseMVA, bus, gen, branch, success, et] = runpf(mpc, mpopt);
0138 t_is(gen(1:2, QG), [-50+8.02; 50+16.05], 2, [t '2 gens, proportional']);
0139 
0140 t = 'reactive generation allocation : ';
0141 mpc = loadcase(casefile);
0142 %% generator data
0143 %    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
0144 mpc.gen = [
0145     1    0    0    300    -300    1    100    1    250    10    0    0    0    0    0    0    0    0    0    0    0;
0146     2    54    0    0    -5    1    100    1    300    10    0    0    0    0    0    0    0    0    0    0    0;
0147     2    54    0    5    -5    1    100    1    300    10    0    0    0    0    0    0    0    0    0    0    0;
0148     2    55    0    25     10    1    100    1    300    10    0    0    0    0    0    0    0    0    0    0    0;
0149     30    25    1    300    -300    1    100    1    270    10    0    0    0    0    0    0    0    0    0    0    0;
0150     30    30    2    300    -300    1    100    1    270    10    0    0    0    0    0    0    0    0    0    0    0;
0151     30    30    -3    300    -300    1    100    1    270    10    0    0    0    0    0    0    0    0    0    0    0;
0152 ];
0153 mpc.bus(3, BUS_TYPE) = PQ;
0154 r = runpf(mpc, mpopt);
0155 t_is(r.gen(2:4, QG), [-5; -5; 10] + [1; 2; 3]*1.989129794, 8, [t 'PV bus']);
0156 t_is(r.gen(5:7, QG), [1; 2; -3], 8, [t 'PQ bus']);
0157 
0158 %% network with islands
0159 t = 'network w/islands : DC PF : ';
0160 mpc0 = loadcase(casefile);
0161 mpc0.gen(1, PG) = 60;
0162 mpc0.gen(1, [PMIN PMAX QMIN QMAX PG QG]) = mpc0.gen(1, [PMIN PMAX QMIN QMAX PG QG]) / 2;
0163 mpc0.gen = [mpc0.gen(1, :); mpc0.gen];
0164 mpc1 = mpc0;
0165 mpc  = mpc0;
0166 nb = size(mpc.bus, 1);
0167 mpc1.bus(:, BUS_I)        = mpc1.bus(:, BUS_I) + nb;
0168 mpc1.branch(:, F_BUS)    = mpc1.branch(:, F_BUS) + nb;
0169 mpc1.branch(:, T_BUS)    = mpc1.branch(:, T_BUS) + nb;
0170 mpc1.gen(:, GEN_BUS)    = mpc1.gen(:, GEN_BUS) + nb;
0171 mpc.bus            = [mpc.bus; mpc1.bus];
0172 mpc.branch        = [mpc.branch; mpc1.branch];
0173 mpc.gen            = [mpc.gen; mpc1.gen];
0174 %mpopt = mpoption(mpopt, 'out.bus', 1, 'out.gen', 1, 'out.all', -1, 'verbose', 2);
0175 mpopt = mpoption(mpopt, 'verbose', verbose);
0176 r = rundcpf(mpc, mpopt);
0177 t_is(r.bus( 1:9,  VA), bus_soln(:, VA), 8, [t 'voltage angles 1']);
0178 t_is(r.bus(10:18, VA), bus_soln(:, VA), 8, [t 'voltage angles 2']);
0179 Pg = [gen_soln(1, PG)-30; 30; gen_soln(2:3, PG)];
0180 t_is(r.gen(1:4, PG), Pg, 8, [t 'active power generation 1']);
0181 t_is(r.gen(5:8, PG), Pg, 8, [t 'active power generation 1']);
0182 
0183 t = 'network w/islands : AC PF : ';
0184 %% get solved AC power flow case from MAT-file
0185 load soln9_pf;      %% defines bus_soln, gen_soln, branch_soln
0186 r = runpf(mpc, mpopt);
0187 t_is(r.bus( 1:9,  VA), bus_soln(:, VA), 8, [t 'voltage angles 1']);
0188 t_is(r.bus(10:18, VA), bus_soln(:, VA), 8, [t 'voltage angles 2']);
0189 Pg = [gen_soln(1, PG)-30; 30; gen_soln(2:3, PG)];
0190 t_is(r.gen(1:4, PG), Pg, 8, [t 'active power generation 1']);
0191 t_is(r.gen(5:8, PG), Pg, 8, [t 'active power generation 1']);
0192 
0193 t_end;
0194 
0195 if have_fcn('octave')
0196     warning(s1.state, 'Octave:load-file-in-path');
0197 end

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