% INDMAT.M %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Index matrices
%There are six sections in the DWC; The order of stage numbering section
%wise is started from C11,C12 (Prefrac), C21,C22,C23,C24 (Main column),
%Refer to figure in the Master thesis Ambari Khanam (2013)
%No. of stages in each section=12 (coldata.Nt=[12 12 12 12 12 12])
%No. of states in ecah section is 2*coldata.Nt(section), each section
%contains 24 states (12 for comp A and 12 for comp B) and then comes the
%next section. 
global coldata
%states numbering in the prefractionator
im_x1 = 1:2 * coldata.Nt(1);                   % 24 (12 for A and 12 for B)  states in C11 (prefractionator)
im_x2 = im_x1(end) + [1:2 * coldata.Nt(2)];    %25-48 states in C12 (Prefrac)
% States numbering in the main column
im_x21 = im_x2(end) + [1:2 * coldata.Nt(3)];   %49-24*3=72 states in C21 (Main column)
im_x22 = im_x21(end) + [1:2 * coldata.Nt(4)];  %73-24*4=96 states in C22
im_x23 = im_x22(end) + [1:2 * coldata.Nt(5)];  %97-24*5=120 states in C23
im_x24 = im_x23(end) + [1:2 * coldata.Nt(6)];  %111-24*6=144 states in C24
% States, Reboiler, condenser and side stream 
im_xr = im_x24(end) + [1:2];                   %145 146, comp A and B of reboiler stage
im_xt = im_xr(end) + [1:2];                    %147, 148, of condenser
im_xS1 = im_xt(end) + [1:2];                   %149,150, of side stream 

%Holdups in the prefractionator
im_m1 = im_xS1(end) + [1:coldata.Nt(1)];       %150-162, trays holdups C11
im_m2 = im_m1(end) + [1:coldata.Nt(2)];        %163-174, trays holdups C12

%Holdups in the main column
im_m21 =  im_m2(end) + [1:coldata.Nt(3)];      %175-186, trays holdups C21
im_m22 = im_m21(end) + [1:coldata.Nt(4)];      %187-198, trays holdups C22
im_m23 = im_m22(end) + [1:coldata.Nt(5)];      %199-210, trays holdups C23
im_m24 = im_m23(end) + [1:coldata.Nt(6)];      %211-222, trays holdups C24
%Reboiler, tank and side stream holdups
im_mr = im_m24(end) + 1;                       %223,     Reboiler
im_mt = im_mr(end) + 1;                        %224,     Condenser tank
im_mS1 = im_mt(end) + 1;                       %225,     Side stream collector
%Reshape the matrix to get comp A and B on the same stage, further to use
%for temperature calculation
II1=reshape(im_x1,coldata.Nt(1),2);
II2=reshape(im_x2,coldata.Nt(2),2);
II3=reshape(im_x21,coldata.Nt(3),2);
II4=reshape(im_x22,coldata.Nt(4),2);
II5=reshape(im_x23,coldata.Nt(5),2);
II6=reshape(im_x24,coldata.Nt(6),2);


     
















