Home > matpower6.0 > t > t_loadcase.m

t_loadcase

PURPOSE ^

T_LOADCASE Test that LOADCASE works with a struct as well as case file.

SYNOPSIS ^

function t_loadcase(quiet)

DESCRIPTION ^

T_LOADCASE  Test that LOADCASE works with a struct as well as case file.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function t_loadcase(quiet)
0002 %T_LOADCASE  Test that LOADCASE works with a struct as well as case file.
0003 
0004 %   MATPOWER
0005 %   Copyright (c) 2004-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 http://www.pserc.cornell.edu/matpower/ for more info.
0011 
0012 if nargin < 1
0013     quiet = 0;
0014 end
0015 
0016 t_begin(240, quiet);
0017 
0018 %% compare result of loading from M-file file to result of using data matrices
0019 casefile = 't_case9_opf';
0020 matfile  = 't_mat9_opf';
0021 pfcasefile = 't_case9_pf';
0022 pfmatfile  = 't_mat9_pf';
0023 casefilev2 = 't_case9_opfv2';
0024 matfilev2  = 't_mat9_opfv2';
0025 pfcasefilev2 = 't_case9_pfv2';
0026 pfmatfilev2  = 't_mat9_pfv2';
0027 
0028 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0029     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0030 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0031     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0032     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0033 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0034     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0035     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0036 
0037 %% read version 1 OPF data matrices
0038 [baseMVA, bus, gen, branch, areas, gencost] = feval(casefile);
0039 %% save as .mat file
0040 eval(['save ' matfile '.mat baseMVA bus gen branch areas gencost']);
0041 
0042 %% read version 2 OPF data matrices
0043 mpc = feval(casefilev2);
0044 %% save as .mat file
0045 eval(['save ' matfilev2 '.mat mpc']);
0046 
0047 %% prepare expected matrices for v1 load
0048 %% (missing gen cap curve & branch ang diff lims)
0049 tmp1 = {mpc.baseMVA, mpc.bus, mpc.gen, mpc.branch, [1 5], mpc.gencost};
0050 tmp2 = {mpc.baseMVA, mpc.bus, mpc.gen, mpc.branch, [1 5], mpc.gencost};
0051 %% remove capability curves, angle difference limits
0052 tmp1{3}(2:3, [PC1, PC2, QC1MIN, QC1MAX, QC2MIN, QC2MAX]) = zeros(2,6);
0053 tmp1{4}(1, ANGMAX) = 360;
0054 tmp1{4}(9, ANGMIN) = -360;
0055 [baseMVA, bus, gen, branch, areas, gencost] = deal(tmp1{:});
0056 
0057 %%-----  load OPF data into individual matrices  -----
0058 t = 'loadcase(opf_M_file_v1) without .m extension : ';
0059 [baseMVA1, bus1, gen1, branch1, areas1, gencost1] = loadcase(casefile);
0060 t_is(baseMVA1,  baseMVA,    12, [t 'baseMVA']);
0061 t_is(bus1,      bus,        12, [t 'bus']);
0062 t_is(gen1,      gen,        12, [t 'gen']);
0063 t_is(branch1,   branch,     12, [t 'branch']);
0064 t_is(areas1,    areas,      12, [t 'areas']);
0065 t_is(gencost1,  gencost,    12, [t 'gencost']);
0066 
0067 t = 'loadcase(opf_M_file_v1) with .m extension : ';
0068 [baseMVA1, bus1, gen1, branch1, areas1, gencost1] = loadcase([casefile '.m']);
0069 t_is(baseMVA1,  baseMVA,    12, [t 'baseMVA']);
0070 t_is(bus1,      bus,        12, [t 'bus']);
0071 t_is(gen1,      gen,        12, [t 'gen']);
0072 t_is(branch1,   branch,     12, [t 'branch']);
0073 t_is(areas1,    areas,      12, [t 'areas']);
0074 t_is(gencost1,  gencost,    12, [t 'gencost']);
0075 
0076 t = 'loadcase(opf_MAT_file_v1) without .mat extension : ';
0077 [baseMVA1, bus1, gen1, branch1, areas1, gencost1] = loadcase(matfile);
0078 t_is(baseMVA1,  baseMVA,    12, [t 'baseMVA']);
0079 t_is(bus1,      bus,        12, [t 'bus']);
0080 t_is(gen1,      gen,        12, [t 'gen']);
0081 t_is(branch1,   branch,     12, [t 'branch']);
0082 t_is(areas1,    areas,      12, [t 'areas']);
0083 t_is(gencost1,  gencost,    12, [t 'gencost']);
0084 
0085 t = 'loadcase(opf_MAT_file_v1) with .mat extension : ';
0086 [baseMVA1, bus1, gen1, branch1, areas1, gencost1] = loadcase([matfile '.mat']);
0087 t_is(baseMVA1,  baseMVA,    12, [t 'baseMVA']);
0088 t_is(bus1,      bus,        12, [t 'bus']);
0089 t_is(gen1,      gen,        12, [t 'gen']);
0090 t_is(branch1,   branch,     12, [t 'branch']);
0091 t_is(areas1,    areas,      12, [t 'areas']);
0092 t_is(gencost1,  gencost,    12, [t 'gencost']);
0093 
0094 %% prepare expected matrices for v2 load
0095 [baseMVA, bus, gen, branch, areas, gencost] = deal(tmp2{:});
0096 areas = [];
0097 
0098 t = 'loadcase(opf_M_file_v2) without .m extension : ';
0099 [baseMVA1, bus1, gen1, branch1, areas1, gencost1] = loadcase(casefilev2);
0100 t_is(baseMVA1,  baseMVA,    12, [t 'baseMVA']);
0101 t_is(bus1,      bus,        12, [t 'bus']);
0102 t_is(gen1,      gen,        12, [t 'gen']);
0103 t_is(branch1,   branch,     12, [t 'branch']);
0104 t_is(areas1,    areas,      12, [t 'areas']);
0105 t_is(gencost1,  gencost,    12, [t 'gencost']);
0106 
0107 t = 'loadcase(opf_M_file_v2) with .m extension : ';
0108 [baseMVA1, bus1, gen1, branch1, areas1, gencost1] = loadcase([casefilev2 '.m']);
0109 t_is(baseMVA1,  baseMVA,    12, [t 'baseMVA']);
0110 t_is(bus1,      bus,        12, [t 'bus']);
0111 t_is(gen1,      gen,        12, [t 'gen']);
0112 t_is(branch1,   branch,     12, [t 'branch']);
0113 t_is(areas1,    areas,      12, [t 'areas']);
0114 t_is(gencost1,  gencost,    12, [t 'gencost']);
0115 
0116 t = 'loadcase(opf_MAT_file_v2) without .mat extension : ';
0117 [baseMVA1, bus1, gen1, branch1, areas1, gencost1] = loadcase(matfilev2);
0118 t_is(baseMVA1,  baseMVA,    12, [t 'baseMVA']);
0119 t_is(bus1,      bus,        12, [t 'bus']);
0120 t_is(gen1,      gen,        12, [t 'gen']);
0121 t_is(branch1,   branch,     12, [t 'branch']);
0122 t_is(areas1,    areas,      12, [t 'areas']);
0123 t_is(gencost1,  gencost,    12, [t 'gencost']);
0124 
0125 t = 'loadcase(opf_MAT_file_v2) with .mat extension : ';
0126 [baseMVA1, bus1, gen1, branch1, areas1, gencost1] = loadcase([matfilev2 '.mat']);
0127 t_is(baseMVA1,  baseMVA,    12, [t 'baseMVA']);
0128 t_is(bus1,      bus,        12, [t 'bus']);
0129 t_is(gen1,      gen,        12, [t 'gen']);
0130 t_is(branch1,   branch,     12, [t 'branch']);
0131 t_is(areas1,    areas,      12, [t 'areas']);
0132 t_is(gencost1,  gencost,    12, [t 'gencost']);
0133 
0134 %% prepare expected matrices for v1 load
0135 [baseMVA, bus, gen, branch, areas, gencost] = deal(tmp1{:});
0136 
0137 t = 'loadcase(opf_struct_v1) (no version): ';
0138 [baseMVA1, bus1, gen1, branch1, areas1, gencost1] = feval(casefile);
0139 clear c;
0140 c.baseMVA   = baseMVA1;
0141 c.bus       = bus1;
0142 c.gen       = gen1;
0143 c.branch    = branch1;
0144 c.areas     = areas1;
0145 c.gencost   = gencost1;
0146 [baseMVA2, bus2, gen2, branch2, areas2, gencost2] = loadcase(c);
0147 t_is(baseMVA2,  baseMVA,    12, [t 'baseMVA']);
0148 t_is(bus2,      bus,        12, [t 'bus']);
0149 t_is(gen2,      gen,        12, [t 'gen']);
0150 t_is(branch2,   branch,     12, [t 'branch']);
0151 t_is(areas2,    areas,      12, [t 'areas']);
0152 t_is(gencost2,  gencost,    12, [t 'gencost']);
0153 
0154 t = 'loadcase(opf_struct_v1) (version=''1''): ';
0155 c.version   = '1';
0156 [baseMVA2, bus2, gen2, branch2, areas2, gencost2] = loadcase(c);
0157 t_is(baseMVA2,  baseMVA,    12, [t 'baseMVA']);
0158 t_is(bus2,      bus,        12, [t 'bus']);
0159 t_is(gen2,      gen,        12, [t 'gen']);
0160 t_is(branch2,   branch,     12, [t 'branch']);
0161 t_is(areas2,    areas,      12, [t 'areas']);
0162 t_is(gencost2,  gencost,    12, [t 'gencost']);
0163 
0164 %% prepare expected matrices for v2 load
0165 [baseMVA, bus, gen, branch, areas, gencost] = deal(tmp2{:});
0166 
0167 t = 'loadcase(opf_struct_v2) (no version): ';
0168 clear c;
0169 c.baseMVA   = baseMVA;
0170 c.bus       = bus;
0171 c.gen       = gen;
0172 c.branch    = branch;
0173 c.areas     = areas;
0174 c.gencost   = gencost;
0175 [baseMVA2, bus2, gen2, branch2, areas2, gencost2] = loadcase(c);
0176 t_is(baseMVA2,  baseMVA,    12, [t 'baseMVA']);
0177 t_is(bus2,      bus,        12, [t 'bus']);
0178 t_is(gen2,      gen,        12, [t 'gen']);
0179 t_is(branch2,   branch,     12, [t 'branch']);
0180 t_is(areas2,    areas,      12, [t 'areas']);
0181 t_is(gencost2,  gencost,    12, [t 'gencost']);
0182 
0183 t = 'loadcase(opf_struct_v2) (version=''2''): ';
0184 clear c;
0185 c.baseMVA   = baseMVA;
0186 c.bus       = bus;
0187 c.gen       = gen;
0188 c.branch    = branch;
0189 c.areas     = areas;
0190 c.gencost   = gencost;
0191 c.version   = '2';
0192 [baseMVA2, bus2, gen2, branch2, areas2, gencost2] = loadcase(c);
0193 t_is(baseMVA2,  baseMVA,    12, [t 'baseMVA']);
0194 t_is(bus2,      bus,        12, [t 'bus']);
0195 t_is(gen2,      gen,        12, [t 'gen']);
0196 t_is(branch2,   branch,     12, [t 'branch']);
0197 t_is(areas2,    areas,      12, [t 'areas']);
0198 t_is(gencost2,  gencost,    12, [t 'gencost']);
0199 
0200 %%-----  load OPF data into struct  -----
0201 %% prepare expected matrices for v1 load
0202 [baseMVA, bus, gen, branch, areas, gencost] = deal(tmp1{:});
0203 
0204 t = 'mpc = loadcase(opf_M_file_v1) without .m extension : ';
0205 mpc1 = loadcase(casefile);
0206 t_is(mpc1.baseMVA,  baseMVA,    12, [t 'baseMVA']);
0207 t_is(mpc1.bus,      bus,        12, [t 'bus']);
0208 t_is(mpc1.gen,      gen,        12, [t 'gen']);
0209 t_is(mpc1.branch,   branch,     12, [t 'branch']);
0210 t_is(mpc1.areas,    areas,      12, [t 'areas']);
0211 t_is(mpc1.gencost,  gencost,    12, [t 'gencost']);
0212 
0213 t = 'mpc = loadcase(opf_M_file_v1) with .m extension : ';
0214 mpc1 = loadcase([casefile '.m']);
0215 t_is(mpc1.baseMVA,  baseMVA,    12, [t 'baseMVA']);
0216 t_is(mpc1.bus,      bus,        12, [t 'bus']);
0217 t_is(mpc1.gen,      gen,        12, [t 'gen']);
0218 t_is(mpc1.branch,   branch,     12, [t 'branch']);
0219 t_is(mpc1.areas,    areas,      12, [t 'areas']);
0220 t_is(mpc1.gencost,  gencost,    12, [t 'gencost']);
0221 
0222 t = 'mpc = loadcase(opf_MAT_file_v1) without .mat extension : ';
0223 mpc1 = loadcase(matfile);
0224 t_is(mpc1.baseMVA,  baseMVA,    12, [t 'baseMVA']);
0225 t_is(mpc1.bus,      bus,        12, [t 'bus']);
0226 t_is(mpc1.gen,      gen,        12, [t 'gen']);
0227 t_is(mpc1.branch,   branch,     12, [t 'branch']);
0228 t_is(mpc1.areas,    areas,      12, [t 'areas']);
0229 t_is(mpc1.gencost,  gencost,    12, [t 'gencost']);
0230 
0231 t = 'mpc = loadcase(opf_MAT_file_v1) with .mat extension : ';
0232 mpc1 = loadcase([matfile '.mat']);
0233 t_is(mpc1.baseMVA,  baseMVA,    12, [t 'baseMVA']);
0234 t_is(mpc1.bus,      bus,        12, [t 'bus']);
0235 t_is(mpc1.gen,      gen,        12, [t 'gen']);
0236 t_is(mpc1.branch,   branch,     12, [t 'branch']);
0237 t_is(mpc1.areas,    areas,      12, [t 'areas']);
0238 t_is(mpc1.gencost,  gencost,    12, [t 'gencost']);
0239 
0240 %% prepare expected matrices for v2 load
0241 [baseMVA, bus, gen, branch, areas, gencost] = deal(tmp2{:});
0242 
0243 t = 'mpc = loadcase(opf_M_file_v2) without .m extension : ';
0244 mpc1 = loadcase(casefilev2);
0245 t_is(mpc1.baseMVA,  baseMVA,    12, [t 'baseMVA']);
0246 t_is(mpc1.bus,      bus,        12, [t 'bus']);
0247 t_is(mpc1.gen,      gen,        12, [t 'gen']);
0248 t_is(mpc1.branch,   branch,     12, [t 'branch']);
0249 t_is(mpc1.gencost,  gencost,    12, [t 'gencost']);
0250 
0251 t = 'mpc = loadcase(opf_M_file_v2) with .m extension : ';
0252 mpc1 = loadcase([casefilev2 '.m']);
0253 t_is(mpc1.baseMVA,  baseMVA,    12, [t 'baseMVA']);
0254 t_is(mpc1.bus,      bus,        12, [t 'bus']);
0255 t_is(mpc1.gen,      gen,        12, [t 'gen']);
0256 t_is(mpc1.branch,   branch,     12, [t 'branch']);
0257 t_is(mpc1.gencost,  gencost,    12, [t 'gencost']);
0258 
0259 t = 'mpc = loadcase(opf_MAT_file_v2) without .mat extension : ';
0260 mpc1 = loadcase(matfilev2);
0261 t_is(mpc1.baseMVA,  baseMVA,    12, [t 'baseMVA']);
0262 t_is(mpc1.bus,      bus,        12, [t 'bus']);
0263 t_is(mpc1.gen,      gen,        12, [t 'gen']);
0264 t_is(mpc1.branch,   branch,     12, [t 'branch']);
0265 t_is(mpc1.gencost,  gencost,    12, [t 'gencost']);
0266 
0267 t = 'mpc = loadcase(opf_MAT_file_v2) with .mat extension : ';
0268 mpc1 = loadcase([matfilev2 '.mat']);
0269 t_is(mpc1.baseMVA,  baseMVA,    12, [t 'baseMVA']);
0270 t_is(mpc1.bus,      bus,        12, [t 'bus']);
0271 t_is(mpc1.gen,      gen,        12, [t 'gen']);
0272 t_is(mpc1.branch,   branch,     12, [t 'branch']);
0273 t_is(mpc1.gencost,  gencost,    12, [t 'gencost']);
0274 
0275 %% prepare expected matrices for v1 load
0276 [baseMVA, bus, gen, branch, areas, gencost] = deal(tmp1{:});
0277 
0278 t = 'mpc = loadcase(opf_struct_v1) (no version): ';
0279 [baseMVA1, bus1, gen1, branch1, areas1, gencost1] = feval(casefile);
0280 clear c;
0281 c.baseMVA   = baseMVA1;
0282 c.bus       = bus1;
0283 c.gen       = gen1;
0284 c.branch    = branch1;
0285 c.areas     = areas1;
0286 c.gencost   = gencost1;
0287 mpc2 = loadcase(c);
0288 t_is(mpc2.baseMVA,  baseMVA,    12, [t 'baseMVA']);
0289 t_is(mpc2.bus,      bus,        12, [t 'bus']);
0290 t_is(mpc2.gen,      gen,        12, [t 'gen']);
0291 t_is(mpc2.branch,   branch,     12, [t 'branch']);
0292 t_is(mpc2.areas,    areas,      12, [t 'areas']);
0293 t_is(mpc2.gencost,  gencost,    12, [t 'gencost']);
0294 
0295 t = 'mpc = loadcase(opf_struct_v1) (version=''1''): ';
0296 c.version   = '1';
0297 mpc2 = loadcase(c);
0298 t_is(mpc2.baseMVA,  baseMVA,    12, [t 'baseMVA']);
0299 t_is(mpc2.bus,      bus,        12, [t 'bus']);
0300 t_is(mpc2.gen,      gen,        12, [t 'gen']);
0301 t_is(mpc2.branch,   branch,     12, [t 'branch']);
0302 t_is(mpc2.areas,    areas,      12, [t 'areas']);
0303 t_is(mpc2.gencost,  gencost,    12, [t 'gencost']);
0304 
0305 %% prepare expected matrices for v2 load
0306 [baseMVA, bus, gen, branch, areas, gencost] = deal(tmp2{:});
0307 
0308 t = 'mpc = loadcase(opf_struct_v2) (no version): ';
0309 clear c;
0310 c.baseMVA   = baseMVA;
0311 c.bus       = bus;
0312 c.gen       = gen;
0313 c.branch    = branch;
0314 c.gencost   = gencost;
0315 mpc2 = loadcase(c);
0316 t_is(mpc2.baseMVA,  baseMVA,    12, [t 'baseMVA']);
0317 t_is(mpc2.bus,      bus,        12, [t 'bus']);
0318 t_is(mpc2.gen,      gen,        12, [t 'gen']);
0319 t_is(mpc2.branch,   branch,     12, [t 'branch']);
0320 t_is(mpc2.gencost,  gencost,    12, [t 'gencost']);
0321 t_ok(strcmp(mpc2.version, '2'), [t 'version']);  
0322 
0323 t = 'mpc = loadcase(opf_struct_v2) (version=''2''): ';
0324 clear c;
0325 c.baseMVA   = baseMVA;
0326 c.bus       = bus;
0327 c.gen       = gen;
0328 c.branch    = branch;
0329 c.gencost   = gencost;
0330 c.version   = '2';
0331 mpc2 = loadcase(c);
0332 t_is(mpc2.baseMVA,  baseMVA,    12, [t 'baseMVA']);
0333 t_is(mpc2.bus,      bus,        12, [t 'bus']);
0334 t_is(mpc2.gen,      gen,        12, [t 'gen']);
0335 t_is(mpc2.branch,   branch,     12, [t 'branch']);
0336 t_is(mpc2.gencost,  gencost,    12, [t 'gencost']);
0337 
0338 
0339 %% read version 1 PF data matrices
0340 [baseMVA, bus, gen, branch] = feval(pfcasefile);
0341 eval(['save ' pfmatfile '.mat baseMVA bus gen branch']);
0342 
0343 %% read version 2 PF data matrices
0344 mpc = feval(pfcasefilev2);
0345 tmp = {mpc.baseMVA, mpc.bus, mpc.gen, mpc.branch};
0346 [baseMVA, bus, gen, branch] = deal(tmp{:});
0347 %% save as .mat file
0348 eval(['save ' pfmatfilev2 '.mat mpc']);
0349 
0350 %%-----  load PF data into individual matrices  -----
0351 t = 'loadcase(pf_M_file_v1) without .m extension : ';
0352 [baseMVA1, bus1, gen1, branch1] = loadcase(pfcasefile);
0353 t_is(baseMVA1,  baseMVA,    12, [t 'baseMVA']);
0354 t_is(bus1,      bus,        12, [t 'bus']);
0355 t_is(gen1,      gen,        12, [t 'gen']);
0356 t_is(branch1,   branch,     12, [t 'branch']);
0357 
0358 t = 'loadcase(pf_M_file_v1) with .m extension : ';
0359 [baseMVA1, bus1, gen1, branch1] = loadcase([pfcasefile '.m']);
0360 t_is(baseMVA1,  baseMVA,    12, [t 'baseMVA']);
0361 t_is(bus1,      bus,        12, [t 'bus']);
0362 t_is(gen1,      gen,        12, [t 'gen']);
0363 t_is(branch1,   branch,     12, [t 'branch']);
0364 
0365 t = 'loadcase(pf_MAT_file_v1) without .mat extension : ';
0366 [baseMVA1, bus1, gen1, branch1] = loadcase(pfmatfile);
0367 t_is(baseMVA1,  baseMVA,    12, [t 'baseMVA']);
0368 t_is(bus1,      bus,        12, [t 'bus']);
0369 t_is(gen1,      gen,        12, [t 'gen']);
0370 t_is(branch1,   branch,     12, [t 'branch']);
0371 
0372 t = 'loadcase(pf_MAT_file_v1) with .mat extension : ';
0373 [baseMVA1, bus1, gen1, branch1] = loadcase([pfmatfile '.mat']);
0374 t_is(baseMVA1,  baseMVA,    12, [t 'baseMVA']);
0375 t_is(bus1,      bus,        12, [t 'bus']);
0376 t_is(gen1,      gen,        12, [t 'gen']);
0377 t_is(branch1,   branch,     12, [t 'branch']);
0378 
0379 t = 'loadcase(pf_M_file_v2) without .m extension : ';
0380 [baseMVA1, bus1, gen1, branch1] = loadcase(pfcasefilev2);
0381 t_is(baseMVA1,  baseMVA,    12, [t 'baseMVA']);
0382 t_is(bus1,      bus,        12, [t 'bus']);
0383 t_is(gen1,      gen,        12, [t 'gen']);
0384 t_is(branch1,   branch,     12, [t 'branch']);
0385 
0386 t = 'loadcase(pf_M_file_v2) with .m extension : ';
0387 [baseMVA1, bus1, gen1, branch1] = loadcase([pfcasefilev2 '.m']);
0388 t_is(baseMVA1,  baseMVA,    12, [t 'baseMVA']);
0389 t_is(bus1,      bus,        12, [t 'bus']);
0390 t_is(gen1,      gen,        12, [t 'gen']);
0391 t_is(branch1,   branch,     12, [t 'branch']);
0392 
0393 t = 'loadcase(pf_MAT_file_v2) without .mat extension : ';
0394 [baseMVA1, bus1, gen1, branch1] = loadcase(pfmatfilev2);
0395 t_is(baseMVA1,  baseMVA,    12, [t 'baseMVA']);
0396 t_is(bus1,      bus,        12, [t 'bus']);
0397 t_is(gen1,      gen,        12, [t 'gen']);
0398 t_is(branch1,   branch,     12, [t 'branch']);
0399 
0400 t = 'loadcase(pf_MAT_file_v2) with .mat extension : ';
0401 [baseMVA1, bus1, gen1, branch1] = loadcase([pfmatfilev2 '.mat']);
0402 t_is(baseMVA1,  baseMVA,    12, [t 'baseMVA']);
0403 t_is(bus1,      bus,        12, [t 'bus']);
0404 t_is(gen1,      gen,        12, [t 'gen']);
0405 t_is(branch1,   branch,     12, [t 'branch']);
0406 
0407 t = 'loadcase(pf_struct_v1) (no version): ';
0408 [baseMVA1, bus1, gen1, branch1] = feval(pfcasefile);
0409 clear c;
0410 c.baseMVA   = baseMVA1;
0411 c.bus       = bus1;
0412 c.gen       = gen1;
0413 c.branch    = branch1;
0414 [baseMVA2, bus2, gen2, branch2] = loadcase(c);
0415 t_is(baseMVA2,  baseMVA,    12, [t 'baseMVA']);
0416 t_is(bus2,      bus,        12, [t 'bus']);
0417 t_is(gen2,      gen,        12, [t 'gen']);
0418 t_is(branch2,   branch,     12, [t 'branch']);
0419 
0420 t = 'loadcase(pf_struct_v1) (version=''1''): ';
0421 c.version   = '1';
0422 [baseMVA2, bus2, gen2, branch2] = loadcase(c);
0423 t_is(baseMVA2,  baseMVA,    12, [t 'baseMVA']);
0424 t_is(bus2,      bus,        12, [t 'bus']);
0425 t_is(gen2,      gen,        12, [t 'gen']);
0426 t_is(branch2,   branch,     12, [t 'branch']);
0427 
0428 t = 'loadcase(pf_struct_v2) : ';
0429 clear c;
0430 c.baseMVA   = baseMVA;
0431 c.bus       = bus;
0432 c.gen       = gen;
0433 c.branch    = branch;
0434 c.version   = '2';
0435 [baseMVA2, bus2, gen2, branch2] = loadcase(c);
0436 t_is(baseMVA2,  baseMVA,    12, [t 'baseMVA']);
0437 t_is(bus2,      bus,        12, [t 'bus']);
0438 t_is(gen2,      gen,        12, [t 'gen']);
0439 t_is(branch2,   branch,     12, [t 'branch']);
0440 
0441 
0442 %%-----  load PF data into struct  -----
0443 t = 'mpc = loadcase(pf_M_file_v1) without .m extension : ';
0444 mpc1 = loadcase(pfcasefile);
0445 t_is(mpc1.baseMVA,  baseMVA,    12, [t 'baseMVA']);
0446 t_is(mpc1.bus,      bus,        12, [t 'bus']);
0447 t_is(mpc1.gen,      gen,        12, [t 'gen']);
0448 t_is(mpc1.branch,   branch,     12, [t 'branch']);
0449 
0450 t = 'mpc = loadcase(pf_M_file_v1) with .m extension : ';
0451 mpc1 = loadcase([pfcasefile '.m']);
0452 t_is(mpc1.baseMVA,  baseMVA,    12, [t 'baseMVA']);
0453 t_is(mpc1.bus,      bus,        12, [t 'bus']);
0454 t_is(mpc1.gen,      gen,        12, [t 'gen']);
0455 t_is(mpc1.branch,   branch,     12, [t 'branch']);
0456 
0457 t = 'mpc = loadcase(pf_MAT_file_v1) without .mat extension : ';
0458 mpc1 = loadcase(pfmatfile);
0459 t_is(mpc1.baseMVA,  baseMVA,    12, [t 'baseMVA']);
0460 t_is(mpc1.bus,      bus,        12, [t 'bus']);
0461 t_is(mpc1.gen,      gen,        12, [t 'gen']);
0462 t_is(mpc1.branch,   branch,     12, [t 'branch']);
0463 
0464 t = 'mpc = loadcase(pf_MAT_file_v1) with .mat extension : ';
0465 mpc1 = loadcase([pfmatfile '.mat']);
0466 t_is(mpc1.baseMVA,  baseMVA,    12, [t 'baseMVA']);
0467 t_is(mpc1.bus,      bus,        12, [t 'bus']);
0468 t_is(mpc1.gen,      gen,        12, [t 'gen']);
0469 t_is(mpc1.branch,   branch,     12, [t 'branch']);
0470 
0471 t = 'mpc = loadcase(pf_M_file_v2) without .m extension : ';
0472 mpc1 = loadcase(pfcasefilev2);
0473 t_is(mpc1.baseMVA,  baseMVA,    12, [t 'baseMVA']);
0474 t_is(mpc1.bus,      bus,        12, [t 'bus']);
0475 t_is(mpc1.gen,      gen,        12, [t 'gen']);
0476 t_is(mpc1.branch,   branch,     12, [t 'branch']);
0477 
0478 t = 'mpc = loadcase(pf_M_file_v2) with .m extension : ';
0479 mpc1 = loadcase([pfcasefilev2 '.m']);
0480 t_is(mpc1.baseMVA,  baseMVA,    12, [t 'baseMVA']);
0481 t_is(mpc1.bus,      bus,        12, [t 'bus']);
0482 t_is(mpc1.gen,      gen,        12, [t 'gen']);
0483 t_is(mpc1.branch,   branch,     12, [t 'branch']);
0484 
0485 t = 'mpc = loadcase(pf_MAT_file_v2) without .mat extension : ';
0486 mpc1 = loadcase(pfmatfilev2);
0487 t_is(mpc1.baseMVA,  baseMVA,    12, [t 'baseMVA']);
0488 t_is(mpc1.bus,      bus,        12, [t 'bus']);
0489 t_is(mpc1.gen,      gen,        12, [t 'gen']);
0490 t_is(mpc1.branch,   branch,     12, [t 'branch']);
0491 
0492 t = 'mpc = loadcase(pf_MAT_file_v2) with .mat extension : ';
0493 mpc1 = loadcase([pfmatfilev2 '.mat']);
0494 t_is(mpc1.baseMVA,  baseMVA,    12, [t 'baseMVA']);
0495 t_is(mpc1.bus,      bus,        12, [t 'bus']);
0496 t_is(mpc1.gen,      gen,        12, [t 'gen']);
0497 t_is(mpc1.branch,   branch,     12, [t 'branch']);
0498 
0499 t = 'mpc = loadcase(pf_struct_v1) (no version): ';
0500 [baseMVA1, bus1, gen1, branch1] = feval(pfcasefile);
0501 clear c;
0502 c.baseMVA   = baseMVA1;
0503 c.bus       = bus1;
0504 c.gen       = gen1;
0505 c.branch    = branch1;
0506 mpc2 = loadcase(c);
0507 t_is(mpc2.baseMVA,  baseMVA,    12, [t 'baseMVA']);
0508 t_is(mpc2.bus,      bus,        12, [t 'bus']);
0509 t_is(mpc2.gen,      gen,        12, [t 'gen']);
0510 t_is(mpc2.branch,   branch,     12, [t 'branch']);
0511 
0512 t = 'mpc = loadcase(pf_struct_v1) (version=''1''): ';
0513 c.version   = '1';
0514 mpc2 = loadcase(c);
0515 t_is(mpc2.baseMVA,  baseMVA,    12, [t 'baseMVA']);
0516 t_is(mpc2.bus,      bus,        12, [t 'bus']);
0517 t_is(mpc2.gen,      gen,        12, [t 'gen']);
0518 t_is(mpc2.branch,   branch,     12, [t 'branch']);
0519 
0520 t = 'mpc = loadcase(pf_struct_v2) : ';
0521 clear c;
0522 c.baseMVA   = baseMVA;
0523 c.bus       = bus;
0524 c.gen       = gen;
0525 c.branch    = branch;
0526 c.version   = '2';
0527 mpc2 = loadcase(c);
0528 t_is(mpc2.baseMVA,  baseMVA,    12, [t 'baseMVA']);
0529 t_is(mpc2.bus,      bus,        12, [t 'bus']);
0530 t_is(mpc2.gen,      gen,        12, [t 'gen']);
0531 t_is(mpc2.branch,   branch,     12, [t 'branch']);
0532 
0533 %% cleanup
0534 delete([ matfile '.mat' ]);
0535 delete([ pfmatfile '.mat' ]);
0536 delete([ matfilev2 '.mat' ]);
0537 delete([ pfmatfilev2 '.mat' ]);
0538 
0539 t = 'runpf(my_M_file)';
0540 mpopt = mpoption('verbose', 0, 'out.all', 0);
0541 [baseMVA3, bus3, gen3, branch3, success, et] = runpf(pfcasefile, mpopt);
0542 t_ok( success, t );
0543 
0544 t = 'runpf(my_struct)';
0545 [baseMVA4, bus4, gen4, branch4, success, et] = runpf(c, mpopt);
0546 t_ok( success, t );
0547 
0548 t = 'runpf result comparison : ';
0549 t_is(baseMVA3,  baseMVA4,   12, [t 'baseMVA']);
0550 t_is(bus3,      bus4,       12, [t 'bus']);
0551 t_is(gen3,      gen4,       12, [t 'gen']);
0552 t_is(branch3,   branch4,    12, [t 'branch']);
0553 
0554 t = 'runpf(modified_struct)';
0555 c.gen(3,2) = c.gen(3,2) + 1;            %% increase gen 3 output by 1
0556 [baseMVA5, bus5, gen5, branch5, success, et] = runpf(c, mpopt);
0557 t_is(gen5(1,2), gen4(1,2) - 1, 1, t);   %% slack bus output should decrease by 1
0558 
0559 %% $MATPOWER/t/t_loadcase should not be in path
0560 if exist('case_for_off_path_test') == 2
0561     warning('You have $MATPOWER/t/t_loadcase in your path. In general your path should not include sub-directories of $MATPOWER/t. While harmless, it does prevent this test from verifying the ability to load m-file cases that are outside your path.');
0562 end
0563 
0564 t = 'mpc = loadcase(<file not in path>) : ';
0565 % find path to t_mfile2fh.m
0566 cwd = pwd;
0567 [p, n, e] = fileparts(which('t_loadcase'));
0568 offpathcase = [p filesep 't_loadcase' filesep 'case_for_off_path_test'];
0569 mpc = loadcase(offpathcase);
0570 t_ok(strcmp(mpc.version, '2'), [t 'version']);
0571 t_is(mpc.baseMVA, 100, 15, [t 'baseMVA']);
0572 t_is(size(mpc.bus), [2 VMIN], 15, [t 'bus']);
0573 t_is(size(mpc.gen), [1 APF], 15, [t 'gen']);
0574 t_is(size(mpc.branch), [1 ANGMAX], 15, [t 'branch']);
0575 t_is(size(mpc.gencost), [1 7], 15, [t 'gencost']);
0576 
0577 t_end;

Generated on Fri 16-Dec-2016 12:45:37 by m2html © 2005