Solving partial differential equations using pdepe solver

5 次查看(过去 30 天)
I have to solve two coupled partial differential equations which I have attached below. I used pdepe solver for those equations but I am getting error. I would like to know whether I can solve such equations with pdepe solver.
I have written the following code for the above equations.
% paramters
global P R T L epsf pel tc epstar beta Keq cref yin sh gamma p
% paramters
L = 6e-2; % in m
epsf = 0.43;
beta = 46.65;
Keq = 75;
epstar = epsf + Keq*beta;
pel = 21.73;
tc = 140e-3; % in sec
P = 1e5; % in pascals
R = 8.314; % in j/mol-k
T = 323; % in K
cref = P/(R*T); % in mol/m3
yin = 2420;
sh = 4.51;
gamma = 0.111;
p = 0.0326;
% defining mesh
xmesh = linspace(0,1,300);
tmesh = linspace(0,1500,500);
% using pdepe solver
m = 0;
sol = pdepe(m,@adsorp,@adsorpic,@adsorpbc,xmesh,tmesh);
% % plotting results
% plot(tmesh,sol(:,end)*1e6*R*T/P)
% xlabel('time (sec)')
% ylabel('concentration (ppm)')
function [c,f,s] = adsorp(x,t,u,dudx)
global epsf beta pel sh p gamma Keq
c = [epsf; beta];
f = [((1/pel)*dudx(1));0 ];
s = [-dudx(1)-(sh/p)*(u(1)-(gamma*u(1)+beta*u(2)/Keq)/(gamma+beta*(1-u(2)))); (sh/p)*(u(1)-(gamma*u(1)+beta*u(2)/Keq)/(gamma+beta*(1-u(2))))];
end
function u0 = adsorpic(x)
u0 = [0;0];
end
function [pl,ql,pr,qr] = adsorpbc(xl,ul,xr,ur,t)
global yin
pl = [ul(1)-yin;0];
ql = [1;0];
pr = [0;0];
qr = [1;0];
end
when I am running above code I am getting error as follows:
Error using pdepe (line 293)
Spatial discretization has failed. Discretization supports only parabolic and elliptic equations, with flux term
involving spatial derivative.
Error in systemofpdesusingpdepe (line 27)
sol = pdepe(m,@adsorp,@adsorpic,@adsorpbc,xmesh,tmesh);
Can someone please tell whether the pdepe solver can be used for these type of problems? Also suggestions on the method to solve above equations is very much appreciated.

采纳的回答

Torsten
Torsten 2022-6-9
编辑:Torsten 2022-6-9
Some people say, one can take pdepe for this kind of problem (e.g. Bill Greene), I'd say one shouldn't because it's problematic.
The second equation is a pure ordinary differential equation without spatial derivatives. Thus boundary conditions for it cannot be imposed. And you did this: you didn't impose boundary conditions. But pdepe expects them at both ends. So one way to artificially deal with this problem is to set pl(2) = pr(2) = 0, ql(2) = qr(2) = 1. Try if the results come out to be reasonable.
And I think your boundary condition for y_f in the code has the wrong sign (at least the sign compared to your attached image is reversed).
Why do you try pdepe ? Your code using the method of lines was ok in my opinion. It's not a problem with the code, but with the adsorption parameters that caused that the breakthrough was too early.
  7 个评论
Torsten
Torsten 2022-6-10
E.g. if you multiply p.K0 by a factor of 8, you get a breakthrough time at about 300 minutes.
Rahmat Sunarya
Rahmat Sunarya 2023-5-1
I see my style of coding here similar to inscript below :)
Thank You
clc
clear
close all
% parameters
L=6e-2;
epsf=0.43;
Keq=74;
pel = 21.73;
Def=11.8e-4;
P = 1e5;
R = 8.314;
T = 50+273;
yin = 2420;
Cin=(yin*1e-6*P)/(R*T);
uf=0.43;
sh =4.51;
p = 0.0326;
gamma = 0.111;
beta = 46.65;
% creating step size
Nz=301;
z=linspace(0,L,Nz);
dz=z(2)-z(1);
% creating time steps
t=linspace(0,15000,500);
% initial Conditions
IC_A=zeros(1,Nz); %for C
IC_B=zeros(1,Nz); %for q
IC=[IC_A, IC_B];
% using ode solver
[t,y]=ode15s(@f12,t,IC);
% plotting results
plot(t,y(:,end)*1e6*R*T/P)
function dydt=f12(~,y)
L=6e-2;
epsf=0.43;
Keq=74;
pel = 21.73;
Def=11.8e-4;
P = 1e5;
R = 8.314;
T = 50+273;
yin = 2420;
Cin=(yin*1e-6*P)/(R*T);
uf=0.43;
sh =4.51;
p = 0.0326;
gamma = 0.111;
beta = 46.65;
Nz=301;
z=linspace(0,L,Nz);
dz=z(2)-z(1);
dCdt=zeros(Nz,1);
dqdt=zeros(Nz,1);
C=y(1:Nz); %for C
q=y(Nz+1:2*Nz); %for q
% B.C at x = 0
C(1) = Cin;
% creating interior points
for i=2:Nz-1
dqdt(i)=(sh/(p*beta))*(C(i)-(gamma*C(i)+beta*q(i)/Keq)/(gamma+beta*(1-q(i))));
dCdt(i)=(-1/(2*dz*epsf))*(C(i+1)-C(i-1)) + (1/(dz^2*epsf*pel))*(C(i+1)-2*C(i)+C(i-1)) - (beta/epsf)*dqdt(i);
end
dCdt(Nz) = dCdt(Nz-1);
dydt=[dCdt;dqdt];
end

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by