Home > matpower5.1 > t > t_opf_ipopt.m

t_opf_ipopt

PURPOSE ^

T_OPF_IPOPT Tests for IPOPT-based AC optimal power flow.

SYNOPSIS ^

function t_opf_ipopt(quiet)

DESCRIPTION ^

T_OPF_IPOPT  Tests for IPOPT-based AC optimal power flow.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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

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