Subroutine MakeMPCr generates the reduced model in MATPOWER case format. The reduced model generated in this subroutine will not involve generator placement and load redistribution. [mpcreduced,BCIRC,ExBus] = MakeMPCr(ERPEQ,DataEQ,CIndxEQ,ShuntData,ERP, DataB,ExBus,PivInd,PivOrd,BCIRC,newbusnum,oldbusnum,mpcfull,BoundBus) INPUT DATA: ERPEQ: 1*n array, includes end of row pointers of the equivalent lines DataEQ: 1*n array, includes value of equivalent line reactance CIndxEQ: 1*n array, includes column indices of equivalent lines ShuntData, 1*n array, includes bus shunts data of all buses in the reduced model ERP, 1*n array, includes end of row pointer of the original full model bus admittance matrix DataB, 1*n array, includes value of all non-zeros in the original full model bus adminttance matrix ExBus, 1*n array, includes indices of external buses PivOrd: 1*n array, includes bus indices after pivotting PivInd: 1*n array, includes bus ordering after pivotting BCIRC, 1*n array, includes branch circit number of the full model newbusnum, 1*n array, includes internal bus indices oldbusnum, 1*n array, includes original bus indices mpcfull, struct, the original full model BoundBus, 1*n array, includes indices of boundary buses OUTPUT DATA: mpcreduced: struct, the reduced model BCIRC: 1*n array, the branch circuit number of the reduced model ExBus: 1*n array, the external bus indices NOTE: The output data of this subroutine will be converted to original indices.
0001 function [mpcreduced,BCIRC,ExBus] = MakeMPCr(ERPEQ,DataEQ,CIndxEQ,ShuntData,ERP,DataB,ExBus,PivInd,PivOrd,BCIRC,newbusnum,oldbusnum,mpcfull,BoundBus) 0002 % Subroutine MakeMPCr generates the reduced model in MATPOWER case 0003 % format. The reduced model generated in this subroutine will not involve 0004 % generator placement and load redistribution. 0005 % 0006 % [mpcreduced,BCIRC,ExBus] = MakeMPCr(ERPEQ,DataEQ,CIndxEQ,ShuntData,ERP, 0007 % DataB,ExBus,PivInd,PivOrd,BCIRC,newbusnum,oldbusnum,mpcfull,BoundBus) 0008 % 0009 % INPUT DATA: 0010 % ERPEQ: 1*n array, includes end of row pointers of the equivalent lines 0011 % DataEQ: 1*n array, includes value of equivalent line reactance 0012 % CIndxEQ: 1*n array, includes column indices of equivalent lines 0013 % ShuntData, 1*n array, includes bus shunts data of all buses in the 0014 % reduced model 0015 % ERP, 1*n array, includes end of row pointer of the original full model 0016 % bus admittance matrix 0017 % DataB, 1*n array, includes value of all non-zeros in the original full 0018 % model bus adminttance matrix 0019 % ExBus, 1*n array, includes indices of external buses 0020 % PivOrd: 1*n array, includes bus indices after pivotting 0021 % PivInd: 1*n array, includes bus ordering after pivotting 0022 % BCIRC, 1*n array, includes branch circit number of the full model 0023 % newbusnum, 1*n array, includes internal bus indices 0024 % oldbusnum, 1*n array, includes original bus indices 0025 % mpcfull, struct, the original full model 0026 % BoundBus, 1*n array, includes indices of boundary buses 0027 % 0028 % OUTPUT DATA: 0029 % mpcreduced: struct, the reduced model 0030 % BCIRC: 1*n array, the branch circuit number of the reduced model 0031 % ExBus: 1*n array, the external bus indices 0032 % 0033 % NOTE: 0034 % The output data of this subroutine will be converted to original 0035 % indices. 0036 0037 % MATPOWER 0038 % Copyright (c) 2014-2015 by Power System Engineering Research Center (PSERC) 0039 % by Yujia Zhu, PSERC ASU 0040 % 0041 % $Id: MakeMPCr.m 2655 2015-03-18 16:40:32Z ray $ 0042 % 0043 % This file is part of MATPOWER. 0044 % Covered by the 3-clause BSD License (see LICENSE file for details). 0045 % See http://www.pserc.cornell.edu/matpower/ for more info. 0046 0047 ExLen=length(ExBus); 0048 %% Create the reduced model case file 0049 mpcreduced = mpcfull; 0050 branch = mpcreduced.branch; 0051 bus = mpcreduced.bus; 0052 int_flag = ones(size(branch,1),1); 0053 %% delete all branches connect external buses 0054 % 1. eliminate all branches connecting external bus 0055 % check from bus 0056 for i = 1:length(ExBus) 0057 tf=ismember(branch(:,1),ExBus(i)); 0058 int_flag = int_flag.*~tf; 0059 end 0060 % check to bus 0061 for i = 1:length(ExBus) 0062 tf=ismember(branch(:,2),ExBus(i)); 0063 int_flag = int_flag.*~tf; 0064 end 0065 branch(int_flag==0,:)=[]; % delete all marked branches 0066 BCIRC(int_flag==0,:)=[]; 0067 %% delete all external buses 0068 for i = 1:length(ExBus) 0069 bus(bus(:,1)==ExBus(i),:)=[]; 0070 end 0071 %% Generate data for equivalent branches 0072 if any(DataEQ) 0073 FromInd=zeros(size(CIndxEQ)); 0074 AddEqBranch = zeros(length(DataEQ),size(branch,2)); 0075 0076 for i = ExLen+1:length(ERPEQ)-1 0077 FromInd(ERPEQ(i)+1:ERPEQ(i+1))=i; 0078 end 0079 for i = 1:length(CIndxEQ) 0080 AddEqBranch(i,[1,2,4])=[PivInd(FromInd(i)),PivInd(CIndxEQ(i)),-DataEQ(i)]; 0081 end 0082 AddEqBranch(:,6)=99999; % RATEA 0083 AddEqBranch(:,7)=99999; % RATEB 0084 AddEqBranch(:,8)=99999; % RATEC 0085 0086 AddEqBranch(:,9)=1; % tap 0087 AddEqBranch(:,10)=0; % phase shift 0088 AddEqBranch(:,11)=1; % status 0089 AddEqBranch(:,12)=-360; % min angle 0090 AddEqBranch(:,13)=360; 0091 % generate circuit number 0092 EqBCIRC = max(99,10^(ceil(log10(max(BCIRC)-1)))-1); 0093 AddEqBCIRC = ones(size(AddEqBranch,1),1)*EqBCIRC; 0094 branch = [branch;AddEqBranch]; 0095 BCIRC = [BCIRC;AddEqBCIRC]; 0096 0097 mpcreduced.branch = branch; 0098 else 0099 fprintf('\nNo equivalent branch is generated'); 0100 mpcreduced.branch=branch; 0101 end 0102 %% Calculate Bus Shunt 0103 BusShunt=zeros(size(mpcfull.bus,1)-ExLen,2); 0104 BusShunt(:,1)=ExLen+1:size(mpcfull.bus,1); 0105 BusShunt(:,2)=DataB(ERP(BusShunt(:,1))+1); % add original diagonal element in Y matrix of the bus in; 0106 BusShunt(1:length(BoundBus),2)=BusShunt(1:length(BoundBus),2)+ShuntData'; 0107 for i = 1:size(branch,1) 0108 m=PivOrd(branch(i,1))-ExLen; 0109 n=PivOrd(branch(i,2))-ExLen; 0110 BusShunt(m,2)=BusShunt(m,2)-1/branch(i,4); 0111 BusShunt(n,2)=BusShunt(n,2)-1/branch(i,4); 0112 end 0113 BusShunt(:,1)=PivInd(BusShunt(:,1)); 0114 BusShunt(:,2)=BusShunt(:,2)*mpcfull.baseMVA; 0115 % Plug the shunts value into the case file 0116 bus=sortrows(bus,1); 0117 BusShunt=sortrows(BusShunt,1); 0118 bus(:,6)=BusShunt(:,2); 0119 mpcreduced.bus=bus; 0120 %% covert all bus numbers back to original numbering 0121 mpcreduced.branch(:,5)=0; % all branch shunts are converted to bus shunts 0122 mpcreduced.branch(:,1)=interp1(newbusnum,oldbusnum,mpcreduced.branch(:,1)); 0123 mpcreduced.branch(:,2)=interp1(newbusnum,oldbusnum,mpcreduced.branch(:,2)); 0124 mpcreduced.bus(:,1)=interp1(newbusnum,oldbusnum,mpcreduced.bus(:,1)); 0125 ExBus = interp1(newbusnum,oldbusnum,ExBus')'; 0126 mpcreduced.gen(:,1)=interp1(newbusnum,oldbusnum,mpcreduced.gen(:,1)); 0127 0128 end