Home > matpower4.0 > t > t_scale_load.m

t_scale_load

PURPOSE ^

T_SCALE_LOAD Tests for code in SCALE_LOAD.

SYNOPSIS ^

function t_scale_load(quiet)

DESCRIPTION ^

T_SCALE_LOAD  Tests for code in SCALE_LOAD.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function t_scale_load(quiet)
0002 %T_SCALE_LOAD  Tests for code in SCALE_LOAD.
0003 
0004 %   MATPOWER
0005 %   $Id: t_scale_load.m,v 1.7 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 = 275;
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 %%-----  single load zone, one scale factor  -----
0079 load = 2;
0080 t = 'all fixed loads (PQ) * 2 : ';
0081 bus = scale_load(load, mpc.bus);
0082 t_is(sum(bus(:, PD)), load*total.fixed.p, 8, [t 'total fixed P']);
0083 t_is(sum(bus(:, QD)), load*total.fixed.q, 8, [t 'total fixed Q']);
0084 opt = struct('which', 'FIXED');
0085 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0086 t_is(sum(bus(:, PD)), load*total.fixed.p, 8, [t 'total fixed P']);
0087 t_is(sum(bus(:, QD)), load*total.fixed.q, 8, [t 'total fixed Q']);
0088 t_is(-sum(gen(ld, PMIN)), total.disp.p, 8, [t 'total disp P']);
0089 t_is(-sum(gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0090 t_is(-sum(gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0091 
0092 t = 'all fixed loads (P) * 2 : ';
0093 opt = struct('pq', 'P');
0094 bus = scale_load(load, mpc.bus, [], [], opt);
0095 t_is(sum(bus(:, PD)), load*total.fixed.p, 8, [t 'total fixed P']);
0096 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0097 opt = struct('pq', 'P', 'which', 'FIXED');
0098 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0099 t_is(sum(bus(:, PD)), load*total.fixed.p, 8, [t 'total fixed P']);
0100 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0101 t_is(-sum(gen(ld, PMIN)), total.disp.p, 8, [t 'total disp P']);
0102 t_is(-sum(gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0103 t_is(-sum(gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0104 
0105 t = 'all loads (PQ) * 2 : ';
0106 [bus, gen] = scale_load(load, mpc.bus, mpc.gen);
0107 t_is(sum(bus(:, PD)), load*total.fixed.p, 8, [t 'total fixed P']);
0108 t_is(sum(bus(:, QD)), load*total.fixed.q, 8, [t 'total fixed Q']);
0109 t_is(-sum(gen(ld, PMIN)), load*total.disp.p, 8, [t 'total disp P']);
0110 t_is(-sum(gen(ld, QMIN)), load*total.disp.qmin, 8, [t 'total disp Qmin']);
0111 t_is(-sum(gen(ld, QMAX)), load*total.disp.qmax, 8, [t 'total disp Qmax']);
0112 
0113 t = 'all loads (P) * 2 : ';
0114 opt = struct('pq', 'P');
0115 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0116 t_is(sum(bus(:, PD)), load*total.fixed.p, 8, [t 'total fixed P']);
0117 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0118 t_is(-sum(gen(ld, PMIN)), load*total.disp.p, 8, [t 'total disp P']);
0119 t_is(-sum(gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0120 t_is(-sum(gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0121 
0122 t = 'all disp loads (PQ) * 2 : ';
0123 opt = struct('which', 'DISPATCHABLE');
0124 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0125 t_is(sum(bus(:, PD)), total.fixed.p, 8, [t 'total fixed P']);
0126 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0127 t_is(-sum(gen(ld, PMIN)), load*total.disp.p, 8, [t 'total disp P']);
0128 t_is(-sum(gen(ld, QMIN)), load*total.disp.qmin, 8, [t 'total disp Qmin']);
0129 t_is(-sum(gen(ld, QMAX)), load*total.disp.qmax, 8, [t 'total disp Qmax']);
0130 
0131 t = 'all disp loads (P) * 2 : ';
0132 opt = struct('pq', 'P', 'which', 'DISPATCHABLE');
0133 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0134 t_is(sum(bus(:, PD)), total.fixed.p, 8, [t 'total fixed P']);
0135 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0136 t_is(-sum(gen(ld, PMIN)), load*total.disp.p, 8, [t 'total disp P']);
0137 t_is(-sum(gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0138 t_is(-sum(gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0139 
0140 %%-----  single load zone, one scale quantity  -----
0141 load = 200;
0142 t = 'all fixed loads (PQ) => total = 200 : ';
0143 opt = struct('scale', 'QUANTITY');
0144 bus = scale_load(load, mpc.bus, [], [], opt);
0145 t_is(sum(bus(:, PD)), load, 8, [t 'total fixed P']);
0146 t_is(sum(bus(:, QD)), load/total.fixed.p*total.fixed.q, 8, [t 'total fixed Q']);
0147 opt = struct('scale', 'QUANTITY', 'which', 'FIXED');
0148 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0149 t_is(sum(bus(:, PD)), load-total.disp.p, 8, [t 'total fixed P']);
0150 t_is(sum(bus(:, QD)), (load-total.disp.p)/total.fixed.p*total.fixed.q, 8, [t 'total fixed Q']);
0151 t_is(-sum(gen(ld, PMIN)), total.disp.p, 8, [t 'total disp P']);
0152 t_is(-sum(gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0153 t_is(-sum(gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0154 
0155 t = 'all fixed loads (P) => total = 200 : ';
0156 opt = struct('scale', 'QUANTITY', 'pq', 'P');
0157 bus = scale_load(load, mpc.bus, [], [], opt);
0158 t_is(sum(bus(:, PD)), load, 8, [t 'total fixed P']);
0159 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0160 opt = struct('scale', 'QUANTITY', 'pq', 'P', 'which', 'FIXED');
0161 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0162 t_is(sum(bus(:, PD)), load-total.disp.p, 8, [t 'total fixed P']);
0163 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0164 t_is(-sum(gen(ld, PMIN)), total.disp.p, 8, [t 'total disp P']);
0165 t_is(-sum(gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0166 t_is(-sum(gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0167 
0168 t = 'all loads (PQ) => total = 200 : ';
0169 opt = struct('scale', 'QUANTITY');
0170 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0171 t_is(sum(bus(:, PD)), load/total.both.p*total.fixed.p, 8, [t 'total fixed P']);
0172 t_is(sum(bus(:, QD)), load/total.both.p*total.fixed.q, 8, [t 'total fixed Q']);
0173 t_is(-sum(gen(ld, PMIN)), load/total.both.p*total.disp.p, 8, [t 'total disp P']);
0174 t_is(-sum(gen(ld, QMIN)), load/total.both.p*total.disp.qmin, 8, [t 'total disp Qmin']);
0175 t_is(-sum(gen(ld, QMAX)), load/total.both.p*total.disp.qmax, 8, [t 'total disp Qmax']);
0176 
0177 t = 'all loads (P) => total = 200 : ';
0178 opt = struct('scale', 'QUANTITY', 'pq', 'P');
0179 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0180 t_is(sum(bus(:, PD)), load/total.both.p*total.fixed.p, 8, [t 'total fixed P']);
0181 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0182 t_is(-sum(gen(ld, PMIN)), load/total.both.p*total.disp.p, 8, [t 'total disp P']);
0183 t_is(-sum(gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0184 t_is(-sum(gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0185 
0186 t = 'all disp loads (PQ) => total = 200 : ';
0187 opt = struct('scale', 'QUANTITY', 'which', 'DISPATCHABLE');
0188 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0189 t_is(sum(bus(:, PD)), total.fixed.p, 8, [t 'total fixed P']);
0190 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0191 t_is(-sum(gen(ld, PMIN)), load-total.fixed.p, 8, [t 'total disp P']);
0192 t_is(-sum(gen(ld, QMIN)), (load-total.fixed.p)/total.disp.p*total.disp.qmin, 8, [t 'total disp Qmin']);
0193 t_is(-sum(gen(ld, QMAX)), (load-total.fixed.p)/total.disp.p*total.disp.qmax, 8, [t 'total disp Qmax']);
0194 
0195 t = 'all disp loads (P) => total = 200 : ';
0196 opt = struct('scale', 'QUANTITY', 'pq', 'P', 'which', 'DISPATCHABLE');
0197 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0198 t_is(sum(bus(:, PD)), total.fixed.p, 8, [t 'total fixed P']);
0199 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0200 t_is(-sum(gen(ld, PMIN)), load-total.fixed.p, 8, [t 'total disp P']);
0201 t_is(-sum(gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0202 t_is(-sum(gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0203 
0204 %%-----  3 zones, area scale factors  -----
0205 t = 'area fixed loads (PQ) * [3 2 1] : ';
0206 load = [3 2 1];
0207 bus = scale_load(load, mpc.bus);
0208 for k = 1:length(load)
0209     t_is(sum(bus(a{k}, PD)), load(k)*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0210     t_is(sum(bus(a{k}, QD)), load(k)*area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0211 end
0212 opt = struct('which', 'FIXED');
0213 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0214 for k = 1:length(load)
0215     t_is(sum(bus(a{k}, PD)), load(k)*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0216     t_is(sum(bus(a{k}, QD)), load(k)*area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0217     t_is(-sum(gen(lda{k}, PMIN)), area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
0218     t_is(-sum(gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0219     t_is(-sum(gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0220 end
0221 
0222 t = 'area fixed loads (P) * [3 2 1] : ';
0223 load = [3 2 1];
0224 opt = struct('pq', 'P');
0225 bus = scale_load(load, mpc.bus, [], [], opt);
0226 for k = 1:length(load)
0227     t_is(sum(bus(a{k}, PD)), load(k)*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0228     t_is(sum(bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0229 end
0230 opt = struct('pq', 'P', 'which', 'FIXED');
0231 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0232 for k = 1:length(load)
0233     t_is(sum(bus(a{k}, PD)), load(k)*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0234     t_is(sum(bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0235     t_is(-sum(gen(lda{k}, PMIN)), area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
0236     t_is(-sum(gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0237     t_is(-sum(gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0238 end
0239 
0240 t = 'all area loads (PQ) * [3 2 1] : ';
0241 [bus, gen] = scale_load(load, mpc.bus, mpc.gen);
0242 for k = 1:length(load)
0243     t_is(sum(bus(a{k}, PD)), load(k)*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0244     t_is(sum(bus(a{k}, QD)), load(k)*area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0245     t_is(-sum(gen(lda{k}, PMIN)), load(k)*area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
0246     t_is(-sum(gen(lda{k}, QMIN)), load(k)*area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0247     t_is(-sum(gen(lda{k}, QMAX)), load(k)*area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0248 end
0249 
0250 t = 'all area loads (P) * [3 2 1] : ';
0251 opt = struct('pq', 'P');
0252 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0253 for k = 1:length(load)
0254     t_is(sum(bus(a{k}, PD)), load(k)*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0255     t_is(sum(bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0256     t_is(-sum(gen(lda{k}, PMIN)), load(k)*area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
0257     t_is(-sum(gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0258     t_is(-sum(gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0259 end
0260 
0261 t = 'area disp loads (PQ) * [3 2 1] : ';
0262 opt = struct('which', 'DISPATCHABLE');
0263 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0264 for k = 1:length(load)
0265     t_is(sum(bus(a{k}, PD)), area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0266     t_is(sum(bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0267     t_is(-sum(gen(lda{k}, PMIN)), load(k)*area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
0268     t_is(-sum(gen(lda{k}, QMIN)), load(k)*area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0269     t_is(-sum(gen(lda{k}, QMAX)), load(k)*area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0270 end
0271 
0272 t = 'area disp loads (P) * [3 2 1] : ';
0273 opt = struct('pq', 'P', 'which', 'DISPATCHABLE');
0274 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0275 for k = 1:length(load)
0276     t_is(sum(bus(a{k}, PD)), area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0277     t_is(sum(bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0278     t_is(-sum(gen(lda{k}, PMIN)), load(k)*area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
0279     t_is(-sum(gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0280     t_is(-sum(gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0281 end
0282 
0283 %%-----  3 zones, area scale quantities  -----
0284 t = 'area fixed loads (PQ) => total = [100 80 60] : ';
0285 load = [100 80 60];
0286 opt = struct('scale', 'QUANTITY');
0287 bus = scale_load(load, mpc.bus, [], [], opt);
0288 for k = 1:length(load)
0289     t_is(sum(bus(a{k}, PD)), load(k), 8, sprintf('%s area %d fixed P', t, k));
0290     t_is(sum(bus(a{k}, QD)), load(k)/area(k).fixed.p*area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0291 end
0292 opt = struct('scale', 'QUANTITY', 'which', 'FIXED');
0293 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0294 for k = 1:length(load)
0295     t_is(sum(bus(a{k}, PD)), load(k)-area(k).disp.p, 8, sprintf('%s area %d fixed P', t, k));
0296     t_is(sum(bus(a{k}, QD)), (load(k)-area(k).disp.p)/area(k).fixed.p*area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0297     t_is(-sum(gen(lda{k}, PMIN)), area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
0298     t_is(-sum(gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0299     t_is(-sum(gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0300 end
0301 
0302 t = 'area fixed loads (P) => total = [100 80 60] : ';
0303 load = [100 80 60];
0304 opt = struct('scale', 'QUANTITY', 'pq', 'P');
0305 bus = scale_load(load, mpc.bus, [], [], opt);
0306 for k = 1:length(load)
0307     t_is(sum(bus(a{k}, PD)), load(k), 8, sprintf('%s area %d fixed P', t, k));
0308     t_is(sum(bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0309 end
0310 opt = struct('scale', 'QUANTITY', 'pq', 'P', 'which', 'FIXED');
0311 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0312 for k = 1:length(load)
0313     t_is(sum(bus(a{k}, PD)), load(k)-area(k).disp.p, 8, sprintf('%s area %d fixed P', t, k));
0314     t_is(sum(bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0315     t_is(-sum(gen(lda{k}, PMIN)), area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
0316     t_is(-sum(gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0317     t_is(-sum(gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0318 end
0319 
0320 t = 'all area loads (PQ) => total = [100 80 60] : ';
0321 opt = struct('scale', 'QUANTITY');
0322 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0323 for k = 1:length(load)
0324     t_is(sum(bus(a{k}, PD)), load(k)/area(k).both.p*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0325     t_is(sum(bus(a{k}, QD)), load(k)/area(k).both.p*area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0326     t_is(-sum(gen(lda{k}, PMIN)), load(k)/area(k).both.p*area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
0327     t_is(-sum(gen(lda{k}, QMIN)), load(k)/area(k).both.p*area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0328     t_is(-sum(gen(lda{k}, QMAX)), load(k)/area(k).both.p*area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0329 end
0330 
0331 t = 'all area loads (P) => total = [100 80 60] : ';
0332 opt = struct('scale', 'QUANTITY', 'pq', 'P');
0333 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0334 for k = 1:length(load)
0335     t_is(sum(bus(a{k}, PD)), load(k)/area(k).both.p*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0336     t_is(sum(bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0337     t_is(-sum(gen(lda{k}, PMIN)), load(k)/area(k).both.p*area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
0338     t_is(-sum(gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0339     t_is(-sum(gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0340 end
0341 
0342 t = 'area disp loads (PQ) => total = [100 80 60] : throws expected exception';
0343 load = [100 80 60];
0344 opt = struct('scale', 'QUANTITY', 'which', 'DISPATCHABLE');
0345 err = 0;
0346 try
0347     [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0348 catch
0349     [msg, id] = lasterr;
0350     expected = 'scale_load: impossible to make zone 2 load equal 80 by scaling non-existent dispatchable load';
0351     if ~isempty(findstr(expected, msg))
0352         err = 1;
0353     end
0354 end
0355 t_ok(err, t);
0356 
0357 t = 'area disp loads (PQ) => total = [100 74.3941 60] : ';
0358 load = [100 area(2).fixed.p 60];
0359 opt = struct('scale', 'QUANTITY', 'which', 'DISPATCHABLE');
0360 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0361 for k = 1:length(load)
0362     t_is(sum(bus(a{k}, PD)), area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0363     t_is(sum(bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0364     t_is(-sum(gen(lda{k}, PMIN)), load(k)-area(k).fixed.p, 8, sprintf('%s area %d disp P', t, k));
0365     if k == 2
0366         t_is(-sum(gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0367         t_is(-sum(gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0368     else
0369         t_is(-sum(gen(lda{k}, QMIN)), (load(k)-area(k).fixed.p)/area(k).disp.p*area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0370         t_is(-sum(gen(lda{k}, QMAX)), (load(k)-area(k).fixed.p)/area(k).disp.p*area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0371     end
0372 end
0373 
0374 t = 'area disp loads (P) => total = [100 74.3941 60] : ';
0375 opt = struct('scale', 'QUANTITY', 'pq', 'P', 'which', 'DISPATCHABLE');
0376 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0377 for k = 1:length(load)
0378     t_is(sum(bus(a{k}, PD)), area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0379     t_is(sum(bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0380     t_is(-sum(gen(lda{k}, PMIN)), load(k)-area(k).fixed.p, 8, sprintf('%s area %d disp P', t, k));
0381     t_is(-sum(gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0382     t_is(-sum(gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0383 end
0384 
0385 %%-----  explict single load zone  -----
0386 t = 'explicit single load zone';
0387 load_zone = zeros(1, size(mpc.bus, 1));
0388 load_zone([3 4]) = 1;
0389 load = 2;
0390 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, load_zone);
0391 Pd = mpc.bus(:, PD);
0392 Pd([3 4]) = load * Pd([3 4]);
0393 t_is( bus(:, PD), Pd, 8, t);
0394 
0395 %%-----  explict multiple load zone  -----
0396 t = 'explicit multiple load zone';
0397 load_zone = zeros(1, size(mpc.bus, 1));
0398 load_zone([3 4]) = 1;
0399 load_zone([7 8]) = 2;
0400 load = [2 0.5];
0401 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, load_zone);
0402 Pd = mpc.bus(:, PD);
0403 Pd([3 4]) = load(1) * Pd([3 4]);
0404 Pd([7 8]) = load(2) * Pd([7 8]);
0405 t_is( bus(:, PD), Pd, 8, t);
0406 
0407 t_end;

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