Home > matpower5.1 > extras > se > outputpfsoln.m

outputpfsoln

PURPOSE ^

OUTPUTPFSOLN Output power flow solution.

SYNOPSIS ^

function outputpfsoln(baseMVA, bus, gen, branch, converged, et, type_solver, iterNum)

DESCRIPTION ^

OUTPUTPFSOLN  Output power flow solution.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function outputpfsoln(baseMVA, bus, gen, branch, converged, et, type_solver, iterNum)
0002 %OUTPUTPFSOLN  Output power flow solution.
0003 
0004 %   MATPOWER
0005 %   Copyright (c) 1996-2015 by Power System Engineering Research Center (PSERC)
0006 %   by Rui Bo
0007 %   and Ray Zimmerman, PSERC Cornell
0008 %
0009 %   $Id: outputpfsoln.m 2644 2015-03-11 19:34:22Z ray $
0010 %
0011 %   This file is part of MATPOWER.
0012 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0013 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0014 
0015 %% define named indices into bus, gen, branch matrices
0016 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0017     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0018 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, ...
0019     GEN_STATUS, PMAX, PMIN, MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN] = idx_gen;
0020 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, ...
0021     RATE_C, TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST] = idx_brch;
0022 
0023 fd = 1; % output to screen
0024 
0025 %% sizes of things
0026 nb = size(bus, 1);      %% number of buses
0027 nl = size(branch, 1);   %% number of branches
0028 ng = size(gen, 1);      %% number of generators
0029 
0030 %% parameters
0031 ong  = find( gen(:, GEN_STATUS) > 0);
0032 nzld = find(bus(:, PD) | bus(:, QD));
0033 
0034 %% calculate losses
0035 loss = branch(:, PF) + j*branch(:, QF) + branch(:, PT) + j*branch(:, QT);
0036 
0037 %% ---output case and solver information
0038 fprintf(fd, '\n\n');
0039 if type_solver == 1 % newton's method
0040     fprintf(fd, 'Newton''s method is chosen to solve Power Flow.\n');
0041 elseif  type_solver == 2 % decoupled method
0042     fprintf(fd, 'Decoupled method is chosen to solve Power Flow.\n');
0043 else
0044     fprintf('Error: unknow ''type_solver''.\n');
0045     pause
0046 end
0047 
0048 if converged
0049     fprintf(fd, '\nConverged in %.2f seconds\n', et);
0050 else
0051     fprintf(fd, '\nDid not converge (%.2f seconds)\n', et);
0052 end
0053 fprintf(fd, '\n[iteration number]: %d\n', iterNum);
0054 
0055 %% ---output generation information
0056 fprintf(fd, '\n================================================================================');
0057 fprintf(fd, '\n|     Generator Data                                                           |');
0058 fprintf(fd, '\n================================================================================');
0059 fprintf(fd, '\n Gen   Bus   Status     Pg        Qg   ');
0060 fprintf(fd, '\n  #     #              (MW)     (MVAr) ');
0061 fprintf(fd, '\n----  -----  ------  --------  --------');
0062 for k = 1:length(ong)
0063     i = ong(k);
0064     fprintf(fd, '\n%3d %6d     %2d ', i, gen(i, GEN_BUS), gen(i, GEN_STATUS));
0065     if gen(i, GEN_STATUS) > 0 & (gen(i, PG) | gen(i, QG))
0066         fprintf(fd, '%10.2f%10.2f', gen(i, PG), gen(i, QG));
0067     else
0068         fprintf(fd, '       -         -  ');
0069     end
0070 end
0071 fprintf(fd, '\n                     --------  --------');
0072 fprintf(fd, '\n            Total: %9.2f%10.2f', sum(gen(ong, PG)), sum(gen(ong, QG)));
0073 fprintf(fd, '\n');
0074 
0075 %% ---output bus information
0076 fprintf(fd, '\n================================================================================');
0077 fprintf(fd, '\n|     Bus Data                                                                 |');
0078 fprintf(fd, '\n================================================================================');
0079 fprintf(fd, '\n Bus      Voltage          Generation             Load        ');
0080 fprintf(fd, '\n  #   Mag(pu) Ang(deg)   P (MW)   Q (MVAr)   P (MW)   Q (MVAr)');
0081 fprintf(fd, '\n----- ------- --------  --------  --------  --------  --------');
0082 for i = 1:nb
0083     fprintf(fd, '\n%5d%7.3f%9.3f', bus(i, [BUS_I, VM, VA]));
0084     g  = find(gen(:, GEN_STATUS) > 0 & gen(:, GEN_BUS) == bus(i, BUS_I));
0085     if ~isempty(g)
0086         fprintf(fd, '%10.2f%10.2f', sum(gen(g, PG)), sum(gen(g, QG)));
0087     else
0088         fprintf(fd, '       -         -  ');
0089     end
0090     if bus(i, PD) | bus(i, QD)
0091         fprintf(fd, '%10.2f%10.2f ', bus(i, [PD, QD]));
0092     else
0093         fprintf(fd, '       -         -   ');
0094     end
0095 end
0096 fprintf(fd, '\n                        --------  --------  --------  --------');
0097 fprintf(fd, '\n               Total: %9.2f %9.2f %9.2f %9.2f', ...
0098     sum(gen(ong, PG)), sum(gen(ong, QG)), ...
0099     sum(bus(nzld, PD)), ...
0100     sum(bus(nzld, QD)));
0101 fprintf(fd, '\n');
0102 
0103 %% ---output bus information
0104 fprintf(fd, '\n================================================================================');
0105 fprintf(fd, '\n|     Branch Data                                                              |');
0106 fprintf(fd, '\n================================================================================');
0107 fprintf(fd, '\nBrnch   From   To    From Bus Injection   To Bus Injection     Loss (I^2 * Z)  ');
0108 fprintf(fd, '\n  #     Bus    Bus    P (MW)   Q (MVAr)   P (MW)   Q (MVAr)   P (MW)   Q (MVAr)');
0109 fprintf(fd, '\n-----  -----  -----  --------  --------  --------  --------  --------  --------');
0110 fprintf(fd, '\n%4d%7d%7d%10.2f%10.2f%10.2f%10.2f%10.3f%10.2f', ...
0111         [   [1:nl]', branch(:, [F_BUS, T_BUS]), ...
0112             branch(:, [PF, QF]), branch(:, [PT, QT]), ...
0113             real(loss), imag(loss) ...
0114         ]');
0115 fprintf(fd, '\n                                                             --------  --------');
0116 fprintf(fd, '\n                                                    Total:%10.3f%10.2f', ...
0117         sum(real(loss)), sum(imag(loss)));
0118 fprintf(fd, '\n');

Generated on Fri 20-Mar-2015 18:23:34 by m2html © 2005