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

Click For Summary

Discussion Overview

The discussion revolves around solving a one-dimensional diffusion equation using the Forward Time Centered Space (FTCS) scheme. Participants are exploring numerical methods, boundary conditions, and the comparison of numerical results with analytical solutions.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant presents a diffusion equation and describes their implementation of the FTCS scheme in MATLAB, expressing dissatisfaction with the numerical results.
  • Another participant requests the numerical results and seeks clarification on what aspects are unsatisfactory.
  • A participant mentions having an analytical solution and shares a figure comparing the numerical and analytical results, indicating that the numerical values are excessively high.
  • One participant suggests that understanding someone else's MATLAB code can be challenging and recommends writing out the algorithm in LaTeX for clarity. They also advise moving boundary condition assignments outside the main loop for efficiency.
  • A participant provides discretization methods for the boundary condition and the main differential equation, detailing how they arrive at the main loop of the algorithm.
  • Another participant hints at having a potentially better method but does not provide details at the moment.

Areas of Agreement / Disagreement

Participants express varying levels of understanding and satisfaction with the numerical results, with no consensus on the correctness of the implementation or the results. Multiple approaches and suggestions are presented without resolution.

Contextual Notes

Some participants note potential issues with the implementation, such as the placement of boundary condition assignments, but do not reach a definitive conclusion about the source of the numerical discrepancies.

Who May Find This Useful

Individuals interested in numerical methods for solving partial differential equations, particularly in the context of diffusion processes, as well as those working with MATLAB for computational modeling.

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: 603
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
7K