Home > matpower5.1 > total_load.m

total_load

PURPOSE ^

TOTAL_LOAD Returns vector of total load in each load zone.

SYNOPSIS ^

function [Pd, Qd] = total_load(bus, gen, load_zone, opt)

DESCRIPTION ^

TOTAL_LOAD Returns vector of total load in each load zone.
   PD = TOTAL_LOAD(BUS) returns active power demand for each zone.
   PD = TOTAL_LOAD(BUS, GEN, LOAD_ZONE, OPT)
   [PD, QD] = TOTAL_LOAD(...) returns both active and reative power
   demand for each zone.

   BUS - standard BUS matrix with nb rows, where the fixed active
       and reactive loads are specified in columns PD and QD

   GEN - (optional) standard GEN matrix with ng rows, where the
       dispatchable loads are specified by columns PG, QG, PMIN,
       QMIN and QMAX (in rows for which ISLOAD(GEN) returns true).
       If GEN is empty, it assumes there are no dispatchable loads.

   LOAD_ZONE - (optional) nb element vector where the value of
       each element is either zero or the index of the load zone
       to which the corresponding bus belongs. If LOAD_ZONE(b) = k
       then the loads at bus b will added to the values of PD(k) and
       QD(k). If LOAD_ZONE is empty, the default is defined as the areas
       specified in the BUS matrix, i.e. LOAD_ZONE = BUS(:, BUS_AREA)
       and load will have dimension = MAX(BUS(:, BUS_AREA)). If
       LOAD_ZONE = 'all', the result is a scalar with the total system
       load.

   OPT - (optional) option struct, with the following fields:
           'type'  -  string specifying types of loads to include, default
                      is 'BOTH' if GEN is provided, otherwise 'FIXED'
               'FIXED'        : sum only fixed loads
               'DISPATCHABLE' : sum only dispatchable loads
               'BOTH'         : sum both fixed and dispatchable loads
           'nominal' -  1 : use nominal load for dispatchable loads
                        0 : (default) use actual realized load for
                             dispatchable loads

       For backward compatibility with MATPOWER 4.x, OPT can also
       take the form of a string, with the same options as OPT.type above.
       In this case, again for backward compatibility, it is the "nominal"
       load that is computed for dispatchable loads, not the actual
       realized load. Using a string for OPT is deprecated and
       will be removed in a future version.

   Examples:
       Return the total active load for each area as defined in BUS_AREA.

       Pd = total_load(bus);

       Return total active and reactive load, fixed and dispatchable, for
       entire system.

       [Pd, Qd] = total_load(bus, gen, 'all');

       Return the total of the nominal dispatchable loads at buses 10-20.

       load_zone = zeros(nb, 1);
       load_zone(10:20) = 1;
       opt = struct('type', 'DISPATCHABLE', 'nominal', 1);
       Pd = total_load(bus, gen, load_zone, opt)

   See also SCALE_LOAD.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [Pd, Qd] = total_load(bus, gen, load_zone, opt)
