0001 function t_opf_userfcns(quiet)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 if nargin < 1
0016 quiet = 0;
0017 end
0018
0019 t_begin(51, quiet);
0020
0021 casefile = 't_case30_userfcns';
0022 if quiet
0023 verbose = 0;
0024 else
0025 verbose = 0;
0026 end
0027 mpopt = mpoption('opf.violation', 1e-6, 'mips.gradtol', 1e-8, ...
0028 'mips.comptol', 1e-8, 'mips.costtol', 1e-9);
0029 mpopt = mpoption(mpopt, 'out.all', 0, 'verbose', verbose);
0030 mpopt = mpoption(mpopt, 'opf.ac.solver', 'MIPS', 'opf.dc.solver', 'MIPS');
0031
0032
0033 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0034 TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0035 ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0036 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0037 MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0038 QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0039
0040
0041 t = 'fixed reserves : ';
0042 mpc = loadcase(casefile);
0043 t_ok(~toggle_reserves(mpc, 'status'), 'toggle_reserves(mpc, ''status'') == 0');
0044 mpc = toggle_reserves(mpc, 'on');
0045 t_ok(toggle_reserves(mpc, 'status'), 'toggle_reserves(mpc, ''status'') == 1');
0046 r = runopf(mpc, mpopt);
0047 t_ok(r.success, [t 'success']);
0048 t_is(r.reserves.R, [25; 15; 0; 0; 19.3906; 0.6094], 4, [t 'reserves.R']);
0049 t_is(r.reserves.prc, [2; 2; 2; 2; 5.5; 5.5], 4, [t 'reserves.prc']);
0050 t_is(r.reserves.mu.Pmax, [0; 0; 0; 0; 0.5; 0], 4, [t 'reserves.mu.Pmax']);
0051 t_is(r.reserves.mu.l, [0; 0; 1; 2; 0; 0], 4, [t 'reserves.mu.l']);
0052 t_is(r.reserves.mu.u, [0.1; 0; 0; 0; 0; 0], 4, [t 'reserves.mu.u']);
0053 t_ok(~isfield(r.if, 'P'), [t 'no iflims']);
0054 t_is(r.reserves.totalcost, 177.8047, 4, [t 'totalcost']);
0055
0056 t = 'toggle_reserves(mpc, ''off'') : ';
0057 mpc = toggle_reserves(mpc, 'off');
0058 t_ok(~toggle_reserves(mpc, 'status'), 'toggle_reserves(mpc, ''status'') == 0');
0059 r = runopf(mpc, mpopt);
0060 t_ok(r.success, [t 'success']);
0061 t_ok(~isfield(r.reserves, 'R'), [t 'no reserves']);
0062 t_ok(~isfield(r.if, 'P'), [t 'no iflims']);
0063
0064 t = 'interface flow lims (DC) : ';
0065 mpc = loadcase(casefile);
0066 t_ok(~toggle_iflims(mpc, 'status'), 'toggle_iflims( mpc, ''status'') == 0');
0067 mpc = toggle_iflims(mpc, 'on');
0068 t_ok(toggle_iflims(mpc, 'status'), 'toggle_iflims( mpc, ''status'') == 1');
0069 r = rundcopf(mpc, mpopt);
0070 t_ok(r.success, [t 'success']);
0071 t_is(r.if.P, [-15; 20], 4, [t 'if.P']);
0072 t_is(r.if.mu.l, [0.048427; 0], 6, [t 'if.mu.l']);
0073 t_is(r.if.mu.u, [0; 0.132573], 6, [t 'if.mu.u']);
0074 t_is(r.branch(14, PF), 8.244, 3, [t 'flow in branch 14']);
0075 t_ok(~isfield(r.reserves, 'R'), [t 'no reserves']);
0076
0077 t = 'reserves + interface flow lims (DC) : ';
0078 mpc = loadcase(casefile);
0079 t_ok(~toggle_reserves(mpc, 'status'), 'toggle_reserves(mpc, ''status'') == 0');
0080 t_ok(~toggle_iflims(mpc, 'status'), 'toggle_iflims( mpc, ''status'') == 0');
0081 mpc = toggle_reserves(mpc, 'on');
0082 t_ok(toggle_reserves(mpc, 'status'), 'toggle_reserves(mpc, ''status'') == 1');
0083 t_ok(~toggle_iflims(mpc, 'status'), 'toggle_iflims( mpc, ''status'') == 0');
0084 mpc = toggle_iflims(mpc, 'on');
0085 t_ok(toggle_reserves(mpc, 'status'), 'toggle_reserves(mpc, ''status'') == 1');
0086 t_ok(toggle_iflims(mpc, 'status'), 'toggle_iflims( mpc, ''status'') == 1');
0087 r = rundcopf(mpc, mpopt);
0088 t_ok(r.success, [t 'success']);
0089 t_is(r.if.P, [-15; 20], 4, [t 'if.P']);
0090 t_is(r.if.mu.l, [0.048427; 0], 6, [t 'if.mu.l']);
0091 t_is(r.if.mu.u, [0; 0.382573], 6, [t 'if.mu.u']);
0092 t_is(r.reserves.R, [25; 15; 0; 0; 16.9; 3.1], 4, [t 'reserves.R']);
0093 t_is(r.reserves.prc, [2; 2; 2; 2; 5.5; 5.5], 4, [t 'reserves.prc']);
0094 t_is(r.reserves.mu.Pmax, [0; 0; 0; 0; 0.5; 0], 4, [t 'reserves.mu.Pmax']);
0095 t_is(r.reserves.mu.l, [0; 0; 1; 2; 0; 0], 4, [t 'reserves.mu.l']);
0096 t_is(r.reserves.mu.u, [0.1; 0; 0; 0; 0; 0], 4, [t 'reserves.mu.u']);
0097 t_is(r.reserves.totalcost, 179.05, 4, [t 'totalcost']);
0098
0099 t = 'interface flow lims (AC) : ';
0100 mpc = toggle_reserves(mpc, 'off');
0101 t_ok(~toggle_reserves(mpc, 'status'), 'toggle_reserves(mpc, ''status'') == 0');
0102 t_ok(toggle_iflims(mpc, 'status'), 'toggle_iflims( mpc, ''status'') == 1');
0103 r = runopf(mpc, mpopt);
0104 t_ok(r.success, [t 'success']);
0105 t_is(r.if.P, [-9.101; 21.432], 3, [t 'if.P']);
0106 t_is(r.if.mu.l, [0; 0], 6, [t 'if.mu.l']);
0107 t_is(r.if.mu.u, [0; 0.10198], 5, [t 'if.mu.u']);
0108 t_ok(~isfield(r.reserves, 'R'), [t 'no reserves']);
0109
0110 t = 'interface flow lims (line out) : ';
0111 mpc = loadcase(casefile);
0112 mpc = toggle_iflims(mpc, 'on');
0113 mpc.branch(12, BR_STATUS) = 0;
0114 r = rundcopf(mpc, mpopt);
0115 t_ok(r.success, [t 'success']);
0116 t_is(r.if.P, [-15; 20], 4, [t 'if.P']);
0117 t_is(r.if.mu.l, [0.048427; 0], 6, [t 'if.mu.l']);
0118 t_is(r.if.mu.u, [0; 0.132573], 6, [t 'if.mu.u']);
0119 t_is(r.branch(14, PF), 10.814, 3, [t 'flow in branch 14']);
0120 t_ok(~isfield(r.reserves, 'R'), [t 'no reserves']);
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133 t_end;