Home > matpower6.0 > most > loadstoragedata.m

loadstoragedata

PURPOSE ^

LOADSTORAGEDATA Load StorageData table into StorageData struct.

SYNOPSIS ^

function sd = loadstoragedata(sd_table, mpc)

DESCRIPTION ^

LOADSTORAGEDATA   Load StorageData table into StorageData struct.

   SD = LOADSTORAGEDATA(SD_TABLE)
   SD = LOADSTORAGEDATA(SD_TABLE, GEN)
   SD = LOADSTORAGEDATA(SD_TABLE, MPC)

   Loads data from a StorageData table struct, or from a M-file or MAT-file
   that returns such a struct, and converts it to a StorageData struct.
   StorageData contains all parameters required by MOST for storage
   units that is not included in MPC or xGenData.

   If the first argument is the name of an M-file the optional second
   argument will be passed to it. This can be useful for cases where
   the user wishes to use data from GEN or GENCOST to set values in the
   StorageData.

   Inputs:
       SD_TABLE : a StorageData table struct or the name of an M-file
                   or MAT-file that returns one, with the following fields
           .colnames : N dimensional cell array of names corresponding
               to the columns of the 'data' field. Valid column names
               are the same as the output field names. All columns are
               optional and the correpsonding defaults are listed
               next the output field names below.
           .data : (NS x N) matrix of data
           .MinStorageLevel                 (optional)     (scalar)
           .MaxStorageLevel                 (optional)     (scalar)
           .OutEff                          (optional)     (scalar)
           .InEff                           (optional)     (scalar)
           .LossFactor                      (optional)     (scalar)
           .rho                             (optional)     (scalar)
           (values in any of the scalar fields listed above are
            overridden by any corresponding values in the 'data' table)
       GEN : (optional) standard GEN matrix for generators corresponding
             to storage units in SD_TABLE
       MPC : (optional) MATPOWER case struct containing GEN and GENCOST
             matrices for generators corresponding to storage units in
             SD_TABLE

   Output:
       SD : a StorageData struct, contains the following fields,
               all of which are (NS x 1) vectors unless otherwise
               indicated. Defaults are as provided by MD_INIT.
           .UnitIdx                            (ns x 1)
           .ExpectedTerminalStorageAim         (ns x 1)
           .ExpectedTerminalStorageMin         (ns x 1)
           .ExpectedTerminalStorageMax         (ns x 1)
           .InitialStorage                     (ns x 1)
           .InitialStorageLowerBound           (ns x 1)
           .InitialStorageUpperBound           (ns x 1)
           .InitialStorageCost                 (ns x 1)
           .TerminalStoragePrice               (ns x 1)
           .TerminalChargingPrice0             (ns x 1)
           .TerminalDischargingPrice0          (ns x 1)
           .TerminalChargingPriceK             (ns x 1)
           .TerminalDischargingPriceK          (ns x 1)
           .MinStorageLevel                    (ns x 1) or (1 x 1)
           .MaxStorageLevel                    (ns x 1) or (1 x 1)
           .OutEff                             (ns x 1) or (1 x 1)
           .InEff                              (ns x 1) or (1 x 1)
           .LossFactor                         (ns x 1) or (1 x 1)
           .rho                                (ns x 1) or (1 x 1)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function sd = loadstoragedata(sd_table, mpc)
