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

Generated on Mon 24-Jun-2019 15:58:45 by m2html © 2005