Home > matpower6.0 > most > loadxgendata.m

loadxgendata

PURPOSE ^

LOADXGENDATA Load xGenData table into xGenData struct.

SYNOPSIS ^

function xgd = loadxgendata(xgd_table, mpc)

DESCRIPTION ^

LOADXGENDATA   Load xGenData table into xGenData struct.

   XGD = LOADXGENDATA(XGD_TABLE)
   XGD = LOADXGENDATA(XGD_TABLE, GEN)
   XGD = LOADXGENDATA(XGD_TABLE, MPC)

   Loads data from an xGenData table struct, or from a function or MAT-file
   that returns such a struct, and converts it to an xGenData struct.
   xGenData contains all of the per-generator data required by MOST
   that is not included in MPC, including reserve offer data.

   If the first argument is the name of a function 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
   xGenData.

   Inputs:
       XGD_TABLE : an xGenData table struct or the name of a function
                   or MAT-file that returns one, with 2 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 corresponding defaults are listed
               next to the output field names below.
           .data : (NG x N) matrix of data
           If XGD_TABLE is empty, an xGenData struct will be created
           with default values (requires GEN or MPC).
       GEN : (optional) standard GEN matrix for generators corresponding
             to XGD_TABLE
       MPC : (optional) MATPOWER case struct containing GEN and GENCOST
             matrices for generators corresponding to XGD_TABLE

   Output:
       XGD :   an xGenData struct, contains the following fields,
               all of which are (NG x 1) vectors
           .CommitSched                        (default = C*)
               (if MPC or GEN not provided, default = 1)
           .InitialPg                          (default = GEN(:, PG))
               (only optional on input if MPC or GEN are provided)
           .TerminalPg (only included if provided in input)
           .RampWearCostCoeff                  (default = 0)
           .PositiveActiveReservePrice         (default = 0)
           .PositiveActiveReserveQuantity      (default = R*)
           .NegativeActiveReservePrice         (default = 0)
           .NegativeActiveReserveQuantity      (default = R*)
           .PositiveActiveDeltaPrice           (default = 0)
           .NegativeActiveDeltaPrice           (default = 0)
           .PositiveLoadFollowReservePrice     (default = 0)
           .PositiveLoadFollowReserveQuantity  (default = R*)
           .NegativeLoadFollowReservePrice     (default = 0)
           .NegativeLoadFollowReserveQuantity  (default = R*)
           .CommitKey                          (default = not present)
           .InitialState **                    (default = +/-Inf, based on C*)
           .MinUp **                           (default = 1)
           .MinDown **                         (default = 1)
               (potential future additions)
                   FuelType (would need to define numeric constants for each)

       * If GEN or MPC are provided then C = GEN(:, GEN_STATUS) and
         R = 2 * (GEN(:, PMAX) - MIN(0, GEN(:, PMIN))), otherwise
         C = 1 and R = Inf.
       ** Requires CommitKey be present and non-empty.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function xgd = loadxgendata(xgd_table, mpc)
