Home > matpower5.1 > 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-2015 by Power System Engineering Research Center (PSERC)
0006 %   by Ray Zimmerman, PSERC Cornell
0007 %
0008 %   $Id: t_makePTDF.m 2644 2015-03-11 19:34:22Z ray $
0009 %
0010 %   This file is part of MATPOWER.
0011 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0012 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0013 
0014 if nargin < 1
0015     quiet = 0;
0016 end
0017 
0018 ntests = 24;
0019 t_begin(ntests, quiet);
0020 
0021 casefile = 't_case9_opf';
0022 if quiet
0023     verbose = 0;
0024 else
0025     verbose = 0;
0026 end
0027 
0028 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0029     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0030 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0031     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0032     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0033 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0034     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0035     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0036 
0037 %% load case
0038 mpopt = mpoption('out.all', 0, 'verbose', verbose);
0039 [baseMVA, bus, gen, gencost, branch, f, success, et] = ...
0040     rundcopf(casefile, mpopt);
0041 [i2e, bus, gen, branch] = ext2int(bus, gen, branch);
0042 nb  = size(bus, 1);
0043 nbr = size(branch, 1);
0044 ng  = size(gen, 1);
0045 
0046 %% compute injections and flows
0047 Cg = sparse(gen(:, GEN_BUS), (1:ng)', ones(ng, 1), nb, ng);
0048 Pg = Cg * gen(:, PG);
0049 Pd = bus(:, PD);
0050 P  = Pg - Pd;
0051 ig = find(P > 0);
0052 il = find(P <= 0);
0053 F  = branch(:, PF);
0054 
0055 %% create corresponding slack distribution matrices
0056 e1 = zeros(nb, 1);  e1(1) = 1;
0057 e4 = zeros(nb, 1);  e4(4) = 1;
0058 D1  = eye(nb, nb) - e1 * ones(1, nb);
0059 D4  = eye(nb, nb) - e4 * ones(1, nb);
0060 Deq = eye(nb, nb) - ones(nb, 1) / nb * ones(1, nb);
0061 Dg  = eye(nb) - Pd/sum(Pd) * ones(1, nb);
0062 Dd  = eye(nb) - Pg/sum(Pg) * ones(1, nb);
0063 
0064 %% create some PTDF matrices
0065 H1  = makePTDF(baseMVA, bus, branch, 1);
0066 H4  = makePTDF(baseMVA, bus, branch, 4);
0067 Heq = makePTDF(baseMVA, bus, branch, ones(nb, 1));
0068 Hg  = makePTDF(baseMVA, bus, branch, Pd);
0069 Hd  = makePTDF(baseMVA, bus, branch, Pg);
0070 
0071 %% matrices get properly transformed by slack dist matrices
0072 t_is(H1,  H1 * D1, 8,  'H1  == H1 * D1');
0073 t_is(H4,  H1 * D4, 8,  'H4  == H1 * D4');
0074 t_is(Heq, H1 * Deq, 8, 'Heq == H1 * Deq');
0075 t_is(Hg,  H1 * Dg, 8,  'Hg  == H1 * Dg');
0076 t_is(Hd,  H1 * Dd, 8,  'Hd  == H1 * Dd');
0077 t_is(H1,  Heq * D1, 8,  'H1  == Heq * D1');
0078 t_is(H4,  Heq * D4, 8,  'H4  == Heq * D4');
0079 t_is(Heq, Heq * Deq, 8, 'Heq == Heq * Deq');
0080 t_is(Hg,  Heq * Dg, 8,  'Hg  == Heq * Dg');
0081 t_is(Hd,  Heq * Dd, 8,  'Hd  == Heq * Dd');
0082 t_is(H1,  Hg * D1, 8,  'H1  == Hg * D1');
0083 t_is(H4,  Hg * D4, 8,  'H4  == Hg * D4');
0084 t_is(Heq, Hg * Deq, 8, 'Heq == Hg * Deq');
0085 t_is(Hg,  Hg * Dg, 8,  'Hg  == Hg * Dg');
0086 t_is(Hd,  Hg * Dd, 8,  'Hd  == Hg * Dd');
0087 
0088 %% PTDFs can reconstruct flows
0089 t_is(F,  H1 * P,  3,  'Flow == H1  * P');
0090 t_is(F,  H4 * P,  3,  'Flow == H4  * P');
0091 t_is(F,  Heq * P, 3,  'Flow == Heq * P');
0092 t_is(F,  Hg * P,  3,  'Flow == Hg  * P');
0093 t_is(F,  Hd * P,  3,  'Flow == Hd  * P');
0094 
0095 %% other
0096 t_is(F,  Hg * Pg,  3,  'Flow == Hg  * Pg');
0097 t_is(F,  Hd * (-Pd),  3,  'Flow == Hd  * (-Pd)');
0098 t_is(zeros(nbr,1),  Hg * (-Pd),  3,  'zeros == Hg  * (-Pd)');
0099 t_is(zeros(nbr,1),  Hd * Pg,  3,  'zeros == Hd  * Pg');
0100 
0101 t_end;

Generated on Fri 20-Mar-2015 18:23:34 by m2html © 2005