Home > matpower4.1 > t > t_total_load.m

t_total_load

PURPOSE ^

T_TOTAL_LOAD Tests for code in TOTAL_LOAD.

SYNOPSIS ^

function t_total_load(quiet)

DESCRIPTION ^

T_TOTAL_LOAD  Tests for code in TOTAL_LOAD.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function t_total_load(quiet)
0002 %T_TOTAL_LOAD  Tests for code in TOTAL_LOAD.
0003 
0004 %   MATPOWER
0005 %   $Id: t_total_load.m,v 1.5 2010/04/26 19:45:26 ray Exp $
0006 %   by Ray Zimmerman, PSERC Cornell
0007 %   Copyright (c) 2008-2010 by Power System Engineering Research Center (PSERC)
0008 %
0009 %   This file is part of MATPOWER.
0010 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0011 %
0012 %   MATPOWER is free software: you can redistribute it and/or modify
0013 %   it under the terms of the GNU General Public License as published
0014 %   by the Free Software Foundation, either version 3 of the License,
0015 %   or (at your option) any later version.
0016 %
0017 %   MATPOWER is distributed in the hope that it will be useful,
0018 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0019 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0020 %   GNU General Public License for more details.
0021 %
0022 %   You should have received a copy of the GNU General Public License
0023 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0024 %
0025 %   Additional permission under GNU GPL version 3 section 7
0026 %
0027 %   If you modify MATPOWER, or any covered work, to interface with
0028 %   other modules (such as MATLAB code and MEX-files) available in a
0029 %   MATLAB(R) or comparable environment containing parts covered
0030 %   under other licensing terms, the licensors of MATPOWER grant
0031 %   you additional permission to convey the resulting work.
0032 
0033 if nargin < 1
0034     quiet = 0;
0035 end
0036 
0037 n_tests = 48;
0038 
0039 t_begin(n_tests, quiet);
0040 
0041 %% define named indices into data matrices
0042 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0043     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0044 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0045     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0046     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0047 
0048 mpc = loadcase('t_auction_case');
0049 mpc.gen(8, GEN_BUS) = 2;    %% multiple d. loads per area, same bus as gen
0050 mpc.gen(8, [QG QMIN QMAX]) = [ 3 0 3 ];
0051 %% put it load before gen in matrix
0052 mpc.gen = [mpc.gen(8, :); mpc.gen(1:7, :); mpc.gen(9, :)];
0053 ld = find(isload(mpc.gen));
0054 for k = 1:3
0055     a{k} = find(mpc.bus(:, BUS_AREA) == k); %% buses in area k
0056     [junk, tmp, junk2] = intersect(mpc.gen(ld, GEN_BUS), a{k});
0057     lda{k} = ld(tmp);                       %% disp loads in area k
0058 end
0059 for k = 1:3
0060     area(k).fixed.p = sum(mpc.bus(a{k}, PD));
0061     area(k).fixed.q = sum(mpc.bus(a{k}, QD));
0062     area(k).disp.p = -sum(mpc.gen(lda{k}, PMIN));
0063     area(k).disp.qmin = -sum(mpc.gen(lda{k}, QMIN));
0064     area(k).disp.qmax = -sum(mpc.gen(lda{k}, QMAX));
0065     area(k).disp.q = area(k).disp.qmin + area(k).disp.qmax;
0066     area(k).both.p = area(k).fixed.p + area(k).disp.p;
0067     area(k).both.q = area(k).fixed.q + area(k).disp.q;
0068 end
0069 total.fixed.p = sum(mpc.bus(:, PD));
0070 total.fixed.q = sum(mpc.bus(:, QD));
0071 total.disp.p = -sum(mpc.gen(ld, PMIN));
0072 total.disp.qmin = -sum(mpc.gen(ld, QMIN));
0073 total.disp.qmax = -sum(mpc.gen(ld, QMAX));
0074 total.disp.q = total.disp.qmin + total.disp.qmax;
0075 total.both.p = total.fixed.p + total.disp.p;
0076 total.both.q = total.fixed.q + total.disp.q;
0077 
0078 %%-----  all load  -----
0079 t = '      Pd = total_load(bus) : ';
0080 Pd = total_load(mpc.bus);
0081 t_is(Pd, [area(1).fixed.p; area(2).fixed.p; area(3).fixed.p], 12, [t 'Pd']);
0082 
0083 t = '[Pd, Qd] = total_load(bus) : ';
0084 [Pd, Qd] = total_load(mpc.bus);
0085 t_is(Pd, [area(1).fixed.p; area(2).fixed.p; area(3).fixed.p], 12, [t 'Pd']);
0086 t_is(Qd, [area(1).fixed.q; area(2).fixed.q; area(3).fixed.q], 12, [t 'Qd']);
0087 
0088 t = '      Pd = total_load(bus, gen) : ';
0089 Pd = total_load(mpc.bus, mpc.gen);
0090 t_is(Pd, [area(1).both.p; area(2).both.p; area(3).both.p], 12, [t 'Pd']);
0091 
0092 t = '[Pd, Qd] = total_load(bus, gen) : ';
0093 [Pd, Qd] = total_load(mpc.bus, mpc.gen);
0094 t_is(Pd, [area(1).both.p; area(2).both.p; area(3).both.p], 12, [t 'Pd']);
0095 t_is(Qd, [area(1).both.q; area(2).both.q; area(3).both.q], 12, [t 'Qd']);
0096 
0097 t = '      Pd = total_load(bus, [], ''all'') : ';
0098 Pd = total_load(mpc.bus, [], 'all');
0099 t_is(Pd, total.fixed.p, 12, [t 'Pd']);
0100 
0101 t = '[Pd, Qd] = total_load(bus, [], ''all'') : ';
0102 [Pd, Qd] = total_load(mpc.bus, [], 'all');
0103 t_is(Pd, total.fixed.p, 12, [t 'Pd']);
0104 t_is(Qd, total.fixed.q, 12, [t 'Qd']);
0105 
0106 t = '      Pd = total_load(bus, gen, ''all'') : ';
0107 Pd = total_load(mpc.bus, mpc.gen, 'all');
0108 t_is(Pd, total.both.p, 12, [t 'Pd']);
0109 
0110 t = '[Pd, Qd] = total_load(bus, gen, ''all'') : ';
0111 [Pd, Qd] = total_load(mpc.bus, mpc.gen, 'all');
0112 t_is(Pd, total.both.p, 12, [t 'Pd']);
0113 t_is(Qd, total.both.q, 12, [t 'Qd']);
0114 
0115 t = '      Pd = total_load(bus, gen, ''all'', ''BOTH'') : ';
0116 Pd = total_load(mpc.bus, mpc.gen, 'all', 'BOTH');
0117 t_is(Pd, total.both.p, 12, [t 'Pd']);
0118 
0119 t = '[Pd, Qd] = total_load(bus, gen, ''all'', ''BOTH'') : ';
0120 [Pd, Qd] = total_load(mpc.bus, mpc.gen, 'all', 'BOTH');
0121 t_is(Pd, total.both.p, 12, [t 'Pd']);
0122 t_is(Qd, total.both.q, 12, [t 'Qd']);
0123 
0124 t = '      Pd = total_load(bus, gen, ''all'', ''FIXED'') : ';
0125 Pd = total_load(mpc.bus, mpc.gen, 'all', 'FIXED');
0126 t_is(Pd, total.fixed.p, 12, [t 'Pd']);
0127 
0128 t = '[Pd, Qd] = total_load(bus, gen, ''all'', ''FIXED'') : ';
0129 [Pd, Qd] = total_load(mpc.bus, mpc.gen, 'all', 'FIXED');
0130 t_is(Pd, total.fixed.p, 12, [t 'Pd']);
0131 t_is(Qd, total.fixed.q, 12, [t 'Qd']);
0132 
0133 t = '      Pd = total_load(bus, gen, ''all'', ''DISPATCHABLE'') : ';
0134 Pd = total_load(mpc.bus, mpc.gen, 'all', 'DISPATCHABLE');
0135 t_is(Pd, total.disp.p, 12, [t 'Pd']);
0136 
0137 t = '[Pd, Qd] = total_load(bus, gen, ''all'', ''DISPATCHABLE'') : ';
0138 [Pd, Qd] = total_load(mpc.bus, mpc.gen, 'all', 'DISPATCHABLE');
0139 t_is(Pd, total.disp.p, 12, [t 'Pd']);
0140 t_is(Qd, total.disp.q, 12, [t 'Qd']);
0141 
0142 t = '      Pd = total_load(bus, gen, [], ''BOTH'') : ';
0143 Pd = total_load(mpc.bus, mpc.gen, [], 'BOTH');
0144 t_is(Pd, [area(1).both.p; area(2).both.p; area(3).both.p], 12, [t 'Pd']);
0145 
0146 t = '[Pd, Qd] = total_load(bus, gen, [], ''BOTH'') : ';
0147 [Pd, Qd] = total_load(mpc.bus, mpc.gen, [], 'BOTH');
0148 t_is(Pd, [area(1).both.p; area(2).both.p; area(3).both.p], 12, [t 'Pd']);
0149 t_is(Qd, [area(1).both.q; area(2).both.q; area(3).both.q], 12, [t 'Qd']);
0150 
0151 t = '      Pd = total_load(bus, gen, [], ''FIXED'') : ';
0152 Pd = total_load(mpc.bus, mpc.gen, [], 'FIXED');
0153 t_is(Pd, [area(1).fixed.p; area(2).fixed.p; area(3).fixed.p], 12, [t 'Pd']);
0154 
0155 t = '[Pd, Qd] = total_load(bus, gen, [], ''FIXED'') : ';
0156 [Pd, Qd] = total_load(mpc.bus, mpc.gen, [], 'FIXED');
0157 t_is(Pd, [area(1).fixed.p; area(2).fixed.p; area(3).fixed.p], 12, [t 'Pd']);
0158 t_is(Qd, [area(1).fixed.q; area(2).fixed.q; area(3).fixed.q], 12, [t 'Qd']);
0159 
0160 t = '      Pd = total_load(bus, gen, [], ''DISPATCHABLE'') : ';
0161 Pd = total_load(mpc.bus, mpc.gen, [], 'DISPATCHABLE');
0162 t_is(Pd, [area(1).disp.p; area(2).disp.p; area(3).disp.p], 12, [t 'Pd']);
0163 
0164 t = '[Pd, Qd] = total_load(bus, gen, [], ''DISPATCHABLE'') : ';
0165 [Pd, Qd] = total_load(mpc.bus, mpc.gen, [], 'DISPATCHABLE');
0166 t_is(Pd, [area(1).disp.p; area(2).disp.p; area(3).disp.p], 12, [t 'Pd']);
0167 t_is(Qd, [area(1).disp.q; area(2).disp.q; area(3).disp.q], 12, [t 'Qd']);
0168 
0169 %%-----  explicit single load zone  -----
0170 nb = size(mpc.bus, 1);
0171 load_zone = zeros(nb, 1);
0172 k = find(mpc.bus(:, BUS_AREA) == 2);    %% area 2
0173 load_zone(k) = 1;
0174 t = '      Pd = total_load(bus, gen, load_zone1, ''BOTH'') : ';
0175 Pd = total_load(mpc.bus, mpc.gen, load_zone, 'BOTH');
0176 t_is(Pd, area(2).both.p, 12, [t 'Pd']);
0177 
0178 t = '[Pd, Qd] = total_load(bus, gen, load_zone1, ''BOTH'') : ';
0179 [Pd, Qd] = total_load(mpc.bus, mpc.gen, load_zone, 'BOTH');
0180 t_is(Pd, area(2).both.p, 12, [t 'Pd']);
0181 t_is(Qd, area(2).both.q, 12, [t 'Qd']);
0182 
0183 t = '      Pd = total_load(bus, gen, load_zone1, ''FIXED'') : ';
0184 Pd = total_load(mpc.bus, mpc.gen, load_zone, 'FIXED');
0185 t_is(Pd, area(2).fixed.p, 12, [t 'Pd']);
0186 
0187 t = '[Pd, Qd] = total_load(bus, gen, load_zone1, ''FIXED'') : ';
0188 [Pd, Qd] = total_load(mpc.bus, mpc.gen, load_zone, 'FIXED');
0189 t_is(Pd, area(2).fixed.p, 12, [t 'Pd']);
0190 t_is(Qd, area(2).fixed.q, 12, [t 'Qd']);
0191 
0192 t = '      Pd = total_load(bus, gen, load_zone1, ''DISPATCHABLE'') : ';
0193 Pd = total_load(mpc.bus, mpc.gen, load_zone, 'DISPATCHABLE');
0194 t_is(Pd, area(2).disp.p, 12, [t 'Pd']);
0195 
0196 t = '[Pd, Qd] = total_load(bus, gen, load_zone1, ''DISPATCHABLE'') : ';
0197 [Pd, Qd] = total_load(mpc.bus, mpc.gen, load_zone, 'DISPATCHABLE');
0198 t_is(Pd, area(2).disp.p, 12, [t 'Pd']);
0199 t_is(Qd, area(2).disp.q, 12, [t 'Qd']);
0200 
0201 %%-----  explicit multiple load zone  -----
0202 load_zone = zeros(nb, 1);
0203 k = find(mpc.bus(:, BUS_AREA) == 3);    %% area 3
0204 load_zone(k) = 1;
0205 k = find(mpc.bus(:, BUS_AREA) == 1);    %% area 1
0206 load_zone(k) = 2;
0207 t = '      Pd = total_load(bus, gen, load_zone2, ''BOTH'') : ';
0208 Pd = total_load(mpc.bus, mpc.gen, load_zone, 'BOTH');
0209 t_is(Pd, [area(3).both.p; area(1).both.p], 12, [t 'Pd']);
0210 
0211 t = '[Pd, Qd] = total_load(bus, gen, load_zone2, ''BOTH'') : ';
0212 [Pd, Qd] = total_load(mpc.bus, mpc.gen, load_zone, 'BOTH');
0213 t_is(Pd, [area(3).both.p; area(1).both.p], 12, [t 'Pd']);
0214 t_is(Qd, [area(3).both.q; area(1).both.q], 12, [t 'Qd']);
0215 
0216 t = '      Pd = total_load(bus, gen, load_zone2, ''FIXED'') : ';
0217 Pd = total_load(mpc.bus, mpc.gen, load_zone, 'FIXED');
0218 t_is(Pd, [area(3).fixed.p; area(1).fixed.p], 12, [t 'Pd']);
0219 
0220 t = '[Pd, Qd] = total_load(bus, gen, load_zone2, ''FIXED'') : ';
0221 [Pd, Qd] = total_load(mpc.bus, mpc.gen, load_zone, 'FIXED');
0222 t_is(Pd, [area(3).fixed.p; area(1).fixed.p], 12, [t 'Pd']);
0223 t_is(Qd, [area(3).fixed.q; area(1).fixed.q], 12, [t 'Qd']);
0224 
0225 t = '      Pd = total_load(bus, gen, load_zone2, ''DISPATCHABLE'') : ';
0226 Pd = total_load(mpc.bus, mpc.gen, load_zone, 'DISPATCHABLE');
0227 t_is(Pd, [area(3).disp.p; area(1).disp.p], 12, [t 'Pd']);
0228 
0229 t = '[Pd, Qd] = total_load(bus, gen, load_zone2, ''DISPATCHABLE'') : ';
0230 [Pd, Qd] = total_load(mpc.bus, mpc.gen, load_zone, 'DISPATCHABLE');
0231 t_is(Pd, [area(3).disp.p; area(1).disp.p], 12, [t 'Pd']);
0232 t_is(Qd, [area(3).disp.q; area(1).disp.q], 12, [t 'Qd']);
0233 
0234 t_end;

Generated on Mon 26-Jan-2015 15:00:13 by m2html © 2005