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

In summary: Your problem with the high values is due to your explicit method and is common when the values you're solving for are large. I will get back to you.In summary, the conversation is about solving a 1-D diffusion equation using the Forward-Time Central-Space (FTCS) scheme. The code has been written for it, but the results are not satisfactory as they give high values. The main algorithm for the method is discussed and a better method is suggested for solving the problem. The issue of high values is attributed to the explicit method used.
  • #1
Juliousceasor
25
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
  • #2
Can you post the results? What do they look like? What don't you like about them?
 
  • #3
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: 547
  • #4
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.
 
  • #5
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
 
  • #6
I have a better method, I don't have time now but I will post one later this evening.
 

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

1. What is the 1D diffusion equation?

The 1D diffusion equation is a mathematical model used to describe the movement of a substance or particles in one-dimensional space. It is also known as the heat equation or the diffusion equation.

2. What does the 1D diffusion equation represent?

The 1D diffusion equation represents the change in concentration or temperature of a substance over time and space due to the random movement of particles.

3. What are the key assumptions made in the 1D diffusion equation?

The key assumptions in the 1D diffusion equation are that the substance being diffused is evenly distributed, the diffusion is one-dimensional, and there are no external forces acting on the substance.

4. How is the 1D diffusion equation solved?

The 1D diffusion equation can be solved using various analytical or numerical methods, such as separation of variables, Fourier transform, or finite difference methods.

5. What are some real-world applications of the 1D diffusion equation?

The 1D diffusion equation has many applications in fields such as physics, chemistry, biology, and engineering. It is used to model diffusion processes in various systems, including heat transfer, chemical reactions, and fluid flow.

Back
Top