Home > matpower7.1 > lib > t > t_pf_dc.m

t_pf_dc

PURPOSE ^

T_PF_DC Tests for DC power flow solver.

SYNOPSIS ^

function t_pf_dc(quiet)

DESCRIPTION ^

T_PF_DC  Tests for DC power flow solver.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function t_pf_dc(quiet)
0002 %T_PF_DC  Tests for DC power flow solver.
0003 
0004 %   MATPOWER
0005 %   Copyright (c) 2004-2019, 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 https://matpower.org for more info.
0011 
0012 if nargin < 1
0013     quiet = 0;
0014 end
0015 
0016 t_begin(14, quiet);
0017 
0018 casefile = 't_case9_pf';
0019 if quiet
0020     verbose = 0;
0021 else
0022     verbose = 1;
0023 end
0024 if have_feature('octave')
0025     if have_feature('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, 'pf.tol', 1e-9, 'verbose', 0);
0034 mpopt = mpoption(mpopt, 'verbose', verbose);
0035 
0036 %% define named indices into bus, gen, branch matrices
0037 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0038     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0039 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0040     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0041     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0042 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0043     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0044     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0045 
0046 %% network with islands
0047 mpc0 = loadcase(casefile);
0048 mpc0.gen(1, PG) = 60;
0049 mpc0.gen(1, [PMIN PMAX QMIN QMAX PG QG]) = mpc0.gen(1, [PMIN PMAX QMIN QMAX PG QG]) / 2;
0050 mpc0.gen = [mpc0.gen(1, :); mpc0.gen];
0051 mpc1 = mpc0;
0052 mpc  = mpc0;
0053 nb = size(mpc.bus, 1);
0054 mpc1.bus(:, BUS_I)      = mpc1.bus(:, BUS_I) + nb;
0055 mpc1.branch(:, F_BUS)   = mpc1.branch(:, F_BUS) + nb;
0056 mpc1.branch(:, T_BUS)   = mpc1.branch(:, T_BUS) + nb;
0057 mpc1.gen(:, GEN_BUS)    = mpc1.gen(:, GEN_BUS) + nb;
0058 mpc.bus         = [mpc.bus; mpc1.bus];
0059 mpc.branch      = [mpc.branch; mpc1.branch];
0060 mpc.gen         = [mpc.gen; mpc1.gen];
0061 mpc1 = mpc;
0062 
0063 %%-----  DC power flow  -----
0064 %% get solved AC power flow case from MAT-file
0065 load soln9_dcpf;        %% defines bus_soln, gen_soln, branch_soln
0066 
0067 %% run DC PF
0068 t = 'DC PF : ';
0069 [baseMVA, bus, gen, branch, success, et] = rundcpf(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 r = rundcpf(casefile, mpopt);
0075 t_ok(r.success, [t 'success']);
0076 t_is(r.bus, bus_soln, 6, [t 'bus']);
0077 t_is(r.gen, gen_soln, 6, [t 'gen']);
0078 t_is(r.branch, branch_soln, 6, [t 'branch']);
0079 
0080 %% network with islands
0081 t = sprintf('DC PF - network w/islands : ');
0082 mpc  = mpc1;
0083 %mpopt = mpoption(mpopt, 'out.bus', 1, 'out.gen', 1, 'out.all', -1, 'verbose', 2);
0084 r = rundcpf(mpc, mpopt);
0085 t_ok(r.success, [t 'success']);
0086 t_is(r.bus( 1:9,  VA), bus_soln(:, VA), 8, [t 'voltage angles 1']);
0087 t_is(r.bus(10:18, VA), bus_soln(:, VA), 8, [t 'voltage angles 2']);
0088 Pg = [gen_soln(1, PG)-30; 30; gen_soln(2:3, PG)];
0089 t_is(r.gen(1:4, PG), Pg, 8, [t 'active power generation 1']);
0090 t_is(r.gen(5:8, PG), Pg, 8, [t 'active power generation 1']);
0091 
0092 %% island without slack bus (catch singluar matrix?)
0093 t = sprintf('DC PF - network w/islands w/o slack : ');
0094 k = find(mpc.bus(:, BUS_TYPE) == REF);
0095 mpc.bus(k(2), BUS_TYPE) = PV;
0096 warn_state = warning;
0097 warning('off', 'all');  %% turn of (near-)singular matrix warnings
0098 r = rundcpf(mpc, mpopt);
0099 warning(warn_state);
0100 t_is(r.success, 0, 12, [t 'success = 0']);
0101 
0102 t_end;
0103 
0104 if have_feature('octave')
0105     warning(s1.state, file_in_path_warn_id);
0106 end

Generated on Fri 09-Oct-2020 11:21:31 by m2html © 2005