How to solve coupled partial differential equations with method of lines?

26 visualizaciones (últimos 30 días)
I am getting problem in solving the partial differential equations used for modelling of packed bed adsorption column. I have attached the equations which I need to solve.
I solved it using method of lines approach with the help of some code which I got on mathworks ask community. But the graph which I am getting is different from which I need to get.
Can anyone help me in solving these equations?
I am also providing the code which I used to solve.
% parameters
eps = 0.41; % bed porosity
volflow = 5e-7; % volumetric flow rate in m3/sec
dia = 0.022; % bed internal dia in m
bedarea = pi*dia^2/4;
u = volflow/bedarea; % superficial velocity in m/s
Dl = 0.08e-4; % axial dipsersion coefficient in m2/sec
rhop = 1228.5; % particle density
Kl = 0.226; % overall mass transfer coeff in sec-1
P = 102000; % total pressure in pascals
R = 8.314; % gas constant in jol/mol-k
T = 500; % gas temp in K
yco2 = 0.2; % co2 mole fraction
cfeed = yco2*P/(R*T); % feed conc in mol/m3
K0 = 4.31e-9; % in pascal-1
delh = -29380; % heat of adsorption in j/mol
Keq = K0*exp(-delh/(R*T)); % equilibrium constant in pascal-1
% using method of lines
tf = 300; % End time
nz = 400; % Number of gateways
np = nz + 1; % Number of gateposts
% Initial Concentrations
C = zeros(np,1);
q = zeros(np,1);
c0 = [C; q];
dt = tf/300;
tspan = 0:dt:tf;
[t, c] = ode15s(@rates, tspan, c0);
% Plot results
plot(t,c(:,np-4)/cfeed),grid
xlabel('time'), ylabel('C/Cfeed')
function dcdt = rates(~,c)
eps = 0.41; % bed porosity
volflow = 5e-7; % volumetric flow rate in m3/sec
dia = 0.022; % bed internal dia in m
bedarea = pi*dia^2/4;
u = volflow/bedarea; % superficial velocity in m/s
Dl = 0.08e-4; % axial dipsersion coefficient in m2/sec
rhop = 1228.5; % particle density
Kl = 0.226; % overall mass transfer coeff in sec-1
P = 102000; % total pressure in pascals
R = 8.314; % gas constant in jol/mol-k
T = 500; % gas temp in K
yco2 = 0.2; % co2 mole fraction
cfeed = yco2*P/(R*T); % feed conc in mol/m3
K0 = 4.31e-9; % in pascal-1
delh = -29380; % heat of adsorption in j/mol
Keq = K0*exp(-delh/(R*T)); % equilibrium constant in pascal-1
qm = 5.09; % max adsrobed conc in mol/kg
n = 0.429; % toth isotherm parameter
L = 0.171;
nz = 400;
np = nz + 1;
dz = L/nz;
C = c(1:np);
q = c(np+1:2*np);
dCdt = zeros(np,1);
dqdt = zeros(np,1);
% boundary condition at z=0
C(1) = (1/(eps*Dl+u*dz))*((eps*Dl*C(2)+u*cfeed*dz));
for i = 2:np-1
dCdt(i) = (Dl/dz^2)*(C(i+1)-2*C(i)+C(i-1)) - (u/(2*eps*dz))*(C(i+1)-C(i-1)) - (((1-eps)*rhop)/eps)*dqdt(i);
dqdt(i) = Kl*((qm*Keq*C(i)*R*T/(1+(Keq*C(i)*R*T)^n)^(1/n)) - q(i));
end
% boundary conditions at z=L
dCdt(np) = dCdt(np-1);
% Combine rates for the function to return to the calling routine
dcdt = [real(dCdt); real(dqdt)];
end
Here I used time interms of seconds. So when I plot the graph the x-axis is also in seconds and my breakthrough time which I am getting is around 35 seconds. But in the experimental values for showed that the breakthrough time for the graph is around 300 minutes.
so please someone help whether there is any mistake which I am doing in my code.
  4 comentarios
Davide Masiello
Davide Masiello el 31 de Mayo de 2022
What are z+ and z- in the flux boundary condition?
Ari Dillep Sai
Ari Dillep Sai el 31 de Mayo de 2022
C at z+ corresponds to the concentration after entering into the column and C at z- corresponds to the concentration before entering into the column which is inlet concentration

Iniciar sesión para comentar.

Respuesta aceptada

