Home > matpower4.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, which_type)

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, WHICH_TYPE)
   [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.

   WHICH_TYPE - (optional) (default is 'BOTH' if GEN is provided, else 'FIXED')
       'FIXED'        : sum only fixed loads
       'DISPATCHABLE' : sum only dispatchable loads
       'BOTH'         : sum both fixed and dispatchable 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 dispatchable loads at buses 10-20.

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

   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, which_type)
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, WHICH_TYPE)
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 %   WHICH_TYPE - (optional) (default is 'BOTH' if GEN is provided, else 'FIXED')
0027 %       'FIXED'        : sum only fixed loads
0028 %       'DISPATCHABLE' : sum only dispatchable loads
0029 %       'BOTH'         : sum both fixed and dispatchable loads
0030 %
0031 %   Examples:
0032 %       Return the total active load for each area as defined in BUS_AREA.
0033 %
0034 %       Pd = total_load(bus);
0035 %
0036 %       Return total active and reactive load, fixed and dispatchable, for
0037 %       entire system.
0038 %
0039 %       [Pd, Qd] = total_load(bus, gen, 'all');
0040 %
0041 %       Return the total of the dispatchable loads at buses 10-20.
0042 %
0043 %       load_zone = zeros(nb, 1);
0044 %       load_zone(10:20) = 1;
0045 %       Pd = total_load(bus, gen, load_zone, 'DISPATCHABLE')
0046 %
0047 %   See also SCALE_LOAD.
0048 
0049 %   MATPOWER
0050 %   $Id: total_load.m,v 1.8 2010/04/26 19:45:25 ray Exp $
0051 %   by Ray Zimmerman, PSERC Cornell
0052 %   Copyright (c) 2004-2010 by Power System Engineering Research Center (PSERC)
0053 %
0054 %   This file is part of MATPOWER.
0055 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0056 %
0057 %   MATPOWER is free software: you can redistribute it and/or modify
0058 %   it under the terms of the GNU General Public License as published
0059 %   by the Free Software Foundation, either version 3 of the License,
0060 %   or (at your option) any later version.
0061 %
0062 %   MATPOWER is distributed in the hope that it will be useful,
0063 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0064 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0065 %   GNU General Public License for more details.
0066 %
0067 %   You should have received a copy of the GNU General Public License
0068 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0069 %
0070 %   Additional permission under GNU GPL version 3 section 7
0071 %
0072 %   If you modify MATPOWER, or any covered work, to interface with
0073 %   other modules (such as MATLAB code and MEX-files) available in a
0074 %   MATLAB(R) or comparable environment containing parts covered
0075 %   under other licensing terms, the licensors of MATPOWER grant
0076 %   you additional permission to convey the resulting work.
0077 
0078 %% define constants
0079 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0080     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0081 %% purposely being backward compatible with older MATPOWER
0082 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, ...
0083     PMAX, PMIN, MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN] = idx_gen;
0084 
0085 nb = size(bus, 1);          %% number of buses
0086 
0087 %%-----  process inputs  -----
0088 if nargin < 4
0089     which_type = [];
0090     if nargin < 3
0091         load_zone = [];
0092         if nargin < 2
0093             gen = [];
0094         end
0095     end
0096 end
0097 
0098 %% fill out and check which_type
0099 if isempty(gen)
0100     which_type = 'FIXED';
0101 end
0102 if isempty(which_type) && ~isempty(gen)
0103     which_type = 'BOTH';     %% 'FIXED', 'DISPATCHABLE' or 'BOTH'
0104 end
0105 if which_type(1) ~= 'F' && which_type(1) ~= 'D' && which_type(1) ~= 'B'
0106     error('total_load: which_type should be ''FIXED'', ''DISPATCHABLE'' or ''BOTH''');
0107 end
0108 want_Q      = (nargout > 1);
0109 want_fixed  = (which_type(1) == 'B' || which_type(1) == 'F');
0110 want_disp   = (which_type(1) == 'B' || which_type(1) == 'D');
0111 
0112 %% initialize load_zone
0113 if ischar(load_zone) && strcmp(load_zone, 'all')
0114     load_zone = ones(nb, 1);        %% make a single zone of all buses
0115 elseif isempty(load_zone)
0116     load_zone = bus(:, BUS_AREA);   %% use areas defined in bus data as zones
0117 end
0118 nz = max(load_zone);    %% number of load zones
0119 
0120 %% fixed load at each bus, & initialize dispatchable
0121 if want_fixed
0122     Pdf = bus(:, PD);       %% real power
0123     if want_Q
0124         Qdf = bus(:, QD);   %% reactive power
0125     end
0126 else
0127     Pdf = zeros(nb, 1);     %% real power
0128     if want_Q
0129         Qdf = zeros(nb, 1); %% reactive power
0130     end
0131 end
0132 
0133 %% dispatchable load at each bus
0134 if want_disp            %% need dispatchable
0135     ng = size(gen, 1);
0136     is_ld = isload(gen) & gen(:, GEN_STATUS) > 0;
0137     ld = find(is_ld);
0138 
0139     %% create map of external bus numbers to bus indices
0140     i2e = bus(:, BUS_I);
0141     e2i = sparse(max(i2e), 1);
0142     e2i(i2e) = (1:nb)';
0143 
0144     Cld = sparse(e2i(gen(:, GEN_BUS)), (1:ng)', is_ld, nb, ng);
0145     Pdd = -Cld * gen(:, PMIN);      %% real power
0146     if want_Q
0147         Q = zeros(ng, 1);
0148         Q(ld) = (gen(ld, QMIN) == 0) .* gen(ld, QMAX) + ...
0149                 (gen(ld, QMAX) == 0) .* gen(ld, QMIN);
0150         Qdd = -Cld * Q;             %% reactive power
0151     end
0152 else
0153     Pdd = zeros(nb, 1);
0154     if want_Q
0155         Qdd = zeros(nb, 1);
0156     end
0157 end
0158 
0159 %% compute load sums
0160 Pd = zeros(nz, 1);
0161 if want_Q
0162     Qd = zeros(nz, 1);
0163 end
0164 for k = 1:nz
0165     idx = find( load_zone == k );
0166     Pd(k) = sum(Pdf(idx)) + sum(Pdd(idx));
0167     if want_Q
0168         Qd(k) = sum(Qdf(idx)) + sum(Qdd(idx));
0169     end
0170 end

Generated on Mon 26-Jan-2015 14:56:45 by m2html © 2005