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

Generated on Mon 26-Jan-2015 15:21:31 by m2html © 2005