% ------------------------------%
% TERNARY COMPOSITION DIAGRAMS  %
% Stathis Skouras, January 2002 %
% ----------------------------- %
% Stages at top section
NT1=25;
% Stages at botton section
NT2=25;
% Total stages (icluding the three vessels)
NT=NT1+NT2+3;

% Creates the ternary diagram
X = [0 2*sqrt(3)/3];
Y = [0 0];
plot(X,Y,'k') 
hold on
axis off
axis([0 2*sqrt(3)/3 0 1])
axis equal
X = [0 sqrt(3)/3];
Y = [0 1];
plot(X,Y,'k') 
X = [sqrt(3)/3 2*sqrt(3)/3]; 
Y = [1 0];  
h=gca;
text(sqrt(3)/3-0.1,1.07,'Ethanol [sn]'); h2=get(h,'Children');set(h2(1),'FontWeight','bold'); 
text(sqrt(3)/3-0.055,1.035,'78.3 ^oC'); h3=get(h,'Children');set(h3(1),'FontSize',10);
text(2*sqrt(3)/3-0.12,-0.04,'Benzene [sn]');h2=get(h,'Children');set(h2(1),'FontWeight','bold');
text(2*sqrt(3)/3-0.06,-0.08,'80.1 ^oC'); h3=get(h,'Children');set(h3(1),'FontSize',10);
text(-0.1,-0.04,'Water [sn]');h2=get(h,'Children');set(h2(1),'FontWeight','bold');
text(-0.060,-0.08,'100 ^oC'); h3=get(h,'Children');set(h3(1),'FontSize',10);

text(2*sqrt(3)/3-0.25,0.5,'hom.az [s]');h2=get(h,'Children');set(h2(1),'FontWeight','bold');
text(2*sqrt(3)/3-0.20,0.46,'68 ^oC'); h3=get(h,'Children');set(h3(1),'FontSize',10);
text(2*sqrt(3)/3-0.82,0.97,'hom.az [s]');h2=get(h,'Children');set(h2(1),'FontWeight','bold');
text(2*sqrt(3)/3-0.79,0.93,'78.2 ^oC'); h3=get(h,'Children');set(h3(1),'FontSize',10);

text(2*sqrt(3)/3-0.45,-0.04,'het.az [s]');h2=get(h,'Children');set(h2(1),'FontWeight','bold');
text(2*sqrt(3)/3-0.41,-0.08,'69 ^oC'); h3=get(h,'Children');set(h3(1),'FontSize',10);
text(2*sqrt(3)/3-0.61,0.28,'het.az [un]');h2=get(h,'Children');set(h2(1),'FontWeight','bold');
text(2*sqrt(3)/3-0.57,0.24,'66.1 ^oC'); h3=get(h,'Children');set(h3(1),'FontSize',10);

text(2*sqrt(3)/3-0.55,0.6,'F');h2=get(h,'Children');set(h2(1),'FontWeight','bold');


%text(2*sqrt(3)/3-1.30,0.85,'Serafimov^,s class 3.1-2');h2=get(h,'Children');set(h2(1),'FontWeight','bold');
text(2*sqrt(3)/3-1.40,0.75,'....... still path');h2=get(h,'Children');set(h2(1),'FontWeight','bold');
text(2*sqrt(3)/3-1.40,0.65,'-o-o- column liquid profile');h2=get(h,'Children');set(h2(1),'FontWeight','bold');

plot(X,Y,'k') 


% --------------------------------------------
% Feed composition
% --------------------------------------------
Xf1=0.6;
Xf2=0.2;
tf1=Xf1;
tf3=1-Xf1-Xf2;
tf2=2*sqrt(3)/3 - sqrt(3)/3*tf1 - 2*sqrt(3)/3*tf3;
plot(tf2,tf1,'ko')


% --------------------------------------------
% Column composition profile
% ---------------------------------------------
load Xss
% Light component
Xp1=Xss(1:NT);
% Intermediate component
Xp2=Xss(NT+1:2*NT);
% Creates the 'triangle' compositions
% Light component
tx1=Xp1;
% Heavy component
tx3=1-Xp1-Xp2;
% Intermediate component
tx2=2*sqrt(3)/3 - sqrt(3)/3*tx1 - 2*sqrt(3)/3*tx3;
plot(tx2,tx1,'k-.o')


load x

% --------------------------------------------
% Top vessel path
% ---------------------------------------------
% Light component
Xt1=x(:,1);
% Intermediate component
Xt2=x(:,NT+1);
% Creates the 'triangle' compositions
% Light component
tx1=Xt1;
% Heavy component
tx3=1-Xt1-Xt2;
% Intermediate component
tx2=2*sqrt(3)/3 - sqrt(3)/3*tx1 - 2*sqrt(3)/3*tx3;
%plot(tx2,tx1,'r.')

% --------------------------------------------
% Middle vessel path
% ---------------------------------------------
% Light component
Xm1=x(:,NT1+2);
% Intermediate component
Xm2=x(:,NT+NT1+2);
% Creates the 'triangle' compositions
% Light component
tx1=Xm1;
% Heavy component
tx3=1-Xm1-Xm2;
% Intermediate component
tx2=2*sqrt(3)/3 - sqrt(3)/3*tx1 - 2*sqrt(3)/3*tx3;
%plot(tx2,tx1,'k.')

% --------------------------------------------
% Bottom vessel path
% ---------------------------------------------
% Light component
Xb1=x(:,NT);
% Intermediate component
Xb2=x(:,2*NT);
% Creates the 'triangle' compositions
% Light component
tx1=Xb1;
% Heavy component
tx3=1-Xb1-Xb2;
% Intermediate component
tx2=2*sqrt(3)/3 - sqrt(3)/3*tx1 - 2*sqrt(3)/3*tx3;
plot(tx2,tx1,'k.')