Home > matpower5.0 > int2ext.m

int2ext

PURPOSE ^

INT2EXT Converts internal to external bus numbering.

SYNOPSIS ^

function [bus, gen, branch, areas] = int2ext(i2e, bus, gen, branch, areas)

DESCRIPTION ^

INT2EXT   Converts internal to external bus numbering.

   This function has two forms, (1) the old form that operates on
   and returns individual matrices and (2) the new form that operates
   on and returns an entire MATPOWER case struct.

   1.  [BUS, GEN, BRANCH, AREAS] = INT2EXT(I2E, BUS, GEN, BRANCH, AREAS)
       [BUS, GEN, BRANCH] = INT2EXT(I2E, BUS, GEN, BRANCH)

   Converts from the consecutive internal bus numbers back to the originals
   using the mapping provided by the I2E vector returned from EXT2INT,
   where EXTERNAL_BUS_NUMBER = I2E(INTERNAL_BUS_NUMBER).
   AREAS is completely ignored and is only included here for backward
   compatibility of the API.

   Examples:
       [bus, gen, branch, areas] = int2ext(i2e, bus, gen, branch, areas);
       [bus, gen, branch] = int2ext(i2e, bus, gen, branch);

   2.  MPC = INT2EXT(MPC)

   If the input is a single MATPOWER case struct, then it restores all
   buses, generators and branches that were removed because of being
   isolated or off-line, and reverts to the original generator ordering
   and original bus numbering. This requires that the 'order' field
   created by EXT2INT be in place.

   Example:
       mpc = int2ext(mpc);

   See also EXT2INT, I2E_FIELD, I2E_DATA.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [bus, gen, branch, areas] = int2ext(i2e, bus, gen, branch, areas)
