Home > matpower6.0 > t > t_opf_softlims.m

t_opf_softlims

PURPOSE ^

T_OPF_SOFTLIMS Tests for userfcn callbacks (softlims) w/OPF.

SYNOPSIS ^

function t_opf_softlims(quiet)

DESCRIPTION ^

T_OPF_SOFTLIMS  Tests for userfcn callbacks (softlims) w/OPF.
   Includes high-level tests of soft limits implementations.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function t_opf_softlims(quiet)
0002 %T_OPF_SOFTLIMS  Tests for userfcn callbacks (softlims) w/OPF.
0003 %   Includes high-level tests of soft limits implementations.
0004 
0005 %   MATPOWER
0006 %   Copyright (c) 2009-2016, Power Systems Engineering Research Center (PSERC)
0007 %   by Ray Zimmerman, PSERC Cornell
0008 %
0009 %   This file is part of MATPOWER.
0010 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0011 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0012 
0013 if nargin < 1
0014     quiet = 0;
0015 end
0016 
0017 casefile = 'case9';
0018 if quiet
0019     verbose = 0;
0020 else
0021     verbose = 0;
0022 end
0023 
0024 t_begin(55, quiet);
0025 
0026 %% define constants
0027 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0028     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0029     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0030 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0031     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0032     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0033 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
0034 
0035 %% set options
0036 mpopt = mpoption('model', 'DC', 'opf.dc.solver', 'MIPS');
0037 mpopt = mpoption(mpopt, 'opf.violation', 1e-6, 'mips.gradtol', 1e-8, ...
0038         'mips.comptol', 1e-8, 'mips.costtol', 1e-9);
0039 if verbose <= 1
0040     mpopt = mpoption(mpopt, 'out.all', 0);
0041 end
0042 mpopt = mpoption(mpopt, 'verbose', verbose);
0043 
0044 %% load and modify case file
0045 mpc = loadcase(casefile);
0046 nl = size(mpc.branch, 1);
0047 mpc.gencost(:, NCOST) = 2;
0048 mpc.gencost(:, COST) = [];
0049 mpc.gencost(:, COST) = [50; 40; 25];
0050 mpc.gencost(:, COST+1) = 0;
0051 mpc.branch(2:6, RATE_A) = [0; 120; 0; 120; 0];
0052 mpc.branch(3, RATE_A) = 120;
0053 mpc.branch(5, RATE_A) = 120;
0054 mpc.branch = [mpc.branch(1:4, :); mpc.branch(4, :);  mpc.branch(5:end, :)];
0055 mpc.branch(5, BR_STATUS) = 0;
0056 
0057 nl = size(mpc.branch, 1);   %% number of branches
0058 
0059 %% create soft limit inputs
0060 mpc.softlims.idx = (2:nl)';
0061 mpc.softlims.cost = 100 * ones(nl-1, 1);
0062 
0063 t = 'hard limits : ';
0064 t_ok(~toggle_softlims(mpc, 'status'), 'toggle_softlims(mpc, ''status'') == 0');
0065 r = runopf(mpc, mpopt);
0066 t_ok(r.success, [t 'success']);
0067 t_ok(~isfield(r.softlims, 'overload'), [t 'no softlims.overload']);
0068 t_ok(~isfield(r.softlims, 'overload'), [t 'no softlims.ovl_cost']);
0069 t_is(r.f, 9126.87, 4, [t 'f']);
0070 t_is(r.gen(:, PG), [12.687; 62.3130; 240], 4, [t 'Pg']);
0071 t_is(r.branch(:, PF), [12.687; -30; -120; 240; 0; 120; 20; -62.3130; 82.3130; -42.687], 4, [t 'Pf']);
0072 t_is(r.branch(:, MU_SF)+r.branch(:, MU_ST), [0; 0; 35.6504; 0; 0; 7.9756; 0; 0; 0; 0], 4, [t 'mu Pf']);
0073 
0074 t = 'soft limits (satisfied) : ';
0075 mpc = toggle_softlims(mpc, 'on');
0076 t_ok(toggle_softlims(mpc, 'status'), 'toggle_softlims(mpc, ''status'') == 1');
0077 r = runopf(mpc, mpopt);
0078 t_ok(r.success, [t 'success']);
0079 t_ok(isfield(r.softlims, 'overload'), [t 'softlims.overload exists']);
0080 t_ok(isfield(r.softlims, 'overload'), [t 'softlims.ovl_cost exists']);
0081 t_is(r.f, 9126.87, 4, [t 'f']);
0082 t_is(r.gen(:, PG), [12.687; 62.3130; 240], 4, [t 'Pg']);
0083 t_is(r.branch(:, PF), [12.687; -30; -120; 240; 0; 120; 20; -62.3130; 82.3130; -42.687], 4, [t 'Pf']);
0084 t_is(r.branch(:, MU_SF)+r.branch(:, MU_ST), [0; 0; 35.6504; 0; 0; 7.9756; 0; 0; 0; 0], 4, [t 'mu Pf']);
0085 t_is(r.softlims.overload, zeros(10, 1), 12, [t 'softlims.overload']);
0086 t_is(r.softlims.ovl_cost, zeros(10, 1), 12, [t 'softlims.ovl_cost']);
0087 t_is(r.order.branch.status.on(r.order.int.softlims.idx), [3; 6; 8; 9; 10], 12, [t 'mu Pf']);
0088 
0089 t = 'savecase(fname, mpc) : ';
0090 fn = sprintf('softlims_savecase_test_%d', fix(1e8*rand));
0091 savecase(fn, mpc);
0092 mpc1 = loadcase(fn);
0093 delete([fn '.m']);
0094 t_ok(isfield(mpc1, 'softlims'), [t 'mpc.softlims']);
0095 t_ok(isfield(mpc1.softlims, 'idx'), [t 'mpc.softlims.idx']);
0096 t_is(mpc1.softlims.idx, mpc.softlims.idx, 5, [t 'mpc.softlims.idx']);
0097 t_ok(isfield(mpc1.softlims, 'cost'), [t 'mpc.softlims.cost']);
0098 t_is(mpc1.softlims.cost, mpc.softlims.cost, 5, [t 'mpc.softlims.cost']);
0099 
0100 t = 'savecase(fname, results) : ';
0101 fn = sprintf('softlims_savecase_test_%d', fix(1e8*rand));
0102 savecase(fn, r);
0103 mpc1 = loadcase(fn);
0104 delete([fn '.m']);
0105 t_ok(isfield(mpc1, 'softlims'), [t 'results.softlims']);
0106 t_ok(isfield(mpc1.softlims, 'idx'), [t 'results.softlims.idx']);
0107 t_is(mpc1.softlims.idx, r.softlims.idx, 5, [t 'results.softlims.idx']);
0108 t_ok(isfield(mpc1.softlims, 'cost'), [t 'results.softlims.cost']);
0109 t_is(mpc1.softlims.cost, r.softlims.cost, 5, [t 'results.softlims.cost']);
0110 t_ok(isfield(mpc1.softlims, 'overload'), [t 'results.softlims.overload']);
0111 t_is(mpc1.softlims.overload, r.softlims.overload, 5, [t 'results.softlims.overload']);
0112 t_ok(isfield(mpc1.softlims, 'ovl_cost'), [t 'results.softlims.ovl_cost']);
0113 t_is(mpc1.softlims.ovl_cost, r.softlims.ovl_cost, 4, [t 'results.softlims.ovl_cost']);
0114 
0115 t = 'soft limits (violated) : ';
0116 mpc = rmfield(mpc, 'softlims');
0117 mpc.softlims.cost = 20;
0118 r = runopf(mpc, mpopt);
0119 t_ok(r.success, [t 'success']);
0120 t_ok(isfield(r.softlims, 'overload'), [t 'softlims.overload exists']);
0121 t_ok(isfield(r.softlims, 'overload'), [t 'softlims.ovl_cost exists']);
0122 t_is(r.f, 9106.5059, 4, [t 'f']);
0123 t_is(r.gen(:, PG), [10; 63.6988; 241.3012], 4, [t 'Pg']);
0124 t_is(r.branch(:, PF), [10; -31.3012; -121.3012; 241.3012; 0; 120; 20; -63.6988; 83.6988; -41.3012], 4, [t 'Pf']);
0125 t_is(r.branch(:, MU_SF)+r.branch(:, MU_ST), [0; 0; 20; 0; 0; 13.2992; 0; 0; 0; 0], 4, [t 'mu Pf']);
0126 t_is(r.softlims.overload, [0; 0; 1.3011811; 0; 0; 0; 0; 0; 0; 0], 6, [t 'softlims.overload']);
0127 t_is(r.softlims.ovl_cost, [0; 0; 26.023622; 0; 0; 0; 0; 0; 0; 0], 6, [t 'softlims.ovl_cost']);
0128 
0129 t = 'savecase(fname, mpc) : ';
0130 fn = sprintf('softlims_savecase_test_%d', fix(1e8*rand));
0131 savecase(fn, mpc);
0132 mpc1 = loadcase(fn);
0133 delete([fn '.m']);
0134 t_ok(isfield(mpc1, 'softlims'), [t 'mpc.softlims']);
0135 t_ok(~isfield(mpc1.softlims, 'idx'), [t 'mpc.softlims.idx']);
0136 t_ok(isfield(mpc1.softlims, 'cost'), [t 'mpc.softlims.cost']);
0137 t_is(mpc1.softlims.cost, mpc.softlims.cost, 5, [t 'mpc.softlims.cost']);
0138 
0139 t = 'savecase(fname, results) : ';
0140 fn = sprintf('softlims_savecase_test_%d', fix(1e8*rand));
0141 savecase(fn, r);
0142 mpc1 = loadcase(fn);
0143 delete([fn '.m']);
0144 t_ok(isfield(mpc1, 'softlims'), [t 'results.softlims']);
0145 t_ok(isfield(mpc1.softlims, 'idx'), [t 'results.softlims.idx']);
0146 t_ok(isempty(mpc1.softlims.idx), [t 'results.softlims.idx']);
0147 t_ok(isfield(mpc1.softlims, 'cost'), [t 'results.softlims.cost']);
0148 t_is(mpc1.softlims.cost, r.softlims.cost, 5, [t 'results.softlims.cost']);
0149 t_ok(isfield(mpc1.softlims, 'overload'), [t 'results.softlims.overload']);
0150 t_is(mpc1.softlims.overload, r.softlims.overload, 5, [t 'results.softlims.overload']);
0151 t_ok(isfield(mpc1.softlims, 'ovl_cost'), [t 'results.softlims.ovl_cost']);
0152 t_is(mpc1.softlims.ovl_cost, r.softlims.ovl_cost, 4, [t 'results.softlims.ovl_cost']);
0153 
0154 t_end;

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