Subroutine BuildYMat construct the addmittance matrix and store it in a compact storage format in order to apply sparse technique. [CIndx,ERP,DataB]=BuildYMat(NFROM,NTO,BraNum,LineB,BCIRC,BusNum,NUMB,SelfB) INPUT DATA: NFROM: 1*n array, includes bus indices of from end buses of every branch NTO: 1*n array, includes bus indices of to end buses of every branch BraNum: scalar, number of branaches NUMB: 1*n array, bus indices SelfB: 1*n array, total B shunts on every bus (B shunt on bus and half the branch B shunt) OUTPUT DATA: CIndx: 1*n array, includes column indices of every row in the addmittance matrix ERP: 1*n array, includes end of row pointers of the admittance matrix DataB: 1*n array, includes admittance values in the admittance matrix
0001 function [CIndx,ERP,DataB]=BuildYMat(NFROM,NTO,BraNum,LineB,BCIRC,BusNum,NUMB,SelfB) 0002 % Subroutine BuildYMat construct the addmittance matrix and store it in a 0003 % compact storage format in order to apply sparse technique. 0004 % 0005 % [CIndx,ERP,DataB]=BuildYMat(NFROM,NTO,BraNum,LineB,BCIRC,BusNum,NUMB,SelfB) 0006 % 0007 % INPUT DATA: 0008 % NFROM: 1*n array, includes bus indices of from end buses of every 0009 % branch 0010 % NTO: 1*n array, includes bus indices of to end buses of every branch 0011 % BraNum: scalar, number of branaches 0012 % NUMB: 1*n array, bus indices 0013 % SelfB: 1*n array, total B shunts on every bus (B shunt on bus and half 0014 % the branch B shunt) 0015 % 0016 % OUTPUT DATA: 0017 % CIndx: 1*n array, includes column indices of every row in the 0018 % addmittance matrix 0019 % ERP: 1*n array, includes end of row pointers of the admittance matrix 0020 % DataB: 1*n array, includes admittance values in the admittance matrix 0021 0022 % MATPOWER 0023 % Copyright (c) 2014-2015 by Power System Engineering Research Center (PSERC) 0024 % by Yujia Zhu, PSERC ASU 0025 % 0026 % $Id: BuildYMat.m 2655 2015-03-18 16:40:32Z ray $ 0027 % 0028 % This file is part of MATPOWER. 0029 % Covered by the 3-clause BSD License (see LICENSE file for details). 0030 % See http://www.pserc.cornell.edu/matpower/ for more info. 0031 0032 %% Initialization 0033 ERP = 0:BusNum; % consider two things: 1. 0 at the begining, 2. diagonal element is non-zero for every row 0034 %%%% Be aware of 1. Isolated buses; 2. Offline branches 0035 %% Read the branch one by one 0036 %first generate the ERP array 0037 for i=1:BraNum 0038 if BCIRC(i)==1 % if the circuit number is not 1, then the line is parallel line and the index will not increment 0039 ERP((NFROM(i)+1):(BusNum+1)) = ERP((NFROM(i)+1):(BusNum+1))+1; 0040 ERP((NTO(i)+1):(BusNum+1)) = ERP((NTO(i)+1):(BusNum+1))+1; 0041 end 0042 end 0043 %second generate the CIndx and Data array; 0044 DataB = zeros(1,ERP(BusNum+1)); 0045 % DataG = AssignSpace(ERP(BusNum+1)); 0046 CIndx = zeros(1,ERP(BusNum+1)); 0047 ICLP = ERP; 0048 ICLP = ICLP+1; 0049 ICLP(BusNum+1) = []; 0050 ICLP=[0,ICLP]; 0051 CIndx(ICLP(2:BusNum+1))=NUMB; 0052 ICLP(2:BusNum+1)=ICLP(2:BusNum+1)+1; % first consider all diagonal elements 0053 0054 %b = 1./BranchData(:,4); 0055 for i = 1:BraNum; 0056 0057 %% 0058 DataB(ICLP([NFROM(i)+1,NTO(i)+1]))=DataB(ICLP([NFROM(i)+1,NTO(i)+1]))-LineB(i); 0059 %% 0060 if i<BraNum 0061 if BCIRC(i+1)==1 0062 CIndx(ICLP([NFROM(i)+1,NTO(i)+1]))=[NTO(i),NFROM(i)]; 0063 ICLP([NFROM(i)+1,NTO(i)+1])=ICLP([NFROM(i)+1,NTO(i)+1])+1; 0064 end 0065 else 0066 CIndx(ICLP([NFROM(i)+1,NTO(i)+1]))=[NTO(i),NFROM(i)]; 0067 end 0068 0069 end 0070 for i = 1:BusNum 0071 DataB(ERP(NUMB(i))+1)=DataB(ERP(NUMB(i))+1)+SelfB(i); 0072 end 0073 0074 end