Home > matpower7.0 > lib > t > t_opf_dc_bpmpd.m

t_opf_dc_bpmpd

PURPOSE ^

T_OPF_DC_BPMPD Tests for DC optimal power flow using BPMPD_MEX solver.

SYNOPSIS ^

function t_opf_dc_bpmpd(quiet)

DESCRIPTION ^

T_OPF_DC_BPMPD  Tests for DC optimal power flow using BPMPD_MEX solver.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function t_opf_dc_bpmpd(quiet)
0002 %T_OPF_DC_BPMPD  Tests for DC optimal power flow using BPMPD_MEX solver.
0003 
0004 %   MATPOWER
0005 %   Copyright (c) 2004-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 = 24;
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 
0029 casefile = 't_case9_opf';
0030 if quiet
0031     verbose = 0;
0032 else
0033     verbose = 0;
0034 end
0035 
0036 t0 = 'DC OPF (BPMPD): ';
0037 mpopt = mpoption('out.all', 0, 'verbose', verbose);
0038 mpopt = mpoption(mpopt, 'opf.dc.solver', 'BPMPD');
0039 
0040 %% run DC OPF
0041 if have_fcn('bpmpd')
0042     %% set up indices
0043     ib_data     = [1:BUS_AREA BASE_KV:VMIN];
0044     ib_voltage  = [VM VA];
0045     ib_lam      = [LAM_P LAM_Q];
0046     ib_mu       = [MU_VMAX MU_VMIN];
0047     ig_data     = [GEN_BUS QMAX QMIN MBASE:APF];
0048     ig_disp     = [PG QG VG];
0049     ig_mu       = (MU_PMAX:MU_QMIN);
0050     ibr_data    = (1:ANGMAX);
0051     ibr_flow    = (PF:QT);
0052     ibr_mu      = [MU_SF MU_ST];
0053     ibr_angmu   = [MU_ANGMIN MU_ANGMAX];
0054     
0055     %% get solved DC power flow case from MAT-file
0056     load soln9_dcopf;       %% defines bus_soln, gen_soln, branch_soln, f_soln
0057     
0058     %% run OPF
0059     t = t0;
0060     [baseMVA, bus, gen, gencost, branch, f, success, et] = rundcopf(casefile, mpopt);
0061     t_ok(success, [t 'success']);
0062     t_is(f, f_soln, 3, [t 'f']);
0063     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0064     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0065     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0066     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0067     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0068     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0069     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0070     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0071     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0072     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0073 
0074     %%-----  run OPF with extra linear user constraints & costs  -----
0075     %% two new z variables
0076     %%      0 <= z1, P3 - P1 <= z1
0077     %%      0 <= z2, P3 - P2 <= z2
0078     %% with A and N sized for DC opf
0079     mpc = loadcase(casefile);
0080     mpc.A = sparse([1;1;1;2;2;2],[10;12;13;12;11;14],[-1;1;-1;1;-1;-1],2,14);
0081     mpc.u = [0; 0];
0082     mpc.l = [-Inf; -Inf];
0083     mpc.zl = [0; 0];
0084     
0085     mpc.N = sparse([1;2], [13;14], [1;1], 2, 14);   %% new z variables only
0086     mpc.fparm = ones(2,1) * [1 0 0 1];              %% w = r = z
0087     mpc.H = sparse(2,2);                            %% no quadratic term
0088     mpc.Cw = [1000;1];
0089 
0090     t = [t0 'w/extra constraints & costs 1 : '];
0091     [r, success] = rundcopf(mpc, mpopt);
0092     t_ok(success, [t 'success']);
0093     t_is(r.gen(1, PG), 116.15974, 5, [t 'Pg1 = 116.15974']);
0094     t_is(r.gen(3, PG), 116.15974, 5, [t 'Pg3 = 116.15974']);
0095     t_is(r.var.val.z, [0; 0.3348], 4, [t 'user vars']);
0096     t_is(r.cost.usr, 0.3348, 4, [t 'user costs']);
0097 
0098     %% with A and N sized for AC opf
0099     mpc = loadcase(casefile);
0100     mpc.A = sparse([1;1;1;2;2;2],[19;21;25;21;20;26],[-1;1;-1;1;-1;-1],2,26);
0101     mpc.u = [0; 0];
0102     mpc.l = [-Inf; -Inf];
0103     mpc.zl = [0; 0];
0104 
0105     mpc.N = sparse([1;2], [25;26], [1;1], 2, 26);   %% new z variables only
0106     mpc.fparm = ones(2,1) * [1 0 0 1];              %% w = r = z
0107     mpc.H = sparse(2,2);                            %% no quadratic term
0108     mpc.Cw = [1000;1];
0109 
0110     t = [t0 'w/extra constraints & costs 2 : '];
0111     [r, success] = rundcopf(mpc, mpopt);
0112     t_ok(success, [t 'success']);
0113     t_is(r.gen(1, PG), 116.15974, 5, [t 'Pg1 = 116.15974']);
0114     t_is(r.gen(3, PG), 116.15974, 5, [t 'Pg3 = 116.15974']);
0115     t_is(r.var.val.z, [0; 0.3348], 4, [t 'user vars']);
0116     t_is(r.cost.usr, 0.3348, 4, [t 'user costs']);
0117 
0118     t = [t0 'infeasible : '];
0119     %% with A and N sized for DC opf
0120     mpc = loadcase(casefile);
0121     mpc.A = sparse([1;1], [10;11], [1;1], 1, 14);   %% Pg1 + Pg2
0122     mpc.u = Inf;
0123     mpc.l = 600;
0124     [r, success] = rundcopf(mpc, mpopt);
0125     t_ok(~success, [t 'no success']);
0126 
0127     %% OPF with all buses isolated
0128     t = [t0 'all buses isolated : '];
0129     mpc = loadcase(casefile);
0130     mpc.bus(:, BUS_TYPE) = NONE;
0131     try
0132         r = rundcopf(mpc, mpopt);
0133         t_is(r.success, 0, 12, [t 'success = 0']);
0134     catch
0135         t_ok(0, [t 'unexpected fatal error']);
0136     end
0137 else
0138     t_skip(num_tests, 'BPMPD_MEX not available');
0139 end
0140 
0141 t_end;

Generated on Mon 24-Jun-2019 15:58:45 by m2html © 2005