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

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