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

t_makePTDF

PURPOSE ^

T_MAKEPTDF Tests for MAKEPTDF.

SYNOPSIS ^

function t_makePTDF(quiet)

DESCRIPTION ^

T_MAKEPTDF  Tests for MAKEPTDF.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function t_makePTDF(quiet)
0002 %T_MAKEPTDF  Tests for MAKEPTDF.
0003 
0004 %   MATPOWER
0005 %   Copyright (c) 2006-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 ntests = 24;
0017 t_begin(ntests, quiet);
0018 
0019 casefile = 't_case9_opf';
0020 if quiet
0021     verbose = 0;
0022 else
0023     verbose = 0;
0024 end
0025 
0026 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0027     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0028 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0029     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0030     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0031 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0032     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0033     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0034 
0035 %% load case
0036 mpopt = mpoption('out.all', 0, 'verbose', verbose);
0037 [baseMVA, bus, gen, gencost, branch, f, success, et] = ...
0038     rundcopf(casefile, mpopt);
0039 [i2e, bus, gen, branch] = ext2int(bus, gen, branch);
0040 nb  = size(bus, 1);
0041 nbr = size(branch, 1);
0042 ng  = size(gen, 1);
0043 
0044 %% compute injections and flows
0045 Cg = sparse(gen(:, GEN_BUS), (1:ng)', ones(ng, 1), nb, ng);
0046 Pg = Cg * gen(:, PG);
0047 Pd = bus(:, PD);
0048 P  = Pg - Pd;
0049 ig = find(P > 0);
0050 il = find(P <= 0);
0051 F  = branch(:, PF);
0052 
0053 %% create corresponding slack distribution matrices
0054 e1 = zeros(nb, 1);  e1(1) = 1;
0055 e4 = zeros(nb, 1);  e4(4) = 1;
0056 D1  = eye(nb, nb) - e1 * ones(1, nb);
0057 D4  = eye(nb, nb) - e4 * ones(1, nb);
0058 Deq = eye(nb, nb) - ones(nb, 1) / nb * ones(1, nb);
0059 Dg  = eye(nb) - Pd/sum(Pd) * ones(1, nb);
0060 Dd  = eye(nb) - Pg/sum(Pg) * ones(1, nb);
0061 
0062 %% create some PTDF matrices
0063 H1  = makePTDF(baseMVA, bus, branch, 1);
0064 H4  = makePTDF(baseMVA, bus, branch, 4);
0065 Heq = makePTDF(baseMVA, bus, branch, ones(nb, 1));
0066 Hg  = makePTDF(baseMVA, bus, branch, Pd);
0067 Hd  = makePTDF(baseMVA, bus, branch, Pg);
0068 
0069 %% matrices get properly transformed by slack dist matrices
0070 t_is(H1,  H1 * D1, 8,  'H1  == H1 * D1');
0071 t_is(H4,  H1 * D4, 8,  'H4  == H1 * D4');
0072 t_is(Heq, H1 * Deq, 8, 'Heq == H1 * Deq');
0073 t_is(Hg,  H1 * Dg, 8,  'Hg  == H1 * Dg');
0074 t_is(Hd,  H1 * Dd, 8,  'Hd  == H1 * Dd');
0075 t_is(H1,  Heq * D1, 8,  'H1  == Heq * D1');
0076 t_is(H4,  Heq * D4, 8,  'H4  == Heq * D4');
0077 t_is(Heq, Heq * Deq, 8, 'Heq == Heq * Deq');
0078 t_is(Hg,  Heq * Dg, 8,  'Hg  == Heq * Dg');
0079 t_is(Hd,  Heq * Dd, 8,  'Hd  == Heq * Dd');
0080 t_is(H1,  Hg * D1, 8,  'H1  == Hg * D1');
0081 t_is(H4,  Hg * D4, 8,  'H4  == Hg * D4');
0082 t_is(Heq, Hg * Deq, 8, 'Heq == Hg * Deq');
0083 t_is(Hg,  Hg * Dg, 8,  'Hg  == Hg * Dg');
0084 t_is(Hd,  Hg * Dd, 8,  'Hd  == Hg * Dd');
0085 
0086 %% PTDFs can reconstruct flows
0087 t_is(F,  H1 * P,  3,  'Flow == H1  * P');
0088 t_is(F,  H4 * P,  3,  'Flow == H4  * P');
0089 t_is(F,  Heq * P, 3,  'Flow == Heq * P');
0090 t_is(F,  Hg * P,  3,  'Flow == Hg  * P');
0091 t_is(F,  Hd * P,  3,  'Flow == Hd  * P');
0092 
0093 %% other
0094 t_is(F,  Hg * Pg,  3,  'Flow == Hg  * Pg');
0095 t_is(F,  Hd * (-Pd),  3,  'Flow == Hd  * (-Pd)');
0096 t_is(zeros(nbr,1),  Hg * (-Pd),  3,  'zeros == Hg  * (-Pd)');
0097 t_is(zeros(nbr,1),  Hd * Pg,  3,  'zeros == Hd  * Pg');
0098 
0099 t_end;

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