Home > matpower5.1 > t > t_dcline.m

t_dcline

PURPOSE ^

T_DCLINE Tests for DC line extension in TOGGLE_DCLINE.

SYNOPSIS ^

function t_dcline(quiet)

DESCRIPTION ^

T_DCLINE  Tests for DC line extension in TOGGLE_DCLINE.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function t_dcline(quiet)
0002 %T_DCLINE  Tests for DC line extension in TOGGLE_DCLINE.
0003 
0004 %   MATPOWER
0005 %   Copyright (c) 2011-2015 by Power System Engineering Research Center (PSERC)
0006 %   by Ray Zimmerman, PSERC Cornell
0007 %
0008 %   $Id: t_dcline.m 2662 2015-03-20 20:02:08Z ray $
0009 %
0010 %   This file is part of MATPOWER.
0011 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0012 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0013 
0014 if nargin < 1
0015     quiet = 0;
0016 end
0017 
0018 num_tests = 50;
0019 
0020 t_begin(num_tests, quiet);
0021 
0022 %% define named indices into data matrices
0023 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0024     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0025 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0026     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0027     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0028 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0029     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0030     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0031 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
0032 c = idx_dcline;
0033 
0034 casefile = 't_case9_dcline';
0035 if quiet
0036     verbose = 0;
0037 else
0038     verbose = 0;
0039 end
0040 if have_fcn('octave')
0041     if have_fcn('octave', 'vnum') >= 4
0042         file_in_path_warn_id = 'Octave:data-file-in-path';
0043     else
0044         file_in_path_warn_id = 'Octave:load-file-in-path';
0045     end
0046     s1 = warning('query', file_in_path_warn_id);
0047     warning('off', file_in_path_warn_id);
0048 end
0049 
0050 t0 = '';
0051 mpopt = mpoption('opf.violation', 1e-6, 'mips.gradtol', 1e-8, ...
0052         'mips.comptol', 1e-8, 'mips.costtol', 1e-9);
0053 mpopt = mpoption(mpopt, 'opf.ac.solver', 'MIPS', 'opf.dc.solver', 'MIPS');
0054 mpopt = mpoption(mpopt, 'out.all', 0, 'verbose', verbose);
0055 
0056 %% set up indices
0057 ib_data     = [1:BUS_AREA BASE_KV:VMIN];
0058 ib_voltage  = [VM VA];
0059 ib_lam      = [LAM_P LAM_Q];
0060 ib_mu       = [MU_VMAX MU_VMIN];
0061 ig_data     = [GEN_BUS QMAX QMIN MBASE:APF];
0062 ig_disp     = [PG QG VG];
0063 ig_mu       = (MU_PMAX:MU_QMIN);
0064 ibr_data    = (1:ANGMAX);
0065 ibr_flow    = (PF:QT);
0066 ibr_mu      = [MU_SF MU_ST];
0067 ibr_angmu   = [MU_ANGMIN MU_ANGMAX];
0068 
0069 %% load case
0070 mpc0 = loadcase(casefile);
0071 mpc0 = rmfield(mpc0, 'dclinecost');
0072 mpc = mpc0;
0073 mpc = toggle_dcline(mpc, 'on');
0074 mpc = toggle_dcline(mpc, 'off');
0075 ndc = size(mpc.dcline, 1);
0076 
0077 %% run AC OPF w/o DC lines
0078 t = [t0 'AC OPF (no DC lines) : '];
0079 [r0, success] = runopf(mpc0, mpopt);
0080 t_ok(success, [t 'success']);
0081 [r,  success] = runopf(mpc, mpopt);
0082 t_ok(success, [t 'success']);
0083 t_is(r.f, r0.f, 8, [t 'f']);
0084 t_is(   r.bus(:,ib_data   ),    r0.bus(:,ib_data   ), 10, [t 'bus data']);
0085 t_is(   r.bus(:,ib_voltage),    r0.bus(:,ib_voltage),  3, [t 'bus voltage']);
0086 t_is(   r.bus(:,ib_lam    ),    r0.bus(:,ib_lam    ),  3, [t 'bus lambda']);
0087 t_is(   r.bus(:,ib_mu     ),    r0.bus(:,ib_mu     ),  2, [t 'bus mu']);
0088 t_is(   r.gen(:,ig_data   ),    r0.gen(:,ig_data   ), 10, [t 'gen data']);
0089 t_is(   r.gen(:,ig_disp   ),    r0.gen(:,ig_disp   ),  3, [t 'gen dispatch']);
0090 t_is(   r.gen(:,ig_mu     ),    r0.gen(:,ig_mu     ),  3, [t 'gen mu']);
0091 t_is(r.branch(:,ibr_data  ), r0.branch(:,ibr_data  ), 10, [t 'branch data']);
0092 t_is(r.branch(:,ibr_flow  ), r0.branch(:,ibr_flow  ),  3, [t 'branch flow']);
0093 t_is(r.branch(:,ibr_mu    ), r0.branch(:,ibr_mu    ),  2, [t 'branch mu']);
0094 
0095 t = [t0 'AC PF (no DC lines) : '];
0096 mpc1 = struct('baseMVA', [], 'bus', [], 'branch', [], 'gencost', [], 'dcline', []);
0097 [mpc1.baseMVA, mpc1.bus, mpc1.gen, mpc1.branch, mpc1.gencost, mpc1.dcline] = ...
0098     deal(r.baseMVA, r.bus(:, 1:VMIN), r.gen(:, 1:APF), ...
0099         r.branch(:, 1:ANGMAX), r.gencost, r.dcline(:, 1:c.LOSS1));
0100 mpc1.bus(:, VM) = 1;
0101 mpc1.bus(:, VA) = 0;
0102 [rp, success] = runpf(mpc1, mpopt);
0103 t_ok(success, [t 'success']);
0104 t_is(   rp.bus(:,ib_voltage),    r.bus(:,ib_voltage),  3, [t 'bus voltage']);
0105 t_is(   rp.gen(:,ig_disp   ),    r.gen(:,ig_disp   ),  3, [t 'gen dispatch']);
0106 t_is(rp.branch(:,ibr_flow  ), r.branch(:,ibr_flow  ),  3, [t 'branch flow']);
0107 
0108 %% run with DC lines
0109 t = [t0 'AC OPF (with DC lines) : '];
0110 mpc = toggle_dcline(mpc, 'on');
0111 [r, success] = runopf(mpc, mpopt);
0112 t_ok(success, [t 'success']);
0113 expected = [
0114     10    8.9    -10    10    1.0674    1.0935;
0115     2.2776    2.2776    0    0    1.0818    1.0665;
0116     0    0    0    0    1.0000    1.0000;
0117     10    9.5    0.0563    -10    1.0778    1.0665;
0118 ];
0119 t_is(r.dcline(:, c.PF:c.VT), expected, 4, [t 'P Q V']);
0120 expected = [
0121     0    0.8490    0.6165    0    0    0.2938;
0122     0    0    0    0.4290    0.0739    0;
0123     0    0    0    0    0    0;
0124     0    7.2209    0    0    0.0739    0;
0125 ];
0126 t_is(r.dcline(:, c.MU_PMIN:c.MU_QMAXT), expected, 3, [t 'mu']);
0127 
0128 t = [t0 'AC PF (with DC lines) : '];
0129 mpc1 = struct('baseMVA', [], 'bus', [], 'branch', [], 'gencost', [], 'dcline', []);
0130 [mpc1.baseMVA, mpc1.bus, mpc1.gen, mpc1.branch, mpc1.gencost, mpc1.dcline] = ...
0131     deal(r.baseMVA, r.bus(:, 1:VMIN), r.gen(:, 1:APF), ...
0132         r.branch(:, 1:ANGMAX), r.gencost, r.dcline(:, 1:c.LOSS1));
0133 mpc1 = toggle_dcline(mpc1, 'on');
0134 mpc1.bus(:, VM) = 1;
0135 mpc1.bus(:, VA) = 0;
0136 [rp, success] = runpf(mpc1, mpopt);
0137 t_ok(success, [t 'success']);
0138 t_is(   rp.bus(:,ib_voltage),    r.bus(:,ib_voltage), 3, [t 'bus voltage']);
0139 %t_is(   rp.gen(:,ig_disp   ),    r.gen(:,ig_disp   ), 3, [t 'gen dispatch']);
0140 t_is(   rp.gen(1:2,ig_disp ),    r.gen(1:2,ig_disp ), 3, [t 'gen dispatch']);
0141 t_is(   rp.gen(3,PG        ),    r.gen(3,PG        ), 3, [t 'gen dispatch']);
0142 t_is(   rp.gen(3,QG)+rp.dcline(1,c.QF), r.gen(3,QG)+r.dcline(1,c.QF), 3, [t 'gen dispatch']);
0143 t_is(rp.branch(:,ibr_flow  ), r.branch(:,ibr_flow  ), 3, [t 'branch flow']);
0144 
0145 %% add appropriate P and Q injections and check angles and generation when running PF
0146 t = [t0 'AC PF (with equivalent injections) : '];
0147 mpc1 = struct('baseMVA', [], 'bus', [], 'branch', [], 'gencost', [], 'dcline', []);
0148 [mpc1.baseMVA, mpc1.bus, mpc1.gen, mpc1.branch, mpc1.gencost, mpc1.dcline] = ...
0149     deal(r.baseMVA, r.bus(:, 1:VMIN), r.gen(:, 1:APF), ...
0150         r.branch(:, 1:ANGMAX), r.gencost, r.dcline(:, 1:c.LOSS1));
0151 mpc1.bus(:, VM) = 1;
0152 mpc1.bus(:, VA) = 0;
0153 for k = 1:ndc
0154     if mpc1.dcline(k, c.BR_STATUS)
0155         ff = find(mpc1.bus(:, BUS_I) == mpc1.dcline(k, c.F_BUS));
0156         tt = find(mpc1.bus(:, BUS_I) == mpc1.dcline(k, c.T_BUS));
0157         mpc1.bus(ff, PD) = mpc1.bus(ff, PD) + r.dcline(k, c.PF);
0158         mpc1.bus(ff, QD) = mpc1.bus(ff, QD) - r.dcline(k, c.QF);
0159         mpc1.bus(tt, PD) = mpc1.bus(tt, PD) - r.dcline(k, c.PT);
0160         mpc1.bus(tt, QD) = mpc1.bus(tt, QD) - r.dcline(k, c.QT);
0161         mpc1.bus(ff, VM) = r.dcline(k, c.VF);
0162         mpc1.bus(tt, VM) = r.dcline(k, c.VT);
0163         mpc1.bus(ff, BUS_TYPE) = PV;
0164         mpc1.bus(tt, BUS_TYPE) = PV;
0165     end
0166 end
0167 [rp, success] = runpf(mpc1, mpopt);
0168 t_ok(success, [t 'success']);
0169 t_is(   rp.bus(:,ib_voltage),    r.bus(:,ib_voltage),  3, [t 'bus voltage']);
0170 t_is(   rp.gen(:,ig_disp   ),    r.gen(:,ig_disp   ),  3, [t 'gen dispatch']);
0171 t_is(rp.branch(:,ibr_flow  ), r.branch(:,ibr_flow  ),  3, [t 'branch flow']);
0172 
0173 %% test DC OPF
0174 t = [t0 'DC OPF (with DC lines) : '];
0175 mpc = mpc0;
0176 mpc.gen(1, PMIN) = 10;
0177 mpc.branch(5, RATE_A) = 100;
0178 mpc = toggle_dcline(mpc, 'on');
0179 [r, success] = rundcopf(mpc, mpopt);
0180 t_ok(success, [t 'success']);
0181 expected = [
0182     10    8.9    0    0    1.01    1;
0183     2    2    0    0    1    1;
0184     0    0    0    0    1    1;
0185     10    9.5    0    0    1    0.98;
0186 ];
0187 t_is(r.dcline(:, c.PF:c.VT), expected, 4, [t 'P Q V']);
0188 expected = [
0189     0    1.8602    0    0    0    0;
0190     1.8507    0    0    0    0    0;
0191     0    0    0    0    0    0;
0192     0    0.2681    0    0    0    0;
0193 ];
0194 t_is(r.dcline(:, c.MU_PMIN:c.MU_QMAXT), expected, 3, [t 'mu']);
0195 
0196 t = [t0 'DC PF (with DC lines) : '];
0197 mpc1 = struct('baseMVA', [], 'bus', [], 'branch', [], 'gencost', [], 'dcline', []);
0198 [mpc1.baseMVA, mpc1.bus, mpc1.gen, mpc1.branch, mpc1.gencost, mpc1.dcline] = ...
0199     deal(r.baseMVA, r.bus(:, 1:VMIN), r.gen(:, 1:APF), ...
0200         r.branch(:, 1:ANGMAX), r.gencost, r.dcline(:, 1:c.LOSS1));
0201 mpc1 = toggle_dcline(mpc1, 'on');
0202 mpc1.bus(:, VA) = 0;
0203 [rp, success] = rundcpf(mpc1, mpopt);
0204 t_ok(success, [t 'success']);
0205 t_is(   rp.bus(:,ib_voltage),    r.bus(:,ib_voltage), 3, [t 'bus voltage']);
0206 t_is(   rp.gen(:,ig_disp   ),    r.gen(:,ig_disp   ), 3, [t 'gen dispatch']);
0207 t_is(rp.branch(:,ibr_flow  ), r.branch(:,ibr_flow  ), 3, [t 'branch flow']);
0208 
0209 %% add appropriate P injections and check angles and generation when running PF
0210 t = [t0 'DC PF (with equivalent injections) : '];
0211 mpc1 = struct('baseMVA', [], 'bus', [], 'branch', [], 'gencost', [], 'dcline', []);
0212 [mpc1.baseMVA, mpc1.bus, mpc1.gen, mpc1.branch, mpc1.gencost, mpc1.dcline] = ...
0213     deal(r.baseMVA, r.bus(:, 1:VMIN), r.gen(:, 1:APF), ...
0214         r.branch(:, 1:ANGMAX), r.gencost, r.dcline(:, 1:c.LOSS1));
0215 mpc1.bus(:, VA) = 0;
0216 for k = 1:ndc
0217     if mpc1.dcline(k, c.BR_STATUS)
0218         ff = find(mpc1.bus(:, BUS_I) == mpc1.dcline(k, c.F_BUS));
0219         tt = find(mpc1.bus(:, BUS_I) == mpc1.dcline(k, c.T_BUS));
0220         mpc1.bus(ff, PD) = mpc1.bus(ff, PD) + r.dcline(k, c.PF);
0221         mpc1.bus(tt, PD) = mpc1.bus(tt, PD) - r.dcline(k, c.PT);
0222         mpc1.bus(ff, BUS_TYPE) = PV;
0223         mpc1.bus(tt, BUS_TYPE) = PV;
0224     end
0225 end
0226 [rp, success] = rundcpf(mpc1, mpopt);
0227 t_ok(success, [t 'success']);
0228 t_is(   rp.bus(:,ib_voltage),    r.bus(:,ib_voltage),  3, [t 'bus voltage']);
0229 t_is(   rp.gen(:,ig_disp   ),    r.gen(:,ig_disp   ),  3, [t 'gen dispatch']);
0230 t_is(rp.branch(:,ibr_flow  ), r.branch(:,ibr_flow  ),  3, [t 'branch flow']);
0231 
0232 %% run with DC lines
0233 t = [t0 'AC OPF (with DC lines + poly cost) : '];
0234 mpc = loadcase(casefile);
0235 mpc = toggle_dcline(mpc, 'on');
0236 [r, success] = runopf(mpc, mpopt);
0237 t_ok(success, [t 'success']);
0238 expected1 = [
0239     10    8.9    -10    10    1.0663    1.0936;
0240     7.8429    7.8429    0    0    1.0809    1.0667;
0241     0    0    0    0    1.0000    1.0000;
0242     6.0549    5.7522    -0.5897    -10    1.0778    1.0667;
0243 ];
0244 t_is(r.dcline(:, c.PF:c.VT), expected1, 4, [t 'P Q V']);
0245 expected2 = [
0246     0    0.7605    0.6226    0    0    0.2980;
0247     0    0    0    0.4275    0.0792    0;
0248     0    0    0    0    0    0;
0249     0    0    0    0    0.0792    0;
0250 ];
0251 t_is(r.dcline(:, c.MU_PMIN:c.MU_QMAXT), expected2, 3, [t 'mu']);
0252 
0253 mpc.dclinecost(4, 1:8) = [2 0 0 4 0 0 7.3 0];
0254 [r, success] = runopf(mpc, mpopt);
0255 t_ok(success, [t 'success']);
0256 t_is(r.dcline(:, c.PF:c.VT), expected1, 4, [t 'P Q V']);
0257 t_is(r.dcline(:, c.MU_PMIN:c.MU_QMAXT), expected2, 3, [t 'mu']);
0258 
0259 t = [t0 'AC OPF (with DC lines + pwl cost) : '];
0260 mpc.dclinecost(4, 1:8) = [1 0 0 2 0 0 10 73];
0261 [r, success] = runopf(mpc, mpopt);
0262 t_ok(success, [t 'success']);
0263 t_is(r.dcline(:, c.PF:c.VT), expected1, 4, [t 'P Q V']);
0264 t_is(r.dcline(:, c.MU_PMIN:c.MU_QMAXT), expected2, 3, [t 'mu']);
0265 
0266 if have_fcn('octave')
0267     warning(s1.state, file_in_path_warn_id);
0268 end
0269 
0270 t_end;

Generated on Fri 20-Mar-2015 18:23:34 by m2html © 2005