Home > matpower5.0 > i2e_data.m

i2e_data

PURPOSE ^

I2E_DATA Converts data from internal to external bus numbering.

SYNOPSIS ^

function newval = i2e_data(mpc, val, oldval, ordering, dim)

DESCRIPTION ^

I2E_DATA   Converts data from internal to external bus numbering.

   VAL = I2E_DATA(MPC, VAL, OLDVAL, ORDERING)
   VAL = I2E_DATA(MPC, VAL, OLDVAL, ORDERING, DIM)

   For a case struct using internal indexing, this function can be
   used to convert other data structures as well by passing in 3 or 4
   extra parameters in addition to the case struct. If the value passed
   in the 2nd argument (VAL) is a column vector or cell array, it will
   be converted according to the ordering specified by the 4th argument
   (ORDERING, described below). If VAL is an n-dimensional matrix or
   cell array, then the optional 5th argument (DIM, default = 1) can be
   used to specify which dimension to reorder. The 3rd argument (OLDVAL)
   is used to initialize the return value before converting VAL to
   external indexing. In particular, any data corresponding to off-line
   gens or branches or isolated buses or any connected gens or branches
   will be taken from OLDVAL, with VAL supplying the rest of the
   returned data.

   The ORDERING argument 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_ext = i2e_data(mpc, A_int, A_orig, {'bus','bus','gen','gen'}, 2);

       Converts an A matrix for user-supplied OPF constraints from
       internal to external 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_ext = i2e_data(mpc, gencost_int, gencost_orig, {'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 E2I_DATA, I2E_FIELD, INT2EXT.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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

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