Home > matpower6.0 > 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-2016, Power Systems Engineering Research Center (PSERC)
0031 %   by Yujia Zhu, PSERC ASU
0032 %
0033 %   This file is part of MATPOWER.
0034 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0035 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0036 
0037 BranchRec = [mpcreduced_gen.branch(:,[1,2]),BCIRC,mpcreduced_gen.branch(:,[3,4])]; % fnum,tnum,circuit,r,x
0038 if acflag==0
0039     BranchRec(:,4)=0; % for dc, ignore all resistance
0040 end
0041 %% Read the bus data
0042 BusNo = mpcreduced_gen.bus(:,1);
0043 %% Convert original bus number to new bus number
0044 NewBusNo = (1:length(BusNo))';
0045 BusRec(:,1) = NewBusNo;
0046 BusRec = sortrows(BusRec,1);
0047 
0048 tf = ismember(ExBus,ExBusGen);
0049 ExBus = ExBus(tf==0);
0050 ExBus=interp1(BusNo,NewBusNo,ExBus');
0051 tf = ismember(BusRec(:,1),ExBus);
0052 IntBus = BusRec(tf==0,1);
0053 BranchRec(:,1) = interp1(BusNo,NewBusNo,BranchRec(:,1));
0054 BranchRec(:,2) = interp1(BusNo,NewBusNo,BranchRec(:,2));
0055 BranchRec = sortrows(BranchRec,[1,2,3]);
0056 
0057 Gen = mpcreduced_gen.gen;
0058 Gen(:,1)=interp1(BusNo,NewBusNo,Gen(:,1));
0059 Gen = sortrows(Gen,1);
0060 
0061 % clear num txt
0062 %% converter all parallel lines into single lines
0063 [ignore,I]=unique(BranchRec(:,[1 2]),'rows','first'); % return the first unique rows in BranchRec
0064 idx = find(diff(I)~=1);
0065 idx_del = [];
0066 for k = idx',
0067     z = complex(BranchRec(I(k),4),BranchRec(I(k),5)); % complex value of impedances
0068     for kk = I(k)+1:I(k+1)-1 
0069         z1 = complex(BranchRec(kk,4),BranchRec(kk,5)); 
0070         z = 1/(1/z+1/z1);
0071     end
0072     BranchRec(I(k),4) = real(z); 
0073     BranchRec(I(k),5) = imag(z); 
0074     idx_del = [idx_del I(k)+1:I(k+1)-1];
0075 end
0076  BranchRec(idx_del,:) = [];
0077 
0078 %% Convert the external gen network into a radial network by Zmin
0079 GenNum = Gen(:,1);
0080 tf = ismember(GenNum,IntBus);
0081 GenNum(tf==1)=[];  
0082 LinkedBus = zeros(size(BusNo));
0083 LinkedBra = zeros(size(BusNo)); 
0084 %set up the levels
0085 Level = -ones(size(BusNo));
0086 Level(IntBus) = 0;
0087 %set up the distance
0088 Dist = inf*ones(size(BusNo));
0089 Dist(IntBus) = 0;
0090 BranchZ = sqrt(BranchRec(:,4).^2+BranchRec(:,5).^2);
0091 
0092 BusPrevLayer = IntBus;
0093 BusTBD = GenNum;
0094 
0095 for lev=1:1000, 
0096     tf1 = ismember(BranchRec(:,1), BusPrevLayer);
0097     tf2 = ismember(BranchRec(:,2), BusTBD); 
0098     ind = find(tf1&tf2);
0099     for k=ind',
0100         pi = BranchRec(k,1);
0101         gi = BranchRec(k,2);
0102         if Dist(gi)> BranchZ(k)+Dist(pi),
0103             Dist(gi) = BranchZ(k)+Dist(pi);
0104             LinkedBus(gi) = pi;
0105             LinkedBra(gi) = k;
0106             Level(gi) = Level(pi)+1; 
0107         end
0108     end    
0109     tf1 = ismember(BranchRec(:,2), BusPrevLayer);
0110     tf2 = ismember(BranchRec(:,1), BusTBD);
0111     ind = find(tf1&tf2);
0112     for k=ind',
0113         pi = BranchRec(k,2); 
0114         gi = BranchRec(k,1);
0115         if Dist(gi)> BranchZ(k)+Dist(pi), 
0116             Dist(gi) = BranchZ(k)+Dist(pi);
0117             LinkedBus(gi) = pi;
0118             LinkedBra(gi) = k;
0119             Level(gi) = Level(pi)+1;
0120         end
0121     end
0122        
0123 %% make some modifications here
0124 
0125  % link to the internal bus with shortest path
0126     tf1 = ismember(BranchRec(:,1), BusTBD);
0127     tf2 = ismember(BranchRec(:,2), BusTBD);
0128     ind = find(tf1&tf2);
0129     
0130    
0131     
0132     for k=ind',
0133         pi = BranchRec(k,1);
0134         gi = BranchRec(k,2);
0135 
0136         if Dist(gi)> BranchZ(k)+Dist(pi),
0137             Level(gi) = -1;
0138         elseif Dist(pi)> BranchZ(k)+Dist(gi),
0139             Level(pi) = -1;
0140         end
0141     end
0142      %%
0143     BusPrevLayer = find(Level==lev); 
0144     if isempty(BusPrevLayer), % if all buses are islanded
0145         maxLevel = lev-1;
0146         break
0147     end
0148     BusTBD = find(Level==-1); 
0149     if isempty(BusTBD), % all gen buses are determined
0150         maxLevel = lev;
0151         break
0152     end
0153 end
0154 
0155 %%  LinkedBus=0 ->islanded buses       LinkedBus=-1
0156 LinkedBus(IntBus)=-1;
0157 islanded_Bus=BusNo(find(LinkedBus==0)); 
0158 LinkedBus(find(LinkedBus==0))=9999999;
0159 
0160 %%
0161 for i=1:length(LinkedBus) 
0162     if LinkedBus(i)==-1
0163         LinkedBus(i)=i;
0164     end
0165 end
0166 %%
0167 for lev=max(Level):-1:1    
0168     ind=find(Level==lev);
0169     Level(ind)=Level(ind)-1;
0170     
0171     for i=ind',
0172         p=LinkedBus(i);
0173         LinkedBus(i)=LinkedBus(p);
0174     end
0175 end
0176 %%
0177 BusNo=[BusNo;9999999];
0178 NewBusNo=[NewBusNo;9999999];
0179 islandflag = 1;
0180 if isempty(LinkedBus(LinkedBus==9999999))
0181     islandflag = 0;
0182     LinkedBus = [LinkedBus;9999999];
0183 end
0184     LinkedBus = interp1(NewBusNo,BusNo,LinkedBus);%% all the buses in the system and its correponding bus in the reduced system
0185 
0186 NewGenBus=interp1(BusNo,LinkedBus,mpcreduced_gen.gen(:,1));
0187 if ~islandflag
0188     LinkedBus(LinkedBus==9999999)=[];
0189 end
0190 Link = [mpcreduced_gen.bus(:,1),LinkedBus];
0191 %%
0192 end

Generated on Fri 16-Dec-2016 12:45:37 by m2html © 2005