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

addgen2mpc

PURPOSE ^

ADDGEN2MPC Adds a set of generators to a MATPOWER case struct.

SYNOPSIS ^

function [mpco, NewGenIdx] = addgen2mpc(mpci, gen, gencost, fuel)

DESCRIPTION ^

ADDGEN2MPC Adds a set of generators to a MATPOWER case struct.

   [NEW_MPC, IDX] = ADDGEN2MPC(MPC, GEN, GENCOST, GEN_TYPE)

   Inserts a set of generators to a MATPOWER case struct by adding the
   info of the new generators (in inputs GEN, GENCOST and GEN_TYPE) to the
   bottom of the corresponding tables (fields of MPC). Dimensions must
   be consistent.

   Inputs:
       MPC : standard MATPOWER case struct, with the following additional
             fields:
               .genfuel : (optional) cell array of strings with fuel type
                          (filled with 'unknown' if missing)
               .i<type> : vector of generator indices for units of the
                          specified fuel type
       GEN: standard MATPOWER generator matrix for units to be added
       GENCOST: standard MATPOWER generator cost matrix for units to be added
       GEN_TYPE: string or cell array of names of fuel or type of new gens

   Outputs:
       NEW_MPC : the new MATPOWER case with the additional generators
                 appended to GEN, GENCOST, GENFUEL and additional field
                   .i<type> : vector of generator indices for units of the
                              specified fuel type
       IDX : generator indices of the newly added generators

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [mpco, NewGenIdx] = addgen2mpc(mpci, gen, gencost, fuel)
0002 %ADDGEN2MPC Adds a set of generators to a MATPOWER case struct.
0003 %
0004 %   [NEW_MPC, IDX] = ADDGEN2MPC(MPC, GEN, GENCOST, GEN_TYPE)
0005 %
0006 %   Inserts a set of generators to a MATPOWER case struct by adding the
0007 %   info of the new generators (in inputs GEN, GENCOST and GEN_TYPE) to the
0008 %   bottom of the corresponding tables (fields of MPC). Dimensions must
0009 %   be consistent.
0010 %
0011 %   Inputs:
0012 %       MPC : standard MATPOWER case struct, with the following additional
0013 %             fields:
0014 %               .genfuel : (optional) cell array of strings with fuel type
0015 %                          (filled with 'unknown' if missing)
0016 %               .i<type> : vector of generator indices for units of the
0017 %                          specified fuel type
0018 %       GEN: standard MATPOWER generator matrix for units to be added
0019 %       GENCOST: standard MATPOWER generator cost matrix for units to be added
0020 %       GEN_TYPE: string or cell array of names of fuel or type of new gens
0021 %
0022 %   Outputs:
0023 %       NEW_MPC : the new MATPOWER case with the additional generators
0024 %                 appended to GEN, GENCOST, GENFUEL and additional field
0025 %                   .i<type> : vector of generator indices for units of the
0026 %                              specified fuel type
0027 %       IDX : generator indices of the newly added generators
0028 
0029 %   MOST
0030 %   Copyright (c) 2013-2016, Power Systems Engineering Research Center (PSERC)
0031 %   by Daniel Munoz-Alvarez and Ray Zimmerman, PSERC Cornell
0032 %
0033 %   This file is part of MOST.
0034 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0035 %   See https://github.com/MATPOWER/most for more info.
0036 
0037 [ng, ncg]     = size(mpci.gen);
0038 [nr, nc]      = size(gen);
0039 [ng2, ncgc]   = size(mpci.gencost);
0040 [nr2, ncgc2]  = size(gencost);
0041 if nr ~= nr2
0042     error('addgen2mpc: number of rows in GEN (%d) and GENCOST (%d) must agree', nr, nr2);
0043 end
0044 if ng ~= ng2
0045     error('addgen2mpc: number of rows in MPC.GEN (%d) and MPC.GENCOST (%d) must agree', ng, ng2);
0046 end
0047 
0048 %% append rows to GEN
0049 mpco = mpci;
0050 if nc <= ncg
0051     mpco.gen = [mpco.gen ; gen zeros(nr, ncg-nc)];
0052 else
0053     error('addgen2mpc: number of columns of GEN (%d) exceeds number of columns of MPC.GEN (%d)', nc, ncg);
0054 end
0055 
0056 %% append rows to GENCOST
0057 dim_gencost = size(gencost);
0058 dim_gencost_cur = size(mpco.gencost);
0059 if dim_gencost(2) < dim_gencost_cur(2)
0060     mpco.gencost = [mpco.gencost ; [gencost zeros(dim_gencost(1),dim_gencost_cur(2)-dim_gencost(2))]];
0061 elseif dim_gencost(2) > dim_gencost_cur(2)
0062     mpco.gencost = [mpco.gencost zeros(dim_gencost_cur(1),dim_gencost(2)-dim_gencost_cur(2))];
0063     mpco.gencost = [mpco.gencost ; gencost];
0064 else
0065     mpco.gencost = [mpco.gencost ; gencost];
0066 end
0067 
0068 %% initialize 'genfuel'  and 'i<type>' fields if missing
0069 if ~isfield(mpco, 'genfuel')
0070     mpco.genfuel = mat2cell(repmat('unknown', ng, 1), ones(ng,1), 7);
0071 end
0072 if ~isfield(mpco,['i' fuel])
0073     mpco.(['i' fuel]) = [];
0074 end
0075 
0076 %% append 'genfuel' and 'i<type>' fields
0077 if iscell(fuel)
0078     for i = dim_gencost(1)
0079         mpco.genfuel = [mpco.genfuel ; fuel{i}];
0080         mpco.(['i' fuel{i}]) = [ mpco.(['i' fuel{i}]) ; dim_gencost_cur(1) + i ];
0081     end
0082 elseif ischar(fuel)
0083     for i = 1:dim_gencost(1)
0084         mpco.genfuel = [ mpco.genfuel ; fuel ];
0085         mpco.(['i' fuel]) = [ mpco.(['i' fuel]) ; dim_gencost_cur(1) + i ];
0086     end
0087 else
0088     error('addgen2mpc: GEN_TYPE must be a string (or cell array of strings) indicating the fuel type of the new generators');
0089 end
0090 
0091 NewGenIdx = ( ng + 1 : size(mpco.gen,1) )';

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