Home > matpower6.0 > 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-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 num_tests = 63;
0017 
0018 t_begin(num_tests, quiet);
0019 
0020 %% define named indices into data matrices
0021 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0022     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0023 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0024     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0025     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0026 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0027     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0028     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0029 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
0030 c = idx_dcline;
0031 
0032 casefile = 't_case9_dcline';
0033 casefile2 = 'case9';
0034 if quiet
0035     verbose = 0;
0036 else
0037     verbose = 0;
0038 end
0039 if have_fcn('octave')
0040     if have_fcn('octave', 'vnum') >= 4
0041         file_in_path_warn_id = 'Octave:data-file-in-path';
0042     else
0043         file_in_path_warn_id = 'Octave:load-file-in-path';
0044     end
0045     s1 = warning('query', file_in_path_warn_id);
0046     warning('off', file_in_path_warn_id);
0047 end
0048 
0049 mpopt = mpoption('opf.violation', 1e-6, 'mips.gradtol', 1e-8, ...
0050         'mips.comptol', 1e-8, 'mips.costtol', 1e-9);
0051 mpopt = mpoption(mpopt, 'opf.ac.solver', 'MIPS', 'opf.dc.solver', 'MIPS');
0052 mpopt = mpoption(mpopt, 'out.all', 0, 'verbose', verbose);
0053 
0054 %% set up indices
0055 ib_data     = [1:BUS_AREA BASE_KV:VMIN];
0056 ib_voltage  = [VM VA];
0057 ib_lam      = [LAM_P LAM_Q];
0058 ib_mu       = [MU_VMAX MU_VMIN];
0059 ig_data     = [GEN_BUS QMAX QMIN MBASE:APF];
0060 ig_disp     = [PG QG VG];
0061 ig_mu       = (MU_PMAX:MU_QMIN);
0062 ibr_data    = (1:ANGMAX);
0063 ibr_flow    = (PF:QT);
0064 ibr_mu      = [MU_SF MU_ST];
0065 ibr_angmu   = [MU_ANGMIN MU_ANGMAX];
0066 
0067 %% load case
0068 mpc0 = loadcase(casefile);
0069 mpc0 = rmfield(mpc0, 'dclinecost');
0070 mpc = mpc0;
0071 mpc = toggle_dcline(mpc, 'on');
0072 mpc = toggle_dcline(mpc, 'off');
0073 ndc = size(mpc.dcline, 1);
0074 
0075 %% run AC OPF w/o DC lines
0076 t = 'AC OPF (no DC lines) : ';
0077 [r0, success] = runopf(mpc0, mpopt);
0078 t_ok(success, [t 'success']);
0079 [r,  success] = runopf(mpc, mpopt);
0080 t_ok(success, [t 'success']);
0081 t_is(r.f, r0.f, 8, [t 'f']);
0082 t_is(   r.bus(:,ib_data   ),    r0.bus(:,ib_data   ), 10, [t 'bus data']);
0083 t_is(   r.bus(:,ib_voltage),    r0.bus(:,ib_voltage),  3, [t 'bus voltage']);
0084 t_is(   r.bus(:,ib_lam    ),    r0.bus(:,ib_lam    ),  3, [t 'bus lambda']);
0085 t_is(   r.bus(:,ib_mu     ),    r0.bus(:,ib_mu     ),  2, [t 'bus mu']);
0086 t_is(   r.gen(:,ig_data   ),    r0.gen(:,ig_data   ), 10, [t 'gen data']);
0087 t_is(   r.gen(:,ig_disp   ),    r0.gen(:,ig_disp   ),  3, [t 'gen dispatch']);
0088 t_is(   r.gen(:,ig_mu     ),    r0.gen(:,ig_mu     ),  3, [t 'gen mu']);
0089 t_is(r.branch(:,ibr_data  ), r0.branch(:,ibr_data  ), 10, [t 'branch data']);
0090 t_is(r.branch(:,ibr_flow  ), r0.branch(:,ibr_flow  ),  3, [t 'branch flow']);
0091 t_is(r.branch(:,ibr_mu    ), r0.branch(:,ibr_mu    ),  2, [t 'branch mu']);
0092 
0093 t = 'AC PF (no DC lines) : ';
0094 mpc1 = struct('baseMVA', [], 'bus', [], 'branch', [], 'gencost', [], 'dcline', []);
0095 [mpc1.baseMVA, mpc1.bus, mpc1.gen, mpc1.branch, mpc1.gencost, mpc1.dcline] = ...
0096     deal(r.baseMVA, r.bus(:, 1:VMIN), r.gen(:, 1:APF), ...
0097         r.branch(:, 1:ANGMAX), r.gencost, r.dcline(:, 1:c.LOSS1));
0098 mpc1.bus(:, VM) = 1;
0099 mpc1.bus(:, VA) = 0;
0100 [rp, success] = runpf(mpc1, mpopt);
0101 t_ok(success, [t 'success']);
0102 t_is(   rp.bus(:,ib_voltage),    r.bus(:,ib_voltage),  3, [t 'bus voltage']);
0103 t_is(   rp.gen(:,ig_disp   ),    r.gen(:,ig_disp   ),  3, [t 'gen dispatch']);
0104 t_is(rp.branch(:,ibr_flow  ), r.branch(:,ibr_flow  ),  3, [t 'branch flow']);
0105 
0106 %% run with DC lines
0107 t = 'AC OPF (with DC lines) : ';
0108 mpc = toggle_dcline(mpc, 'on');
0109 [r, success] = runopf(mpc, mpopt);
0110 t_ok(success, [t 'success']);
0111 expected = [
0112     10    8.9    -10    10    1.0674    1.0935;
0113     2.2776    2.2776    0    0    1.0818    1.0665;
0114     0    0    0    0    1.0000    1.0000;
0115     10    9.5    0.0563    -10    1.0778    1.0665;
0116 ];
0117 t_is(r.dcline(:, c.PF:c.VT), expected, 4, [t 'P Q V']);
0118 expected = [
0119     0    0.8490    0.6165    0    0    0.2938;
0120     0    0    0    0.4290    0.0739    0;
0121     0    0    0    0    0    0;
0122     0    7.2209    0    0    0.0739    0;
0123 ];
0124 t_is(r.dcline(:, c.MU_PMIN:c.MU_QMAXT), expected, 3, [t 'mu']);
0125 
0126 t = 'AC PF (with DC lines) : ';
0127 mpc1 = struct('baseMVA', [], 'bus', [], 'branch', [], 'gencost', [], 'dcline', []);
0128 [mpc1.baseMVA, mpc1.bus, mpc1.gen, mpc1.branch, mpc1.gencost, mpc1.dcline] = ...
0129     deal(r.baseMVA, r.bus(:, 1:VMIN), r.gen(:, 1:APF), ...
0130         r.branch(:, 1:ANGMAX), r.gencost, r.dcline(:, 1:c.LOSS1));
0131 mpc1 = toggle_dcline(mpc1, 'on');
0132 mpc1.bus(:, VM) = 1;
0133 mpc1.bus(:, VA) = 0;
0134 [rp, success] = runpf(mpc1, mpopt);
0135 t_ok(success, [t 'success']);
0136 t_is(   rp.bus(:,ib_voltage),    r.bus(:,ib_voltage), 3, [t 'bus voltage']);
0137 %t_is(   rp.gen(:,ig_disp   ),    r.gen(:,ig_disp   ), 3, [t 'gen dispatch']);
0138 t_is(   rp.gen(1:2,ig_disp ),    r.gen(1:2,ig_disp ), 3, [t 'gen dispatch']);
0139 t_is(   rp.gen(3,PG        ),    r.gen(3,PG        ), 3, [t 'gen dispatch']);
0140 t_is(   rp.gen(3,QG)+rp.dcline(1,c.QF), r.gen(3,QG)+r.dcline(1,c.QF), 3, [t 'gen dispatch']);
0141 t_is(rp.branch(:,ibr_flow  ), r.branch(:,ibr_flow  ), 3, [t 'branch flow']);
0142 
0143 %% add appropriate P and Q injections and check angles and generation when running PF
0144 t = 'AC PF (with equivalent injections) : ';
0145 mpc1 = struct('baseMVA', [], 'bus', [], 'branch', [], 'gencost', [], 'dcline', []);
0146 [mpc1.baseMVA, mpc1.bus, mpc1.gen, mpc1.branch, mpc1.gencost, mpc1.dcline] = ...
0147     deal(r.baseMVA, r.bus(:, 1:VMIN), r.gen(:, 1:APF), ...
0148         r.branch(:, 1:ANGMAX), r.gencost, r.dcline(:, 1:c.LOSS1));
0149 mpc1.bus(:, VM) = 1;
0150 mpc1.bus(:, VA) = 0;
0151 for k = 1:ndc
0152     if mpc1.dcline(k, c.BR_STATUS)
0153         ff = find(mpc1.bus(:, BUS_I) == mpc1.dcline(k, c.F_BUS));
0154         tt = find(mpc1.bus(:, BUS_I) == mpc1.dcline(k, c.T_BUS));
0155         mpc1.bus(ff, PD) = mpc1.bus(ff, PD) + r.dcline(k, c.PF);
0156         mpc1.bus(ff, QD) = mpc1.bus(ff, QD) - r.dcline(k, c.QF);
0157         mpc1.bus(tt, PD) = mpc1.bus(tt, PD) - r.dcline(k, c.PT);
0158         mpc1.bus(tt, QD) = mpc1.bus(tt, QD) - r.dcline(k, c.QT);
0159         mpc1.bus(ff, VM) = r.dcline(k, c.VF);
0160         mpc1.bus(tt, VM) = r.dcline(k, c.VT);
0161         mpc1.bus(ff, BUS_TYPE) = PV;
0162         mpc1.bus(tt, BUS_TYPE) = PV;
0163     end
0164 end
0165 [rp, success] = runpf(mpc1, mpopt);
0166 t_ok(success, [t 'success']);
0167 t_is(   rp.bus(:,ib_voltage),    r.bus(:,ib_voltage),  3, [t 'bus voltage']);
0168 t_is(   rp.gen(:,ig_disp   ),    r.gen(:,ig_disp   ),  3, [t 'gen dispatch']);
0169 t_is(rp.branch(:,ibr_flow  ), r.branch(:,ibr_flow  ),  3, [t 'branch flow']);
0170 
0171 %% test DC OPF
0172 t = 'DC OPF (with DC lines) : ';
0173 mpc = mpc0;
0174 mpc.gen(1, PMIN) = 10;
0175 mpc.branch(5, RATE_A) = 100;
0176 mpc = toggle_dcline(mpc, 'on');
0177 [r, success] = rundcopf(mpc, mpopt);
0178 t_ok(success, [t 'success']);
0179 expected = [
0180     10    8.9    0    0    1.01    1;
0181     2    2    0    0    1    1;
0182     0    0    0    0    1    1;
0183     10    9.5    0    0    1    0.98;
0184 ];
0185 t_is(r.dcline(:, c.PF:c.VT), expected, 4, [t 'P Q V']);
0186 expected = [
0187     0    1.8602    0    0    0    0;
0188     1.8507    0    0    0    0    0;
0189     0    0    0    0    0    0;
0190     0    0.2681    0    0    0    0;
0191 ];
0192 t_is(r.dcline(:, c.MU_PMIN:c.MU_QMAXT), expected, 3, [t 'mu']);
0193 
0194 t = 'DC PF (with DC lines) : ';
0195 mpc1 = struct('baseMVA', [], 'bus', [], 'branch', [], 'gencost', [], 'dcline', []);
0196 [mpc1.baseMVA, mpc1.bus, mpc1.gen, mpc1.branch, mpc1.gencost, mpc1.dcline] = ...
0197     deal(r.baseMVA, r.bus(:, 1:VMIN), r.gen(:, 1:APF), ...
0198         r.branch(:, 1:ANGMAX), r.gencost, r.dcline(:, 1:c.LOSS1));
0199 mpc1 = toggle_dcline(mpc1, 'on');
0200 mpc1.bus(:, VA) = 0;
0201 [rp, success] = rundcpf(mpc1, mpopt);
0202 t_ok(success, [t 'success']);
0203 t_is(   rp.bus(:,ib_voltage),    r.bus(:,ib_voltage), 3, [t 'bus voltage']);
0204 t_is(   rp.gen(:,ig_disp   ),    r.gen(:,ig_disp   ), 3, [t 'gen dispatch']);
0205 t_is(rp.branch(:,ibr_flow  ), r.branch(:,ibr_flow  ), 3, [t 'branch flow']);
0206 
0207 %% add appropriate P injections and check angles and generation when running PF
0208 t = 'DC PF (with equivalent injections) : ';
0209 mpc1 = struct('baseMVA', [], 'bus', [], 'branch', [], 'gencost', [], 'dcline', []);
0210 [mpc1.baseMVA, mpc1.bus, mpc1.gen, mpc1.branch, mpc1.gencost, mpc1.dcline] = ...
0211     deal(r.baseMVA, r.bus(:, 1:VMIN), r.gen(:, 1:APF), ...
0212         r.branch(:, 1:ANGMAX), r.gencost, r.dcline(:, 1:c.LOSS1));
0213 mpc1.bus(:, VA) = 0;
0214 for k = 1:ndc
0215     if mpc1.dcline(k, c.BR_STATUS)
0216         ff = find(mpc1.bus(:, BUS_I) == mpc1.dcline(k, c.F_BUS));
0217         tt = find(mpc1.bus(:, BUS_I) == mpc1.dcline(k, c.T_BUS));
0218         mpc1.bus(ff, PD) = mpc1.bus(ff, PD) + r.dcline(k, c.PF);
0219         mpc1.bus(tt, PD) = mpc1.bus(tt, PD) - r.dcline(k, c.PT);
0220         mpc1.bus(ff, BUS_TYPE) = PV;
0221         mpc1.bus(tt, BUS_TYPE) = PV;
0222     end
0223 end
0224 [rp, success] = rundcpf(mpc1, mpopt);
0225 t_ok(success, [t 'success']);
0226 t_is(   rp.bus(:,ib_voltage),    r.bus(:,ib_voltage),  3, [t 'bus voltage']);
0227 t_is(   rp.gen(:,ig_disp   ),    r.gen(:,ig_disp   ),  3, [t 'gen dispatch']);
0228 t_is(rp.branch(:,ibr_flow  ), r.branch(:,ibr_flow  ),  3, [t 'branch flow']);
0229 
0230 %% run with DC lines
0231 t = 'AC OPF (with DC lines + poly cost) : ';
0232 mpc = loadcase(casefile);
0233 mpc = toggle_dcline(mpc, 'on');
0234 [r, success] = runopf(mpc, mpopt);
0235 t_ok(success, [t 'success']);
0236 expected1 = [
0237     10    8.9    -10    10    1.0663    1.0936;
0238     7.8429    7.8429    0    0    1.0809    1.0667;
0239     0    0    0    0    1.0000    1.0000;
0240     6.0549    5.7522    -0.5897    -10    1.0778    1.0667;
0241 ];
0242 t_is(r.dcline(:, c.PF:c.VT), expected1, 4, [t 'P Q V']);
0243 expected2 = [
0244     0    0.7605    0.6226    0    0    0.2980;
0245     0    0    0    0.4275    0.0792    0;
0246     0    0    0    0    0    0;
0247     0    0    0    0    0.0792    0;
0248 ];
0249 t_is(r.dcline(:, c.MU_PMIN:c.MU_QMAXT), expected2, 3, [t 'mu']);
0250 
0251 mpc.dclinecost(4, 1:8) = [2 0 0 4 0 0 7.3 0];
0252 [r, success] = runopf(mpc, mpopt);
0253 t_ok(success, [t 'success']);
0254 t_is(r.dcline(:, c.PF:c.VT), expected1, 4, [t 'P Q V']);
0255 t_is(r.dcline(:, c.MU_PMIN:c.MU_QMAXT), expected2, 3, [t 'mu']);
0256 
0257 t = 'AC OPF (with DC lines + pwl cost) : ';
0258 mpc.dclinecost(4, 1:8) = [1 0 0 2 0 0 10 73];
0259 [r, success] = runopf(mpc, mpopt);
0260 t_ok(success, [t 'success']);
0261 t_is(r.dcline(:, c.PF:c.VT), expected1, 4, [t 'P Q V']);
0262 t_is(r.dcline(:, c.MU_PMIN:c.MU_QMAXT), expected2, 3, [t 'mu']);
0263 
0264 t = 'AC OPF w/Qg cost (with DC lines + pwl cost) : ';
0265 mpc.gencost = [mpc.gencost; mpc.gencost];
0266 mpc.gencost(4:end, COST:end) = 0;
0267 mpc.gencost(4:end, MODEL) = 2;
0268 mpc.gencost(4:end, NCOST) = 2;
0269 mpc.gencost(5, COST+1) = 1;
0270 [r, success] = runopf(mpc, mpopt);
0271 t_ok(success, [t 'success']);
0272 t_is(r.dcline(:, c.PF:c.VT), expected1, 4, [t 'P Q V']);
0273 t_is(r.dcline(:, c.MU_PMIN:c.MU_QMAXT), expected2, 3, [t 'mu']);
0274 
0275 t = 'AC OPF (isolated gen bus w/DC connection) : ';
0276 mpc = loadcase(casefile2);
0277 % use case9 with bus 2 connected by DC line instead of AC line
0278 % requires making bus 2 a REF bus as well
0279 %%-----  DC Line Data  -----
0280 %    fbus    tbus    status    Pf    Pt    Qf    Qt    Vf    Vt    Pmin    Pmax    QminF    QmaxF    QminT    QmaxT    loss0    loss1
0281 mpc.dcline = [
0282     8    2    1    -163    163    0    0    1    1    -200    200    0    0    0    0    0    0;
0283 ];
0284 mpc.branch(7, BR_STATUS) = 0;
0285 mpc.bus(2, BUS_TYPE) = REF;
0286 mpc = toggle_dcline(mpc, 'on');
0287 
0288 [r, success] = runopf(mpc, mpopt);
0289 t_ok(success, [t 'success']);
0290 t_is(r.dcline(:, c.PF:c.VT), [-134.3323 -134.3323 0 0 1.1 1], 4, [t 'P Q V']);
0291 t_is(r.dcline(:, c.MU_PMIN:c.MU_QMAXT), [0 0 0.1311 0 0 0], 4, [t 'mu']);
0292 
0293 t = 'AC PF (isolated gen bus w/DC connection) : ';
0294 [r, success] = runpf(mpc, mpopt);
0295 t_ok(success, [t 'success']);
0296 t_is(r.dcline(:, c.PF:c.VT), [-163 -163 0.2146 0 1 1], 4, [t 'P Q V']);
0297 
0298 t = 'DC OPF (isolated gen bus w/DC connection) : ';
0299 [r, success] = rundcopf(mpc, mpopt);
0300 t_ok(success, [t 'success']);
0301 t_is(r.dcline(:, c.PF:c.VT), [-134.3776 -134.3776 0 0 1 1], 4, [t 'P Q V']);
0302 t_is(r.dcline(:, c.MU_PMIN:c.MU_QMAXT), [0 0 0 0 0 0], 3, [t 'mu']);
0303 
0304 t = 'DC PF (isolated gen bus w/DC connection) : ';
0305 [r, success] = rundcpf(mpc, mpopt);
0306 t_ok(success, [t 'success']);
0307 t_is(r.dcline(:, c.PF:c.VT), [-163 -163 0 0 1 1], 4, [t 'P Q V']);
0308 
0309 
0310 if have_fcn('octave')
0311     warning(s1.state, file_in_path_warn_id);
0312 end
0313 
0314 t_end;

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