Davide Masiello
Davide Masiello el 31 de Mayo de 2022
Editada: Davide Masiello el 31 de Mayo de 2022
Hi @Ari Dillep Sai, take a look at the code below.
The breakthrough now is found to be sometimes after 4000 s (or ~67 mins), so not the 300 mins you have suggested, but maybe a bit better than the 35 s you were getting before.
Also note the following improvements to the code:
1 - I have passed all the constants as external parameters, so you don't have to define them again in the function.
2 - I have written the method of lines without use of for loops, but with wise use of logical indexing.
3 - ode15s solves a system of DAEs now, which is necessary given the algebraic nature of the boundary conditions for the diffusion equation.
I am not sure this will work for you but it might be a good starting point to develop your final solution.
I suggest you go throught the equations and the values of the parameters again, and ensure that everything is correct.
clear,clc
% Parameters
p.eps = 0.41; % bed porosity
p.volflow = 5e-7; % volumetric flow rate in m3/sec
p.dia = 0.022; % bed internal dia in m
p.bedarea = pi*p.dia^2/4;
p.u = p.volflow/p.bedarea; % superficial velocity in m/s
p.Dl = 0.08e-4; % axial dipsersion coefficient in m2/sec
p.rhop = 1228.5; % particle density
p.Kl = 0.226; % overall mass transfer coeff in sec-1
p.P = 102000; % total pressure in pascals
p.R = 8.314; % gas constant in jol/mol-k
p.T = 500; % gas temp in K
p.yco2 = 0.2; % co2 mole fraction
p.cfeed = p.yco2*p.P/(p.R*p.T); % feed conc in mol/m3
p.K0 = 4.31e-9; % in pascal-1
p.delh = -29380; % heat of adsorption in j/mol
p.Keq = p.K0*exp(-p.delh/(p.R*p.T)); % equilibrium constant in pascal-1
p.qm = 5.09; % max adsrobed conc in mol/kg
p.n = 0.429; % toth isotherm parameter
p.L = 0.171; % bed length
% using method of lines
tf = 300*60; % End time
p.nz = 400; % Number of nodes
z = linspace(0,p.L,p.nz); % Space domain
dz = diff(z); p.dz = dz(1); % Space increment
% Initial conditions
c = zeros(p.nz,1);
q = zeros(p.nz,1);
y0 = [c;q];
tspan = [0 tf];
% Mass matrix (for DAE system)
M = eye(2*p.nz);
M(1,1) = 0;
M(p.nz,p.nz) = 0;
options = odeset('Mass',M,'MassSingular','yes');
[t,y] = ode15s(@(t,y)rates(t,y,p),tspan,y0,options);
% Plot results
plot(t/60,y(:,p.nz)/p.cfeed)
grid
xlabel('time (mins)')
ylabel('C/Cfeed')
title('Dimensionless concentration at ''z = L''')
hold on
plot(t/60,0.05*ones(size(t)),'--r')
legend('C/Cfeed','breakthrough')
function out = rates(~,y,p)
% Variables
c = y(1:p.nz,1);
q = y(p.nz+1:2*p.nz,1);
% Space derivatives
dcdz = zeros(p.nz,1);
d2cdz2 = zeros(p.nz,1);
dcdz(2:end-1) = (c(3:end)-c(1:end-2))/(2*p.dz);
d2cdz2(2:end-1) = (c(3:end)-2*c(2:end-1)+c(1:end-2))/(p.dz^2);
% Saturation
qstar = p.qm*p.Keq*c*p.R*p.T./((1+(p.Keq*c*p.R*p.T).^(p.n)).^(1/p.n));
% Governing equations
dqdt = p.Kl*(qstar-q);
dcdt = p.Dl*d2cdz2-p.u*dcdz/p.eps-p.rhop*(1-p.eps)*dqdt/p.eps;
% Boundary conditions
dcdt(1) = p.eps*p.Dl*(c(2)-c(1))/p.dz+p.u*(p.cfeed-c(1));
dcdt(end) = c(end)-c(end-1);
% Output
out = [dcdt;dqdt];
end
  24 comentarios
Zahra
Zahra el 4 de Nov. de 2024 a las 13:58
the boundary conditions should be written for dcdz not dcdt! To me, it seems that these equations need to be deiscretized at z direction and then be solved by using ode solvers. This is what I am trying to do for my model.
Torsten
Torsten el 4 de Nov. de 2024 a las 19:16
Editada: Torsten el 4 de Nov. de 2024 a las 19:17
the boundary conditions should be written for dcdz not dcdt!
The boundary condition is inserted into the differential equation. Thus you get an expression for dcdt that uses the set boundary condition.
Example:
Equation
dT/dt = a*d^2T/dz^2
with
dT/dz = 0
at the right endpoint z_n.
This gives a differential equation in z_n as
dT/dt @z_n ~
a * (dT/dz @z_n - dT/dz @z_(n-1/2))/(dz/2) = % Use boundary condition dT/dz @z_n = 0 here
-2*a * dT/dz @z_(n-1/2) / dz ~
-2*a * (T @z_n - T @z_(n-1) )/dz^2

Iniciar sesión para comentar.

Más respuestas (1)

Torsten
Torsten el 30 de Mayo de 2022
Editada: Torsten el 30 de Mayo de 2022
The sink term
- (((1-eps)*rhop)/eps)*dqdt(i);
for the concentration of your gaseous species is always 0 because you specify dqdt(i) after dCdt(i) in the for-loop.
Thus the breakthrough is at the time instant
t_break = L/(u/eps)
  4 comentarios
Ari Dillep Sai
Ari Dillep Sai el 30 de Mayo de 2022
Can you please let me know the mistakes in the code?
Ari Dillep Sai
Ari Dillep Sai el 31 de Mayo de 2022
Editada: Ari Dillep Sai el 31 de Mayo de 2022
Hi Torsten,
Can you help me in finding mistakes in my code with the respect to the boundary conditions and modelling equations?

Iniciar sesión para comentar.

Categorías

Más información sobre Chemistry en Help Center y File Exchange.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by