0002 %LOADSTORAGEDATA   Load StorageData table into StorageData struct.
0003 %
0004 %   SD = LOADSTORAGEDATA(SD_TABLE)
0005 %   SD = LOADSTORAGEDATA(SD_TABLE, GEN)
0006 %   SD = LOADSTORAGEDATA(SD_TABLE, MPC)
0007 %
0008 %   Loads data from a StorageData table struct, or from a M-file or MAT-file
0009 %   that returns such a struct, and converts it to a StorageData struct.
0010 %   StorageData contains all parameters required by MOST for storage
0011 %   units that is not included in MPC or xGenData.
0012 %
0013 %   If the first argument is the name of an M-file the optional second
0014 %   argument will be passed to it. This can be useful for cases where
0015 %   the user wishes to use data from GEN or GENCOST to set values in the
0016 %   StorageData.
0017 %
0018 %   Inputs:
0019 %       SD_TABLE : a StorageData table struct or the name of an M-file
0020 %                   or MAT-file that returns one, with the following fields
0021 %           .colnames : N dimensional cell array of names corresponding
0022 %               to the columns of the 'data' field. Valid column names
0023 %               are the same as the output field names. All columns are
0024 %               optional and the correpsonding defaults are listed
0025 %               next the output field names below.
0026 %           .data : (NS x N) matrix of data
0027 %           .MinStorageLevel                 (optional)     (scalar)
0028 %           .MaxStorageLevel                 (optional)     (scalar)
0029 %           .OutEff                          (optional)     (scalar)
0030 %           .InEff                           (optional)     (scalar)
0031 %           .LossFactor                      (optional)     (scalar)
0032 %           .rho                             (optional)     (scalar)
0033 %           (values in any of the scalar fields listed above are
0034 %            overridden by any corresponding values in the 'data' table)
0035 %       GEN : (optional) standard GEN matrix for generators corresponding
0036 %             to storage units in SD_TABLE
0037 %       MPC : (optional) MATPOWER case struct containing GEN and GENCOST
0038 %             matrices for generators corresponding to storage units in
0039 %             SD_TABLE
0040 %
0041 %   Output:
0042 %       SD : a StorageData struct, contains the following fields,
0043 %               all of which are (NS x 1) vectors unless otherwise
0044 %               indicated. Defaults are as provided by MD_INIT.
0045 %           .UnitIdx                            (ns x 1)
0046 %           .ExpectedTerminalStorageAim         (ns x 1)
0047 %           .ExpectedTerminalStorageMin         (ns x 1)
0048 %           .ExpectedTerminalStorageMax         (ns x 1)
0049 %           .InitialStorage                     (ns x 1)
0050 %           .InitialStorageLowerBound           (ns x 1)
0051 %           .InitialStorageUpperBound           (ns x 1)
0052 %           .InitialStorageCost                 (ns x 1)
0053 %           .TerminalStoragePrice               (ns x 1)
0054 %           .TerminalChargingPrice0             (ns x 1)
0055 %           .TerminalDischargingPrice0          (ns x 1)
0056 %           .TerminalChargingPriceK             (ns x 1)
0057 %           .TerminalDischargingPriceK          (ns x 1)
0058 %           .MinStorageLevel                    (ns x 1) or (1 x 1)
0059 %           .MaxStorageLevel                    (ns x 1) or (1 x 1)
0060 %           .OutEff                             (ns x 1) or (1 x 1)
0061 %           .InEff                              (ns x 1) or (1 x 1)
0062 %           .LossFactor                         (ns x 1) or (1 x 1)
0063 %           .rho                                (ns x 1) or (1 x 1)
0064 
0065 %   MOST
0066 %   Copyright (c) 2013-2016, Power Systems Engineering Research Center (PSERC)
0067 %   by Ray Zimmerman, PSERC Cornell
0068 %
0069 %   This file is part of MOST.
0070 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0071 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0072 
0073 %% define named indices into data matrices
0074 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0075     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0076     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0077 
0078 %% input arg handling
0079 if ischar(sd_table)
0080     infile = sprintf(' in file: ''%s''', sd_table);
0081 else
0082     infile = '';
0083 end
0084 if nargin < 2
0085     args = [];
0086     gen = [];
0087 else
0088     args = mpc;
0089     if isstruct(mpc)
0090         gen = mpc.gen;
0091     else
0092         gen = mpc;
0093     end
0094 end
0095 ns0 = size(gen, 1);      %% number of storage units in gen matrix
0096 
0097 %% load the table
0098 fields = {'colnames', 'data'};
0099 sdt = loadgenericdata(sd_table, 'struct', fields, 'sd_table', args);
0100 if isempty(sdt)
0101     sdt.colnames = {};
0102     sdt.data = [];
0103 end
0104 [ns, nc] = size(sdt.data);
0105 
0106 %% check consistency of dimensions of data table, colnames and gen
0107 if ns0 > 0 && ns > 0 && ns ~= ns0
0108     error('loadstoragedata: # of rows in ''data'' table (%d) do not equal rows in GEN (%d)%s', ...
0109         ns, ns0, infile);
0110 end
0111 if nc ~= length(sdt.colnames)
0112     error('loadstoragedata: # of columns in ''data'' table (%d) do match entries in ''colnames'' (%d)%s', ...
0113         nc, length(sdt.colnames), infile);
0114 end
0115 
0116 %% initialize storage data with default values from md_init's Storage field
0117 sd = getfield(md_init(), 'Storage');
0118 
0119 %% set individual fields
0120 f = {   'MinStorageLevel', ...
0121         'MaxStorageLevel', ...
0122         'OutEff', ...
0123         'InEff', ...
0124         'LossFactor', ...
0125         'rho'
0126     };
0127 for k = 1:length(f)
0128     if isfield(sd_table, f{k});
0129         sd.(f{k}) = sd_table.(f{k});
0130     end
0131 end
0132 
0133 %% create cell array with valid fields for checking
0134 valid_fields = {
0135         'UnitIdx', ...
0136         'ExpectedTerminalStorageAim', ...
0137         'ExpectedTerminalStorageMin', ...
0138         'ExpectedTerminalStorageMax', ...
0139         'InitialStorage', ...
0140         'InitialStorageLowerBound', ...
0141         'InitialStorageUpperBound', ...
0142         'InitialStorageCost', ...
0143         'TerminalStoragePrice', ...
0144         'TerminalChargingPrice0', ...
0145         'TerminalDischargingPrice0', ...
0146         'TerminalChargingPriceK', ...
0147         'TerminalDischargingPriceK', ...
0148         'MinStorageLevel', ...
0149         'MaxStorageLevel', ...
0150         'OutEff', ...
0151         'InEff', ...
0152         'LossFactor', ...
0153         'rho'
0154     };
0155 
0156 %% copy data from table
0157 for j = 1:nc
0158     %% check for valid colname
0159     if ~any(strcmp(sdt.colnames{j}, valid_fields))
0160         error('loadstoragedata: ''%s'' is not a valid StorageData field name%s', sdt.colnames{j}, infile);
0161     end
0162     %% copy data
0163     sd.(sdt.colnames{j}) = sdt.data(:, j);
0164 end

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