0002 %INT2EXT   Converts internal to external bus numbering.
0003 %
0004 %   This function has two forms, (1) the old form that operates on
0005 %   and returns individual matrices and (2) the new form that operates
0006 %   on and returns an entire MATPOWER case struct.
0007 %
0008 %   1.  [BUS, GEN, BRANCH, AREAS] = INT2EXT(I2E, BUS, GEN, BRANCH, AREAS)
0009 %       [BUS, GEN, BRANCH] = INT2EXT(I2E, BUS, GEN, BRANCH)
0010 %
0011 %   Converts from the consecutive internal bus numbers back to the originals
0012 %   using the mapping provided by the I2E vector returned from EXT2INT,
0013 %   where EXTERNAL_BUS_NUMBER = I2E(INTERNAL_BUS_NUMBER).
0014 %   AREAS is completely ignored and is only included here for backward
0015 %   compatibility of the API.
0016 %
0017 %   Examples:
0018 %       [bus, gen, branch, areas] = int2ext(i2e, bus, gen, branch, areas);
0019 %       [bus, gen, branch] = int2ext(i2e, bus, gen, branch);
0020 %
0021 %   2.  MPC = INT2EXT(MPC)
0022 %
0023 %   If the input is a single MATPOWER case struct, then it restores all
0024 %   buses, generators and branches that were removed because of being
0025 %   isolated or off-line, and reverts to the original generator ordering
0026 %   and original bus numbering. This requires that the 'order' field
0027 %   created by EXT2INT be in place.
0028 %
0029 %   Example:
0030 %       mpc = int2ext(mpc);
0031 %
0032 %   See also EXT2INT, I2E_FIELD, I2E_DATA.
0033 
0034 %   MATPOWER
0035 %   $Id: int2ext.m 2424 2014-11-13 18:45:25Z ray $
0036 %   by Ray Zimmerman, PSERC Cornell
0037 %   Copyright (c) 1996-2010 by Power System Engineering Research Center (PSERC)
0038 %
0039 %   This file is part of MATPOWER.
0040 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0041 %
0042 %   MATPOWER is free software: you can redistribute it and/or modify
0043 %   it under the terms of the GNU General Public License as published
0044 %   by the Free Software Foundation, either version 3 of the License,
0045 %   or (at your option) any later version.
0046 %
0047 %   MATPOWER is distributed in the hope that it will be useful,
0048 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0049 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0050 %   GNU General Public License for more details.
0051 %
0052 %   You should have received a copy of the GNU General Public License
0053 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0054 %
0055 %   Additional permission under GNU GPL version 3 section 7
0056 %
0057 %   If you modify MATPOWER, or any covered work, to interface with
0058 %   other modules (such as MATLAB code and MEX-files) available in a
0059 %   MATLAB(R) or comparable environment containing parts covered
0060 %   under other licensing terms, the licensors of MATPOWER grant
0061 %   you additional permission to convey the resulting work.
0062 
0063 if isstruct(i2e)
0064     mpc = i2e;
0065     if nargin == 1
0066         if ~isfield(mpc, 'order')
0067             error('int2ext: mpc does not have the ''order'' field required for conversion back to external numbering.');
0068         end
0069         o = mpc.order;
0070 
0071         if o.state == 'i'
0072             %% define names for columns to data matrices
0073             [PQ, PV, REF, NONE, BUS_I] = idx_bus;
0074             GEN_BUS = idx_gen;
0075             [F_BUS, T_BUS] = idx_brch;
0076 
0077             %% execute userfcn callbacks for 'int2ext' stage
0078             if isfield(mpc, 'userfcn')
0079                 mpc = run_userfcn(mpc.userfcn, 'int2ext', mpc);
0080             end
0081             
0082             %% convert back "extra" fields
0083             if isfield(mpc, 'gencost')
0084                 ordering = {'gen'};         %% Pg cost only
0085                 if size(mpc.gencost, 1) == 2*size(mpc.gen, 1)
0086                     ordering{2} = 'gen';    %% include Qg cost
0087                 end
0088                 mpc = i2e_field(mpc, 'gencost', ordering);
0089             end
0090             %% assume A and N are "read-only"
0091             %% (otherwise need to convert back, using i2e_field() which
0092             %% requires knowing if they are sized for AC or DC)
0093             if isfield(mpc, 'A')
0094                 o.int.A = mpc.A;
0095                 mpc.A = o.ext.A;
0096             end
0097             if isfield(mpc, 'N')
0098                 o.int.N = mpc.N;
0099                 mpc.N = o.ext.N;
0100             end
0101 
0102             %% save data matrices with internal ordering & restore originals
0103             o.int.bus    = mpc.bus;
0104             o.int.branch = mpc.branch;
0105             o.int.gen    = mpc.gen;
0106             mpc.bus     = o.ext.bus;
0107             mpc.branch  = o.ext.branch;
0108             mpc.gen     = o.ext.gen;
0109 
0110             %% zero pad data matrices on right if necessary
0111             nci = size(o.int.bus, 2);
0112             [nr, nc] = size(mpc.bus);
0113             if nc < nci
0114                 mpc.bus = [mpc.bus zeros(nr, nci-nc)];
0115             end
0116             nci = size(o.int.branch, 2);
0117             [nr, nc] = size(mpc.branch);
0118             if nc < nci
0119                 mpc.branch = [mpc.branch zeros(nr, nci-nc)];
0120             end
0121             nci = size(o.int.gen, 2);
0122             [nr, nc] = size(mpc.gen);
0123             if nc < nci
0124                 mpc.gen = [mpc.gen zeros(nr, nci-nc)];
0125             end
0126 
0127             %% update data (in bus, branch, and gen only)
0128             mpc.bus(o.bus.status.on, :)       = o.int.bus;
0129             mpc.branch(o.branch.status.on, :) = o.int.branch;
0130             mpc.gen(o.gen.status.on, :)       = o.int.gen(o.gen.i2e, :);
0131 
0132             %% revert to original bus numbers
0133             mpc.bus(o.bus.status.on, BUS_I) = ...
0134                     o.bus.i2e( mpc.bus(o.bus.status.on, BUS_I) );
0135             mpc.branch(o.branch.status.on, F_BUS) = ...
0136                     o.bus.i2e( mpc.branch(o.branch.status.on, F_BUS) );
0137             mpc.branch(o.branch.status.on, T_BUS) = ...
0138                     o.bus.i2e( mpc.branch(o.branch.status.on, T_BUS) );
0139             mpc.gen(o.gen.status.on, GEN_BUS) = ...
0140                     o.bus.i2e( mpc.gen(o.gen.status.on, GEN_BUS) );
0141 
0142             if isfield(o, 'ext')
0143                 o = rmfield(o, 'ext');
0144             end
0145             o.state = 'e';
0146             mpc.order = o;
0147         else
0148             error('int2ext: mpc claims it is already using external numbering.');
0149         end
0150 
0151         bus = mpc;
0152     else                    %% convert extra data
0153         if ischar(bus) || iscell(bus)   %% field
0154             warning('Calls of the form MPC = INT2EXT(MPC, ''FIELD_NAME'', ...) have been deprecated. Please replace INT2EXT with I2E_FIELD.');
0155             if nargin > 3
0156                 dim = branch;
0157             else
0158                 dim = 1;
0159             end
0160             bus = i2e_field(mpc, bus, gen, dim);
0161         else                            %% value
0162             warning('Calls of the form VAL = INT2EXT(MPC, VAL, ...) have been deprecated. Please replace INT2EXT with I2E_DATA.');
0163             if nargin > 4
0164                 dim = areas;
0165             else
0166                 dim = 1;
0167             end
0168             bus = i2e_data(mpc, bus, gen, branch, dim);
0169         end
0170     end
0171 else            %% old form
0172     %% define names for columns to data matrices
0173     [PQ, PV, REF, NONE, BUS_I] = idx_bus;
0174     [GEN_BUS] = idx_gen;
0175     [F_BUS, T_BUS] = idx_brch;
0176 
0177     bus(:, BUS_I)               = i2e( bus(:, BUS_I)            );
0178     gen(:, GEN_BUS)             = i2e( gen(:, GEN_BUS)          );
0179     branch(:, F_BUS)            = i2e( branch(:, F_BUS)         );
0180     branch(:, T_BUS)            = i2e( branch(:, T_BUS)         );
0181 end

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