Home > matpower5.0 > e2i_data.m

e2i_data

PURPOSE ^

E2I_DATA Converts data from external to internal indexing.

SYNOPSIS ^

function newval = e2i_data(mpc, val, ordering, dim)

DESCRIPTION ^

E2I_DATA   Converts data from external to internal indexing.

   VAL = E2I_DATA(MPC, VAL, ORDERING)
   VAL = E2I_DATA(MPC, VAL, ORDERING, DIM)

   When given a case struct that has already been converted to
   internal indexing, this function can be used to convert other data
   structures as well by passing in 2 or 3 extra parameters in
   addition to the case struct. If the value passed in the 2nd
   argument is a column vector or cell array, it will be converted
   according to the ORDERING specified by the 3rd argument (described
   below). If VAL is an n-dimensional matrix or cell array, then the
   optional 4th argument (DIM, default = 1) can be used to specify
   which dimension to reorder. The return value in this case is the
   value passed in, converted to internal indexing.

   The 3rd argument, ORDERING, is used to indicate whether the data
   corresponds to bus-, gen- or branch-ordered data. It can be one
   of the following three strings: 'bus', 'gen' or 'branch'. For
   data structures with multiple blocks of data, ordered by bus,
   gen or branch, they can be converted with a single call by
   specifying ORDERING as a cell array of strings.

   Any extra elements, rows, columns, etc. beyond those indicated
   in ORDERING, are not disturbed.

   Examples:
       A_int = e2i_data(mpc, A_ext, {'bus','bus','gen','gen'}, 2);

       Converts an A matrix for user-supplied OPF constraints from
       external to internal ordering, where the columns of the A
       matrix correspond to bus voltage angles, then voltage
       magnitudes, then generator real power injections and finally
       generator reactive power injections.

       gencost_int = e2i_data(mpc, gencost_ext, {'gen','gen'}, 1);

       Converts a GENCOST matrix that has both real and reactive power
       costs (in rows 1--ng and ng+1--2*ng, respectively).

   See also I2E_DATA, E2I_FIELD, EXT2INT.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function newval = e2i_data(mpc, val, ordering, dim)
0002 %E2I_DATA   Converts data from external to internal indexing.
0003 %
0004 %   VAL = E2I_DATA(MPC, VAL, ORDERING)
0005 %   VAL = E2I_DATA(MPC, VAL, ORDERING, DIM)
0006 %
0007 %   When given a case struct that has already been converted to
0008 %   internal indexing, this function can be used to convert other data
0009 %   structures as well by passing in 2 or 3 extra parameters in
0010 %   addition to the case struct. If the value passed in the 2nd
0011 %   argument is a column vector or cell array, it will be converted
0012 %   according to the ORDERING specified by the 3rd argument (described
0013 %   below). If VAL is an n-dimensional matrix or cell array, then the
0014 %   optional 4th argument (DIM, default = 1) can be used to specify
0015 %   which dimension to reorder. The return value in this case is the
0016 %   value passed in, converted to internal indexing.
0017 %
0018 %   The 3rd argument, ORDERING, is used to indicate whether the data
0019 %   corresponds to bus-, gen- or branch-ordered data. It can be one
0020 %   of the following three strings: 'bus', 'gen' or 'branch'. For
0021 %   data structures with multiple blocks of data, ordered by bus,
0022 %   gen or branch, they can be converted with a single call by
0023 %   specifying ORDERING as a cell array of strings.
0024 %
0025 %   Any extra elements, rows, columns, etc. beyond those indicated
0026 %   in ORDERING, are not disturbed.
0027 %
0028 %   Examples:
0029 %       A_int = e2i_data(mpc, A_ext, {'bus','bus','gen','gen'}, 2);
0030 %
0031 %       Converts an A matrix for user-supplied OPF constraints from
0032 %       external to internal ordering, where the columns of the A
0033 %       matrix correspond to bus voltage angles, then voltage
0034 %       magnitudes, then generator real power injections and finally
0035 %       generator reactive power injections.
0036 %
0037 %       gencost_int = e2i_data(mpc, gencost_ext, {'gen','gen'}, 1);
0038 %
0039 %       Converts a GENCOST matrix that has both real and reactive power
0040 %       costs (in rows 1--ng and ng+1--2*ng, respectively).
0041 %
0042 %   See also I2E_DATA, E2I_FIELD, EXT2INT.
0043 
0044 %   MATPOWER
0045 %   $Id: e2i_data.m 2421 2014-11-12 20:49:31Z ray $
0046 %   by Ray Zimmerman, PSERC Cornell
0047 %   Copyright (c) 2009-2014 by Power System Engineering Research Center (PSERC)
0048 %
0049 %   This file is part of MATPOWER.
0050 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0051 %
0052 %   MATPOWER is free software: you can redistribute it and/or modify
0053 %   it under the terms of the GNU General Public License as published
0054 %   by the Free Software Foundation, either version 3 of the License,
0055 %   or (at your option) any later version.
0056 %
0057 %   MATPOWER is distributed in the hope that it will be useful,
0058 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0059 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0060 %   GNU General Public License for more details.
0061 %
0062 %   You should have received a copy of the GNU General Public License
0063 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0064 %
0065 %   Additional permission under GNU GPL version 3 section 7
0066 %
0067 %   If you modify MATPOWER, or any covered work, to interface with
0068 %   other modules (such as MATLAB code and MEX-files) available in a
0069 %   MATLAB(R) or comparable environment containing parts covered
0070 %   under other licensing terms, the licensors of MATPOWER grant
0071 %   you additional permission to convey the resulting work.
0072 
0073 if ~isfield(mpc, 'order')
0074     error('e2i_data: mpc does not have the ''order'' field required to convert from external to internal numbering.');
0075 end
0076 o = mpc.order;
0077 if o.state ~= 'i'
0078     error('e2i_data: mpc does not have internal ordering data available, call ext2int first');
0079 end
0080 if nargin < 4
0081     dim = 1;
0082 end
0083 if ischar(ordering)         %% single set
0084     if strcmp(ordering, 'gen')
0085         idx = o.(ordering).status.on(o.(ordering).e2i);
0086     else
0087         idx = o.(ordering).status.on;
0088     end
0089     newval = get_reorder(val, idx, dim);
0090 else                        %% multiple sets
0091     b = 0;  %% base
0092     for k = 1:length(ordering)
0093         n = size(o.ext.(ordering{k}), 1);
0094         v = get_reorder(val, b+(1:n), dim);
0095         new_v{k} = e2i_data(mpc, v, ordering{k}, dim);
0096         b = b + n;
0097     end
0098     n = size(val, dim);
0099     if n > b                %% the rest
0100         v = get_reorder(val, b+1:n, dim);
0101         new_v{length(new_v)+1} = v;
0102     end
0103     newval = cat(dim, new_v{:});
0104 end

Generated on Mon 26-Jan-2015 15:21:31 by m2html © 2005