Home > matpower7.0 > lib > 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 %   Copyright (c) 2008-2016, Power Systems Engineering Research Center (PSERC)
0006 %   by Ray Zimmerman, PSERC Cornell
0007 %
0008 %   This file is part of MATPOWER.
0009 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0010 %   See https://matpower.org for more info.
0011 
0012 if nargin < 1
0013     quiet = 0;
0014 end
0015 
0016 n_tests = 250;
0017 
0018 t_begin(n_tests, quiet);
0019 
0020 %% define named indices into data matrices
0021 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0022     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0023 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0024     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0025     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0026 
0027 mpc = loadcase('t_auction_case');
0028 mpc.gen(8, GEN_BUS) = 2;    %% multiple d. loads per area, same bus as gen
0029 mpc.gen(8, [PG QG QMIN QMAX]) = [-20 2 0 3 ];
0030 %% put load before gen in matrix
0031 mpc.gen = [mpc.gen(8, :); mpc.gen(1:7, :); mpc.gen(9, :)];
0032 %% add an isolated bus (with both kinds of load)
0033 k = 12;
0034 mpc.bus = [mpc.bus(1:k, :); mpc.bus(k, :); mpc.bus(k+1:end, :)];
0035 mpc.bus(k, BUS_I) = mpc.bus(k, BUS_I)*10;
0036 mpc.bus(k, BUS_TYPE) = NONE;
0037 mpc.gen = [mpc.gen; mpc.gen(end, :)];
0038 mpc.gen(end, GEN_BUS) = mpc.bus(k, BUS_I);
0039 
0040 ld = find(isload(mpc.gen(1:end-1, :)));
0041 for k = 1:3
0042     a{k} = find(mpc.bus(:, BUS_AREA) == k & mpc.bus(:, BUS_TYPE) ~= NONE); %% buses in area k
0043     [junk, tmp, junk2] = intersect(mpc.gen(ld, GEN_BUS), a{k});
0044     lda{k} = ld(tmp);                       %% disp loads in area k
0045 end
0046 for k = 1:3
0047     area(k).fixed.p = sum(mpc.bus(a{k}, PD));
0048     area(k).fixed.q = sum(mpc.bus(a{k}, QD));
0049     area(k).disp.pnom = -sum(mpc.gen(lda{k}, PMIN));
0050     area(k).disp.p = -sum(mpc.gen(lda{k}, PG));
0051     area(k).disp.qmin = -sum(mpc.gen(lda{k}, QMIN));
0052     area(k).disp.qmax = -sum(mpc.gen(lda{k}, QMAX));
0053     area(k).disp.qnom = area(k).disp.qmin + area(k).disp.qmax;
0054     area(k).disp.q = -sum(mpc.gen(lda{k}, QG));
0055     area(k).both.pnom = area(k).fixed.p + area(k).disp.pnom;
0056     area(k).both.qnom = area(k).fixed.q + area(k).disp.qnom;
0057     area(k).both.p = area(k).fixed.p + area(k).disp.p;
0058     area(k).both.q = area(k).fixed.q + area(k).disp.q;
0059 end
0060 k = find(mpc.bus(:, BUS_TYPE) ~= NONE);
0061 total.fixed.p = sum(mpc.bus(k, PD));
0062 total.fixed.q = sum(mpc.bus(k, QD));
0063 total.disp.p = -sum(mpc.gen(ld, PG));
0064 total.disp.pnom = -sum(mpc.gen(ld, PMIN));
0065 total.disp.qmin = -sum(mpc.gen(ld, QMIN));
0066 total.disp.qmax = -sum(mpc.gen(ld, QMAX));
0067 total.disp.q = -sum(mpc.gen(ld, QG));
0068 total.disp.qnom = total.disp.qmin + total.disp.qmax;
0069 total.both.pnom = total.fixed.p + total.disp.pnom;
0070 total.both.qnom = total.fixed.q + total.disp.qnom;
0071 total.both.p = total.fixed.p + total.disp.p;
0072 total.both.q = total.fixed.q + total.disp.q;
0073 
0074 %%-----  all load  -----
0075 t = '      Pd = total_load(bus) : ';
0076 Pd = total_load(mpc.bus);
0077 t_is(Pd, [area(1).fixed.p; area(2).fixed.p; area(3).fixed.p], 12, [t 'Pd']);
0078 
0079 t = '[Pd, Qd] = total_load(bus) : ';
0080 [Pd, Qd] = total_load(mpc.bus);
0081 t_is(Pd, [area(1).fixed.p; area(2).fixed.p; area(3).fixed.p], 12, [t 'Pd']);
0082 t_is(Qd, [area(1).fixed.q; area(2).fixed.q; area(3).fixed.q], 12, [t 'Qd']);
0083 
0084 t = '      Pd = total_load(bus, gen) : ';
0085 Pd = total_load(mpc.bus, mpc.gen);
0086 t_is(Pd, [area(1).both.p; area(2).both.p; area(3).both.p], 12, [t 'Pd']);
0087 
0088 t = '[Pd, Qd] = total_load(bus, gen) : ';
0089 [Pd, Qd] = 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 t_is(Qd, [area(1).both.q; area(2).both.q; area(3).both.q], 12, [t 'Qd']);
0092 
0093 t = '      Pd = total_load(bus, [], ''all'') : ';
0094 Pd = total_load(mpc.bus, [], 'all');
0095 t_is(Pd, total.fixed.p, 12, [t 'Pd']);
0096 
0097 t = '[Pd, Qd] = total_load(bus, [], ''all'') : ';
0098 [Pd, Qd] = total_load(mpc.bus, [], 'all');
0099 t_is(Pd, total.fixed.p, 12, [t 'Pd']);
0100 t_is(Qd, total.fixed.q, 12, [t 'Qd']);
0101 
0102 t = '      Pd = total_load(b, g, ''all'') : ';
0103 Pd = total_load(mpc.bus, mpc.gen, 'all');
0104 t_is(Pd, total.both.p, 12, [t 'Pd']);
0105 
0106 t = '[Pd, Qd] = total_load(b, g, ''all'') : ';
0107 [Pd, Qd] = total_load(mpc.bus, mpc.gen, 'all');
0108 t_is(Pd, total.both.p, 12, [t 'Pd']);
0109 t_is(Qd, total.both.q, 12, [t 'Qd']);
0110 
0111 t = '      Pd = total_load(b, g, ''all'', .type = ''BOTH'') : ';
0112 opt = struct('type', 'BOTH');
0113 Pd = total_load(mpc.bus, mpc.gen, 'all', opt);
0114 t_is(Pd, total.both.p, 12, [t 'Pd']);
0115 
0116 t = '      Pd = total_load(b, g, ''all'', .type = ''BOTH'' .nominal = 1) : ';
0117 opt = struct('type', 'BOTH', 'nominal', 1);
0118 Pd = total_load(mpc.bus, mpc.gen, 'all', opt);
0119 t_is(Pd, total.both.pnom, 12, [t 'Pd']);
0120 
0121 t = '      Pd = total_load(b, g, ''all'', .type = ''BOTH'' .nominal = 0) : ';
0122 opt = struct('type', 'BOTH', 'nominal', 0);
0123 Pd = total_load(mpc.bus, mpc.gen, 'all', opt);
0124 t_is(Pd, total.both.p, 12, [t 'Pd']);
0125 
0126 t = '[Pd, Qd] = total_load(b, g, ''all'', .type = ''BOTH'') : ';
0127 opt = struct('type', 'BOTH');
0128 [Pd, Qd] = total_load(mpc.bus, mpc.gen, 'all', opt);
0129 t_is(Pd, total.both.p, 12, [t 'Pd']);
0130 t_is(Qd, total.both.q, 12, [t 'Qd']);
0131 
0132 t = '      Pd = total_load(b, g, ''all'', .type = ''FIXED'') : ';
0133 opt = struct('type', 'FIXED');
0134 Pd = total_load(mpc.bus, mpc.gen, 'all', opt);
0135 t_is(Pd, total.fixed.p, 12, [t 'Pd']);
0136 
0137 t = '[Pd, Qd] = total_load(b, g, ''all'', .type = ''FIXED'') : ';
0138 opt = struct('type', 'FIXED');
0139 [Pd, Qd] = total_load(mpc.bus, mpc.gen, 'all', opt);
0140 t_is(Pd, total.fixed.p, 12, [t 'Pd']);
0141 t_is(Qd, total.fixed.q, 12, [t 'Qd']);
0142 
0143 t = '      Pd = total_load(b, g, ''all'', .type = ''DISPATCHABLE'') : ';
0144 opt = struct('type', 'DISPATCHABLE');
0145 Pd = total_load(mpc.bus, mpc.gen, 'all', opt);
0146 t_is(Pd, total.disp.p, 12, [t 'Pd']);
0147 
0148 t = '      Pd = total_load(b, g, ''all'', .type = ''DISP'' .nominal = 1) : ';
0149 opt = struct('type', 'DISP', 'nominal', 1);
0150 Pd = total_load(mpc.bus, mpc.gen, 'all', opt);
0151 t_is(Pd, total.disp.pnom, 12, [t 'Pd']);
0152 
0153 t = '      Pd = total_load(b, g, ''all'', .type = ''DISP'' .nominal = 0) : ';
0154 opt = struct('type', 'DISP', 'nominal', 0);
0155 Pd = total_load(mpc.bus, mpc.gen, 'all', opt);
0156 t_is(Pd, total.disp.p, 12, [t 'Pd']);
0157 
0158 t = '[Pd, Qd] = total_load(b, g, ''all'', .type = ''DISPATCHABLE'') : ';
0159 opt = struct('type', 'DISPATCHABLE');
0160 [Pd, Qd] = total_load(mpc.bus, mpc.gen, 'all', opt);
0161 t_is(Pd, total.disp.p, 12, [t 'Pd']);
0162 t_is(Qd, total.disp.q, 12, [t 'Qd']);
0163 
0164 t = '[Pd, Qd] = total_load(b, g, ''all'', .type = ''DISP'' .nominal = 1) : ';
0165 opt = struct('type', 'DISP', 'nominal', 1);
0166 [Pd, Qd] = total_load(mpc.bus, mpc.gen, 'all', opt);
0167 t_is(Pd, total.disp.pnom, 12, [t 'Pd']);
0168 t_is(Qd, total.disp.qnom, 12, [t 'Qd']);
0169 
0170 t = '[Pd, Qd] = total_load(b, g, ''all'', .type = ''DISP'' .nominal = 0) : ';
0171 opt = struct('type', 'DISP', 'nominal', 0);
0172 [Pd, Qd] = total_load(mpc.bus, mpc.gen, 'all', opt);
0173 t_is(Pd, total.disp.p, 12, [t 'Pd']);
0174 t_is(Qd, total.disp.q, 12, [t 'Qd']);
0175 
0176 t = '      Pd = total_load(b, g, [], .type = ''BOTH'') : ';
0177 opt = struct('type', 'BOTH');
0178 Pd = total_load(mpc.bus, mpc.gen, [], opt);
0179 t_is(Pd, [area(1).both.p; area(2).both.p; area(3).both.p], 12, [t 'Pd']);
0180 
0181 t = '      Pd = total_load(b, g, [], .type = ''BOTH'' .nominal = 1) : ';
0182 opt = struct('type', 'BOTH', 'nominal', 1);
0183 Pd = total_load(mpc.bus, mpc.gen, [], opt);
0184 t_is(Pd, [area(1).both.pnom; area(2).both.pnom; area(3).both.pnom], 12, [t 'Pd']);
0185 
0186 t = '      Pd = total_load(b, g, [], .type = ''BOTH'' .nominal = 0) : ';
0187 opt = struct('type', 'BOTH', 'nominal', 0);
0188 Pd = total_load(mpc.bus, mpc.gen, [], opt);
0189 t_is(Pd, [area(1).both.p; area(2).both.p; area(3).both.p], 12, [t 'Pd']);
0190 
0191 t = '[Pd, Qd] = total_load(b, g, [], .type = ''BOTH'') : ';
0192 opt = struct('type', 'BOTH');
0193 [Pd, Qd] = total_load(mpc.bus, mpc.gen, [], opt);
0194 t_is(Pd, [area(1).both.p; area(2).both.p; area(3).both.p], 12, [t 'Pd']);
0195 t_is(Qd, [area(1).both.q; area(2).both.q; area(3).both.q], 12, [t 'Qd']);
0196 
0197 t = '[Pd, Qd] = total_load(b, g, [], .type = ''BOTH'' .nominal = 1) : ';
0198 opt = struct('type', 'BOTH', 'nominal', 1);
0199 [Pd, Qd] = total_load(mpc.bus, mpc.gen, [], opt);
0200 t_is(Pd, [area(1).both.pnom; area(2).both.pnom; area(3).both.pnom], 12, [t 'Pd']);
0201 t_is(Qd, [area(1).both.qnom; area(2).both.qnom; area(3).both.qnom], 12, [t 'Qd']);
0202 
0203 t = '[Pd, Qd] = total_load(b, g, [], .type = ''BOTH'' .nominal = 0) : ';
0204 opt = struct('type', 'BOTH', 'nominal', 0);
0205 [Pd, Qd] = total_load(mpc.bus, mpc.gen, [], opt);
0206 t_is(Pd, [area(1).both.p; area(2).both.p; area(3).both.p], 12, [t 'Pd']);
0207 t_is(Qd, [area(1).both.q; area(2).both.q; area(3).both.q], 12, [t 'Qd']);
0208 
0209 t = '      Pd = total_load(b, g, [], .type = ''FIXED'') : ';
0210 opt = struct('type', 'FIXED');
0211 Pd = total_load(mpc.bus, mpc.gen, [], opt);
0212 t_is(Pd, [area(1).fixed.p; area(2).fixed.p; area(3).fixed.p], 12, [t 'Pd']);
0213 
0214 t = '[Pd, Qd] = total_load(b, g, [], .type = ''FIXED'') : ';
0215 opt = struct('type', 'FIXED');
0216 [Pd, Qd] = total_load(mpc.bus, mpc.gen, [], opt);
0217 t_is(Pd, [area(1).fixed.p; area(2).fixed.p; area(3).fixed.p], 12, [t 'Pd']);
0218 t_is(Qd, [area(1).fixed.q; area(2).fixed.q; area(3).fixed.q], 12, [t 'Qd']);
0219 
0220 t = '      Pd = total_load(b, g, [], .type = ''DISPATCHABLE'') : ';
0221 opt = struct('type', 'DISPATCHABLE');
0222 Pd = total_load(mpc.bus, mpc.gen, [], opt);
0223 t_is(Pd, [area(1).disp.p; area(2).disp.p; area(3).disp.p], 12, [t 'Pd']);
0224 
0225 t = '      Pd = total_load(b, g, [], .type = ''DISP'' .nominal = 1) : ';
0226 opt = struct('type', 'DISP', 'nominal', 1);
0227 Pd = total_load(mpc.bus, mpc.gen, [], opt);
0228 t_is(Pd, [area(1).disp.pnom; area(2).disp.pnom; area(3).disp.pnom], 12, [t 'Pd']);
0229 
0230 t = '      Pd = total_load(b, g, [], .type = ''DISP'' .nominal = 0) : ';
0231 opt = struct('type', 'DISP', 'nominal', 0);
0232 Pd = total_load(mpc.bus, mpc.gen, [], opt);
0233 t_is(Pd, [area(1).disp.p; area(2).disp.p; area(3).disp.p], 12, [t 'Pd']);
0234 
0235 t = '[Pd, Qd] = total_load(b, g, [], .type = ''DISPATCHABLE'') : ';
0236 opt = struct('type', 'DISPATCHABLE');
0237 [Pd, Qd] = total_load(mpc.bus, mpc.gen, [], opt);
0238 t_is(Pd, [area(1).disp.p; area(2).disp.p; area(3).disp.p], 12, [t 'Pd']);
0239 t_is(Qd, [area(1).disp.q; area(2).disp.q; area(3).disp.q], 12, [t 'Qd']);
0240 
0241 t = '[Pd, Qd] = total_load(b, g, [], .type = ''DISP'' .nominal = 1) : ';
0242 opt = struct('type', 'DISP', 'nominal', 1);
0243 [Pd, Qd] = total_load(mpc.bus, mpc.gen, [], opt);
0244 t_is(Pd, [area(1).disp.pnom; area(2).disp.pnom; area(3).disp.pnom], 12, [t 'Pd']);
0245 t_is(Qd, [area(1).disp.qnom; area(2).disp.qnom; area(3).disp.qnom], 12, [t 'Qd']);
0246 
0247 t = '[Pd, Qd] = total_load(b, g, [], .type = ''DISP'' .nominal = 0) : ';
0248 opt = struct('type', 'DISP', 'nominal', 0);
0249 [Pd, Qd] = total_load(mpc.bus, mpc.gen, [], opt);
0250 t_is(Pd, [area(1).disp.p; area(2).disp.p; area(3).disp.p], 12, [t 'Pd']);
0251 t_is(Qd, [area(1).disp.q; area(2).disp.q; area(3).disp.q], 12, [t 'Qd']);
0252 
0253 %%-----  explicit single load zone  -----
0254 nb = size(mpc.bus, 1);
0255 load_zone = zeros(nb, 1);
0256 k = find(mpc.bus(:, BUS_AREA) == 1);    %% area 1
0257 load_zone(k) = 1;
0258 t = '      Pd = total_load(b, g, ld_zone1, .type = ''BOTH'') : ';
0259 opt = struct('type', 'BOTH');
0260 Pd = total_load(mpc.bus, mpc.gen, load_zone, opt);
0261 t_is(Pd, area(1).both.p, 12, [t 'Pd']);
0262 
0263 t = '      Pd = total_load(b, g, ld_zone1, .type = ''BOTH'' .nominal = 1) : ';
0264 opt = struct('type', 'BOTH', 'nominal', 1);
0265 Pd = total_load(mpc.bus, mpc.gen, load_zone, opt);
0266 t_is(Pd, area(1).both.pnom, 12, [t 'Pd']);
0267 
0268 t = '      Pd = total_load(b, g, ld_zone1, .type = ''BOTH'' .nominal = 0) : ';
0269 opt = struct('type', 'BOTH', 'nominal', 0);
0270 Pd = total_load(mpc.bus, mpc.gen, load_zone, opt);
0271 t_is(Pd, area(1).both.p, 12, [t 'Pd']);
0272 
0273 t = '[Pd, Qd] = total_load(b, g, ld_zone1, .type = ''BOTH'') : ';
0274 opt = struct('type', 'BOTH');
0275 [Pd, Qd] = total_load(mpc.bus, mpc.gen, load_zone, opt);
0276 t_is(Pd, area(1).both.p, 12, [t 'Pd']);
0277 t_is(Qd, area(1).both.q, 12, [t 'Qd']);
0278 
0279 t = '[Pd, Qd] = total_load(b, g, ld_zone1, .type = ''BOTH'' .nominal = 1) : ';
0280 opt = struct('type', 'BOTH', 'nominal', 1);
0281 [Pd, Qd] = total_load(mpc.bus, mpc.gen, load_zone, opt);
0282 t_is(Pd, area(1).both.pnom, 12, [t 'Pd']);
0283 t_is(Qd, area(1).both.qnom, 12, [t 'Qd']);
0284 
0285 t = '[Pd, Qd] = total_load(b, g, ld_zone1, .type = ''BOTH'' .nominal = 0) : ';
0286 opt = struct('type', 'BOTH', 'nominal', 0);
0287 [Pd, Qd] = total_load(mpc.bus, mpc.gen, load_zone, opt);
0288 t_is(Pd, area(1).both.p, 12, [t 'Pd']);
0289 t_is(Qd, area(1).both.q, 12, [t 'Qd']);
0290 
0291 t = '      Pd = total_load(b, g, ld_zone1, .type = ''FIXED'') : ';
0292 opt = struct('type', 'FIXED');
0293 Pd = total_load(mpc.bus, mpc.gen, load_zone, opt);
0294 t_is(Pd, area(1).fixed.p, 12, [t 'Pd']);
0295 
0296 t = '[Pd, Qd] = total_load(b, g, ld_zone1, .type = ''FIXED'') : ';
0297 opt = struct('type', 'FIXED');
0298 [Pd, Qd] = total_load(mpc.bus, mpc.gen, load_zone, opt);
0299 t_is(Pd, area(1).fixed.p, 12, [t 'Pd']);
0300 t_is(Qd, area(1).fixed.q, 12, [t 'Qd']);
0301 
0302 t = '      Pd = total_load(b, g, ld_zone1, .type = ''DISPATCHABLE'') : ';
0303 opt = struct('type', 'DISPATCHABLE');
0304 Pd = total_load(mpc.bus, mpc.gen, load_zone, opt);
0305 t_is(Pd, area(1).disp.p, 12, [t 'Pd']);
0306 
0307 t = '      Pd = total_load(b, g, ld_zone1, .type = ''DISP'' .nominal = 1) : ';
0308 opt = struct('type', 'DISP', 'nominal', 1);
0309 Pd = total_load(mpc.bus, mpc.gen, load_zone, opt);
0310 t_is(Pd, area(1).disp.pnom, 12, [t 'Pd']);
0311 
0312 t = '      Pd = total_load(b, g, ld_zone1, .type = ''DISP'' .nominal = 0) : ';
0313 opt = struct('type', 'DISP', 'nominal', 0);
0314 Pd = total_load(mpc.bus, mpc.gen, load_zone, opt);
0315 t_is(Pd, area(1).disp.p, 12, [t 'Pd']);
0316 
0317 t = '[Pd, Qd] = total_load(b, g, ld_zone1, .type = ''DISPATCHABLE'') : ';
0318 opt = struct('type', 'DISPATCHABLE');
0319 [Pd, Qd] = total_load(mpc.bus, mpc.gen, load_zone, opt);
0320 t_is(Pd, area(1).disp.p, 12, [t 'Pd']);
0321 t_is(Qd, area(1).disp.q, 12, [t 'Qd']);
0322 
0323 t = '[Pd, Qd] = total_load(b, g, ld_zone1, .type = ''DISP'' .nominal = 1) : ';
0324 opt = struct('type', 'DISP', 'nominal', 1);
0325 [Pd, Qd] = total_load(mpc.bus, mpc.gen, load_zone, opt);
0326 t_is(Pd, area(1).disp.pnom, 12, [t 'Pd']);
0327 t_is(Qd, area(1).disp.qnom, 12, [t 'Qd']);
0328 
0329 t = '[Pd, Qd] = total_load(b, g, ld_zone1, .type = ''DISP'' .nominal = 0) : ';
0330 opt = struct('type', 'DISP', 'nominal', 0);
0331 [Pd, Qd] = total_load(mpc.bus, mpc.gen, load_zone, opt);
0332 t_is(Pd, area(1).disp.p, 12, [t 'Pd']);
0333 t_is(Qd, area(1).disp.q, 12, [t 'Qd']);
0334 
0335 %%-----  explicit multiple load zone  -----
0336 load_zone = zeros(nb, 1);
0337 k = find(mpc.bus(:, BUS_AREA) == 3);    %% area 3
0338 load_zone(k) = 1;
0339 k = find(mpc.bus(:, BUS_AREA) == 1);    %% area 1
0340 load_zone(k) = 2;
0341 t = '      Pd = total_load(b, g, ld_zone2, .type = ''BOTH'') : ';
0342 opt = struct('type', 'BOTH');
0343 Pd = total_load(mpc.bus, mpc.gen, load_zone, opt);
0344 t_is(Pd, [area(3).both.p; area(1).both.p], 12, [t 'Pd']);
0345 
0346 t = '      Pd = total_load(b, g, ld_zone2, .type = ''BOTH'' .nominal = 1) : ';
0347 opt = struct('type', 'BOTH', 'nominal', 1);
0348 Pd = total_load(mpc.bus, mpc.gen, load_zone, opt);
0349 t_is(Pd, [area(3).both.pnom; area(1).both.pnom], 12, [t 'Pd']);
0350 
0351 t = '      Pd = total_load(b, g, ld_zone2, .type = ''BOTH'' .nominal = 0) : ';
0352 opt = struct('type', 'BOTH', 'nominal', 0);
0353 Pd = total_load(mpc.bus, mpc.gen, load_zone, opt);
0354 t_is(Pd, [area(3).both.p; area(1).both.p], 12, [t 'Pd']);
0355 
0356 t = '[Pd, Qd] = total_load(b, g, ld_zone2, .type = ''BOTH'') : ';
0357 opt = struct('type', 'BOTH');
0358 [Pd, Qd] = total_load(mpc.bus, mpc.gen, load_zone, opt);
0359 t_is(Pd, [area(3).both.p; area(1).both.p], 12, [t 'Pd']);
0360 t_is(Qd, [area(3).both.q; area(1).both.q], 12, [t 'Qd']);
0361 
0362 t = '[Pd, Qd] = total_load(b, g, ld_zone2, .type = ''BOTH'' .nominal = 1) : ';
0363 opt = struct('type', 'BOTH', 'nominal', 1);
0364 [Pd, Qd] = total_load(mpc.bus, mpc.gen, load_zone, opt);
0365 t_is(Pd, [area(3).both.pnom; area(1).both.pnom], 12, [t 'Pd']);
0366 t_is(Qd, [area(3).both.qnom; area(1).both.qnom], 12, [t 'Qd']);
0367 
0368 t = '[Pd, Qd] = total_load(b, g, ld_zone2, .type = ''BOTH'' .nominal = 0) : ';
0369 opt = struct('type', 'BOTH', 'nominal', 0);
0370 [Pd, Qd] = total_load(mpc.bus, mpc.gen, load_zone, opt);
0371 t_is(Pd, [area(3).both.p; area(1).both.p], 12, [t 'Pd']);
0372 t_is(Qd, [area(3).both.q; area(1).both.q], 12, [t 'Qd']);
0373 
0374 t = '      Pd = total_load(b, g, ld_zone2, .type = ''FIXED'') : ';
0375 opt = struct('type', 'FIXED');
0376 Pd = total_load(mpc.bus, mpc.gen, load_zone, opt);
0377 t_is(Pd, [area(3).fixed.p; area(1).fixed.p], 12, [t 'Pd']);
0378 
0379 t = '[Pd, Qd] = total_load(b, g, ld_zone2, .type = ''FIXED'') : ';
0380 opt = struct('type', 'FIXED');
0381 [Pd, Qd] = total_load(mpc.bus, mpc.gen, load_zone, opt);
0382 t_is(Pd, [area(3).fixed.p; area(1).fixed.p], 12, [t 'Pd']);
0383 t_is(Qd, [area(3).fixed.q; area(1).fixed.q], 12, [t 'Qd']);
0384 
0385 t = '      Pd = total_load(b, g, ld_zone2, .type = ''DISPATCHABLE'') : ';
0386 opt = struct('type', 'DISPATCHABLE');
0387 Pd = total_load(mpc.bus, mpc.gen, load_zone, opt);
0388 t_is(Pd, [area(3).disp.p; area(1).disp.p], 12, [t 'Pd']);
0389 
0390 t = '      Pd = total_load(b, g, ld_zone2, .type = ''DISP'' .nominal = 1) : ';
0391 opt = struct('type', 'DISP', 'nominal', 1);
0392 Pd = total_load(mpc.bus, mpc.gen, load_zone, opt);
0393 t_is(Pd, [area(3).disp.pnom; area(1).disp.pnom], 12, [t 'Pd']);
0394 
0395 t = '      Pd = total_load(b, g, ld_zone2, .type = ''DISP'' .nominal = 0) : ';
0396 opt = struct('type', 'DISP', 'nominal', 0);
0397 Pd = total_load(mpc.bus, mpc.gen, load_zone, opt);
0398 t_is(Pd, [area(3).disp.p; area(1).disp.p], 12, [t 'Pd']);
0399 
0400 t = '[Pd, Qd] = total_load(b, g, ld_zone2, .type = ''DISPATCHABLE'') : ';
0401 opt = struct('type', 'DISPATCHABLE');
0402 [Pd, Qd] = total_load(mpc.bus, mpc.gen, load_zone, opt);
0403 t_is(Pd, [area(3).disp.p; area(1).disp.p], 12, [t 'Pd']);
0404 t_is(Qd, [area(3).disp.q; area(1).disp.q], 12, [t 'Qd']);
0405 
0406 t = '[Pd, Qd] = total_load(b, g, ld_zone2, .type = ''DISP'' .nominal = 1) : ';
0407 opt = struct('type', 'DISP', 'nominal', 1);
0408 [Pd, Qd] = total_load(mpc.bus, mpc.gen, load_zone, opt);
0409 t_is(Pd, [area(3).disp.pnom; area(1).disp.pnom], 12, [t 'Pd']);
0410 t_is(Qd, [area(3).disp.qnom; area(1).disp.qnom], 12, [t 'Qd']);
0411 
0412 t = '[Pd, Qd] = total_load(b, g, ld_zone2, .type = ''DISP'' .nominal = 0) : ';
0413 opt = struct('type', 'DISP', 'nominal', 0);
0414 [Pd, Qd] = total_load(mpc.bus, mpc.gen, load_zone, opt);
0415 t_is(Pd, [area(3).disp.p; area(1).disp.p], 12, [t 'Pd']);
0416 t_is(Qd, [area(3).disp.q; area(1).disp.q], 12, [t 'Qd']);
0417 
0418 %%-----  old DEPRECATED string options, below  -----
0419 %%-----  all load  -----
0420 t = '      Pd = total_load(b, g, ''all'', ''BOTH'') : ';
0421 Pd = total_load(mpc.bus, mpc.gen, 'all', 'BOTH');
0422 t_is(Pd, total.both.pnom, 12, [t 'Pd']);
0423 
0424 t = '[Pd, Qd] = total_load(b, g, ''all'', ''BOTH'') : ';
0425 [Pd, Qd] = total_load(mpc.bus, mpc.gen, 'all', 'BOTH');
0426 t_is(Pd, total.both.pnom, 12, [t 'Pd']);
0427 t_is(Qd, total.both.qnom, 12, [t 'Qd']);
0428 
0429 t = '      Pd = total_load(b, g, ''all'', ''FIXED'') : ';
0430 Pd = total_load(mpc.bus, mpc.gen, 'all', 'FIXED');
0431 t_is(Pd, total.fixed.p, 12, [t 'Pd']);
0432 
0433 t = '[Pd, Qd] = total_load(b, g, ''all'', ''FIXED'') : ';
0434 [Pd, Qd] = total_load(mpc.bus, mpc.gen, 'all', 'FIXED');
0435 t_is(Pd, total.fixed.p, 12, [t 'Pd']);
0436 t_is(Qd, total.fixed.q, 12, [t 'Qd']);
0437 
0438 t = '      Pd = total_load(b, g, ''all'', ''DISPATCHABLE'') : ';
0439 Pd = total_load(mpc.bus, mpc.gen, 'all', 'DISPATCHABLE');
0440 t_is(Pd, total.disp.pnom, 12, [t 'Pd']);
0441 
0442 t = '[Pd, Qd] = total_load(b, g, ''all'', ''DISPATCHABLE'') : ';
0443 [Pd, Qd] = total_load(mpc.bus, mpc.gen, 'all', 'DISPATCHABLE');
0444 t_is(Pd, total.disp.pnom, 12, [t 'Pd']);
0445 t_is(Qd, total.disp.qnom, 12, [t 'Qd']);
0446 
0447 t = '      Pd = total_load(b, g, [], ''BOTH'') : ';
0448 Pd = total_load(mpc.bus, mpc.gen, [], 'BOTH');
0449 t_is(Pd, [area(1).both.pnom; area(2).both.pnom; area(3).both.pnom], 12, [t 'Pd']);
0450 
0451 t = '[Pd, Qd] = total_load(b, g, [], ''BOTH'') : ';
0452 [Pd, Qd] = total_load(mpc.bus, mpc.gen, [], 'BOTH');
0453 t_is(Pd, [area(1).both.pnom; area(2).both.pnom; area(3).both.pnom], 12, [t 'Pd']);
0454 t_is(Qd, [area(1).both.qnom; area(2).both.qnom; area(3).both.qnom], 12, [t 'Qd']);
0455 
0456 t = '      Pd = total_load(b, g, [], ''FIXED'') : ';
0457 Pd = total_load(mpc.bus, mpc.gen, [], 'FIXED');
0458 t_is(Pd, [area(1).fixed.p; area(2).fixed.p; area(3).fixed.p], 12, [t 'Pd']);
0459 
0460 t = '[Pd, Qd] = total_load(b, g, [], ''FIXED'') : ';
0461 [Pd, Qd] = total_load(mpc.bus, mpc.gen, [], 'FIXED');
0462 t_is(Pd, [area(1).fixed.p; area(2).fixed.p; area(3).fixed.p], 12, [t 'Pd']);
0463 t_is(Qd, [area(1).fixed.q; area(2).fixed.q; area(3).fixed.q], 12, [t 'Qd']);
0464 
0465 t = '      Pd = total_load(b, g, [], ''DISPATCHABLE'') : ';
0466 Pd = total_load(mpc.bus, mpc.gen, [], 'DISPATCHABLE');
0467 t_is(Pd, [area(1).disp.pnom; area(2).disp.pnom; area(3).disp.pnom], 12, [t 'Pd']);
0468 
0469 t = '[Pd, Qd] = total_load(b, g, [], ''DISPATCHABLE'') : ';
0470 [Pd, Qd] = total_load(mpc.bus, mpc.gen, [], 'DISPATCHABLE');
0471 t_is(Pd, [area(1).disp.pnom; area(2).disp.pnom; area(3).disp.pnom], 12, [t 'Pd']);
0472 t_is(Qd, [area(1).disp.qnom; area(2).disp.qnom; area(3).disp.qnom], 12, [t 'Qd']);
0473 
0474 %%-----  explicit single load zone  -----
0475 nb = size(mpc.bus, 1);
0476 load_zone = zeros(nb, 1);
0477 k = find(mpc.bus(:, BUS_AREA) == 1);    %% area 1
0478 load_zone(k) = 1;
0479 t = '      Pd = total_load(b, g, ld_zone1, ''BOTH'') : ';
0480 Pd = total_load(mpc.bus, mpc.gen, load_zone, 'BOTH');
0481 t_is(Pd, area(1).both.pnom, 12, [t 'Pd']);
0482 
0483 t = '[Pd, Qd] = total_load(b, g, ld_zone1, ''BOTH'') : ';
0484 [Pd, Qd] = total_load(mpc.bus, mpc.gen, load_zone, 'BOTH');
0485 t_is(Pd, area(1).both.pnom, 12, [t 'Pd']);
0486 t_is(Qd, area(1).both.qnom, 12, [t 'Qd']);
0487 
0488 t = '      Pd = total_load(b, g, ld_zone1, ''FIXED'') : ';
0489 Pd = total_load(mpc.bus, mpc.gen, load_zone, 'FIXED');
0490 t_is(Pd, area(1).fixed.p, 12, [t 'Pd']);
0491 
0492 t = '[Pd, Qd] = total_load(b, g, ld_zone1, ''FIXED'') : ';
0493 [Pd, Qd] = total_load(mpc.bus, mpc.gen, load_zone, 'FIXED');
0494 t_is(Pd, area(1).fixed.p, 12, [t 'Pd']);
0495 t_is(Qd, area(1).fixed.q, 12, [t 'Qd']);
0496 
0497 t = '      Pd = total_load(b, g, ld_zone1, ''DISPATCHABLE'') : ';
0498 Pd = total_load(mpc.bus, mpc.gen, load_zone, 'DISPATCHABLE');
0499 t_is(Pd, area(1).disp.pnom, 12, [t 'Pd']);
0500 
0501 t = '[Pd, Qd] = total_load(b, g, ld_zone1, ''DISPATCHABLE'') : ';
0502 [Pd, Qd] = total_load(mpc.bus, mpc.gen, load_zone, 'DISPATCHABLE');
0503 t_is(Pd, area(1).disp.pnom, 12, [t 'Pd']);
0504 t_is(Qd, area(1).disp.qnom, 12, [t 'Qd']);
0505 
0506 %%-----  explicit multiple load zone  -----
0507 load_zone = zeros(nb, 1);
0508 k = find(mpc.bus(:, BUS_AREA) == 3);    %% area 3
0509 load_zone(k) = 1;
0510 k = find(mpc.bus(:, BUS_AREA) == 1);    %% area 1
0511 load_zone(k) = 2;
0512 t = '      Pd = total_load(b, g, ld_zone2, ''BOTH'') : ';
0513 Pd = total_load(mpc.bus, mpc.gen, load_zone, 'BOTH');
0514 t_is(Pd, [area(3).both.pnom; area(1).both.pnom], 12, [t 'Pd']);
0515 
0516 t = '[Pd, Qd] = total_load(b, g, ld_zone2, ''BOTH'') : ';
0517 [Pd, Qd] = total_load(mpc.bus, mpc.gen, load_zone, 'BOTH');
0518 t_is(Pd, [area(3).both.pnom; area(1).both.pnom], 12, [t 'Pd']);
0519 t_is(Qd, [area(3).both.qnom; area(1).both.qnom], 12, [t 'Qd']);
0520 
0521 t = '      Pd = total_load(b, g, ld_zone2, ''FIXED'') : ';
0522 Pd = total_load(mpc.bus, mpc.gen, load_zone, 'FIXED');
0523 t_is(Pd, [area(3).fixed.p; area(1).fixed.p], 12, [t 'Pd']);
0524 
0525 t = '[Pd, Qd] = total_load(b, g, ld_zone2, ''FIXED'') : ';
0526 [Pd, Qd] = total_load(mpc.bus, mpc.gen, load_zone, 'FIXED');
0527 t_is(Pd, [area(3).fixed.p; area(1).fixed.p], 12, [t 'Pd']);
0528 t_is(Qd, [area(3).fixed.q; area(1).fixed.q], 12, [t 'Qd']);
0529 
0530 t = '      Pd = total_load(b, g, ld_zone2, ''DISPATCHABLE'') : ';
0531 Pd = total_load(mpc.bus, mpc.gen, load_zone, 'DISPATCHABLE');
0532 t_is(Pd, [area(3).disp.pnom; area(1).disp.pnom], 12, [t 'Pd']);
0533 
0534 t = '[Pd, Qd] = total_load(b, g, ld_zone2, ''DISPATCHABLE'') : ';
0535 [Pd, Qd] = total_load(mpc.bus, mpc.gen, load_zone, 'DISPATCHABLE');
0536 t_is(Pd, [area(3).disp.pnom; area(1).disp.pnom], 12, [t 'Pd']);
0537 t_is(Qd, [area(3).disp.qnom; area(1).disp.qnom], 12, [t 'Qd']);
0538 
0539 %%------------------------------------------------------------------
0540 %% mostly same tests below, but with MPC input
0541 
0542  %%-----  all load  -----
0543 t = '      Pd = total_load(mpc) : ';
0544 Pd = total_load(mpc);
0545 t_is(Pd, [area(1).both.p; area(2).both.p; area(3).both.p], 12, [t 'Pd']);
0546 
0547 t = '[Pd, Qd] = total_load(mpc) : ';
0548 [Pd, Qd] = total_load(mpc);
0549 t_is(Pd, [area(1).both.p; area(2).both.p; area(3).both.p], 12, [t 'Pd']);
0550 t_is(Qd, [area(1).both.q; area(2).both.q; area(3).both.q], 12, [t 'Qd']);
0551 
0552 t = '      Pd = total_load(mpc, ''all'') : ';
0553 Pd = total_load(mpc, 'all');
0554 t_is(Pd, total.both.p, 12, [t 'Pd']);
0555 
0556 t = '[Pd, Qd] = total_load(mpc, ''all'') : ';
0557 [Pd, Qd] = total_load(mpc, 'all');
0558 t_is(Pd, total.both.p, 12, [t 'Pd']);
0559 t_is(Qd, total.both.q, 12, [t 'Qd']);
0560 
0561 t = '      Pd = total_load(mpc, ''all'', .type = ''BOTH'') : ';
0562 opt = struct('type', 'BOTH');
0563 Pd = total_load(mpc, 'all', opt);
0564 t_is(Pd, total.both.p, 12, [t 'Pd']);
0565 
0566 t = '      Pd = total_load(mpc, ''all'', .type = ''BOTH'' .nominal = 1) : ';
0567 opt = struct('type', 'BOTH', 'nominal', 1);
0568 Pd = total_load(mpc, 'all', opt);
0569 t_is(Pd, total.both.pnom, 12, [t 'Pd']);
0570 
0571 t = '      Pd = total_load(mpc, ''all'', .type = ''BOTH'' .nominal = 0) : ';
0572 opt = struct('type', 'BOTH', 'nominal', 0);
0573 Pd = total_load(mpc, 'all', opt);
0574 t_is(Pd, total.both.p, 12, [t 'Pd']);
0575 
0576 t = '[Pd, Qd] = total_load(mpc, ''all'', .type = ''BOTH'') : ';
0577 opt = struct('type', 'BOTH');
0578 [Pd, Qd] = total_load(mpc, 'all', opt);
0579 t_is(Pd, total.both.p, 12, [t 'Pd']);
0580 t_is(Qd, total.both.q, 12, [t 'Qd']);
0581 
0582 t = '      Pd = total_load(mpc, ''all'', .type = ''FIXED'') : ';
0583 opt = struct('type', 'FIXED');
0584 Pd = total_load(mpc, 'all', opt);
0585 t_is(Pd, total.fixed.p, 12, [t 'Pd']);
0586 
0587 t = '[Pd, Qd] = total_load(mpc, ''all'', .type = ''FIXED'') : ';
0588 opt = struct('type', 'FIXED');
0589 [Pd, Qd] = total_load(mpc, 'all', opt);
0590 t_is(Pd, total.fixed.p, 12, [t 'Pd']);
0591 t_is(Qd, total.fixed.q, 12, [t 'Qd']);
0592 
0593 t = '      Pd = total_load(mpc, ''all'', .type = ''DISPATCHABLE'') : ';
0594 opt = struct('type', 'DISPATCHABLE');
0595 Pd = total_load(mpc, 'all', opt);
0596 t_is(Pd, total.disp.p, 12, [t 'Pd']);
0597 
0598 t = '      Pd = total_load(mpc, ''all'', .type = ''DISP'' .nominal = 1) : ';
0599 opt = struct('type', 'DISP', 'nominal', 1);
0600 Pd = total_load(mpc, 'all', opt);
0601 t_is(Pd, total.disp.pnom, 12, [t 'Pd']);
0602 
0603 t = '      Pd = total_load(mpc, ''all'', .type = ''DISP'' .nominal = 0) : ';
0604 opt = struct('type', 'DISP', 'nominal', 0);
0605 Pd = total_load(mpc, 'all', opt);
0606 t_is(Pd, total.disp.p, 12, [t 'Pd']);
0607 
0608 t = '[Pd, Qd] = total_load(mpc, ''all'', .type = ''DISPATCHABLE'') : ';
0609 opt = struct('type', 'DISPATCHABLE');
0610 [Pd, Qd] = total_load(mpc, 'all', opt);
0611 t_is(Pd, total.disp.p, 12, [t 'Pd']);
0612 t_is(Qd, total.disp.q, 12, [t 'Qd']);
0613 
0614 t = '[Pd, Qd] = total_load(mpc, ''all'', .type = ''DISP'' .nominal = 1) : ';
0615 opt = struct('type', 'DISP', 'nominal', 1);
0616 [Pd, Qd] = total_load(mpc, 'all', opt);
0617 t_is(Pd, total.disp.pnom, 12, [t 'Pd']);
0618 t_is(Qd, total.disp.qnom, 12, [t 'Qd']);
0619 
0620 t = '[Pd, Qd] = total_load(mpc, ''all'', .type = ''DISP'' .nominal = 0) : ';
0621 opt = struct('type', 'DISP', 'nominal', 0);
0622 [Pd, Qd] = total_load(mpc, 'all', opt);
0623 t_is(Pd, total.disp.p, 12, [t 'Pd']);
0624 t_is(Qd, total.disp.q, 12, [t 'Qd']);
0625 
0626 t = '      Pd = total_load(mpc, [], .type = ''BOTH'') : ';
0627 opt = struct('type', 'BOTH');
0628 Pd = total_load(mpc, [], opt);
0629 t_is(Pd, [area(1).both.p; area(2).both.p; area(3).both.p], 12, [t 'Pd']);
0630 
0631 t = '      Pd = total_load(mpc, [], .type = ''BOTH'' .nominal = 1) : ';
0632 opt = struct('type', 'BOTH', 'nominal', 1);
0633 Pd = total_load(mpc, [], opt);
0634 t_is(Pd, [area(1).both.pnom; area(2).both.pnom; area(3).both.pnom], 12, [t 'Pd']);
0635 
0636 t = '      Pd = total_load(mpc, [], .type = ''BOTH'' .nominal = 0) : ';
0637 opt = struct('type', 'BOTH', 'nominal', 0);
0638 Pd = total_load(mpc, [], opt);
0639 t_is(Pd, [area(1).both.p; area(2).both.p; area(3).both.p], 12, [t 'Pd']);
0640 
0641 t = '[Pd, Qd] = total_load(mpc, [], .type = ''BOTH'') : ';
0642 opt = struct('type', 'BOTH');
0643 [Pd, Qd] = total_load(mpc, [], opt);
0644 t_is(Pd, [area(1).both.p; area(2).both.p; area(3).both.p], 12, [t 'Pd']);
0645 t_is(Qd, [area(1).both.q; area(2).both.q; area(3).both.q], 12, [t 'Qd']);
0646 
0647 t = '[Pd, Qd] = total_load(mpc, [], .type = ''BOTH'' .nominal = 1) : ';
0648 opt = struct('type', 'BOTH', 'nominal', 1);
0649 [Pd, Qd] = total_load(mpc, [], opt);
0650 t_is(Pd, [area(1).both.pnom; area(2).both.pnom; area(3).both.pnom], 12, [t 'Pd']);
0651 t_is(Qd, [area(1).both.qnom; area(2).both.qnom; area(3).both.qnom], 12, [t 'Qd']);
0652 
0653 t = '[Pd, Qd] = total_load(mpc, [], .type = ''BOTH'' .nominal = 0) : ';
0654 opt = struct('type', 'BOTH', 'nominal', 0);
0655 [Pd, Qd] = total_load(mpc, [], opt);
0656 t_is(Pd, [area(1).both.p; area(2).both.p; area(3).both.p], 12, [t 'Pd']);
0657 t_is(Qd, [area(1).both.q; area(2).both.q; area(3).both.q], 12, [t 'Qd']);
0658 
0659 t = '      Pd = total_load(mpc, [], .type = ''FIXED'') : ';
0660 opt = struct('type', 'FIXED');
0661 Pd = total_load(mpc, [], opt);
0662 t_is(Pd, [area(1).fixed.p; area(2).fixed.p; area(3).fixed.p], 12, [t 'Pd']);
0663 
0664 t = '[Pd, Qd] = total_load(mpc, [], .type = ''FIXED'') : ';
0665 opt = struct('type', 'FIXED');
0666 [Pd, Qd] = total_load(mpc, [], opt);
0667 t_is(Pd, [area(1).fixed.p; area(2).fixed.p; area(3).fixed.p], 12, [t 'Pd']);
0668 t_is(Qd, [area(1).fixed.q; area(2).fixed.q; area(3).fixed.q], 12, [t 'Qd']);
0669 
0670 t = '      Pd = total_load(mpc, [], .type = ''DISPATCHABLE'') : ';
0671 opt = struct('type', 'DISPATCHABLE');
0672 Pd = total_load(mpc, [], opt);
0673 t_is(Pd, [area(1).disp.p; area(2).disp.p; area(3).disp.p], 12, [t 'Pd']);
0674 
0675 t = '      Pd = total_load(mpc, [], .type = ''DISP'' .nominal = 1) : ';
0676 opt = struct('type', 'DISP', 'nominal', 1);
0677 Pd = total_load(mpc, [], opt);
0678 t_is(Pd, [area(1).disp.pnom; area(2).disp.pnom; area(3).disp.pnom], 12, [t 'Pd']);
0679 
0680 t = '      Pd = total_load(mpc, [], .type = ''DISP'' .nominal = 0) : ';
0681 opt = struct('type', 'DISP', 'nominal', 0);
0682 Pd = total_load(mpc, [], opt);
0683 t_is(Pd, [area(1).disp.p; area(2).disp.p; area(3).disp.p], 12, [t 'Pd']);
0684 
0685 t = '[Pd, Qd] = total_load(mpc, [], .type = ''DISPATCHABLE'') : ';
0686 opt = struct('type', 'DISPATCHABLE');
0687 [Pd, Qd] = total_load(mpc, [], opt);
0688 t_is(Pd, [area(1).disp.p; area(2).disp.p; area(3).disp.p], 12, [t 'Pd']);
0689 t_is(Qd, [area(1).disp.q; area(2).disp.q; area(3).disp.q], 12, [t 'Qd']);
0690 
0691 t = '[Pd, Qd] = total_load(mpc, [], .type = ''DISP'' .nominal = 1) : ';
0692 opt = struct('type', 'DISP', 'nominal', 1);
0693 [Pd, Qd] = total_load(mpc, [], opt);
0694 t_is(Pd, [area(1).disp.pnom; area(2).disp.pnom; area(3).disp.pnom], 12, [t 'Pd']);
0695 t_is(Qd, [area(1).disp.qnom; area(2).disp.qnom; area(3).disp.qnom], 12, [t 'Qd']);
0696 
0697 t = '[Pd, Qd] = total_load(mpc, [], .type = ''DISP'' .nominal = 0) : ';
0698 opt = struct('type', 'DISP', 'nominal', 0);
0699 [Pd, Qd] = total_load(mpc, [], opt);
0700 t_is(Pd, [area(1).disp.p; area(2).disp.p; area(3).disp.p], 12, [t 'Pd']);
0701 t_is(Qd, [area(1).disp.q; area(2).disp.q; area(3).disp.q], 12, [t 'Qd']);
0702 
0703 %%-----  explicit single load zone  -----
0704 nb = size(mpc.bus, 1);
0705 load_zone = zeros(nb, 1);
0706 k = find(mpc.bus(:, BUS_AREA) == 1);    %% area 1
0707 load_zone(k) = 1;
0708 t = '      Pd = total_load(mpc, ld_zone1, .type = ''BOTH'') : ';
0709 opt = struct('type', 'BOTH');
0710 Pd = total_load(mpc, load_zone, opt);
0711 t_is(Pd, area(1).both.p, 12, [t 'Pd']);
0712 
0713 t = '      Pd = total_load(mpc, ld_zone1, .type = ''BOTH'' .nominal = 1) : ';
0714 opt = struct('type', 'BOTH', 'nominal', 1);
0715 Pd = total_load(mpc, load_zone, opt);
0716 t_is(Pd, area(1).both.pnom, 12, [t 'Pd']);
0717 
0718 t = '      Pd = total_load(mpc, ld_zone1, .type = ''BOTH'' .nominal = 0) : ';
0719 opt = struct('type', 'BOTH', 'nominal', 0);
0720 Pd = total_load(mpc, load_zone, opt);
0721 t_is(Pd, area(1).both.p, 12, [t 'Pd']);
0722 
0723 t = '[Pd, Qd] = total_load(mpc, ld_zone1, .type = ''BOTH'') : ';
0724 opt = struct('type', 'BOTH');
0725 [Pd, Qd] = total_load(mpc, load_zone, opt);
0726 t_is(Pd, area(1).both.p, 12, [t 'Pd']);
0727 t_is(Qd, area(1).both.q, 12, [t 'Qd']);
0728 
0729 t = '[Pd, Qd] = total_load(mpc, ld_zone1, .type = ''BOTH'' .nominal = 1) : ';
0730 opt = struct('type', 'BOTH', 'nominal', 1);
0731 [Pd, Qd] = total_load(mpc, load_zone, opt);
0732 t_is(Pd, area(1).both.pnom, 12, [t 'Pd']);
0733 t_is(Qd, area(1).both.qnom, 12, [t 'Qd']);
0734 
0735 t = '[Pd, Qd] = total_load(mpc, ld_zone1, .type = ''BOTH'' .nominal = 0) : ';
0736 opt = struct('type', 'BOTH', 'nominal', 0);
0737 [Pd, Qd] = total_load(mpc, load_zone, opt);
0738 t_is(Pd, area(1).both.p, 12, [t 'Pd']);
0739 t_is(Qd, area(1).both.q, 12, [t 'Qd']);
0740 
0741 t = '      Pd = total_load(mpc, ld_zone1, .type = ''FIXED'') : ';
0742 opt = struct('type', 'FIXED');
0743 Pd = total_load(mpc, load_zone, opt);
0744 t_is(Pd, area(1).fixed.p, 12, [t 'Pd']);
0745 
0746 t = '[Pd, Qd] = total_load(mpc, ld_zone1, .type = ''FIXED'') : ';
0747 opt = struct('type', 'FIXED');
0748 [Pd, Qd] = total_load(mpc, load_zone, opt);
0749 t_is(Pd, area(1).fixed.p, 12, [t 'Pd']);
0750 t_is(Qd, area(1).fixed.q, 12, [t 'Qd']);
0751 
0752 t = '      Pd = total_load(mpc, ld_zone1, .type = ''DISPATCHABLE'') : ';
0753 opt = struct('type', 'DISPATCHABLE');
0754 Pd = total_load(mpc, load_zone, opt);
0755 t_is(Pd, area(1).disp.p, 12, [t 'Pd']);
0756 
0757 t = '      Pd = total_load(mpc, ld_zone1, .type = ''DISP'' .nominal = 1) : ';
0758 opt = struct('type', 'DISP', 'nominal', 1);
0759 Pd = total_load(mpc, load_zone, opt);
0760 t_is(Pd, area(1).disp.pnom, 12, [t 'Pd']);
0761 
0762 t = '      Pd = total_load(mpc, ld_zone1, .type = ''DISP'' .nominal = 0) : ';
0763 opt = struct('type', 'DISP', 'nominal', 0);
0764 Pd = total_load(mpc, load_zone, opt);
0765 t_is(Pd, area(1).disp.p, 12, [t 'Pd']);
0766 
0767 t = '[Pd, Qd] = total_load(mpc, ld_zone1, .type = ''DISPATCHABLE'') : ';
0768 opt = struct('type', 'DISPATCHABLE');
0769 [Pd, Qd] = total_load(mpc, load_zone, opt);
0770 t_is(Pd, area(1).disp.p, 12, [t 'Pd']);
0771 t_is(Qd, area(1).disp.q, 12, [t 'Qd']);
0772 
0773 t = '[Pd, Qd] = total_load(mpc, ld_zone1, .type = ''DISP'' .nominal = 1) : ';
0774 opt = struct('type', 'DISP', 'nominal', 1);
0775 [Pd, Qd] = total_load(mpc, load_zone, opt);
0776 t_is(Pd, area(1).disp.pnom, 12, [t 'Pd']);
0777 t_is(Qd, area(1).disp.qnom, 12, [t 'Qd']);
0778 
0779 t = '[Pd, Qd] = total_load(mpc, ld_zone1, .type = ''DISP'' .nominal = 0) : ';
0780 opt = struct('type', 'DISP', 'nominal', 0);
0781 [Pd, Qd] = total_load(mpc, load_zone, opt);
0782 t_is(Pd, area(1).disp.p, 12, [t 'Pd']);
0783 t_is(Qd, area(1).disp.q, 12, [t 'Qd']);
0784 
0785 %%-----  explicit multiple load zone  -----
0786 load_zone = zeros(nb, 1);
0787 k = find(mpc.bus(:, BUS_AREA) == 3);    %% area 3
0788 load_zone(k) = 1;
0789 k = find(mpc.bus(:, BUS_AREA) == 1);    %% area 1
0790 load_zone(k) = 2;
0791 t = '      Pd = total_load(mpc, ld_zone2, .type = ''BOTH'') : ';
0792 opt = struct('type', 'BOTH');
0793 Pd = total_load(mpc, load_zone, opt);
0794 t_is(Pd, [area(3).both.p; area(1).both.p], 12, [t 'Pd']);
0795 
0796 t = '      Pd = total_load(mpc, ld_zone2, .type = ''BOTH'' .nominal = 1) : ';
0797 opt = struct('type', 'BOTH', 'nominal', 1);
0798 Pd = total_load(mpc, load_zone, opt);
0799 t_is(Pd, [area(3).both.pnom; area(1).both.pnom], 12, [t 'Pd']);
0800 
0801 t = '      Pd = total_load(mpc, ld_zone2, .type = ''BOTH'' .nominal = 0) : ';
0802 opt = struct('type', 'BOTH', 'nominal', 0);
0803 Pd = total_load(mpc, load_zone, opt);
0804 t_is(Pd, [area(3).both.p; area(1).both.p], 12, [t 'Pd']);
0805 
0806 t = '[Pd, Qd] = total_load(mpc, ld_zone2, .type = ''BOTH'') : ';
0807 opt = struct('type', 'BOTH');
0808 [Pd, Qd] = total_load(mpc, load_zone, opt);
0809 t_is(Pd, [area(3).both.p; area(1).both.p], 12, [t 'Pd']);
0810 t_is(Qd, [area(3).both.q; area(1).both.q], 12, [t 'Qd']);
0811 
0812 t = '[Pd, Qd] = total_load(mpc, ld_zone2, .type = ''BOTH'' .nominal = 1) : ';
0813 opt = struct('type', 'BOTH', 'nominal', 1);
0814 [Pd, Qd] = total_load(mpc, load_zone, opt);
0815 t_is(Pd, [area(3).both.pnom; area(1).both.pnom], 12, [t 'Pd']);
0816 t_is(Qd, [area(3).both.qnom; area(1).both.qnom], 12, [t 'Qd']);
0817 
0818 t = '[Pd, Qd] = total_load(mpc, ld_zone2, .type = ''BOTH'' .nominal = 0) : ';
0819 opt = struct('type', 'BOTH', 'nominal', 0);
0820 [Pd, Qd] = total_load(mpc, load_zone, opt);
0821 t_is(Pd, [area(3).both.p; area(1).both.p], 12, [t 'Pd']);
0822 t_is(Qd, [area(3).both.q; area(1).both.q], 12, [t 'Qd']);
0823 
0824 t = '      Pd = total_load(mpc, ld_zone2, .type = ''FIXED'') : ';
0825 opt = struct('type', 'FIXED');
0826 Pd = total_load(mpc, load_zone, opt);
0827 t_is(Pd, [area(3).fixed.p; area(1).fixed.p], 12, [t 'Pd']);
0828 
0829 t = '[Pd, Qd] = total_load(mpc, ld_zone2, .type = ''FIXED'') : ';
0830 opt = struct('type', 'FIXED');
0831 [Pd, Qd] = total_load(mpc, load_zone, opt);
0832 t_is(Pd, [area(3).fixed.p; area(1).fixed.p], 12, [t 'Pd']);
0833 t_is(Qd, [area(3).fixed.q; area(1).fixed.q], 12, [t 'Qd']);
0834 
0835 t = '      Pd = total_load(mpc, ld_zone2, .type = ''DISPATCHABLE'') : ';
0836 opt = struct('type', 'DISPATCHABLE');
0837 Pd = total_load(mpc, load_zone, opt);
0838 t_is(Pd, [area(3).disp.p; area(1).disp.p], 12, [t 'Pd']);
0839 
0840 t = '      Pd = total_load(mpc, ld_zone2, .type = ''DISP'' .nominal = 1) : ';
0841 opt = struct('type', 'DISP', 'nominal', 1);
0842 Pd = total_load(mpc, load_zone, opt);
0843 t_is(Pd, [area(3).disp.pnom; area(1).disp.pnom], 12, [t 'Pd']);
0844 
0845 t = '      Pd = total_load(mpc, ld_zone2, .type = ''DISP'' .nominal = 0) : ';
0846 opt = struct('type', 'DISP', 'nominal', 0);
0847 Pd = total_load(mpc, load_zone, opt);
0848 t_is(Pd, [area(3).disp.p; area(1).disp.p], 12, [t 'Pd']);
0849 
0850 t = '[Pd, Qd] = total_load(mpc, ld_zone2, .type = ''DISPATCHABLE'') : ';
0851 opt = struct('type', 'DISPATCHABLE');
0852 [Pd, Qd] = total_load(mpc, load_zone, opt);
0853 t_is(Pd, [area(3).disp.p; area(1).disp.p], 12, [t 'Pd']);
0854 t_is(Qd, [area(3).disp.q; area(1).disp.q], 12, [t 'Qd']);
0855 
0856 t = '[Pd, Qd] = total_load(mpc, ld_zone2, .type = ''DISP'' .nominal = 1) : ';
0857 opt = struct('type', 'DISP', 'nominal', 1);
0858 [Pd, Qd] = total_load(mpc, load_zone, opt);
0859 t_is(Pd, [area(3).disp.pnom; area(1).disp.pnom], 12, [t 'Pd']);
0860 t_is(Qd, [area(3).disp.qnom; area(1).disp.qnom], 12, [t 'Qd']);
0861 
0862 t = '[Pd, Qd] = total_load(mpc, ld_zone2, .type = ''DISP'' .nominal = 0) : ';
0863 opt = struct('type', 'DISP', 'nominal', 0);
0864 [Pd, Qd] = total_load(mpc, load_zone, opt);
0865 t_is(Pd, [area(3).disp.p; area(1).disp.p], 12, [t 'Pd']);
0866 t_is(Qd, [area(3).disp.q; area(1).disp.q], 12, [t 'Qd']);
0867 
0868 %%-----  old DEPRECATED string options, below  -----
0869 %%-----  all load  -----
0870 t = '      Pd = total_load(mpc, ''all'', ''BOTH'') : ';
0871 Pd = total_load(mpc, 'all', 'BOTH');
0872 t_is(Pd, total.both.pnom, 12, [t 'Pd']);
0873 
0874 t = '[Pd, Qd] = total_load(mpc, ''all'', ''BOTH'') : ';
0875 [Pd, Qd] = total_load(mpc, 'all', 'BOTH');
0876 t_is(Pd, total.both.pnom, 12, [t 'Pd']);
0877 t_is(Qd, total.both.qnom, 12, [t 'Qd']);
0878 
0879 t = '      Pd = total_load(mpc, ''all'', ''FIXED'') : ';
0880 Pd = total_load(mpc, 'all', 'FIXED');
0881 t_is(Pd, total.fixed.p, 12, [t 'Pd']);
0882 
0883 t = '[Pd, Qd] = total_load(mpc, ''all'', ''FIXED'') : ';
0884 [Pd, Qd] = total_load(mpc, 'all', 'FIXED');
0885 t_is(Pd, total.fixed.p, 12, [t 'Pd']);
0886 t_is(Qd, total.fixed.q, 12, [t 'Qd']);
0887 
0888 t = '      Pd = total_load(mpc, ''all'', ''DISPATCHABLE'') : ';
0889 Pd = total_load(mpc, 'all', 'DISPATCHABLE');
0890 t_is(Pd, total.disp.pnom, 12, [t 'Pd']);
0891 
0892 t = '[Pd, Qd] = total_load(mpc, ''all'', ''DISPATCHABLE'') : ';
0893 [Pd, Qd] = total_load(mpc, 'all', 'DISPATCHABLE');
0894 t_is(Pd, total.disp.pnom, 12, [t 'Pd']);
0895 t_is(Qd, total.disp.qnom, 12, [t 'Qd']);
0896 
0897 t = '      Pd = total_load(mpc, [], ''BOTH'') : ';
0898 Pd = total_load(mpc, [], 'BOTH');
0899 t_is(Pd, [area(1).both.pnom; area(2).both.pnom; area(3).both.pnom], 12, [t 'Pd']);
0900 
0901 t = '[Pd, Qd] = total_load(mpc, [], ''BOTH'') : ';
0902 [Pd, Qd] = total_load(mpc, [], 'BOTH');
0903 t_is(Pd, [area(1).both.pnom; area(2).both.pnom; area(3).both.pnom], 12, [t 'Pd']);
0904 t_is(Qd, [area(1).both.qnom; area(2).both.qnom; area(3).both.qnom], 12, [t 'Qd']);
0905 
0906 t = '      Pd = total_load(mpc, [], ''FIXED'') : ';
0907 Pd = total_load(mpc, [], 'FIXED');
0908 t_is(Pd, [area(1).fixed.p; area(2).fixed.p; area(3).fixed.p], 12, [t 'Pd']);
0909 
0910 t = '[Pd, Qd] = total_load(mpc, [], ''FIXED'') : ';
0911 [Pd, Qd] = total_load(mpc, [], 'FIXED');
0912 t_is(Pd, [area(1).fixed.p; area(2).fixed.p; area(3).fixed.p], 12, [t 'Pd']);
0913 t_is(Qd, [area(1).fixed.q; area(2).fixed.q; area(3).fixed.q], 12, [t 'Qd']);
0914 
0915 t = '      Pd = total_load(mpc, [], ''DISPATCHABLE'') : ';
0916 Pd = total_load(mpc, [], 'DISPATCHABLE');
0917 t_is(Pd, [area(1).disp.pnom; area(2).disp.pnom; area(3).disp.pnom], 12, [t 'Pd']);
0918 
0919 t = '[Pd, Qd] = total_load(mpc, [], ''DISPATCHABLE'') : ';
0920 [Pd, Qd] = total_load(mpc, [], 'DISPATCHABLE');
0921 t_is(Pd, [area(1).disp.pnom; area(2).disp.pnom; area(3).disp.pnom], 12, [t 'Pd']);
0922 t_is(Qd, [area(1).disp.qnom; area(2).disp.qnom; area(3).disp.qnom], 12, [t 'Qd']);
0923 
0924 %%-----  explicit single load zone  -----
0925 nb = size(mpc.bus, 1);
0926 load_zone = zeros(nb, 1);
0927 k = find(mpc.bus(:, BUS_AREA) == 1);    %% area 1
0928 load_zone(k) = 1;
0929 t = '      Pd = total_load(mpc, ld_zone1, ''BOTH'') : ';
0930 Pd = total_load(mpc, load_zone, 'BOTH');
0931 t_is(Pd, area(1).both.pnom, 12, [t 'Pd']);
0932 
0933 t = '[Pd, Qd] = total_load(mpc, ld_zone1, ''BOTH'') : ';
0934 [Pd, Qd] = total_load(mpc, load_zone, 'BOTH');
0935 t_is(Pd, area(1).both.pnom, 12, [t 'Pd']);
0936 t_is(Qd, area(1).both.qnom, 12, [t 'Qd']);
0937 
0938 t = '      Pd = total_load(mpc, ld_zone1, ''FIXED'') : ';
0939 Pd = total_load(mpc, load_zone, 'FIXED');
0940 t_is(Pd, area(1).fixed.p, 12, [t 'Pd']);
0941 
0942 t = '[Pd, Qd] = total_load(mpc, ld_zone1, ''FIXED'') : ';
0943 [Pd, Qd] = total_load(mpc, load_zone, 'FIXED');
0944 t_is(Pd, area(1).fixed.p, 12, [t 'Pd']);
0945 t_is(Qd, area(1).fixed.q, 12, [t 'Qd']);
0946 
0947 t = '      Pd = total_load(mpc, ld_zone1, ''DISPATCHABLE'') : ';
0948 Pd = total_load(mpc, load_zone, 'DISPATCHABLE');
0949 t_is(Pd, area(1).disp.pnom, 12, [t 'Pd']);
0950 
0951 t = '[Pd, Qd] = total_load(mpc, ld_zone1, ''DISPATCHABLE'') : ';
0952 [Pd, Qd] = total_load(mpc, load_zone, 'DISPATCHABLE');
0953 t_is(Pd, area(1).disp.pnom, 12, [t 'Pd']);
0954 t_is(Qd, area(1).disp.qnom, 12, [t 'Qd']);
0955 
0956 %%-----  explicit multiple load zone  -----
0957 load_zone = zeros(nb, 1);
0958 k = find(mpc.bus(:, BUS_AREA) == 3);    %% area 3
0959 load_zone(k) = 1;
0960 k = find(mpc.bus(:, BUS_AREA) == 1);    %% area 1
0961 load_zone(k) = 2;
0962 t = '      Pd = total_load(mpc, ld_zone2, ''BOTH'') : ';
0963 Pd = total_load(mpc, load_zone, 'BOTH');
0964 t_is(Pd, [area(3).both.pnom; area(1).both.pnom], 12, [t 'Pd']);
0965 
0966 t = '[Pd, Qd] = total_load(mpc, ld_zone2, ''BOTH'') : ';
0967 [Pd, Qd] = total_load(mpc, load_zone, 'BOTH');
0968 t_is(Pd, [area(3).both.pnom; area(1).both.pnom], 12, [t 'Pd']);
0969 t_is(Qd, [area(3).both.qnom; area(1).both.qnom], 12, [t 'Qd']);
0970 
0971 t = '      Pd = total_load(mpc, ld_zone2, ''FIXED'') : ';
0972 Pd = total_load(mpc, load_zone, 'FIXED');
0973 t_is(Pd, [area(3).fixed.p; area(1).fixed.p], 12, [t 'Pd']);
0974 
0975 t = '[Pd, Qd] = total_load(mpc, ld_zone2, ''FIXED'') : ';
0976 [Pd, Qd] = total_load(mpc, load_zone, 'FIXED');
0977 t_is(Pd, [area(3).fixed.p; area(1).fixed.p], 12, [t 'Pd']);
0978 t_is(Qd, [area(3).fixed.q; area(1).fixed.q], 12, [t 'Qd']);
0979 
0980 t = '      Pd = total_load(mpc, ld_zone2, ''DISPATCHABLE'') : ';
0981 Pd = total_load(mpc, load_zone, 'DISPATCHABLE');
0982 t_is(Pd, [area(3).disp.pnom; area(1).disp.pnom], 12, [t 'Pd']);
0983 
0984 t = '[Pd, Qd] = total_load(mpc, ld_zone2, ''DISPATCHABLE'') : ';
0985 [Pd, Qd] = total_load(mpc, load_zone, 'DISPATCHABLE');
0986 t_is(Pd, [area(3).disp.pnom; area(1).disp.pnom], 12, [t 'Pd']);
0987 t_is(Qd, [area(3).disp.qnom; area(1).disp.qnom], 12, [t 'Qd']);
0988 
0989 t_end;

Generated on Mon 24-Jun-2019 15:58:45 by m2html © 2005