Adsorption Modelling - Solving PDE - Axial Dispersion Model
Show older comments
Dear all,
I am trying to develop a simple model for an adsorption column. I have attached a file that contains the equations that I am trying to solve.
To solve the system, I am trying to solve the axial dispersion model (neglecting pressure drop, and hence, the dv/dz term) alongside the Linear Driving Force (LDF) model, which gives an expression for dq/dt in the axial dispersion PDE (see attached file). I am also using the Langmuir equation to give an expression for q* (equilibrium concentration) in the LDF equation.
Unknown variables are q and c, all other variables are known (i.e. D, v, epsilon etc.( / are the independent variables (i.e. time, t, and length, z).
I have tried using the Method of Lines to solve this system (again, see attached file), but I am aware that the system I have developed is flawed.
Any suggestions on how to approach this problem would be appreciated. I would preferably like to solve the system using either a PDE solver or ode45 applied to the method of lines.
My code so far is as follows:
Data File:
%%Constants
D = 3*10^-8; % Axial Dispersion coefficient
v = 1*10^-3; % Superficial velocity
epsilon = 0.4; % Voidage fraction
k = 3*10^-5; % Mass Transfer Coefficient
bH = 2.5*10^-5; % Langmuir parameter for H2
L = 1; % Column length
%%MoL Coefficients & Mesh Generation
N = 20;
dz = L/N;
z = [0:dz:L];
% MoL Coefficients from Discretisation
alph = ((D/(dz^2)) + ((v)/(2*dz)));
bet = ((-2*D)/(dz^2));
gamm = ((D/(dz^2)) - ((v)/(2*dz)));
%%Initial / Boundary Conditions
% Initial condition for ODE 1:
c0 = 0; % C at t = 0 for all z
% Boundary Condition for ODE 1:
cFeed = 10; % C at z = 0 for all t
qs = (1+bH*cFeed)/(bH*cFeed); % Conc. of adsorbed phase at surface saturation
% Initial Condition for ODE 2:
q0 = qs*((bH*cFeed)/(1+bH*cFeed))-1; % Initial concentration in adsorbed phase
% Time Boundaries
t0 = 0;
tf = 10000;
% Initial equilibrium conc.
qeq0 = qs*((bH*c0)/(1+bH*c0));
dq0 = k*qeq0;
Solving using ODE45:
close all
clear all
clc
% Call Data File
DataFile;
tspan = [0:10000];
[t,c] = ode45('cprime', tspan, c0);
Cprime file
function [ dcdt ] = cprime(~, c)
% Call data file to define constants
DataFile;
t=t0;
q = q0;
[dqdt] = qprime(t, q, k, qs, bH, c);
%%Create Tri-diagonal Matrix A
A = zeros(N,N);
for i = 2 : N-1
A(i, i-1) = alph;
A(i, i) = bet;
A(i, i+1) = gamm;
end
A(1,1) = bet;
A(1,2) = gamm;
A(N,N-1) = alph+gamm;
A(N-1, N) = gamm;
A(N,N) = bet;
b = ones(N,1);
b(1) = cFeed*alph-((1-epsilon)/(epsilon)*(k*(qeq-q)));
dcdt = (A*c + b);
end
qprime file:
function [dqdt] = qprime(~, q, k, qs, bH, c)
DataFile;
qeq = qs*((bH*c)/(1+bH*c));
dqdt = k*(qeq-q);
end
I am really struggling to figure out how to structure my code / approach these equations.
Any help would be muchly appreciated!
Thanks!
46 Comments
ALOK PRASAD
on 28 May 2018
Ashley Gratton
I am also developing the same the model. Can you please send me the code as I am having problem in generating it?
Thanks
Alok Prasad
Ashley Gratton
on 28 May 2018
ALOK PRASAD
on 28 May 2018
Edited: ALOK PRASAD
on 28 May 2018
Ashley, That will of great use. I have just started modelling so I am using only one adsorbate and neglecting the axial dispersion term and also trying to get the breakthrough curves.Your help will be of great use. Actually I am discretizing in both spatial and time domain.Thus getting nonlinear algebraic equations. Can you suggest me any numerical method by which it can be solved? Thanks
Ashley Gratton
on 28 May 2018
ALOK PRASAD
on 28 May 2018
Thanks a lot. Actually I am assuming it to be a plug flow that's why neglected the axial term .What's the problem in your mentioned code?
Ashley Gratton
on 28 May 2018
Ashley Gratton
on 28 May 2018
ALOK PRASAD
on 29 May 2018
Edited: ALOK PRASAD
on 29 May 2018
Ashley, Thanks a lot. Actually I am having problem in selection of step size in both time and size domain. Can you suggest me any way to get rid of such problem? Thanks Alok
ALOK PRASAD
on 30 May 2018
Hey Ashley, Thanks a lot. I am able to run the program, but the problem is that I am not able to get the proper breakthrough curves. In the curve, concentration remains zero for sometime and it starts increasing which is quite obvious as the adsorbent is on the verge of saturation. But after sometime the curve should attain a constant value but instead of that its oscillating. What could be the possible reason? Your help will be very much appreciated. Thanks, Alok
Ashley Gratton
on 30 May 2018
ALOK PRASAD
on 30 May 2018
ODE 45..chosen boundary conditions are c(z=0,t)=co(constant feed concentration) , c(z,t=0)=0 and q(z,t=0)=0. How to choose time step size or mesh grid size to make it stable? Could you please help me in sorting it out? Thanks
ALOK PRASAD
on 4 Jun 2018
Hello Sir, Can we use the same technique for the system having multiadsorbate? Thanks
Ashley Gratton
on 4 Jun 2018
ALOK PRASAD
on 7 Jun 2018
Edited: ALOK PRASAD
on 7 Jun 2018
Thanks Ashley for such a great help. But I am having the same problem as the curve begin to oscillate after reaching the the inlet bulk phase adsorbate concentration value.Can you provide me your email so that I can forward my program to you. I have attached the plot that I got. Thanks
ALOK PRASAD
on 17 Jun 2018
hey ashley, in case of multiadsorbate system, velocity should not be taken as a constant value. Then how to evaluate the the du/dt term? Can this be calculated using overall mass balance? Thanks
Ashley Gratton
on 17 Jun 2018
ALOK PRASAD
on 22 Jun 2018
Thanks a lot Ashley I just want to know that how have you discretized dc/dz. I know that ode45 uses unequispaced grid points so we have to discretized it by considering the same. But how to do that? Thanks
Ashley Gratton
on 22 Jun 2018
ALOK PRASAD
on 22 Jun 2018
Edited: ALOK PRASAD
on 22 Jun 2018
Whatever you said I got that very well. But the way you have discretized the term dc/dz and d2c/dz2 is the main problem. Using central difference on dc/dz at any point I will get (c(i+1)-c(i-1))/2*dz. But you had different way in you program. Please can you clarify my doubts? Thanks
Ashley Gratton
on 22 Jun 2018
ALOK PRASAD
on 29 Jun 2018
Thanks Ashley, In case of multiadsorbate apart from the langmuir extended equation, what are the modification that one should kept in mind to make the program? Thanks
Ashley Gratton
on 29 Jun 2018
ALOK PRASAD
on 29 Jun 2018
Ashley Gratton
on 29 Jun 2018
ALOK PRASAD
on 30 Jun 2018
Extremely sorry. I have send you the wrong code. The code for multi-adsorbate system is attached below.
ALOK PRASAD
on 2 Jul 2018
hey Ashley can you please look at the program? Thanks
ALOK PRASAD
on 2 Jul 2018
Hey Ashley. Can you please tell me that what can we do with the D2c/Dz2 term at z=L? Thanks
ALOK PRASAD
on 9 Jul 2018
HEY ASHLEY CAN YOU PLEASE LOOK AT THE ATTACHED PROGRAM IN ABOVE COMMENTS? THANKS
ALOK PRASAD
on 16 Jul 2018
Hi Ashley .. Can we use ODE 15s for in case of multiadsorbate? Thanks
ALOK PRASAD
on 30 Jul 2018
Hi Ashley, From where I can get the values of qmax ,Kldf and b(langmuir parameter) for the adsorption of Carbondioxide and nitrogen on activated carbon? Thanks
ALOK PRASAD
on 23 Aug 2018
Hi Ashley, hope you are doing well. I have a question, suppose I have a fixed bed and I have to operate it at 10 bar pressure and gas is entering the column at atmospheric pressure, I know the mole fraction of species in the gas and thus I can calculate their partial pressure using Ptot * mole_fraction where Ptot is the atmospheric pressure. Now I have the mass balance equation for the component using that I can easily get the breakthrough curves. The question is that no where I have used the column pressure in my equation so how to accommodate that 10 bar pressure in my calculation? Thanks
Nelson Guy
on 21 Nov 2018
Hello, were you able to run the multiadsorbate breakthrough code?
ALOK PRASAD
on 26 Dec 2018
Yes @Nelson Guy
Are you doing the same thing?
ALOK PRASAD
on 24 Mar 2019
Hi,
Can we code the desorption of a bed saturated with some gas by applying vacuum?
Can you tell me the governing equations associated with the same?
Thanks
Nelson Guy
on 27 Apr 2019
Hello Ashok
Yes i am tryin to do the same thing.
I would also need to mimick breakthroughs binary system propane/propylene 50/50 on zeolite using perhaps the code above, any ideas?
Regards
Nelson
Nelson Guy
on 29 Apr 2019
ashok were you able to get the vaccum desorption equations?
ALOK PRASAD
on 28 May 2019
Hello Nelson Guy
The rate of adsorption and desorption is governed by difference in adsorbed phase concentration at the particle surface in equilibrium with local and instantaneous bulk phase concentration and average adsorbed phase concentration.
Hence the governing equations wll remain same as that of we used in the adsorption process.But still I am not able to get the solution. Did you get the equations and solution for vaccum desorption? Any kind of help will help me a lot.
Regards
Alok
Nelson Guy
on 4 Jul 2019
Hi Alok. No, i was not able to resolve the VA.
In a differenot note were you able to generate the code for binary gases mixtures (say Propane/Propylene etc) on Zeolite or porous media?
I used an IAST code but does not seem to work. Can you share your code for 2 gases mixtures?
best
Nelson
LUIS MOLLERICON
on 8 Jul 2019
Hi,
I just saw the model in the pdf document, and I noticed that the linear driving force model applied is a function of the same "q". Shouldnt it be expresed as a concentration difference?
I really appreciate your help
Best regards
Luis
Nelson Guy
on 9 Jul 2019
alok can you please share the multiadsorbate breakthrough code?
ALOK PRASAD
on 11 Sep 2019
are you done with the single adsorbate case?
AJITA GUPTA
on 15 Oct 2020
Hi Alok, I am solving the same kind of problem but unable to get breakthrough curve can you share your code so that I can see where I am going wrong.
Drew Moxon
on 11 Nov 2021
What are the units of x-axis 'time'?
Ridhwan Lawal
on 3 May 2022
Hello @Ashley Gratton please Did you find a solution to your problem? I am havin this exact same challenge with my project too
Federico Urbinati
on 19 Oct 2022
hi halok
did you manage to define the matlab code for multiadsorbate system?
I can't go ahead, can you publish it?
if you want I can give you a contact to write to us in private
Thanks in advance
federico
Accepted Answer
More Answers (7)
Abraham Boayue
on 2 Mar 2018
1 vote
Hey Ashley, referring to Equation 1.1 in your paper, q appeared as a partial differential equation and then as an ODE in Eq 1.5, can you tell why it is so? If it is a PDE, what are the initial and boundary conditions on q (C has these conditions given but not for q, recall that when you solve an ODE without the initial conditions given, you obtain a general solution, with these conditions given, you can obtain a particular solution), these conditions are necessary to obtain reasonable solutions. Do you have an idea of the kind of plot that you are expecting from the solutions of your equations, a plot would be helpful to allow others to work on the problem. I am trying to apply finite difference method to solve the problem, but would need some answers to my questions.
8 Comments
Ashley Gratton
on 3 Mar 2018
Abraham Boayue
on 5 Mar 2018
You are very much welcome Ash, I will keep you posted if I am successful. Good luck for now.
AB
Nelson Guy
on 24 Apr 2019
Edited: Nelson Guy
on 24 Apr 2019
Hello
I used the same code for mimicking breakthrough curve for single gas adsorption on solid zeolite- fixed bed.
%Assumed plug flow, langmuir, Dubinin-A, LDF
% Initialization
close all
clear all
clc
%System Set-up %
%Propane Zeolite
D = 3.37*10^-13; % Axial Dispersion coefficient [m^2/s]
v =1*10^-3; % Superficial velocity [m/s]
epsilon = 0.4; % Voidage fraction []
k = 0.02516; % Mass Transfer Coefficient [1/s]
cFeed = 10; % Feed concentration [mol/m^3]
d=1285720; % density zeolite [g/m^3]Y-DP
L = 0.1; % Column length [m]
%isotherm parameters
E=6224;
W0=41.72*4.4615;
n=0.8646;
b=10^(-4);
qs=2.5;
%Gas parameters
Temp=273.15+60; %Temperature
ps=869200; %Saturation pressure of gas
R=8.3144621; %Gas constant
Cs=ps/(R*Temp);
qe=@(C) qs*b*C/(1+b*C);
%qe=@(C) W0*exp(-(R*Temp*log(Cs./C)/E).^n);
t0 = 0; % Initial Time
tf = 10000; % Final time
dt = 100; % Time step
z = [0:L/20:L]; % Mesh generation
t = [t0:dt:tf]; % Time vector
n = numel(z); % Size of mesh grid
%Initial Conditions / Vector Creation
c0 = zeros(n,1);
c0(1) = cFeed;
q0 = zeros(n,1); % t = 0, q = 0 for all z, this makes sense to me
y0 = [c0 ; q0]; % Appends conditions together
%ODE15S Solver
[T, Y] = ode23s(@(t,y) user(t,y,z,n,D,v,epsilon,k,d,qe),t,y0);
plot(T,Y);
%filename = 'testdata.xlsx';
%xlswrite(filename,[t.' T Y])
function DyDt=user(~, y, z, n,D,v,epsilon,k,d,qe)
% Variables being allocated zero vectors
c = zeros(n,1);
q = zeros(n,1);
DcDt = zeros(n,1);
DqDt = zeros(n,1);
DyDt = zeros(2*n,1);
zhalf = zeros(n-1,1);
DcDz = zeros(n,1);
D2cDz2 = zeros(n,1);
c = y(1:n);
q = y(n+1:2*n);
% Interior mesh points
zhalf(1:n-1)=(z(1:n-1)+z(2:n))/2;
for i=2:n-1
DcDz(i) = ((z(i)-z(i-1))/(z(i+1)-z(i))*(c(i+1)-c(i))+(z(i+1)-z(i))/(z(i)-z(i-1))*(c(i)-c(i-1)))/(z(i+1)-z(i-1));
D2cDz2(i) = (zhalf(i)*(c(i+1)-c(i))/(z(i+1)-z(i))-zhalf(i-1)*(c(i)-c(i-1))/(z(i)-z(i-1)))/(zhalf(i)-zhalf(i-1));
end
% Calculate DcDz and D2cDz2 at z=L for boundary condition dc/dz = 0
DcDz(n) = 0;
D2cDz2(n) = -1.0/(z(n)-zhalf(n-1))*(c(n)-c(n-1))/(z(n)-z(n-1));
% Set time derivatives at z=0
% DcDt = 0 since c=cFeed remains constant over time and is already set as initial condition
% Standard setting for q
DqDt(1) = k*( qe(c(1)) - q(1) );
DcDt(1) = 0.0;
% Set time derivatives in remaining points
for i=2:n
%Equation: dq/dt = k(q*-q) where q* = qs * (b*c)/(1+b*c)
DqDt(i) = k*( qe(c(i)) - q(i) );
%Equation: dc/dt = D * d2c/dz2 - v/e*dc/dz - (d*(1-e)/(e))*dq/dt
DcDt(i) = D*D2cDz2(i) - (v/epsilon)*DcDz(i) - (d*(1-epsilon)/(epsilon))*DqDt(i);
end
% Concatenate vector of time derivatives
DyDt = [DcDt;DqDt];
end
But aftter sometimes the curve starts oscillating. AGAIN Same question above Why please? is this a bounday condition, mesh or time step issue etc?
Regards
Nelson
Ashley Gratton
on 24 Apr 2019
Edited: Ashley Gratton
on 24 Apr 2019
Torsten
on 24 Apr 2019
Change the corresponding lines to:
z = [0:L/500:L]; % Mesh generation
plot(z,Y(30,1:n).',z,Y(60,1:n).',z,Y(90,1:n).');
DcDz(i) = (c(i)-c(i-1))/(z(i)-z(i-1));
instead of
z = [0:L/20:L]; % Mesh generation
plot(T,Y);
DcDz(i) = ((z(i)-z(i-1))/(z(i+1)-z(i))*(c(i+1)-c(i))+(z(i+1)-z(i))/(z(i)-z(i-1))*(c(i)-c(i-1)))/(z(i+1)-z(i-1));
Nelson Guy
on 25 Apr 2019
Edited: Nelson Guy
on 28 Apr 2019
Thanks, it worked this way:
z = [0:L/500:L]; % Mesh generation
plot(T,Y);
DcDz(i) = (c(i)-c(i-1))/(z(i)-z(i-1));
I would like to perform a binary mixture 50% Propane and 50% Propylene breakthroughs for selectivity purposes?
Any ideas for the code below
%Assumed plug flow, langmuir, Dubinin-A, LDF
% Initialization
close all
clear all
clc
%System Set-up %
%Propane/Propylene zeolite
D1 =3.37E-13; % Axial Dispersion coefficient [m^2/s] of propane
D2= 1.61E-12; % Axial Dispersion coefficient [m^2/s] of propylene
v =1*10^-3; % Superficial velocity [m/s]
epsilon = 0.4; % Voidage fraction []
k1 =0.02516; % Mass Transfer Coefficient [1/s] of propane
k2 =0.2074; % Mass Transfer Coefficient [1/s] of propylene
c1Feed=5; % Feed concentration [mol/m^3]of propane
c2Feed=5; % Feed concentration [mol/m^3]of propylene
d=1285720; % density acetylftw [g/m^3]Y-DP
L = 0.1; % Column length [m]
%isotherm parameters
E=6224;
W0=41.72*4.4615;
n=0.8646;
b1=10^(-4);
qs1=53;
b2= 10^(-3);
qs2=56;
%Gas parameters
Temp=273.15+60; %Temperature
ps=869200; %Saturation pressure of gas
R=8.3144621; %Gas constant
Cs=ps/(R*Temp);
qe=@(C1,C2) (qs1*b1*C1/(1+b1*C1))+(qs2*b2*C2/(1+b2*C2));
%qe=@(C1,C2) W01*exp(-(R*Temp*log(Cs1./C1)/E1).^n1)+W02*exp(-(R*Temp*log(Cs2./C2)/E2).^n2);
t0 = 0; % Initial Time
tf = 10000; % Final time
dt = 100; % Time step
z = [0:L/500:L]; % Mesh generation
t = [t0:dt:tf]; % Time vector
n = numel(z); % Size of mesh grid
%Initial Conditions / Vector Creation
c01 = zeros(n,1);
C02=zeros(n,1);
c01(1) = c1Feed;
c02(1)=c2Feed;
q01 = zeros(n,1); % t = 0, q = 0 for all z
q02=zeros(n,1);
y01 = [c01 ; q01]; % Appends conditions together
y02=[c02;q02]
%ODE15S Solver
[T1, Y1] = ode23s(@(t,y1) user(t,y1,z,n,D1,v,epsilon,k1,d1,qe1),t,y01);
[T2, Y2] = ode23s(@(t,y2) user(t,y2,z,n,D2,v,epsilon,k2,d2,qe2),t,y02);
plot(T1,Y1);
plot(T2,Y2);
filename = 'testdata.xlsx';
xlswrite(filename,[t.' T1 Y1 T2 Y2])
function DyDt=user(~, y, z, n,D,v,epsilon,k,d,qe)
% Variables being allocated zero vectors
c1 = zeros(n,1);
c2= zeros(n,1);
q1 = zeros(n,1);
q2= zeros(n,1);
Dc1Dt = zeros(n,1);
Dc2Dt = zeros(n,1);
Dq1Dt = zeros(n,1);
Dq2Dt = zeros(n,1);
Dy1Dt = zeros(2*n,1);
Dy2Dt = zeros(2*n,1);
zhalf = zeros(n-1,1);
Dc1Dz = zeros(n,1);
Dc2Dz = zeros(n,1);
D2c1Dz2 = zeros(n,1);
D2c2Dz2 = zeros(n,1);
c1 = y1(1:n);
c2 = y2(1:n);
q1= y1(n+1:2*n);
q2= y2(n+1:2*n);
% Interior mesh points
zhalf(1:n-1)=(z(1:n-1)+z(2:n))/2;
for i=2:n-1
DcDz(i) = (c(i)-c(i-1))/(z(i)-z(i-1));
D2cDz2(i) = (zhalf(i)*(c(i+1)-c(i))/(z(i+1)-z(i))-zhalf(i-1)*(c(i)-c(i-1))/(z(i)-z(i-1)))/(zhalf(i)-zhalf(i-1));
end
% Calculate DcDz and D2cDz2 at z=L for boundary condition dc/dz = 0
DcDz(n) = 0;
D2cDz2(n) = -1.0/(z(n)-zhalf(n-1))*(c(n)-c(n-1))/(z(n)-z(n-1));
% Set time derivatives at z=0
% DcDt = 0 since c=cFeed remains constant over time and is already set as initial condition
% Standard setting for q
Dq1Dt(1) = k1*( qe1(c1(1)) - q1(1) );
Dq2Dt(1) = k2*( qe2(c2(1)) - q2(1) );
Dc1Dt(1) = 0.0;
Dc2Dt(1) = 0.0;
% Set time derivatives in remaining points
for i=2:n
%Equation: dq/dt = k(q*-q) where q* = qs * (b*c)/(1+b*c)
Dq1Dt(i) = k1*( qe1(c1(i)) - q1(i) );
Dq2Dt(i) = k2*( qe2(c2(i)) - q2(i) );
%Equation: dc/dt = D * d2c/dz2 - v/e*dc/dz - (d*(1-e)/(e))*dq/dt
Dc1Dt(i) = D1*D2c1Dz2(i) - (v/epsilon)*Dc1Dz(i) - (d1*(1-epsilon)/(epsilon))*Dq1Dt(i);
Dc2Dt(i) = D2*D2c2Dz2(i) - (v/epsilon)*Dc2Dz(i) - (d2*(1-epsilon)/(epsilon))*Dq2Dt(i);
end
% Concatenate vector of time derivatives
Dy1Dt = [Dc1Dt;Dq1Dt];
Dy2Dt = [Dc2Dt;Dq2Dt];
end
Regards
N
Nelson Guy
on 27 Apr 2019
and Thanks Ash and Trosten.
Nelson
Nelson Guy
on 4 Jul 2019
any clues Ash and Trosten for modeling binary gas mixtures in breakthrough mode? say Propane/Propylene
Abraham Boayue
on 5 Mar 2018
1 vote
I still have come up with a reasonable solution, but I am making some progress so far. Here is an image that I obtained from using the finite difference method. Take a look at it and tell me what you think.
Abraham Boayue
on 5 Mar 2018
1 vote
An image-
2 Comments
Ashley Gratton
on 6 Mar 2018
Abraham Boayue
on 6 Mar 2018
The graphs represent the concentration profile. The x axis is the timeline and the vertical axis shows how the concentration depreciates over time.
Abraham Boayue
on 6 Mar 2018
0 votes
I am using the following papers as a guide: http://www.cellulosechemtechnol.ro/pdf/CCT7-8(2014)/p.717-726.pdf
Patricia Sáez González
on 10 Sep 2019
function main
% Initialisation
close all
clear all
clc
%System Set-up %
%Define Variables
D = 3*10^-8; % Axial Dispersion coefficient
v = 1*10^-3; % Superficial velocity
epsilon = 0.4; % Voidage fraction
k = 3*10^-5; % Mass Transfer Coefficient
b = 2.5*10^-5; % Langmuir parameter
qs = 2*10^4; % Saturation capacity
cFeed = 10; % Feed concentration
L = 1; % Column length
t0 = 0; % Initial Time
tf = 1000; % Final time
dt = 0.5; % Time step
z = [0:0.01:L]; % Mesh generation
t = [t0:dt:tf];% Time vector
n = numel(z); % Size of mesh grid
%Initial Conditions / Vector Creation
c0 = zeros(n,1);
c0(1) = cFeed;
q0 = zeros(n,1); % t = 0, q = 0 for all z, this makes sense to me
y0 = [c0 ; q0]; % Appends conditions together
%ODE15S Solver
[T, Y] = ode15s(@(t,y) MyFun(t,y,z,n),t,y0);
plot(T,Y);
end
function DyDt=MyFun(~, y, z, n)
% Defining Constants
D = 3*10^-8; % Axial Dispersion coefficient
v = 1*10^-3; % Superficial velocity
epsilon = 0.4; % Voidage fraction
k = 3*10^-5; % Mass Transfer Coefficient
b = 2.5*10^-5; % Langmuir parameter
qs = 20000; % Saturation capacity
% Variables being allocated zero vectors
c = zeros(n,1);
q = zeros(n,1);
DcDt = zeros(n,1);
DqDt = zeros(n,1);
DyDt = zeros(2*n,1);
zhalf = zeros(n-1,1);
DcDz = zeros(n,1);
D2cDz2 = zeros(n,1);
c = y(1:n);
q = y(n+1:2*n);
% Interior mesh points
zhalf(1:n-1)=(z(1:n-1)+z(2:n))/2;
for i=2:n-1
DcDz(i) = ((z(i)-z(i-1))/(z(i+1)-z(i))*(c(i+1)-c(i))+(z(i+1)-z(i))/(z(i)-z(i-1))*(c(i)-c(i-1)))/(z(i+1)-z(i-1));
D2cDz2(i) = (zhalf(i)*(c(i+1)-c(i))/(z(i+1)-z(i))-zhalf(i-1)*(c(i)-c(i-1))/(z(i)-z(i-1)))/(zhalf(i)-zhalf(i-1));
end
% Calculate DcDz and D2cDz2 at z=L for boundary condition dc/dz = 0
DcDz(n) = 0;
D2cDz2(n) = -1.0/(z(n)-zhalf(n-1))*(c(n)-c(n-1))/(z(n)-z(n-1));
% Set time derivatives at z=0
% DcDt = 0 since c=cFeed remains constant over time and is already set as initial condition
% Standard setting for q
DqDt(1) = k*( ((qs*b*c(1))/(1 + b*c(1))) - q(1) );
DcDt(1) = 0.0;
% Set time derivatives in remaining points
for i=2:n
%Equation: dq/dt = k(q*-q) where q* = qs * (b*c)/(1+b*c)
DqDt(i) = k*( ((qs*b*c(i))/(1 + b*c(i))) - q(i) );
%Equation: dc/dt = D * d2c/dz2 - v*dc/dz - ((1-e)/(e))*dq/dt
DcDt(i) = D*D2cDz2(i) - v*DcDz(i) - ((1-epsilon)/(epsilon))*DqDt(i);
end
% Concatenate vector of time derivatives
DyDt = [DcDt;DqDt];
end
This is the code which I am using. I don't have much knowledge about Matlab but I need to finish the code for my thesis. My question is, I need to model a fixed bed to obtain the breakthrough curves, so, I would like to know how to obtain these curves (C/C0 vs t) from this code. I would appreciate any help. Thank you very much!
4 Comments
Torsten
on 10 Sep 2019
function main
%System Set-up %
%Define Variables
%D = 3*10^-8; % Axial Dispersion coefficient
%v = 1*10^-3; % Superficial velocity
%epsilon = 0.4; % Voidage fraction
%k = 3*10^-5; % Mass Transfer Coefficient
%b = 2.5*10^-5; % Langmuir parameter
%qs = 2*10^4; % Saturation capacity
cFeed = 10; % Feed concentration
L = 1; % Column length
t0 = 0; % Initial Time
%tf = 1000; % Final time
tf = 2000; % Final time
dt = 0.5; % Time step
% z=[0:0.01:L]; %Mesh generation
z = [0:0.0005:L]; %Mesh generation
t = [t0:dt:tf];% Time vector
n = numel(z); % Size of mesh grid
%Initial Conditions / Vector Creation
c0 = zeros(n,1);
c0(1) = cFeed;
q0 = zeros(n,1); % t = 0, q = 0 for all z, this makes sense to me
y0 = [c0 ; q0]; % Appends conditions together
%ODE15S Solver
[T, Y] = ode15s(@(t,y) MyFun(t,y,z,n),t,y0);
%plot(T,Y);
plot(T,Y(:,n)/cFeed)
end
function DyDt=MyFun(~, y, z, n)
% Defining Constants
D = 3*10^-8; % Axial Dispersion coefficient
v = 1*10^-3; % Superficial velocity
epsilon = 0.4; % Voidage fraction
k = 3*10^-5; % Mass Transfer Coefficient
b = 2.5*10^-5; % Langmuir parameter
qs = 20000; % Saturation capacity
% Variables being allocated zero vectors
c = zeros(n,1);
q = zeros(n,1);
DcDt = zeros(n,1);
DqDt = zeros(n,1);
DyDt = zeros(2*n,1);
zhalf = zeros(n-1,1);
DcDz = zeros(n,1);
D2cDz2 = zeros(n,1);
c = y(1:n);
q = y(n+1:2*n);
% Interior mesh points
zhalf(1:n-1)=(z(1:n-1)+z(2:n))/2;
for i=2:n-1
%DcDz(i) = ((z(i)-z(i-1))/(z(i+1)-z(i))*(c(i+1)-c(i))+(z(i+1)-z(i))/(z(i)-z(i-1))*(c(i)-c(i-1)))/(z(i+1)-z(i-1));
DcDz(i) = (c(i)-c(i-1))/(z(i)-z(i-1));
D2cDz2(i) = (zhalf(i)*(c(i+1)-c(i))/(z(i+1)-z(i))-zhalf(i-1)*(c(i)-c(i-1))/(z(i)-z(i-1)))/(zhalf(i)-zhalf(i-1));
end
% Calculate DcDz and D2cDz2 at z=L for boundary condition dc/dz = 0
DcDz(n) = 0;
D2cDz2(n) = -1.0/(z(n)-zhalf(n-1))*(c(n)-c(n-1))/(z(n)-z(n-1));
% Set time derivatives at z=0
% DcDt = 0 since c=cFeed remains constant over time and is already set as initial condition
% Standard setting for q
DqDt(1) = k*( ((qs*b*c(1))/(1 + b*c(1))) - q(1) );
DcDt(1) = 0.0;
% Set time derivatives in remaining points
for i=2:n
%Equation: dq/dt = k(q*-q) where q* = qs * (b*c)/(1+b*c)
DqDt(i) = k*( ((qs*b*c(i))/(1 + b*c(i))) - q(i) );
%Equation: dc/dt = D * d2c/dz2 - v*dc/dz - ((1-e)/(e))*dq/dt
DcDt(i) = D*D2cDz2(i) - v*DcDz(i) - ((1-epsilon)/(epsilon))*DqDt(i);
end
% Concatenate vector of time derivatives
DyDt = [DcDt;DqDt];
end
Abhijit
on 21 Apr 2020
Hi Torsten, The nth location is showing q data instead of c data. The typical breakthrough is obtained up to n-1th location, i.e., by plotting plot(T,Y(:,n-1)/cFeed), I am getting the breakthrough curve at the outlet. Please help me as I couldn't find the reason of this anomaly. Thanks! The code helps me a lot.
Luis Gilberto Domínguez López
on 25 May 2020
Hi there!
You have help me a lot with this code thank you so much. I was wondering what would happen if instead of a "step" change (breakthrough analysis) you make a rectangular pulse of concentration. I was trying to implement this change in the code unseccesfully because of my lack of experience. could you give some advice?

nashwa tarek
on 13 Jul 2020
hi patricia ,
i want to ask you , your code doesnt study the effect of initial concentration, can you have a clue what if i want to study the effect of concentration with the column length and the velocity
nashwa tarek
on 4 Jul 2020
0 votes
function main
%System Set-up %
%Define Variables
%D = 3*10^-8; % Axial Dispersion coefficient
%v = 1*10^-3; % Superficial velocity
%epsilon = 0.4; % Voidage fraction
%k = 3*10^-5; % Mass Transfer Coefficient
%Kf=2.5*10^-5; %freundlish parameter
%nf= 1.45; %freundlish constant
cFeed = 10; % Feed concentration
L = 1; % Column length
t0 = 0; % Initial Time
%tf = 1000; % Final time
tf = 2000; % Final time
dt = 0.5; % Time step
% z=[0:0.01:L]; %Mesh generation
z = [0:0.0005:L]; %Mesh generation
t = [t0:dt:tf];% Time vector
n = numel(z); % Size of mesh grid
%Initial Conditions / Vector Creation
c0 = zeros(n,1);
c0(1) = cFeed;
q0 = zeros(n,1); % t = 0, q = 0 for all z, this makes sense to me
y0 = [c0 ; q0]; % Appends conditions together
%ODE15S Solver
[T, Y] = ode15s(@(t,y) MyFun(t,y,z,n),t,y0);
%plot(T,Y);
plot(T,Y(:,n)/cFeed)
end
function DyDt=MyFun(~, y, z, n)
% Defining Constants
D = 3*10^-8; % Axial Dispersion coefficient
v = 1*10^-3; % Superficial velocity
epsilon = 0.4; % Voidage fraction
k = 3*10^-5; % Mass Transfer Coefficient
Kf=2.5*10^-5; %freundlish parameter
nf= 1.45; %freundlish constant
% Variables being allocated zero vectors
c = zeros(n,1);
q = zeros(n,1);
DcDt = zeros(n,1);
DqDt = zeros(n,1);
DyDt = zeros(2*n,1);
zhalf = zeros(n-1,1);
DcDz = zeros(n,1);
D2cDz2 = zeros(n,1);
c = y(1:n);
q = y(n+1:2*n);
% Interior mesh points
zhalf(1:n-1)=(z(1:n-1)+z(2:n))/2;
for i=2:n-1
%DcDz(i) = ((z(i)-z(i-1))/(z(i+1)-z(i))*(c(i+1)-c(i))+(z(i+1)-z(i))/(z(i)-z(i-1))*(c(i)-c(i-1)))/(z(i+1)-z(i-1));
DcDz(i) = (c(i)-c(i-1))/(z(i)-z(i-1));
D2cDz2(i) = (zhalf(i)*(c(i+1)-c(i))/(z(i+1)-z(i))-zhalf(i-1)*(c(i)-c(i-1))/(z(i)-z(i-1)))/(zhalf(i)-zhalf(i-1));
end
% Calculate DcDz and D2cDz2 at z=L for boundary condition dc/dz = 0
DcDz(n) = 0;
D2cDz2(n) = -1.0/(z(n)-zhalf(n-1))*(c(n)-c(n-1))/(z(n)-z(n-1));
% Set time derivatives at z=0
% DcDt = 0 since c=cFeed remains constant over time and is already set as initial condition
% Standard setting for q
DqDt(1) = k*(kf*(c(1)^(1/nf))-q(1));
DcDt(1) = 0.0;
% Set time derivatives in remaining points
for i=2:n
%Equation: dq/dt = K(q*-q) where q*=kf*(c^(1/nf))
DqDt(i) = k*(kf*(c(i)^(1/nf))-q(i));
%Equation: dc/dt = D * d2c/dz2 - v*dc/dz - ((1-e)/(e))*dq/dt
DcDt(i) = D*D2cDz2(i) - v*DcDz(i) - ((1-epsilon)/(epsilon))*DqDt(i);
end
% Concatenate vector of time derivatives
DyDt = [DcDt;DqDt];
end
This is the code which I am using. I don't have much knowledge about Matlab but I need to finish the code for my thesis. My question is, I need to model a fixed bed to obtain the breakthrough curves using freundlish isotherm, so, I would like to know how to obtain these curves (C/C0 vs t) from this code. i cant run this code i dont know where is the problem. I would appreciate any help. Thank you very much
Federico Urbinati
on 18 Oct 2022
0 votes
hi does anyone have the matlab code to solve adsorption when you have multiple components and not just one?
I hope someone can answer, I can not go forward. thank you
Categories
Find more on Multicore Processor Targets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!