Home > matpower5.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)

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 %   $Id: total_load.m 2417 2014-11-12 15:57:35Z ray $
0064 %   by Ray Zimmerman, PSERC Cornell
0065 %   Copyright (c) 2004-2014 by Power System Engineering Research Center (PSERC)
0066 %
0067 %   This file is part of MATPOWER.
0068 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0069 %
0070 %   MATPOWER is free software: you can redistribute it and/or modify
0071 %   it under the terms of the GNU General Public License as published
0072 %   by the Free Software Foundation, either version 3 of the License,
0073 %   or (at your option) any later version.
0074 %
0075 %   MATPOWER is distributed in the hope that it will be useful,
0076 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0077 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0078 %   GNU General Public License for more details.
0079 %
0080 %   You should have received a copy of the GNU General Public License
0081 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0082 %
0083 %   Additional permission under GNU GPL version 3 section 7
0084 %
0085 %   If you modify MATPOWER, or any covered work, to interface with
0086 %   other modules (such as MATLAB code and MEX-files) available in a
0087 %   MATLAB(R) or comparable environment containing parts covered
0088 %   under other licensing terms, the licensors of MATPOWER grant
0089 %   you additional permission to convey the resulting work.
0090 
0091 %% define constants
0092 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0093     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0094 %% purposely being backward compatible with older MATPOWER
0095 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, ...
0096     PMAX, PMIN, MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN] = idx_gen;
0097 
0098 nb = size(bus, 1);          %% number of buses
0099 
0100 %%-----  process inputs  -----
0101 if nargin < 4
0102     opt = [];
0103     if nargin < 3
0104         load_zone = [];
0105         if nargin < 2
0106             gen = [];
0107         end
0108     end
0109 end
0110 
0111 %% default options
0112 if ischar(opt)      %% convert old WHICH_TYPE string option to struct
0113     opt = struct('type', opt, 'nominal', 1);
0114 else
0115     if ~isfield(opt, 'type')
0116         if isempty(gen)
0117             opt.type = 'FIXED';
0118         else
0119             opt.type = 'BOTH';
0120         end
0121     end
0122     if ~isfield(opt, 'nominal')
0123         opt.nominal = 0;
0124     end
0125 end
0126 switch upper(opt.type(1))
0127     case {'F', 'D', 'B'}
0128         %% OK
0129     otherwise
0130         error('total_load: OPT.type should be ''FIXED'', ''DISPATCHABLE'' or ''BOTH''');
0131 end
0132 want_Q      = (nargout > 1);
0133 want_fixed  = (opt.type(1) == 'B' || opt.type(1) == 'F');
0134 want_disp   = (opt.type(1) == 'B' || opt.type(1) == 'D');
0135 
0136 %% initialize load_zone
0137 if ischar(load_zone) && strcmp(load_zone, 'all')
0138     load_zone = ones(nb, 1);        %% make a single zone of all buses
0139 elseif isempty(load_zone)
0140     load_zone = bus(:, BUS_AREA);   %% use areas defined in bus data as zones
0141 end
0142 nz = max(load_zone);    %% number of load zones
0143 
0144 %% fixed load at each bus, & initialize dispatchable
0145 if want_fixed
0146     Pdf = bus(:, PD);       %% real power
0147     if want_Q
0148         Qdf = bus(:, QD);   %% reactive power
0149     end
0150 else
0151     Pdf = zeros(nb, 1);     %% real power
0152     if want_Q
0153         Qdf = zeros(nb, 1); %% reactive power
0154     end
0155 end
0156 
0157 %% dispatchable load at each bus
0158 if want_disp            %% need dispatchable
0159     ng = size(gen, 1);
0160     is_ld = isload(gen) & gen(:, GEN_STATUS) > 0;
0161     ld = find(is_ld);
0162 
0163     %% create map of external bus numbers to bus indices
0164     i2e = bus(:, BUS_I);
0165     e2i = sparse(max(i2e), 1);
0166     e2i(i2e) = (1:nb)';
0167 
0168     Cld = sparse(e2i(gen(:, GEN_BUS)), (1:ng)', is_ld, nb, ng);
0169     if opt.nominal      %% use nominal power
0170         Pdd = -Cld * gen(:, PMIN);      %% real power
0171         if want_Q
0172             Q = zeros(ng, 1);
0173             Q(ld) = (gen(ld, QMIN) == 0) .* gen(ld, QMAX) + ...
0174                     (gen(ld, QMAX) == 0) .* gen(ld, QMIN);
0175             Qdd = -Cld * Q;             %% reactive power
0176         end
0177     else                %% use realized actual power dispatch
0178         Pdd = -Cld * gen(:, PG);        %% real power
0179         if want_Q
0180             Qdd = -Cld * gen(:, QG);    %% reactive power
0181         end
0182     end
0183 else
0184     Pdd = zeros(nb, 1);
0185     if want_Q
0186         Qdd = zeros(nb, 1);
0187     end
0188 end
0189 
0190 %% compute load sums
0191 Pd = zeros(nz, 1);
0192 if want_Q
0193     Qd = zeros(nz, 1);
0194 end
0195 for k = 1:nz
0196     idx = find( load_zone == k & bus(:, BUS_TYPE) ~= NONE);
0197     Pd(k) = sum(Pdf(idx)) + sum(Pdd(idx));
0198     if want_Q
0199         Qd(k) = sum(Qdf(idx)) + sum(Qdd(idx));
0200     end
0201 end

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