Solve piecewise PDE system

8 views (last 30 days)
Aaron Löwenstein
Aaron Löwenstein on 8 Sep 2020
Commented: J. Alex Lee on 18 Sep 2020
I am trying to solve a system of PDEs describing the diffusion and reaction of 4 different substances.
The reaction is as follows:
The concentration of E does not matter and is not calculated.
My eqn. system is set up as
as the system is symmetric,
The initial conditions are defined piecewise, so that there are three different regions with differing concentrations initially.
The boundary condition is no flux over the edges of the system:
My code is
clear vars; close all;
DH = 9.31e-5; % cm^2 s^-1
DOH = 5.3e-5; % cm^2 s^-1
DDMP = 2.25e-5; % cm^2 s^-1
DAcetone = 1.28e-5; % cm^2 s^-1
T = 298; % K
global R
R = 3.144; % J K^-1 mol^-1
% concentration guesses
scale_factor = 3;
cDMP_A = 0.4*scale_factor; % mol L^-1
cDMP_B = 0*scale_factor;
cDMP_C = 0*scale_factor;
cOH_A = 0.35*scale_factor; % mol L^-1
cH_A = 1e-14/cOH_A;
cOH_B = 1e-7; % mol L^-1
cH_B = 1e-7;
cH_C = 0.251*scale_factor;
cOH_C = 1e-14/cH_C;
% define mesh
x = 0:0.001:1.379;
t = 0:0.001:60;
sol = pdepe(0, @(x, t, u, dudx)pdefunc(x, t, u, dudx, [DDMP; DAcetone; DH; DOH], T), @(x)pdeic(x, 0.1895, 1.1895, 1.379, cDMP_A, cH_A, cOH_A, cH_C, cOH_C), @pdebc, x, t);
% functions
function [c, f, s] = pdefunc(x, t, u, dudx, D, T)
global R
c = ones(4, 1);
f = D.*dudx;
s = [-7.32e10.*exp(-46200/(R.*T)).*u(1).*u(3); ...
7.32e10.*exp(-46200/(R.*T)).*u(1).*u(3); ...
-1e20.*u(3).*u(4);
-1e20.*u(3).*u(4)];
end
function u0 = pdeic(x, xa, xb, xc, cDMP_A, cH_A, cOH_A, cH_C, cOH_C)
if x >= 0 && x <= xa
u0 = [cDMP_A; ...
0; ...
cH_A; ...
cOH_A];
elseif x > xa && x <= xb
u0 = [0; ...
0; ...
1e-7; ...
1e-7];
elseif x > xb && x <= xc
u0 = [0; ...
0; ...
cH_C;
cOH_C];
end
end
function [pl, ql, pr, qr] = pdebc(xl, ul, xr, ur, t)
pl = [0; 0; 0; 0];
pr = [0; 0; 0; 0];
ql = [1; 1; 1; 1];
qr = [1; 1; 1; 1];
end
The output I get is
Warning: Failure at t=7.476760e-13. Unable to meet integration tolerances without reducing the step size below the smallest value allowed
(1.615587e-27) at time t.
Expected output: Solved PDE.
How can I change my code to let it calculate my concentrations successfully?
  9 Comments
Aaron Löwenstein
Aaron Löwenstein on 18 Sep 2020
I never heard about the CFL condition before and just read about it. How I understand pdepe is that it uses different timesteps internally in order to try and yield stable solutions and then interpolates the solution at the time steps that one provides. This means that pdepe is supposed to deal with this condition, if I am not mistaken.
J. Alex Lee
J. Alex Lee on 18 Sep 2020
agree...i also wondered at first if your very sharp steps (in space) in the initial conditions will be problematic...what if you try smoothing out the IC into more sigmoidal shapes...do you get the same oscillations?

Sign in to comment.

Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!