Home > matpower5.1 > extras > reduction > MoveExGen.m

MoveExGen

PURPOSE ^

Subroutine MoveExGen moves generators on external buses to internal buses

SYNOPSIS ^

function [NewGenBus,Link]=MoveExGen(mpcreduced_gen,ExBus,ExBusGen,BCIRC,acflag)

DESCRIPTION ^

 Subroutine MoveExGen moves generators on external buses to internal buses
 based on shortest electrical distance strategy.
 
   [NewGenBus,Link]=MoveExGen(mpcreduced_gen,ExBus,ExBusGen,BCIRC,acflag)

 INPUT DATA:
   mpcreduced_gen: struct, reduced model with all non-generator external
       buses eliminated.
   ExBus: 1*n array, includes all external bus indices
   ExBusGen: 1*n array, includes external generator bus indices
   BCIRC: 1*n array, includes branch circuit numbers in full model
   acflag: scalar, if = 0, ignore all resistance, if = 1, calculate
       electrical distance involving resistance.
 
 OUTPUT DATA:
   NewGenBus: n*1 vector, includes new generator bus numbers after moving
       generators
   Link: n*2 matrix, includes generator mapping data of all generators.
       The first column is the original generator bus number and the second
       column is the new generator bus number after moving external generators

 NOTE:
   The electrical distance between two buses are calcualted as sum of
   impedance in series connecting the two buses. If acflag = 0, the
   impedance is same as reactance.
   The shortest distance is found based on Dijkstra's algorithm.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [NewGenBus,Link]=MoveExGen(mpcreduced_gen,ExBus,ExBusGen,BCIRC,acflag)
