Can You Help Me Solve a 1D Diffusion Equation with a FTCS Scheme?

Click For Summary
SUMMARY

The forum discussion centers on solving a 1D diffusion equation using the Forward Time Central Space (FTCS) scheme. The equation is defined as dc/dt = D*d^2c/dx^2 - Lc, with boundary conditions involving a Dirac delta function. The user has implemented a MATLAB code but is obtaining unsatisfactory numerical results, which are significantly higher than expected compared to the analytical solution. Key issues identified include the placement of boundary condition updates within the time-stepping loop, which may affect computational efficiency and accuracy.

PREREQUISITES
  • Understanding of 1D diffusion equations and their boundary conditions
  • Familiarity with the Forward Time Central Space (FTCS) numerical scheme
  • Proficiency in MATLAB programming, particularly with matrix operations
  • Knowledge of numerical methods for solving partial differential equations
NEXT STEPS
  • Review MATLAB's built-in functions for solving parabolic equations
  • Learn about the stability criteria for the FTCS scheme in numerical analysis
  • Investigate alternative numerical methods for solving diffusion equations, such as implicit schemes
  • Explore techniques for optimizing MATLAB code to improve computational efficiency
USEFUL FOR

Researchers, engineers, and students working with numerical simulations of diffusion processes, particularly those using MATLAB for solving partial differential equations.

Juliousceasor
Messages
23
Reaction score
0
I have a 1_D diffusion equation

dc/dt = D*d^2c/dx^2-Lc

where L,D = constants

I am trying to solve the equation above by following b.c. by FTCS scheme

-D*dc/dx = J0*delta(t); where delta(t)= dirac delta function ----(upper boundary)

I have written the code for it

but i just don't get the satisfactory answers. Could anyone help?

% --- Define constants and initial condition
clc;
clear;

L = 0.02; % length of domain in x direction
I0 = 0.0000829*24*60*60; % Bq m^-2 day^-1
L1 = (0.693/53.2); % Decay constant day^-1
tmax = 120; % end time
nx = 90;% number of nodes in x direction
nt = 121; % number of time steps
dx = L/(nx-1);
dt = tmax/(nt-1);
alpha= 2.5*10^-13*24*3600;
r = alpha*dt/dx^2; rr = 1 - 2*r-L1*dt;
v = 2.5*10^-6; % Convection velocity m day^-1
J0 = I0/sqrt(L1*alpha); % total inventory of Be-7 in soil
% --- Create arrays to save data for export
x = linspace(0,L,nx);
t = linspace(0,tmax,nt);
U = zeros(nx,nt);

% --- Set IC and BC
U(:,1)= 0;

% --- Loop over time steps

for m= 2:nt
U(1,m) = J0; %--- Upper boundary
U(end,m) = 0; %--- Lower boundary

for i= 2:nx-1


U(i,m) = r*U(i-1,m-1)+ rr*U(i,m-1)+ r*U(i+1,m-1);


end
end
 
Physics news on Phys.org
Can you post the results? What do they look like? What don't you like about them?
 
The numerical results are giving me very high values. I also have the analytical solution to it. I have posted a figure(please see the attachment). Blue dots in the figure is the numerical solution and the very small red line (which is hardly visible) is the analytical solution. I just do not understand what wrong with my Program. Could you help?
 

Attachments

  • result.jpg
    result.jpg
    14.3 KB · Views: 596
Trying to understand the method from someones MATLAB code is hard, I use MATLAB a great deal, it's a wonderful piece of kit. I believe it has an inbuilt parabolic equation solver, if that would be of any help for you.

Can you write you algorithm out (preferably in LaTeX) so I can see what you're doing please.

I will say one thing now though, you have the lines:
U(1,m) = J0; %--- Upper boundary
U(end,m) = 0; %--- Lower boundary
inside your double loop. It is good programming practice to keep these out of the looping as for one it cuts down on computational time and secondly it may inadvertently affect your algorithm.
 
First boundary condition is discretized as

D*dU/dx = D* (U(i+1,m)-U(i-1,m))/(2*dx)

The main differential equation is dicrretized as

d^2U/dx^2= (U(i+1,m)-2*U(i,m)+U(i-1,m))/(dx^2)--------(1)

dU/dt = (U(i,m+1)-U(i,m))/dt------------------------(2)

Using discretizations (1) and (2) in the main differential equation and reaaranging it we get,

U(i,m+1) = r*U(i-1,m)+ rr*U(i,m)+ r*U(i+1,m); (this is the main loop of the method)

here r = D*dt/dx^2; rr = 1 - 2*r-L*dt;

I hope this helps
 
I have a better method, I don't have time now but I will post one later this evening.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 1 ·
Replies
1
Views
6K
Replies
1
Views
2K
  • · Replies 41 ·
2
Replies
41
Views
10K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 0 ·
Replies
0
Views
7K
  • · Replies 23 ·
Replies
23
Views
6K