0001 function res = t_cpf(quiet)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 if nargin < 1
0015 quiet = 0;
0016 end
0017
0018 num_tests = 81;
0019 t_begin(num_tests, quiet);
0020
0021 if have_fcn('matlab', 'vnum') < 7.001
0022 t_skip(num_tests, 'RUNCPF requires cellfun() construct not available before Matlab 7.1');
0023 else
0024 plot_nose_curve = 0;
0025 verbose = 0;
0026
0027 casefile = 't_case9_pfv2';
0028 if have_fcn('octave')
0029 if have_fcn('octave', 'vnum') >= 4
0030 file_in_path_warn_id = 'Octave:data-file-in-path';
0031 else
0032 file_in_path_warn_id = 'Octave:load-file-in-path';
0033 end
0034 s1 = warning('query', file_in_path_warn_id);
0035 warning('off', file_in_path_warn_id);
0036 end
0037 mpopt = mpoption('out.all', 0, 'verbose', verbose);
0038
0039 mpopt = mpoption(mpopt, 'cpf.step', 0.02);
0040
0041
0042 mpopt = mpoption(mpopt, 'cpf.plot.level', plot_nose_curve);
0043
0044
0045
0046 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0047 VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0048 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0049 TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0050 ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0051 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0052 MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0053 QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0054
0055
0056 mpcb = loadcase(casefile);
0057
0058 mpcb.bus = [mpcb.bus(1:3, :); mpcb.bus(3, :); mpcb.bus(4:end, :)];
0059 mpcb.bus(4, BUS_I) = 50;
0060 mpcb.bus(4, BUS_TYPE) = NONE;
0061
0062
0063 mpct = mpcb;
0064 factor = 2.5;
0065 mpct.gen(:, [PG QG]) = mpct.gen(:, [PG QG]) * factor;
0066 mpct.bus(:, [PD QD]) = mpct.bus(:, [PD QD]) * factor;
0067
0068
0069 t = 'Continuation PF to lambda = 0.7 (natural) : ';
0070 mpopt = mpoption(mpopt, 'cpf.stop_at', 0.7, 'cpf.parameterization', 1);
0071 r = runcpf(mpcb, mpct, mpopt);
0072 iterations = 35;
0073 t_ok(r.success, [t 'success']);
0074 t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0075 t_is(r.cpf.max_lam, 0.7, 12, [t 'max_lam']);
0076 t_is(size(r.cpf.V_p), [10 iterations+1], 12, [t 'size(V_p)']);
0077 t_is(size(r.cpf.V_c), [10 iterations+1], 12, [t 'size(V_c)']);
0078 t_is(size(r.cpf.lam_p), [1 iterations+1], 12, [t 'size(lam_p)']);
0079 t_is(size(r.cpf.lam_c), [1 iterations+1], 12, [t 'size(lam_c)']);
0080
0081 t = 'Continuation PF to lambda = 0.7 (arc length) : ';
0082 mpopt = mpoption(mpopt, 'cpf.stop_at', 0.7, 'cpf.parameterization', 2);
0083 r = runcpf(mpcb, mpct, mpopt);
0084 iterations = 41;
0085 t_ok(r.success, [t 'success']);
0086 t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0087 t_is(r.cpf.max_lam, 0.7, 12, [t 'max_lam']);
0088 t_is(size(r.cpf.V_p), [10 iterations+1], 12, [t 'size(V_p)']);
0089 t_is(size(r.cpf.V_c), [10 iterations+1], 12, [t 'size(V_c)']);
0090 t_is(size(r.cpf.lam_p), [1 iterations+1], 12, [t 'size(lam_p)']);
0091 t_is(size(r.cpf.lam_c), [1 iterations+1], 12, [t 'size(lam_c)']);
0092
0093 t = 'Continuation PF to lambda = 0.7 (pseudo arc length) : ';
0094 mpopt = mpoption(mpopt, 'cpf.stop_at', 0.7, 'cpf.parameterization', 3);
0095 r = runcpf(mpcb, mpct, mpopt);
0096 iterations = 41;
0097 t_ok(r.success, [t 'success']);
0098 t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0099 t_is(r.cpf.max_lam, 0.7, 12, [t 'max_lam']);
0100 t_is(size(r.cpf.V_p), [10 iterations+1], 12, [t 'size(V_p)']);
0101 t_is(size(r.cpf.V_c), [10 iterations+1], 12, [t 'size(V_c)']);
0102 t_is(size(r.cpf.lam_p), [1 iterations+1], 12, [t 'size(lam_p)']);
0103 t_is(size(r.cpf.lam_c), [1 iterations+1], 12, [t 'size(lam_c)']);
0104
0105 t = 'Continuation PF to nose point (arc length) : ';
0106 mpopt = mpoption(mpopt, 'cpf.stop_at', 'NOSE', 'cpf.parameterization', 2);
0107 mpopt = mpoption(mpopt, 'cpf.adapt_step', 1);
0108 r = runcpf(mpcb, mpct, mpopt);
0109 iterations = 22;
0110 t_ok(r.success, [t 'success']);
0111 t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0112 t_is(r.cpf.max_lam, 0.99025, 3, [t 'max_lam']);
0113 t_is(size(r.cpf.V_p), [10 iterations+1], 12, [t 'size(V_p)']);
0114 t_is(size(r.cpf.V_c), [10 iterations+1], 12, [t 'size(V_c)']);
0115 t_is(size(r.cpf.lam_p), [1 iterations+1], 12, [t 'size(lam_p)']);
0116 t_is(size(r.cpf.lam_c), [1 iterations+1], 12, [t 'size(lam_c)']);
0117
0118 t = 'Continuation PF to nose point (pseudo arc length) : ';
0119 mpopt = mpoption(mpopt, 'cpf.stop_at', 'NOSE', 'cpf.parameterization', 3);
0120 mpopt = mpoption(mpopt, 'cpf.adapt_step', 1);
0121 r = runcpf(mpcb, mpct, mpopt);
0122 iterations = 22;
0123 t_ok(r.success, [t 'success']);
0124 t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0125 t_is(r.cpf.max_lam, 0.99025, 3, [t 'max_lam']);
0126 t_is(size(r.cpf.V_p), [10 iterations+1], 12, [t 'size(V_p)']);
0127 t_is(size(r.cpf.V_c), [10 iterations+1], 12, [t 'size(V_c)']);
0128 t_is(size(r.cpf.lam_p), [1 iterations+1], 12, [t 'size(lam_p)']);
0129 t_is(size(r.cpf.lam_c), [1 iterations+1], 12, [t 'size(lam_c)']);
0130
0131 t = 'Continuation PF (full trace) (arc length) : ';
0132 mpopt = mpoption(mpopt, 'cpf.stop_at', 'FULL', 'cpf.parameterization', 2);
0133 r = runcpf(mpcb, mpct, mpopt);
0134 iterations = 45;
0135 t_ok(r.success, [t 'success']);
0136 t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0137 t_is(r.cpf.max_lam, 0.99025, 3, [t 'max_lam']);
0138 t_is(size(r.cpf.V_p), [10 iterations+1], 12, [t 'size(V_p)']);
0139 t_is(size(r.cpf.V_c), [10 iterations+1], 12, [t 'size(V_c)']);
0140 t_is(size(r.cpf.lam_p), [1 iterations+1], 12, [t 'size(lam_p)']);
0141 t_is(size(r.cpf.lam_c), [1 iterations+1], 12, [t 'size(lam_c)']);
0142
0143 t = 'Continuation PF (full trace) (pseudo arc length) : ';
0144 mpopt = mpoption(mpopt, 'cpf.stop_at', 'FULL', 'cpf.parameterization', 3);
0145 r = runcpf(mpcb, mpct, mpopt);
0146 iterations = 45;
0147 t_ok(r.success, [t 'success']);
0148 t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0149 t_is(r.cpf.max_lam, 0.99025, 3, [t 'max_lam']);
0150 t_is(size(r.cpf.V_p), [10 iterations+1], 12, [t 'size(V_p)']);
0151 t_is(size(r.cpf.V_c), [10 iterations+1], 12, [t 'size(V_c)']);
0152 t_is(size(r.cpf.lam_p), [1 iterations+1], 12, [t 'size(lam_p)']);
0153 t_is(size(r.cpf.lam_c), [1 iterations+1], 12, [t 'size(lam_c)']);
0154
0155 t = '1 user callback : ';
0156 mpopt = mpoption(mpopt, 'cpf.stop_at', 0.7, 'cpf.parameterization', 3);
0157 mpopt = mpoption(mpopt, 'cpf.adapt_step', 1);
0158 mpopt = mpoption(mpopt, 'cpf.user_callback', 't_cpf_cb1');
0159 r = runcpf(mpcb, mpct, mpopt);
0160 iterations = 7;
0161 t_ok(r.success, [t 'success']);
0162 t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0163 t_is(r.cpf.max_lam, 0.7, 12, [t 'max_lam']);
0164 t_is(size(r.cpf.lam_c), [1 iterations+1], 12, [t 'size(lam_c)']);
0165 t_ok(isfield(r.cpf, 'cb1'), [t 'isfield cpf.cb1']);
0166 t_ok(isstruct(r.cpf.cb1), [t 'isstruct cpf.cb1']);
0167 t_ok(isfield(r.cpf.cb1, 'initial'), [t 'isfield cpf.cb1.initial']);
0168 t_ok(isfield(r.cpf.cb1, 'iteration'), [t 'isfield cpf.cb1.iteration']);
0169 t_ok(isfield(r.cpf.cb1, 'final'), [t 'isfield cpf.cb1.final']);
0170 t_is(r.cpf.cb1.initial, 1, 12, [t 'r.cpf.cb1.initial']);
0171 t_is(r.cpf.cb1.iteration, iterations, 12, [t 'r.cpf.cb1.iterations']);
0172 t_is(r.cpf.cb1.final, 1, 12, [t 'r.cpf.cb1.final']);
0173
0174 t = '2 user callbacks (with args) : ';
0175 mpopt = mpoption(mpopt, 'cpf.user_callback', {'t_cpf_cb1', 't_cpf_cb2'});
0176 cb_args = struct('cb2', struct('initial', 20, 'iteration', 2, 'final', 200));
0177 mpopt = mpoption(mpopt, 'cpf.user_callback_args', cb_args);
0178 r = runcpf(mpcb, mpct, mpopt);
0179 iterations = 7;
0180 t_ok(r.success, [t 'success']);
0181 t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0182 t_is(r.cpf.max_lam, 0.7, 12, [t 'max_lam']);
0183 t_is(size(r.cpf.lam_c), [1 iterations+1], 12, [t 'size(lam_c)']);
0184 t_ok(isfield(r.cpf, 'cb1'), [t 'isfield cpf.cb1']);
0185 t_ok(isstruct(r.cpf.cb1), [t 'isstruct cpf.cb1']);
0186 t_ok(isfield(r.cpf.cb1, 'initial'), [t 'isfield cpf.cb1.initial']);
0187 t_ok(isfield(r.cpf.cb1, 'iteration'), [t 'isfield cpf.cb1.iteration']);
0188 t_ok(isfield(r.cpf.cb1, 'final'), [t 'isfield cpf.cb1.final']);
0189 t_is(r.cpf.cb1.initial, 1, 12, [t 'r.cpf.cb1.initial']);
0190 t_is(r.cpf.cb1.iteration, iterations, 12, [t 'r.cpf.cb1.iterations']);
0191 t_is(r.cpf.cb1.final, 1, 12, [t 'r.cpf.cb1.final']);
0192 t_ok(isfield(r.cpf, 'cb2'), [t 'isfield cpf.cb2']);
0193 t_ok(isstruct(r.cpf.cb2), [t 'isstruct cpf.cb2']);
0194 t_ok(isfield(r.cpf.cb2, 'initial'), [t 'isfield cpf.cb2.initial']);
0195 t_ok(isfield(r.cpf.cb2, 'iteration'), [t 'isfield cpf.cb2.iteration']);
0196 t_ok(isfield(r.cpf.cb2, 'final'), [t 'isfield cpf.cb2.final']);
0197 t_is(r.cpf.cb2.initial, 20, 12, [t 'r.cpf.cb2.initial']);
0198 t_is(r.cpf.cb2.iteration, 2*iterations, 12, [t 'r.cpf.cb2.iterations']);
0199 t_is(r.cpf.cb2.final, 200, 12, [t 'r.cpf.cb2.final']);
0200
0201 if have_fcn('octave')
0202 warning(s1.state, file_in_path_warn_id);
0203 end
0204 end
0205
0206 t_end;
0207
0208 if nargout
0209 res = r;
0210 end