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