Home > matpower5.0 > case_info.m

case_info

PURPOSE ^

CASE_INFO Prints information about islands in a network.

SYNOPSIS ^

function [groupss, isolated] = case_info(mpc, fd)

DESCRIPTION ^

CASE_INFO Prints information about islands in a network.
   CASE_INFO(MPC)
   CASE_INFO(MPC, FD)
   [GROUPS, ISOLATED] = CASE_INFO(...)

   Prints out detailed information about a MATPOWER case. Optionally prints
   to an open file, whose file identifier, as returned by FOPEN, is
   specified in the optional second parameter FD. Optional return arguments
   include GROUPS and ISOLATED buses, as returned by FIND_ISLANDS.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [groupss, isolated] = case_info(mpc, fd)
0002 %CASE_INFO Prints information about islands in a network.
0003 %   CASE_INFO(MPC)
0004 %   CASE_INFO(MPC, FD)
0005 %   [GROUPS, ISOLATED] = CASE_INFO(...)
0006 %
0007 %   Prints out detailed information about a MATPOWER case. Optionally prints
0008 %   to an open file, whose file identifier, as returned by FOPEN, is
0009 %   specified in the optional second parameter FD. Optional return arguments
0010 %   include GROUPS and ISOLATED buses, as returned by FIND_ISLANDS.
0011 
0012 %   TO DO: Add checking of bus types (isolated bus not marked as such).
0013 %          Check for infeasible limits PMAX < PMIN, QMAX < QMIN, VMAX < VMIN,
0014 %               etc.
0015 %          Warn about islands without reference buses.
0016 %          Warn about PV and ref buses without generators.
0017 %          Separate branch charging injections from series losses.
0018 %          Report islands that are connected by DC lines.
0019 
0020 %   MATPOWER
0021 %   $Id: case_info.m 2472 2014-12-16 21:32:08Z ray $
0022 %   by Ray Zimmerman, PSERC Cornell
0023 %   Copyright (c) 2012-2013 by Power System Engineering Research Center (PSERC)
0024 %
0025 %   This file is part of MATPOWER.
0026 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0027 %
0028 %   MATPOWER is free software: you can redistribute it and/or modify
0029 %   it under the terms of the GNU General Public License as published
0030 %   by the Free Software Foundation, either version 3 of the License,
0031 %   or (at your option) any later version.
0032 %
0033 %   MATPOWER is distributed in the hope that it will be useful,
0034 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0035 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0036 %   GNU General Public License for more details.
0037 %
0038 %   You should have received a copy of the GNU General Public License
0039 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0040 %
0041 %   Additional permission under GNU GPL version 3 section 7
0042 %
0043 %   If you modify MATPOWER, or any covered work, to interface with
0044 %   other modules (such as MATLAB code and MEX-files) available in a
0045 %   MATLAB(R) or comparable environment containing parts covered
0046 %   under other licensing terms, the licensors of MATPOWER grant
0047 %   you additional permission to convey the resulting work.
0048 
0049 %% define named indices into data matrices
0050 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0051     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0052 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0053     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0054     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0055 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0056     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0057     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0058 c = idx_dcline;
0059 
0060 if nargin < 2
0061     fd = 1;     %% print to stdio by default
0062 end
0063 
0064 tic;
0065 
0066 %% load case if necessary
0067 mpc = loadcase(mpc);
0068 
0069 %% sizes of things
0070 nb  = size(mpc.bus, 1);     %% number of buses
0071 nl  = size(mpc.branch, 1);  %% number of branches
0072 if isfield(mpc, 'dcline')   %% number of DC lines
0073     ndc = size(mpc.dcline, 1);
0074 else
0075     ndc = 0;
0076 end
0077 ng  = size(mpc.gen, 1);     %% number of dispatchable injections
0078 
0079 %% max bus number
0080 mb  = max(abs([mpc.bus(:, BUS_I); mpc.gen(:, GEN_BUS); ...
0081             mpc.branch(:, F_BUS); mpc.branch(:, T_BUS)]));
0082 nbase = 10^(fix(log10(mb))+1);  %% negative bus numbers
0083                                 %% are subtracted from nbase
0084                                 %% to get something positive
0085 
0086 %% check for negative or zero bus numbers in bus matrix
0087 bus_i = mpc.bus(:, BUS_I);
0088 nonpos_bus = find(bus_i <= 0);
0089 bus_i(nonpos_bus) = -bus_i(nonpos_bus) + nbase;
0090 
0091 %% create external to internal bus map, with range for
0092 %% converted non-positive bus numbers
0093 e2i = sparse(bus_i, ones(nb, 1), 1:nb, nbase+mb, 1);
0094 
0095 %% find unknown bus numbers from gen, branch or dcline matrices
0096 unknown_gbus = unknown_buses(e2i, nbase, mpc.gen(:, GEN_BUS));
0097 unknown_fbus = unknown_buses(e2i, nbase, mpc.branch(:, F_BUS));
0098 unknown_tbus = unknown_buses(e2i, nbase, mpc.branch(:, T_BUS));
0099 if ndc
0100     unknown_fbusdc = unknown_buses(e2i, nbase, mpc.dcline(:, c.F_BUS));
0101     unknown_tbusdc = unknown_buses(e2i, nbase, mpc.dcline(:, c.T_BUS));
0102 end
0103 
0104 if length(nonpos_bus)
0105     fprintf(fd, 'Bad bus numbers:              %d\n', length(nonpos_bus));
0106     for k = 1:length(nonpos_bus)
0107         s = sprintf('bus(%d, BUS_I)', nonpos_bus(k));
0108         fprintf(fd, '%24s = %d\n', s, mpc.bus(nonpos_bus(k), BUS_I));
0109     end
0110 end
0111 if ~isempty(unknown_gbus)
0112     fprintf(fd, 'Unknown generator buses:      %d\n', length(unknown_gbus));
0113     for k = 1:length(unknown_gbus)
0114         s = sprintf('gen(%d, GEN_BUS)', unknown_gbus(k));
0115         fprintf(fd, '%24s = %d\n', s, mpc.gen(unknown_gbus(k), GEN_BUS));
0116     end
0117 
0118     %% remove them
0119     mpc.gen(unknown_gbus, :) = [];
0120     ng  = size(mpc.gen, 1);     %% number of dispatchable injections
0121 end
0122 if ~isempty(unknown_fbus)
0123     fprintf(fd, 'Unknown branch "from" buses:  %d\n', length(unknown_fbus));
0124     for k = 1:length(unknown_fbus)
0125         s = sprintf('branch(%d, F_BUS)', unknown_fbus(k));
0126         fprintf(fd, '%24s = %d\n', s, mpc.branch(unknown_fbus(k), F_BUS));
0127     end
0128 end
0129 if ~isempty(unknown_tbus)
0130     fprintf(fd, 'Unknown branch "to" buses:    %d\n', length(unknown_tbus));
0131     for k = 1:length(unknown_tbus)
0132         s = sprintf('branch(%d, T_BUS)', unknown_tbus(k));
0133         fprintf(fd, '%24s = %d\n', s, mpc.branch(unknown_tbus(k), T_BUS));
0134     end
0135 end
0136 %% remove branches connected to unknown buses
0137 if ~isempty(unknown_fbus) || ~isempty(unknown_tbus)
0138     tmp = unique([unknown_fbus; unknown_tbus]);
0139     mpc.branch(tmp, :) = [];    %% remove them
0140     nl  = size(mpc.branch, 1);  %% number of branches
0141 end
0142 if ndc
0143     if ~isempty(unknown_fbusdc)
0144         fprintf(fd, 'Unknown DC line "from" buses: %d\n', length(unknown_fbusdc));
0145         for k = 1:length(unknown_fbusdc)
0146             s = sprintf('dcline(%d, c.F_BUS)', unknown_fbusdc(k));
0147             fprintf(fd, '%24s = %d\n', s, mpc.dcline(unknown_fbusdc(k), c.F_BUS));
0148         end
0149     end
0150     if ~isempty(unknown_tbusdc)
0151         fprintf(fd, 'Unknown DC line "to" buses:   %d\n', length(unknown_tbusdc));
0152         for k = 1:length(unknown_tbusdc)
0153             s = sprintf('dcline(%d, c.T_BUS)', unknown_tbusdc(k));
0154             fprintf(fd, '%24s = %d\n', s, mpc.dcline(unknown_tbusdc(k), c.T_BUS));
0155         end
0156     end
0157     %% remove branches connected to unknown buses
0158     if ~isempty(unknown_fbusdc) || ~isempty(unknown_tbusdc)
0159         tmp = unique([unknown_fbusdc; unknown_tbusdc]);
0160         mpc.dcline(tmp, :) = [];    %% remove them
0161         ndc  = size(mpc.dcline, 1); %% number of DC lines
0162     end
0163 end
0164 
0165 %% build connectivity structures
0166 C_on = sparse(1:nl, e2i(mpc.branch(:, F_BUS)), -mpc.branch(:, BR_STATUS), nl, nb) + ...
0167     sparse(1:nl, e2i(mpc.branch(:, T_BUS)),  mpc.branch(:, BR_STATUS), nl, nb);
0168 C = sparse(1:nl, e2i(mpc.branch(:, F_BUS)), -1, nl, nb) + ...
0169     sparse(1:nl, e2i(mpc.branch(:, T_BUS)),  1, nl, nb);
0170 if ndc
0171     Cdc_on = sparse(1:ndc, e2i(mpc.dcline(:, c.F_BUS)), -mpc.dcline(:, c.BR_STATUS), ndc, nb) + ...
0172         sparse(1:ndc, e2i(mpc.dcline(:, c.T_BUS)),  mpc.dcline(:, c.BR_STATUS), ndc, nb);
0173     Cdc = sparse(1:ndc, e2i(mpc.dcline(:, c.F_BUS)), -1, ndc, nb) + ...
0174         sparse(1:ndc, e2i(mpc.dcline(:, c.T_BUS)),  1, ndc, nb);
0175 end
0176 Cg_on = sparse(1:ng, e2i(mpc.gen(:, GEN_BUS)), mpc.gen(:, GEN_STATUS), ng, nb);
0177 Cg = sparse(1:ng, e2i(mpc.gen(:, GEN_BUS)), 1, ng, nb);
0178 
0179 %% check for islands
0180 fprintf(fd, 'Checking connectivity ... ');
0181 [groups, isolated] = connected_components(C_on);
0182 
0183 ngr = length(groups);   %% number of islands
0184 nis = length(isolated); %% number of isolated buses
0185 have_isolated = nis > 0;
0186 if ngr == 1
0187     if have_isolated
0188         if nis == 1, s = ''; else, s = 'es'; end
0189         fprintf(fd, 'single connected network, plus %d isolated bus%s\n', nis, s);
0190     else
0191         fprintf(fd, 'single fully connected network\n');
0192     end
0193 else
0194     if nis == 1, s = ''; else, s = 'es'; end
0195     fprintf(fd, '%d connected groups, %d isolated bus%s\n', ngr, nis, s);
0196 end
0197 
0198 %% collect info on groups
0199 bron  = mpc.branch(:, BR_STATUS)  > 0;
0200 broff = mpc.branch(:, BR_STATUS) <= 0;
0201 if ndc
0202     dcon  = mpc.dcline(:, c.BR_STATUS)  > 0;
0203     dcoff = mpc.dcline(:, c.BR_STATUS) <= 0;
0204 end
0205 gon   = mpc.gen(:, GEN_STATUS)  > 0;
0206 goff  = mpc.gen(:, GEN_STATUS) <= 0;
0207 
0208 %% initialize data structures
0209 d0 = struct( ...
0210     'nb', 0, ...
0211     'nl', 0, ...
0212     'nl_on', 0, ...
0213     'nl_off', 0, ...
0214     'nlt', 0, ...
0215 ...%     'nlt_on', 0, ... %% (always zero)
0216     'nlt_off', 0, ...
0217     'ndc', 0, ...
0218     'ndc_on', 0, ...
0219     'ndc_off', 0, ...
0220     'ndct', 0, ...
0221     'ndct_on', 0, ...
0222     'ndct_off', 0, ...
0223     'ndc_all', 0, ...
0224     'ng', 0, ...
0225     'ng_on', 0, ...
0226     'ng_off', 0, ...
0227     'nsh', 0, ...
0228     'nld', 0, ...
0229     'nld_on', 0, ...
0230     'nld_off', 0, ...
0231     'nfld', 0, ...
0232     'ndld', 0, ...
0233     'ndld_on', 0, ...
0234     'ndld_off', 0, ...
0235     'Pmax', 0, ...
0236     'Qmax', 0, ...
0237     'Pmax_on', 0, ...
0238     'Qmax_on', 0, ...
0239     'Pmax_off', 0, ...
0240     'Qmax_off', 0, ...
0241     'Pmin', 0, ...
0242     'Qmin', 0, ...
0243     'Pmin_on', 0, ...
0244     'Qmin_on', 0, ...
0245     'Pmin_off', 0, ...
0246     'Qmin_off', 0, ...
0247     'Pg', 0, ...
0248     'Qg', 0, ...
0249     'Ps', 0, ...
0250     'Qs', 0, ...
0251     'Ploss', 0, ...
0252     'Qloss', 0, ...
0253     'Pd', 0, ...
0254     'Qd', 0, ...
0255     'Pd_fixed', 0, ...
0256     'Qd_fixed', 0, ...
0257     'Pd_disp_cap', 0, ...
0258     'Qd_disp_cap', 0, ...
0259     'Pd_disp_cap_on', 0, ...
0260     'Qd_disp_cap_on', 0, ...
0261     'Pd_disp_cap_off', 0, ...
0262     'Qd_disp_cap_off', 0, ...
0263     'Pd_disp', 0, ...
0264     'Qd_disp', 0, ...
0265     'Pd_cap', 0, ...
0266     'Qd_cap', 0, ...
0267     'Pd_cap_on', 0, ...
0268     'Qd_cap_on', 0, ...
0269     'Pd_cap_off', 0, ...
0270     'Qd_cap_off', 0, ...
0271     'Pdc', 0, ...
0272     'Pmaxdc', 0, ...
0273     'Pmaxdc_on', 0, ...
0274     'Pmaxdc_off', 0, ...
0275     'Pmindc', 0, ...
0276     'Pmindc_on', 0, ...
0277     'Pmindc_off', 0 ...
0278 );
0279 d = d0;
0280 total = d0;
0281 allrefs = find(mpc.bus(:, BUS_TYPE) == REF);
0282 refs = {};
0283 nrefs = 0;
0284 ibr_tie_all = [];
0285 idc_tie_all = [];
0286 idc_tie_all_on  = [];
0287 idc_tie_all_off = [];
0288 
0289 %% gather data
0290 fields = fieldnames(d);
0291 for k = 1:ngr+have_isolated
0292     %% initialize d(k)
0293     for f = 1:length(fields)
0294         ff = fields{f};
0295         d(k).(ff) = d0.(ff);
0296     end
0297     if k > ngr
0298         b = isolated';
0299         ibr = [];
0300         idc = [];
0301     else
0302         b = groups{k};
0303         %% branches with both ends in group
0304         ibr = find(sum(abs(C(:, b)), 2) & ~sum(C(:, b), 2));
0305         if ndc
0306             idc = find(sum(abs(Cdc(:, b)), 2) & ~sum(Cdc(:, b), 2));
0307         else
0308             idc = [];
0309         end
0310     end
0311     %% branches with one end in group
0312     ibr_tie = find(sum(C(:, b), 2));
0313     if ndc
0314         idc_tie = find(sum(Cdc(:, b), 2));
0315     else
0316         idc_tie = [];
0317     end
0318     refs{k} = b(find(mpc.bus(b, BUS_TYPE) == REF));
0319     nrefs = nrefs + length(refs{k});
0320 
0321     ibr_on  = ibr(find(bron(ibr)));
0322     ibr_off = ibr(find(broff(ibr)));
0323 %     ibr_tie_on  = ibr_tie(find(bron(ibr_tie))); %% (always empty)
0324     ibr_tie_off = ibr_tie(find(broff(ibr_tie)));
0325     ibr_tie_all = unique([ ibr_tie_all; ibr_tie_off ]);
0326     if ndc
0327         idc_on  = idc(find(dcon(idc)));
0328         idc_off = idc(find(dcoff(idc)));
0329         idc_tie_on  = idc_tie(find(dcon(idc_tie)));
0330         idc_tie_off = idc_tie(find(dcoff(idc_tie)));
0331         idc_tie_all = unique([ idc_tie_all; idc_tie ]);
0332         idc_tie_all_on  = unique([ idc_tie_all_on;  idc_tie_on ]);
0333         idc_tie_all_off = unique([ idc_tie_all_off; idc_tie_off ]);
0334     end
0335     ig      = find(sum(abs(Cg(:, b)), 2));
0336     ig_on   = ig(find(gon(ig)  & ~isload(mpc.gen(ig, :))));
0337     ig_off  = ig(find(goff(ig) & ~isload(mpc.gen(ig, :))));
0338     idld_on = ig(find(gon(ig)  &  isload(mpc.gen(ig, :))));
0339     idld_off= ig(find(goff(ig) &  isload(mpc.gen(ig, :))));
0340 
0341     d(k).nb = length(b);        %% # of buses
0342     d(k).nl = length(ibr);      %% # of branches
0343     d(k).nl_on  = length(ibr_on);   %% # of in-service branches
0344     d(k).nl_off = length(ibr_off);  %% # of out-of-service branches
0345     d(k).nlt = length(ibr_tie);     %% # of tie-lines
0346 %     d(k).nlt_on  = length(ibr_tie_on);  %% # of in-service tie-lines (always zero)
0347     d(k).nlt_off = length(ibr_tie_off); %% # of out-of-service tie-lines
0348     if ndc
0349         d(k).ndc = length(idc);      %% # of dc lines
0350         d(k).ndc_on  = length(idc_on);   %% # of in-service dc lines
0351         d(k).ndc_off = length(idc_off);  %% # of out-of-service dc lines
0352         d(k).ndct = length(idc_tie);      %% # of dc tie-lines
0353         d(k).ndct_on  = length(idc_tie_on);   %% # of in-service dc tie-lines
0354         d(k).ndct_off = length(idc_tie_off);  %% # of out-of-service dc tie-lines
0355         d(k).ndc_all = d(k).ndc + d(k).ndct;
0356     end
0357     d(k).ng = length(ig_on) + length(ig_off);   %% # of gen
0358     d(k).ng_on  = length(ig_on);    %% # of in-service gens
0359     d(k).ng_off = length(ig_off);   %% # of out-of-service gens
0360     d(k).nsh = length(find(mpc.bus(b, GS) ~= 0 | mpc.bus(b, BS) ~= 0)); %% # of shunt elements
0361     d(k).nfld = length(find(mpc.bus(b, PD) ~= 0 | mpc.bus(b, QD) ~= 0));    %% # of fixed loads
0362     d(k).ndld = length(idld_on) + length(idld_off); %% # of disp loads
0363     d(k).ndld_on  = length(idld_on);    %% # of in-service disp loads
0364     d(k).ndld_off = length(idld_off);   %% # of out-of-service disp loads
0365     d(k).nld = d(k).nfld + d(k).ndld;   %% # of fixed + disp loads
0366     d(k).nld_on  = d(k).nfld + d(k).ndld_on;    %% # of in-service fixed + disp loads
0367     d(k).nld_off = d(k).ndld_off;       %% # of out-of-service fixed + disp loads
0368 
0369     d(k).Pmax_on    = sum(mpc.gen(ig_on,  PMAX));
0370     d(k).Pmax_off   = sum(mpc.gen(ig_off, PMAX));
0371     d(k).Pmax       = d(k).Pmax_on + d(k).Pmax_off;
0372     d(k).Pmin_on    = sum(mpc.gen(ig_on,  PMIN));
0373     d(k).Pmin_off   = sum(mpc.gen(ig_off, PMIN));
0374     d(k).Pmin       = d(k).Pmin_on + d(k).Pmin_off;
0375     d(k).Pg         = sum(mpc.gen(ig_on,  PG));
0376 
0377     d(k).Qmax_on    = sum(mpc.gen(ig_on,  QMAX));
0378     d(k).Qmax_off   = sum(mpc.gen(ig_off, QMAX));
0379     d(k).Qmax       = d(k).Qmax_on + d(k).Qmax_off;
0380     d(k).Qmin_on    = sum(mpc.gen(ig_on,  QMIN));
0381     d(k).Qmin_off   = sum(mpc.gen(ig_off, QMIN));
0382     d(k).Qmin       = d(k).Qmin_on + d(k).Qmin_off;
0383     d(k).Qg         = sum(mpc.gen(ig_on,  QG));
0384 
0385     d(k).Ps         = sum(-mpc.bus(b, VM) .^ 2 .* mpc.bus(b, GS));
0386     d(k).Qs         = sum( mpc.bus(b, VM) .^ 2 .* mpc.bus(b, BS));
0387     if size(mpc.branch, 2) > PF
0388         d(k).Ploss      = sum(mpc.branch(ibr_on, PF) + mpc.branch(ibr_on, PT));
0389         d(k).Qloss      = sum(mpc.branch(ibr_on, QF) + mpc.branch(ibr_on, QT));
0390     end
0391 
0392     d(k).Pd_fixed   = sum(mpc.bus(b, PD));
0393     d(k).Qd_fixed   = sum(mpc.bus(b, QD));
0394     d(k).Pd_disp_cap_on     = sum(-mpc.gen(idld_on,  PMIN));
0395     d(k).Qd_disp_cap_on     = sum(-mpc.gen(idld_on,  QMIN));
0396     d(k).Pd_disp_cap_off    = sum(-mpc.gen(idld_off, PMIN));
0397     d(k).Qd_disp_cap_off    = sum(-mpc.gen(idld_off, QMIN));
0398     d(k).Pd_disp_cap        = d(k).Pd_disp_cap_on + d(k).Pd_disp_cap_off;
0399     d(k).Qd_disp_cap        = d(k).Qd_disp_cap_on + d(k).Qd_disp_cap_off;
0400     d(k).Pd_disp            = sum(-mpc.gen(idld_on,  PG));
0401     d(k).Qd_disp            = sum(-mpc.gen(idld_on,  QG));
0402     d(k).Pd                 = d(k).Pd_fixed + d(k).Pd_disp;
0403     d(k).Qd                 = d(k).Qd_fixed + d(k).Qd_disp;
0404     d(k).Pd_cap             = d(k).Pd_fixed + d(k).Pd_disp_cap;
0405     d(k).Qd_cap             = d(k).Qd_fixed + d(k).Qd_disp_cap;
0406     d(k).Pd_cap_on          = d(k).Pd_fixed + d(k).Pd_disp_cap_on;
0407     d(k).Qd_cap_on          = d(k).Qd_fixed + d(k).Qd_disp_cap_on;
0408     d(k).Pd_cap_off         = d(k).Pd_disp_cap_off;
0409     d(k).Qd_cap_off         = d(k).Qd_disp_cap_off;
0410 
0411     if ndc
0412         f = find(sum(Cdc(:, b), 2) < 0);
0413         t = find(sum(Cdc(:, b), 2) > 0);
0414         d(k).Pdc    = sum(mpc.dcline(f, c.PF)) - sum(mpc.dcline(t, c.PT));
0415         d(k).Pmaxdc = sum(mpc.dcline(f, c.PMAX)) - sum(mpc.dcline(t, c.PMAX));
0416         d(k).Pmindc = sum(mpc.dcline(f, c.PMIN)) - sum(mpc.dcline(t, c.PMIN));
0417         f = find(sum(Cdc(:, b), 2) < 0 & dcon);
0418         t = find(sum(Cdc(:, b), 2) > 0 & dcon);
0419         d(k).Pmaxdc_on = sum(mpc.dcline(f, c.PMAX)) - sum(mpc.dcline(t, c.PMAX));
0420         d(k).Pmindc_on = sum(mpc.dcline(f, c.PMIN)) - sum(mpc.dcline(t, c.PMIN));
0421         f = find(sum(Cdc(:, b), 2) < 0 & dcoff);
0422         t = find(sum(Cdc(:, b), 2) > 0 & dcoff);
0423         d(k).Pmaxdc_off = sum(mpc.dcline(f, c.PMAX)) - sum(mpc.dcline(t, c.PMAX));
0424         d(k).Pmindc_off = sum(mpc.dcline(f, c.PMIN)) - sum(mpc.dcline(t, c.PMIN));
0425     end
0426 
0427     %% accumulate totals
0428     for f = 1:length(fields)
0429         ff = fields{f};
0430         total.(ff) = total.(ff) + d(k).(ff);
0431     end
0432 
0433     total.nl = nl;
0434     total.nl_on  = length(find(bron));
0435     total.nl_off = length(find(broff));
0436     total.ndc = ndc;
0437     if ndc
0438         total.ndc_on  = length(find(dcon));
0439         total.ndc_off = length(find(dcoff));
0440     else
0441         total.ndc_on  = 0;
0442         total.ndc_off = 0;
0443     end
0444 end
0445 total.nlt       = length(ibr_tie_all);
0446 % total.nlt_on  = 0;
0447 total.nlt_off   = length(ibr_tie_all);
0448 if ndc
0449     total.ndct      = length(idc_tie_all);
0450     total.ndct_on   = length(idc_tie_all_on);
0451     total.ndct_off  = length(idc_tie_all_off);
0452 end
0453 
0454 %% print summary
0455 et = toc;
0456 fprintf(fd, 'Elapsed time is %f seconds.\n', et);
0457 fprintf(fd, '================================================================================\n');
0458 pages = ceil((ngr + have_isolated + 1) / 5);
0459 for page = 1:pages
0460     if page == 1
0461         if ngr == 1 && ~have_isolated
0462             islands = [];
0463         else
0464             islands = 1:min(4, ngr+have_isolated);
0465         end
0466     else
0467         fprintf(fd, '--------------------------------------------------------------------------------\n');
0468         islands = (5*(page-1)):min(5*page-1, ngr+have_isolated);
0469     end
0470 
0471     %% header row 1
0472     fprintf(fd, '%-20s', '');
0473     if page == 1
0474         fprintf(fd, '    Full    ');
0475     end
0476     for k = islands
0477         if k > ngr
0478             fprintf(fd, '  Isolated  ');
0479         else
0480             fprintf(fd, '   Island   ');
0481         end
0482     end
0483     fprintf(fd, '\n');
0484 
0485     %% header row 2
0486     fprintf(fd, '%-20s', '');
0487     if page == 1
0488         fprintf(fd, '   System   ');
0489     end
0490     for k = islands
0491         if k > ngr
0492             fprintf(fd, '    Buses   ');
0493         else
0494             fprintf(fd, '  %5d     ', k);
0495         end
0496     end
0497     fprintf(fd, '\n');
0498 
0499     %% header row 3
0500     fprintf(fd, '%-20s', 'Number of:');
0501     if page == 1
0502         fprintf(fd, ' ---------- ');
0503     end
0504     for k = islands
0505         fprintf(fd, ' ---------- ');
0506     end
0507     fprintf(fd, '\n');
0508 
0509     p = struct('page', page, 'islands', islands, 'total', total, 'd', d);
0510 
0511     print_row(fd, p, ' %8d   ', '  buses',          'nb');
0512     print_row(fd, p, ' %8d   ', '  loads',          'nld');
0513     print_row(fd, p, ' %8d   ', '    on',           'nld_on');
0514     print_row(fd, p, ' %8d   ', '    off',          'nld_off');
0515     print_row(fd, p, ' %8d   ', '    fixed',        'nfld');
0516     print_row(fd, p, ' %8d   ', '    dispatchable', 'ndld');
0517     print_row(fd, p, ' %8d   ', '      on',         'ndld_on');
0518     print_row(fd, p, ' %8d   ', '      off',        'ndld_off');
0519     print_row(fd, p, ' %8d   ', '  generators',     'ng');
0520     print_row(fd, p, ' %8d   ', '    on',           'ng_on');
0521     print_row(fd, p, ' %8d   ', '    off',          'ng_off');
0522     print_row(fd, p, ' %8d   ', '  shunt elements', 'nsh');
0523     print_row(fd, p, ' %8d   ', '  branches',       'nl');
0524     print_row(fd, p, ' %8d   ', '    on',           'nl_on');
0525     print_row(fd, p, ' %8d   ', '    off',          'nl_off');
0526 %     print_row(fd, p, ' %8d   ', '    ties',         'nlt');     %% (always same as nlt_off)
0527     print_row(fd, p, ' %8d   ', '    ties (off)',   'nlt_off');
0528     if ndc
0529         print_row(fd, p, ' %8d   ', '  DC lines',     'ndc_all');
0530         print_row(fd, p, ' %8d   ', '    within',     'ndc');
0531         print_row(fd, p, ' %8d   ', '      on',       'ndc_on');
0532         print_row(fd, p, ' %8d   ', '      off',      'ndc_off');
0533         print_row(fd, p, ' %8d   ', '    ties',       'ndct');
0534         print_row(fd, p, ' %8d   ', '      on',       'ndct_on');
0535         print_row(fd, p, ' %8d   ', '      off',      'ndct_off');
0536     end
0537 
0538     fprintf(fd, '\n%-20s\n', 'Load');
0539     fprintf(fd,   '%-20s\n', '  active (MW)');
0540     print_row(fd, p, '%11.1f ', '    dispatched',       'Pd');
0541     print_row(fd, p, '%11.1f ', '      fixed',          'Pd_fixed');
0542     print_row(fd, p, '%11.1f ', '      dispatchable',   'Pd_disp');
0543     print_row(fd, p, '%11.1f ', '    nominal',          'Pd_cap');
0544     print_row(fd, p, '%11.1f ', '      on',             'Pd_cap_on');
0545     print_row(fd, p, '%11.1f ', '      off',            'Pd_cap_off');
0546     print_row(fd, p, '%11.1f ', '      fixed',          'Pd_fixed');
0547     print_row(fd, p, '%11.1f ', '      dispatchable',   'Pd_disp_cap');
0548     print_row(fd, p, '%11.1f ', '        on',           'Pd_disp_cap_on');
0549     print_row(fd, p, '%11.1f ', '        off',          'Pd_disp_cap_off');
0550     fprintf(fd,   '%-20s\n', '  reactive (MVAr)');
0551     print_row(fd, p, '%11.1f ', '    dispatched',       'Qd');
0552     print_row(fd, p, '%11.1f ', '      fixed',          'Qd_fixed');
0553     print_row(fd, p, '%11.1f ', '      dispatchable',   'Qd_disp');
0554     print_row(fd, p, '%11.1f ', '    nominal',          'Qd_cap');
0555     print_row(fd, p, '%11.1f ', '      on',             'Qd_cap_on');
0556     print_row(fd, p, '%11.1f ', '      off',            'Qd_cap_off');
0557     print_row(fd, p, '%11.1f ', '      fixed',          'Qd_fixed');
0558     print_row(fd, p, '%11.1f ', '      dispatchable',   'Qd_disp_cap');
0559     print_row(fd, p, '%11.1f ', '        on',           'Qd_disp_cap_on');
0560     print_row(fd, p, '%11.1f ', '        off',          'Qd_disp_cap_off');
0561 
0562     fprintf(fd, '\n%-20s\n', 'Generation');
0563     fprintf(fd,   '%-20s\n', '  active (MW)');
0564     print_row(fd, p, '%11.1f ', '    dispatched',       'Pg');
0565     print_row(fd, p, '%11.1f ', '    max capacity',     'Pmax');
0566     print_row(fd, p, '%11.1f ', '      on',             'Pmax_on');
0567     print_row(fd, p, '%11.1f ', '      off',            'Pmax_off');
0568     print_row(fd, p, '%11.1f ', '    min capacity',     'Pmin');
0569     print_row(fd, p, '%11.1f ', '      on',             'Pmin_on');
0570     print_row(fd, p, '%11.1f ', '      off',            'Pmin_off');
0571     fprintf(fd,   '%-20s\n', '  reactive (MVAr)');
0572     print_row(fd, p, '%11.1f ', '    dispatched',       'Qg');
0573     print_row(fd, p, '%11.1f ', '    max capacity',     'Qmax');
0574     print_row(fd, p, '%11.1f ', '      on',             'Qmax_on');
0575     print_row(fd, p, '%11.1f ', '      off',            'Qmax_off');
0576     print_row(fd, p, '%11.1f ', '    min capacity',     'Qmin');
0577     print_row(fd, p, '%11.1f ', '      on',             'Qmin_on');
0578     print_row(fd, p, '%11.1f ', '      off',            'Qmin_off');
0579 
0580     fprintf(fd, '\n%-20s\n', 'Shunt Injections');
0581     print_row(fd, p, '%11.1f ', '    active (MW)',      'Ps');
0582     print_row(fd, p, '%11.1f ', '    reactive (MVAr)',  'Qs');
0583 
0584     fprintf(fd, '\n%-20s\n', 'Branch Losses');
0585     print_row(fd, p, '%11.1f ', '    active (MW)',      'Ploss');
0586     print_row(fd, p, '%11.1f ', '    reactive (MVAr)',  'Qloss');
0587 
0588     fprintf(fd, '\n%-20s\n', 'DC line');
0589     fprintf(fd,   '%-20s\n', '  export (MW)');
0590     print_row(fd, p, '%11.1f ', '    dispatch',      'Pdc');
0591     print_row(fd, p, '%11.1f ', '    max capacity',  'Pmaxdc');
0592     print_row(fd, p, '%11.1f ', '      on',          'Pmaxdc_on');
0593     print_row(fd, p, '%11.1f ', '      off',         'Pmaxdc_off');
0594     print_row(fd, p, '%11.1f ', '    min capacity',  'Pmindc');
0595     print_row(fd, p, '%11.1f ', '      on',          'Pmindc_on');
0596     print_row(fd, p, '%11.1f ', '      off',         'Pmindc_off');
0597 
0598     fprintf(fd, '\n%-20s\n', 'Reference Buses');
0599 
0600     fprintf(fd, '%-20s', '  num of ref buses');
0601     if page == 1
0602         fprintf(fd, ' %8d   ', nrefs);
0603     end
0604     for k = islands
0605         fprintf(fd, ' %8d   ', length(refs{k}));
0606     end
0607     fprintf(fd, '\n');
0608 
0609     for j = 1:nrefs
0610         if j == 1
0611             fprintf(fd, '%-20s', '  ref bus numbers');
0612         else
0613             fprintf(fd, '%-20s', '');
0614         end
0615         if page == 1
0616             fprintf(fd, ' %8d   ', mpc.bus(allrefs(j), BUS_I));
0617         end
0618         for k = islands
0619             if j <= length(refs{k})
0620                 fprintf(fd, ' %8d   ', mpc.bus(refs{k}(j), BUS_I));
0621             else
0622                 fprintf(fd, ' %8s   ', '');
0623             end
0624         end
0625         fprintf(fd, '\n');
0626     end
0627 
0628     if page ~= pages
0629         fprintf(fd, '\n\n');
0630     end
0631 end
0632 
0633 %% assign output arguments as requested
0634 if nargout > 0
0635     groupss = groups;
0636 end
0637 
0638 
0639 function print_row(fd, p, template, name, field)
0640 templatez = sprintf('%%%ds', length(sprintf(template, 0)));
0641 fprintf(fd, '%-20s', name);
0642 if p.page == 1
0643     if p.total.(field) == 0
0644         fprintf(fd, templatez, '-   ');
0645     else
0646         fprintf(fd, template, p.total.(field));
0647     end
0648 end
0649 for k = p.islands
0650     if p.d(k).(field) == 0
0651         fprintf(fd, templatez, '-   ');
0652     else
0653         fprintf(fd, template, p.d(k).(field));
0654     end
0655 end
0656 fprintf(fd, '\n');
0657 
0658 
0659 function unknown = unknown_buses(e2i, nbase, bus_list)
0660 nonpos = find(bus_list <= 0);
0661 bus_list(nonpos) = -bus_list(nonpos) + nbase;
0662 unknown = find(e2i(bus_list) == 0);

Generated on Mon 26-Jan-2015 15:21:31 by m2html © 2005