0001 function printpf(baseMVA, bus, gen, branch, f, success, et, fd, mpopt)
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 if isstruct(baseMVA)
0063 have_results_struct = 1;
0064 results = baseMVA;
0065 if nargin < 3 || isempty(gen)
0066 mpopt = mpoption;
0067 else
0068 mpopt = gen;
0069 end
0070 if mpopt(32) == 0 && mpopt(43) == 0
0071 return;
0072 end
0073 if nargin < 2 || isempty(bus)
0074 fd = 1;
0075 else
0076 fd = bus;
0077 end
0078 [baseMVA, bus, gen, branch, success, et] = ...
0079 deal(results.baseMVA, results.bus, results.gen, results.branch, ...
0080 results.success, results.et);
0081 if isfield(results, 'f') && ~isempty(results.f)
0082 f = results.f;
0083 else
0084 f = [];
0085 end
0086 else
0087 have_results_struct = 0;
0088 if nargin < 9
0089 mpopt = mpoption;
0090 if nargin < 8
0091 fd = 1;
0092 end
0093 end
0094 if mpopt(32) == 0 && mpopt(43) == 0
0095 return;
0096 end
0097 end
0098 isOPF = ~isempty(f);
0099
0100
0101 isDC = mpopt(10);
0102 OUT_ALL = mpopt(32);
0103 OUT_ANY = OUT_ALL == 1;
0104 OUT_SYS_SUM = OUT_ALL == 1 || (OUT_ALL == -1 && mpopt(33));
0105 OUT_AREA_SUM = OUT_ALL == 1 || (OUT_ALL == -1 && mpopt(34));
0106 OUT_BUS = OUT_ALL == 1 || (OUT_ALL == -1 && mpopt(35));
0107 OUT_BRANCH = OUT_ALL == 1 || (OUT_ALL == -1 && mpopt(36));
0108 OUT_GEN = OUT_ALL == 1 || (OUT_ALL == -1 && mpopt(37));
0109 OUT_ANY = OUT_ANY || (OUT_ALL == -1 && ...
0110 (OUT_SYS_SUM || OUT_AREA_SUM || OUT_BUS || ...
0111 OUT_BRANCH || OUT_GEN));
0112 if OUT_ALL == -1
0113 OUT_ALL_LIM = mpopt(38);
0114 elseif OUT_ALL == 1
0115 OUT_ALL_LIM = 2;
0116 else
0117 OUT_ALL_LIM = 0;
0118 end
0119 OUT_ANY = OUT_ANY || OUT_ALL_LIM >= 1;
0120 if OUT_ALL_LIM == -1
0121 OUT_V_LIM = mpopt(39);
0122 OUT_LINE_LIM = mpopt(40);
0123 OUT_PG_LIM = mpopt(41);
0124 OUT_QG_LIM = mpopt(42);
0125 else
0126 OUT_V_LIM = OUT_ALL_LIM;
0127 OUT_LINE_LIM = OUT_ALL_LIM;
0128 OUT_PG_LIM = OUT_ALL_LIM;
0129 OUT_QG_LIM = OUT_ALL_LIM;
0130 end
0131 OUT_ANY = OUT_ANY || (OUT_ALL_LIM == -1 && (OUT_V_LIM || OUT_LINE_LIM || OUT_PG_LIM || OUT_QG_LIM));
0132 OUT_RAW = mpopt(43);
0133 ptol = 1e-6;
0134
0135
0136 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0137 VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0138 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0139 MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0140 QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0141 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0142 TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0143 ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0144
0145
0146 i2e = bus(:, BUS_I);
0147 e2i = sparse(max(i2e), 1);
0148 e2i(i2e) = (1:size(bus, 1))';
0149
0150
0151 nb = size(bus, 1);
0152 nl = size(branch, 1);
0153 ng = size(gen, 1);
0154
0155
0156 if isDC
0157 bus(:, [QD, BS]) = zeros(nb, 2);
0158 gen(:, [QG, QMAX, QMIN]) = zeros(ng, 3);
0159 branch(:, [BR_R, BR_B]) = zeros(nl, 2);
0160 end
0161
0162
0163 ties = find(bus(e2i(branch(:, F_BUS)), BUS_AREA) ~= bus(e2i(branch(:, T_BUS)), BUS_AREA));
0164
0165 tap = ones(nl, 1);
0166 xfmr = find(branch(:, TAP));
0167 tap(xfmr) = branch(xfmr, TAP);
0168 tap = tap .* exp(1j*pi/180 * branch(:, SHIFT));
0169 nzld = find(bus(:, PD) | bus(:, QD));
0170 sorted_areas = sort(bus(:, BUS_AREA));
0171 s_areas = sorted_areas([1; find(diff(sorted_areas))+1]);
0172 nzsh = find(bus(:, GS) | bus(:, BS));
0173 allg = find( ~isload(gen) );
0174 ong = find( gen(:, GEN_STATUS) > 0 & ~isload(gen) );
0175 onld = find( gen(:, GEN_STATUS) > 0 & isload(gen) );
0176 V = bus(:, VM) .* exp(sqrt(-1) * pi/180 * bus(:, VA));
0177 out = find(branch(:, BR_STATUS) == 0);
0178 nout = length(out);
0179 if isDC
0180 loss = zeros(nl,1);
0181 else
0182 loss = baseMVA * abs(V(e2i(branch(:, F_BUS))) ./ tap - V(e2i(branch(:, T_BUS)))) .^ 2 ./ ...
0183 (branch(:, BR_R) - 1j * branch(:, BR_X));
0184 end
0185 fchg = abs(V(e2i(branch(:, F_BUS))) ./ tap) .^ 2 .* branch(:, BR_B) * baseMVA / 2;
0186 tchg = abs(V(e2i(branch(:, T_BUS))) ) .^ 2 .* branch(:, BR_B) * baseMVA / 2;
0187 loss(out) = zeros(nout, 1);
0188 fchg(out) = zeros(nout, 1);
0189 tchg(out) = zeros(nout, 1);
0190
0191
0192 if OUT_ANY
0193
0194 if success
0195 fprintf(fd, '\nConverged in %.2f seconds', et);
0196 else
0197 fprintf(fd, '\nDid not converge (%.2f seconds)\n', et);
0198 end
0199
0200
0201 if isOPF
0202 fprintf(fd, '\nObjective Function Value = %.2f $/hr', f);
0203 end
0204 end
0205 if OUT_SYS_SUM
0206 fprintf(fd, '\n================================================================================');
0207 fprintf(fd, '\n| System Summary |');
0208 fprintf(fd, '\n================================================================================');
0209 fprintf(fd, '\n\nHow many? How much? P (MW) Q (MVAr)');
0210 fprintf(fd, '\n--------------------- ------------------- ------------- -----------------');
0211 fprintf(fd, '\nBuses %6d Total Gen Capacity %7.1f %7.1f to %.1f', nb, sum(gen(allg, PMAX)), sum(gen(allg, QMIN)), sum(gen(allg, QMAX)));
0212 fprintf(fd, '\nGenerators %5d On-line Capacity %7.1f %7.1f to %.1f', length(allg), sum(gen(ong, PMAX)), sum(gen(ong, QMIN)), sum(gen(ong, QMAX)));
0213 fprintf(fd, '\nCommitted Gens %5d Generation (actual) %7.1f %7.1f', length(ong), sum(gen(ong, PG)), sum(gen(ong, QG)));
0214 fprintf(fd, '\nLoads %5d Load %7.1f %7.1f', length(nzld)+length(onld), sum(bus(nzld, PD))-sum(gen(onld, PG)), sum(bus(nzld, QD))-sum(gen(onld, QG)));
0215 fprintf(fd, '\n Fixed %5d Fixed %7.1f %7.1f', length(nzld), sum(bus(nzld, PD)), sum(bus(nzld, QD)));
0216 fprintf(fd, '\n Dispatchable %5d Dispatchable %7.1f of %-7.1f%7.1f', length(onld), -sum(gen(onld, PG)), -sum(gen(onld, PMIN)), -sum(gen(onld, QG)));
0217 fprintf(fd, '\nShunts %5d Shunt (inj) %7.1f %7.1f', length(nzsh), ...
0218 -sum(bus(nzsh, VM) .^ 2 .* bus(nzsh, GS)), sum(bus(nzsh, VM) .^ 2 .* bus(nzsh, BS)) );
0219 fprintf(fd, '\nBranches %5d Losses (I^2 * Z) %8.2f %8.2f', nl, sum(real(loss)), sum(imag(loss)) );
0220 fprintf(fd, '\nTransformers %5d Branch Charging (inj) - %7.1f', length(xfmr), sum(fchg) + sum(tchg) );
0221 fprintf(fd, '\nInter-ties %5d Total Inter-tie Flow %7.1f %7.1f', length(ties), sum(abs(branch(ties, PF)-branch(ties, PT))) / 2, sum(abs(branch(ties, QF)-branch(ties, QT))) / 2);
0222 fprintf(fd, '\nAreas %5d', length(s_areas));
0223 fprintf(fd, '\n');
0224 fprintf(fd, '\n Minimum Maximum');
0225 fprintf(fd, '\n ------------------------- --------------------------------');
0226 [minv, mini] = min(bus(:, VM));
0227 [maxv, maxi] = max(bus(:, VM));
0228 fprintf(fd, '\nVoltage Magnitude %7.3f p.u. @ bus %-4d %7.3f p.u. @ bus %-4d', minv, bus(mini, BUS_I), maxv, bus(maxi, BUS_I));
0229 [minv, mini] = min(bus(:, VA));
0230 [maxv, maxi] = max(bus(:, VA));
0231 fprintf(fd, '\nVoltage Angle %8.2f deg @ bus %-4d %8.2f deg @ bus %-4d', minv, bus(mini, BUS_I), maxv, bus(maxi, BUS_I));
0232 if ~isDC
0233 [maxv, maxi] = max(real(loss));
0234 fprintf(fd, '\nP Losses (I^2*R) - %8.2f MW @ line %d-%d', maxv, branch(maxi, F_BUS), branch(maxi, T_BUS));
0235 [maxv, maxi] = max(imag(loss));
0236 fprintf(fd, '\nQ Losses (I^2*X) - %8.2f MVAr @ line %d-%d', maxv, branch(maxi, F_BUS), branch(maxi, T_BUS));
0237 end
0238 if isOPF
0239 [minv, mini] = min(bus(:, LAM_P));
0240 [maxv, maxi] = max(bus(:, LAM_P));
0241 fprintf(fd, '\nLambda P %8.2f $/MWh @ bus %-4d %8.2f $/MWh @ bus %-4d', minv, bus(mini, BUS_I), maxv, bus(maxi, BUS_I));
0242 [minv, mini] = min(bus(:, LAM_Q));
0243 [maxv, maxi] = max(bus(:, LAM_Q));
0244 fprintf(fd, '\nLambda Q %8.2f $/MWh @ bus %-4d %8.2f $/MWh @ bus %-4d', minv, bus(mini, BUS_I), maxv, bus(maxi, BUS_I));
0245 end
0246 fprintf(fd, '\n');
0247 end
0248
0249 if OUT_AREA_SUM
0250 fprintf(fd, '\n================================================================================');
0251 fprintf(fd, '\n| Area Summary |');
0252 fprintf(fd, '\n================================================================================');
0253 fprintf(fd, '\nArea # of # of Gens # of Loads # of # of # of # of');
0254 fprintf(fd, '\n Num Buses Total Online Total Fixed Disp Shunt Brchs Xfmrs Ties');
0255 fprintf(fd, '\n---- ----- ----- ------ ----- ----- ----- ----- ----- ----- -----');
0256 for i=1:length(s_areas)
0257 a = s_areas(i);
0258 ib = find(bus(:, BUS_AREA) == a);
0259 ig = find(bus(e2i(gen(:, GEN_BUS)), BUS_AREA) == a & ~isload(gen));
0260 igon = find(bus(e2i(gen(:, GEN_BUS)), BUS_AREA) == a & gen(:, GEN_STATUS) > 0 & ~isload(gen));
0261 ildon = find(bus(e2i(gen(:, GEN_BUS)), BUS_AREA) == a & gen(:, GEN_STATUS) > 0 & isload(gen));
0262 inzld = find(bus(:, BUS_AREA) == a & (bus(:, PD) | bus(:, QD)));
0263 inzsh = find(bus(:, BUS_AREA) == a & (bus(:, GS) | bus(:, BS)));
0264 ibrch = find(bus(e2i(branch(:, F_BUS)), BUS_AREA) == a & bus(e2i(branch(:, T_BUS)), BUS_AREA) == a);
0265 in_tie = find(bus(e2i(branch(:, F_BUS)), BUS_AREA) == a & bus(e2i(branch(:, T_BUS)), BUS_AREA) ~= a);
0266 out_tie = find(bus(e2i(branch(:, F_BUS)), BUS_AREA) ~= a & bus(e2i(branch(:, T_BUS)), BUS_AREA) == a);
0267 if isempty(xfmr)
0268 nxfmr = 0;
0269 else
0270 nxfmr = length(find(bus(e2i(branch(xfmr, F_BUS)), BUS_AREA) == a & bus(e2i(branch(xfmr, T_BUS)), BUS_AREA) == a));
0271 end
0272 fprintf(fd, '\n%3d %6d %5d %5d %5d %5d %5d %5d %5d %5d %5d', ...
0273 a, length(ib), length(ig), length(igon), ...
0274 length(inzld)+length(ildon), length(inzld), length(ildon), ...
0275 length(inzsh), length(ibrch), nxfmr, length(in_tie)+length(out_tie));
0276 end
0277 fprintf(fd, '\n---- ----- ----- ------ ----- ----- ----- ----- ----- ----- -----');
0278 fprintf(fd, '\nTot: %6d %5d %5d %5d %5d %5d %5d %5d %5d %5d', ...
0279 nb, length(allg), length(ong), length(nzld)+length(onld), ...
0280 length(nzld), length(onld), length(nzsh), nl, length(xfmr), length(ties));
0281 fprintf(fd, '\n');
0282 fprintf(fd, '\nArea Total Gen Capacity On-line Gen Capacity Generation');
0283 fprintf(fd, '\n Num MW MVAr MW MVAr MW MVAr');
0284 fprintf(fd, '\n---- ------ ------------------ ------ ------------------ ------ ------');
0285 for i=1:length(s_areas)
0286 a = s_areas(i);
0287 ig = find(bus(e2i(gen(:, GEN_BUS)), BUS_AREA) == a & ~isload(gen));
0288 igon = find(bus(e2i(gen(:, GEN_BUS)), BUS_AREA) == a & gen(:, GEN_STATUS) > 0 & ~isload(gen));
0289 fprintf(fd, '\n%3d %7.1f %7.1f to %-7.1f %7.1f %7.1f to %-7.1f %7.1f %7.1f', ...
0290 a, sum(gen(ig, PMAX)), sum(gen(ig, QMIN)), sum(gen(ig, QMAX)), ...
0291 sum(gen(igon, PMAX)), sum(gen(igon, QMIN)), sum(gen(igon, QMAX)), ...
0292 sum(gen(igon, PG)), sum(gen(igon, QG)) );
0293 end
0294 fprintf(fd, '\n---- ------ ------------------ ------ ------------------ ------ ------');
0295 fprintf(fd, '\nTot: %7.1f %7.1f to %-7.1f %7.1f %7.1f to %-7.1f %7.1f %7.1f', ...
0296 sum(gen(allg, PMAX)), sum(gen(allg, QMIN)), sum(gen(allg, QMAX)), ...
0297 sum(gen(ong, PMAX)), sum(gen(ong, QMIN)), sum(gen(ong, QMAX)), ...
0298 sum(gen(ong, PG)), sum(gen(ong, QG)) );
0299 fprintf(fd, '\n');
0300 fprintf(fd, '\nArea Disp Load Cap Disp Load Fixed Load Total Load');
0301 fprintf(fd, '\n Num MW MVAr MW MVAr MW MVAr MW MVAr');
0302 fprintf(fd, '\n---- ------ ------ ------ ------ ------ ------ ------ ------');
0303 Qlim = (gen(:, QMIN) == 0) .* gen(:, QMAX) + (gen(:, QMAX) == 0) .* gen(:, QMIN);
0304 for i=1:length(s_areas)
0305 a = s_areas(i);
0306 ildon = find(bus(e2i(gen(:, GEN_BUS)), BUS_AREA) == a & gen(:, GEN_STATUS) > 0 & isload(gen));
0307 inzld = find(bus(:, BUS_AREA) == a & (bus(:, PD) | bus(:, QD)));
0308 fprintf(fd, '\n%3d %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f', ...
0309 a, -sum(gen(ildon, PMIN)), ...
0310 -sum(Qlim(ildon)), ...
0311 -sum(gen(ildon, PG)), -sum(gen(ildon, QG)), ...
0312 sum(bus(inzld, PD)), sum(bus(inzld, QD)), ...
0313 -sum(gen(ildon, PG)) + sum(bus(inzld, PD)), ...
0314 -sum(gen(ildon, QG)) + sum(bus(inzld, QD)) );
0315 end
0316 fprintf(fd, '\n---- ------ ------ ------ ------ ------ ------ ------ ------');
0317 fprintf(fd, '\nTot: %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f %7.1f', ...
0318 -sum(gen(onld, PMIN)), ...
0319 -sum(Qlim(onld)), ...
0320 -sum(gen(onld, PG)), -sum(gen(onld, QG)), ...
0321 sum(bus(nzld, PD)), sum(bus(nzld, QD)), ...
0322 -sum(gen(onld, PG)) + sum(bus(nzld, PD)), ...
0323 -sum(gen(onld, QG)) + sum(bus(nzld, QD)) );
0324 fprintf(fd, '\n');
0325 fprintf(fd, '\nArea Shunt Inj Branch Series Losses Net Export');
0326 fprintf(fd, '\n Num MW MVAr Charging MW MVAr MW MVAr');
0327 fprintf(fd, '\n---- ------ ------ -------- ------ ------ ------ ------');
0328 for i=1:length(s_areas)
0329 a = s_areas(i);
0330 inzsh = find(bus(:, BUS_AREA) == a & (bus(:, GS) | bus(:, BS)));
0331 ibrch = find(bus(e2i(branch(:, F_BUS)), BUS_AREA) == a & bus(e2i(branch(:, T_BUS)), BUS_AREA) == a & branch(:, BR_STATUS));
0332 in_tie = find(bus(e2i(branch(:, F_BUS)), BUS_AREA) ~= a & bus(e2i(branch(:, T_BUS)), BUS_AREA) == a & branch(:, BR_STATUS));
0333 out_tie = find(bus(e2i(branch(:, F_BUS)), BUS_AREA) == a & bus(e2i(branch(:, T_BUS)), BUS_AREA) ~= a & branch(:, BR_STATUS));
0334 fprintf(fd, '\n%3d %7.1f %7.1f %7.1f %7.2f %7.2f %7.1f %7.1f', ...
0335 a, -sum(bus(inzsh, VM) .^ 2 .* bus(inzsh, GS)), ...
0336 sum(bus(inzsh, VM) .^ 2 .* bus(inzsh, BS)), ...
0337 sum(fchg(ibrch)) + sum(tchg(ibrch)) + sum(fchg(out_tie)) + sum(tchg(in_tie)), ...
0338 sum(real(loss(ibrch))) + sum(real(loss([in_tie; out_tie]))) / 2, ...
0339 sum(imag(loss(ibrch))) + sum(imag(loss([in_tie; out_tie]))) / 2, ...
0340 sum(branch(in_tie, PT))+sum(branch(out_tie, PF)) - sum(real(loss([in_tie; out_tie]))) / 2, ...
0341 sum(branch(in_tie, QT))+sum(branch(out_tie, QF)) - sum(imag(loss([in_tie; out_tie]))) / 2 );
0342 end
0343 fprintf(fd, '\n---- ------ ------ -------- ------ ------ ------ ------');
0344 fprintf(fd, '\nTot: %7.1f %7.1f %7.1f %7.2f %7.2f - -', ...
0345 -sum(bus(nzsh, VM) .^ 2 .* bus(nzsh, GS)), ...
0346 sum(bus(nzsh, VM) .^ 2 .* bus(nzsh, BS)), ...
0347 sum(fchg) + sum(tchg), sum(real(loss)), sum(imag(loss)) );
0348 fprintf(fd, '\n');
0349 end
0350
0351
0352 if OUT_GEN
0353 if isOPF
0354 genlamP = bus(e2i(gen(:, GEN_BUS)), LAM_P);
0355 genlamQ = bus(e2i(gen(:, GEN_BUS)), LAM_Q);
0356 end
0357 fprintf(fd, '\n================================================================================');
0358 fprintf(fd, '\n| Generator Data |');
0359 fprintf(fd, '\n================================================================================');
0360 fprintf(fd, '\n Gen Bus Status Pg Qg ');
0361 if isOPF, fprintf(fd, ' Lambda ($/MVA-hr)'); end
0362 fprintf(fd, '\n # # (MW) (MVAr) ');
0363 if isOPF, fprintf(fd, ' P Q '); end
0364 fprintf(fd, '\n---- ----- ------ -------- --------');
0365 if isOPF, fprintf(fd, ' -------- --------'); end
0366 for k = 1:length(ong)
0367 i = ong(k);
0368 fprintf(fd, '\n%3d %6d %2d ', i, gen(i, GEN_BUS), gen(i, GEN_STATUS));
0369 if gen(i, GEN_STATUS) > 0 && (gen(i, PG) || gen(i, QG))
0370 fprintf(fd, '%10.2f%10.2f', gen(i, PG), gen(i, QG));
0371 else
0372 fprintf(fd, ' - - ');
0373 end
0374 if isOPF, fprintf(fd, '%10.2f%10.2f', genlamP(i), genlamQ(i)); end
0375 end
0376 fprintf(fd, '\n -------- --------');
0377 fprintf(fd, '\n Total: %9.2f%10.2f', sum(gen(ong, PG)), sum(gen(ong, QG)));
0378 fprintf(fd, '\n');
0379 if ~isempty(onld)
0380 fprintf(fd, '\n================================================================================');
0381 fprintf(fd, '\n| Dispatchable Load Data |');
0382 fprintf(fd, '\n================================================================================');
0383 fprintf(fd, '\n Gen Bus Status Pd Qd ');
0384 if isOPF, fprintf(fd, ' Lambda ($/MVA-hr)'); end
0385 fprintf(fd, '\n # # (MW) (MVAr) ');
0386 if isOPF, fprintf(fd, ' P Q '); end
0387 fprintf(fd, '\n---- ----- ------ -------- --------');
0388 if isOPF, fprintf(fd, ' -------- --------'); end
0389 for k = 1:length(onld)
0390 i = onld(k);
0391 fprintf(fd, '\n%3d %6d %2d ', i, gen(i, GEN_BUS), gen(i, GEN_STATUS));
0392 if gen(i, GEN_STATUS) > 0 && (gen(i, PG) || gen(i, QG))
0393 fprintf(fd, '%10.2f%10.2f', -gen(i, PG), -gen(i, QG));
0394 else
0395 fprintf(fd, ' - - ');
0396 end
0397 if isOPF, fprintf(fd, '%10.2f%10.2f', genlamP(i), genlamQ(i)); end
0398 end
0399 fprintf(fd, '\n -------- --------');
0400 fprintf(fd, '\n Total: %9.2f%10.2f', -sum(gen(onld, PG)), -sum(gen(onld, QG)));
0401 fprintf(fd, '\n');
0402 end
0403 end
0404
0405
0406 if OUT_BUS
0407 fprintf(fd, '\n================================================================================');
0408 fprintf(fd, '\n| Bus Data |');
0409 fprintf(fd, '\n================================================================================');
0410 fprintf(fd, '\n Bus Voltage Generation Load ');
0411 if isOPF, fprintf(fd, ' Lambda($/MVA-hr)'); end
0412 fprintf(fd, '\n # Mag(pu) Ang(deg) P (MW) Q (MVAr) P (MW) Q (MVAr)');
0413 if isOPF, fprintf(fd, ' P Q '); end
0414 fprintf(fd, '\n----- ------- -------- -------- -------- -------- --------');
0415 if isOPF, fprintf(fd, ' ------- -------'); end
0416 for i = 1:nb
0417 fprintf(fd, '\n%5d%7.3f%9.3f', bus(i, [BUS_I, VM, VA]));
0418 g = find(gen(:, GEN_STATUS) > 0 & gen(:, GEN_BUS) == bus(i, BUS_I) & ...
0419 ~isload(gen));
0420 ld = find(gen(:, GEN_STATUS) > 0 & gen(:, GEN_BUS) == bus(i, BUS_I) & ...
0421 isload(gen));
0422 if ~isempty(g)
0423 fprintf(fd, '%10.2f%10.2f', sum(gen(g, PG)), sum(gen(g, QG)));
0424 else
0425 fprintf(fd, ' - - ');
0426 end
0427 if bus(i, PD) || bus(i, QD) || ~isempty(ld)
0428 if ~isempty(ld)
0429 fprintf(fd, '%10.2f*%9.2f*', bus(i, PD) - sum(gen(ld, PG)), ...
0430 bus(i, QD) - sum(gen(ld, QG)));
0431 else
0432 fprintf(fd, '%10.2f%10.2f ', bus(i, [PD, QD]));
0433 end
0434 else
0435 fprintf(fd, ' - - ');
0436 end
0437 if isOPF
0438 fprintf(fd, '%9.3f', bus(i, LAM_P));
0439 if abs(bus(i, LAM_Q)) > ptol
0440 fprintf(fd, '%8.3f', bus(i, LAM_Q));
0441 else
0442 fprintf(fd, ' -');
0443 end
0444 end
0445 end
0446 fprintf(fd, '\n -------- -------- -------- --------');
0447 fprintf(fd, '\n Total: %9.2f %9.2f %9.2f %9.2f', ...
0448 sum(gen(ong, PG)), sum(gen(ong, QG)), ...
0449 sum(bus(nzld, PD)) - sum(gen(onld, PG)), ...
0450 sum(bus(nzld, QD)) - sum(gen(onld, QG)));
0451 fprintf(fd, '\n');
0452 end
0453
0454
0455 if OUT_BRANCH
0456 fprintf(fd, '\n================================================================================');
0457 fprintf(fd, '\n| Branch Data |');
0458 fprintf(fd, '\n================================================================================');
0459 fprintf(fd, '\nBrnch From To From Bus Injection To Bus Injection Loss (I^2 * Z) ');
0460 fprintf(fd, '\n # Bus Bus P (MW) Q (MVAr) P (MW) Q (MVAr) P (MW) Q (MVAr)');
0461 fprintf(fd, '\n----- ----- ----- -------- -------- -------- -------- -------- --------');
0462 fprintf(fd, '\n%4d%7d%7d%10.2f%10.2f%10.2f%10.2f%10.3f%10.2f', ...
0463 [ (1:nl)', branch(:, [F_BUS, T_BUS]), ...
0464 branch(:, [PF, QF]), branch(:, [PT, QT]), ...
0465 real(loss), imag(loss) ...
0466 ]');
0467 fprintf(fd, '\n -------- --------');
0468 fprintf(fd, '\n Total:%10.3f%10.2f', ...
0469 sum(real(loss)), sum(imag(loss)));
0470 fprintf(fd, '\n');
0471 end
0472
0473
0474 if isOPF
0475 ctol = mpopt(16);
0476
0477 if ~isDC && (OUT_V_LIM == 2 || (OUT_V_LIM == 1 && ...
0478 (any(bus(:, VM) < bus(:, VMIN) + ctol) || ...
0479 any(bus(:, VM) > bus(:, VMAX) - ctol) || ...
0480 any(bus(:, MU_VMIN) > ptol) || ...
0481 any(bus(:, MU_VMAX) > ptol))))
0482 fprintf(fd, '\n================================================================================');
0483 fprintf(fd, '\n| Voltage Constraints |');
0484 fprintf(fd, '\n================================================================================');
0485 fprintf(fd, '\nBus # Vmin mu Vmin |V| Vmax Vmax mu');
0486 fprintf(fd, '\n----- -------- ----- ----- ----- --------');
0487 for i = 1:nb
0488 if OUT_V_LIM == 2 || (OUT_V_LIM == 1 && ...
0489 (bus(i, VM) < bus(i, VMIN) + ctol || ...
0490 bus(i, VM) > bus(i, VMAX) - ctol || ...
0491 bus(i, MU_VMIN) > ptol || bus(i, MU_VMAX) > ptol))
0492 fprintf(fd, '\n%5d', bus(i, BUS_I));
0493 if bus(i, VM) < bus(i, VMIN) + ctol || bus(i, MU_VMIN) > ptol
0494 fprintf(fd, '%10.3f', bus(i, MU_VMIN));
0495 else
0496 fprintf(fd, ' - ');
0497 end
0498 fprintf(fd, '%8.3f%7.3f%7.3f', bus(i, [VMIN, VM, VMAX]));
0499 if bus(i, VM) > bus(i, VMAX) - ctol || bus(i, MU_VMAX) > ptol
0500 fprintf(fd, '%10.3f', bus(i, MU_VMAX));
0501 else
0502 fprintf(fd, ' - ');
0503 end
0504 end
0505 end
0506 fprintf(fd, '\n');
0507 end
0508
0509
0510 if OUT_PG_LIM == 2 || ...
0511 (OUT_PG_LIM == 1 && (any(gen(ong, PG) < gen(ong, PMIN) + ctol) || ...
0512 any(gen(ong, PG) > gen(ong, PMAX) - ctol) || ...
0513 any(gen(ong, MU_PMIN) > ptol) || ...
0514 any(gen(ong, MU_PMAX) > ptol))) || ...
0515 (~isDC && (OUT_QG_LIM == 2 || ...
0516 (OUT_QG_LIM == 1 && (any(gen(ong, QG) < gen(ong, QMIN) + ctol) || ...
0517 any(gen(ong, QG) > gen(ong, QMAX) - ctol) || ...
0518 any(gen(ong, MU_QMIN) > ptol) || ...
0519 any(gen(ong, MU_QMAX) > ptol)))))
0520 fprintf(fd, '\n================================================================================');
0521 fprintf(fd, '\n| Generation Constraints |');
0522 fprintf(fd, '\n================================================================================');
0523 end
0524 if OUT_PG_LIM == 2 || (OUT_PG_LIM == 1 && ...
0525 (any(gen(ong, PG) < gen(ong, PMIN) + ctol) || ...
0526 any(gen(ong, PG) > gen(ong, PMAX) - ctol) || ...
0527 any(gen(ong, MU_PMIN) > ptol) || ...
0528 any(gen(ong, MU_PMAX) > ptol)))
0529 fprintf(fd, '\n Gen Bus Active Power Limits');
0530 fprintf(fd, '\n # # Pmin mu Pmin Pg Pmax Pmax mu');
0531 fprintf(fd, '\n---- ----- ------- -------- -------- -------- -------');
0532 for k = 1:length(ong)
0533 i = ong(k);
0534 if OUT_PG_LIM == 2 || (OUT_PG_LIM == 1 && ...
0535 (gen(i, PG) < gen(i, PMIN) + ctol || ...
0536 gen(i, PG) > gen(i, PMAX) - ctol || ...
0537 gen(i, MU_PMIN) > ptol || gen(i, MU_PMAX) > ptol))
0538 fprintf(fd, '\n%4d%6d ', i, gen(i, GEN_BUS));
0539 if gen(i, PG) < gen(i, PMIN) + ctol || gen(i, MU_PMIN) > ptol
0540 fprintf(fd, '%8.3f', gen(i, MU_PMIN));
0541 else
0542 fprintf(fd, ' - ');
0543 end
0544 if gen(i, PG)
0545 fprintf(fd, '%10.2f%10.2f%10.2f', gen(i, [PMIN, PG, PMAX]));
0546 else
0547 fprintf(fd, '%10.2f - %10.2f', gen(i, [PMIN, PMAX]));
0548 end
0549 if gen(i, PG) > gen(i, PMAX) - ctol || gen(i, MU_PMAX) > ptol
0550 fprintf(fd, '%9.3f', gen(i, MU_PMAX));
0551 else
0552 fprintf(fd, ' - ');
0553 end
0554 end
0555 end
0556 fprintf(fd, '\n');
0557 end
0558
0559
0560 if ~isDC && (OUT_QG_LIM == 2 || (OUT_QG_LIM == 1 && ...
0561 (any(gen(ong, QG) < gen(ong, QMIN) + ctol) || ...
0562 any(gen(ong, QG) > gen(ong, QMAX) - ctol) || ...
0563 any(gen(ong, MU_QMIN) > ptol) || ...
0564 any(gen(ong, MU_QMAX) > ptol))))
0565 fprintf(fd, '\nGen Bus Reactive Power Limits');
0566 fprintf(fd, '\n # # Qmin mu Qmin Qg Qmax Qmax mu');
0567 fprintf(fd, '\n--- --- ------- -------- -------- -------- -------');
0568 for k = 1:length(ong)
0569 i = ong(k);
0570 if OUT_QG_LIM == 2 || (OUT_QG_LIM == 1 && ...
0571 (gen(i, QG) < gen(i, QMIN) + ctol || ...
0572 gen(i, QG) > gen(i, QMAX) - ctol || ...
0573 gen(i, MU_QMIN) > ptol || gen(i, MU_QMAX) > ptol))
0574 fprintf(fd, '\n%3d%5d', i, gen(i, GEN_BUS));
0575 if gen(i, QG) < gen(i, QMIN) + ctol || gen(i, MU_QMIN) > ptol
0576 fprintf(fd, '%8.3f', gen(i, MU_QMIN));
0577 else
0578 fprintf(fd, ' - ');
0579 end
0580 if gen(i, QG)
0581 fprintf(fd, '%10.2f%10.2f%10.2f', gen(i, [QMIN, QG, QMAX]));
0582 else
0583 fprintf(fd, '%10.2f - %10.2f', gen(i, [QMIN, QMAX]));
0584 end
0585 if gen(i, QG) > gen(i, QMAX) - ctol || gen(i, MU_QMAX) > ptol
0586 fprintf(fd, '%9.3f', gen(i, MU_QMAX));
0587 else
0588 fprintf(fd, ' - ');
0589 end
0590 end
0591 end
0592 fprintf(fd, '\n');
0593 end
0594
0595
0596 if OUT_PG_LIM == 2 || OUT_QG_LIM == 2 || ...
0597 (OUT_PG_LIM == 1 && (any(gen(onld, PG) < gen(onld, PMIN) + ctol) || ...
0598 any(gen(onld, PG) > gen(onld, PMAX) - ctol) || ...
0599 any(gen(onld, MU_PMIN) > ptol) || ...
0600 any(gen(onld, MU_PMAX) > ptol))) || ...
0601 (OUT_QG_LIM == 1 && (any(gen(onld, QG) < gen(onld, QMIN) + ctol) || ...
0602 any(gen(onld, QG) > gen(onld, QMAX) - ctol) || ...
0603 any(gen(onld, MU_QMIN) > ptol) || ...
0604 any(gen(onld, MU_QMAX) > ptol)))
0605 fprintf(fd, '\n================================================================================');
0606 fprintf(fd, '\n| Dispatchable Load Constraints |');
0607 fprintf(fd, '\n================================================================================');
0608 end
0609 if OUT_PG_LIM == 2 || (OUT_PG_LIM == 1 && ...
0610 (any(gen(onld, PG) < gen(onld, PMIN) + ctol) || ...
0611 any(gen(onld, PG) > gen(onld, PMAX) - ctol) || ...
0612 any(gen(onld, MU_PMIN) > ptol) || ...
0613 any(gen(onld, MU_PMAX) > ptol)))
0614 fprintf(fd, '\nGen Bus Active Power Limits');
0615 fprintf(fd, '\n # # Pmin mu Pmin Pg Pmax Pmax mu');
0616 fprintf(fd, '\n--- --- ------- -------- -------- -------- -------');
0617 for k = 1:length(onld)
0618 i = onld(k);
0619 if OUT_PG_LIM == 2 || (OUT_PG_LIM == 1 && ...
0620 (gen(i, PG) < gen(i, PMIN) + ctol || ...
0621 gen(i, PG) > gen(i, PMAX) - ctol || ...
0622 gen(i, MU_PMIN) > ptol || gen(i, MU_PMAX) > ptol))
0623 fprintf(fd, '\n%3d%5d', i, gen(i, GEN_BUS));
0624 if gen(i, PG) < gen(i, PMIN) + ctol || gen(i, MU_PMIN) > ptol
0625 fprintf(fd, '%8.3f', gen(i, MU_PMIN));
0626 else
0627 fprintf(fd, ' - ');
0628 end
0629 if gen(i, PG)
0630 fprintf(fd, '%10.2f%10.2f%10.2f', gen(i, [PMIN, PG, PMAX]));
0631 else
0632 fprintf(fd, '%10.2f - %10.2f', gen(i, [PMIN, PMAX]));
0633 end
0634 if gen(i, PG) > gen(i, PMAX) - ctol || gen(i, MU_PMAX) > ptol
0635 fprintf(fd, '%9.3f', gen(i, MU_PMAX));
0636 else
0637 fprintf(fd, ' - ');
0638 end
0639 end
0640 end
0641 fprintf(fd, '\n');
0642 end
0643
0644
0645 if ~isDC && (OUT_QG_LIM == 2 || (OUT_QG_LIM == 1 && ...
0646 (any(gen(onld, QG) < gen(onld, QMIN) + ctol) || ...
0647 any(gen(onld, QG) > gen(onld, QMAX) - ctol) || ...
0648 any(gen(onld, MU_QMIN) > ptol) || ...
0649 any(gen(onld, MU_QMAX) > ptol))))
0650 fprintf(fd, '\nGen Bus Reactive Power Limits');
0651 fprintf(fd, '\n # # Qmin mu Qmin Qg Qmax Qmax mu');
0652 fprintf(fd, '\n--- --- ------- -------- -------- -------- -------');
0653 for k = 1:length(onld)
0654 i = onld(k);
0655 if OUT_QG_LIM == 2 || (OUT_QG_LIM == 1 && ...
0656 (gen(i, QG) < gen(i, QMIN) + ctol || ...
0657 gen(i, QG) > gen(i, QMAX) - ctol || ...
0658 gen(i, MU_QMIN) > ptol || gen(i, MU_QMAX) > ptol))
0659 fprintf(fd, '\n%3d%5d', i, gen(i, GEN_BUS));
0660 if gen(i, QG) < gen(i, QMIN) + ctol || gen(i, MU_QMIN) > ptol
0661 fprintf(fd, '%8.3f', gen(i, MU_QMIN));
0662 else
0663 fprintf(fd, ' - ');
0664 end
0665 if gen(i, QG)
0666 fprintf(fd, '%10.2f%10.2f%10.2f', gen(i, [QMIN, QG, QMAX]));
0667 else
0668 fprintf(fd, '%10.2f - %10.2f', gen(i, [QMIN, QMAX]));
0669 end
0670 if gen(i, QG) > gen(i, QMAX) - ctol || gen(i, MU_QMAX) > ptol
0671 fprintf(fd, '%9.3f', gen(i, MU_QMAX));
0672 else
0673 fprintf(fd, ' - ');
0674 end
0675 end
0676 end
0677 fprintf(fd, '\n');
0678 end
0679
0680
0681 if mpopt(24) == 1 || isDC
0682 Ff = branch(:, PF);
0683 Ft = branch(:, PT);
0684 str = '\n # Bus Pf mu Pf |Pmax| Pt Pt mu Bus';
0685 elseif mpopt(24) == 2
0686 Ff = abs( (branch(:, PF) + 1j * branch(:, QF)) ./ V(e2i(branch(:, F_BUS))) );
0687 Ft = abs( (branch(:, PT) + 1j * branch(:, QT)) ./ V(e2i(branch(:, T_BUS))) );
0688 str = '\n # Bus |If| mu |If| |Imax| |It| |It| mu Bus';
0689 else
0690 Ff = abs(branch(:, PF) + 1j * branch(:, QF));
0691 Ft = abs(branch(:, PT) + 1j * branch(:, QT));
0692 str = '\n # Bus |Sf| mu |Sf| |Smax| |St| |St| mu Bus';
0693 end
0694 if OUT_LINE_LIM == 2 || (OUT_LINE_LIM == 1 && ...
0695 (any(branch(:, RATE_A) ~= 0 & abs(Ff) > branch(:, RATE_A) - ctol) || ...
0696 any(branch(:, RATE_A) ~= 0 & abs(Ft) > branch(:, RATE_A) - ctol) || ...
0697 any(branch(:, MU_SF) > ptol) || ...
0698 any(branch(:, MU_ST) > ptol)))
0699 fprintf(fd, '\n================================================================================');
0700 fprintf(fd, '\n| Branch Flow Constraints |');
0701 fprintf(fd, '\n================================================================================');
0702 fprintf(fd, '\nBrnch From "From" End Limit "To" End To');
0703 fprintf(fd, str);
0704 fprintf(fd, '\n----- ----- ------- -------- -------- -------- ------- -----');
0705 for i = 1:nl
0706 if OUT_LINE_LIM == 2 || (OUT_LINE_LIM == 1 && ...
0707 ((branch(i, RATE_A) ~= 0 && abs(Ff(i)) > branch(i, RATE_A) - ctol) || ...
0708 (branch(i, RATE_A) ~= 0 && abs(Ft(i)) > branch(i, RATE_A) - ctol) || ...
0709 branch(i, MU_SF) > ptol || branch(i, MU_ST) > ptol))
0710 fprintf(fd, '\n%4d%7d', i, branch(i, F_BUS));
0711 if Ff(i) > branch(i, RATE_A) - ctol || branch(i, MU_SF) > ptol
0712 fprintf(fd, '%10.3f', branch(i, MU_SF));
0713 else
0714 fprintf(fd, ' - ');
0715 end
0716 fprintf(fd, '%9.2f%10.2f%10.2f', ...
0717 [Ff(i), branch(i, RATE_A), Ft(i)]);
0718 if Ft(i) > branch(i, RATE_A) - ctol || branch(i, MU_ST) > ptol
0719 fprintf(fd, '%10.3f', branch(i, MU_ST));
0720 else
0721 fprintf(fd, ' - ');
0722 end
0723 fprintf(fd, '%6d', branch(i, T_BUS));
0724 end
0725 end
0726 fprintf(fd, '\n');
0727 end
0728 end
0729
0730
0731 if have_results_struct && isfield(results, 'userfcn')
0732 run_userfcn(results.userfcn, 'printpf', results, fd, mpopt);
0733 end
0734
0735
0736 if OUT_RAW
0737 fprintf(fd, '---------- raw PB::Soln data below ----------\n');
0738 fprintf(fd, 'bus\n');
0739 if isOPF
0740 fprintf(fd, '%d\t%d\t%g\t%g\t%g\t%g\t%g\t%g\n', ...
0741 bus(:, [BUS_I, BUS_TYPE, VM, VA, LAM_P, LAM_Q, MU_VMAX, MU_VMIN])');
0742
0743 fprintf(fd, 'branch\n');
0744 fprintf(fd, '%d\t%g\t%g\t%g\t%g\t%g\t%g\n', ...
0745 [(1:nl)' branch(:, [PF, QF, PT, QT, MU_SF, MU_ST])]');
0746
0747 fprintf(fd, 'gen\n');
0748 fprintf(fd, '%d\t%g\t%g\t%g\t%d\t%g\t%g\t%g\t%g\n', ...
0749 [(1:ng)' gen(:, [PG, QG, VG, GEN_STATUS, MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN])]');
0750 else
0751 fprintf(fd, '%d\t%d\t%f\t%f\t%d\t%d\t%d\t%d\n', ...
0752 [bus(:, [BUS_I, BUS_TYPE, VM, VA]) zeros(nb, 4)]');
0753
0754 fprintf(fd, 'branch\n');
0755 fprintf(fd, '%d\t%f\t%f\t%f\t%f\t%d\t%d\n', ...
0756 [(1:nl)' branch(:, [PF, QF, PT, QT]) zeros(nl, 2)]');
0757
0758 fprintf(fd, 'gen\n');
0759 fprintf(fd, '%d\t%f\t%f\t%f\t%d\t%d\t%d\t%d\t%d\n', ...
0760 [(1:ng)' gen(:, [PG, QG, VG, GEN_STATUS]) zeros(ng, 4)]');
0761 end
0762 fprintf(fd, 'end\n');
0763 fprintf(fd, '---------- raw PB::Soln data above ----------\n');
0764 end