Home > matpower6.0 > 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, mpopt)

DESCRIPTION ^

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

   MPC - standard MATPOWER case struct

   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)). LOAD_ZONE
       can also take the following string values:
           'all'  - use a single zone for the entire system (return scalar)
           'area' - use LOAD_ZONE = BUS(:, BUS_AREA), same as default
           'bus'  - use a different zone for each bus (i.e. to compute
               final values of bus-wise loads, including voltage dependent
               fixed loads and or dispatchable loads)

   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.

   MPOPT - (optional) MATPOWER options struct, which may specify
       a voltage dependent (ZIP) load model for fixed loads

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

Generated on Fri 16-Dec-2016 12:45:37 by m2html © 2005