Home > matpower7.1 > extras > syngrid > lib > t > t_syngrid.m

t_syngrid

PURPOSE ^

T_SYNGRID Tests for syngrid().

SYNOPSIS ^

function t_syngrid(quiet)

DESCRIPTION ^

T_SYNGRID  Tests for syngrid().

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function t_syngrid(quiet)
0002 %T_SYNGRID  Tests for syngrid().
0003 
0004 %   SynGrid
0005 %   Copyright (c) 2017-2018, Power Systems Engineering Research Center (PSERC)
0006 %   by Ray Zimmerman, PSERC Cornell
0007 %
0008 %   This file is part of SynGrid.
0009 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0010 
0011 %% define named indices into bus, gen, branch matrices
0012 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0013     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0014 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0015     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0016     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0017 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0018     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0019     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0020 
0021 if nargin < 1
0022     quiet = 0;
0023 end
0024 
0025 if have_fcn('octave')   %% currently SLOW, only do the smallest
0026     NN = [30];
0027 else
0028     NN = [30 150 300];
0029 end
0030 
0031 num_tests = 9*length(NN) + 6;
0032 if quiet
0033     verbose = 0;
0034 else
0035     verbose = 0;
0036 end
0037 mpopt = mpoption('out.all', 0, 'opf.dc.solver', 'MIPS', 'verbose', verbose);
0038 
0039 %% turn off warnings
0040 if have_fcn('octave')
0041     warn_id1 = 'Octave:nearly-singular-matrix';
0042     warn_id2 = 'Octave:singular-matrix';
0043     if have_fcn('octave', 'vnum') >= 4
0044         file_in_path_warn_id = 'Octave:data-file-in-path';
0045     else
0046         file_in_path_warn_id = 'Octave:load-file-in-path';
0047     end
0048     s3 = warning('query', file_in_path_warn_id);
0049     warning('off', file_in_path_warn_id);
0050 else
0051     warn_id1 = 'MATLAB:nearlySingularMatrix';
0052     warn_id2 = 'MATLAB:singularMatrix';
0053 end
0054 s1 = warning('query', warn_id1);
0055 s2 = warning('query', warn_id2);
0056 warning('off', warn_id1);
0057 warning('off', warn_id2);
0058 
0059 t_begin(num_tests, quiet);
0060 
0061 %% test syngrid(N)
0062 for k = 1:length(NN)
0063     N = NN(k);
0064     t = sprintf('syngrid(%d) : ', N);
0065     mpc = syngrid(N);
0066     nb = size(mpc.bus, 1);      %% number of buses
0067     t_is(nb, N, 12, [t 'number of buses']);
0068     
0069     br2b = size(mpc.branch, 1)./size(mpc.bus, 1);
0070     t_ok(br2b >= 1.25 && br2b <= 2.5, [t 'branch to bus ratio']);
0071     
0072     avg_ndg = 2 * br2b;
0073     t_ok(avg_ndg >= 2.5 && avg_ndg <= 5, [t 'average node degree']);
0074         
0075     ig = find(mpc.gen(:, GEN_STATUS) > 0);  %% online gens
0076     t_ok(sum(mpc.bus(:, PD)) < sum(mpc.gen(ig, PMAX)), [t 'gen adequacy']);
0077     
0078     r = rundcpf(mpc, mpopt);
0079     t_ok(r.success, [t 'DC PF success']);
0080     
0081     t_ok(all(r.gen(ig, PG) >= r.gen(ig, PMIN)), [t 'gen feasibility (Pmin)']);
0082     t_ok(all(r.gen(:,  PG) <= r.gen(:,  PMAX)), [t 'gen feasibility (Pmax)']);
0083     t_ok(all(abs(r.branch(:,  PT)) <= r.branch(:,  RATE_A)), [t 'no line overloads']);
0084 %     r = runpf(mpc, mpopt);
0085 %     t_ok(r.success, [t 'AC PF success']);
0086     
0087     r = rundcopf(mpc, mpopt);
0088     t_ok(r.success, [t 'DC OPF success']);
0089 end
0090 
0091 %% test saving to a file
0092 N = 25;
0093 fn = sprintf('case%dsg_%d', N, fix(1e9*rand));
0094 t = sprintf('syngrid(%d, [], ''%s'') : ', N, fn);
0095 syngrid(N, [], fn);
0096 t_ok(exist([fn '.m'], 'file') == 2, [t 'file created successfully']);
0097 mpc = loadcase(fn);
0098 delete([fn '.m']);
0099 nb = size(mpc.bus, 1);      %% number of buses
0100 t_is(nb, N, 12, [t 'number of buses']);
0101 
0102 %% test DC power flow solution for case created by SynGrid
0103 t = 't_sg_case100 : ';
0104 mpc = loadcase('t_sg_case100');
0105 expected = load('t_sg_case100_V');
0106 r = rundcpf(mpc, mpopt);
0107 t_ok(r.success, [t 'DC PF success']);
0108 V = r.bus(:, VM) .* exp(1j*r.bus(:, VA)*pi/180);
0109 t_is(V, expected.Vpf, 8, [t 'DC PF correct V']);
0110 
0111 %% test DC OPF solution for case created by SynGrid
0112 r = rundcopf(mpc, mpopt);
0113 t_ok(r.success, [t 'DC OPF success']);
0114 V = r.bus(:, VM) .* exp(1j*r.bus(:, VA)*pi/180);
0115 t_is(V, expected.Vopf, 8, [t 'DC OPF correct V']);
0116 
0117 t_end;
0118 
0119 %% turn warnings back on
0120 warning(s1.state, warn_id1);
0121 warning(s2.state, warn_id2);
0122 if have_fcn('octave')
0123     warning(s3.state, file_in_path_warn_id);
0124 end

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