Home > matpower5.1 > 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 %   Copyright (c) 2008-2015 by Power System Engineering Research Center (PSERC)
0006 %   by Ray Zimmerman, PSERC Cornell
0007 %
0008 %   $Id: t_scale_load.m 2644 2015-03-11 19:34:22Z ray $
0009 %
0010 %   This file is part of MATPOWER.
0011 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0012 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0013 
0014 if nargin < 1
0015     quiet = 0;
0016 end
0017 
0018 n_tests = 407;
0019 
0020 t_begin(n_tests, quiet);
0021 
0022 %% define named indices into data matrices
0023 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0024     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0025 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0026     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0027     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0028 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
0029 
0030 mpc = loadcase('t_auction_case');
0031 mpc.gen(8, GEN_BUS) = 2;    %% multiple d. loads per area, same bus as gen
0032 mpc.gen(8, [QG QMIN QMAX]) = [ 3 0 3 ];
0033 mpc.gencost(7, COST:end) = [-30 -600 -20 -300 -10 -100 0 0];    % 10, 20, 30
0034 mpc.gencost(8, COST:end) = [-30  -60 -20  -30 -10  -10 0 0];    % 1, 2, 3
0035 mpc.gencost(9, COST:end) = [-30 -850 -10 -250  -5  -50 0 0];    % 10, 20, 30
0036 %% put a load before gen in matrix
0037 mpc.gen = [mpc.gen(8, :); mpc.gen(1:7, :); mpc.gen(9, :)];
0038 mpc.gencost = [mpc.gencost(8, :); mpc.gencost(1:7, :); mpc.gencost(9, :)];
0039 gg = find(~isload(mpc.gen));
0040 ld = find( isload(mpc.gen));
0041 for k = 1:3
0042     a{k} = find(mpc.bus(:, BUS_AREA) == k); %% 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.p = -sum(mpc.gen(lda{k}, PMIN));
0050     area(k).disp.qmin = -sum(mpc.gen(lda{k}, QMIN));
0051     area(k).disp.qmax = -sum(mpc.gen(lda{k}, QMAX));
0052     area(k).disp.q = area(k).disp.qmin + area(k).disp.qmax;
0053     area(k).both.p = area(k).fixed.p + area(k).disp.p;
0054     area(k).both.q = area(k).fixed.q + area(k).disp.q;
0055 end
0056 total.fixed.p = sum(mpc.bus(:, PD));
0057 total.fixed.q = sum(mpc.bus(:, QD));
0058 total.disp.p = -sum(mpc.gen(ld, PMIN));
0059 total.disp.qmin = -sum(mpc.gen(ld, QMIN));
0060 total.disp.qmax = -sum(mpc.gen(ld, QMAX));
0061 total.disp.q = total.disp.qmin + total.disp.qmax;
0062 total.both.p = total.fixed.p + total.disp.p;
0063 total.both.q = total.fixed.q + total.disp.q;
0064 orig_gc = mpc.gencost;
0065 
0066 %%-----  single load zone, one scale factor  -----
0067 load = 2;
0068 t = 'all fixed loads (PQ) * 2 : ';
0069 bus = scale_load(load, mpc.bus);
0070 t_is(sum(bus(:, PD)), load*total.fixed.p, 8, [t 'total fixed P']);
0071 t_is(sum(bus(:, QD)), load*total.fixed.q, 8, [t 'total fixed Q']);
0072 opt = struct('which', 'FIXED');
0073 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0074 t_is(sum(bus(:, PD)), load*total.fixed.p, 8, [t 'total fixed P']);
0075 t_is(sum(bus(:, QD)), load*total.fixed.q, 8, [t 'total fixed Q']);
0076 t_is(-sum(gen(ld, PMIN)), total.disp.p, 8, [t 'total disp P']);
0077 t_is(-sum(gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0078 t_is(-sum(gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0079 
0080 t = 'all fixed loads (P) * 2 : ';
0081 opt = struct('pq', 'P');
0082 bus = scale_load(load, mpc.bus, [], [], opt);
0083 t_is(sum(bus(:, PD)), load*total.fixed.p, 8, [t 'total fixed P']);
0084 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0085 opt = struct('pq', 'P', 'which', 'FIXED');
0086 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0087 t_is(sum(bus(:, PD)), load*total.fixed.p, 8, [t 'total fixed P']);
0088 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0089 t_is(-sum(gen(ld, PMIN)), total.disp.p, 8, [t 'total disp P']);
0090 t_is(-sum(gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0091 t_is(-sum(gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0092 
0093 t = 'all loads (PQ) * 2 : ';
0094 [bus, gen] = scale_load(load, mpc.bus, mpc.gen);
0095 t_is(sum(bus(:, PD)), load*total.fixed.p, 8, [t 'total fixed P']);
0096 t_is(sum(bus(:, QD)), load*total.fixed.q, 8, [t 'total fixed Q']);
0097 t_is(-sum(gen(ld, PMIN)), load*total.disp.p, 8, [t 'total disp P']);
0098 t_is(-sum(gen(ld, QMIN)), load*total.disp.qmin, 8, [t 'total disp Qmin']);
0099 t_is(-sum(gen(ld, QMAX)), load*total.disp.qmax, 8, [t 'total disp Qmax']);
0100 
0101 t = 'all loads/costs (PQ) * 2 : ';
0102 [bus, gen, gencost] = scale_load(load, mpc.bus, mpc.gen, [], [], mpc.gencost);
0103 t_is(sum(bus(:, PD)), load*total.fixed.p, 8, [t 'total fixed P']);
0104 t_is(sum(bus(:, QD)), load*total.fixed.q, 8, [t 'total fixed Q']);
0105 t_is(-sum(gen(ld, PMIN)), load*total.disp.p, 8, [t 'total disp P']);
0106 t_is(-sum(gen(ld, QMIN)), load*total.disp.qmin, 8, [t 'total disp Qmin']);
0107 t_is(-sum(gen(ld, QMAX)), load*total.disp.qmax, 8, [t 'total disp Qmax']);
0108 t_is(gencost(gg, COST:end),   orig_gc(gg, COST:end), 8, [t 'gencost gens']);
0109 t_is(gencost(ld, COST:end), 2*orig_gc(ld, COST:end), 8, [t 'gencost loads']);
0110 
0111 t = 'all loads (P) * 2 : ';
0112 opt = struct('pq', 'P');
0113 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0114 t_is(sum(bus(:, PD)), load*total.fixed.p, 8, [t 'total fixed P']);
0115 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0116 t_is(-sum(gen(ld, PMIN)), load*total.disp.p, 8, [t 'total disp P']);
0117 t_is(-sum(gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0118 t_is(-sum(gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0119 
0120 t = 'all loads/costs (P) * 2 : ';
0121 opt = struct('pq', 'P');
0122 [bus, gen, gencost] = scale_load(load, mpc.bus, mpc.gen, [], opt, mpc.gencost);
0123 t_is(sum(bus(:, PD)), load*total.fixed.p, 8, [t 'total fixed P']);
0124 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0125 t_is(-sum(gen(ld, PMIN)), load*total.disp.p, 8, [t 'total disp P']);
0126 t_is(-sum(gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0127 t_is(-sum(gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0128 t_is(gencost(gg, COST:end),   orig_gc(gg, COST:end), 8, [t 'gencost gens']);
0129 t_is(gencost(ld, COST:end), 2*orig_gc(ld, COST:end), 8, [t 'gencost loads']);
0130 
0131 t = 'all disp loads (PQ) * 2 : ';
0132 opt = struct('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)), load*total.disp.qmin, 8, [t 'total disp Qmin']);
0138 t_is(-sum(gen(ld, QMAX)), load*total.disp.qmax, 8, [t 'total disp Qmax']);
0139 
0140 t = 'all disp loads/costs (PQ) * 2 : ';
0141 opt = struct('which', 'DISPATCHABLE');
0142 [bus, gen, gencost] = scale_load(load, mpc.bus, mpc.gen, [], opt, mpc.gencost);
0143 t_is(sum(bus(:, PD)), total.fixed.p, 8, [t 'total fixed P']);
0144 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0145 t_is(-sum(gen(ld, PMIN)), load*total.disp.p, 8, [t 'total disp P']);
0146 t_is(-sum(gen(ld, QMIN)), load*total.disp.qmin, 8, [t 'total disp Qmin']);
0147 t_is(-sum(gen(ld, QMAX)), load*total.disp.qmax, 8, [t 'total disp Qmax']);
0148 t_is(gencost(gg, COST:end),   orig_gc(gg, COST:end), 8, [t 'gencost gens']);
0149 t_is(gencost(ld, COST:end), 2*orig_gc(ld, COST:end), 8, [t 'gencost loads']);
0150 
0151 t = 'all disp loads (P) * 2 : ';
0152 opt = struct('pq', 'P', 'which', 'DISPATCHABLE');
0153 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0154 t_is(sum(bus(:, PD)), total.fixed.p, 8, [t 'total fixed P']);
0155 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0156 t_is(-sum(gen(ld, PMIN)), load*total.disp.p, 8, [t 'total disp P']);
0157 t_is(-sum(gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0158 t_is(-sum(gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0159 
0160 t = 'all disp loads/costs (P) * 2 : ';
0161 opt = struct('pq', 'P', 'which', 'DISPATCHABLE');
0162 [bus, gen, gencost] = scale_load(load, mpc.bus, mpc.gen, [], opt, mpc.gencost);
0163 t_is(sum(bus(:, PD)), total.fixed.p, 8, [t 'total fixed P']);
0164 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0165 t_is(-sum(gen(ld, PMIN)), load*total.disp.p, 8, [t 'total disp P']);
0166 t_is(-sum(gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0167 t_is(-sum(gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0168 t_is(gencost(gg, COST:end),   orig_gc(gg, COST:end), 8, [t 'gencost gens']);
0169 t_is(gencost(ld, COST:end), 2*orig_gc(ld, COST:end), 8, [t 'gencost loads']);
0170 
0171 %%-----  single load zone, one scale quantity  -----
0172 load = 200;
0173 t = 'all fixed loads (PQ) => total = 200 : ';
0174 opt = struct('scale', 'QUANTITY');
0175 bus = scale_load(load, mpc.bus, [], [], opt);
0176 t_is(sum(bus(:, PD)), load, 8, [t 'total fixed P']);
0177 t_is(sum(bus(:, QD)), load/total.fixed.p*total.fixed.q, 8, [t 'total fixed Q']);
0178 opt = struct('scale', 'QUANTITY', 'which', 'FIXED');
0179 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0180 t_is(sum(bus(:, PD)), load-total.disp.p, 8, [t 'total fixed P']);
0181 t_is(sum(bus(:, QD)), (load-total.disp.p)/total.fixed.p*total.fixed.q, 8, [t 'total fixed Q']);
0182 t_is(-sum(gen(ld, PMIN)), 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 fixed loads (P) => total = 200 : ';
0187 opt = struct('scale', 'QUANTITY', 'pq', 'P');
0188 bus = scale_load(load, mpc.bus, [], [], opt);
0189 t_is(sum(bus(:, PD)), load, 8, [t 'total fixed P']);
0190 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0191 opt = struct('scale', 'QUANTITY', 'pq', 'P', 'which', 'FIXED');
0192 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0193 t_is(sum(bus(:, PD)), load-total.disp.p, 8, [t 'total fixed P']);
0194 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0195 t_is(-sum(gen(ld, PMIN)), total.disp.p, 8, [t 'total disp P']);
0196 t_is(-sum(gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0197 t_is(-sum(gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0198 
0199 t = 'all loads (PQ) => total = 200 : ';
0200 opt = struct('scale', 'QUANTITY');
0201 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0202 t_is(sum(bus(:, PD)), load/total.both.p*total.fixed.p, 8, [t 'total fixed P']);
0203 t_is(sum(bus(:, QD)), load/total.both.p*total.fixed.q, 8, [t 'total fixed Q']);
0204 t_is(-sum(gen(ld, PMIN)), load/total.both.p*total.disp.p, 8, [t 'total disp P']);
0205 t_is(-sum(gen(ld, QMIN)), load/total.both.p*total.disp.qmin, 8, [t 'total disp Qmin']);
0206 t_is(-sum(gen(ld, QMAX)), load/total.both.p*total.disp.qmax, 8, [t 'total disp Qmax']);
0207 
0208 t = 'all loads/costs (PQ) => total = 200 : ';
0209 opt = struct('scale', 'QUANTITY');
0210 [bus, gen, gencost] = scale_load(load, mpc.bus, mpc.gen, [], opt, mpc.gencost);
0211 t_is(sum(bus(:, PD)), load/total.both.p*total.fixed.p, 8, [t 'total fixed P']);
0212 t_is(sum(bus(:, QD)), load/total.both.p*total.fixed.q, 8, [t 'total fixed Q']);
0213 t_is(-sum(gen(ld, PMIN)), load/total.both.p*total.disp.p, 8, [t 'total disp P']);
0214 t_is(-sum(gen(ld, QMIN)), load/total.both.p*total.disp.qmin, 8, [t 'total disp Qmin']);
0215 t_is(-sum(gen(ld, QMAX)), load/total.both.p*total.disp.qmax, 8, [t 'total disp Qmax']);
0216 t_is(gencost(gg, COST:end),   orig_gc(gg, COST:end), 8, [t 'gencost gens']);
0217 t_is(gencost(ld, COST:end), load/total.both.p*orig_gc(ld, COST:end), 8, [t 'gencost loads']);
0218 
0219 t = 'all loads (P) => total = 200 : ';
0220 opt = struct('scale', 'QUANTITY', 'pq', 'P');
0221 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0222 t_is(sum(bus(:, PD)), load/total.both.p*total.fixed.p, 8, [t 'total fixed P']);
0223 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0224 t_is(-sum(gen(ld, PMIN)), load/total.both.p*total.disp.p, 8, [t 'total disp P']);
0225 t_is(-sum(gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0226 t_is(-sum(gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0227 
0228 t = 'all loads/costs (P) => total = 200 : ';
0229 opt = struct('scale', 'QUANTITY', 'pq', 'P');
0230 [bus, gen, gencost] = scale_load(load, mpc.bus, mpc.gen, [], opt, mpc.gencost);
0231 t_is(sum(bus(:, PD)), load/total.both.p*total.fixed.p, 8, [t 'total fixed P']);
0232 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0233 t_is(-sum(gen(ld, PMIN)), load/total.both.p*total.disp.p, 8, [t 'total disp P']);
0234 t_is(-sum(gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0235 t_is(-sum(gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0236 t_is(gencost(gg, COST:end),   orig_gc(gg, COST:end), 8, [t 'gencost gens']);
0237 t_is(gencost(ld, COST:end), load/total.both.p*orig_gc(ld, COST:end), 8, [t 'gencost loads']);
0238 
0239 t = 'all disp loads (PQ) => total = 200 : ';
0240 opt = struct('scale', 'QUANTITY', 'which', 'DISPATCHABLE');
0241 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0242 t_is(sum(bus(:, PD)), total.fixed.p, 8, [t 'total fixed P']);
0243 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0244 t_is(-sum(gen(ld, PMIN)), load-total.fixed.p, 8, [t 'total disp P']);
0245 t_is(-sum(gen(ld, QMIN)), (load-total.fixed.p)/total.disp.p*total.disp.qmin, 8, [t 'total disp Qmin']);
0246 t_is(-sum(gen(ld, QMAX)), (load-total.fixed.p)/total.disp.p*total.disp.qmax, 8, [t 'total disp Qmax']);
0247 
0248 t = 'all disp loads/costs (PQ) => total = 200 : ';
0249 opt = struct('scale', 'QUANTITY', 'which', 'DISPATCHABLE');
0250 [bus, gen, gencost] = scale_load(load, mpc.bus, mpc.gen, [], opt, mpc.gencost);
0251 t_is(sum(bus(:, PD)), total.fixed.p, 8, [t 'total fixed P']);
0252 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0253 t_is(-sum(gen(ld, PMIN)), load-total.fixed.p, 8, [t 'total disp P']);
0254 t_is(-sum(gen(ld, QMIN)), (load-total.fixed.p)/total.disp.p*total.disp.qmin, 8, [t 'total disp Qmin']);
0255 t_is(-sum(gen(ld, QMAX)), (load-total.fixed.p)/total.disp.p*total.disp.qmax, 8, [t 'total disp Qmax']);
0256 t_is(gencost(gg, COST:end),   orig_gc(gg, COST:end), 8, [t 'gencost gens']);
0257 t_is(gencost(ld, COST:end), (load-total.fixed.p)/total.disp.p*orig_gc(ld, COST:end), 8, [t 'gencost loads']);
0258 
0259 t = 'all disp loads (P) => total = 200 : ';
0260 opt = struct('scale', 'QUANTITY', 'pq', 'P', 'which', 'DISPATCHABLE');
0261 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0262 t_is(sum(bus(:, PD)), total.fixed.p, 8, [t 'total fixed P']);
0263 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0264 t_is(-sum(gen(ld, PMIN)), load-total.fixed.p, 8, [t 'total disp P']);
0265 t_is(-sum(gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0266 t_is(-sum(gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0267 
0268 t = 'all disp loads/costs (P) => total = 200 : ';
0269 opt = struct('scale', 'QUANTITY', 'pq', 'P', 'which', 'DISPATCHABLE');
0270 [bus, gen, gencost] = scale_load(load, mpc.bus, mpc.gen, [], opt, mpc.gencost);
0271 t_is(sum(bus(:, PD)), total.fixed.p, 8, [t 'total fixed P']);
0272 t_is(sum(bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0273 t_is(-sum(gen(ld, PMIN)), load-total.fixed.p, 8, [t 'total disp P']);
0274 t_is(-sum(gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0275 t_is(-sum(gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0276 t_is(gencost(gg, COST:end),   orig_gc(gg, COST:end), 8, [t 'gencost gens']);
0277 t_is(gencost(ld, COST:end), (load-total.fixed.p)/total.disp.p*orig_gc(ld, COST:end), 8, [t 'gencost loads']);
0278 
0279 %%-----  3 zones, area scale factors  -----
0280 t = 'area fixed loads (PQ) * [3 2 1] : ';
0281 load = [3 2 1];
0282 bus = scale_load(load, mpc.bus);
0283 for k = 1:length(load)
0284     t_is(sum(bus(a{k}, PD)), load(k)*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0285     t_is(sum(bus(a{k}, QD)), load(k)*area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0286 end
0287 opt = struct('which', 'FIXED');
0288 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0289 for k = 1:length(load)
0290     t_is(sum(bus(a{k}, PD)), load(k)*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0291     t_is(sum(bus(a{k}, QD)), load(k)*area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0292     t_is(-sum(gen(lda{k}, PMIN)), area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
0293     t_is(-sum(gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0294     t_is(-sum(gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0295 end
0296 
0297 t = 'area fixed loads (P) * [3 2 1] : ';
0298 load = [3 2 1];
0299 opt = struct('pq', 'P');
0300 bus = scale_load(load, mpc.bus, [], [], opt);
0301 for k = 1:length(load)
0302     t_is(sum(bus(a{k}, PD)), load(k)*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0303     t_is(sum(bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0304 end
0305 opt = struct('pq', 'P', 'which', 'FIXED');
0306 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0307 for k = 1:length(load)
0308     t_is(sum(bus(a{k}, PD)), load(k)*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0309     t_is(sum(bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0310     t_is(-sum(gen(lda{k}, PMIN)), area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
0311     t_is(-sum(gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0312     t_is(-sum(gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0313 end
0314 
0315 t = 'all area loads (PQ) * [3 2 1] : ';
0316 [bus, gen] = scale_load(load, mpc.bus, mpc.gen);
0317 for k = 1:length(load)
0318     t_is(sum(bus(a{k}, PD)), load(k)*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0319     t_is(sum(bus(a{k}, QD)), load(k)*area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0320     t_is(-sum(gen(lda{k}, PMIN)), load(k)*area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
0321     t_is(-sum(gen(lda{k}, QMIN)), load(k)*area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0322     t_is(-sum(gen(lda{k}, QMAX)), load(k)*area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0323 end
0324 
0325 t = 'all area loads/costs (PQ) * [3 2 1] : ';
0326 [bus, gen, gencost] = scale_load(load, mpc.bus, mpc.gen, [], [], mpc.gencost);
0327 for k = 1:length(load)
0328     t_is(sum(bus(a{k}, PD)), load(k)*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0329     t_is(sum(bus(a{k}, QD)), load(k)*area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0330     t_is(-sum(gen(lda{k}, PMIN)), load(k)*area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
0331     t_is(-sum(gen(lda{k}, QMIN)), load(k)*area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0332     t_is(-sum(gen(lda{k}, QMAX)), load(k)*area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0333     t_is(gencost(lda{k}, COST:end), load(k)*orig_gc(lda{k}, COST:end), 8, sprintf('%s area %d gencost loads', t, k));
0334 end
0335 t_is(gencost(gg, COST:end), orig_gc(gg, COST:end), 8, sprintf('%s gencost gens', t));
0336 
0337 t = 'all area loads (P) * [3 2 1] : ';
0338 opt = struct('pq', 'P');
0339 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0340 for k = 1:length(load)
0341     t_is(sum(bus(a{k}, PD)), load(k)*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0342     t_is(sum(bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0343     t_is(-sum(gen(lda{k}, PMIN)), load(k)*area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
0344     t_is(-sum(gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0345     t_is(-sum(gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0346 end
0347 
0348 t = 'all area loads/costs (P) * [3 2 1] : ';
0349 opt = struct('pq', 'P');
0350 [bus, gen, gencost] = scale_load(load, mpc.bus, mpc.gen, [], opt, mpc.gencost);
0351 for k = 1:length(load)
0352     t_is(sum(bus(a{k}, PD)), load(k)*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0353     t_is(sum(bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0354     t_is(-sum(gen(lda{k}, PMIN)), load(k)*area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
0355     t_is(-sum(gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0356     t_is(-sum(gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0357     t_is(gencost(lda{k}, COST:end), load(k)*orig_gc(lda{k}, COST:end), 8, sprintf('%s area %d gencost loads', t, k));
0358 end
0359 t_is(gencost(gg, COST:end), orig_gc(gg, COST:end), 8, sprintf('%s gencost gens', t));
0360 
0361 t = 'area disp loads (PQ) * [3 2 1] : ';
0362 opt = struct('which', 'DISPATCHABLE');
0363 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0364 for k = 1:length(load)
0365     t_is(sum(bus(a{k}, PD)), area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0366     t_is(sum(bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0367     t_is(-sum(gen(lda{k}, PMIN)), load(k)*area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
0368     t_is(-sum(gen(lda{k}, QMIN)), load(k)*area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0369     t_is(-sum(gen(lda{k}, QMAX)), load(k)*area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0370 end
0371 
0372 t = 'area disp loads/costs (PQ) * [3 2 1] : ';
0373 opt = struct('which', 'DISPATCHABLE');
0374 [bus, gen, gencost] = scale_load(load, mpc.bus, mpc.gen, [], opt, mpc.gencost);
0375 for k = 1:length(load)
0376     t_is(sum(bus(a{k}, PD)), area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0377     t_is(sum(bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0378     t_is(-sum(gen(lda{k}, PMIN)), load(k)*area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
0379     t_is(-sum(gen(lda{k}, QMIN)), load(k)*area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0380     t_is(-sum(gen(lda{k}, QMAX)), load(k)*area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0381     t_is(gencost(lda{k}, COST:end), load(k)*orig_gc(lda{k}, COST:end), 8, sprintf('%s area %d gencost loads', t, k));
0382 end
0383 t_is(gencost(gg, COST:end), orig_gc(gg, COST:end), 8, sprintf('%s gencost gens', t));
0384 
0385 t = 'area disp loads (P) * [3 2 1] : ';
0386 opt = struct('pq', 'P', 'which', 'DISPATCHABLE');
0387 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0388 for k = 1:length(load)
0389     t_is(sum(bus(a{k}, PD)), area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0390     t_is(sum(bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0391     t_is(-sum(gen(lda{k}, PMIN)), load(k)*area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
0392     t_is(-sum(gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0393     t_is(-sum(gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0394 end
0395 
0396 t = 'area disp loads/costs (P) * [3 2 1] : ';
0397 opt = struct('pq', 'P', 'which', 'DISPATCHABLE');
0398 [bus, gen, gencost] = scale_load(load, mpc.bus, mpc.gen, [], opt, mpc.gencost);
0399 for k = 1:length(load)
0400     t_is(sum(bus(a{k}, PD)), area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0401     t_is(sum(bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0402     t_is(-sum(gen(lda{k}, PMIN)), load(k)*area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
0403     t_is(-sum(gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0404     t_is(-sum(gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0405     t_is(gencost(lda{k}, COST:end), load(k)*orig_gc(lda{k}, COST:end), 8, sprintf('%s area %d gencost loads', t, k));
0406 end
0407 t_is(gencost(gg, COST:end), orig_gc(gg, COST:end), 8, sprintf('%s gencost gens', t));
0408 
0409 %%-----  3 zones, area scale quantities  -----
0410 t = 'area fixed loads (PQ) => total = [100 80 60] : ';
0411 load = [100 80 60];
0412 opt = struct('scale', 'QUANTITY');
0413 bus = scale_load(load, mpc.bus, [], [], opt);
0414 for k = 1:length(load)
0415     t_is(sum(bus(a{k}, PD)), load(k), 8, sprintf('%s area %d fixed P', t, k));
0416     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));
0417 end
0418 opt = struct('scale', 'QUANTITY', 'which', 'FIXED');
0419 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0420 for k = 1:length(load)
0421     t_is(sum(bus(a{k}, PD)), load(k)-area(k).disp.p, 8, sprintf('%s area %d fixed P', t, k));
0422     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));
0423     t_is(-sum(gen(lda{k}, PMIN)), area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
0424     t_is(-sum(gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0425     t_is(-sum(gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0426 end
0427 
0428 t = 'area fixed loads (P) => total = [100 80 60] : ';
0429 load = [100 80 60];
0430 opt = struct('scale', 'QUANTITY', 'pq', 'P');
0431 bus = scale_load(load, mpc.bus, [], [], opt);
0432 for k = 1:length(load)
0433     t_is(sum(bus(a{k}, PD)), load(k), 8, sprintf('%s area %d fixed P', t, k));
0434     t_is(sum(bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0435 end
0436 opt = struct('scale', 'QUANTITY', 'pq', 'P', 'which', 'FIXED');
0437 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0438 for k = 1:length(load)
0439     t_is(sum(bus(a{k}, PD)), load(k)-area(k).disp.p, 8, sprintf('%s area %d fixed P', t, k));
0440     t_is(sum(bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0441     t_is(-sum(gen(lda{k}, PMIN)), area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
0442     t_is(-sum(gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0443     t_is(-sum(gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0444 end
0445 
0446 t = 'all area loads (PQ) => total = [100 80 60] : ';
0447 opt = struct('scale', 'QUANTITY');
0448 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0449 for k = 1:length(load)
0450     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));
0451     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));
0452     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));
0453     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));
0454     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));
0455 end
0456 
0457 t = 'all area loads (P) => total = [100 80 60] : ';
0458 opt = struct('scale', 'QUANTITY', 'pq', 'P');
0459 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0460 for k = 1:length(load)
0461     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));
0462     t_is(sum(bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0463     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));
0464     t_is(-sum(gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0465     t_is(-sum(gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0466 end
0467 
0468 t = 'area disp loads (PQ) => total = [100 80 60] : throws expected exception';
0469 load = [100 80 60];
0470 opt = struct('scale', 'QUANTITY', 'which', 'DISPATCHABLE');
0471 err = 0;
0472 try
0473     [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0474 catch
0475     [msg, id] = lasterr;
0476     expected = 'scale_load: impossible to make zone 2 load equal 80 by scaling non-existent dispatchable load';
0477     if ~isempty(findstr(expected, msg))
0478         err = 1;
0479     end
0480 end
0481 t_ok(err, t);
0482 
0483 t = 'area disp loads (PQ) => total = [100 74.3941 60] : ';
0484 load = [100 area(2).fixed.p 60];
0485 opt = struct('scale', 'QUANTITY', 'which', 'DISPATCHABLE');
0486 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0487 for k = 1:length(load)
0488     t_is(sum(bus(a{k}, PD)), area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0489     t_is(sum(bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0490     t_is(-sum(gen(lda{k}, PMIN)), load(k)-area(k).fixed.p, 8, sprintf('%s area %d disp P', t, k));
0491     if k == 2
0492         t_is(-sum(gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0493         t_is(-sum(gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0494     else
0495         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));
0496         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));
0497     end
0498 end
0499 
0500 t = 'area disp loads (P) => total = [100 74.3941 60] : ';
0501 opt = struct('scale', 'QUANTITY', 'pq', 'P', 'which', 'DISPATCHABLE');
0502 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, [], opt);
0503 for k = 1:length(load)
0504     t_is(sum(bus(a{k}, PD)), area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
0505     t_is(sum(bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
0506     t_is(-sum(gen(lda{k}, PMIN)), load(k)-area(k).fixed.p, 8, sprintf('%s area %d disp P', t, k));
0507     t_is(-sum(gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
0508     t_is(-sum(gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
0509 end
0510 
0511 %%-----  explict single load zone  -----
0512 t = 'explicit single load zone';
0513 load_zone = zeros(1, size(mpc.bus, 1));
0514 load_zone([3 4]) = 1;
0515 load = 2;
0516 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, load_zone);
0517 Pd = mpc.bus(:, PD);
0518 Pd([3 4]) = load * Pd([3 4]);
0519 t_is( bus(:, PD), Pd, 8, t);
0520 
0521 %%-----  explict multiple load zone  -----
0522 t = 'explicit multiple load zone';
0523 load_zone = zeros(1, size(mpc.bus, 1));
0524 load_zone([3 4]) = 1;
0525 load_zone([7 8]) = 2;
0526 load = [2 0.5];
0527 [bus, gen] = scale_load(load, mpc.bus, mpc.gen, load_zone);
0528 Pd = mpc.bus(:, PD);
0529 Pd([3 4]) = load(1) * Pd([3 4]);
0530 Pd([7 8]) = load(2) * Pd([7 8]);
0531 t_is( bus(:, PD), Pd, 8, t);
0532 
0533 t_end;

Generated on Fri 20-Mar-2015 18:23:34 by m2html © 2005