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

t_load2disp

PURPOSE ^

T_LOAD2DISP Tests for LOAD2DISP.

SYNOPSIS ^

function t_load2disp(quiet)

DESCRIPTION ^

T_LOAD2DISP  Tests for LOAD2DISP.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function t_load2disp(quiet)
0002 %T_LOAD2DISP  Tests for LOAD2DISP.
0003 
0004 %   MATPOWER
0005 %   Copyright (c) 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 = 72;
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 mpopt = mpoption('opf.violation', 1e-6, 'mips.gradtol', 1e-8, ...
0047         'mips.comptol', 1e-8, 'mips.costtol', 1e-9);
0048 mpopt = mpoption(mpopt, 'out.all', 0, 'verbose', verbose, 'opf.ac.solver', 'MIPS');
0049 
0050 %% set up indices
0051 ib_data     = [1:BUS_AREA BASE_KV:VMIN];
0052 ib_voltage  = [VM VA];
0053 ib_lam      = [LAM_P LAM_Q];
0054 ib_mu       = [MU_VMAX MU_VMIN];
0055 ig_data     = [GEN_BUS QMAX QMIN MBASE:APF];
0056 ig_disp     = [PG QG VG];
0057 ig_mu       = (MU_PMAX:MU_QMIN);
0058 ibr_data    = (1:ANGMAX);
0059 ibr_flow    = (PF:QT);
0060 ibr_mu      = [MU_SF MU_ST];
0061 ibr_angmu   = [MU_ANGMIN MU_ANGMAX];
0062 
0063 %% get solved AC OPF case from MAT-file
0064 load soln9_opf;     %% defines bus_soln, gen_soln, branch_soln, f_soln
0065 
0066 %% load2disp
0067 mpc0 = loadcase(casefile);
0068 mpc1 = load2disp(mpc0);
0069 ng = size(mpc0.gen, 1);
0070 ib = find(mpc0.bus(:, PD));
0071 ig = ng+(1:length(ib));
0072 
0073 t = 'mpc = load2disp(mpc) : ';
0074 t_is(size(mpc1.gen, 1), size(mpc0.gen, 1)+length(ib), 12, [t 'number of gens']);
0075 t_is(mpc1.bus(:, PD), 0, 12, [t 'PD is zero']);
0076 t_is(mpc1.bus(:, QD), 0, 12, [t 'QD is zero']);
0077 t_is(mpc1.gen(ig, PG), -mpc0.bus(ib, PD), 12, [t 'PG = -PD']);
0078 t_is(mpc1.gen(ig, PMIN), -mpc0.bus(ib, PD), 12, [t 'PMIN = -PD']);
0079 t_is(mpc1.gen(ig, PMAX), 0, 12, [t 'PMAX = 0']);
0080 t_is(mpc1.gen(ig, QMIN), -mpc0.bus(ib, QD), 12, [t 'QMIN = -QD']);
0081 t_is(mpc1.gen(ig, QMAX), 0, 12, [t 'QMAX = 0']);
0082 t_is(mpc1.gen(ig, VG), mpc0.bus(ib, VM), 12, [t 'VG']);
0083 t_is(mpc1.gencost(ig, MODEL), 2, 12, [t 'gencost(:, MODEL)']);
0084 t_is(mpc1.gencost(ig, NCOST), 2, 12, [t 'gencost(:, NCOST)']);
0085 t_is(mpc1.gencost(ig, COST), 5000, 12, [t 'gencost(:, COST)']);
0086 
0087 t = 'mpc = load2disp(mpc, '''', idx, voll) : ';
0088 idx = [5;7];
0089 ig = ng+(1:length(idx));
0090 mpc2 = load2disp(mpc0, '', idx, 1000);
0091 t_is(size(mpc2.gen, 1), size(mpc0.gen, 1)+length(idx), 12, [t 'number of gens']);
0092 t_is(mpc2.bus(:, PD), [zeros(8,1); 125], 12, [t 'PD']);
0093 t_is(mpc2.bus(:, QD), [zeros(8,1);  50], 12, [t 'QD']);
0094 t_is(mpc2.gen(ig, PG), -mpc0.bus(idx, PD), 12, [t 'PG = -PD']);
0095 t_is(mpc2.gen(ig, PMIN), -mpc0.bus(idx, PD), 12, [t 'PMIN = -PD']);
0096 t_is(mpc2.gen(ig, PMAX), 0, 12, [t 'PMAX = 0']);
0097 t_is(mpc2.gen(ig, QMIN), -mpc0.bus(idx, QD), 12, [t 'QMIN = -QD']);
0098 t_is(mpc2.gen(ig, QMAX), 0, 12, [t 'QMAX = 0']);
0099 t_is(mpc2.gen(ig, VG), mpc0.bus(idx, VM), 12, [t 'VG']);
0100 t_is(mpc2.gencost(ig, MODEL), 2, 12, [t 'gencost(:, MODEL)']);
0101 t_is(mpc2.gencost(ig, NCOST), 2, 12, [t 'gencost(:, NCOST)']);
0102 t_is(mpc2.gencost(ig, COST), 1000, 12, [t 'gencost(:, COST)']);
0103 
0104 %% run OPF
0105 t = 'fixed load OPF soln : ';
0106 r0 = runopf(mpc0, mpopt);
0107 t_ok(r0.success, [t 'success']);
0108 t_is(r0.f, f_soln, 3, [t 'f']);
0109 t_is(r0.bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0110 t_is(r0.bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0111 t_is(r0.bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0112 t_is(r0.bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0113 t_is(r0.gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0114 t_is(r0.gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0115 t_is(r0.gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0116 t_is(r0.branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0117 t_is(r0.branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0118 t_is(r0.branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0119 
0120 t = 'disp load OPF soln : ';
0121 r1 = runopf(mpc1, mpopt);
0122 t_ok(r0.success, [t 'success']);
0123 t_is(r0.f, f_soln, 3, [t 'f']);
0124 t_is(r0.bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0125 t_is(r0.bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0126 t_is(r0.bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0127 t_is(r0.bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0128 t_is(r0.gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0129 t_is(r0.gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0130 t_is(r0.gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0131 t_is(r0.branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0132 t_is(r0.branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0133 t_is(r0.branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0134 
0135 t = 'mpc = load2disp(solved_mpc) + gentype/genfuel : ';
0136 r0.genfuel = {'ng'; 'coal'; 'hydro'};
0137 r0.gentype = {'GT'; 'ST'; 'HY'};
0138 mpc3 = load2disp(r0);
0139 ib = find(mpc0.bus(:, PD));
0140 ig = ng+(1:length(ib));
0141 t_is(size(mpc3.gen, 1), size(mpc0.gen, 1)+length(ib), 12, [t 'number of gens']);
0142 t_is(mpc3.bus(:, PD), 0, 12, [t 'PD is zero']);
0143 t_is(mpc3.bus(:, QD), 0, 12, [t 'QD is zero']);
0144 t_is(mpc3.gen(ig, PG), -mpc0.bus(ib, PD), 12, [t 'PG = -PD']);
0145 t_is(mpc3.gen(ig, PMIN), -mpc0.bus(ib, PD), 12, [t 'PMIN = -PD']);
0146 t_is(mpc3.gen(ig, PMAX), 0, 12, [t 'PMAX = 0']);
0147 t_is(mpc3.gen(ig, QMIN), -mpc0.bus(ib, QD), 12, [t 'QMIN = -QD']);
0148 t_is(mpc3.gen(ig, QMAX), 0, 12, [t 'QMAX = 0']);
0149 t_is(mpc3.gen(ig, VG), r0.bus(ib, VM), 12, [t 'VG']);
0150 t_is(mpc3.gencost(ig, MODEL), 2, 12, [t 'gencost(:, MODEL)']);
0151 t_is(mpc3.gencost(ig, NCOST), 2, 12, [t 'gencost(:, NCOST)']);
0152 t_is(mpc3.gencost(ig, COST), 5000, 12, [t 'gencost(:, COST)']);
0153 t_ok(isfield(mpc3, 'gentype'), [t 'results.gentype']);
0154 t_ok(isfield(mpc3, 'genfuel'), [t 'results.genfuel']);
0155 if isfield(mpc3, 'gentype')
0156     t_ok(isequal(mpc3.gentype, {r0.gentype{:}, 'DL', 'DL', 'DL'}'), [t 'results.results.gentype']);
0157 else
0158     t_ok(0, [t 'results.results.gentype']);
0159     got = mpc3.gentype
0160     expected = {r0.gentype{:}, 'DL', 'DL', 'DL'}'
0161 end
0162 if isfield(mpc3, 'genfuel')
0163     t_ok(isequal(mpc3.genfuel, {r0.genfuel{:}, 'dl', 'dl', 'dl'}'), [t 'results.results.genfuel']);
0164 else
0165     t_ok(0, [t 'results.results.genfuel']);
0166     got = mpc3.genfuel
0167     expected = {r0.genfuel{:}, 'dl', 'dl', 'dl'}'
0168 end
0169 
0170 t = 'loadshed(mpc) : ';
0171 shed = loadshed(mpc3.gen);
0172 t_is(size(shed), [3 1], 12, [t 'size']);
0173 t_is(shed, [0;0;0], 12, [t 'all zeros']);
0174 
0175 t = 'loadshed(mpc, ild) : ';
0176 ild = [6; 5];
0177 shed = loadshed(mpc3.gen, ild);
0178 t_is(size(shed), [2 1], 12, [t 'size']);
0179 t_is(shed, [0;0], 12, [t 'all zeros']);
0180 
0181 ild = find(isload(mpc3.gen));
0182 mpc3.gen(ild, PG) = [-80; -100; -120];
0183 
0184 t = 'loadshed(mpc) : ';
0185 shed = loadshed(mpc3.gen);
0186 t_is(size(shed), [3 1], 12, [t 'size']);
0187 t_is(shed, [10;0;5], 12, [t 'all zeros']);
0188 
0189 t = 'loadshed(mpc, ild) : ';
0190 ild = [6; 5];
0191 shed = loadshed(mpc3.gen, ild);
0192 t_is(size(shed), [2 1], 12, [t 'size']);
0193 t_is(shed, [5;0], 12, [t 'all zeros']);
0194 
0195 if have_feature('octave')
0196     warning(s1.state, file_in_path_warn_id);
0197 end
0198 
0199 t_end;

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