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