1 D Unsteady Diffusion Equation by Finite Volume (Fully Implicit) Scheme
59 次查看(过去 30 天)
显示 更早的评论
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 个评论
小宝 王
2021-11-18
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.
回答(2 个)
darova
2021-9-1
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Stochastic Differential Equation (SDE) Models 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!