Home > matpower7.1 > 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 = 65;
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 r = rundcopf(casefile, mpopt);
0038 mpc = ext2int(r);
0039 [baseMVA, bus, gen, branch] = deal(mpc.baseMVA, mpc.bus, mpc.gen, mpc.branch);
0040 % [baseMVA, bus, gen, gencost, branch, f, success, et] = ...
0041 %     rundcopf(casefile, mpopt);
0042 % [i2e, bus, gen, branch] = ext2int(bus, gen, branch);
0043 nb  = size(bus, 1);
0044 nbr = size(branch, 1);
0045 ng  = size(gen, 1);
0046 
0047 %% compute injections and flows
0048 Cg = sparse(gen(:, GEN_BUS), (1:ng)', ones(ng, 1), nb, ng);
0049 Pg = Cg * gen(:, PG);
0050 Pd = bus(:, PD);
0051 P  = Pg - Pd;
0052 ig = find(P > 0);
0053 il = find(P <= 0);
0054 F  = branch(:, PF);
0055 
0056 %% create corresponding slack distribution matrices
0057 e1 = zeros(nb, 1);  e1(1) = 1;
0058 e4 = zeros(nb, 1);  e4(4) = 1;
0059 D1  = eye(nb, nb) - e1 * ones(1, nb);
0060 D4  = eye(nb, nb) - e4 * ones(1, nb);
0061 Deq = eye(nb, nb) - ones(nb, 1) / nb * ones(1, nb);
0062 Dd  = eye(nb) - Pd/sum(Pd) * ones(1, nb);
0063 Dg  = eye(nb) - Pg/sum(Pg) * ones(1, nb);
0064 
0065 %% create some PTDF matrices
0066 H   = makePTDF(baseMVA, bus, branch);
0067 H1  = makePTDF(baseMVA, bus, branch, 1);
0068 H4  = makePTDF(baseMVA, bus, branch, 4);
0069 Heq = makePTDF(baseMVA, bus, branch, ones(nb, 1));
0070 Hd  = makePTDF(baseMVA, bus, branch, Pd);
0071 Hg  = makePTDF(baseMVA, bus, branch, Pg);
0072 
0073 %% default slack
0074 t_is(H, H1, 12, 'default slack');
0075 
0076 %% using mpc
0077 t_is(makePTDF(mpc), H, 12, 'MPC : default slack');
0078 t_is(makePTDF(mpc, 1), H1, 12, 'H1 (from MPC)');
0079 t_is(makePTDF(mpc, 4), H4, 12, 'H4 (from MPC)');
0080 t_is(makePTDF(mpc, ones(nb,1)), Heq, 12, 'Heq (from MPC)');
0081 t_is(makePTDF(mpc, Pd), Hd, 12, 'Hd (from MPC)');
0082 t_is(makePTDF(mpc, Pg), Hg, 12, 'Hg (from MPC)');
0083 
0084 %% vector slack same as scalar, using mpc
0085 t_is(H1, makePTDF(mpc, e1), 12, 'H1 (scalar slack) = H1 (vector slack)');
0086 t_is(H4, makePTDF(mpc, e4), 12, 'H4 (scalar slack) = H4 (vector slack)');
0087 
0088 %% matrices get properly transformed by slack dist matrices
0089 t_is(H1,  H1 * D1, 8,  'H1  == H1 * D1');
0090 t_is(H4,  H1 * D4, 8,  'H4  == H1 * D4');
0091 t_is(Heq, H1 * Deq, 8, 'Heq == H1 * Deq');
0092 t_is(Hd,  H1 * Dd, 8,  'Hd  == H1 * Dd');
0093 t_is(Hg,  H1 * Dg, 8,  'Hg  == H1 * Dg');
0094 t_is(H1,  Heq * D1, 8,  'H1  == Heq * D1');
0095 t_is(H4,  Heq * D4, 8,  'H4  == Heq * D4');
0096 t_is(Heq, Heq * Deq, 8, 'Heq == Heq * Deq');
0097 t_is(Hd,  Heq * Dd, 8,  'Hd  == Heq * Dd');
0098 t_is(Hg,  Heq * Dg, 8,  'Hg  == Heq * Dg');
0099 t_is(H1,  Hd * D1, 8,  'H1  == Hd * D1');
0100 t_is(H4,  Hd * D4, 8,  'H4  == Hd * D4');
0101 t_is(Heq, Hd * Deq, 8, 'Heq == Hd * Deq');
0102 t_is(Hd,  Hd * Dd, 8,  'Hd  == Hd * Dd');
0103 t_is(Hg,  Hd * Dg, 8,  'Hg  == Hd * Dg');
0104 
0105 %% PTDFs can reconstruct flows
0106 t_is(F,  H1 * P,  3,  'Flow == H1  * P');
0107 t_is(F,  H4 * P,  3,  'Flow == H4  * P');
0108 t_is(F,  Heq * P, 3,  'Flow == Heq * P');
0109 t_is(F,  Hd * P,  3,  'Flow == Hd  * P');
0110 t_is(F,  Hg * P,  3,  'Flow == Hg  * P');
0111 
0112 %% other
0113 t_is(F,  Hd * Pg,  3,  'Flow == Hd  * Pg');
0114 t_is(F,  Hg * (-Pd),  3,  'Flow == Hg  * (-Pd)');
0115 t_is(zeros(nbr,1),  Hd * (-Pd),  3,  'zeros == Hd  * (-Pd)');
0116 t_is(zeros(nbr,1),  Hg * Pg,  3,  'zeros == Hg  * Pg');
0117 
0118 %% single column, single slack
0119 for k = 1:nb
0120     Hk = makePTDF(baseMVA, bus, branch, 1, k);
0121     t_is(Hk, H1(:, k), 12, sprintf('H1 : column %d', k));
0122 end
0123 for k = 1:nb
0124     Hk = makePTDF(mpc, 4, k);
0125     t_is(Hk, H4(:, k), 12, sprintf('H4 : column %d', k));
0126 end
0127 
0128 %% multiple columns, distributed slack
0129 Hk = makePTDF(baseMVA, bus, branch, ones(nb, 1), (1:nb)');
0130 t_is(Hk, Heq, 12, 'Heq : all columns');
0131 
0132 Hk = makePTDF(mpc, Pd, find(Pd));
0133 t_is(Hk, Hd(:, find(Pd)), 12, 'Hd : Pd columns');
0134 
0135 Hk = makePTDF(baseMVA, bus, branch, Pg, find(Pg));
0136 t_is(Hk, Hg(:, find(Pg)), 12, 'Hg : Pg columns');
0137 
0138 %% specific transfers
0139 for k = 1:nb
0140     txfr = zeros(nb, 1);    txfr(4) = -1;   txfr(k) = txfr(k) + 1;
0141     H = makePTDF(mpc, 4, txfr);
0142     t_is(H, H4(:, k), 12, sprintf('H4 (txfr) : column %d', k));
0143 end
0144 txfr = eye(9,9); txfr(1, :) = txfr(1, :) - 1;
0145 H = makePTDF(mpc, 1, txfr);
0146 t_is(H, H1, 12, sprintf('H1 (txfr) : full', k));
0147 txfr = eye(9,9); txfr(4, :) = txfr(4, :) - 1;
0148 H = makePTDF(mpc, 4, txfr);
0149 t_is(H, H4, 12, sprintf('H4 (txfr) : full', k));
0150 
0151 t_end;

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