Home > matpower7.1 > most > lib > addstorage.m

addstorage

PURPOSE ^

ADDWIND Adds storage units and corresponding xGen/StorageData to existing data.

SYNOPSIS ^

function [idx, new_mpc, new_xgd, new_sd] = addstorage(storage, mpc, xgd, sd)

DESCRIPTION ^

ADDWIND   Adds storage units and corresponding xGen/StorageData to existing data.

   [IDX, NEW_MPC] = ADDSTORAGE(STORAGE, MPC)
   [IDX, NEW_MPC, NEW_XGD, NEW_SD] = ADDSTORAGE(STORAGE, MPC)
   [IDX, NEW_MPC, NEW_XGD, NEW_SD] = ADDSTORAGE(STORAGE, MPC, XGD)
   [IDX, NEW_MPC, NEW_XGD, NEW_SD] = ADDSTORAGE(STORAGE, MPC, XGD, SD)

   Given a StorageUnitData structure, or the name of a file containing such
   a structure, this function adds the specified storage generators to an
   existing MATPOWER case, xGenData struct and StorageData struct.

   Inputs:
       STORAGE : a StorageUnitData struct or the name of an M-file
                   or MAT-file that returns one, with the following fields
           .gen     : rows to be appended to the GEN matrix from MPC
           .gencost : (optional) rows to be added to the GENCOST matrix
                      from MPC, default is zero cost
           .xgd_table : xGenData table struct or filename providing data for
                        the storage units being added. See LOADSTORAGEDATA
                        for more information on the xGenData table format.
           .sd_table : StorageData table struct or filename providing data
                       for the storage units being added. See LOADSTORAGEDATA
                       for more information on the StorageData table format.
       MPC : MATPOWER case struct to which storage generators will be added
       XGD : (optional) xGenData struct corresponding to the generators
             already in MPC, to which the new xGenData for the storage
             units will be added.
       SD : (optional) StorageData struct corresponding to the generators
            already in MPC, to which the new StorageData for the storage
            units will be added.

   Output:
       IDX : Generator indices of newly added storage units.
       NEW_MPC : MPC with storage units appended to MPC.GEN and MPC.GENCOST
                 MPC.GENFUEL (= 'ess').
       NEW_XGD : XGD with xGenData for new storage units appended.
       NEW_SD  : SD with StorageData for new storage units appended.

   See also LOADSTORAGEDATA, LOADXGENDATA.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [idx, new_mpc, new_xgd, new_sd] = addstorage(storage, mpc, xgd, sd)
