0001 function t_makePTDF(quiet)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
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
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
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
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
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
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
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
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;