0002 %LOADXGENDATA   Load xGenData table into xGenData struct.
0003 %
0004 %   XGD = LOADXGENDATA(XGD_TABLE)
0005 %   XGD = LOADXGENDATA(XGD_TABLE, GEN)
0006 %   XGD = LOADXGENDATA(XGD_TABLE, MPC)
0007 %
0008 %   Loads data from an xGenData table struct, or from a function or MAT-file
0009 %   that returns such a struct, and converts it to an xGenData struct.
0010 %   xGenData contains all of the per-generator data required by MOST
0011 %   that is not included in MPC, including reserve offer data.
0012 %
0013 %   If the first argument is the name of a function 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 %   xGenData.
0017 %
0018 %   Inputs:
0019 %       XGD_TABLE : an xGenData table struct or the name of a function
0020 %                   or MAT-file that returns one, with 2 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 corresponding defaults are listed
0025 %               next to the output field names below.
0026 %           .data : (NG x N) matrix of data
0027 %           If XGD_TABLE is empty, an xGenData struct will be created
0028 %           with default values (requires GEN or MPC).
0029 %       GEN : (optional) standard GEN matrix for generators corresponding
0030 %             to XGD_TABLE
0031 %       MPC : (optional) MATPOWER case struct containing GEN and GENCOST
0032 %             matrices for generators corresponding to XGD_TABLE
0033 %
0034 %   Output:
0035 %       XGD :   an xGenData struct, contains the following fields,
0036 %               all of which are (NG x 1) vectors
0037 %           .CommitSched                        (default = C*)
0038 %               (if MPC or GEN not provided, default = 1)
0039 %           .InitialPg                          (default = GEN(:, PG))
0040 %               (only optional on input if MPC or GEN are provided)
0041 %           .TerminalPg (only included if provided in input)
0042 %           .RampWearCostCoeff                  (default = 0)
0043 %           .PositiveActiveReservePrice         (default = 0)
0044 %           .PositiveActiveReserveQuantity      (default = R*)
0045 %           .NegativeActiveReservePrice         (default = 0)
0046 %           .NegativeActiveReserveQuantity      (default = R*)
0047 %           .PositiveActiveDeltaPrice           (default = 0)
0048 %           .NegativeActiveDeltaPrice           (default = 0)
0049 %           .PositiveLoadFollowReservePrice     (default = 0)
0050 %           .PositiveLoadFollowReserveQuantity  (default = R*)
0051 %           .NegativeLoadFollowReservePrice     (default = 0)
0052 %           .NegativeLoadFollowReserveQuantity  (default = R*)
0053 %           .CommitKey                          (default = not present)
0054 %           .InitialState **                    (default = +/-Inf, based on C*)
0055 %           .MinUp **                           (default = 1)
0056 %           .MinDown **                         (default = 1)
0057 %               (potential future additions)
0058 %                   FuelType (would need to define numeric constants for each)
0059 %
0060 %       * If GEN or MPC are provided then C = GEN(:, GEN_STATUS) and
0061 %         R = 2 * (GEN(:, PMAX) - MIN(0, GEN(:, PMIN))), otherwise
0062 %         C = 1 and R = Inf.
0063 %       ** Requires CommitKey be present and non-empty.
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(xgd_table)
0080     infile = sprintf(' in file: ''%s''', xgd_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 ng0 = size(gen, 1);      %% number of gens in gen matrix
0096 
0097 %% load the table
0098 fields = {'colnames', 'data'};
0099 xgdt = loadgenericdata(xgd_table, 'struct', fields, 'xgd_table', args);
0100 if isempty(xgdt)
0101     xgdt.colnames = {};
0102     xgdt.data = [];
0103 end
0104 [ng, nc] = size(xgdt.data);
0105 
0106 %% check consistency of dimensions of data table, colnames and gen
0107 if ng0 > 0 && ng > 0 && ng ~= ng0
0108     error('loadxgendata: # of rows in ''data'' table (%d) do not equal rows in GEN (%d)%s', ...
0109         ng, ng0, infile);
0110 end
0111 if nc ~= length(xgdt.colnames)
0112     error('loadxgendata: # of columns in ''data'' table (%d) do match entries in ''colnames'' (%d)%s', ...
0113         nc, length(xgdt.colnames), infile);
0114 end
0115 
0116 %% check for UC
0117 if any(strcmp('CommitKey', xgdt.colnames))
0118     UC = 1;
0119 else
0120     UC = 0;
0121 end
0122 
0123 %% initialize xGenData output struct with defaults
0124 if ng0 > 0
0125     C = gen(:, GEN_STATUS);
0126     Pg = gen(:, PG);
0127     R = 2 * (gen(:, PMAX) - min(0, gen(:, PMIN)));
0128     Z = zeros(ng0, 1);
0129     W = ones(ng0, 1);
0130 else
0131     C = ones(ng, 1);
0132     Pg = Z;
0133     R = Inf(ng, 1);
0134     Z = zeros(ng, 1);
0135     W = ones(ng, 1);
0136 end
0137 xgd = struct( ...
0138     'CommitSched',                          C, ...
0139     'InitialPg',                            Pg, ...
0140     'RampWearCostCoeff',                    Z, ...
0141     'PositiveActiveReservePrice',           Z, ...
0142     'PositiveActiveReserveQuantity',        R, ...
0143     'NegativeActiveReservePrice',           Z, ...
0144     'NegativeActiveReserveQuantity',        R, ...
0145     'PositiveActiveDeltaPrice',             Z, ...
0146     'NegativeActiveDeltaPrice',             Z, ...
0147     'PositiveLoadFollowReservePrice',       Z, ...
0148     'PositiveLoadFollowReserveQuantity',    R, ...
0149     'NegativeLoadFollowReservePrice',       Z, ...
0150     'NegativeLoadFollowReserveQuantity',    R ...
0151 );
0152 if UC
0153     xgd.CommitKey       = C;
0154     xgd.InitialState    = C;
0155     xgd.InitialState(C > 0)  =  Inf;
0156     xgd.InitialState(C <= 0) = -Inf;
0157     xgd.MinUp           = W;
0158     xgd.MinDown         = W;
0159 end
0160 
0161 %% create cell array with valid fields for checking
0162 valid_fields = fieldnames(xgd);
0163 valid_fields{end+1} = 'TerminalPg';
0164 valid_fields{end+1} = 'CommitKey';
0165 valid_fields{end+1} = 'InitialState';
0166 valid_fields{end+1} = 'MinUp';
0167 valid_fields{end+1} = 'MinDown';
0168 
0169 %% copy data from table
0170 for j = 1:nc
0171     %% check for valid colname
0172     if ~any(strcmp(xgdt.colnames{j}, valid_fields))
0173         error('loadxgendata: ''%s'' is not a valid xGenData field name%s', xgdt.colnames{j}, infile);
0174     end
0175     %% copy data
0176     xgd.(xgdt.colnames{j}) = xgdt.data(:, j);
0177 end

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