1 D Unsteady Diffusion Equation by Finite Volume (Fully Implicit) Scheme

59 views (last 30 days)
Hi, Community,
Need some help to solve 1 D Unsteady Diffusion Equation by Finite Volume (Fully Implicit) Scheme . MATLAB Code is working. When I compare it with Book results, it is significantly different. If it is possible to improve. Attached files are
a -Figure(taken from Book) which show origional example (problem)
b- PDF(taken from Book) shows main scheme to implement.
Your idea will be highly appreciated.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% This code solves the unsteady 1D diffuion equation using FVM for the
% unknown Temperature.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all
close all
clc
tic
%% Sort out Inputs
% Number of Control Volumes
N = 5;
% Domain length
L = 0.02; %[m]
% Grid Spacing (Wall thickness)
h = L/(N);
% Diffusivity (Thermal conductivity)
k = 10; %[W/m-K]
% Specific Heat Capacity
Row_c = 10e6; %[J/m^(3)-K]
% Uniform Heat Generation, A Source Term
q = 1000e3; % [W/m^(3)]
% The center of the first cell is at dx/2 & the last cell is at L-dx/2.
x = h/2 : h : L-(h/2);
% Cross sectional area of the 1D domain
A = 1; %[m^2]
% Diffusivity (Heat)
alpha = k/Row_c;
% Simulation Time
t_Final = 8;
% Discrete Time Steps
dt = 2;
% Left Surface Temperature
T_a = 0; %[\circ c]
% Right Surface Temperature
T_b = 0; %[\circ c]
% Parameteric Setup
lambda = (alpha.*dt)/(h^2);
%% Initializing Variable
% Unknowns at time level n
T_Old = zeros(N,1);
% Unknowns at time level n+1
T_New = zeros(N,1);
% Initial Value (Initial Condition)
T_Old(:) = 200;
% Fully Implicit Scheme to Solve 1D Unsteady Diffusion.
% Time loop
for n = 1:t_Final/dt;
C(N,N) = 0;
D(N) = 0;
for i = 1: N
if i > 1 && i < N
C(i,i) = (1 + 2*lambda).*T_Old(i);
C(i,i+1) = -lambda.*T_Old(i);
C(i,i-1) = -lambda.*T_Old(i);
D(i)=T_Old(i);
elseif i == 1
% For 1st boundary node
C(i,i) = (1 + lambda).*T_Old(i);
C(i,i+1) = -lambda.*T_Old(i);
D(i) = T_Old(i);
else
% For Last boundary node
C(i,i) = (1 + 3*lambda).*T_Old(i);
C(i,i-1) = -lambda.*T_Old(i);
D(i) = 2*T_b*lambda + T_Old(i);
end
end
T_New = (inv(C)*D').*T_Old;
% Update calculations
T_Old = T_New;
end
T_New
  1 Comment
小宝 王
小宝 王 on 18 Nov 2021
May I ask your advice on how to learn finite volume method ? and this question comes from that book, can you share it with me,I would be very grateful.

Sign in to comment.

Answers (2)

darova
darova on 1 Sep 2021
Try this simple difference scheme:
lam = 0.5; % k*dt/rho/dx^2
n = 20;
T = zeros(n);
T(1,:) = 200; % t = 0 condition (T=200)
T(:,end) = 0; % x = L condition (T=0)
h = surf(T);
for i = 1:size(T,1)-1
for j = 2:size(T,2)-1
T(i+1,j) = T(i,j) + lam*(T(i,j+1) - 2*T(i,j) + T(i,j-1));
end
T(i+1,1) = T(i+1,2); % x = 0 condition (dT/dx=0)
set(h,'zdata',T)
pause(0.3)
end
  2 Comments
Shahid Hasnain
Shahid Hasnain on 1 Sep 2021
@darova Thank you for idea, it is forward Euler's scheme on time. As I mentioned im my problem it is fully Implicit. My result are at 8s (t_Final) is correct. I got same coefficient matrix which is on the book but at time 40s. Results are significantly different. I am stuck in time loop which change the results. Also, T_old are changing strangely. Any other idea. Your idea is not aligned, it is very good. I am sorry to say.
Shahid Hasnain
Shahid Hasnain on 1 Sep 2021
Edited: Shahid Hasnain on 1 Sep 2021
in time n=1, I got the following
C =
225 -25 0 0 0
-25 250 -25 0 0
0 -25 250 -25 0
0 0 -25 250 -25
0 0 0 -25 275
and
D =
200
200
200
200
200
which are perfectly match with book. After that there is something I am missing.

Sign in to comment.


Nadza Basyuni
Nadza Basyuni on 26 Jun 2023

Categories

Find more on Stochastic Differential Equation (SDE) Models in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!