Home > matpower4.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 %   $Id: outputpfsoln.m,v 1.4 2010/04/26 19:45:26 ray Exp $
0006 %   by Rui Bo
0007 %   and Ray Zimmerman, PSERC Cornell
0008 %   Copyright (c) 1996-2010 by Power System Engineering Research Center (PSERC)
0009 %   Copyright (c) 2009-2010 by Rui Bo
0010 %
0011 %   This file is part of MATPOWER.
0012 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0013 %
0014 %   MATPOWER is free software: you can redistribute it and/or modify
0015 %   it under the terms of the GNU General Public License as published
0016 %   by the Free Software Foundation, either version 3 of the License,
0017 %   or (at your option) any later version.
0018 %
0019 %   MATPOWER is distributed in the hope that it will be useful,
0020 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0021 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0022 %   GNU General Public License for more details.
0023 %
0024 %   You should have received a copy of the GNU General Public License
0025 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0026 %
0027 %   Additional permission under GNU GPL version 3 section 7
0028 %
0029 %   If you modify MATPOWER, or any covered work, to interface with
0030 %   other modules (such as MATLAB code and MEX-files) available in a
0031 %   MATLAB(R) or comparable environment containing parts covered
0032 %   under other licensing terms, the licensors of MATPOWER grant
0033 %   you additional permission to convey the resulting work.
0034 
0035 %% define named indices into bus, gen, branch matrices
0036 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0037     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0038 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, ...
0039     GEN_STATUS, PMAX, PMIN, MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN] = idx_gen;
0040 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, ...
0041     RATE_C, TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST] = idx_brch;
0042 
0043 fd = 1; % output to screen
0044 
0045 %% sizes of things
0046 nb = size(bus, 1);      %% number of buses
0047 nl = size(branch, 1);   %% number of branches
0048 ng = size(gen, 1);      %% number of generators
0049 
0050 %% parameters
0051 ong  = find( gen(:, GEN_STATUS) > 0);
0052 nzld = find(bus(:, PD) | bus(:, QD));
0053 
0054 %% calculate losses
0055 loss = branch(:, PF) + j*branch(:, QF) + branch(:, PT) + j*branch(:, QT);
0056 
0057 %% ---output case and solver information
0058 fprintf(fd, '\n\n');
0059 if type_solver == 1 % newton's method
0060     fprintf(fd, 'Newton''s method is chosen to solve Power Flow.\n');
0061 elseif  type_solver == 2 % decoupled method
0062     fprintf(fd, 'Decoupled method is chosen to solve Power Flow.\n');
0063 else
0064     fprintf('Error: unknow ''type_solver''.\n');
0065     pause
0066 end
0067 
0068 if converged
0069     fprintf(fd, '\nConverged in %.2f seconds\n', et);
0070 else
0071     fprintf(fd, '\nDid not converge (%.2f seconds)\n', et);
0072 end
0073 fprintf(fd, '\n[iteration number]: %d\n', iterNum);
0074 
0075 %% ---output generation information
0076 fprintf(fd, '\n================================================================================');
0077 fprintf(fd, '\n|     Generator Data                                                           |');
0078 fprintf(fd, '\n================================================================================');
0079 fprintf(fd, '\n Gen   Bus   Status     Pg        Qg   ');
0080 fprintf(fd, '\n  #     #              (MW)     (MVAr) ');
0081 fprintf(fd, '\n----  -----  ------  --------  --------');
0082 for k = 1:length(ong)
0083     i = ong(k);
0084     fprintf(fd, '\n%3d %6d     %2d ', i, gen(i, GEN_BUS), gen(i, GEN_STATUS));
0085     if gen(i, GEN_STATUS) > 0 & (gen(i, PG) | gen(i, QG))
0086         fprintf(fd, '%10.2f%10.2f', gen(i, PG), gen(i, QG));
0087     else
0088         fprintf(fd, '       -         -  ');
0089     end
0090 end
0091 fprintf(fd, '\n                     --------  --------');
0092 fprintf(fd, '\n            Total: %9.2f%10.2f', sum(gen(ong, PG)), sum(gen(ong, QG)));
0093 fprintf(fd, '\n');
0094 
0095 %% ---output bus information
0096 fprintf(fd, '\n================================================================================');
0097 fprintf(fd, '\n|     Bus Data                                                                 |');
0098 fprintf(fd, '\n================================================================================');
0099 fprintf(fd, '\n Bus      Voltage          Generation             Load        ');
0100 fprintf(fd, '\n  #   Mag(pu) Ang(deg)   P (MW)   Q (MVAr)   P (MW)   Q (MVAr)');
0101 fprintf(fd, '\n----- ------- --------  --------  --------  --------  --------');
0102 for i = 1:nb
0103     fprintf(fd, '\n%5d%7.3f%9.3f', bus(i, [BUS_I, VM, VA]));
0104     g  = find(gen(:, GEN_STATUS) > 0 & gen(:, GEN_BUS) == bus(i, BUS_I));
0105     if ~isempty(g)
0106         fprintf(fd, '%10.2f%10.2f', sum(gen(g, PG)), sum(gen(g, QG)));
0107     else
0108         fprintf(fd, '       -         -  ');
0109     end
0110     if bus(i, PD) | bus(i, QD)
0111         fprintf(fd, '%10.2f%10.2f ', bus(i, [PD, QD]));
0112     else
0113         fprintf(fd, '       -         -   ');
0114     end
0115 end
0116 fprintf(fd, '\n                        --------  --------  --------  --------');
0117 fprintf(fd, '\n               Total: %9.2f %9.2f %9.2f %9.2f', ...
0118     sum(gen(ong, PG)), sum(gen(ong, QG)), ...
0119     sum(bus(nzld, PD)), ...
0120     sum(bus(nzld, QD)));
0121 fprintf(fd, '\n');
0122 
0123 %% ---output bus information
0124 fprintf(fd, '\n================================================================================');
0125 fprintf(fd, '\n|     Branch Data                                                              |');
0126 fprintf(fd, '\n================================================================================');
0127 fprintf(fd, '\nBrnch   From   To    From Bus Injection   To Bus Injection     Loss (I^2 * Z)  ');
0128 fprintf(fd, '\n  #     Bus    Bus    P (MW)   Q (MVAr)   P (MW)   Q (MVAr)   P (MW)   Q (MVAr)');
0129 fprintf(fd, '\n-----  -----  -----  --------  --------  --------  --------  --------  --------');
0130 fprintf(fd, '\n%4d%7d%7d%10.2f%10.2f%10.2f%10.2f%10.3f%10.2f', ...
0131         [   [1:nl]', branch(:, [F_BUS, T_BUS]), ...
0132             branch(:, [PF, QF]), branch(:, [PT, QT]), ...
0133             real(loss), imag(loss) ...
0134         ]');
0135 fprintf(fd, '\n                                                             --------  --------');
0136 fprintf(fd, '\n                                                    Total:%10.3f%10.2f', ...
0137         sum(real(loss)), sum(imag(loss)));
0138 fprintf(fd, '\n');

Generated on Mon 26-Jan-2015 15:00:13 by m2html © 2005