0001 function [xfmr, bus, warns, bus_name] = psse_convert_xfmr(warns, trans2, trans3, verbose, baseMVA, bus, bus_name)
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
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0069 VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0070 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0071 TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0072 ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0073
0074
0075 nb = size(bus, 1);
0076 nt2 = size(trans2, 1);
0077 nt3 = size(trans3, 1);
0078
0079
0080 starbus = zeros(nt3, VMIN);
0081 if nt3 > 0
0082 mb = max(bus(:, BUS_I));
0083 b = 10^ceil(log10(mb+1));
0084 wind1bus = trans3(:,1);
0085 e2i = sparse(bus(:, BUS_I), ones(nb, 1), 1:nb, max(bus(:, BUS_I)), 1);
0086 starbus(:, BUS_I) = (b+1:b+nt3)';
0087 starbus(:, BUS_TYPE) = PQ;
0088 starbus(trans3(:,12)==0, BUS_TYPE) = NONE;
0089 starbus(:, VA) = trans3(:,31);
0090 starbus(:, VM) = trans3(:,30);
0091 starbus(:, [BUS_AREA, ZONE]) = bus(e2i(wind1bus), [7,11]);
0092 starbus(:, BASE_KV) = 1;
0093 starbus(:, VMAX) = 1.1;
0094 starbus(:, VMIN) = 0.9;
0095 end
0096
0097
0098 [tf,fbus] = ismember(trans2(:,1), bus(:, BUS_I));
0099 [tf,tbus] = ismember(trans2(:,2), bus(:, BUS_I));
0100
0101 k = find(fbus == 0 | tbus == 0);
0102 if ~isempty(k)
0103 warns{end+1} = sprintf('Ignoring %d two-winding transformers with bad bus numbers', length(k));
0104 if verbose
0105 fprintf('WARNING: Ignoring %d two-winding transformers with bad bus numbers', length(k));
0106 end
0107 fbus(k) = [];
0108 tbus(k) = [];
0109 trans2(k, :) = [];
0110 nt2 = nt2 - length(k);
0111 end
0112 Zbs = bus(:, BASE_KV).^2 / baseMVA;
0113 if nt2 > 0
0114 cw2 = find(trans2(:,5) == 2);
0115 cw3 = find(trans2(:,5) == 3);
0116 cw23 = [cw2;cw3];
0117 cz2 = find(trans2(:,6) == 2);
0118 cz3 = find(trans2(:,6) == 3);
0119 cz23 = [cz2;cz3];
0120
0121 R = trans2(:,21);
0122 X = trans2(:,22);
0123 Zb = ones(nt2, 1);
0124 Zb(cz23) = trans2(cz23,25).^2 ./ trans2(cz23,23);
0125 R(cz2) = R(cz2) .* Zb(cz2) ./ Zbs(fbus(cz2));
0126 X(cz23) = X(cz23) .* Zb(cz23) ./ Zbs(fbus(cz23));
0127 R(cz3) = trans2(cz3,25).^2 ./ trans2(cz3,21) ./ Zbs(fbus(cz3));
0128 tap = trans2(:,24) ./ trans2(:,40);
0129 tap(cw23) = tap(cw23) .* bus(tbus(cw23), BASE_KV)./bus(fbus(cw23), BASE_KV);
0130 tap(cw3) = tap(cw3) .* trans2(cw3,25)./trans2(cw3,41);
0131 shift = trans2(:, 26);
0132 end
0133
0134
0135 [tf,ind1] = ismember(trans3(:,1), bus(:, BUS_I));
0136 [tf,ind2] = ismember(trans3(:,2), bus(:, BUS_I));
0137 [tf,ind3] = ismember(trans3(:,3), bus(:, BUS_I));
0138
0139 k = find(ind1 == 0 | ind2 == 0 | ind3 == 0);
0140 if ~isempty(k)
0141 warns{end+1} = sprintf('Ignoring %d three-winding transformers with bad bus numbers', length(k));
0142 if verbose
0143 fprintf('WARNING: Ignoring %d three-winding transformers with bad bus numbers', length(k));
0144 end
0145 ind1(k) = [];
0146 ind2(k) = [];
0147 ind3(k) = [];
0148 trans3(k, :) = [];
0149 starbus(k, :) = [];
0150 nt3 = nt3 - length(k);
0151 end
0152
0153
0154
0155
0156
0157 if nt3 > 0
0158 cw2 = find(trans3(:,5) == 2);
0159 cw3 = find(trans3(:,5) == 3);
0160 cw23 = [cw2;cw3];
0161 cz2 = find(trans3(:,6) == 2);
0162 cz3 = find(trans3(:,6) == 3);
0163 cz23 = [cz2;cz3];
0164
0165 tap1 = trans3(:, 32);
0166 tap2 = trans3(:, 48);
0167 tap3 = trans3(:, 64);
0168 tap1(cw23) = tap1(cw23) ./ bus(ind1(cw23), BASE_KV);
0169 tap2(cw23) = tap2(cw23) ./ bus(ind2(cw23), BASE_KV);
0170 tap3(cw23) = tap3(cw23) ./ bus(ind3(cw23), BASE_KV);
0171 tap1(cw3) = tap1(cw3) .* trans3(cw3, 33);
0172 tap2(cw3) = tap2(cw3) .* trans3(cw3, 49);
0173 tap3(cw3) = tap3(cw3) .* trans3(cw3, 65);
0174 shift1 = trans3(:, 34);
0175 shift2 = trans3(:, 50);
0176 shift3 = trans3(:, 66);
0177
0178 trans3(cz3, 33) = bus(ind1(cz3), BASE_KV);
0179 trans3(cz3, 49) = bus(ind1(cz3), BASE_KV);
0180 trans3(cz3, 65) = bus(ind1(cz3), BASE_KV);
0181
0182 R12 = trans3(:, 21);
0183 X12 = trans3(:, 22);
0184 R23 = trans3(:, 24);
0185 X23 = trans3(:, 25);
0186 R31 = trans3(:, 27);
0187 X31 = trans3(:, 28);
0188 Zb1 = trans3(:, 33).^2 ./ trans3(:, 23);
0189 Zb2 = trans3(:, 49).^2 ./ trans3(:, 26);
0190 Zb3 = trans3(:, 65).^2 ./ trans3(:, 29);
0191
0192 R12(cz2) = R12(cz2) .* Zb1(cz2) ./ Zbs(ind1(cz2));
0193 X12(cz2) = X12(cz2) .* Zb1(cz2) ./ Zbs(ind1(cz2));
0194 R23(cz2) = R23(cz2) .* Zb2(cz2) ./ Zbs(ind2(cz2));
0195 X23(cz2) = X23(cz2) .* Zb2(cz2) ./ Zbs(ind2(cz2));
0196 R31(cz2) = R31(cz2) .* Zb3(cz2) ./ Zbs(ind3(cz2));
0197 X31(cz2) = X31(cz2) .* Zb3(cz2) ./ Zbs(ind3(cz2));
0198
0199 R12(cz3) = (trans3(cz3,33)*1000) .^ 2 ./ trans3(cz3,21) ./ Zbs(ind1(cz3));
0200 X12(cz3) = trans3(cz3,22) .* Zb1(cz3) ./ Zbs(ind3(cz3));
0201 R23(cz3) = (trans3(cz3,49)*1000) .^ 2 ./ trans3(cz3,24) ./ Zbs(ind2(cz3));
0202 X23(cz3) = trans3(cz3,25) .* Zb2(cz3) ./ Zbs(ind3(cz3));
0203 R31(cz3) = (trans3(cz3,65)*1000) .^ 2 ./ trans3(cz3,27) ./ Zbs(ind3(cz3));
0204 X31(cz3) = trans3(cz3,28) .* Zb3(cz3) ./ Zbs(ind3(cz3));
0205
0206 R1 = (R12+R31-R23) ./ 2;
0207 R2 = (R12+R23-R31) ./ 2;
0208 R3 = (R31+R23-R12) ./ 2;
0209 X1 = (X12+X31-X23) ./ 2;
0210 X2 = (X12+X23-X31) ./ 2;
0211 X3 = (X31+X23-X12) ./ 2;
0212 end
0213
0214
0215
0216 xfmr2 = zeros(nt2, ANGMAX);
0217 if nt2 > 0
0218 xfmr2(:, [F_BUS T_BUS]) = trans2(:,[1,2]);
0219 xfmr2(:, [BR_R BR_X TAP SHIFT]) = [R X tap shift];
0220 xfmr2(:, [RATE_A RATE_B RATE_C]) = trans2(:,[27,28,29]);
0221 xfmr2(:, BR_STATUS) = trans2(:,12);
0222 xfmr2(:, ANGMIN) = -360;
0223 xfmr2(:, ANGMAX) = 360;
0224 end
0225
0226
0227 xfmr3 = zeros(3*nt3, ANGMAX);
0228 if nt3 > 0
0229 idx1 = (1:3:3*nt3)';
0230 idx2 = idx1+1;
0231 idx3 = idx1+2;
0232
0233 xfmr3(idx1, [F_BUS T_BUS]) = [trans3(:,1), starbus(:,1)];
0234 xfmr3(idx2, [F_BUS T_BUS]) = [trans3(:,2), starbus(:,1)];
0235 xfmr3(idx3, [F_BUS T_BUS]) = [trans3(:,3), starbus(:,1)];
0236
0237 xfmr3(idx1, [BR_R BR_X TAP SHIFT]) = [R1 X1 tap1 shift1];
0238 xfmr3(idx2, [BR_R BR_X TAP SHIFT]) = [R2 X2 tap2 shift2];
0239 xfmr3(idx3, [BR_R BR_X TAP SHIFT]) = [R3 X3 tap3 shift3];
0240
0241 xfmr3(idx1, [RATE_A RATE_B RATE_C]) = trans3(:,[35,36,37]);
0242 xfmr3(idx2, [RATE_A RATE_B RATE_C]) = trans3(:,[51,52,53]);
0243 xfmr3(idx3, [RATE_A RATE_B RATE_C]) = trans3(:,[67,68,69]);
0244 xfmr3(:, ANGMIN) = -360;
0245 xfmr3(:, ANGMAX) = 360;
0246
0247 xfmr3(:, BR_STATUS) = 1;
0248 status = trans3(:, 12);
0249 k1 = find(status == 0 | status == 4);
0250 k2 = find(status == 0 | status == 2);
0251 k3 = find(status == 0 | status == 3);
0252 if ~isempty(k1)
0253 xfmr3(idx1(k1), BR_STATUS) = 0;
0254 end
0255 if ~isempty(k2)
0256 xfmr3(idx2(k2), BR_STATUS) = 0;
0257 end
0258 if ~isempty(k3)
0259 xfmr3(idx3(k3), BR_STATUS) = 0;
0260 end
0261 end
0262
0263
0264 xfmr = [xfmr2; xfmr3];
0265
0266
0267
0268
0269
0270
0271
0272
0273 bus = [bus; starbus];
0274 if nt3 > 0
0275 warns{end+1} = sprintf('Added buses %d-%d as star-points for 3-winding transformers.', ...
0276 starbus(1, BUS_I), starbus(end, BUS_I));
0277 if verbose
0278 fprintf('Added buses %d-%d as star-points for 3-winding transformers.\n', ...
0279 starbus(1, BUS_I), starbus(end, BUS_I));
0280 end
0281 end
0282 if nargin > 6 && nargout > 3
0283 starbus_name = cell(nt3, 1);
0284 for k = 1:nt3
0285 starbus_name{k} = sprintf('STAR_POINT_XFMR_%d', k);
0286 end
0287 bus_name = [bus_name; starbus_name];
0288 end