Home > matpower4.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 %   $Id: t_makePTDF.m,v 1.11 2010/04/26 19:45:26 ray Exp $
0006 %   by Ray Zimmerman, PSERC Cornell
0007 %   Copyright (c) 2006-2010 by Power System Engineering Research Center (PSERC)
0008 %
0009 %   This file is part of MATPOWER.
0010 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0011 %
0012 %   MATPOWER is free software: you can redistribute it and/or modify
0013 %   it under the terms of the GNU General Public License as published
0014 %   by the Free Software Foundation, either version 3 of the License,
0015 %   or (at your option) any later version.
0016 %
0017 %   MATPOWER is distributed in the hope that it will be useful,
0018 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0019 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0020 %   GNU General Public License for more details.
0021 %
0022 %   You should have received a copy of the GNU General Public License
0023 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0024 %
0025 %   Additional permission under GNU GPL version 3 section 7
0026 %
0027 %   If you modify MATPOWER, or any covered work, to interface with
0028 %   other modules (such as MATLAB code and MEX-files) available in a
0029 %   MATLAB(R) or comparable environment containing parts covered
0030 %   under other licensing terms, the licensors of MATPOWER grant
0031 %   you additional permission to convey the resulting work.
0032 
0033 if nargin < 1
0034     quiet = 0;
0035 end
0036 
0037 ntests = 24;
0038 t_begin(ntests, quiet);
0039 
0040 casefile = 't_case9_opf';
0041 if quiet
0042     verbose = 0;
0043 else
0044     verbose = 0;
0045 end
0046 
0047 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0048     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0049 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0050     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0051     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0052 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0053     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0054     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0055 
0056 %% load case
0057 mpopt = mpoption('OUT_ALL', 0, 'VERBOSE', verbose);
0058 [baseMVA, bus, gen, gencost, branch, f, success, et] = ...
0059     rundcopf(casefile, mpopt);
0060 [i2e, bus, gen, branch] = ext2int(bus, gen, branch);
0061 nb  = size(bus, 1);
0062 nbr = size(branch, 1);
0063 ng  = size(gen, 1);
0064 
0065 %% compute injections and flows
0066 Cg = sparse(gen(:, GEN_BUS), (1:ng)', ones(ng, 1), nb, ng);
0067 Pg = Cg * gen(:, PG);
0068 Pd = bus(:, PD);
0069 P  = Pg - Pd;
0070 ig = find(P > 0);
0071 il = find(P <= 0);
0072 F  = branch(:, PF);
0073 
0074 %% create corresponding slack distribution matrices
0075 e1 = zeros(nb, 1);  e1(1) = 1;
0076 e4 = zeros(nb, 1);  e4(4) = 1;
0077 D1  = eye(nb, nb) - e1 * ones(1, nb);
0078 D4  = eye(nb, nb) - e4 * ones(1, nb);
0079 Deq = eye(nb, nb) - ones(nb, 1) / nb * ones(1, nb);
0080 Dg  = eye(nb) - Pd/sum(Pd) * ones(1, nb);
0081 Dd  = eye(nb) - Pg/sum(Pg) * ones(1, nb);
0082 
0083 %% create some PTDF matrices
0084 H1  = makePTDF(baseMVA, bus, branch, 1);
0085 H4  = makePTDF(baseMVA, bus, branch, 4);
0086 Heq = makePTDF(baseMVA, bus, branch, ones(nb, 1));
0087 Hg  = makePTDF(baseMVA, bus, branch, Pd);
0088 Hd  = makePTDF(baseMVA, bus, branch, Pg);
0089 
0090 %% matrices get properly transformed by slack dist matrices
0091 t_is(H1,  H1 * D1, 8,  'H1  == H1 * D1');
0092 t_is(H4,  H1 * D4, 8,  'H4  == H1 * D4');
0093 t_is(Heq, H1 * Deq, 8, 'Heq == H1 * Deq');
0094 t_is(Hg,  H1 * Dg, 8,  'Hg  == H1 * Dg');
0095 t_is(Hd,  H1 * Dd, 8,  'Hd  == H1 * Dd');
0096 t_is(H1,  Heq * D1, 8,  'H1  == Heq * D1');
0097 t_is(H4,  Heq * D4, 8,  'H4  == Heq * D4');
0098 t_is(Heq, Heq * Deq, 8, 'Heq == Heq * Deq');
0099 t_is(Hg,  Heq * Dg, 8,  'Hg  == Heq * Dg');
0100 t_is(Hd,  Heq * Dd, 8,  'Hd  == Heq * Dd');
0101 t_is(H1,  Hg * D1, 8,  'H1  == Hg * D1');
0102 t_is(H4,  Hg * D4, 8,  'H4  == Hg * D4');
0103 t_is(Heq, Hg * Deq, 8, 'Heq == Hg * Deq');
0104 t_is(Hg,  Hg * Dg, 8,  'Hg  == Hg * Dg');
0105 t_is(Hd,  Hg * Dd, 8,  'Hd  == Hg * Dd');
0106 
0107 %% PTDFs can reconstruct flows
0108 t_is(F,  H1 * P,  3,  'Flow == H1  * P');
0109 t_is(F,  H4 * P,  3,  'Flow == H4  * P');
0110 t_is(F,  Heq * P, 3,  'Flow == Heq * P');
0111 t_is(F,  Hg * P,  3,  'Flow == Hg  * P');
0112 t_is(F,  Hd * P,  3,  'Flow == Hd  * P');
0113 
0114 %% other
0115 t_is(F,  Hg * Pg,  3,  'Flow == Hg  * Pg');
0116 t_is(F,  Hd * (-Pd),  3,  'Flow == Hd  * (-Pd)');
0117 t_is(zeros(nbr,1),  Hg * (-Pd),  3,  'zeros == Hg  * (-Pd)');
0118 t_is(zeros(nbr,1),  Hd * Pg,  3,  'zeros == Hd  * Pg');
0119 
0120 t_end;

Generated on Mon 26-Jan-2015 15:00:13 by m2html © 2005