0002 %ADDWIND   Adds storage units and corresponding xGen/StorageData to existing data.
0003 %
0004 %   [IDX, NEW_MPC] = ADDSTORAGE(STORAGE, MPC)
0005 %   [IDX, NEW_MPC, NEW_XGD, NEW_SD] = ADDSTORAGE(STORAGE, MPC)
0006 %   [IDX, NEW_MPC, NEW_XGD, NEW_SD] = ADDSTORAGE(STORAGE, MPC, XGD)
0007 %   [IDX, NEW_MPC, NEW_XGD, NEW_SD] = ADDSTORAGE(STORAGE, MPC, XGD, SD)
0008 %
0009 %   Given a StorageUnitData structure, or the name of a file containing such
0010 %   a structure, this function adds the specified storage generators to an
0011 %   existing MATPOWER case, xGenData struct and StorageData struct.
0012 %
0013 %   Inputs:
0014 %       STORAGE : a StorageUnitData struct or the name of an M-file
0015 %                   or MAT-file that returns one, with the following fields
0016 %           .gen     : rows to be appended to the GEN matrix from MPC
0017 %           .gencost : (optional) rows to be added to the GENCOST matrix
0018 %                      from MPC, default is zero cost
0019 %           .xgd_table : xGenData table struct or filename providing data for
0020 %                        the storage units being added. See LOADSTORAGEDATA
0021 %                        for more information on the xGenData table format.
0022 %           .sd_table : StorageData table struct or filename providing data
0023 %                       for the storage units being added. See LOADSTORAGEDATA
0024 %                       for more information on the StorageData table format.
0025 %       MPC : MATPOWER case struct to which storage generators will be added
0026 %       XGD : (optional) xGenData struct corresponding to the generators
0027 %             already in MPC, to which the new xGenData for the storage
0028 %             units will be added.
0029 %       SD : (optional) StorageData struct corresponding to the generators
0030 %            already in MPC, to which the new StorageData for the storage
0031 %            units will be added.
0032 %
0033 %   Output:
0034 %       IDX : Generator indices of newly added storage units.
0035 %       NEW_MPC : MPC with storage units appended to MPC.GEN and MPC.GENCOST
0036 %                 MPC.GENFUEL (= 'ess').
0037 %       NEW_XGD : XGD with xGenData for new storage units appended.
0038 %       NEW_SD  : SD with StorageData for new storage units appended.
0039 %
0040 %   See also LOADSTORAGEDATA, LOADXGENDATA.
0041 
0042 %   MOST
0043 %   Copyright (c) 2013-2016, Power Systems Engineering Research Center (PSERC)
0044 %   by Ray Zimmerman, PSERC Cornell
0045 %
0046 %   This file is part of MOST.
0047 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0048 %   See https://github.com/MATPOWER/most for more info.
0049 
0050 %% define named indices into data matrices
0051 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
0052 
0053 %% define fuel type for storage
0054 STORAGE_FUEL = 'ess';
0055 
0056 %% input arg handling
0057 if nargin < 4
0058     sd = [];
0059     if nargin < 3
0060         xgd = [];
0061     end
0062 end
0063 if ischar(storage)
0064     infile = sprintf(' in file: ''%s''', storage);
0065     storage = loadgenericdata(storage, 'struct', 'gen', 'storage');
0066 else
0067     infile = '';
0068 end
0069 
0070 %% add to MPC
0071 ns = size(storage.gen, 1);          %% number of storage units being added
0072 if isfield(storage, 'gencost')
0073     storage_gencost = storage.gencost;
0074 else        %% use zero cost by default
0075     storage_gencost = repmat([POLYNOMIAL 0 0 2 0 0], ns, 1);
0076 end
0077 [new_mpc, idx] = addgen2mpc(mpc, storage.gen, storage_gencost, STORAGE_FUEL);
0078 
0079 %% handle xGenData and StorageData
0080 if nargout > 2      %% output NEW_XGD, NEW_SD requested
0081     %% xGenData
0082     if isfield(storage, 'xgd_table')
0083         storage_xgd = loadxgendata(storage.xgd_table, storage.gen);
0084     else
0085         error('addstorage: missing XGD_TABLE field in STORAGE');
0086     end
0087 
0088     if isempty(xgd)     %% no input XGD provided
0089         new_xgd = storage_xgd;
0090     else                %% input XGD provided
0091         %% append rows of every field in xgd
0092         new_xgd = xgd;
0093         fields = fieldnames(xgd);
0094         for f = 1:length(fields)
0095             ff = fields{f};
0096             %% dims of wind_xgd fields already checked by loadxgendata
0097             if size(xgd.(ff), 1) ~= size(mpc.gen, 1)
0098                 error('addstorage: # of rows in XGD.%s (%d) does not match MPC.GEN (%d)', ...
0099                     ff, size(xgd.(ff), 1), size(mpc.gen, 1));
0100             end
0101             new_xgd.(ff) = [xgd.(ff); storage_xgd.(ff)];
0102         end
0103     end
0104 
0105     %% StorageData
0106     if isfield(storage, 'sd_table')
0107         storage_sd = loadstoragedata(storage.sd_table, storage.gen);
0108     else
0109         error('addstorage: missing SD_TABLE field in STORAGE');
0110     end
0111 
0112     storage_sd.UnitIdx = idx;       %% add UnitIdx field
0113 
0114     if isempty(sd)     %% no input SD provided
0115         new_sd = storage_sd;
0116     else                %% input SD provided
0117         %% find number of storage units in original mpc
0118         ns0 = length(find(strcmp(mpc.genfuel, STORAGE_FUEL)));
0119         new_sd = sd;
0120         fields = fieldnames(sd);
0121         for f = 1:length(fields)    %% append rows of every field in sd
0122             ff = fields{f};
0123             add_ns  = size(storage_sd.(ff), 1);
0124             orig_ns = size(        sd.(ff), 1);
0125             if orig_ns ~= 1 || add_ns ~= 1 || sd.(ff) ~= storage_sd.(ff)
0126                 %% at least one of them is not 1-d or else they don't match
0127                 if orig_ns == 1     %% original is 1-d
0128                     %% expand it
0129                     sd.(ff) = ones(ns0, 1) * sd.(ff);
0130                 end
0131                 if add_ns == 1      %% new is 1-d
0132                     %% expand it
0133                     storage_sd.(ff) = ones(ns, 1) * storage_sd.(ff);
0134                 end
0135                 %% concatenate them
0136                 new_sd.(ff) = [sd.(ff); storage_sd.(ff)];
0137             % else (both are 1-d and they match)
0138             %   do nothing, just use old sd.(ff)
0139             end
0140         end
0141     end
0142 end

Generated on Fri 09-Oct-2020 11:21:31 by m2html © 2005