Home > matpower7.1 > lib > 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 https://matpower.org for more info.
0011 
0012 if nargin < 1
0013     quiet = 0;
0014 end
0015 
0016 num_tests = 366;
0017 t_begin(num_tests, quiet);
0018 
0019 if have_feature('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_feature('octave')
0027         if have_feature('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 = 'base == target : ';
0072     r = runcpf(mpcb, mpcb, mpopt);
0073     iterations = 1;
0074     t_ok(r.success, [t 'success']);
0075     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0076     t_is(r.cpf.max_lam, 0, 12, [t 'max_lam']);
0077     t_is(size(r.cpf.V_hat), [10 1], 12, [t 'size(V_hat)']);
0078     t_is(size(r.cpf.V), [10 1], 12, [t 'size(V)']);
0079     t_is(size(r.cpf.lam_hat), [1 1], 12, [t 'size(lam_hat)']);
0080     t_is(size(r.cpf.lam), [1 1], 12, [t 'size(lam)']);
0081     t_ok(strfind(r.cpf.done_msg, 'Base case and target case have identical load and generation'), [t 'done_msg']);
0082     t_is(length(r.cpf.events), 0, 12, [t 'length(events) == 0']);
0083 
0084     t = 'CPF to lambda = 0.7 (natural) : ';
0085     mpopt = mpoption(mpopt, 'cpf.stop_at', 0.7, 'cpf.parameterization', 1);
0086     r = runcpf(mpcb, mpct, mpopt);
0087     iterations = 35;
0088     t_ok(r.success, [t 'success']);
0089     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0090     t_is(r.cpf.max_lam, 0.7, 12, [t 'max_lam']);
0091     t_is(size(r.cpf.V_hat), [10 iterations+1], 12, [t 'size(V_hat)']);
0092     t_is(size(r.cpf.V), [10 iterations+1], 12, [t 'size(V)']);
0093     t_is(size(r.cpf.lam_hat), [1 iterations+1], 12, [t 'size(lam_hat)']);
0094     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0095     t_ok(strfind(r.cpf.done_msg, 'Reached desired lambda 0.7'), [t 'done_msg']);
0096     t_is(length(r.cpf.events), 1, 12, [t 'length(events) == 1']);
0097     t_is(r.cpf.events(1).k, iterations, 12, [t 'events(1).k']);
0098     t_is(r.cpf.events(1).idx, 1, 12, [t 'events(1).idx']);
0099     t_ok(strcmp(r.cpf.events(1).name, 'TARGET_LAM'), [t 'events(1).name']);
0100 
0101     t = 'CPF to lambda = 0.7 (arc length) : ';
0102     mpopt = mpoption(mpopt, 'cpf.stop_at', 0.7, 'cpf.parameterization', 2);
0103     r = runcpf(mpcb, mpct, mpopt);
0104     iterations = 41;
0105     t_ok(r.success, [t 'success']);
0106     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0107     t_is(r.cpf.max_lam, 0.7, 12, [t 'max_lam']);
0108     t_is(size(r.cpf.V_hat), [10 iterations+1], 12, [t 'size(V_hat)']);
0109     t_is(size(r.cpf.V), [10 iterations+1], 12, [t 'size(V)']);
0110     t_is(size(r.cpf.lam_hat), [1 iterations+1], 12, [t 'size(lam_hat)']);
0111     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0112     t_ok(strfind(r.cpf.done_msg, 'Reached desired lambda 0.7'), [t 'done_msg']);
0113     t_is(length(r.cpf.events), 1, 12, [t 'length(events) == 1']);
0114     t_is(r.cpf.events(1).k, iterations, 12, [t 'events(1).k']);
0115     t_is(r.cpf.events(1).idx, 1, 12, [t 'events(1).idx']);
0116     t_ok(strcmp(r.cpf.events(1).name, 'TARGET_LAM'), [t 'events(1).name']);
0117 
0118     t = 'CPF to lambda = 0.7 (pseudo arc length) : ';
0119     mpopt = mpoption(mpopt, 'cpf.stop_at', 0.7, 'cpf.parameterization', 3);
0120     r = runcpf(mpcb, mpct, mpopt);
0121     iterations = 41;
0122     t_ok(r.success, [t 'success']);
0123     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0124     t_is(r.cpf.max_lam, 0.7, 12, [t 'max_lam']);
0125     t_is(size(r.cpf.V_hat), [10 iterations+1], 12, [t 'size(V_hat)']);
0126     t_is(size(r.cpf.V), [10 iterations+1], 12, [t 'size(V)']);
0127     t_is(size(r.cpf.lam_hat), [1 iterations+1], 12, [t 'size(lam_hat)']);
0128     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0129     t_ok(strfind(r.cpf.done_msg, 'Reached desired lambda 0.7'), [t 'done_msg']);
0130     t_is(length(r.cpf.events), 1, 12, [t 'length(events) == 1']);
0131     t_is(r.cpf.events(1).k, iterations, 12, [t 'events(1).k']);
0132     t_is(r.cpf.events(1).idx, 1, 12, [t 'events(1).idx']);
0133     t_ok(strcmp(r.cpf.events(1).name, 'TARGET_LAM'), [t 'events(1).name']);
0134 
0135     t = 'CPF to nose pt (arc length) : ';
0136     mpopt = mpoption(mpopt, 'cpf.stop_at', 'NOSE', 'cpf.parameterization', 2);
0137     mpopt = mpoption(mpopt, 'cpf.adapt_step', 1);
0138     r = runcpf(mpcb, mpct, mpopt);
0139     iterations = 23;
0140     t_ok(r.success, [t 'success']);
0141     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0142     t_is(r.cpf.max_lam, 0.99025, 3, [t 'max_lam']);
0143     t_is(size(r.cpf.V_hat), [10 iterations+1], 12, [t 'size(V_hat)']);
0144     t_is(size(r.cpf.V), [10 iterations+1], 12, [t 'size(V)']);
0145     t_is(size(r.cpf.lam_hat), [1 iterations+1], 12, [t 'size(lam_hat)']);
0146     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0147     t_ok(strfind(r.cpf.done_msg, 'Reached steady state loading limit'), [t 'done_msg']);
0148     t_is(length(r.cpf.events), 1, 12, [t 'length(events) == 1']);
0149     t_is(r.cpf.events(1).k, iterations, 12, [t 'events(1).k']);
0150     t_is(r.cpf.events(1).idx, 1, 12, [t 'events(1).idx']);
0151     t_ok(strcmp(r.cpf.events(1).name, 'NOSE'), [t 'events(1).name']);
0152 
0153     t = 'CPF to nose pt (pseudo arc length) : ';
0154     mpopt = mpoption(mpopt, 'cpf.stop_at', 'NOSE', 'cpf.parameterization', 3);
0155     mpopt = mpoption(mpopt, 'cpf.adapt_step', 1);
0156     r = runcpf(mpcb, mpct, mpopt);
0157     iterations = 23;
0158     t_ok(r.success, [t 'success']);
0159     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0160     t_is(r.cpf.max_lam, 0.99025, 3, [t 'max_lam']);
0161     t_is(size(r.cpf.V_hat), [10 iterations+1], 12, [t 'size(V_hat)']);
0162     t_is(size(r.cpf.V), [10 iterations+1], 12, [t 'size(V)']);
0163     t_is(size(r.cpf.lam_hat), [1 iterations+1], 12, [t 'size(lam_hat)']);
0164     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0165     t_ok(strfind(r.cpf.done_msg, 'Reached steady state loading limit'), [t 'done_msg']);
0166     t_is(length(r.cpf.events), 1, 12, [t 'length(events) == 1']);
0167     t_is(r.cpf.events(1).k, iterations, 12, [t 'events(1).k']);
0168     t_is(r.cpf.events(1).idx, 1, 12, [t 'events(1).idx']);
0169     t_ok(strcmp(r.cpf.events(1).name, 'NOSE'), [t 'events(1).name']);
0170 
0171     t = 'CPF to nose pt (pseudo arc length) w/Q lims: ';
0172     mpopt_qlim = mpoption(mpopt, 'cpf.stop_at', 'NOSE', 'cpf.parameterization', 3,'cpf.enforce_q_lims',1);
0173     mpopt_qlim = mpoption(mpopt_qlim, 'cpf.adapt_step', 1);
0174     r = runcpf(mpcb, mpct, mpopt_qlim);
0175     iterations = 19;
0176     t_ok(r.success, [t 'success']);
0177     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0178     t_is(r.cpf.max_lam, 0.795809, 6, [t 'max_lam']);
0179     t_is(size(r.cpf.V_hat), [10 iterations+1], 12, [t 'size(V_hat)']);
0180     t_is(size(r.cpf.V), [10 iterations+1], 12, [t 'size(V)']);
0181     t_is(size(r.cpf.lam_hat), [1 iterations+1], 12, [t 'size(lam_hat)']);
0182     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0183     t_ok(strfind(r.cpf.done_msg, 'Reached steady state loading limit'), [t 'done_msg']);
0184     ek = [12 iterations];
0185     eidx = [1 1];
0186     ename = {'QLIM', 'NOSE'};
0187     ne = length(ek);
0188     t_is(length(r.cpf.events), ne, 12, sprintf('%ssize(events) == %d', t, ne));
0189     for j = 1:ne
0190         t_is(r.cpf.events(j).k, ek(j), 12, sprintf('%sevents(%d).k == %d', t, j, ek(j)));
0191         t_is(r.cpf.events(j).idx, eidx(j), 12, sprintf('%sevents(%d).idx == %d', t, j, eidx(j)));
0192         t_ok(strcmp(r.cpf.events(j).name, ename{j}), sprintf('%sevents(%d).name = ''%s''', t, j, ename{j}));
0193     end
0194     
0195     t = 'CPF to nose pt (pseudo arc length) w/P lims: ';
0196     mpopt_plim = mpoption(mpopt, 'cpf.stop_at', 'NOSE', 'cpf.parameterization', 3,'cpf.enforce_p_lims',1);
0197     mpopt_plim = mpoption(mpopt_plim, 'cpf.adapt_step', 1);
0198     r = runcpf(mpcb, mpct, mpopt_plim);
0199     iterations = 21;
0200     t_ok(r.success, [t 'success']);
0201     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0202     t_is(r.cpf.max_lam, 0.97975, 4, [t 'max_lam']);
0203     t_is(size(r.cpf.V_hat), [10 iterations+1], 12, [t 'size(V_hat)']);
0204     t_is(size(r.cpf.V), [10 iterations+1], 12, [t 'size(V)']);
0205     t_is(size(r.cpf.lam_hat), [1 iterations+1], 12, [t 'size(lam_hat)']);
0206     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0207     t_ok(strcmp(r.cpf.done_msg, 'All generators at Pmax'), [t 'done_msg']);
0208     ek = [7 13 iterations];
0209     eidx = [3 1 2];
0210     ename = {'PLIM', 'PLIM', 'PLIM'};
0211     ne = length(ek);
0212     t_is(length(r.cpf.events), ne, 12, sprintf('%ssize(events) == %d', t, ne));
0213     for j = 1:ne
0214         t_is(r.cpf.events(j).k, ek(j), 12, sprintf('%sevents(%d).k == %d', t, j, ek(j)));
0215         t_is(r.cpf.events(j).idx, eidx(j), 12, sprintf('%sevents(%d).idx == %d', t, j, eidx(j)));
0216         t_ok(strcmp(r.cpf.events(j).name, ename{j}), sprintf('%sevents(%d).name = ''%s''', t, j, ename{j}));
0217     end
0218     
0219     t = 'CPF to nose pt (pseudo arc length) w/flow lims: ';
0220     mpopt_flowlim = mpoption(mpopt, 'cpf.stop_at', 'NOSE', 'cpf.parameterization', 3,'cpf.enforce_flow_lims',1);
0221     mpopt_flowlim = mpoption(mpopt_flowlim, 'cpf.adapt_step', 1);
0222     r = runcpf(mpcb, mpct, mpopt_flowlim);
0223     iterations = 3;
0224     t_ok(r.success, [t 'success']);
0225     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0226     t_is(r.cpf.max_lam, 0.110684, 6, [t 'max_lam']);
0227     t_is(size(r.cpf.V_hat), [10 iterations+1], 12, [t 'size(V_hat)']);
0228     t_is(size(r.cpf.V), [10 iterations+1], 12, [t 'size(V)']);
0229     t_is(size(r.cpf.lam_hat), [1 iterations+1], 12, [t 'size(lam_hat)']);
0230     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0231     t_ok(strfind(r.cpf.done_msg, 'branch flow limit reached'), [t 'done_msg']);
0232     t_is(length(r.cpf.events), 1, 12, [t 'length(events) == 1']);
0233     t_is(r.cpf.events(1).k, iterations, 12, [t 'events(1).k']);
0234     t_is(r.cpf.events(1).idx, 5, 12, [t 'events(1).idx']);
0235     t_ok(strcmp(r.cpf.events(1).name, 'FLIM'), [t 'events(1).name']);
0236     
0237     t = 'CPF to nose pt (pseudo arc length) w/violated flow lims: ';
0238     mpopt_flowlim = mpoption(mpopt, 'cpf.stop_at', 'NOSE', 'cpf.parameterization', 3,'cpf.enforce_flow_lims',1);
0239     mpopt_flowlim = mpoption(mpopt_flowlim, 'cpf.adapt_step', 1);
0240     mpcb1 = mpcb;
0241     mpcb1.branch(1, RATE_A) = 75;
0242     r = runcpf(mpcb1, mpct, mpopt_flowlim);
0243     iterations = 1;
0244     t_ok(r.success, [t 'success']);
0245     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0246     t_is(r.cpf.max_lam, 0, 6, [t 'max_lam']);
0247     t_is(size(r.cpf.V_hat), [10 iterations], 12, [t 'size(V_hat)']);
0248     t_is(size(r.cpf.V), [10 iterations], 12, [t 'size(V)']);
0249     t_is(size(r.cpf.lam_hat), [1 iterations], 12, [t 'size(lam_hat)']);
0250     t_is(size(r.cpf.lam), [1 iterations], 12, [t 'size(lam)']);
0251     t_ok(strfind(r.cpf.done_msg, 'branch flow limit violated in base case'), [t 'done_msg']);
0252     t_is(length(r.cpf.events), 0, 12, [t 'length(events) == 0']);
0253     
0254     t = 'CPF to nose pt (pseudo arc length) w/V lims: ';
0255     mpopt_vlim = mpoption(mpopt, 'cpf.stop_at', 'NOSE', 'cpf.parameterization', 3,'cpf.enforce_v_lims',1);
0256     mpopt_vlim = mpoption(mpopt_vlim, 'cpf.adapt_step', 1);
0257     r = runcpf(mpcb, mpct, mpopt_vlim);
0258     iterations = 6;
0259     t_ok(r.success, [t 'success']);
0260     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0261     t_is(r.cpf.max_lam, 0.316932, 6, [t 'max_lam']);
0262     t_is(size(r.cpf.V_hat), [10 iterations+1], 12, [t 'size(V_hat)']);
0263     t_is(size(r.cpf.V), [10 iterations+1], 12, [t 'size(V)']);
0264     t_is(size(r.cpf.lam_hat), [1 iterations+1], 12, [t 'size(lam_hat)']);
0265     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0266     t_ok(strfind(r.cpf.done_msg, 'bus voltage magnitude limit reached'), [t 'done_msg']);
0267     t_is(length(r.cpf.events), 1, 12, [t 'length(events) == 1']);
0268     t_is(r.cpf.events(1).k, iterations, 12, [t 'events(1).k']);
0269     t_is(r.cpf.events(1).idx, 9, 12, [t 'events(1).idx']);
0270     t_ok(strcmp(r.cpf.events(1).name, 'VLIM'), [t 'events(1).name']);
0271     
0272     t = 'CPF to nose pt (pseudo arc length) w/violated V lims: ';
0273     mpopt_vlim = mpoption(mpopt, 'cpf.stop_at', 'NOSE', 'cpf.parameterization', 3,'cpf.enforce_v_lims',1);
0274     mpopt_vlim = mpoption(mpopt_vlim, 'cpf.adapt_step', 1);
0275     mpcb1 = mpcb;
0276     mpcb1.bus(6, VMIN) = 0.98;
0277     r = runcpf(mpcb1, mpct, mpopt_vlim);
0278     iterations = 1;
0279     t_ok(r.success, [t 'success']);
0280     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0281     t_is(r.cpf.max_lam, 0, 6, [t 'max_lam']);
0282     t_is(size(r.cpf.V_hat), [10 iterations], 12, [t 'size(V_hat)']);
0283     t_is(size(r.cpf.V), [10 iterations], 12, [t 'size(V)']);
0284     t_is(size(r.cpf.lam_hat), [1 iterations], 12, [t 'size(lam_hat)']);
0285     t_is(size(r.cpf.lam), [1 iterations], 12, [t 'size(lam)']);
0286     t_ok(strfind(r.cpf.done_msg, 'bus voltage magnitude limit violated in base case'), [t 'done_msg']);
0287     t_is(length(r.cpf.events), 0, 12, [t 'length(events) == 0']);
0288     
0289     t = 'CPF to nose pt (pseudo arc length) w/V+flow lims: ';
0290     mpopt_vlim = mpoption(mpopt, 'cpf.stop_at', 'NOSE', 'cpf.parameterization', 3,'cpf.enforce_v_lims',1,'cpf.enforce_flow_lims',1);
0291     mpopt_vlim = mpoption(mpopt_vlim, 'cpf.adapt_step', 1);
0292     r = runcpf(mpcb, mpct, mpopt_vlim);
0293     iterations = 3;
0294     t_ok(r.success, [t 'success']);
0295     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0296     t_is(r.cpf.max_lam, 0.110684, 6, [t 'max_lam']);
0297     t_is(size(r.cpf.V_hat), [10 iterations+1], 12, [t 'size(V_hat)']);
0298     t_is(size(r.cpf.V), [10 iterations+1], 12, [t 'size(V)']);
0299     t_is(size(r.cpf.lam_hat), [1 iterations+1], 12, [t 'size(lam_hat)']);
0300     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0301     t_ok(strfind(r.cpf.done_msg, 'branch flow limit reached'), [t 'done_msg']);
0302     t_is(length(r.cpf.events), 1, 12, [t 'length(events) == 1']);
0303     t_is(r.cpf.events(1).k, iterations, 12, [t 'events(1).k']);
0304     t_is(r.cpf.events(1).idx, 5, 12, [t 'events(1).idx']);
0305     t_ok(strcmp(r.cpf.events(1).name, 'FLIM'), [t 'events(1).name']);
0306     
0307     t = 'CPF to nose pt (pseudo arc length) w/PQ lims: ';
0308     mpopt_pqlim = mpoption(mpopt, 'cpf.stop_at', 'NOSE', 'cpf.parameterization', 3,'cpf.enforce_q_lims',1,'cpf.enforce_p_lims',1);
0309     mpopt_pqlim = mpoption(mpopt_pqlim, 'cpf.adapt_step', 1);
0310     r = runcpf(mpcb, mpct, mpopt_pqlim);
0311     iterations = 20;
0312     t_ok(r.success, [t 'success']);
0313     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0314     t_is(r.cpf.max_lam, 0.833343, 3, [t 'max_lam']);
0315     t_is(size(r.cpf.V_hat), [10 iterations+1], 12, [t 'size(V_hat)']);
0316     t_is(size(r.cpf.V), [10 iterations+1], 12, [t 'size(V)']);
0317     t_is(size(r.cpf.lam_hat), [1 iterations+1], 12, [t 'size(lam_hat)']);
0318     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0319     t_ok(strfind(r.cpf.done_msg, 'Reached steady state loading limit'), [t 'done_msg']);
0320     ek = [7 14 iterations];
0321     eidx = [3 1 1];
0322     ename = {'PLIM', 'QLIM', 'NOSE'};
0323     ne = length(ek);
0324     t_is(length(r.cpf.events), ne, 12, sprintf('%ssize(events) == %d', t, ne));
0325     for j = 1:ne
0326         t_is(r.cpf.events(j).k, ek(j), 12, sprintf('%sevents(%d).k == %d', t, j, ek(j)));
0327         t_is(r.cpf.events(j).idx, eidx(j), 12, sprintf('%sevents(%d).idx == %d', t, j, eidx(j)));
0328         t_ok(strcmp(r.cpf.events(j).name, ename{j}), sprintf('%sevents(%d).name = ''%s''', t, j, ename{j}));
0329     end
0330 
0331     t = 'CPF (full trace) (arc length) : ';
0332     mpopt = mpoption(mpopt, 'cpf.stop_at', 'FULL', 'cpf.parameterization', 2);
0333     r = runcpf(mpcb, mpct, mpopt);
0334     iterations = 47;
0335     t_ok(r.success, [t 'success']);
0336     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0337     t_is(r.cpf.max_lam, 0.99025, 3, [t 'max_lam']);
0338     t_is(size(r.cpf.V_hat), [10 iterations+1], 12, [t 'size(V_hat)']);
0339     t_is(size(r.cpf.V), [10 iterations+1], 12, [t 'size(V)']);
0340     t_is(size(r.cpf.lam_hat), [1 iterations+1], 12, [t 'size(lam_hat)']);
0341     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0342     t_ok(strfind(r.cpf.done_msg, 'Traced full continuation curve in'), [t 'done_msg']);
0343     t_is(length(r.cpf.events), 1, 12, [t 'length(events) == 1']);
0344     t_is(r.cpf.events(1).k, iterations, 12, [t 'events(1).k']);
0345     t_is(r.cpf.events(1).idx, 1, 12, [t 'events(1).idx']);
0346     t_ok(strcmp(r.cpf.events(1).name, 'TARGET_LAM'), [t 'events(1).name']);
0347 
0348     t = 'CPF (full trace) (pseudo arc length) : ';
0349     mpopt = mpoption(mpopt, 'cpf.stop_at', 'FULL', 'cpf.parameterization', 3);
0350     r = runcpf(mpcb, mpct, mpopt);
0351     iterations = 47;
0352     t_ok(r.success, [t 'success']);
0353     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0354     t_is(r.cpf.max_lam, 0.99025, 3, [t 'max_lam']);
0355     t_is(size(r.cpf.V_hat), [10 iterations+1], 12, [t 'size(V_hat)']);
0356     t_is(size(r.cpf.V), [10 iterations+1], 12, [t 'size(V)']);
0357     t_is(size(r.cpf.lam_hat), [1 iterations+1], 12, [t 'size(lam_hat)']);
0358     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0359     t_ok(strfind(r.cpf.done_msg, 'Traced full continuation curve in'), [t 'done_msg']);
0360     t_is(length(r.cpf.events), 1, 12, [t 'length(events) == 1']);
0361     t_is(r.cpf.events(1).k, iterations, 12, [t 'events(1).k']);
0362     t_is(r.cpf.events(1).idx, 1, 12, [t 'events(1).idx']);
0363     t_ok(strcmp(r.cpf.events(1).name, 'TARGET_LAM'), [t 'events(1).name']);
0364 
0365     t = 'CPF (full trace) (pseudo arc length) w/Q lims: ';
0366     mpopt_qlim = mpoption(mpopt, 'cpf.stop_at', 'FULL', 'cpf.parameterization', 3,'cpf.enforce_q_lims',1);
0367     mpopt_qlim = mpoption(mpopt_qlim, 'cpf.adapt_step', 1);
0368     r = runcpf(mpcb, mpct, mpopt_qlim);
0369     iterations = 43;
0370     t_ok(r.success, [t 'success']);
0371     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0372     t_is(r.cpf.max_lam, 0.795759, 6, [t 'max_lam']);
0373     t_is(size(r.cpf.V_hat), [10 iterations+1], 12, [t 'size(V_hat)']);
0374     t_is(size(r.cpf.V), [10 iterations+1], 12, [t 'size(V)']);
0375     t_is(size(r.cpf.lam_hat), [1 iterations+1], 12, [t 'size(lam_hat)']);
0376     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0377     t_ok(strcmp(r.cpf.done_msg, 'No REF or PV buses remaining.'), [t 'done_msg']);
0378     ek = [12 22 iterations];
0379     eidx = [1 3 2];
0380     ename = {'QLIM', 'QLIM', 'QLIM'};
0381     ne = length(ek);
0382     t_is(length(r.cpf.events), ne, 12, sprintf('%ssize(events) == %d', t, ne));
0383     for j = 1:ne
0384         t_is(r.cpf.events(j).k, ek(j), 12, sprintf('%sevents(%d).k == %d', t, j, ek(j)));
0385         t_is(r.cpf.events(j).idx, eidx(j), 12, sprintf('%sevents(%d).idx == %d', t, j, eidx(j)));
0386         t_ok(strcmp(r.cpf.events(j).name, ename{j}), sprintf('%sevents(%d).name = ''%s''', t, j, ename{j}));
0387     end
0388 
0389     t = 'bug #12 : early termination : ';
0390     mpcbx = mpcb;
0391     mpctx = mpct;
0392     mpcbx.gen(1, QMAX) = 24.07;
0393     mpctx.gen(1, QMAX) = 24.07;
0394     r = runcpf(mpcbx, mpctx, mpopt_qlim);
0395     iterations = 38;
0396     t_ok(r.success, [t 'success']);
0397     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0398 
0399     t = 'all buses isolated : ';
0400     mpcbx.bus(:, BUS_TYPE) = NONE;
0401     try
0402         r = runcpf(mpcbx, mpctx, mpopt);
0403         t_is(r.success, 0, 12, [t 'success = 0']);
0404     catch
0405         t_ok(0, [t 'unexpected fatal error']);
0406     end
0407 
0408     t = '1 user callback : ';
0409     mpopt = mpoption(mpopt, 'cpf.stop_at', 0.7, 'cpf.parameterization', 3);
0410     mpopt = mpoption(mpopt, 'cpf.adapt_step', 1);
0411     mpopt = mpoption(mpopt, 'cpf.user_callback', 't_cpf_cb1');
0412     r = runcpf(mpcb, mpct, mpopt);
0413     iterations = 9;
0414     t_ok(r.success, [t 'success']);
0415     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0416     t_is(r.cpf.max_lam, 0.7, 12, [t 'max_lam']);
0417     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0418     t_ok(strfind(r.cpf.done_msg, 'Reached desired lambda 0.7'), [t 'done_msg']);
0419     t_is(length(r.cpf.events), 1, 12, [t 'length(events) == 1']);
0420     t_is(r.cpf.events(1).k, iterations, 12, [t 'events(1).k']);
0421     t_is(r.cpf.events(1).idx, 1, 12, [t 'events(1).idx']);
0422     t_ok(strcmp(r.cpf.events(1).name, 'TARGET_LAM'), [t 'events(1).name']);
0423     t_ok(isfield(r.cpf, 'cb1'), [t 'isfield cpf.cb1']);
0424     t_ok(isstruct(r.cpf.cb1), [t 'isstruct cpf.cb1']);
0425     t_ok(isfield(r.cpf.cb1, 'initial'), [t 'isfield cpf.cb1.initial']);
0426     t_ok(isfield(r.cpf.cb1, 'iteration'), [t 'isfield cpf.cb1.iteration']);
0427     t_ok(isfield(r.cpf.cb1, 'final'), [t 'isfield cpf.cb1.final']);
0428     t_is(r.cpf.cb1.initial, 1, 12, [t 'r.cpf.cb1.initial']);
0429     t_is(r.cpf.cb1.iteration, iterations, 12, [t 'r.cpf.cb1.iterations']);
0430     t_is(r.cpf.cb1.final, 1, 12, [t 'r.cpf.cb1.final']);
0431     t_ok(strcmp(r.cpf.shared, '1111111111'), [t 'r.cpf.shared']);
0432 
0433     t = '1 user callback : ';
0434     cb1 = struct('fcn', 't_cpf_cb1', 'priority', 10);
0435     mpopt = mpoption(mpopt, 'cpf.stop_at', 0.7, 'cpf.parameterization', 3);
0436     mpopt = mpoption(mpopt, 'cpf.adapt_step', 1);
0437     mpopt = mpoption(mpopt, 'cpf.user_callback', cb1);
0438     r = runcpf(mpcb, mpct, mpopt);
0439     iterations = 9;
0440     t_ok(r.success, [t 'success']);
0441     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0442     t_is(r.cpf.max_lam, 0.7, 12, [t 'max_lam']);
0443     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0444     t_ok(strfind(r.cpf.done_msg, 'Reached desired lambda 0.7'), [t 'done_msg']);
0445     t_is(length(r.cpf.events), 1, 12, [t 'length(events) == 1']);
0446     t_is(r.cpf.events(1).k, iterations, 12, [t 'events(1).k']);
0447     t_is(r.cpf.events(1).idx, 1, 12, [t 'events(1).idx']);
0448     t_ok(strcmp(r.cpf.events(1).name, 'TARGET_LAM'), [t 'events(1).name']);
0449     t_ok(isfield(r.cpf, 'cb1'), [t 'isfield cpf.cb1']);
0450     t_ok(isstruct(r.cpf.cb1), [t 'isstruct cpf.cb1']);
0451     t_ok(isfield(r.cpf.cb1, 'initial'), [t 'isfield cpf.cb1.initial']);
0452     t_ok(isfield(r.cpf.cb1, 'iteration'), [t 'isfield cpf.cb1.iteration']);
0453     t_ok(isfield(r.cpf.cb1, 'final'), [t 'isfield cpf.cb1.final']);
0454     t_is(r.cpf.cb1.initial, 1, 12, [t 'r.cpf.cb1.initial']);
0455     t_is(r.cpf.cb1.iteration, iterations, 12, [t 'r.cpf.cb1.iterations']);
0456     t_is(r.cpf.cb1.final, 1, 12, [t 'r.cpf.cb1.final']);
0457     t_ok(strcmp(r.cpf.shared, '1111111111'), [t 'r.cpf.shared']);
0458 
0459     t = '2 user callbacks (with args) : ';
0460     cb_args = struct('initial', 20, 'iteration', 2, 'final', 200);
0461     cb2 = struct('fcn', 't_cpf_cb2', 'args', cb_args);
0462     mpopt = mpoption(mpopt, 'cpf.user_callback', {'t_cpf_cb1', cb2});
0463     r = runcpf(mpcb, mpct, mpopt);
0464     iterations = 9;
0465     t_ok(r.success, [t 'success']);
0466     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0467     t_is(r.cpf.max_lam, 0.7, 12, [t 'max_lam']);
0468     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0469     t_ok(strfind(r.cpf.done_msg, 'Reached desired lambda 0.7'), [t 'done_msg']);
0470     t_is(length(r.cpf.events), 1, 12, [t 'length(events) == 1']);
0471     t_is(r.cpf.events(1).k, iterations, 12, [t 'events(1).k']);
0472     t_is(r.cpf.events(1).idx, 1, 12, [t 'events(1).idx']);
0473     t_ok(strcmp(r.cpf.events(1).name, 'TARGET_LAM'), [t 'events(1).name']);
0474     t_ok(isfield(r.cpf, 'cb1'), [t 'isfield cpf.cb1']);
0475     t_ok(isstruct(r.cpf.cb1), [t 'isstruct cpf.cb1']);
0476     t_ok(isfield(r.cpf.cb1, 'initial'), [t 'isfield cpf.cb1.initial']);
0477     t_ok(isfield(r.cpf.cb1, 'iteration'), [t 'isfield cpf.cb1.iteration']);
0478     t_ok(isfield(r.cpf.cb1, 'final'), [t 'isfield cpf.cb1.final']);
0479     t_is(r.cpf.cb1.initial, 1, 12, [t 'r.cpf.cb1.initial']);
0480     t_is(r.cpf.cb1.iteration, iterations, 12, [t 'r.cpf.cb1.iterations']);
0481     t_is(r.cpf.cb1.final, 1, 12, [t 'r.cpf.cb1.final']);
0482     t_ok(isfield(r.cpf, 'cb2'), [t 'isfield cpf.cb2']);
0483     t_ok(isstruct(r.cpf.cb2), [t 'isstruct cpf.cb2']);
0484     t_ok(isfield(r.cpf.cb2, 'initial'), [t 'isfield cpf.cb2.initial']);
0485     t_ok(isfield(r.cpf.cb2, 'iteration'), [t 'isfield cpf.cb2.iteration']);
0486     t_ok(isfield(r.cpf.cb2, 'final'), [t 'isfield cpf.cb2.final']);
0487     t_is(r.cpf.cb2.initial, 20, 12, [t 'r.cpf.cb2.initial']);
0488     t_is(r.cpf.cb2.iteration, 2*iterations, 12, [t 'r.cpf.cb2.iterations']);
0489     t_is(r.cpf.cb2.final, 200, 12, [t 'r.cpf.cb2.final']);
0490     t_ok(strcmp(r.cpf.shared, '12121212121212121212'), [t 'r.cpf.shared']);
0491 
0492     t = '2 user callbacks (with priority & args) : ';
0493     cb_args = struct('initial', 20, 'iteration', 2, 'final', 200);
0494     cb2 = struct('fcn', 't_cpf_cb2', 'priority', 21, 'args', cb_args);
0495     mpopt = mpoption(mpopt, 'cpf.user_callback', {'t_cpf_cb1', cb2});
0496     r = runcpf(mpcb, mpct, mpopt);
0497     iterations = 9;
0498     t_ok(r.success, [t 'success']);
0499     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0500     t_is(r.cpf.max_lam, 0.7, 12, [t 'max_lam']);
0501     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0502     t_ok(strfind(r.cpf.done_msg, 'Reached desired lambda 0.7'), [t 'done_msg']);
0503     t_is(length(r.cpf.events), 1, 12, [t 'length(events) == 1']);
0504     t_is(r.cpf.events(1).k, iterations, 12, [t 'events(1).k']);
0505     t_is(r.cpf.events(1).idx, 1, 12, [t 'events(1).idx']);
0506     t_ok(strcmp(r.cpf.events(1).name, 'TARGET_LAM'), [t 'events(1).name']);
0507     t_ok(isfield(r.cpf, 'cb1'), [t 'isfield cpf.cb1']);
0508     t_ok(isstruct(r.cpf.cb1), [t 'isstruct cpf.cb1']);
0509     t_ok(isfield(r.cpf.cb1, 'initial'), [t 'isfield cpf.cb1.initial']);
0510     t_ok(isfield(r.cpf.cb1, 'iteration'), [t 'isfield cpf.cb1.iteration']);
0511     t_ok(isfield(r.cpf.cb1, 'final'), [t 'isfield cpf.cb1.final']);
0512     t_is(r.cpf.cb1.initial, 1, 12, [t 'r.cpf.cb1.initial']);
0513     t_is(r.cpf.cb1.iteration, iterations, 12, [t 'r.cpf.cb1.iterations']);
0514     t_is(r.cpf.cb1.final, 1, 12, [t 'r.cpf.cb1.final']);
0515     t_ok(isfield(r.cpf, 'cb2'), [t 'isfield cpf.cb2']);
0516     t_ok(isstruct(r.cpf.cb2), [t 'isstruct cpf.cb2']);
0517     t_ok(isfield(r.cpf.cb2, 'initial'), [t 'isfield cpf.cb2.initial']);
0518     t_ok(isfield(r.cpf.cb2, 'iteration'), [t 'isfield cpf.cb2.iteration']);
0519     t_ok(isfield(r.cpf.cb2, 'final'), [t 'isfield cpf.cb2.final']);
0520     t_is(r.cpf.cb2.initial, 20, 12, [t 'r.cpf.cb2.initial']);
0521     t_is(r.cpf.cb2.iteration, 2*iterations, 12, [t 'r.cpf.cb2.iterations']);
0522     t_is(r.cpf.cb2.final, 200, 12, [t 'r.cpf.cb2.final']);
0523     t_ok(strcmp(r.cpf.shared, '21212121212121212121'), [t 'r.cpf.shared']);
0524 
0525     t = 'case300 w/Q lims : ';
0526     mpopt = mpoption('out.all', 0, 'verbose', verbose);
0527     mpopt = mpoption(mpopt, 'cpf.stop_at', 'FULL', 'cpf.step', 0.1);
0528     mpopt = mpoption(mpopt, 'cpf.step_max', 0.2);
0529     mpopt = mpoption(mpopt, 'cpf.adapt_step', 0);
0530     mpopt = mpoption(mpopt, 'cpf.enforce_q_lims', 1);
0531     mpcb = loadcase('case300');                         % load base case
0532     mpct = mpcb;                                        % set up target case with
0533     mpct.gen(:, [PG QG]) = mpcb.gen(:, [PG QG]) * 2.5;  % increased generation
0534     mpct.bus(:, [PD QD]) = mpcb.bus(:, [PD QD]) * 2.5;  % and increased load
0535 
0536     r = runcpf(mpcb, mpct, mpopt);
0537     iterations = 43;
0538     t_ok(r.success, [t 'success']);
0539     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0540     t_is(r.cpf.max_lam, 0.03830560, 6, [t 'max_lam']);
0541     t_is(size(r.cpf.V_hat), [300 iterations+1], 12, [t 'size(V_hat)']);
0542     t_is(size(r.cpf.V), [300 iterations+1], 12, [t 'size(V)']);
0543     t_is(size(r.cpf.lam_hat), [1 iterations+1], 12, [t 'size(lam_hat)']);
0544     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0545     t_ok(strfind(r.cpf.done_msg, 'Traced full continuation curve in'), [t 'done_msg']);
0546     qmin_violation = max(0, r.gen(:, QMIN) - r.gen(:, QG));
0547     qmax_violation = max(0, r.gen(:, QG) - r.gen(:, QMAX));
0548     t_is(qmin_violation, 0, 12, [t 'Qmin violation']);
0549     t_is(qmax_violation, 0, 12, [t 'Qmax violation']);
0550     ek = [1 3 5 12 14 17 19 22 24 28 38 41 43];
0551     eidx = [26 19 67 15 59 69 50 66 54 68 87 89 1];
0552     ename = {'QLIM', 'QLIM', 'QLIM', 'QLIM', 'QLIM', 'QLIM', 'QLIM', 'QLIM', 'QLIM', 'QLIM', 'QLIM', 'QLIM', 'TARGET_LAM'};
0553     ne = length(ek);
0554     t_is(length(r.cpf.events), ne, 12, sprintf('%ssize(events) == %d', t, ne));
0555     for j = 1:ne
0556         t_is(r.cpf.events(j).k, ek(j), 12, sprintf('%sevents(%d).k == %d', t, j, ek(j)));
0557         t_is(r.cpf.events(j).idx, eidx(j), 12, sprintf('%sevents(%d).idx == %d', t, j, eidx(j)));
0558         t_ok(strcmp(r.cpf.events(j).name, ename{j}), sprintf('%sevents(%d).name = ''%s''', t, j, ename{j}));
0559     end
0560 
0561     t = 'case14 (unsuccessful) : ';
0562     mpopt = mpoption(mpopt, 'cpf.adapt_step', 1);
0563     mpopt = mpoption(mpopt, 'cpf.enforce_q_lims', 0);
0564     mpcb = loadcase('case14');                          % load base case
0565     mpct = mpcb;                                        % set up target case with
0566     mpct.gen(:, [PG QG]) = mpcb.gen(:, [PG QG]) * 2.5;  % increased generation
0567     mpct.bus(:, [PD QD]) = mpcb.bus(:, [PD QD]) * 2.5;  % and increased load
0568 
0569     r = runcpf(mpcb, mpct, mpopt);
0570     iterations = 79;
0571     t_ok(~r.success, [t 'success']);
0572     t_is(r.cpf.iterations, iterations, 12, [t 'iterations']);
0573     t_is(r.cpf.max_lam, 2.0401678, 6, [t 'max_lam']);
0574     t_is(size(r.cpf.V_hat), [14 iterations+1], 12, [t 'size(V_hat)']);
0575     t_is(size(r.cpf.V), [14 iterations+1], 12, [t 'size(V)']);
0576     t_is(size(r.cpf.lam_hat), [1 iterations+1], 12, [t 'size(lam_hat)']);
0577     t_is(size(r.cpf.lam), [1 iterations+1], 12, [t 'size(lam)']);
0578     t_ok(strfind(r.cpf.done_msg, 'Corrector did not converge in'), [t 'done_msg']);
0579     t_is(length(r.cpf.events), 0, 12, [t 'length(events) == 0']);
0580 
0581     if have_feature('octave')
0582         warning(s1.state, file_in_path_warn_id);
0583     end
0584 end
0585 
0586 t_end;
0587 
0588 if nargout
0589     res = r;
0590 end

Generated on Fri 09-Oct-2020 11:21:31 by m2html © 2005