0002 % Subroutine MoveExGen moves generators on external buses to internal buses
0003 % based on shortest electrical distance strategy.
0004 %
0005 %   [NewGenBus,Link]=MoveExGen(mpcreduced_gen,ExBus,ExBusGen,BCIRC,acflag)
0006 %
0007 % INPUT DATA:
0008 %   mpcreduced_gen: struct, reduced model with all non-generator external
0009 %       buses eliminated.
0010 %   ExBus: 1*n array, includes all external bus indices
0011 %   ExBusGen: 1*n array, includes external generator bus indices
0012 %   BCIRC: 1*n array, includes branch circuit numbers in full model
0013 %   acflag: scalar, if = 0, ignore all resistance, if = 1, calculate
0014 %       electrical distance involving resistance.
0015 %
0016 % OUTPUT DATA:
0017 %   NewGenBus: n*1 vector, includes new generator bus numbers after moving
0018 %       generators
0019 %   Link: n*2 matrix, includes generator mapping data of all generators.
0020 %       The first column is the original generator bus number and the second
0021 %       column is the new generator bus number after moving external generators
0022 %
0023 % NOTE:
0024 %   The electrical distance between two buses are calcualted as sum of
0025 %   impedance in series connecting the two buses. If acflag = 0, the
0026 %   impedance is same as reactance.
0027 %   The shortest distance is found based on Dijkstra's algorithm.
0028 
0029 %   MATPOWER
0030 %   Copyright (c) 2014-2015 by Power System Engineering Research Center (PSERC)
0031 %   by Yujia Zhu, PSERC ASU
0032 %
0033 %   $Id: MoveExGen.m 2655 2015-03-18 16:40:32Z ray $
0034 %
0035 %   This file is part of MATPOWER.
0036 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0037 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0038 
0039 BranchRec = [mpcreduced_gen.branch(:,[1,2]),BCIRC,mpcreduced_gen.branch(:,[3,4])]; % fnum,tnum,circuit,r,x
0040 if acflag==0
0041     BranchRec(:,4)=0; % for dc, ignore all resistance
0042 end
0043 %% Read the bus data
0044 BusNo = mpcreduced_gen.bus(:,1);
0045 %% Convert original bus number to new bus number
0046 NewBusNo = (1:length(BusNo))';
0047 BusRec(:,1) = NewBusNo;
0048 BusRec = sortrows(BusRec,1);
0049 
0050 tf = ismember(ExBus,ExBusGen);
0051 ExBus = ExBus(tf==0);
0052 ExBus=interp1(BusNo,NewBusNo,ExBus');
0053 tf = ismember(BusRec(:,1),ExBus);
0054 IntBus = BusRec(tf==0,1);
0055 BranchRec(:,1) = interp1(BusNo,NewBusNo,BranchRec(:,1));
0056 BranchRec(:,2) = interp1(BusNo,NewBusNo,BranchRec(:,2));
0057 BranchRec = sortrows(BranchRec,[1,2,3]);
0058 
0059 Gen = mpcreduced_gen.gen;
0060 Gen(:,1)=interp1(BusNo,NewBusNo,Gen(:,1));
0061 Gen = sortrows(Gen,1);
0062 
0063 % clear num txt
0064 %% converter all parallel lines into single lines
0065 [ignore,I]=unique(BranchRec(:,[1 2]),'rows','first'); % return the first unique rows in BranchRec
0066 idx = find(diff(I)~=1);
0067 idx_del = [];
0068 for k = idx',
0069     z = complex(BranchRec(I(k),4),BranchRec(I(k),5)); % complex value of impedances
0070     for kk = I(k)+1:I(k+1)-1 
0071         z1 = complex(BranchRec(kk,4),BranchRec(kk,5)); 
0072         z = 1/(1/z+1/z1);
0073     end
0074     BranchRec(I(k),4) = real(z); 
0075     BranchRec(I(k),5) = imag(z); 
0076     idx_del = [idx_del I(k)+1:I(k+1)-1];
0077 end
0078  BranchRec(idx_del,:) = [];
0079 
0080 %% Convert the external gen network into a radial network by Zmin
0081 GenNum = Gen(:,1);
0082 tf = ismember(GenNum,IntBus);
0083 GenNum(tf==1)=[];  
0084 LinkedBus = zeros(size(BusNo));
0085 LinkedBra = zeros(size(BusNo)); 
0086 %set up the levels
0087 Level = -ones(size(BusNo));
0088 Level(IntBus) = 0;
0089 %set up the distance
0090 Dist = inf*ones(size(BusNo));
0091 Dist(IntBus) = 0;
0092 BranchZ = sqrt(BranchRec(:,4).^2+BranchRec(:,5).^2);
0093 
0094 BusPrevLayer = IntBus;
0095 BusTBD = GenNum;
0096 
0097 for lev=1:1000, 
0098     tf1 = ismember(BranchRec(:,1), BusPrevLayer);
0099     tf2 = ismember(BranchRec(:,2), BusTBD); 
0100     ind = find(tf1&tf2);
0101     for k=ind',
0102         pi = BranchRec(k,1);
0103         gi = BranchRec(k,2);
0104         if Dist(gi)> BranchZ(k)+Dist(pi),
0105             Dist(gi) = BranchZ(k)+Dist(pi);
0106             LinkedBus(gi) = pi;
0107             LinkedBra(gi) = k;
0108             Level(gi) = Level(pi)+1; 
0109         end
0110     end    
0111     tf1 = ismember(BranchRec(:,2), BusPrevLayer);
0112     tf2 = ismember(BranchRec(:,1), BusTBD);
0113     ind = find(tf1&tf2);
0114     for k=ind',
0115         pi = BranchRec(k,2); 
0116         gi = BranchRec(k,1);
0117         if Dist(gi)> BranchZ(k)+Dist(pi), 
0118             Dist(gi) = BranchZ(k)+Dist(pi);
0119             LinkedBus(gi) = pi;
0120             LinkedBra(gi) = k;
0121             Level(gi) = Level(pi)+1;
0122         end
0123     end
0124        
0125 %% make some modifications here
0126 
0127  % link to the internal bus with shortest path
0128     tf1 = ismember(BranchRec(:,1), BusTBD);
0129     tf2 = ismember(BranchRec(:,2), BusTBD);
0130     ind = find(tf1&tf2);
0131     
0132    
0133     
0134     for k=ind',
0135         pi = BranchRec(k,1);
0136         gi = BranchRec(k,2);
0137 
0138         if Dist(gi)> BranchZ(k)+Dist(pi),
0139             Level(gi) = -1;
0140         elseif Dist(pi)> BranchZ(k)+Dist(gi),
0141             Level(pi) = -1;
0142         end
0143     end
0144      %%
0145     BusPrevLayer = find(Level==lev); 
0146     if isempty(BusPrevLayer), % if all buses are islanded
0147         maxLevel = lev-1;
0148         break
0149     end
0150     BusTBD = find(Level==-1); 
0151     if isempty(BusTBD), % all gen buses are determined
0152         maxLevel = lev;
0153         break
0154     end
0155 end
0156 
0157 %%  LinkedBus=0 ->islanded buses       LinkedBus=-1
0158 LinkedBus(IntBus)=-1;
0159 islanded_Bus=BusNo(find(LinkedBus==0)); 
0160 LinkedBus(find(LinkedBus==0))=9999999;
0161 
0162 %%
0163 for i=1:length(LinkedBus) 
0164     if LinkedBus(i)==-1
0165         LinkedBus(i)=i;
0166     end
0167 end
0168 %%
0169 for lev=max(Level):-1:1    
0170     ind=find(Level==lev);
0171     Level(ind)=Level(ind)-1;
0172     
0173     for i=ind',
0174         p=LinkedBus(i);
0175         LinkedBus(i)=LinkedBus(p);
0176     end
0177 end
0178 %%
0179 BusNo=[BusNo;9999999];
0180 NewBusNo=[NewBusNo;9999999];
0181 islandflag = 1;
0182 if isempty(LinkedBus(LinkedBus==9999999))
0183     islandflag = 0;
0184     LinkedBus = [LinkedBus;9999999];
0185 end
0186     LinkedBus = interp1(NewBusNo,BusNo,LinkedBus);%% all the buses in the system and its correponding bus in the reduced system
0187 
0188 NewGenBus=interp1(BusNo,LinkedBus,mpcreduced_gen.gen(:,1));
0189 if ~islandflag
0190     LinkedBus(LinkedBus==9999999)=[];
0191 end
0192 Link = [mpcreduced_gen.bus(:,1),LinkedBus];
0193 %%
0194 end

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