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

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