Home > matpower5.1 > 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 %   Copyright (c) 2009-2015 by Power System Engineering Research Center (PSERC)
0049 %   by Ray Zimmerman, PSERC Cornell
0050 %
0051 %   $Id: i2e_data.m 2644 2015-03-11 19:34:22Z ray $
0052 %
0053 %   This file is part of MATPOWER.
0054 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0055 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0056 
0057 if ~isfield(mpc, 'order')
0058     error('i2e_data: mpc does not have the ''order'' field required for conversion back to external numbering.');
0059 end
0060 o = mpc.order;
0061 if o.state ~= 'i'
0062     error('i2e_data: mpc does not appear to be in internal order');
0063 end
0064 if nargin < 5
0065     dim = 1;
0066 end
0067 if ischar(ordering)         %% single set
0068     if strcmp(ordering, 'gen')
0069         v = get_reorder(val, o.(ordering).i2e, dim);
0070     else
0071         v = val;
0072     end
0073     newval = set_reorder(oldval, v, o.(ordering).status.on, dim);
0074 else                        %% multiple sets
0075     be = 0;  %% base, external indexing
0076     bi = 0;  %% base, internal indexing
0077     for k = 1:length(ordering)
0078         ne = size(o.ext.(ordering{k}), 1);
0079         ni = size(mpc.(ordering{k}), 1);
0080         v = get_reorder(val, bi+(1:ni), dim);
0081         oldv = get_reorder(oldval, be+(1:ne), dim);
0082         new_v{k} = i2e_data(mpc, v, oldv, ordering{k}, dim);
0083         be = be + ne;
0084         bi = bi + ni;
0085     end
0086     ni = size(val, dim);
0087     if ni > bi              %% the rest
0088         v = get_reorder(val, bi+1:ni, dim);
0089         new_v{length(new_v)+1} = v;
0090     end
0091     newval = cat(dim, new_v{:});
0092 end

Generated on Fri 20-Mar-2015 18:23:34 by m2html © 2005