0001 function t_makePTDF(quiet)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
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
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
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
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
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
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
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
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;