Home > matpower7.1 > extras > reduction > MakeMPCr.m

MakeMPCr

PURPOSE ^

Subroutine MakeMPCr generates the reduced model in MATPOWER case

SYNOPSIS ^

function [mpcreduced,BCIRC,ExBus] = MakeMPCr(ERPEQ,DataEQ,CIndxEQ,ShuntData,ERP,DataB,ExBus,PivInd,PivOrd,BCIRC,newbusnum,oldbusnum,mpcfull,BoundBus)

DESCRIPTION ^

 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.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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-2016, Power Systems Engineering Research Center (PSERC)
0039 %   by Yujia Zhu, PSERC ASU
0040 %
0041 %   This file is part of MATPOWER/mx-reduction.
0042 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0043 %   See https://github.com/MATPOWER/mx-reduction/ for more info.
0044 
0045 ExLen=length(ExBus);
0046 %% Create the reduced model case file
0047 mpcreduced = mpcfull;
0048 branch = mpcreduced.branch;
0049 bus = mpcreduced.bus;
0050 int_flag = ones(size(branch,1),1);
0051 %% delete all branches connect external buses
0052 % 1. eliminate all branches connecting external bus
0053 % check from bus
0054 for i = 1:length(ExBus)
0055     tf=ismember(branch(:,1),ExBus(i));
0056     int_flag = int_flag.*~tf;
0057 end
0058 % check to bus
0059 for i = 1:length(ExBus)
0060     tf=ismember(branch(:,2),ExBus(i));
0061     int_flag = int_flag.*~tf;
0062 end
0063 branch(int_flag==0,:)=[]; % delete all marked branches
0064 BCIRC(int_flag==0,:)=[];
0065 %% delete all external buses
0066 for i = 1:length(ExBus)
0067     bus(bus(:,1)==ExBus(i),:)=[];
0068 end
0069 %% Generate data for equivalent branches
0070 if any(DataEQ)
0071 FromInd=zeros(size(CIndxEQ));
0072 AddEqBranch = zeros(length(DataEQ),size(branch,2));
0073 
0074 for i = ExLen+1:length(ERPEQ)-1
0075     FromInd(ERPEQ(i)+1:ERPEQ(i+1))=i;
0076 end
0077 for i = 1:length(CIndxEQ)
0078     AddEqBranch(i,[1,2,4])=[PivInd(FromInd(i)),PivInd(CIndxEQ(i)),-DataEQ(i)];
0079 end
0080 AddEqBranch(:,6)=99999; % RATEA
0081 AddEqBranch(:,7)=99999; % RATEB
0082 AddEqBranch(:,8)=99999; % RATEC
0083 
0084 AddEqBranch(:,9)=1; % tap
0085 AddEqBranch(:,10)=0; % phase shift
0086 AddEqBranch(:,11)=1; % status
0087 AddEqBranch(:,12)=-360; % min angle
0088 AddEqBranch(:,13)=360;
0089 % generate circuit number
0090 EqBCIRC = max(99,10^(ceil(log10(max(BCIRC)-1)))-1);
0091 AddEqBCIRC = ones(size(AddEqBranch,1),1)*EqBCIRC;
0092 branch = [branch;AddEqBranch];
0093 BCIRC = [BCIRC;AddEqBCIRC];
0094 
0095 mpcreduced.branch = branch;
0096 else 
0097     fprintf('\nNo equivalent branch is generated');
0098     mpcreduced.branch=branch;
0099 end
0100 %% Calculate Bus Shunt
0101 BusShunt=zeros(size(mpcfull.bus,1)-ExLen,2);
0102 BusShunt(:,1)=ExLen+1:size(mpcfull.bus,1);
0103 BusShunt(:,2)=DataB(ERP(BusShunt(:,1))+1); % add original diagonal element in Y matrix of the bus in;
0104 BusShunt(1:length(BoundBus),2)=BusShunt(1:length(BoundBus),2)+ShuntData';
0105 for i = 1:size(branch,1)
0106     m=PivOrd(branch(i,1))-ExLen;
0107     n=PivOrd(branch(i,2))-ExLen;
0108     BusShunt(m,2)=BusShunt(m,2)-1/branch(i,4);
0109     BusShunt(n,2)=BusShunt(n,2)-1/branch(i,4);
0110 end
0111 BusShunt(:,1)=PivInd(BusShunt(:,1));
0112 BusShunt(:,2)=BusShunt(:,2)*mpcfull.baseMVA;
0113 % Plug the shunts value into the case file
0114 bus=sortrows(bus,1);
0115 BusShunt=sortrows(BusShunt,1);
0116 bus(:,6)=BusShunt(:,2);
0117 mpcreduced.bus=bus;
0118 %% covert all bus numbers back to original numbering
0119 mpcreduced.branch(:,5)=0; % all branch shunts are converted to bus shunts
0120 mpcreduced.branch(:,1)=interp1(newbusnum,oldbusnum,mpcreduced.branch(:,1));
0121 mpcreduced.branch(:,2)=interp1(newbusnum,oldbusnum,mpcreduced.branch(:,2));
0122 mpcreduced.bus(:,1)=interp1(newbusnum,oldbusnum,mpcreduced.bus(:,1));
0123 ExBus = interp1(newbusnum,oldbusnum,ExBus')';
0124 mpcreduced.gen(:,1)=interp1(newbusnum,oldbusnum,mpcreduced.gen(:,1));
0125 
0126 end

Generated on Fri 09-Oct-2020 11:21:31 by m2html © 2005