2d Implicit and Explicit
2d Implicit and Explicit
2d Implicit and Explicit
net/publication/349338093
CITATIONS READS
0 14,524
2 authors:
All content following this page was uploaded by Bhar Kisabo Aliyu on 16 February 2021.
Considering the heat conduction problem with the configuration of a unit‐length square as shown in Fig.1, we
sort its solution via the finite difference method using both:
➢ Forward Euler time scheme (Explicit)
➢ Backward Euler time scheme (Implicit).
The initial temperature is uniform T = 0 and the right side of the square is kept insulated all the time.
(i) Plot figures which show the variation of T along y at x = 0.5 and along x at y = 0.5, at time t = 1 and the
steady state.
(ii) Compare the curves for three different resolutions of 10x10, 20x20, and 40x40 in the same figure.
To determine the largest possible time step in the explicit method, do an instability analysis.
The governing equation is
T 2T 2T
C p =k 2 + 2 (1.0)
t x y
where ρ is the material density, cp is the specific heat and k is the thermal conductivity
Let (1.1) hold, then we can re-write (1.0) as given in (1.2)
k
= (1.1)
C p
T 2T 2T
= 2 + 2 (1.2)
t x y
Considering the boundary conditions as follows:
T =T ( x, y, t ) = 0
T
T ( 0, y, t ) = 0 T (1, y, t ) = =0
x
T ( x, 0, t ) = 0 T ( x,1, t ) = 100
For the unit square plate in this study, the nodes distribution can be shown in Fig. 1a. Adopting the notation
Ti ,kj where i,j are location for a node and k is the time step number. The boundary conditions on the square
material is depicted in Fig. 1b.
(a) (b)
Fig. 1: unit square material depicting nodal placement and boundary conditions
1
1.0 Introduction
This project requires the solution to a two-dimension heat equation as presented in (1) using Finite difference
(FD) method. The forward and backward Euler schemes will be employed for the FD.
Explicit and implicit methods are approaches used in numerical analysis for obtaining numerical
approximations to the solutions of time-dependent ordinary and partial differential equations, as is required
in computer simulations of physical processes. Explicit methods calculate the state of a system at a later time from
the state of the system at the current time, while implicit methods find a solution by solving an equation involving
both the current state of the system and the later one [1].
= (2.1)
t t
2T Ti +1, j − 2Ti , j + Ti −1, j
k k k
= (2.2)
x 2 ( x )
2
2T Ti , j +1 − 2Ti , j + Ti , j −1
k k k
= (2.3)
y 2 ( y )
2
Fig. 2: Temperature trend for centre node T(5,5) using the forward Euler method (Explicit Scheme)
It can be seen from Fig.2a that all three resolutions gave the same result (all three plots are superimposed on
each other). From 0s to about 3s, the nodal temperature decreased exponential and at about 0.3s to 1s, the nodal
temperature came to a steady-state value of about 250C. If we zoom Fig.2a very close to the steady-state value of
250C we get Fig. 2b, here we can see the disparity among the three resolutions. Note, this dispersity is about 0.010
C. Thus, to reduce computational task we could as well just use the 11x11 resolution(coarse) to evaluate the
required result.
In Fig. 3a, the difference between 11x11 and 41x41 resolution is about 1.29 0C(27.9056-26.6145) as captured
in Fig. 3b using data cursor at the 0.5 length of the metal.
3
(a) (b)
Fig. 3: Temperature trend for the x-axis centre nodes (x=0.5) using the forward Euler method (Explicit Scheme)
In Fig.4, all three resolutions gave the same result (superimposed as a single plot, Fig. 4a) and the characteristic
is that of an exponential increase in temperature from 00C to 1000C. The difference between the three resolutions
at the y=0.5 is about 10C between the 41x41 resolution and the 11x11 resolutions.
(a) (b)
Fig. 4: Temperature trend for the y-axis centre nodes (y=0.5) using the forward Euler method (Explicit Scheme)
= (3.1)
t t
k +1 k +1 k +1
2T Ti +1, j − 2Ti , j + Ti −1, j
= (3.2)
x 2 ( x )
2
k +1 k +1 k +1
2T Ti , j +1 − 2Ti , j + Ti , j −1
= (3.3)
y 2 ( y )
2
4
Substituting (3.1), (3.2) and (3.3) in (1.0) gives (3.4)
T − 2Ti , j + Ti −1, j Ti , j +1 − 2Ti , j + Ti , j −1
Ti ,kj+1 − Ti ,kjk +1 k +1 k +1 k +1 k +1 k +1
= i +1, j + (3.4)
t ( ) ( )
2 2
x y
where x = y = h is the integration or simulation step (a constant value)
We can proceed to re-write (3.4) as given in (3.5)
(a) (b)
Fig. 5: Temperature trend for centre node T(5,5) using the forward Euler method (implicit Scheme).
5
At the x-axis centre nodes (x=0.5), we observe a very close approximation between the three resolutions as seen
in Fig. 6a. the difference between the 41x41 resolution and 11x11 resolution observed at that node is
1.0560C(27.9298-26.8742), from Fig. 6b.
(a) (b)
Fig. 6: Temperature trend for the x-axis centre nodes (x=0.5) using the forward Euler method (implicit Scheme)
For the temperature trend for the y-axis centre nodes (y=0.5), as observed in Fig. 7a, all three resolutions gave
the same result (superimposed as a single plot, Fig. 7a) and the characteristic is that of an exponential increase
in temperature from 00C to 1000C. The difference between the three resolutions at the y=0.5 is about 10C between
the 41x41 resolution and the 11x11 resolution.
(a) (b)
Fig. 7: Temperature trend for the y-axis centre nodes (y=0.5) using the forward Euler method (Implicit Scheme)
4. Comparative Analysis
In this section, we bring together the plots for the explicit and implicit method in each case for close-up perusal
and it is seen that for the temperature node T(5,5) and at about 0.3seconds the temperature had gotten to a
steady-state value of about 250C in both the explicit(Fig. 8a) and implicit scheme(Fig. 8b).
6
(a) (b)
Fig. 8: Zoomed Temperature trend for centre node T(5,5) for the explicit and implicit Scheme.
Bringing the temperature trend for the x-axis centre nodes (x=0.5) for the explicit (Fig. 9a) and implicit Scheme
(Fig. 9b) as seen in Fig.9, it is obvious that both schemes gave fairly the same result at the point of interest with
all resolutions in each case giving about the same result.
(a) (b)
Fig. 9: Temperature trend for the x-axis centre nodes (x=0.5) for explicit and the implicit Scheme
For the zoomed temperature trend for the y-axis centre nodes (y=0.5), the explicit scheme (Fig.10a) and the
Implicit Scheme (Fig. 10b) gave about the same result. The maximum temperature at this node is 27.90C in both
cases and with the 41x41 resolution. The 11x11 resolution gave the list temperature, with the explicit scheme
giving us 26.60C and the implicit scheme gave 26.90C.
The gradient of exponential increase is different in both cases. In Fig. 10c, the explicit scheme has a less steep
gradient compared to that of the implicit scheme as captured in Fig. 10d
7
(a) (b)
(d) (e)
Fig. 10: Temperature trend for the y-axis centre nodes (y=0.5) for the explicit and Implicit Scheme
The results obtained using the explicit and implicit scheme agree with each other. For the fact that the implicit
method is more computationally demanding, we decided to simulate the temperature distribution on the square
material using only the explicit scheme with 41x41 resolution as depicted in Fig. 11. Notice that Fig. 11a agrees
with Fig. 3 (explicit scheme) and Fig.6(implicit scheme) if we invert them up-side-down. Better still, if the 1000C
boundary condition is placed at the bottom of the square material gives Fig. 11b (this corresponds to Fig. 3 and
Fig. 6).
(a) (b)
Fig. 11: Temperature distribution along the entire square material using the forward Euler method (Explicit
Scheme)
8
Conclusion
In an attempt to solve a 2D heat equation using explicit and implicit schemes of the finite difference method,
three resolutions (11x11, 21x21 and 41x41) of the square material were used. Two MATLAB m-files were written
for each scheme and the result obtained were in very close agreement. As such, another MATLAB m-file based
on the explicit scheme using a resolution of 41x41 was used to simulate the temperature distribution across the
entire square material.
References
1. Explicit and implicit methods
https://en.wikipedia.org/wiki/Explicit_and_implicit_methods (accessed on 7/02/2021)
2. Darius Pupeikis et al (2010). The effect of the Fourier number on calculation of an unsteady heat
transfer of building walls
https://doi.org/10.3846/jcem.2010.34
3. Donatello Annaratone (2011). Transient Heat Transfer. Springer-Verlag Berlin Heidelberg.
DOI: 10.1007/978-3-642-19777-2
MATLAB CODES
*****first m-file********
%Explicit Scheme 2D Heat
%Finite Difference Method %below is the time-marching calculation
clear all TP1a(:,1)=TPa;
clc for d=(2:nta)
% General inpute TP1a(:,d)=aa*TPa;
T=1.0; % simulation time TPa=TP1a(:,d);
format long end
Fo=0.18; z1a=(ma-ms)/2+1; %declaring the range for the x-center line nodes
f=Fo; z2a=(ma+ms)/2;
g=1-(4*Fo); z3a(1:ms)=(ms+1)/2; %declaring the range for the y-center line nodes
temp=100; for k=(2:ms)
%THIS SECTION CALCULATES TEMPs FOR N=11 z3a(k)=z3a(1)+((k-1)*ms);
ms=11; %matrix size end
dxa=1/(ms-1); %length of dx, same as dy ca(ms)=0;
dta=Fo*dxa^2; for k=(1:ms)
ta=(dta:dta:T); %sample times ca(k)=TP1a(z3a(k),ma);
xa=(0:dxa:1); %length end
nta=length(ta); %time marching length t11a=ta; %n=11
ma=ms^2; %sizing of the matrix TP111a=TP1a(((ma+1)/2),:); %n=11
na=ms^2; x11b=xa; %n=11
TPa(ma,1)=0; TP111b=TP1a(z1a:z2a,ma); %n=11
TP1a(ma,nta)=0; c11c=ca; %n=11
aa(1:ma,1:na)=0; %declaration of the sparse matrix figure(1),plot(t11a,TP111a,'-.')
for e=(1:ma) grid on
aa(e,e)=1; %inserting 1's on the diagonal elements hold on
end figure(2),plot(x11b,TP111b,'-.')
for ee=(1:(ms-2)) grid on
for e=(2:(ms-1)) hold on
qa=(ms*ee)+e; figure(3),plot(x11b,c11c,'-.')
TPa(qa)=temp; grid on
aa(qa,qa)=g; hold on
aa(qa,qa-1)=f; aa
aa(qa,qa+1)=f; %THIS SECTION CALCULATES TEMPs FOR N=21
aa(qa,qa-ms)=f; ms=21; %matrix size
aa(qa,qa+ms)=f; dxb=1/(ms-1); %length of dx, same as dy
end dtb=Fo*dxb^2;
end tb=(dtb:dtb:T); %sample times
TPa(((ma-ms)+1):ma)=temp; xb=(0:dxb:1); %length
9
ntb=length(tb); %time marching length nc=ms^2;
mb=ms^2; %sizing of the matrix TPc(mc,1)=0;
nb=ms^2; TP1c(mc,ntc)=0;
TPb(mb,1)=0; ac(1:mc,1:nc)=0; %declaration of the sparse matrix
TP1b(mb,ntb)=0; for e=(1:mc)
ab(1:mb,1:nb)=0; %declaration of the sparse matrix ac(e,e)=1; %inserting 1's on the diagonal elements
for e=(1:mb) end
ab(e,e)=1; %inserting 1's on the diagonal elements for ee=(1:(ms-2))
end for e=(2:(ms-1))
for ee=(1:(ms-2)) qc=(ms*ee)+e;
for e=(2:(ms-1)) TPc(qc)=temp;
qb=(ms*ee)+e; ac(qc,qc)=g;
TPb(qb)=temp; ac(qc,qc-1)=f;
ab(qb,qb)=g; ac(qc,qc+1)=f;
ab(qb,qb-1)=f; ac(qc,qc-ms)=f;
ab(qb,qb+1)=f; ac(qc,qc+ms)=f;
ab(qb,qb-ms)=f; end
ab(qb,qb+ms)=f; end
end TPc(((mc-ms)+1):mc)=temp;
end %below is the time-marching calculation
TPb(((mb-ms)+1):mb)=temp; TP1c(:,1)=TPc;
%below is the time-marching calculation for d=(2:ntc)
TP1b(:,1)=TPb; TP1c(:,d)=ac*TPc;
for d=(2:ntb) TPc=TP1c(:,d);
TP1b(:,d)=ab*TPb; end
TPb=TP1b(:,d); z1c=(mc-ms)/2+1; %declaring the range for the x-center line nodes
end z2c=(mc+ms)/2;
z1b=(mb-ms)/2+1; %declaring the range for the x-center line nodes z3c(1:ms)=(ms+1)/2; %declaring the range for the y-center line nodes
z2b=(mb+ms)/2; for k=(2:ms)
z3b(1:ms)=(ms+1)/2; %declaring the range for the y-center line nodes z3c(k)=z3c(1)+((k-1)*ms);
for k=(2:ms) end
z3b(k)=z3b(1)+((k-1)*ms); cc(ms)=0;
end for k=(1:ms)
cb(ms)=0; cc(k)=TP1c(z3c(k),mc);
for k=(1:ms) end
cb(k)=TP1b(z3b(k),mb); t41a=tc; %n=41
end TP141a=TP1c(((mc+1)/2),:); %n=41
t21a=tb; %n=21 x41b=xc; %n=41
TP121a=TP1b(((mb+1)/2),:); %n=21 TP141b=TP1c(z1c:z2c,mc); %n=41
x21b=xb; %n=21 c41c=cc; %n=41
TP121b=TP1b(z1b:z2b,mb); %n=21 figure(1),plot(t41a,TP141a,'g-.')
c21c=cb; n=21 grid on
figure(1),plot(t21a,TP121a,'r-.') xlabel('time (s)')
grid on ylabel('nodal temperature (C)')
hold on title('Temp. Profile for center node T(5,5) (Explicit Scheme)')
figure(2),plot(x21b,TP121b,'r-.') legend('11x11 nodes','21x21 nodes','41x41 nodes')
grid on figure(2),plot(x41b,TP141b,'g-.')
hold on grid on
figure(3),plot(x21b,c21c,'r-.') xlabel('length (x-axis) ')
grid on ylabel('nodal temperature (C)')
hold on title('Temp. Profile for the x-axis center nodes (x=0.5) (Explicit Scheme)')
%THIS SECTION CALCULATES TEMPs FOR N=41 legend('11x11 nodes','21x21 nodes','41x41 nodes')
ms=41; %matrix size figure(3),plot(x41b,c41c,'g-.')
dxc=1/(ms-1); %length of dx, same as dy grid on
dtc=Fo*dxc^2; xlabel('length (y-axis) ')
tc=(dtc:dtc:T); %sample times ylabel('nodal temperature (C)')
xc=(0:dxc:1); %length title('Temp. Profile for the y-axis center nodes (y=0.5) (Explicit Scheme)')
ntc=length(tc); %time marching length legend('11x11 nodes','21x21 nodes','41x41 nodes')
mc=ms^2; %sizing of the matrix
*****second m-file********
%Implicit scheme of 2D Heat equation
% Finite Difference Method
10
T=1.0; % simulation time %THIS SECTION CALCULATES TEMPs FOR N=21
format long ms=21; %matrix size
Fo=0.18; dxb=1/(ms-1); %length of dx, same as dy
f=Fo; dtb=Fo*dxb^2;
g=1+(4*Fo); tb=(dtb:dtb:T); %sample times
temp=100; xb=(0:dxb:1); %length
%THIS SECTION CALCULATES TEMPs FOR N=11 ntb=length(tb); %time marching length
ms=11; %matrix size mb=ms^2; %sizing of the matrix
dxa=1/(ms-1); %length of dx, same as dy nb=ms^2;
dta=Fo*dxa^2; TPb(mb,1)=0;
ta=(dta:dta:T); %sample times TP1b(mb,ntb)=0;
xa=(0:dxa:1); %length ab(1:mb,1:nb)=0; %declaration of the sparse matrix
nta=length(ta); %time marching length for e=(1:mb)
ma=ms^2; %sizing of the matrix ab(e,e)=1; %inserting 1's on the diagonal elements
na=ms^2; end
TPa(ma,1)=0; for ee=(1:(ms-2))
TP1a(ma,nta)=0; for e=(2:(ms-1))
aa(1:ma,1:na)=0; %declaration of the sparse matrix qb=(ms*ee)+e;
for e=(1:ma) TPb(qb)=temp;
aa(e,e)=1; %inserting 1's on the diagonal elements ab(qb,qb)=g;
end ab(qb,qb-1)=-f;
for ee=(1:(ms-2)) ab(qb,qb+1)=-f;
for e=(2:(ms-1)) ab(qb,qb-ms)=-f;
qa=(ms*ee)+e; ab(qb,qb+ms)=-f;
TPa(qa)=temp; end
aa(qa,qa)=g; end
aa(qa,qa-1)=-f; ab=inv(ab); % Inversion of matrix ab
aa(qa,qa+1)=-f; TPb(((mb-ms)+1):mb)=temp;
aa(qa,qa-ms)=-f; %below is the time-marching calculation
aa(qa,qa+ms)=-f; TP1b(:,1)=TPb;
end for d=(2:ntb)
end TP1b(:,d)=ab*TPb;
aa=inv(aa); % Inversion of matrix aa TPb=TP1b(:,d);
TPa(((ma-ms)+1):ma)=temp; end
%below is the time-marching calculation z1b=(mb-ms)/2+1; %declaring the range for the x-center line nodes
TP1a(:,1)=TPa; z2b=(mb+ms)/2;
for d=(2:nta) z3b(1:ms)=(ms+1)/2; %declaring the range for the y-center line nodes
TP1a(:,d)=aa*TPa; for k=(2:ms)
TPa=TP1a(:,d); z3b(k)=z3b(1)+((k-1)*ms);
end end
z1a=(ma-ms)/2+1; %declaring the range for the x-center line nodes cb(ms)=0;
z2a=(ma+ms)/2; for k=(1:ms)
z3a(1:ms)=(ms+1)/2; %declaring the range for the y-center line nodes cb(k)=TP1b(z3b(k),mb);
for k=(2:ms) end
z3a(k)=z3a(1)+((k-1)*ms); t21a=tb; %n=21
end TP121a=TP1b(((mb+1)/2),:); %n=21
ca(ms)=0; x21b=xb; %n=21
for k=(1:ms) TP121b=TP1b(z1b:z2b,mb); %n=21
ca(k)=TP1a(z3a(k),ma); c21c=cb; %n=21
end figure(1),plot(t21a,TP121a,'r-.')
t11a=ta; %n=11 grid on
TP111a=TP1a(((ma+1)/2),:); %n=11 figure(2),plot(x21b,TP121b,'r-.')
x11b=xa; %n=11 grid on
TP111b=TP1a(z1a:z2a,ma); %n=11 figure(3),plot(x21b,c21c,'r-.')
c11c=ca; %n=11 grid on
figure(1),plot(t11a,TP111a,'-.') %THIS SECTION CALCULATES TEMPs FOR N=41
grid on ms=41; %matrix size
hold on dxc=1/(ms-1); %length of dx, same as dy
figure(2),plot(x11b,TP111b,'-.') dtc=Fo*dxc^2;
grid on tc=(dtc:dtc:T); %sample times
hold on xc=(0:dxc:1); %length
figure(3),plot(x11b,c11c,'-.') ntc=length(tc); %time marching length
grid on mc=ms^2; %sizing of the matrix
hold on nc=ms^2;
11
TPc(mc,1)=0; x = linspace(0,1,n); dx = x(2)-x(1); y = x; dy = dx;
TP1c(mc,ntc)=0; TOL = 1e-6;
ac(1:mc,1:nc)=0; %declaration of the sparse matrix T = zeros(n);
for e=(1:mc) T(1,1:n) = 0; %BOTTOM
ac(e,e)=1; %inserting 1's on the diagonal elements T(n,1:n) = 100; %TOP
end T(1:n,1) = 0; %LEFT
for ee=(1:(ms-2)) T(1:n,n) = 0; %RIGHT
for e=(2:(ms-1)) dt = dx^2/4;
qc=(ms*ee)+e; error = 1; k = 0;
TPc(qc)=temp; while error > TOL
ac(qc,qc)=g; k = k+1;
ac(qc,qc-1)=-f; Told = T;
ac(qc,qc+1)=-f; for i = 2:n-1
ac(qc,qc-ms)=-f; for j = 2:n-1
ac(qc,qc+ms)=-f; T(i,j) = dt*((Told(i+1,j)-2*Told(i,j)+Told(i-1,j))/dx^2 ...
end + (Told(i,j+1)-2*Told(i,j)+Told(i,j-1))/dy^2) ...
end + Told(i,j);
ac=inv(ac); % Inversion matrix of ac end
TPc(((mc-ms)+1):mc)=temp; end
%below is the time-marching calculation error = max(max(abs(Told-T)));
TP1c(:,1)=TPc; end
for d=(2:ntc)
TP1c(:,d)=ac*TPc; pcolor(x,y,T),shading interp,
TPc=TP1c(:,d); xlabel('x'),ylabel('y'),colorbar
end
z1c=(mc-ms)/2+1; %declaring the range for the x-center line nodes
z2c=(mc+ms)/2;
z3c(1:ms)=(ms+1)/2; %declaring the range for the y-center line nodes
for k=(2:ms)
z3c(k)=z3c(1)+((k-1)*ms);
end
cc(ms)=0;
for k=(1:ms)
cc(k)=TP1c(z3c(k),mc);
end
t41a=tc; %n=41
TP141a=TP1c(((mc+1)/2),:); %n=41
x41b=xc; %n=41
TP141b=TP1c(z1c:z2c,mc); %n=41
c41c=cc; %n=41
figure(1),plot(t41a,TP141a,'g-.')
grid on
xlabel('time (s) ')
ylabel('nodal temperature (C)')
title('Temp. Profile for center node T(5,5) (Implicit Scheme)')
legend('11x11 nodes','21x21 nodes','41x41 nodes')
figure(2),plot(x41b,TP141b,'g-.')
grid on
xlabel('length (x-axis) ')
ylabel('nodal temperature (C)')
title('Temp. Profile for the x-axis center nodes (x=0.5) (Implicit Scheme)')
legend('11x11 nodes','21x21 node','41x41 nodes')
figure(3),plot(x41b,c41c,'g-.')
grid on
xlabel('length (y-axis) ')
ylabel('nodal temperature (C)')
title('Temp. Profile for the y-axis center nodes (y=0.5) (Implicit Scheme)')
legend('11x11 nodes','21x21 nodes','41x41 nodes')
*****third m-file******
%2D Heat Equation.
clear; close all; clc
n = 40; %grid has n - 2 interior points per dimension (overlapping)
12