Home > matpower7.1 > lib > t > t_opf_default.m

t_opf_default

PURPOSE ^

T_OPF_DEFAULT Tests for AC optimal power flow using default solver.

SYNOPSIS ^

function t_opf_default(quiet)

DESCRIPTION ^

T_OPF_DEFAULT  Tests for AC optimal power flow using default solver.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function t_opf_default(quiet)
0002 %T_OPF_DEFAULT  Tests for AC optimal power flow using default solver.
0003 
0004 %   MATPOWER
0005 %   Copyright (c) 2004-2017, 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 = 189;
0017 
0018 t_begin(num_tests, quiet);
0019 
0020 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0021     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0022 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0023     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0024     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0025 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0026     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0027     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0028 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
0029 
0030 casefile = 't_case9_opf';
0031 if quiet
0032     verbose = 0;
0033 else
0034     verbose = 0;
0035 end
0036 if have_feature('octave')
0037     if have_feature('octave', 'vnum') >= 4
0038         file_in_path_warn_id = 'Octave:data-file-in-path';
0039     else
0040         file_in_path_warn_id = 'Octave:load-file-in-path';
0041     end
0042     s1 = warning('query', file_in_path_warn_id);
0043     warning('off', file_in_path_warn_id);
0044 end
0045 
0046 t0 = 'DEFAULT : ';
0047 mpopt = mpoption('opf.violation', 1e-6, 'mips.gradtol', 1e-8, ...
0048         'mips.comptol', 1e-8, 'mips.costtol', 1e-9);
0049 mpopt = mpoption(mpopt, 'out.all', 0, 'verbose', verbose);
0050 if have_feature('pdipmopf')
0051     mpopt = mpoption(mpopt, 'pdipm.gradtol', 1e-8, ...
0052             'pdipm.comptol', 1e-8, 'pdipm.costtol', 1e-9);
0053 end
0054 
0055     %% set up indices
0056     ib_data     = [1:BUS_AREA BASE_KV:VMIN];
0057     ib_voltage  = [VM VA];
0058     ib_lam      = [LAM_P LAM_Q];
0059     ib_mu       = [MU_VMAX MU_VMIN];
0060     ig_data     = [GEN_BUS QMAX QMIN MBASE:APF];
0061     ig_disp     = [PG QG VG];
0062     ig_mu       = (MU_PMAX:MU_QMIN);
0063     ibr_data    = (1:ANGMAX);
0064     ibr_flow    = (PF:QT);
0065     ibr_mu      = [MU_SF MU_ST];
0066     ibr_angmu   = [MU_ANGMIN MU_ANGMAX];
0067 
0068     %% get solved AC OPF case from MAT-file
0069     load soln9_opf;     %% defines bus_soln, gen_soln, branch_soln, f_soln
0070 
0071     %% run OPF
0072     for s = 0:3
0073         mpopt = mpoption(mpopt, 'opf.start', s);
0074         t = sprintf('%s(start=%d): ', t0, s);
0075         [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(casefile, mpopt);
0076         t_ok(success, [t 'success']);
0077         t_is(f, f_soln, 3, [t 'f']);
0078         t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0079         t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0080         t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0081         t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0082         t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0083         t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0084         t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0085         t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0086         t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0087         t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0088     end
0089     mpopt = mpoption(mpopt, 'opf.start', 0);    %% set 'opf.start' back to default
0090 
0091     %% run with automatic conversion of single-block pwl to linear costs
0092     t = [t0 '(single-block PWL) : '];
0093     mpc = loadcase(casefile);
0094     mpc.gencost(2, NCOST) = 2;
0095     [r, success] = runopf(mpc, mpopt);
0096     [f, bus, gen, branch] = deal(r.f, r.bus, r.gen, r.branch);
0097     t_ok(success, [t 'success']);
0098     t_is(f, f_soln, 3, [t 'f']);
0099     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0100     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0101     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0102     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0103     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0104     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0105     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0106     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0107     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0108     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0109     xr = [r.var.val.Va;r.var.val.Vm;r.var.val.Pg;r.var.val.Qg;0;r.var.val.y];
0110     t_is(r.x, xr, 8, [t 'raw x returned from OPF']);
0111 
0112 %     %% get solved AC OPF case from MAT-file
0113 %     load soln9_opf_Plim;       %% defines bus_soln, gen_soln, branch_soln, f_soln
0114 %
0115 %     %% run OPF with active power line limits
0116 %     t = [t0 '(P line lim) : '];
0117 %     mpopt1 = mpoption(mpopt, 'opf.flow_lim', 'P');
0118 %     [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(casefile, mpopt1);
0119 %     t_ok(success, [t 'success']);
0120 %     t_is(f, f_soln, 3, [t 'f']);
0121 %     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0122 %     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0123 %     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0124 %     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0125 %     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0126 %     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0127 %     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0128 %     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0129 %     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0130 %     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0131 %
0132 %     %% run OPF with active power line limits
0133 %     t = [t0 '(P^2 line lim) : '];
0134 %     mpopt1 = mpoption(mpopt, 'opf.flow_lim', '2');
0135 %     [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(casefile, mpopt1);
0136 %     t_ok(success, [t 'success']);
0137 %     t_is(f, f_soln, 3, [t 'f']);
0138 %     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0139 %     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0140 %     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0141 %     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0142 %     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0143 %     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0144 %     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0145 %     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0146 %     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0147 %     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0148 
0149     %%-----  test OPF with quadratic gen costs moved to generalized costs  -----
0150     mpc = loadcase(casefile);
0151     mpc.gencost = [
0152         2   1500    0   3   0.11    5   0;
0153         2   2000    0   3   0.085   1.2 0;
0154         2   3000    0   3   0.1225  1   0;
0155     ];
0156     [baseMVA, bus_soln, gen_soln, gencost, branch_soln, f_soln, success, et] = runopf(mpc, mpopt);
0157     branch_soln = branch_soln(:,1:MU_ST);
0158 
0159     A = sparse(0,0);
0160     l = [];
0161     u = [];
0162     nb = size(mpc.bus, 1);      % number of buses
0163     ng = size(mpc.gen, 1);      % number of gens
0164     thbas = 1;                thend    = thbas+nb-1;
0165     vbas     = thend+1;       vend     = vbas+nb-1;
0166     pgbas    = vend+1;        pgend    = pgbas+ng-1;
0167     qgbas    = pgend+1;       qgend    = qgbas+ng-1;
0168     nxyz = 2*nb + 2*ng;
0169     N = sparse((1:ng)', (pgbas:pgend)', mpc.baseMVA * ones(ng,1), ng, nxyz);
0170     fparm = [ 1    0   0 1;
0171               1 -100 100 1;
0172               1  -10  10 1 ];
0173     H = 2 * spdiags(mpc.gencost(:, 5), 0, ng, ng);
0174     Cw = mpc.gencost(:, 6);
0175     mpc.gencost(:, 5:7) = 0;
0176 
0177     %% run OPF with quadratic gen costs moved to generalized costs
0178     t = [t0 'w/quadratic generalized gen cost : '];
0179     [r, success] = opf(mpc, A, l, u, mpopt, N, fparm, H, Cw);
0180     [f, bus, gen, branch] = deal(r.f, r.bus, r.gen, r.branch);
0181     t_ok(success, [t 'success']);
0182     t_is(f, f_soln, 3, [t 'f']);
0183     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0184     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0185     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0186     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0187     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0188     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0189     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0190     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0191     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0192     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0193     t_is(r.cost.usr, f, 12, [t 'user cost']);
0194 
0195     %%-----  run OPF with legacy costs and deadzone  -----
0196     load soln9_opf;
0197     mpc = loadcase(casefile);
0198     mpc.N = sparse((1:nb)', (vbas:vend)', ones(nb,1), nb, nxyz);
0199     mpc.fparm = ones(nb,1) * [ 2 1.08 0.02 1e8 ];
0200     mpc.Cw = ones(nb, 1);
0201     t = [t0 'w/legacy cost, in deadzone : '];
0202     r = runopf(mpc, mpopt);
0203     [f, bus, gen, branch] = deal(r.f, r.bus, r.gen, r.branch);
0204     t_ok(r.success, [t 'success']);
0205     t_is(f, f_soln, 3, [t 'f']);
0206     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0207     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0208     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0209     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0210     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0211     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0212     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0213     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0214     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0215     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0216     t_is(r.cost.usr, 0, 12, [t 'user cost']);
0217 
0218     t = [t0 'w/legacy cost, not in deadzone : '];
0219     mpc.fparm = ones(nb,1) * [ 2 1.08 0.01 1e8 ];
0220     r = runopf(mpc, mpopt);
0221     [f, bus, gen, branch] = deal(r.f, r.bus, r.gen, r.branch);
0222     t_ok(r.success, [t 'success']);
0223     t_is(f, 9009.0890, 3, [t 'f']);
0224     t_is([min(bus(:, VM)) mean(bus(:, VM)) max(bus(:, VM))], ...
0225         [1.066624, 1.083980, 1.091698], 5, [t 'bus voltage']);
0226     t_is(r.cost.usr, 1673.065465, 5, [t 'user cost']);
0227 
0228     %%-----  run OPF with extra linear user constraints & costs  -----
0229     %% single new z variable constrained to be greater than or equal to
0230     %% deviation from 1 pu voltage at bus 1, linear cost on this z
0231     %% get solved AC OPF case from MAT-file
0232     load soln9_opf_extras1;   %% defines bus_soln, gen_soln, branch_soln, f_soln
0233     A = sparse([1;1;2;2],[10;25;10;25],[-1;1;1;1],2,25);
0234     u = [Inf; Inf];
0235     l = [-1; 1];
0236 
0237     N = sparse(1, 25, 1, 1, 25);    %% new z variable only
0238     fparm = [1 0 0 1];              %% w = r = z
0239     H = sparse(1,1);                %% no quadratic term
0240     Cw = 100;
0241 
0242     t = [t0 'w/extra constraints & costs 1 : '];
0243     [r, success] = opf(casefile, A, l, u, mpopt, N, fparm, H, Cw);
0244     [f, bus, gen, branch] = deal(r.f, r.bus, r.gen, r.branch);
0245     t_ok(success, [t 'success']);
0246     t_is(f, f_soln, 3, [t 'f']);
0247     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0248     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0249     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0250     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0251     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0252     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0253     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0254     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0255     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0256     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0257     t_is(r.var.val.z, 0.025419, 6, [t 'user variable']);
0258     t_is(r.cost.usr, 2.5419, 4, [t 'user cost']);
0259 
0260     %%-----  test OPF with capability curves  -----
0261     mpc = loadcase('t_case9_opfv2');
0262     %% remove angle diff limits
0263     mpc.branch(1, ANGMAX) = 360;
0264     mpc.branch(9, ANGMIN) = -360;
0265 
0266     %% get solved AC OPF case from MAT-file
0267     load soln9_opf_PQcap;   %% defines bus_soln, gen_soln, branch_soln, f_soln
0268     
0269     %% run OPF with capability curves
0270     t = [t0 'w/capability curves : '];
0271     [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(mpc, mpopt);
0272     t_ok(success, [t 'success']);
0273     t_is(f, f_soln, 3, [t 'f']);
0274     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0275     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0276     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0277     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0278     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0279     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0280     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0281     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0282     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0283     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0284 
0285     %%-----  test OPF with angle difference limits  -----
0286     mpc = loadcase('t_case9_opfv2');
0287     %% remove capability curves
0288     mpc.gen(2:3, [PC1, PC2, QC1MIN, QC1MAX, QC2MIN, QC2MAX]) = zeros(2,6);
0289 
0290     %% get solved AC OPF case from MAT-file
0291     load soln9_opf_ang;   %% defines bus_soln, gen_soln, branch_soln, f_soln
0292     
0293     %% run OPF with angle difference limits
0294     t = [t0 'w/angle difference limits : '];
0295     [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(mpc, mpopt);
0296     t_ok(success, [t 'success']);
0297     t_is(f, f_soln, 3, [t 'f']);
0298     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0299     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0300     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0301     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  1, [t 'bus mu']);
0302     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0303     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0304     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0305     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0306     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0307     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0308     t_is(branch(:,ibr_angmu ), branch_soln(:,ibr_angmu ),  2, [t 'branch angle mu']);
0309 
0310     %%-----  test OPF with ignored angle difference limits  -----
0311     %% get solved AC OPF case from MAT-file
0312     load soln9_opf;   %% defines bus_soln, gen_soln, branch_soln, f_soln
0313 
0314     %% run OPF with ignored angle difference limits
0315     t = [t0 'w/ignored angle difference limits : '];
0316     mpopt1 = mpoption(mpopt, 'opf.ignore_angle_lim', 1);
0317     [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(mpc, mpopt1);
0318     %% ang limits are not in this solution data, so let's remove them
0319     branch(1, ANGMAX) = 360;
0320     branch(9, ANGMIN) = -360;
0321     t_ok(success, [t 'success']);
0322     t_is(f, f_soln, 3, [t 'f']);
0323     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0324     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0325     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0326     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0327     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0328     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0329     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0330     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0331     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0332     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0333 
0334     %% angle bounded above by 0, unbounded below
0335     %% for issue/18
0336     t = [t0 'w/angle difference limit = 0 : '];
0337     mpc = loadcase(casefile);
0338     b = 5;
0339     mpc.branch(b, ANGMAX) = 0;
0340     r = runopf(mpc, mpopt);
0341     t_ok(success, [t 'success']);
0342     diff = r.bus(r.branch(b, F_BUS), VA) - r.bus(r.branch(b, T_BUS), VA);
0343     t_is(diff, 0, 5, [t 'angle diff']);
0344 
0345     %%-----  OPF with ref bus not = bus 1, ref angle not = 0  -----
0346     t = [t0 'ref bus ~= 1, ref ang ~= 0 : '];
0347     mpc = loadcase(casefile);
0348     mpc.bus([1;3], BUS_TYPE) = [PV; REF];   %% swap bus types
0349     bus_soln([1;3], BUS_TYPE) = bus_soln([3;1], BUS_TYPE);   %% swap bus types
0350     mpc.bus(3, VA) = 3.3014277;
0351     r = runopf(mpc, mpopt);
0352     [success, f, bus, gen, branch] = deal(r.success, r.f, r.bus, r.gen, r.branch);
0353     t_ok(success, [t 'success']);
0354     t_is(f, f_soln, 3, [t 'f']);
0355     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0356     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0357     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0358     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0359     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0360     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0361     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0362     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0363     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0364     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0365 
0366     %%-----  test OPF with opf.use_vg  -----
0367     %% get solved AC OPF case from MAT-file
0368     load soln9_opf_vg;  %% defines bus_soln, gen_soln, branch_soln, f_soln
0369                         %%    and bus_soln1, gen_soln1, branch_soln1, f_soln1
0370     
0371     %% run with opf.use_vg = 1
0372     t = [t0 'w/opf.use_vg = 1 : '];
0373     mpc = loadcase(casefile);
0374     mpc.gen = mpc.gen([1 2 1 3], :);
0375     mpc.gencost = mpc.gencost([1 2 1 3], :);
0376     mpc.gen([1 3], [PMAX PMIN]) = mpc.gen([1 3], [PMAX PMIN]) / 2;
0377     mpc.gen(3, [QMIN, QMAX]) = 0;   %% no reactive capability for gen 3
0378     mpc.gencost([1 3], COST:end) = mpc.gencost([1 3], COST:end) / 2;
0379     mpc.gen(1, VG) = 1.05;
0380     mpc.gen(3, VG) = 1.06;
0381     mpopt1 = mpoption(mpopt, 'opf.use_vg', 1);
0382     r = runopf(mpc, mpopt1);
0383     t_ok(r.success, [t 'success']);
0384     t_is(r.f, f_soln, 3, [t 'f']);
0385     t_is(   r.bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0386     t_is(   r.bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0387     t_is(   r.bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0388     t_is(   r.bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0389     t_is(   r.gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0390     t_is(   r.gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0391     t_is(   r.gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0392     t_is(r.branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0393     t_is(r.branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0394     t_is(r.branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0395 
0396     %% run with opf.use_vg = 0.9
0397     t = [t0 'w/opf.use_vg = 0.9 : '];
0398     mpopt1 = mpoption(mpopt, 'opf.use_vg', 0.9);
0399     r = runopf(mpc, mpopt1);
0400     t_ok(r.success, [t 'success']);
0401     t_is(r.f, f_soln1, 3, [t 'f']);
0402     t_is(   r.bus(:,ib_data   ),    bus_soln1(:,ib_data   ), 10, [t 'bus data']);
0403     t_is(   r.bus(:,ib_voltage),    bus_soln1(:,ib_voltage),  3, [t 'bus voltage']);
0404     t_is(   r.bus(:,ib_lam    ),    bus_soln1(:,ib_lam    ),  3, [t 'bus lambda']);
0405     t_is(   r.bus(:,ib_mu     ),    bus_soln1(:,ib_mu     ),  2, [t 'bus mu']);
0406     t_is(   r.gen(:,ig_data   ),    gen_soln1(:,ig_data   ), 10, [t 'gen data']);
0407     t_is(   r.gen(:,ig_disp   ),    gen_soln1(:,ig_disp   ),  3, [t 'gen dispatch']);
0408     t_is(   r.gen(:,ig_mu     ),    gen_soln1(:,ig_mu     ),  3, [t 'gen mu']);
0409     t_is(r.branch(:,ibr_data  ), branch_soln1(:,ibr_data  ), 10, [t 'branch data']);
0410     t_is(r.branch(:,ibr_flow  ), branch_soln1(:,ibr_flow  ),  3, [t 'branch flow']);
0411     t_is(r.branch(:,ibr_mu    ), branch_soln1(:,ibr_mu    ),  2, [t 'branch mu']);
0412 
0413     t = [t0 'hi-deg polynomial costs : '];
0414     mpc = loadcase(casefile);
0415     mpc.gencost = [
0416         2   1500    0   6   1e-6/5  0   0   0   0   0;
0417         2   3000    0   5   1e-4/4  0   0   0   0   0;
0418         2   2000    0   3   1/2     0   0   0   0   0;
0419     ];
0420     r = runopf(mpc, mpopt);
0421     [f, bus, gen, branch] = deal(r.f, r.bus, r.gen, r.branch);
0422     t_ok(r.success, [t 'success']);
0423     t_is(f, 11899.4652, 4, [t 'f']);
0424     t_is(gen(:, PG), [100.703628; 88.719864; 128.679485], 5, [t 'Pg']);
0425     t_is([min(bus(:, VM)) mean(bus(:, VM)) max(bus(:, VM))], ...
0426         [1.059191 1.079404 1.1], 5, [t 'bus voltage']);
0427 
0428 %     %% OPF with user-defined nonlinear constraints
0429 %     t = [t0 'w/nonlin eq constraint : '];
0430 %     mpc = loadcase('case30');
0431 %     mpc.user_constraints.nle = {
0432 %         {'Pg_usr', 1, 'opf_nle_fcn1', 'opf_nle_hess1', {'Pg'}, {}}
0433 %     };
0434 %     r = runopf(mpc, mpopt);
0435 %     t_ok(r.success, [t 'success']);
0436 %     t_is(r.gen(1, PG) * r.gen(2, PG) / 100, r.gen(6, PG), 8, t);
0437 %     t_is(r.gen(6, PG), 20.751163, 5, t);
0438 %     %% check for indexing error, issue #77
0439 %     t_is(r.raw.pimul(61), 0, 6, [t 'issue #77']);
0440 %     t_is(r.mu.nln.u(61), 0, 6, [t 'issue #77']);
0441 
0442     %% OPF with all buses isolated
0443     t = [t0 'all buses isolated : '];
0444     mpc.bus(:, BUS_TYPE) = NONE;
0445     try
0446         r = runopf(mpc, mpopt);
0447         t_is(r.success, 0, 12, [t 'success = 0']);
0448     catch
0449         t_ok(0, [t 'unexpected fatal error']);
0450     end
0451 
0452     %% OPF with no branch limits
0453     t = [t0 'w/no branch limits : '];
0454     mpc = loadcase(casefile);
0455     mpc.branch(:, RATE_A) = 0;
0456     r = runopf(mpc, mpopt);
0457     t_ok(r.success, [t 'success']);
0458     t_is(r.f, 5496.128635, 4, [t 'f']);
0459     t_is(r.gen(:, PG), [90; 220.463932; 10], 5, [t 'Pg']);
0460     t_is([min(r.bus(:, VM)) mean(r.bus(:, VM)) max(r.bus(:, VM))], ...
0461         [1.070692 1.090449 1.1], 5, [t 'bus voltage']);
0462 
0463 if have_feature('octave')
0464     warning(s1.state, file_in_path_warn_id);
0465 end
0466 
0467 t_end;

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