Home > matpower7.0 > extras > reduction > MPReduction.m

MPReduction

PURPOSE ^

Function MPReduction does modified Ward reduction to the full system

SYNOPSIS ^

function [mpcreduced,Link,BCIRCr]=MPReduction(mpc,ExBusOrig,Pf_flag)

DESCRIPTION ^

 Function MPReduction does modified Ward reduction to the full system
 model given in the MATPOWER case file (mpc) based the external buses
 (ExBusOrig)defined by the user.

  [mpcreduced,Link,BCIRCr]=MPReduction(mpc,ExBusOrig,Pf_flag)

 INPUT DATA:
   mpc: struct, includes the full model in MATPOWER case format
   ExBusOrig: n*1 vector, include the bus numbers of buses to be
   eliminated
   Pf_flag: scalar, indicate if dc power flow needed to solve (=1) or not
       (=0) in the load redistribution subroutine
   
 OUTPUT DATA:
   mpcreduced: struct, includes the reduced model in MATPOWER case format
   Link: n*2 matrix, includes the generator mapping info, showing how
       external generators are moved: The first column includes generator bus
       numbers in full model and the second column includes generator bus
       nubmers where the external generators are moved to.
   BCIRCr: n*1 vector, includes branch circuit numbers. This vector can be
       used to identify parallel branches and equivalent lines generated by
       the network reduction process. If a branch number is higher than 1 and
       less then it indicate this branch is parallel to one of the branch in
       the full model. If a branch circuit number is 99 then it indicate this
       branch is an equivalent branch.

 Note: The reduction is based on dc assumption which means all resistance,
 reactive power components will be ignored. And the reduced model is only
 good for solving dc power flow or dc opf. If the input full model case
 file includes dclines, it is assumed that no dc terminal is to be
 eliminated, otherwise the function will return error. If Pf_flag = 1
 which means dc power flow need to be solved during the load
 redistribution process, user must make sure that MATPOWER toolbox is
 installed.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [mpcreduced,Link,BCIRCr]=MPReduction(mpc,ExBusOrig,Pf_flag)
