Home > matpower5.1 > extras > reduction > LoadRedistribution.m

LoadRedistribution

PURPOSE ^

Subroutine LoadRedistribution moves loads in reduced model in order to

SYNOPSIS ^

function [mpcreduced,BCIRCr]=LoadRedistribution(mpcfull,mpcreduced,BCIRCr,Pf_flag)

DESCRIPTION ^

 Subroutine LoadRedistribution moves loads in reduced model in order to
 make the dcpf solution on reduced model identical to the full model with
 external generator placed in subroutine MoveExGen.

   [mpcreduced,BCIRCr]=LoadRedistribution(mpcfull,mpcreduced,BCIRCr,Pf_flag)

 INPUT DATA:
   mpcfull: struct, full model data in MATPOWER case format
   mpcreduced: struct, reduced model data with all external buses
       eliminated in MATPOWER case format
   BCIRCr: 1*n array, includes circuit number of branches in reduced model
   Pf_flag: scalar, indicate if dc power flow need to be solved before
   load redistribution.

 OUTPUT DATA:
   mpcreduced: struct, reduced model data with load redistributed
   BCIRCr: 1*n array, includes reordered branch circuit number in reduced
       model

 NOTE:
   The subroutine will first run a dc power flow on the full model. If the
   dc power flow can not be solved on the full model, the subroutine will
   be terminated and an error will be returned.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [mpcreduced,BCIRCr]=LoadRedistribution(mpcfull,mpcreduced,BCIRCr,Pf_flag)
0002 % Subroutine LoadRedistribution moves loads in reduced model in order to
0003 % make the dcpf solution on reduced model identical to the full model with
0004 % external generator placed in subroutine MoveExGen.
0005 %
0006 %   [mpcreduced,BCIRCr]=LoadRedistribution(mpcfull,mpcreduced,BCIRCr,Pf_flag)
0007 %
0008 % INPUT DATA:
0009 %   mpcfull: struct, full model data in MATPOWER case format
0010 %   mpcreduced: struct, reduced model data with all external buses
0011 %       eliminated in MATPOWER case format
0012 %   BCIRCr: 1*n array, includes circuit number of branches in reduced model
0013 %   Pf_flag: scalar, indicate if dc power flow need to be solved before
0014 %   load redistribution.
0015 %
0016 % OUTPUT DATA:
0017 %   mpcreduced: struct, reduced model data with load redistributed
0018 %   BCIRCr: 1*n array, includes reordered branch circuit number in reduced
0019 %       model
0020 %
0021 % NOTE:
0022 %   The subroutine will first run a dc power flow on the full model. If the
0023 %   dc power flow can not be solved on the full model, the subroutine will
0024 %   be terminated and an error will be returned.
0025 
0026 %   MATPOWER
0027 %   Copyright (c) 2014-2015 by Power System Engineering Research Center (PSERC)
0028 %   by Yujia Zhu, PSERC ASU
0029 %
0030 %   $Id: LoadRedistribution.m 2655 2015-03-18 16:40:32Z ray $
0031 %
0032 %   This file is part of MATPOWER.
0033 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0034 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0035 
0036 if Pf_flag==1
0037 % OPT=mpoption('out.all',0);
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 %% Read the full model bus data
0047 %  [BusID, V_mag, V_angle
0048 OrigBusRec=resultfull.bus(:,[1,8,9]);
0049 OrigBusRec=sortrows(OrigBusRec,1); %reorder bus records
0050 %% Read Bus Data
0051 BusRec = mpcreduced.bus;
0052 BusRec = sortrows(BusRec,1);
0053 BusNo = BusRec(:,1);
0054 
0055 %% Use original bus voltage
0056 [ignore, ind]=ismember(BusNo,OrigBusRec(:,1));
0057 BusRec(:,8)=OrigBusRec(ind,2); % Vm
0058 BusRec(:,9)=OrigBusRec(ind,3); % Vang
0059 %% Read Branch DATA
0060 branchdata = mpcreduced.branch;
0061 branchdata = branchdata(branchdata(:,11)==1,:);
0062 [branchdata,braindex] = sortrows(branchdata,[1,2]);
0063 BranchRec=branchdata;
0064 %% Renumber the branch terminal buses
0065 Sbase=100; %MVA
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 %% read phase shifter information
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 %% Form complex voltage vector
0078 Bus_V_Mag_PU=BusRec(:,8);
0079 Bus_V_Pha=BusRec(:,9)/180*pi;
0080 
0081 %% Form Y Matrix
0082 BB=zeros(length(BusNo),length(BusNo));
0083 bb=BranchRec(:,4);
0084 BranchRec(BranchRec(:,9)==0,9)=1;
0085 bb=bb.*(BranchRec(:,9)); % x/tap
0086 bb=1./bb;
0087 for i=1:length( BranchRec(:,4) )
0088 %     i
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     %% phase_shifter
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); % use the full model solution
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 %% fix the phase shifter
0121 if flag==1
0122     P_injected2=P_injected2+B_fix;
0123 end
0124 P_L_should=Generation(:,2)-P_injected2;
0125 %% dealing with HVDC lines
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     % for HVDC lines if one bus of a line is isolated then the buses on the other end
0133     % of the line will be ignored in the inverse power flow program
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); % YZ compensate HVDC line by adding/reducing the loads from the HVDC flows
0138         end
0139     end
0140 end
0141 %% Plug in the results
0142 mpcreduced.bus(:,3)=P_L_should;
0143 mpcreduced.gen = gen;
0144 end

Generated on Fri 20-Mar-2015 18:23:34 by m2html © 2005