Home > matpower7.1 > extras > maxloadlim > tests > t_varGen_case39.m

t_varGen_case39

PURPOSE ^

This function tests the implementation of the variable generators in the

SYNOPSIS ^

function t_varGen_case39(quiet)

DESCRIPTION ^

 This function tests the implementation of the variable generators in the
 IEEE 39 bus system

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function t_varGen_case39(quiet)
0002 % This function tests the implementation of the variable generators in the
0003 % IEEE 39 bus system
0004 
0005 %   MATPOWER
0006 %   Copyright (c) 2015-2016, Power Systems Engineering Research Center (PSERC)
0007 %   by Camille Hamon
0008 %
0009 %   This file is part of MATPOWER/mx-maxloadlim.
0010 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0011 %   See https://github.com/MATPOWER/mx-maxloadlim/ for more info.
0012 
0013 if nargin < 1
0014     quiet = 0;
0015 end
0016 define_constants;
0017 % Loading the case
0018 mpc = loadcase('case39');
0019 
0020 % Defining several load increase directions to be tested
0021 dir_all = [eye(39);ones(1,39)];
0022 dir_var_gen_all = [zeros(9,1) eye(9);0 ones(1,9)];
0023 dir_var_gen_all(:,[1 2]) = dir_var_gen_all(:,[2 1]); % Put the slack gen at the right position
0024 idx_nonzero_loads = mpc.bus(:,PD) > 0;
0025 % Number of load increase directions
0026 nb_dir_load = size(dir_all,1);
0027 nb_dir_gen = size(dir_var_gen_all,1);
0028 % Message header
0029 t0 = 'case39: ';
0030 
0031 num_tests = nb_dir_load*nb_dir_gen; % we don't consider the direction with all zeros
0032 t_begin(num_tests, quiet);
0033 for i = 1:nb_dir_load
0034     dir_load = dir_all(i,:)';
0035     dir_load(~idx_nonzero_loads)=0;
0036     for j = 1:nb_dir_gen
0037         if sum(dir_load) == 0 || dir_load(31) ~= 0
0038             % The code does not currently support load increase at
0039             % nonzero loads or at the slack bus
0040             t = sprintf('%s All load zeros',t0);
0041             t_skip(1, t);
0042         else
0043             dir_var_gen = dir_var_gen_all(j,:)';
0044             idx_var_gen = find(dir_var_gen);
0045             dir_var_gen = dir_var_gen(idx_var_gen);
0046             % Normalizing with respect to both loads and gens
0047             gen_load_dir = [dir_load;dir_var_gen];
0048             dir_load = dir_load/norm(gen_load_dir);
0049             dir_var_gen = dir_var_gen/norm(gen_load_dir);
0050             % Find MLL in the direction of load and gen increase
0051             results_with_gens = maxloadlim(mpc,dir_load,'verbose',0,'idx_var_gen',idx_var_gen,'dir_var_gen',dir_var_gen);
0052             % Set gens to their values in previous results and re-run in
0053             % load space only
0054             mpc2 = mpc;
0055             mpc2.gen(:,PG) = results_with_gens.gen(:,PG);
0056             dir_load2 = dir_load/norm(dir_load);
0057             % Find MLL in the direction of load and gen increase
0058             results_without_gens = maxloadlim(mpc2,dir_load2,'verbose',0);
0059             % Compare the maximum loads
0060             mll_with_gen = results_with_gens.bus(:,PD);
0061             mll_without_gen = results_without_gens.bus(:,PD);
0062             % We compare with a precision of 1MW
0063             t = sprintf('%sLOAD: %s   GEN: %s',t0,mat2str(dir_load),mat2str(dir_var_gen));
0064             if i == 20 && j == 1
0065                 t_skip(1, sprintf('%s - KNOWN MISMATCH: (%.2f, %.2f)', t, mll_with_gen(20), mll_without_gen(20)));
0066             else
0067                 ok = t_is(mll_with_gen,mll_without_gen,0,t);
0068             end
0069         end
0070     end
0071 end
0072 t_end

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