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

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