0002 % Function MPReduction does modified Ward reduction to the full system
0003 % model given in the MATPOWER case file (mpc) based the external buses
0004 % (ExBusOrig)defined by the user.
0005 %
0006 %  [mpcreduced,Link,BCIRCr]=MPReduction(mpc,ExBusOrig,Pf_flag)
0007 %
0008 % INPUT DATA:
0009 %   mpc: struct, includes the full model in MATPOWER case format
0010 %   ExBusOrig: n*1 vector, include the bus numbers of buses to be
0011 %   eliminated
0012 %   Pf_flag: scalar, indicate if dc power flow needed to solve (=1) or not
0013 %       (=0) in the load redistribution subroutine
0014 %
0015 % OUTPUT DATA:
0016 %   mpcreduced: struct, includes the reduced model in MATPOWER case format
0017 %   Link: n*2 matrix, includes the generator mapping info, showing how
0018 %       external generators are moved: The first column includes generator bus
0019 %       numbers in full model and the second column includes generator bus
0020 %       nubmers where the external generators are moved to.
0021 %   BCIRCr: n*1 vector, includes branch circuit numbers. This vector can be
0022 %       used to identify parallel branches and equivalent lines generated by
0023 %       the network reduction process. If a branch number is higher than 1 and
0024 %       less then it indicate this branch is parallel to one of the branch in
0025 %       the full model. If a branch circuit number is 99 then it indicate this
0026 %       branch is an equivalent branch.
0027 %
0028 % Note: The reduction is based on dc assumption which means all resistance,
0029 % reactive power components will be ignored. And the reduced model is only
0030 % good for solving dc power flow or dc opf. If the input full model case
0031 % file includes dclines, it is assumed that no dc terminal is to be
0032 % eliminated, otherwise the function will return error. If Pf_flag = 1
0033 % which means dc power flow need to be solved during the load
0034 % redistribution process, user must make sure that MATPOWER toolbox is
0035 % installed.
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 fprintf('%n Reduction process start');
0046 fprintf('%n Preprocess data')';
0047 [mpc,ExBusOrig]=PreProcessData(mpc,ExBusOrig);
0048 dim = size(mpc.bus,1);
0049 %% Modeling
0050 % check if dc terminals are external
0051 if isfield(mpc,'dcline')
0052 tf1 = ismember(mpc.dcline(:,1),ExBusOrig);
0053 tf2 = ismember(mpc.dcline(:,2),ExBusOrig);
0054 if (sum(tf1)+sum(tf2))>0
0055     error('not able to eliminate HVDC line terminals');
0056 end
0057 end
0058 ExBusOrig = ExBusOrig';
0059 if ~isempty(ExBusOrig)
0060 fprintf('\nConvert input data model');
0061 [NFROM,NTO,BraNum,LineB,ShuntB,BCIRC,BusNum,NUMB,SelfB,mpc,ExBus,newbusnum,oldbusnum] = Initiation(mpc,ExBusOrig); % ExBus with internal numbering
0062 %% Create data structure
0063 fprintf('\nCreating Y matrix of input full model');
0064 [CIndx,ERP,DataB]=BuildYMat(NFROM,NTO,BraNum,LineB,BCIRC,BusNum,NUMB,SelfB);
0065 %% Do Reduction
0066 fprintf('\nDo first round reduction eliminating all external buses');
0067 [mpcreduced,BCIRCr,ExBusr] = DoReduction(DataB,ERP,CIndx,ExBus,NUMB,dim,BCIRC,newbusnum,oldbusnum,mpc); % ExBusr with original numbering
0068 %% Generate the second reduction with all retained buses and all generator
0069 %% buses mpcreduced_gen
0070 % Create the ExBus_Gen to create the reduced model with all gens
0071 tf = ismember(ExBus,mpc.gen(:,1));
0072 ExBusGen = ExBus;
0073 ExBusGen(tf==1)=[]; % delete all external buses with generators
0074 tf=ismember(mpc.gen(:,1),ExBus);
0075 fprintf('\n%d external generators are to be placed',length(tf(tf==1)));
0076 if ~isempty(ExBusGen)
0077 fprintf('\nDo second round reduction eliminating all external non-generator buses');
0078 [mpcreduced_gen,BCIRC_gen,ExBusGen] = DoReduction(DataB,ERP,CIndx,ExBusGen,NUMB,dim,BCIRC,newbusnum,oldbusnum,mpc);
0079 else
0080     mpcreduced_gen = mpc;
0081     mpcreduced_gen=MapBus(mpcreduced_gen,newbusnum,oldbusnum);
0082     BCIRC_gen = BCIRC;
0083 end
0084 %% Move Generators
0085 fprintf('\nPlacing External generators');
0086 [NewGenBus,Link]=MoveExGen(mpcreduced_gen,ExBusOrig,ExBusGen,BCIRC_gen,0);
0087 mpcreduced.gen(:,1)=NewGenBus; % move all external generators
0088 %% Do Inverse PowerFlow
0089 fprintf('\nRedistribute loads');
0090 mpc=MapBus(mpc,newbusnum,oldbusnum);
0091 [mpcreduced,BCIRCr]=LoadRedistribution(mpc,mpcreduced,BCIRCr,Pf_flag);
0092 else
0093     mpcreduced = mpc;
0094     warning('No external buses, reduced model is same as full model');
0095 end
0096 %% Delete large reactance equivalent branches
0097 ind=find(abs(mpcreduced.branch(:,4))>=max(mpc.branch(:,4))*10);
0098 mpcreduced.branch(ind,:)=[];
0099 BCIRCr(ind)=[];
0100 %% Print Results
0101 fprintf('\n**********Reduction Summary****************');
0102 fprintf('\n%d buses in reduced model',size(mpcreduced.bus,1));
0103 fprintf('\n%d branches in reduced model, including %d equivalent lines',size(mpcreduced.branch,1),length(BCIRCr(BCIRCr==max(BCIRCr))));
0104 fprintf('\n%d generators in reduced model',size(mpcreduced.gen,1));
0105 if isfield(mpcreduced,'dcline')
0106 fprintf('\n%d HVDC lines in reduced mode,',size(mpcreduced.dcline,1));
0107 end
0108 fprintf('\n**********Generator Placement Results**************');
0109 for i=1:size(Link,1)
0110     if Link(i,2)-Link(i,1)~=0
0111         fprintf('\nExternal generator on bus %d is moved to %d',Link(i,1),Link(i,2));
0112     end
0113 end
0114 fprintf('\n');
0115 
0116 end

Generated on Mon 24-Jun-2019 15:58:45 by m2html © 2005