0002 %TOTAL_LOAD Returns vector of total load in each load zone.
0003 %   PD = TOTAL_LOAD(BUS) returns active power demand for each zone.
0004 %   PD = TOTAL_LOAD(BUS, GEN, LOAD_ZONE, OPT)
0005 %   [PD, QD] = TOTAL_LOAD(...) returns both active and reative power
0006 %   demand for each zone.
0007 %
0008 %   BUS - standard BUS matrix with nb rows, where the fixed active
0009 %       and reactive loads are specified in columns PD and QD
0010 %
0011 %   GEN - (optional) standard GEN matrix with ng rows, where the
0012 %       dispatchable loads are specified by columns PG, QG, PMIN,
0013 %       QMIN and QMAX (in rows for which ISLOAD(GEN) returns true).
0014 %       If GEN is empty, it assumes there are no dispatchable loads.
0015 %
0016 %   LOAD_ZONE - (optional) nb element vector where the value of
0017 %       each element is either zero or the index of the load zone
0018 %       to which the corresponding bus belongs. If LOAD_ZONE(b) = k
0019 %       then the loads at bus b will added to the values of PD(k) and
0020 %       QD(k). If LOAD_ZONE is empty, the default is defined as the areas
0021 %       specified in the BUS matrix, i.e. LOAD_ZONE = BUS(:, BUS_AREA)
0022 %       and load will have dimension = MAX(BUS(:, BUS_AREA)). If
0023 %       LOAD_ZONE = 'all', the result is a scalar with the total system
0024 %       load.
0025 %
0026 %   OPT - (optional) option struct, with the following fields:
0027 %           'type'  -  string specifying types of loads to include, default
0028 %                      is 'BOTH' if GEN is provided, otherwise 'FIXED'
0029 %               'FIXED'        : sum only fixed loads
0030 %               'DISPATCHABLE' : sum only dispatchable loads
0031 %               'BOTH'         : sum both fixed and dispatchable loads
0032 %           'nominal' -  1 : use nominal load for dispatchable loads
0033 %                        0 : (default) use actual realized load for
0034 %                             dispatchable loads
0035 %
0036 %       For backward compatibility with MATPOWER 4.x, OPT can also
0037 %       take the form of a string, with the same options as OPT.type above.
0038 %       In this case, again for backward compatibility, it is the "nominal"
0039 %       load that is computed for dispatchable loads, not the actual
0040 %       realized load. Using a string for OPT is deprecated and
0041 %       will be removed in a future version.
0042 %
0043 %   Examples:
0044 %       Return the total active load for each area as defined in BUS_AREA.
0045 %
0046 %       Pd = total_load(bus);
0047 %
0048 %       Return total active and reactive load, fixed and dispatchable, for
0049 %       entire system.
0050 %
0051 %       [Pd, Qd] = total_load(bus, gen, 'all');
0052 %
0053 %       Return the total of the nominal dispatchable loads at buses 10-20.
0054 %
0055 %       load_zone = zeros(nb, 1);
0056 %       load_zone(10:20) = 1;
0057 %       opt = struct('type', 'DISPATCHABLE', 'nominal', 1);
0058 %       Pd = total_load(bus, gen, load_zone, opt)
0059 %
0060 %   See also SCALE_LOAD.
0061 
0062 %   MATPOWER
0063 %   Copyright (c) 2004-2015 by Power System Engineering Research Center (PSERC)
0064 %   by Ray Zimmerman, PSERC Cornell
0065 %
0066 %   $Id: total_load.m 2644 2015-03-11 19:34:22Z ray $
0067 %
0068 %   This file is part of MATPOWER.
0069 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0070 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0071 
0072 %% define constants
0073 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0074     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0075 %% purposely being backward compatible with older MATPOWER
0076 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, ...
0077     PMAX, PMIN, MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN] = idx_gen;
0078 
0079 nb = size(bus, 1);          %% number of buses
0080 
0081 %%-----  process inputs  -----
0082 if nargin < 4
0083     opt = [];
0084     if nargin < 3
0085         load_zone = [];
0086         if nargin < 2
0087             gen = [];
0088         end
0089     end
0090 end
0091 
0092 %% default options
0093 if ischar(opt)      %% convert old WHICH_TYPE string option to struct
0094     opt = struct('type', opt, 'nominal', 1);
0095 else
0096     if ~isfield(opt, 'type')
0097         if isempty(gen)
0098             opt.type = 'FIXED';
0099         else
0100             opt.type = 'BOTH';
0101         end
0102     end
0103     if ~isfield(opt, 'nominal')
0104         opt.nominal = 0;
0105     end
0106 end
0107 switch upper(opt.type(1))
0108     case {'F', 'D', 'B'}
0109         %% OK
0110     otherwise
0111         error('total_load: OPT.type should be ''FIXED'', ''DISPATCHABLE'' or ''BOTH''');
0112 end
0113 want_Q      = (nargout > 1);
0114 want_fixed  = (opt.type(1) == 'B' || opt.type(1) == 'F');
0115 want_disp   = (opt.type(1) == 'B' || opt.type(1) == 'D');
0116 
0117 %% initialize load_zone
0118 if ischar(load_zone) && strcmp(load_zone, 'all')
0119     load_zone = ones(nb, 1);        %% make a single zone of all buses
0120 elseif isempty(load_zone)
0121     load_zone = bus(:, BUS_AREA);   %% use areas defined in bus data as zones
0122 end
0123 nz = max(load_zone);    %% number of load zones
0124 
0125 %% fixed load at each bus, & initialize dispatchable
0126 if want_fixed
0127     Pdf = bus(:, PD);       %% real power
0128     if want_Q
0129         Qdf = bus(:, QD);   %% reactive power
0130     end
0131 else
0132     Pdf = zeros(nb, 1);     %% real power
0133     if want_Q
0134         Qdf = zeros(nb, 1); %% reactive power
0135     end
0136 end
0137 
0138 %% dispatchable load at each bus
0139 if want_disp            %% need dispatchable
0140     ng = size(gen, 1);
0141     is_ld = isload(gen) & gen(:, GEN_STATUS) > 0;
0142     ld = find(is_ld);
0143 
0144     %% create map of external bus numbers to bus indices
0145     i2e = bus(:, BUS_I);
0146     e2i = sparse(max(i2e), 1);
0147     e2i(i2e) = (1:nb)';
0148 
0149     Cld = sparse(e2i(gen(:, GEN_BUS)), (1:ng)', is_ld, nb, ng);
0150     if opt.nominal      %% use nominal power
0151         Pdd = -Cld * gen(:, PMIN);      %% real power
0152         if want_Q
0153             Q = zeros(ng, 1);
0154             Q(ld) = (gen(ld, QMIN) == 0) .* gen(ld, QMAX) + ...
0155                     (gen(ld, QMAX) == 0) .* gen(ld, QMIN);
0156             Qdd = -Cld * Q;             %% reactive power
0157         end
0158     else                %% use realized actual power dispatch
0159         Pdd = -Cld * gen(:, PG);        %% real power
0160         if want_Q
0161             Qdd = -Cld * gen(:, QG);    %% reactive power
0162         end
0163     end
0164 else
0165     Pdd = zeros(nb, 1);
0166     if want_Q
0167         Qdd = zeros(nb, 1);
0168     end
0169 end
0170 
0171 %% compute load sums
0172 Pd = zeros(nz, 1);
0173 if want_Q
0174     Qd = zeros(nz, 1);
0175 end
0176 for k = 1:nz
0177     idx = find( load_zone == k & bus(:, BUS_TYPE) ~= NONE);
0178     Pd(k) = sum(Pdf(idx)) + sum(Pdd(idx));
0179     if want_Q
0180         Qd(k) = sum(Qdf(idx)) + sum(Qdd(idx));
0181     end
0182 end

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