Home > matpower6.0 > most > addwind.m

addwind

PURPOSE ^

ADDWIND Adds wind generators and corresponding xGenData to existing data.

SYNOPSIS ^

function [idx, new_mpc, new_xgd] = addwind(wind, mpc, xgd)

DESCRIPTION ^

ADDWIND   Adds wind generators and corresponding xGenData to existing data.

   [IDX, NEW_MPC] = ADDWIND(WIND, MPC)
   [IDX, NEW_MPC, NEW_XGD] = ADDWIND(WIND, MPC)
   [IDX, NEW_MPC, NEW_XGD] = ADDWIND(WIND, MPC, XGD)

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

   Inputs:
       WIND : a WindUnitData 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 wind units being added. See LOADXGENDATA for
                        more information on the xGenData table format.
       MPC : MATPOWER case struct to which wind generators will be added
       XGD : (optional) xGenData struct corresponding to the generators
             already in MPC, to which the new xGenData for the wind units
             will be added.

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

   See also LOADXGENDATA.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [idx, new_mpc, new_xgd] = addwind(wind, mpc, xgd)
0002 %ADDWIND   Adds wind generators and corresponding xGenData to existing data.
0003 %
0004 %   [IDX, NEW_MPC] = ADDWIND(WIND, MPC)
0005 %   [IDX, NEW_MPC, NEW_XGD] = ADDWIND(WIND, MPC)
0006 %   [IDX, NEW_MPC, NEW_XGD] = ADDWIND(WIND, MPC, XGD)
0007 %
0008 %   Given a WindUnitData structure, or the name of a file containing such
0009 %   a structure, this function adds the specified wind generators to an
0010 %   existing MATPOWER case and xGenData struct.
0011 %
0012 %   Inputs:
0013 %       WIND : a WindUnitData struct or the name of an M-file
0014 %                   or MAT-file that returns one, with the following fields
0015 %           .gen     : rows to be appended to the GEN matrix from MPC
0016 %           .gencost : (optional) rows to be added to the GENCOST matrix
0017 %                      from MPC, default is zero cost
0018 %           .xgd_table : xGenData table struct or filename providing data for
0019 %                        the wind units being added. See LOADXGENDATA for
0020 %                        more information on the xGenData table format.
0021 %       MPC : MATPOWER case struct to which wind generators will be added
0022 %       XGD : (optional) xGenData struct corresponding to the generators
0023 %             already in MPC, to which the new xGenData for the wind units
0024 %             will be added.
0025 %
0026 %   Output:
0027 %       IDX : Generator indices of newly added wind units.
0028 %       NEW_MPC : MPC with wind units appended to MPC.GEN and MPC.GENCOST
0029 %                 MPC.GENFUEL (= 'wind').
0030 %       NEW_XGD : XGD with xGenData for new wind units appended.
0031 %
0032 %   See also LOADXGENDATA.
0033 
0034 %   MOST
0035 %   Copyright (c) 2013-2016, Power Systems Engineering Research Center (PSERC)
0036 %   by Ray Zimmerman, PSERC Cornell
0037 %
0038 %   This file is part of MOST.
0039 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0040 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0041 
0042 %% define named indices into data matrices
0043 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
0044 
0045 %% define fuel type for wind
0046 WIND_FUEL = 'wind';
0047 
0048 %% input arg handling
0049 if nargin < 3
0050     xgd = [];
0051 end
0052 if ischar(wind)
0053     infile = sprintf(' in file: ''%s''', wind);
0054     wind = loadgenericdata(wind, 'struct', 'gen', 'wind');
0055 else
0056     infile = '';
0057 end
0058 
0059 %% add to MPC
0060 nw = size(wind.gen, 1);
0061 if isfield(wind, 'gencost')
0062     wind_gencost = wind.gencost;
0063 else        %% use zero cost by default
0064     wind_gencost = repmat([POLYNOMIAL 0 0 2 0 0], nw, 1);
0065 end
0066 [new_mpc, idx] = addgen2mpc(mpc, wind.gen, wind_gencost, WIND_FUEL);
0067 
0068 %% handle xGenData
0069 if nargout > 2      %% output NEW_XGD requested
0070     if isfield(wind, 'xgd_table')
0071         wind_xgd = loadxgendata(wind.xgd_table, wind.gen);
0072     else
0073         error('addwind: missing XGD_TABLE field in WIND');
0074     end
0075 
0076     if isempty(xgd)     %% no input XGD provided
0077         new_xgd = wind_xgd;
0078     else                %% input XGD provided
0079         new_xgd = xgd;
0080         fields = fieldnames(xgd);
0081         for f = 1:length(fields)    %% append rows of every field in xgd
0082             ff = fields{f};
0083             %% dims of wind_xgd fields already checked by loadxgendata
0084             if size(xgd.(ff), 1) ~= size(mpc.gen, 1)
0085                 error('addwind: # of rows in XGD.%s (%d) does not match MPC.GEN (%d)', ...
0086                     ff, size(xgd.(ff), 1), size(mpc.gen, 1));
0087             end
0088             new_xgd.(ff) = [xgd.(ff); wind_xgd.(ff)];
0089         end
0090     end
0091 end

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