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