You are on page 1of 3

MAIN PROGRAM CODE DuncanToor_dgms

% Discrete GMS applied to two bulb diffusion


% Run 3 of Duncan and Toor
% MATLAB program

clear;
clf;

% Enter time for composition value


nt = 7000; % number time steps
tend = 70; % hours

% 1 = hydrogen, 2 = nitrogen, 3 = carbon dioxide


% Calculate the Maxwell-Stefan Diffusivities using Fuller, 1969.
n = 3; % number of components
T = 308.35; % temp, K
P = 101325; % press, Pa
M = [2.02;28.02;44.01]; % vector of mole wts
V = [6.12;18.5;26.7]; % vector of diffusion volumes
C = 1.013e-2; % constant for Fuller equation
DMS= zeros(n);
for i = 1:n;
for j = 1:n;
if i == j
DMS(i,j) = 0;
else
DMS(i,j) = C*T^1.75*sqrt((M(i)+M(j))/(M(i)*M(j)))/...
(P*(V(i)^(1/3)+V(j)^(1/3))^2); % m^2/s
end
end
end

% Set initial composition of each bulb (0 = left, L = right), I know.. no


sense
x00 = [0.50056;0.49954;0];
x0L = [0.49923;0;0.50077];

% Volumes of the two bulbs;


V0 = 77.99e-6; % m^3
VL = 78.63e-6; % m^3

% Length and cross-sectional area of capillary


L = 85.9e-3; % m
A = 3.3282e-6; % m^2

% Cell constant
beta = (V0+VL)/(V0*VL)*(A/L);

% Equilibrium composition
xinf = (V0*x00+VL*x0L)/(V0+VL);

% Compute compositions at all t


dt = tend/nt*3600;
x0 = zeros(n,nt+1);
x0(1:n,1) = x00;
xL(1:n,1) = ((V0+VL)*xinf(1:n)-V0*x0(1:n,1))/VL;

for l = 1:nt+1;

% Fick diffusivities
Dfick = Dms_Dfick(DMS, x0(1:n,l));
% discrete update of compositions
for i = 1:(n-1);
x0(i,l+1) = x0(i,l) - dt*beta*Dfick(i,1:n-1)*(x0(1:n-1,l)-xinf(1:n-1));
end
x0(n,l+1) = 1-sum(x0(1:n-1,l+1));
% Compute values for right bulb
xL(1:n,l+1) = ((V0+VL)*xinf(1:n)-V0*x0(1:n,l+1))/VL;

end

% Plot the values of composition in left bulb with time

r = 0:dt/3600:(nt+1)*dt/3600;

subplot(1,2,1)
plot(r,x0)
xlabel('time, hrs')
ylabel('mole fraction')
title('Duncan & Toor Run3 - Left Bulb')
legend('H2','N2','CO2')

subplot(1,2,2)
plot(r,xL)
xlabel('time, hrs')
ylabel('mole fraction')
title('Duncan & Toor Run3 - Right Bulb')
legend('H2','N2','CO2')

FUNCTION CODE - DFICK

function Dfick = Dms_Dfick(Dms, x)


%*********************************************************************
% This routine calculates Fickian diffusion coefficients based on
% Maxwell-Stefan coefficients.
%
% INPUT: (n x n) Matrix of Maxwell-Stefan diffusion coefficients
% (x) Vector of compositions
% OUTPUT: (n-1 x n-1) Matrix of Fickian diffusion coefficients
%*********************************************************************

n = max(size(Dms));
B = zeros(n-1);
% Calculate the elements of the "B" matrix according to equation 2.1.22
for i=1:1:n-1
for j=1:1:i-1
B(i,j) = -x(i) * (1/Dms(i,j)-1/Dms(i,n));
end
for j=i+1:1:n-1
B(i,j) = -x(i) * (1/Dms(i,j)-1/Dms(i,n));
end
end
% Now correct the diagonal elements of the "B" matrix using equation 2.1.21
for i=1:n-1
sumTerm = 0;
for k=i+1:n
sumTerm = sumTerm + x(k)/Dms(i,k);
end
for k=1:i-1
sumTerm = sumTerm + x(k)/Dms(i,k);
end
B(i,i) = x(i)/Dms(i,n) + sumTerm;
end
Dfick = inv(B);

You might also like