Home > matpower6.0 > t > t_cpf.m

t_cpf

PURPOSE ^

T_CPF Tests for continuation power flow.

SYNOPSIS ^

function res = t_cpf(quiet)

DESCRIPTION ^

T_CPF  Tests for continuation power flow.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function res = t_cpf(quiet)
0002 %T_CPF  Tests for continuation power flow.
0003 
0004 %   MATPOWER
0005 %   Copyright (c) 2013-2016, Power Systems Engineering Research Center (PSERC)
0006 %   by Ray Zimmerman, PSERC Cornell
0007 %
0008 %   This file is part of MATPOWER.
0009 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0010 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0011 
0012 if nargin < 1
0013     quiet = 0;
0014 end
0015 
0016 num_tests = 298;
0017 t_begin(num_tests, quiet);
0018 
0019 if have_fcn('matlab', 'vnum') < 7.001
0020     t_skip(num_tests, 'RUNCPF requires cellfun() construct not available before Matlab 7.1');
0021 else
0022     plot_nose_curve = 0;
0023     verbose = 0;
0024 
0025     casefile = 't_case9_pfv2';
0026     if have_fcn('octave')
0027         if have_fcn('octave', 'vnum') >= 4
0028             file_in_path_warn_id = 'Octave:data-file-in-path';
0029         else
0030             file_in_path_warn_id = 'Octave:load-file-in-path';
0031         end
0032         s1 = warning('query', file_in_path_warn_id);
0033         warning('off', file_in_path_warn_id);
0034     end
0035     mpopt = mpoption('out.all', 0, 'verbose', verbose);
0036     %mpopt = mpoption(mpopt, 'cpf.stop_at', 'FULL', );
0037     mpopt = mpoption(mpopt, 'cpf.step', 0.02);
0038     %mpopt = mpoption(mpopt, 'cpf.adapt_step', 1);
0039     %mpopt = mpoption(mpopt, 'cpf.adapt_step_damping', 1);
0040     %mpopt = mpoption(mpopt, 'cpf.adapt_step_tol', 2e-5);
0041     mpopt = mpoption(mpopt, 'cpf.plot.level', plot_nose_curve);
0042     %mpopt = mpoption(mpopt, 'cpf.plot.bus', 9);
0043     %mpopt = mpoption(mpopt, 'pf.tol', 1e-10);
0044     %mpopt = mpoption(mpopt, 'verbose', 3);
0045 
0046     %% define named indices into bus, gen, branch matrices
0047     [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0048         VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0049     [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0050         TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0051         ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0052     [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0053         MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0054         QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0055 
0056     %% set up base and target cases
0057     mpcb = loadcase(casefile);
0058     %% add isolated bus to make sure int2ext works for V_hat, V
0059     mpcb.bus = [mpcb.bus(1:3, :); mpcb.bus(3, :); mpcb.bus(4:end, :)];
0060     mpcb.bus(4, BUS_I) = 50;
0061     mpcb.bus(4, BUS_TYPE) = NONE;
0062     mpcb.gen(1, QMAX) = 200;    %% decrease a Q lim
0063     % r = runpf(mpcb, mpopt);
0064     % mpcb.gen(1, [PG QG]) = r.gen(1, [PG QG]); %% solved values for slack gen
0065     mpct = mpcb;
0066     factor = 2.5;
0067     mpct.gen(:, [PG QG]) = mpct.gen(:, [PG QG]) * factor;
0068     mpct.bus(:, [PD QD]) = mpct.bus(:, [PD QD]) * factor;
0069 
0070     %% run CPF
0071     t = 'CPF to lambda = 0.7 (natural) : ';
0072     mpopt = mpoption(mpopt, 'cpf.stop_at', 0.7, 'cpf.parameterization', 1);
0073     r = runcpf(mpcb, mpct, mpopt);
0074     iterations = 35;
0075     t_ok(r.success, [t 'success']);
0076     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0077     t_is(r.cpf.max_lam, 0.7, 12, [t 'max_lam']);
0078     t_is(size(r.cpf.V_hat), [10 iterations+1], 12, [t 'size(V_hat)']);
0079     t_is(size(r.cpf.V), [10 iterations+1], 12, [t 'size(V)']);
0080     t_is(size(r.cpf.lam_hat), [1 iterations+1], 12, [t 'size(lam_hat)']);
0081     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0082     t_ok(strfind(r.cpf.done_msg, 'Reached desired lambda 0.7'), [t 'done_msg']);
0083     t_is(length(r.cpf.events), 1, 12, [t 'size(events) == 1']);
0084     t_is(r.cpf.events(1).k, iterations, 12, [t 'events(1).k']);
0085     t_is(r.cpf.events(1).idx, 1, 12, [t 'events(1).idx']);
0086     t_ok(strcmp(r.cpf.events(1).name, 'TARGET_LAM'), [t 'events(1).name']);
0087 
0088     t = 'CPF to lambda = 0.7 (arc length) : ';
0089     mpopt = mpoption(mpopt, 'cpf.stop_at', 0.7, 'cpf.parameterization', 2);
0090     r = runcpf(mpcb, mpct, mpopt);
0091     iterations = 41;
0092     t_ok(r.success, [t 'success']);
0093     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0094     t_is(r.cpf.max_lam, 0.7, 12, [t 'max_lam']);
0095     t_is(size(r.cpf.V_hat), [10 iterations+1], 12, [t 'size(V_hat)']);
0096     t_is(size(r.cpf.V), [10 iterations+1], 12, [t 'size(V)']);
0097     t_is(size(r.cpf.lam_hat), [1 iterations+1], 12, [t 'size(lam_hat)']);
0098     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0099     t_ok(strfind(r.cpf.done_msg, 'Reached desired lambda 0.7'), [t 'done_msg']);
0100     t_is(length(r.cpf.events), 1, 12, [t 'size(events) == 1']);
0101     t_is(r.cpf.events(1).k, iterations, 12, [t 'events(1).k']);
0102     t_is(r.cpf.events(1).idx, 1, 12, [t 'events(1).idx']);
0103     t_ok(strcmp(r.cpf.events(1).name, 'TARGET_LAM'), [t 'events(1).name']);
0104 
0105     t = 'CPF to lambda = 0.7 (pseudo arc length) : ';
0106     mpopt = mpoption(mpopt, 'cpf.stop_at', 0.7, 'cpf.parameterization', 3);
0107     r = runcpf(mpcb, mpct, mpopt);
0108     iterations = 41;
0109     t_ok(r.success, [t 'success']);
0110     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0111     t_is(r.cpf.max_lam, 0.7, 12, [t 'max_lam']);
0112     t_is(size(r.cpf.V_hat), [10 iterations+1], 12, [t 'size(V_hat)']);
0113     t_is(size(r.cpf.V), [10 iterations+1], 12, [t 'size(V)']);
0114     t_is(size(r.cpf.lam_hat), [1 iterations+1], 12, [t 'size(lam_hat)']);
0115     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0116     t_ok(strfind(r.cpf.done_msg, 'Reached desired lambda 0.7'), [t 'done_msg']);
0117     t_is(length(r.cpf.events), 1, 12, [t 'size(events) == 1']);
0118     t_is(r.cpf.events(1).k, iterations, 12, [t 'events(1).k']);
0119     t_is(r.cpf.events(1).idx, 1, 12, [t 'events(1).idx']);
0120     t_ok(strcmp(r.cpf.events(1).name, 'TARGET_LAM'), [t 'events(1).name']);
0121 
0122     t = 'CPF to nose pt (arc length) : ';
0123     mpopt = mpoption(mpopt, 'cpf.stop_at', 'NOSE', 'cpf.parameterization', 2);
0124     mpopt = mpoption(mpopt, 'cpf.adapt_step', 1);
0125     r = runcpf(mpcb, mpct, mpopt);
0126     iterations = 23;
0127     t_ok(r.success, [t 'success']);
0128     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0129     t_is(r.cpf.max_lam, 0.99025, 3, [t 'max_lam']);
0130     t_is(size(r.cpf.V_hat), [10 iterations+1], 12, [t 'size(V_hat)']);
0131     t_is(size(r.cpf.V), [10 iterations+1], 12, [t 'size(V)']);
0132     t_is(size(r.cpf.lam_hat), [1 iterations+1], 12, [t 'size(lam_hat)']);
0133     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0134     t_ok(strfind(r.cpf.done_msg, 'Reached steady state loading limit'), [t 'done_msg']);
0135     t_is(length(r.cpf.events), 1, 12, [t 'size(events) == 1']);
0136     t_is(r.cpf.events(1).k, iterations, 12, [t 'events(1).k']);
0137     t_is(r.cpf.events(1).idx, 1, 12, [t 'events(1).idx']);
0138     t_ok(strcmp(r.cpf.events(1).name, 'NOSE'), [t 'events(1).name']);
0139 
0140     t = 'CPF to nose pt (pseudo arc length) : ';
0141     mpopt = mpoption(mpopt, 'cpf.stop_at', 'NOSE', 'cpf.parameterization', 3);
0142     mpopt = mpoption(mpopt, 'cpf.adapt_step', 1);
0143     r = runcpf(mpcb, mpct, mpopt);
0144     iterations = 23;
0145     t_ok(r.success, [t 'success']);
0146     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0147     t_is(r.cpf.max_lam, 0.99025, 3, [t 'max_lam']);
0148     t_is(size(r.cpf.V_hat), [10 iterations+1], 12, [t 'size(V_hat)']);
0149     t_is(size(r.cpf.V), [10 iterations+1], 12, [t 'size(V)']);
0150     t_is(size(r.cpf.lam_hat), [1 iterations+1], 12, [t 'size(lam_hat)']);
0151     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0152     t_ok(strfind(r.cpf.done_msg, 'Reached steady state loading limit'), [t 'done_msg']);
0153     t_is(length(r.cpf.events), 1, 12, [t 'size(events) == 1']);
0154     t_is(r.cpf.events(1).k, iterations, 12, [t 'events(1).k']);
0155     t_is(r.cpf.events(1).idx, 1, 12, [t 'events(1).idx']);
0156     t_ok(strcmp(r.cpf.events(1).name, 'NOSE'), [t 'events(1).name']);
0157 
0158     t = 'CPF to nose pt (pseudo arc length) w/Q lims: ';
0159     mpopt_qlim = mpoption(mpopt, 'cpf.stop_at', 'NOSE', 'cpf.parameterization', 3,'cpf.enforce_q_lims',1);
0160     mpopt_qlim = mpoption(mpopt_qlim, 'cpf.adapt_step', 1);
0161 %mpopt_qlim = mpoption(mpopt_qlim, 'verbose', 3);
0162     r = runcpf(mpcb, mpct, mpopt_qlim);
0163     iterations = 19;
0164     t_ok(r.success, [t 'success']);
0165     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0166     t_is(r.cpf.max_lam, 0.795809, 6, [t 'max_lam']);
0167     t_is(size(r.cpf.V_hat), [10 iterations+1], 12, [t 'size(V_hat)']);
0168     t_is(size(r.cpf.V), [10 iterations+1], 12, [t 'size(V)']);
0169     t_is(size(r.cpf.lam_hat), [1 iterations+1], 12, [t 'size(lam_hat)']);
0170     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0171     t_ok(strfind(r.cpf.done_msg, 'Reached steady state loading limit'), [t 'done_msg']);
0172     ek = [12 iterations];
0173     eidx = [1 1];
0174     ename = {'QLIM', 'NOSE'};
0175     ne = length(ek);
0176     t_is(length(r.cpf.events), ne, 12, sprintf('%ssize(events) == %d', t, ne));
0177     for j = 1:ne
0178         t_is(r.cpf.events(j).k, ek(j), 12, sprintf('%sevents(%d).k == %d', t, j, ek(j)));
0179         t_is(r.cpf.events(j).idx, eidx(j), 12, sprintf('%sevents(%d).idx == %d', t, j, eidx(j)));
0180         t_ok(strcmp(r.cpf.events(j).name, ename{j}), sprintf('%sevents(%d).name = ''%s''', t, j, ename{j}));
0181     end
0182     
0183     t = 'CPF to nose pt (pseudo arc length) w/P lims: ';
0184     mpopt_plim = mpoption(mpopt, 'cpf.stop_at', 'NOSE', 'cpf.parameterization', 3,'cpf.enforce_p_lims',1);
0185     mpopt_plim = mpoption(mpopt_plim, 'cpf.adapt_step', 1);
0186 %mpopt_plim = mpoption(mpopt_plim, 'verbose', 3);
0187     r = runcpf(mpcb, mpct, mpopt_plim);
0188     iterations = 21;
0189     t_ok(r.success, [t 'success']);
0190     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0191     t_is(r.cpf.max_lam, 0.97975, 4, [t 'max_lam']);
0192     t_is(size(r.cpf.V_hat), [10 iterations+1], 12, [t 'size(V_hat)']);
0193     t_is(size(r.cpf.V), [10 iterations+1], 12, [t 'size(V)']);
0194     t_is(size(r.cpf.lam_hat), [1 iterations+1], 12, [t 'size(lam_hat)']);
0195     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0196     t_ok(strcmp(r.cpf.done_msg, 'All generators at Pmax'), [t 'done_msg']);
0197     ek = [7 13 iterations];
0198     eidx = [2 1 3];
0199     ename = {'PLIM', 'PLIM', 'PLIM'};
0200     ne = length(ek);
0201     t_is(length(r.cpf.events), ne, 12, sprintf('%ssize(events) == %d', t, ne));
0202     for j = 1:ne
0203         t_is(r.cpf.events(j).k, ek(j), 12, sprintf('%sevents(%d).k == %d', t, j, ek(j)));
0204         t_is(r.cpf.events(j).idx, eidx(j), 12, sprintf('%sevents(%d).idx == %d', t, j, eidx(j)));
0205         t_ok(strcmp(r.cpf.events(j).name, ename{j}), sprintf('%sevents(%d).name = ''%s''', t, j, ename{j}));
0206     end
0207     
0208     t = 'CPF to nose pt (pseudo arc length) w/PQ lims: ';
0209     mpopt_pqlim = mpoption(mpopt, 'cpf.stop_at', 'NOSE', 'cpf.parameterization', 3,'cpf.enforce_q_lims',1,'cpf.enforce_p_lims',1);
0210     mpopt_pqlim = mpoption(mpopt_pqlim, 'cpf.adapt_step', 1);
0211 %mpopt_pqlim = mpoption(mpopt_pqlim, 'verbose', 3);
0212     r = runcpf(mpcb, mpct, mpopt_pqlim);
0213     iterations = 20;
0214     t_ok(r.success, [t 'success']);
0215     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0216     t_is(r.cpf.max_lam, 0.833343, 3, [t 'max_lam']);
0217     t_is(size(r.cpf.V_hat), [10 iterations+1], 12, [t 'size(V_hat)']);
0218     t_is(size(r.cpf.V), [10 iterations+1], 12, [t 'size(V)']);
0219     t_is(size(r.cpf.lam_hat), [1 iterations+1], 12, [t 'size(lam_hat)']);
0220     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0221     t_ok(strfind(r.cpf.done_msg, 'Reached steady state loading limit'), [t 'done_msg']);
0222     ek = [7 14 iterations];
0223     eidx = [2 1 1];
0224     ename = {'PLIM', 'QLIM', 'NOSE'};
0225     ne = length(ek);
0226     t_is(length(r.cpf.events), ne, 12, sprintf('%ssize(events) == %d', t, ne));
0227     for j = 1:ne
0228         t_is(r.cpf.events(j).k, ek(j), 12, sprintf('%sevents(%d).k == %d', t, j, ek(j)));
0229         t_is(r.cpf.events(j).idx, eidx(j), 12, sprintf('%sevents(%d).idx == %d', t, j, eidx(j)));
0230         t_ok(strcmp(r.cpf.events(j).name, ename{j}), sprintf('%sevents(%d).name = ''%s''', t, j, ename{j}));
0231     end
0232 
0233     t = 'CPF (full trace) (arc length) : ';
0234     mpopt = mpoption(mpopt, 'cpf.stop_at', 'FULL', 'cpf.parameterization', 2);
0235     r = runcpf(mpcb, mpct, mpopt);
0236     iterations = 47;
0237     t_ok(r.success, [t 'success']);
0238     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0239     t_is(r.cpf.max_lam, 0.99025, 3, [t 'max_lam']);
0240     t_is(size(r.cpf.V_hat), [10 iterations+1], 12, [t 'size(V_hat)']);
0241     t_is(size(r.cpf.V), [10 iterations+1], 12, [t 'size(V)']);
0242     t_is(size(r.cpf.lam_hat), [1 iterations+1], 12, [t 'size(lam_hat)']);
0243     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0244     t_ok(strfind(r.cpf.done_msg, 'Traced full continuation curve in'), [t 'done_msg']);
0245     t_is(length(r.cpf.events), 1, 12, [t 'size(events) == 1']);
0246     t_is(r.cpf.events(1).k, iterations, 12, [t 'events(1).k']);
0247     t_is(r.cpf.events(1).idx, 1, 12, [t 'events(1).idx']);
0248     t_ok(strcmp(r.cpf.events(1).name, 'TARGET_LAM'), [t 'events(1).name']);
0249 
0250     t = 'CPF (full trace) (pseudo arc length) : ';
0251     mpopt = mpoption(mpopt, 'cpf.stop_at', 'FULL', 'cpf.parameterization', 3);
0252     r = runcpf(mpcb, mpct, mpopt);
0253     iterations = 47;
0254     t_ok(r.success, [t 'success']);
0255     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0256     t_is(r.cpf.max_lam, 0.99025, 3, [t 'max_lam']);
0257     t_is(size(r.cpf.V_hat), [10 iterations+1], 12, [t 'size(V_hat)']);
0258     t_is(size(r.cpf.V), [10 iterations+1], 12, [t 'size(V)']);
0259     t_is(size(r.cpf.lam_hat), [1 iterations+1], 12, [t 'size(lam_hat)']);
0260     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0261     t_ok(strfind(r.cpf.done_msg, 'Traced full continuation curve in'), [t 'done_msg']);
0262     t_is(length(r.cpf.events), 1, 12, [t 'size(events) == 1']);
0263     t_is(r.cpf.events(1).k, iterations, 12, [t 'events(1).k']);
0264     t_is(r.cpf.events(1).idx, 1, 12, [t 'events(1).idx']);
0265     t_ok(strcmp(r.cpf.events(1).name, 'TARGET_LAM'), [t 'events(1).name']);
0266 
0267     t = 'CPF (full trace) (pseudo arc length) w/Q lims: ';
0268     mpopt_qlim = mpoption(mpopt, 'cpf.stop_at', 'FULL', 'cpf.parameterization', 3,'cpf.enforce_q_lims',1);
0269     mpopt_qlim = mpoption(mpopt_qlim, 'cpf.adapt_step', 1);
0270 %mpopt_qlim = mpoption(mpopt_qlim, 'verbose', 3);
0271     r = runcpf(mpcb, mpct, mpopt_qlim);
0272     iterations = 43;
0273     t_ok(r.success, [t 'success']);
0274     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0275     t_is(r.cpf.max_lam, 0.795759, 6, [t 'max_lam']);
0276     t_is(size(r.cpf.V_hat), [10 iterations+1], 12, [t 'size(V_hat)']);
0277     t_is(size(r.cpf.V), [10 iterations+1], 12, [t 'size(V)']);
0278     t_is(size(r.cpf.lam_hat), [1 iterations+1], 12, [t 'size(lam_hat)']);
0279     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0280     t_ok(strcmp(r.cpf.done_msg, 'No REF or PV buses remaining.'), [t 'done_msg']);
0281     ek = [12 22 iterations];
0282     eidx = [1 2 3];
0283     ename = {'QLIM', 'QLIM', 'QLIM'};
0284     ne = length(ek);
0285     t_is(length(r.cpf.events), ne, 12, sprintf('%ssize(events) == %d', t, ne));
0286     for j = 1:ne
0287         t_is(r.cpf.events(j).k, ek(j), 12, sprintf('%sevents(%d).k == %d', t, j, ek(j)));
0288         t_is(r.cpf.events(j).idx, eidx(j), 12, sprintf('%sevents(%d).idx == %d', t, j, eidx(j)));
0289         t_ok(strcmp(r.cpf.events(j).name, ename{j}), sprintf('%sevents(%d).name = ''%s''', t, j, ename{j}));
0290     end
0291 
0292     t = '1 user callback : ';
0293     mpopt = mpoption(mpopt, 'cpf.stop_at', 0.7, 'cpf.parameterization', 3);
0294     mpopt = mpoption(mpopt, 'cpf.adapt_step', 1);
0295     mpopt = mpoption(mpopt, 'cpf.user_callback', 't_cpf_cb1');
0296     r = runcpf(mpcb, mpct, mpopt);
0297     iterations = 9;
0298     t_ok(r.success, [t 'success']);
0299     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0300     t_is(r.cpf.max_lam, 0.7, 12, [t 'max_lam']);
0301     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0302     t_ok(strfind(r.cpf.done_msg, 'Reached desired lambda 0.7'), [t 'done_msg']);
0303     t_is(length(r.cpf.events), 1, 12, [t 'size(events) == 1']);
0304     t_is(r.cpf.events(1).k, iterations, 12, [t 'events(1).k']);
0305     t_is(r.cpf.events(1).idx, 1, 12, [t 'events(1).idx']);
0306     t_ok(strcmp(r.cpf.events(1).name, 'TARGET_LAM'), [t 'events(1).name']);
0307     t_ok(isfield(r.cpf, 'cb1'), [t 'isfield cpf.cb1']);
0308     t_ok(isstruct(r.cpf.cb1), [t 'isstruct cpf.cb1']);
0309     t_ok(isfield(r.cpf.cb1, 'initial'), [t 'isfield cpf.cb1.initial']);
0310     t_ok(isfield(r.cpf.cb1, 'iteration'), [t 'isfield cpf.cb1.iteration']);
0311     t_ok(isfield(r.cpf.cb1, 'final'), [t 'isfield cpf.cb1.final']);
0312     t_is(r.cpf.cb1.initial, 1, 12, [t 'r.cpf.cb1.initial']);
0313     t_is(r.cpf.cb1.iteration, iterations, 12, [t 'r.cpf.cb1.iterations']);
0314     t_is(r.cpf.cb1.final, 1, 12, [t 'r.cpf.cb1.final']);
0315     t_ok(strcmp(r.cpf.shared, '1111111111'), [t 'r.cpf.shared']);
0316 
0317     t = '1 user callback : ';
0318     cb1 = struct('fcn', 't_cpf_cb1', 'priority', 10);
0319     mpopt = mpoption(mpopt, 'cpf.stop_at', 0.7, 'cpf.parameterization', 3);
0320     mpopt = mpoption(mpopt, 'cpf.adapt_step', 1);
0321     mpopt = mpoption(mpopt, 'cpf.user_callback', cb1);
0322     r = runcpf(mpcb, mpct, mpopt);
0323     iterations = 9;
0324     t_ok(r.success, [t 'success']);
0325     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0326     t_is(r.cpf.max_lam, 0.7, 12, [t 'max_lam']);
0327     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0328     t_ok(strfind(r.cpf.done_msg, 'Reached desired lambda 0.7'), [t 'done_msg']);
0329     t_is(length(r.cpf.events), 1, 12, [t 'size(events) == 1']);
0330     t_is(r.cpf.events(1).k, iterations, 12, [t 'events(1).k']);
0331     t_is(r.cpf.events(1).idx, 1, 12, [t 'events(1).idx']);
0332     t_ok(strcmp(r.cpf.events(1).name, 'TARGET_LAM'), [t 'events(1).name']);
0333     t_ok(isfield(r.cpf, 'cb1'), [t 'isfield cpf.cb1']);
0334     t_ok(isstruct(r.cpf.cb1), [t 'isstruct cpf.cb1']);
0335     t_ok(isfield(r.cpf.cb1, 'initial'), [t 'isfield cpf.cb1.initial']);
0336     t_ok(isfield(r.cpf.cb1, 'iteration'), [t 'isfield cpf.cb1.iteration']);
0337     t_ok(isfield(r.cpf.cb1, 'final'), [t 'isfield cpf.cb1.final']);
0338     t_is(r.cpf.cb1.initial, 1, 12, [t 'r.cpf.cb1.initial']);
0339     t_is(r.cpf.cb1.iteration, iterations, 12, [t 'r.cpf.cb1.iterations']);
0340     t_is(r.cpf.cb1.final, 1, 12, [t 'r.cpf.cb1.final']);
0341     t_ok(strcmp(r.cpf.shared, '1111111111'), [t 'r.cpf.shared']);
0342 
0343     t = '2 user callbacks (with args) : ';
0344     cb_args = struct('initial', 20, 'iteration', 2, 'final', 200);
0345     cb2 = struct('fcn', 't_cpf_cb2', 'args', cb_args);
0346     mpopt = mpoption(mpopt, 'cpf.user_callback', {'t_cpf_cb1', cb2});
0347     r = runcpf(mpcb, mpct, mpopt);
0348     iterations = 9;
0349     t_ok(r.success, [t 'success']);
0350     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0351     t_is(r.cpf.max_lam, 0.7, 12, [t 'max_lam']);
0352     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0353     t_ok(strfind(r.cpf.done_msg, 'Reached desired lambda 0.7'), [t 'done_msg']);
0354     t_is(length(r.cpf.events), 1, 12, [t 'size(events) == 1']);
0355     t_is(r.cpf.events(1).k, iterations, 12, [t 'events(1).k']);
0356     t_is(r.cpf.events(1).idx, 1, 12, [t 'events(1).idx']);
0357     t_ok(strcmp(r.cpf.events(1).name, 'TARGET_LAM'), [t 'events(1).name']);
0358     t_ok(isfield(r.cpf, 'cb1'), [t 'isfield cpf.cb1']);
0359     t_ok(isstruct(r.cpf.cb1), [t 'isstruct cpf.cb1']);
0360     t_ok(isfield(r.cpf.cb1, 'initial'), [t 'isfield cpf.cb1.initial']);
0361     t_ok(isfield(r.cpf.cb1, 'iteration'), [t 'isfield cpf.cb1.iteration']);
0362     t_ok(isfield(r.cpf.cb1, 'final'), [t 'isfield cpf.cb1.final']);
0363     t_is(r.cpf.cb1.initial, 1, 12, [t 'r.cpf.cb1.initial']);
0364     t_is(r.cpf.cb1.iteration, iterations, 12, [t 'r.cpf.cb1.iterations']);
0365     t_is(r.cpf.cb1.final, 1, 12, [t 'r.cpf.cb1.final']);
0366     t_ok(isfield(r.cpf, 'cb2'), [t 'isfield cpf.cb2']);
0367     t_ok(isstruct(r.cpf.cb2), [t 'isstruct cpf.cb2']);
0368     t_ok(isfield(r.cpf.cb2, 'initial'), [t 'isfield cpf.cb2.initial']);
0369     t_ok(isfield(r.cpf.cb2, 'iteration'), [t 'isfield cpf.cb2.iteration']);
0370     t_ok(isfield(r.cpf.cb2, 'final'), [t 'isfield cpf.cb2.final']);
0371     t_is(r.cpf.cb2.initial, 20, 12, [t 'r.cpf.cb2.initial']);
0372     t_is(r.cpf.cb2.iteration, 2*iterations, 12, [t 'r.cpf.cb2.iterations']);
0373     t_is(r.cpf.cb2.final, 200, 12, [t 'r.cpf.cb2.final']);
0374     t_ok(strcmp(r.cpf.shared, '12121212121212121212'), [t 'r.cpf.shared']);
0375 
0376     t = '2 user callbacks (with priority & args) : ';
0377     cb_args = struct('initial', 20, 'iteration', 2, 'final', 200);
0378     cb2 = struct('fcn', 't_cpf_cb2', 'priority', 21, 'args', cb_args);
0379     mpopt = mpoption(mpopt, 'cpf.user_callback', {'t_cpf_cb1', cb2});
0380     r = runcpf(mpcb, mpct, mpopt);
0381     iterations = 9;
0382     t_ok(r.success, [t 'success']);
0383     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0384     t_is(r.cpf.max_lam, 0.7, 12, [t 'max_lam']);
0385     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0386     t_ok(strfind(r.cpf.done_msg, 'Reached desired lambda 0.7'), [t 'done_msg']);
0387     t_is(length(r.cpf.events), 1, 12, [t 'size(events) == 1']);
0388     t_is(r.cpf.events(1).k, iterations, 12, [t 'events(1).k']);
0389     t_is(r.cpf.events(1).idx, 1, 12, [t 'events(1).idx']);
0390     t_ok(strcmp(r.cpf.events(1).name, 'TARGET_LAM'), [t 'events(1).name']);
0391     t_ok(isfield(r.cpf, 'cb1'), [t 'isfield cpf.cb1']);
0392     t_ok(isstruct(r.cpf.cb1), [t 'isstruct cpf.cb1']);
0393     t_ok(isfield(r.cpf.cb1, 'initial'), [t 'isfield cpf.cb1.initial']);
0394     t_ok(isfield(r.cpf.cb1, 'iteration'), [t 'isfield cpf.cb1.iteration']);
0395     t_ok(isfield(r.cpf.cb1, 'final'), [t 'isfield cpf.cb1.final']);
0396     t_is(r.cpf.cb1.initial, 1, 12, [t 'r.cpf.cb1.initial']);
0397     t_is(r.cpf.cb1.iteration, iterations, 12, [t 'r.cpf.cb1.iterations']);
0398     t_is(r.cpf.cb1.final, 1, 12, [t 'r.cpf.cb1.final']);
0399     t_ok(isfield(r.cpf, 'cb2'), [t 'isfield cpf.cb2']);
0400     t_ok(isstruct(r.cpf.cb2), [t 'isstruct cpf.cb2']);
0401     t_ok(isfield(r.cpf.cb2, 'initial'), [t 'isfield cpf.cb2.initial']);
0402     t_ok(isfield(r.cpf.cb2, 'iteration'), [t 'isfield cpf.cb2.iteration']);
0403     t_ok(isfield(r.cpf.cb2, 'final'), [t 'isfield cpf.cb2.final']);
0404     t_is(r.cpf.cb2.initial, 20, 12, [t 'r.cpf.cb2.initial']);
0405     t_is(r.cpf.cb2.iteration, 2*iterations, 12, [t 'r.cpf.cb2.iterations']);
0406     t_is(r.cpf.cb2.final, 200, 12, [t 'r.cpf.cb2.final']);
0407     t_ok(strcmp(r.cpf.shared, '21212121212121212121'), [t 'r.cpf.shared']);
0408 
0409     t = 'case300 w/Q lims : ';
0410     mpopt = mpoption('out.all', 0, 'verbose', verbose);
0411     mpopt = mpoption(mpopt, 'cpf.stop_at', 'FULL', 'cpf.step', 0.1);
0412     mpopt = mpoption(mpopt, 'cpf.step_max', 0.2);
0413     mpopt = mpoption(mpopt, 'cpf.adapt_step', 0);
0414     mpopt = mpoption(mpopt, 'cpf.enforce_q_lims', 1);
0415     mpcb = loadcase('case300');                         % load base case
0416     mpct = mpcb;                                        % set up target case with
0417     mpct.gen(:, [PG QG]) = mpcb.gen(:, [PG QG]) * 2.5;  % increased generation
0418     mpct.bus(:, [PD QD]) = mpcb.bus(:, [PD QD]) * 2.5;  % and increased load
0419 
0420     r = runcpf(mpcb, mpct, mpopt);
0421     iterations = 41;
0422     t_ok(r.success, [t 'success']);
0423     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0424     t_is(r.cpf.max_lam, 0.03326947, 6, [t 'max_lam']);
0425     t_is(size(r.cpf.V_hat), [300 iterations+1], 12, [t 'size(V_hat)']);
0426     t_is(size(r.cpf.V), [300 iterations+1], 12, [t 'size(V)']);
0427     t_is(size(r.cpf.lam_hat), [1 iterations+1], 12, [t 'size(lam_hat)']);
0428     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0429     t_ok(strfind(r.cpf.done_msg, 'Traced full continuation curve in'), [t 'done_msg']);
0430     ek = [1 3 5 12 14 16 18 21 23 27 36 39 41];
0431     eidx = [26 19 67 59 15 69 50 54 66 68 87 89 1];
0432     ename = {'QLIM', 'QLIM', 'QLIM', 'QLIM', 'QLIM', 'QLIM', 'QLIM', 'QLIM', 'QLIM', 'QLIM', 'QLIM', 'QLIM', 'TARGET_LAM'};
0433     ne = length(ek);
0434     t_is(length(r.cpf.events), ne, 12, sprintf('%ssize(events) == %d', t, ne));
0435     for j = 1:ne
0436         t_is(r.cpf.events(j).k, ek(j), 12, sprintf('%sevents(%d).k == %d', t, j, ek(j)));
0437         t_is(r.cpf.events(j).idx, eidx(j), 12, sprintf('%sevents(%d).idx == %d', t, j, eidx(j)));
0438         t_ok(strcmp(r.cpf.events(j).name, ename{j}), sprintf('%sevents(%d).name = ''%s''', t, j, ename{j}));
0439     end
0440 
0441     t = 'case14 (unsuccessful) : ';
0442     mpopt = mpoption(mpopt, 'cpf.adapt_step', 1);
0443     mpopt = mpoption(mpopt, 'cpf.enforce_q_lims', 0);
0444     mpcb = loadcase('case14');                          % load base case
0445     mpct = mpcb;                                        % set up target case with
0446     mpct.gen(:, [PG QG]) = mpcb.gen(:, [PG QG]) * 2.5;  % increased generation
0447     mpct.bus(:, [PD QD]) = mpcb.bus(:, [PD QD]) * 2.5;  % and increased load
0448 
0449     r = runcpf(mpcb, mpct, mpopt);
0450     iterations = 79;
0451     t_ok(~r.success, [t 'success']);
0452     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0453     t_is(r.cpf.max_lam, 2.0401678, 6, [t 'max_lam']);
0454     t_is(size(r.cpf.V_hat), [14 iterations+1], 12, [t 'size(V_hat)']);
0455     t_is(size(r.cpf.V), [14 iterations+1], 12, [t 'size(V)']);
0456     t_is(size(r.cpf.lam_hat), [1 iterations+1], 12, [t 'size(lam_hat)']);
0457     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0458     t_ok(strfind(r.cpf.done_msg, 'Corrector did not converge in'), [t 'done_msg']);
0459     t_is(length(r.cpf.events), 0, 12, [t 'size(events) == 0']);
0460 
0461     if have_fcn('octave')
0462         warning(s1.state, file_in_path_warn_id);
0463     end
0464 end
0465 
0466 t_end;
0467 
0468 if nargout
0469     res = r;
0470 end

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