Home > matpower5.1 > t > t_opf_mips_sc.m

t_opf_mips_sc

PURPOSE ^

T_OPF_MIPS_SC Tests for step-controlled MIPS-based AC optimal power flow.

SYNOPSIS ^

function t_opf_mips_sc(quiet)

DESCRIPTION ^

T_OPF_MIPS_SC  Tests for step-controlled MIPS-based AC optimal power flow.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function t_opf_mips_sc(quiet)
0002 %T_OPF_MIPS_SC  Tests for step-controlled MIPS-based AC optimal power flow.
0003 
0004 %   MATPOWER
0005 %   Copyright (c) 2004-2015 by Power System Engineering Research Center (PSERC)
0006 %   by Ray Zimmerman, PSERC Cornell
0007 %
0008 %   $Id: t_opf_mips_sc.m 2662 2015-03-20 20:02:08Z ray $
0009 %
0010 %   This file is part of MATPOWER.
0011 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0012 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0013 
0014 if nargin < 1
0015     quiet = 0;
0016 end
0017 
0018 linsolvers = {'\'};
0019 if have_fcn('pardiso')
0020     linsolvers{end+1} = 'PARDISO';
0021 end
0022 
0023 num_tests = 101;
0024 
0025 t_begin(2*num_tests, quiet);
0026 
0027 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0028     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0029 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0030     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0031     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0032 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0033     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0034     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0035 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
0036 
0037 casefile = 't_case9_opf';
0038 if quiet
0039     verbose = 0;
0040 else
0041     verbose = 0;
0042 end
0043 if have_fcn('octave')
0044     if have_fcn('octave', 'vnum') >= 4
0045         file_in_path_warn_id = 'Octave:data-file-in-path';
0046     else
0047         file_in_path_warn_id = 'Octave:load-file-in-path';
0048     end
0049     s1 = warning('query', file_in_path_warn_id);
0050     warning('off', file_in_path_warn_id);
0051 end
0052 
0053 mpopt = mpoption('opf.violation', 1e-6, 'mips.gradtol', 1e-8, ...
0054         'mips.comptol', 1e-8, 'mips.costtol', 1e-9);
0055 mpopt = mpoption(mpopt, 'out.all', 0, 'verbose', verbose, 'opf.ac.solver', 'MIPS', 'mips.step_control', 1);
0056 
0057 for k = 1:length(linsolvers)
0058     mpopt = mpoption(mpopt, 'mips.linsolver', linsolvers{k});
0059     t0 = sprintf('MIPS-sc (%s): ', linsolvers{k});
0060 
0061     %% set up indices
0062     ib_data     = [1:BUS_AREA BASE_KV:VMIN];
0063     ib_voltage  = [VM VA];
0064     ib_lam      = [LAM_P LAM_Q];
0065     ib_mu       = [MU_VMAX MU_VMIN];
0066     ig_data     = [GEN_BUS QMAX QMIN MBASE:APF];
0067     ig_disp     = [PG QG VG];
0068     ig_mu       = (MU_PMAX:MU_QMIN);
0069     ibr_data    = (1:ANGMAX);
0070     ibr_flow    = (PF:QT);
0071     ibr_mu      = [MU_SF MU_ST];
0072     ibr_angmu   = [MU_ANGMIN MU_ANGMAX];
0073 
0074     %% get solved AC power flow case from MAT-file
0075     load soln9_opf;     %% defines bus_soln, gen_soln, branch_soln, f_soln
0076 
0077     %% run OPF
0078     t = t0;
0079     [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(casefile, mpopt);
0080     t_ok(success, [t 'success']);
0081     t_is(f, f_soln, 3, [t 'f']);
0082     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0083     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0084     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0085     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0086     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0087     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0088     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0089     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0090     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0091     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0092 
0093     %% run with automatic conversion of single-block pwl to linear costs
0094     t = [t0 '(single-block PWL) : '];
0095     mpc = loadcase(casefile);
0096     mpc.gencost(3, NCOST) = 2;
0097     [r, success] = runopf(mpc, mpopt);
0098     [f, bus, gen, branch] = deal(r.f, r.bus, r.gen, r.branch);
0099     t_ok(success, [t 'success']);
0100     t_is(f, f_soln, 3, [t 'f']);
0101     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0102     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0103     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0104     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0105     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0106     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0107     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0108     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0109     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0110     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0111     xr = [r.var.val.Va;r.var.val.Vm;r.var.val.Pg;r.var.val.Qg;0;r.var.val.y];
0112     t_is(r.x, xr, 8, [t 'check on raw x returned from OPF']);
0113 
0114     %% get solved AC power flow case from MAT-file
0115     load soln9_opf_Plim;       %% defines bus_soln, gen_soln, branch_soln, f_soln
0116 
0117     %% run OPF with active power line limits
0118     t = [t0 '(P line lim) : '];
0119     mpopt1 = mpoption(mpopt, 'opf.flow_lim', 'P');
0120     [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(casefile, mpopt1);
0121     t_ok(success, [t 'success']);
0122     t_is(f, f_soln, 3, [t 'f']);
0123     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0124     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0125     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0126     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0127     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0128     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0129     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0130     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0131     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0132     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0133 
0134     %%-----  test OPF with quadratic gen costs moved to generalized costs  -----
0135     mpc = loadcase(casefile);
0136     mpc.gencost = [
0137         2   1500    0   3   0.11    5   0;
0138         2   2000    0   3   0.085   1.2 0;
0139         2   3000    0   3   0.1225  1   0;
0140     ];
0141     [baseMVA, bus_soln, gen_soln, gencost, branch_soln, f_soln, success, et] = runopf(mpc, mpopt);
0142     branch_soln = branch_soln(:,1:MU_ST);
0143 
0144     A = sparse(0,0);
0145     l = [];
0146     u = [];
0147     nb = size(mpc.bus, 1);      % number of buses
0148     ng = size(mpc.gen, 1);      % number of gens
0149     thbas = 1;                thend    = thbas+nb-1;
0150     vbas     = thend+1;       vend     = vbas+nb-1;
0151     pgbas    = vend+1;        pgend    = pgbas+ng-1;
0152     qgbas    = pgend+1;       qgend    = qgbas+ng-1;
0153     nxyz = 2*nb + 2*ng;
0154     N = sparse((1:ng)', (pgbas:pgend)', mpc.baseMVA * ones(ng,1), ng, nxyz);
0155     fparm = ones(ng,1) * [ 1 0 0 1 ];
0156     [junk, ix] = sort(mpc.gen(:, 1));
0157     H = 2 * spdiags(mpc.gencost(ix, 5), 0, ng, ng);
0158     Cw = mpc.gencost(ix, 6);
0159     mpc.gencost(:, 5:7) = 0;
0160 
0161     %% run OPF with quadratic gen costs moved to generalized costs
0162     t = [t0 'w/quadratic generalized gen cost : '];
0163     [r, success] = opf(mpc, A, l, u, mpopt, N, fparm, H, Cw);
0164     [f, bus, gen, branch] = deal(r.f, r.bus, r.gen, r.branch);
0165     t_ok(success, [t 'success']);
0166     t_is(f, f_soln, 3, [t 'f']);
0167     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0168     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0169     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0170     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0171     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0172     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0173     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0174     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0175     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0176     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0177     t_is(r.cost.usr, f, 12, [t 'user cost']);
0178 
0179     %%-----  run OPF with extra linear user constraints & costs  -----
0180     %% single new z variable constrained to be greater than or equal to
0181     %% deviation from 1 pu voltage at bus 1, linear cost on this z
0182     %% get solved AC power flow case from MAT-file
0183     load soln9_opf_extras1;   %% defines bus_soln, gen_soln, branch_soln, f_soln
0184     A = sparse([1;1;2;2],[10;25;10;25],[-1;1;1;1],2,25);
0185     u = [Inf; Inf];
0186     l = [-1; 1];
0187 
0188     N = sparse(1, 25, 1, 1, 25);    %% new z variable only
0189     fparm = [1 0 0 1];              %% w = r = z
0190     H = sparse(1,1);                %% no quadratic term
0191     Cw = 100;
0192 
0193     t = [t0 'w/extra constraints & costs 1 : '];
0194     [r, success] = opf(casefile, A, l, u, mpopt, N, fparm, H, Cw);
0195     [f, bus, gen, branch] = deal(r.f, r.bus, r.gen, r.branch);
0196     t_ok(success, [t 'success']);
0197     t_is(f, f_soln, 3, [t 'f']);
0198     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0199     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0200     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0201     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0202     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0203     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0204     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0205     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0206     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0207     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0208     t_is(r.var.val.z, 0.025419, 6, [t 'user variable']);
0209     t_is(r.cost.usr, 2.5419, 4, [t 'user cost']);
0210 
0211     %%-----  test OPF with capability curves  -----
0212     mpc = loadcase('t_case9_opfv2');
0213     %% remove angle diff limits
0214     mpc.branch(1, ANGMAX) = 360;
0215     mpc.branch(9, ANGMIN) = -360;
0216 
0217     %% get solved AC power flow case from MAT-file
0218     load soln9_opf_PQcap;   %% defines bus_soln, gen_soln, branch_soln, f_soln
0219     
0220     %% run OPF with capability curves
0221     t = [t0 'w/capability curves : '];
0222     [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(mpc, mpopt);
0223     t_ok(success, [t 'success']);
0224     t_is(f, f_soln, 3, [t 'f']);
0225     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0226     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0227     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0228     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0229     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0230     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0231     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0232     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0233     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0234     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0235 
0236     %%-----  test OPF with angle difference limits  -----
0237     mpc = loadcase('t_case9_opfv2');
0238     %% remove capability curves
0239     mpc.gen(2:3, [PC1, PC2, QC1MIN, QC1MAX, QC2MIN, QC2MAX]) = zeros(2,6);
0240 
0241     %% get solved AC power flow case from MAT-file
0242     load soln9_opf_ang;   %% defines bus_soln, gen_soln, branch_soln, f_soln
0243     
0244     %% run OPF with angle difference limits
0245     t = [t0 'w/angle difference limits : '];
0246     [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(mpc, mpopt);
0247     t_ok(success, [t 'success']);
0248     t_is(f, f_soln, 3, [t 'f']);
0249     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0250     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0251     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0252     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  1, [t 'bus mu']);
0253     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0254     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0255     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0256     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0257     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0258     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0259     t_is(branch(:,ibr_angmu ), branch_soln(:,ibr_angmu ),  2, [t 'branch angle mu']);
0260 
0261     %%-----  test OPF with ignored angle difference limits  -----
0262     %% get solved AC power flow case from MAT-file
0263     load soln9_opf;   %% defines bus_soln, gen_soln, branch_soln, f_soln
0264 
0265     %% run OPF with ignored angle difference limits
0266     t = [t0 'w/ignored angle difference limits : '];
0267     mpopt1 = mpoption(mpopt, 'opf.ignore_angle_lim', 1);
0268     [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(mpc, mpopt1);
0269     %% ang limits are not in this solution data, so let's remove them
0270     branch(1, ANGMAX) = 360;
0271     branch(9, ANGMIN) = -360;
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 end
0285 
0286 if ~have_fcn('pardiso')
0287     t_skip(num_tests, 'PARDISO linear solver not available');
0288 end
0289 
0290 if have_fcn('octave')
0291     warning(s1.state, file_in_path_warn_id);
0292 end
0293 
0294 t_end;

Generated on Fri 20-Mar-2015 18:23:34 by m2html © 2005