0001 function [mpcreduced,BCIRCr]=LoadRedistribution(mpcfull,mpcreduced,BCIRCr,Pf_flag)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 if Pf_flag==1
0037
0038 [resultfull,successfull]=rundcpf(mpcfull);
0039 if ~successfull
0040 error('unable to solve dc powerflow with original full model, load cannot be redistributed')
0041 end
0042 else resultfull=mpcfull;
0043 successfull=1;
0044 end
0045
0046
0047
0048 OrigBusRec=resultfull.bus(:,[1,8,9]);
0049 OrigBusRec=sortrows(OrigBusRec,1);
0050
0051 BusRec = mpcreduced.bus;
0052 BusRec = sortrows(BusRec,1);
0053 BusNo = BusRec(:,1);
0054
0055
0056 [ignore, ind]=ismember(BusNo,OrigBusRec(:,1));
0057 BusRec(:,8)=OrigBusRec(ind,2);
0058 BusRec(:,9)=OrigBusRec(ind,3);
0059
0060 branchdata = mpcreduced.branch;
0061 branchdata = branchdata(branchdata(:,11)==1,:);
0062 [branchdata,braindex] = sortrows(branchdata,[1,2]);
0063 BranchRec=branchdata;
0064
0065 Sbase=100;
0066 NewBusNo = (1:length(BusNo))';
0067 BusRec(:,1) = NewBusNo;
0068 BranchRec(:,1) = interp1(BusNo,NewBusNo,BranchRec(:,1));
0069 BranchRec(:,2) = interp1(BusNo,NewBusNo,BranchRec(:,2));
0070
0071 ind=find( abs(BranchRec(:,10)) );
0072 flag=0;
0073 if isempty(ind)==0
0074 flag=1;
0075 phase_shifter=BranchRec(ind,:);
0076 end
0077
0078 Bus_V_Mag_PU=BusRec(:,8);
0079 Bus_V_Pha=BusRec(:,9)/180*pi;
0080
0081
0082 BB=zeros(length(BusNo),length(BusNo));
0083 bb=BranchRec(:,4);
0084 BranchRec(BranchRec(:,9)==0,9)=1;
0085 bb=bb.*(BranchRec(:,9));
0086 bb=1./bb;
0087 for i=1:length( BranchRec(:,4) )
0088
0089 m=BranchRec(i,1);
0090 n=BranchRec(i,2);
0091
0092 BB(m,m)=BB(m,m)+bb(i);
0093 BB(n,n)=BB(n,n)+bb(i);
0094
0095 BB(m,n)=BB(m,n)-bb(i);
0096 BB(n,m)=BB(n,m)-bb(i);
0097 end
0098
0099 P_injected2=BB*Bus_V_Pha*Sbase;
0100
0101 if flag==1
0102
0103 B_fix=zeros(length(BB(:,1)),1);
0104 for i=1:length( phase_shifter(:,1) )
0105 B_fix( phase_shifter(i,1) )= B_fix( phase_shifter(i,1) ) - phase_shifter(i,10)*pi/180/phase_shifter(i,4);
0106 B_fix( phase_shifter(i,2) )= B_fix( phase_shifter(i,2) ) + phase_shifter(i,10)*pi/180/phase_shifter(i,4);
0107 end
0108 B_fix=B_fix*Sbase;
0109 end
0110
0111 gen = mpcreduced.gen;
0112 gen(:,2)=resultfull.gen(:,2);
0113 gen(:,1) = interp1(BusNo,NewBusNo,gen(:,1));
0114 Generation = zeros(size(mpcreduced.bus,1),2);
0115 Generation(:,1) = NewBusNo;
0116 for i = 1:size(gen,1)
0117 Generation(gen(i,1),2) = Generation(gen(i,1),2)+gen(i,2);
0118 end
0119 gen(:,1) = interp1(NewBusNo,BusNo,gen(:,1));
0120
0121 if flag==1
0122 P_injected2=P_injected2+B_fix;
0123 end
0124 P_L_should=Generation(:,2)-P_injected2;
0125
0126 if isfield(mpcreduced,'dcline')
0127 dcline = mpcfull.dcline;
0128 HVDC_Line=[dcline(:,1),dcline(:,2),dcline(:,4),dcline(:,5)];
0129 HVDC_Line=sortrows(HVDC_Line,[1 2]);
0130 HVDC_Line(:,1)=interp1(BusNo,NewBusNo,HVDC_Line(:,1));
0131 HVDC_Line(:,2)=interp1(BusNo,NewBusNo,HVDC_Line(:,2));
0132
0133
0134 for i=1:length(HVDC_Line(:,1))
0135 if (BusRec(HVDC_Line(i,1),2)~=4)&&(BusRec(HVDC_Line(i,2),2)~=4)
0136 P_L_should(HVDC_Line(i,1))=P_L_should(HVDC_Line(i,1))-HVDC_Line(i,3);
0137 P_L_should(HVDC_Line(i,2))=P_L_should(HVDC_Line(i,2))+HVDC_Line(i,4);
0138 end
0139 end
0140 end
0141
0142 mpcreduced.bus(:,3)=P_L_should;
0143 mpcreduced.gen = gen;
0144 end