All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Solving Steady and Unsteady State 2d Heat Conduction Equation The two dimension heat conduction equation can be written as (∂T∂t)+α(∂2T∂x2+∂2T∂y2)=0 In the above equation T…
Vivek Ramesh
updated on 15 Aug 2020
Solving Steady and Unsteady State 2d Heat Conduction Equation
The two dimension heat conduction equation can be written as
(∂T∂t)+α(∂2T∂x2+∂2T∂y2)=0(∂T∂t)+α(∂2T∂x2+∂2T∂y2)=0
In the above equation T represents Temperature, 'alpha' represents thermal diffusivity. x and y are spatial coordinates and t is the temporal coordinate.
There are two approaches to solve the problem. These are listed below.
1) Steady State Equation:-
In this approach the change of temperature with time is zero, i.e the term `((delT)/(delt))' is equal to zero. The equation reduces to
∂2T∂x2+∂2T∂y2=0∂2T∂x2+∂2T∂y2=0
In order to discretize the above equation we create a domain of unit length in x and y direction resulting in a unit square. This domain is divided 50 equally spaced grid points in the x and y direction. The Temperature boundary conditions are applied as given below
Top Boundary = 600 K
Bottom Boundary = 900 K
Left Boundary = 400 K
Right Boundary = 800 K
A second order central differencing scheme is applied to calculate the second order derivative terms in the steady state equation. The value of Temperature at point P is evaluated using the neighbourhood values, i.e TL and TR in x direction, Tt and Tb in the y direction.
The discretised equation for 2D steady state is given below
TL-2Tp+TRΔx2+TT-2Tp+TBΔy2=0TL−2Tp+TRΔx2+TT−2Tp+TBΔy2=0
Solving for 'T_p'
Tp=(Δx2⋅Δy22(Δx2+Δy2))⋅((TL+TRΔx2+TT+TBΔy2))Tp=(Δx2⋅Δy22(Δx2+Δy2))⋅((TL+TRΔx2+TT+TBΔy2))
The term '((2(Deltax^2+Deltay^2))/(Deltax^2*Deltay^2)))' is labelled as k
The equation Reduces to
Tp=(1K)⋅((TL+TRΔx2+TT+TBΔy2))Tp=(1K)⋅((TL+TRΔx2+TT+TBΔy2))
There are three iterative solvers which have been used to solve the above equation
a) Jacobi Method
In this method, given a current approximation for x,
xk=(xk1,xk2,xk3,.......xkn)xk=(xk1,xk2,xk3,.......xkn)
the strategy of Jacobi's Method is to use the current values of 'x_2^k','x_3^k','x_n^k' to find a new value for x_1^(k+1)
The Code written for iterative solver using Jacobi Method is given below
%Jacobi Method
clear all
close all
clc
%Input Parameter
nx=50;
ny=50;
x=linspace(0,1,nx);%Grid along X
y=linspace(0,1,ny);%Grid along y
dx=x(2)-x(1);
dy=y(2)-y(1);
T=ones(nx,ny);
%Boundary Conditions
T(1,:)=600;
T(end,:)=900;
T(:,1)=400;
T(:,end)=800;
Tinitial=T;
Told=T;
k=2*((dx^2+dy^2)/(dx^2*dy^2));
Tol=1e-4
error1=9e9
error2=9e9
error3=9e9
jacobi_iter=1;
tic
a=1;
while (error1>Tol)
for i=2:nx-1
for j=2:ny-1
m=(Told(i+1,j)+Told(i-1,j))/(dx*dx);
n=(Told(i,j+1)+Told(i,j-1))/(dy*dy);
T(i,j)=(m+n)/k ;
end
end
error1= max(max(abs(Told-T)));
ERROR1(a)=error1; %Plotting error vs iterations
Told=T;
jacobi_iter=jacobi_iter+1;
JI(a)=jacobi_iter;%Storing iterations in counter
time1=toc;
a=a+1;
end
figure(1);
colormap(jet);
contourf(x,y,T,'showText','on')
set(gca,'YDir','reverse')
tit1=sprintf('Number of iteration=%d\n Simulation Time=%d s',jacobi_iter,time1)
title({'Jacobi solver for steady state',tit1})
colorbar
pause(0.3)
-Plot for Temperature Field . For a grid spacing of 50x50, dx and dy value of 0.0204
No of iterations= 4873. Simulation time 2.189e-1seconds
b) Gauss-Seidel Method
After we compute 'x_1^(k+1)' and it is a better approximation to the true value of x_1 than x_1^k we use the new value 'x_1^(k+1)' in finding 'x_2^(k+1)' . We progressively use the updated values of the variables in the equation. The result is we get faster convergence and lesser simulation time.
Code for Gauss Seidel( TO be read in continuation of Jacobi code)
%Gauss Seidel
tic;
T=Tinitial;
Told=Tinitial;
gauss_seidel=1;
b=1;
while (error2>Tol)
for i=2:nx-1
for j=2:ny-1
m=(T(i+1,j)+T(i-1,j))/(dx*dx);
n=(T(i,j+1)+T(i,j-1))/(dy*dy);
T(i,j)=(m+n)/k ;
end
end
error2= max(max(abs(Told-T)));
Told=T;
ERROR2(b)= error2;
GS(b)=gauss_seidel;
gauss_seidel=gauss_seidel+1;
b=b+1;
time2=toc;
end
figure(2)
colormap(jet);
contourf(x,y,T,'showText','on')
set(gca,'YDir','reverse')
tit2=sprintf('Number of iteration=%d\n Simulation Time=%d s',gauss_seidel,time2)
title({'Gauss Seidel solver for steady state',tit2})
colorbar
pause(0.3)
-Plot for Temperature Field . For a grid spacing of 50x50, dx and dy value of 0.0204
No of iterations= 2610. Simulation time 1.789e-1seconds
-Successive Over Relaxation Method (SOR)
The SOR method of solving a linear system of equations Ax=B is derived by extrapolating the Gauss Seidel Method. The extrapolation takes a the form of weighted average between previous iterate and the computed Gauss seidel iterate successively for each component
xki=ω⋅xki+(1-ω)⋅xk-1ixki=ω⋅xki+(1−ω)⋅xk−1i
'omega' is the relaxation factor
'omega>1', the equation is overelaxed
'omega=1', The equation is same as Gauss Seidel
'omega<1', The equation is under relaxed
COde for SOR (TO be read in continuation of code for Gauss Seidel)
%Successive Over Relaxation
SOR=1;
T=Tinitial
Told=Tinitial;
omega=1.5;
tic
c=1;
while (error3>Tol)
for i=2:nx-1
for j=2:ny-1
m=(T(i+1,j)+T(i-1,j))/(dx*dx);
n=(T(i,j+1)+T(i,j-1))/(dy*dy);
T(i,j)=(1-omega)*Told(i,j) +omega*((m+n)/k );
end
end
error3= max(max(abs(Told-T)));
ERROR3(c)= error3;
Told=T;
SR(c)=SOR;
SOR=SOR+1;
time3=toc;
c=c+1;
end
figure(3)
colormap(jet);
contourf(x,y,T,'showText','on')
set(gca,'YDir','reverse')
tit3=sprintf('Number of iteration=%d\n Simulation Time=%d s',SOR,time3)
title({'SOR solver for steady state',tit3})
colorbar
pause(0.3)
Plot for Temperature Field . For a grid spacing of 50x50, dx and dy value of 0.0204, omega=1.5
No of iterations= 957. Simulation time 8.3477e-02seconds
- Plot showing variation of error with iterations for the three methods
By observing the below plot we note that SOR method converges at much faster rate compared to Gauss seidel and Jacobi.
Unsteady Transient Equation
The unsteady Transient equation for heat conduction is given as
∂T∂t=α⋅(∂2T∂x2+∂2T∂y2)∂T∂t=α⋅(∂2T∂x2+∂2T∂y2)
Discretizing this equation we get
Tn+1p-TnpΔt=α⋅(TL-2⋅Tp+TRΔx2+TT-2⋅Tp+TBΔy2)nTn+1p−TnpΔt=α⋅(TL−2⋅Tp+TRΔx2+TT−2⋅Tp+TBΔy2)n
There are two methods to solve this equation
1) Explicit:- In the explicit method, there would be only one unknown. In this case it is `(T_p^(n+1)'. All other variables are at time step n which have been calculated.
Solving for `(T_p^(n+1)', we get
Tn+1p=Tnp+(α⋅ΔtΔx2)⋅(TnL-2⋅Tnp+TnR)+(α⋅ΔtΔy2)⋅(TnT-2⋅Tnp+TnB)Tn+1p=Tnp+(α⋅ΔtΔx2)⋅(TnL−2⋅Tnp+TnR)+(α⋅ΔtΔy2)⋅(TnT−2⋅Tnp+TnB)
In this equation we have the one unknown `(T_p^(n+1)' on the LHS. All the parameters on RHS are at time step n , a known quantity.
In the above equation we can denote as follows.
' k1=((alpha*Deltat)/(Deltax^2))'
' k2=((alpha*Deltat)/(Deltay^2))'
'k1' and 'k2' are called the CFL numbers for the equation
For the numerical explicit diffusion equation to be stable, it must satisfy the below criteria
k1+k2≤0.5k1+k2≤0.5
In order to solve the transient explicit equation, we solve for Temperature values at each node using values from previous time step. We then run the loop for sufficiently large time steps to obtain the solution. No iterative solver is required.
Code for transient equation
clear all
close all
clc
nx=50;
ny=50;
x=linspace(0,1,nx);
y=linspace(0,1,ny);
dx=x(2)-x(1);
dy=y(2)-y(1);
alpha=4e-3;
dt=0.01;
k1=(alpha*dt)/(dx)^2;
k2=(alpha*dt)/(dy)^2;
T=ones(nx,ny);
T(1,:)=600;
T(end,:)=900;
T(:,1)=400;
T(:,end)=800;
Told=T;
T(1,1)=(400+900)/2;
T(end,1)=(400+600)/2;
T(1,end)=(900+800)/2;
T(end,end)=(800+600)/2;
% k=2*((dx^2+dy^2)/(dx^2*dy^2));
Tol=1e-4;
error1=9e9;
for nt=1:15000
tic;
for i=2:nx-1
for j=2:ny-1
m=k1*(Told(i+1,j)+Told(i-1,j)-2*Told(i,j));
n=k2*(Told(i,j+1)+Told(i,j-1)-2*Told(i,j));
T(i,j)=m+n+Told(i,j) ;
end
end
time1=toc;
Told=T;
end
figure(1);
colormap(jet);
contourf(x,y,T,'showText','on')
set(gca,'YDir','reverse')
tit1=sprintf('Simulation Time=%d s',time1)
title({'Solution for transient explicit '})
colorbar
pause(0.3)
Plot for temperature profile
Parameters considered
No of points along x=50
No of points along y=50
dx=dy=0.0204
thermal diffusivity 'alpha=4e-3'
dt=0.01
CFL along x 'k1=0.0960'
CFL along y 'k2=0.0960'
'k1+k2=0.192' which is less than 0.5. We expect a solution
No of time steps= 150000
Plot
Plot when 'k1+k2 >0.5'. The solution is unstable
Implicit Method
In this method, we have more than one unknown element
Tn+1p-TnpΔt=α⋅(TL-2⋅Tp+TRΔx2+TT-2⋅Tp+TBΔy2)n+1Tn+1p−TnpΔt=α⋅(TL−2⋅Tp+TRΔx2+TT−2⋅Tp+TBΔy2)n+1
Tn+1p=Tnp+(α⋅ΔtΔx2)⋅(Tn+1L-2⋅Tn+1p+Tn+1R)+(α⋅ΔtΔy2)⋅(Tn+1T-2⋅Tn+1p+Tn+1B)Tn+1p=Tnp+(α⋅ΔtΔx2)⋅(Tn+1L−2⋅Tn+1p+Tn+1R)+(α⋅ΔtΔy2)⋅(Tn+1T−2⋅Tn+1p+Tn+1B)
In the above equation we can denote as follows.
' k1=((alpha*Deltat)/(Deltax^2))'
' k2=((alpha*Deltat)/(Deltay^2))'
Collecting terms related to `T_p^(n+1)' on LHS we get
′Tn+1p⋅[1+2k1+2k2]=Tnp+(k1⋅(Tn+1L+Tn+1R)+k2⋅(Tn+1T+Tn+1B))
Solving for `'T_p^(n+1)'
′Tn+1p⋅=[1+2k1+2k2]-1⋅(Tnp+k1⋅(Tn+1L+Tn+1R)+k2⋅(Tn+1T+Tn+1B))
For ease of coding the terms of the above equation are labelled as
'[1+2k1+2k2]^-1= Term1'
'k1*[1+2k1+2k2]^-1= k1*Term1=Term2'
'k2*[1+2k1+2k2]^-1= k2*Term1=Term3'
The above equation is soved using the 3 iterative solvers that were used previously
1. Jacobi solver
clear all
close all
clc
nx=50;
ny=50;
x=linspace(0,1,nx);%Grid Spacing along X
y=linspace(0,1,ny);%Grid Spacing along Y
dx=x(2)-x(1);
dy=y(2)-y(1);
alpha=1.5;%Thermal Diffusivity
dt=1e-2;%Time Step
k1=(alpha*dt)/(dx)^2;%CFL along x
k2=(alpha*dt)/(dy)^2;%CFL along y
term1=(1/(1+2*k1+2*k2));
term2=k1*term1;
term3=k2*term1;
T=ones(nx,ny);
T(1,:)=600;
T(end,:)=900;
T(:,1)=400;
T(:,end)=800;
T(1,1)=(400+600)/2;
T(end,1)=(400+800)/2;
T(1,end)=(900+800)/2;
T(end,end)=(800+600)/2;
Told=T;
Tinitial=T;
Tprev=T;
Tol=1e-4;
jacobi_iter=1;
a=1
for nt=1:1400
error1=9e9;
tic;
while(error1>Tol)
for i=2:nx-1
for j=2:ny-1
H=term2*(Told(i-1,j)+Told(i+1,j));
V=term3*(Told(i,j+1)+Told(i,j-1));
T(i,j)=term1*Tprev(i,j)+ H+V;
end
end
error1=max(max(abs(Told-T)));
Error1(a)=error1;
Told=T;%Spatial Temp values updated within the space iteration
jacobi_iter=jacobi_iter+1;
JI(a)=jacobi_iter;
a=a+1;
time1=toc;
end
Tprev=T;%After convergence the T values updated
end
figure(1)
colormap(jet);
contourf(x,y,T,'showText','on')
set(gca,'YDir','reverse')
tit1=sprintf('Number of iteration=%d\n Simulation Time=%d s',jacobi_iter,time1)
title({'Jacobi Iter solver for implicit',tit1})
colorbar
pause(0.3)
Plot for Temperature
Parameters considered
No of points along x=50
No of points along y=50
dx=dy=0.0204
thermal diffusivity 'alpha=1,5'
dt=0.01
CFL along x 'k1=0.9604'
CFL along y 'k2=0.9604'
No of Time steps = 1400
No of iterations to converge 24199, Simulation time 3.51e-05s
- Gauss seidel Method
Code ( To be read in continuation of Implicit)
%Gauss Seidel Implicit
T=Tinitial;
Told=Tinitial;
Tprev=Tinitial;
gauss_seidel=1;
b=1;
for nt=1:1400
error2=9e9;
tic;
while(error2>Tol)
for i=2:nx-1
for j=2:ny-1
H=term2*(T(i-1,j)+T(i+1,j));
V=term3*(T(i,j+1)+T(i,j-1));
T(i,j)=term1*Tprev(i,j)+ H+V;
end
end
error2=max(max(abs(Told-T)));
Error2(b)=error2;
Told=T;
GS(b)=gauss_seidel;
gauss_seidel=gauss_seidel+1;
b=b+1;
end
Tprev=T;
time2=toc;
end
figure(2)
colormap(jet);
contourf(x,y,T,'showText','on')
set(gca,'YDir','reverse')
tit2=sprintf('Number of iteration=%d\n Simulation Time=%d s',gauss_seidel,time2)
title({'Gauss Seidel Iter solver for implicit',tit2})
colorbar
pause(0.3)
Plot for Temperature
Parameters considered
No of points along x=50
No of points along y=50
dx=dy=0.0204
thermal diffusivity 'alpha=1,5'
dt=0.01
CFL along x 'k1=0.9604'
CFL along y 'k2=0.9604'
No of Time steps = 1400
No of Iteration to converge 14410, Simulation Time 2.7e-05 sec
-SOR
Code for SOR (To be read in continuation with Gauss Seide Implicit)
%SOR Implicit
Told=Tinitial;
Tprev=Tinitial;
T=Tinitial;
omega=1.5
SOR=1;
c=1;
for nt=1:1400
error3=9e9;
tic;
while(error3>Tol)
for i=2:nx-1
for j=2:ny-1
H=term2*(T(i-1,j)+T(i+1,j));
V=term3*(T(i,j+1)+T(i,j-1));
T(i,j)=(term1*Tprev(i,j)+ H+V)*omega+(1-omega)*Told(i,j);
end
end
error3=max(max(abs(Told-T)));
Error3(c)=error3;
Told=T;
SR(c)=SOR;
SOR=SOR+1;
c=c+1;
time3=toc;
end
Tprev=T;
end
figure(3)
colormap(jet);
contourf(x,y,T,'showText','on')
set(gca,'YDir','reverse')
tit2=sprintf('Number of iteration=%d\n Simulation Time=%d s',SOR,time3)
title({'SOR Iter solver for implicit',tit2})
colorbar
pause(0.3)
figure(4)
semilogy(JI,Error1,GS,Error2,'r',SR, Error3,'k');
legend('Jacobi','Gauss Seidel','SOR')
Plot for Temperature
Parameters considered
No of points along x=50
No of points along y=50
dx=dy=0.0204
thermal diffusivity 'alpha=1,5'
dt=0.01
relaxation factor omega=1.5
CFL along x 'k1=0.9604'
CFL along y 'k2=0.9604'
No of Time steps = 1400
No of Iteration to converge 6614, Simulation Time 3.3e-05 sec
-Comparison of decrease of error with iteration for 3 Methods
From the above graph we note that in SOR method the rate of decrease of error is much higher compared to Gauss seidel and Jacobi. Jacobi takes much longer time since we continue to use the old guess values instead of the newly calculated better guess values.
%Full COde for Steady State
clear all
close all
clc
%Input Parameter
nx=50;
ny=50;
x=linspace(0,1,nx);%Grid along X
y=linspace(0,1,ny);%Grid along y
dx=x(2)-x(1);
dy=y(2)-y(1);
T=ones(nx,ny);
%Boundary Conditions
T(1,:)=600;
T(end,:)=900;
T(:,1)=400;
T(:,end)=800;
Tinitial=T;
Told=T;
k=2*((dx^2+dy^2)/(dx^2*dy^2));
Tol=1e-4
error1=9e9
error2=9e9
error3=9e9
jacobi_iter=1;
tic
a=1;
while (error1>Tol)
for i=2:nx-1
for j=2:ny-1
m=(Told(i+1,j)+Told(i-1,j))/(dx*dx);
n=(Told(i,j+1)+Told(i,j-1))/(dy*dy);
T(i,j)=(m+n)/k ;
end
end
error1= max(max(abs(Told-T)));
ERROR1(a)=error1; %Plotting error vs iterations
Told=T;
jacobi_iter=jacobi_iter+1;
JI(a)=jacobi_iter;%Storing iterations in counter
time1=toc;
a=a+1;
end
figure(1);
colormap(jet);
contourf(x,y,T,'showText','on')
set(gca,'YDir','reverse')
tit1=sprintf('Number of iteration=%d\n Simulation Time=%d s',jacobi_iter,time1)
title({'Jacobi solver for steady state',tit1})
colorbar
pause(0.3)
%Gauss Seidel
tic;
T=Tinitial;
Told=Tinitial;
gauss_seidel=1;
b=1;
while (error2>Tol)
for i=2:nx-1
for j=2:ny-1
m=(T(i+1,j)+T(i-1,j))/(dx*dx);
n=(T(i,j+1)+T(i,j-1))/(dy*dy);
T(i,j)=(m+n)/k ;
end
end
error2= max(max(abs(Told-T)));
Told=T;
ERROR2(b)= error2;
GS(b)=gauss_seidel;
gauss_seidel=gauss_seidel+1;
b=b+1;
time2=toc;
end
figure(2)
colormap(jet);
contourf(x,y,T,'showText','on')
set(gca,'YDir','reverse')
tit2=sprintf('Number of iteration=%d\n Simulation Time=%d s',gauss_seidel,time2)
title({'Gauss Seidel solver for steady state',tit2})
colorbar
pause(0.3)
%Successive Over Relaxation
SOR=1;
T=Tinitial
Told=Tinitial;
omega=1.5;
tic
c=1;
while (error3>Tol)
for i=2:nx-1
for j=2:ny-1
m=(T(i+1,j)+T(i-1,j))/(dx*dx);
n=(T(i,j+1)+T(i,j-1))/(dy*dy);
T(i,j)=(1-omega)*Told(i,j) +omega*((m+n)/k );
end
end
error3= max(max(abs(Told-T)));
ERROR3(c)= error3;
Told=T;
SR(c)=SOR;
SOR=SOR+1;
time3=toc;
c=c+1;
end
figure(3)
colormap(jet);
contourf(x,y,T,'showText','on')
set(gca,'YDir','reverse')
tit3=sprintf('Number of iteration=%d\n Simulation Time=%d s',SOR,time3)
title({'SOR solver for steady state',tit3})
colorbar
pause(0.3)
figure(4)
semilogy(JI,ERROR1,GS,ERROR2,'r',SR, ERROR3,'k');
legend('Jacobi','Gauss Seidel','SOR')
xlabel('No of iterations')
ylabel('log of absolute error')
title ('Comaparison of rate of decrease of error with iterations for three methods')
%Full Code for Transient explicit
clear all
close all
clc
nx=50;
ny=50;
x=linspace(0,1,nx);
y=linspace(0,1,ny);
dx=x(2)-x(1);
dy=y(2)-y(1);
alpha=4e-3;
dt=0.01;
k1=(alpha*dt)/(dx)^2;
k2=(alpha*dt)/(dy)^2;
T=ones(nx,ny);
T(1,:)=600;
T(end,:)=900;
T(:,1)=400;
T(:,end)=800;
Told=T;
T(1,1)=(400+900)/2;
T(end,1)=(400+600)/2;
T(1,end)=(900+800)/2;
T(end,end)=(800+600)/2;
% k=2*((dx^2+dy^2)/(dx^2*dy^2));
Tol=1e-4;
error1=9e9;
for nt=1:15000
tic;
for i=2:nx-1
for j=2:ny-1
m=k1*(Told(i+1,j)+Told(i-1,j)-2*Told(i,j));
n=k2*(Told(i,j+1)+Told(i,j-1)-2*Told(i,j));
T(i,j)=m+n+Told(i,j) ;
end
end
time1=toc;
Told=T;
end
figure(1);
colormap(jet);
contourf(x,y,T,'showText','on')
set(gca,'YDir','reverse')
tit1=sprintf('Simulation Time=%d s',time1)
title({'Solution for transient explicit '})
colorbar
pause(0.3)
%Full COde for Implicit
clear all
close all
clc
nx=50;
ny=50;
x=linspace(0,1,nx);%Grid Spacing along X
y=linspace(0,1,ny);%Grid Spacing along Y
dx=x(2)-x(1);
dy=y(2)-y(1);
alpha=1.5;%Thermal Diffusivity
dt=1e-2;%Time Step
k1=(alpha*dt)/(dx)^2;%CFL along x
k2=(alpha*dt)/(dy)^2;%CFL along y
term1=(1/(1+2*k1+2*k2));
term2=k1*term1;
term3=k2*term1;
T=ones(nx,ny);
T(1,:)=600;
T(end,:)=900;
T(:,1)=400;
T(:,end)=800;
T(1,1)=(400+600)/2;
T(end,1)=(400+800)/2;
T(1,end)=(900+800)/2;
T(end,end)=(800+600)/2;
Told=T;
Tinitial=T;
Tprev=T;
Tol=1e-4;
jacobi_iter=1;
a=1
for nt=1:1400
error1=9e9;
tic;
while(error1>Tol)
for i=2:nx-1
for j=2:ny-1
H=term2*(Told(i-1,j)+Told(i+1,j));
V=term3*(Told(i,j+1)+Told(i,j-1));
T(i,j)=term1*Tprev(i,j)+ H+V;
end
end
error1=max(max(abs(Told-T)));
Error1(a)=error1;
Told=T;%Spatial Temp values updated within the space iteration
jacobi_iter=jacobi_iter+1;
JI(a)=jacobi_iter;
a=a+1;
time1=toc;
end
Tprev=T;%After convergence the T values updated
end
figure(1)
colormap(jet);
contourf(x,y,T,'showText','on')
set(gca,'YDir','reverse')
tit1=sprintf('Number of iteration=%d\n Simulation Time=%d s',jacobi_iter,time1)
title({'Jacobi Iter solver for implicit',tit1})
colorbar
pause(0.3)
%Gauss Seidel Implicit
T=Tinitial;
Told=Tinitial;
Tprev=Tinitial;
gauss_seidel=1;
b=1;
for nt=1:1400
error2=9e9;
tic;
while(error2>Tol)
for i=2:nx-1
for j=2:ny-1
H=term2*(T(i-1,j)+T(i+1,j));
V=term3*(T(i,j+1)+T(i,j-1));
T(i,j)=term1*Tprev(i,j)+ H+V;
end
end
error2=max(max(abs(Told-T)));
Error2(b)=error2;
Told=T;
GS(b)=gauss_seidel;
gauss_seidel=gauss_seidel+1;
b=b+1;
end
Tprev=T;
time2=toc;
end
figure(2)
colormap(jet);
contourf(x,y,T,'showText','on')
set(gca,'YDir','reverse')
tit2=sprintf('Number of iteration=%d\n Simulation Time=%d s',gauss_seidel,time2)
title({'Gauss Seidel Iter solver for implicit',tit2})
colorbar
pause(0.3)
%SOR Implicit
Told=Tinitial;
Tprev=Tinitial;
T=Tinitial;
omega=1.5
SOR=1;
c=1;
for nt=1:1400
error3=9e9;
tic;
while(error3>Tol)
for i=2:nx-1
for j=2:ny-1
H=term2*(T(i-1,j)+T(i+1,j));
V=term3*(T(i,j+1)+T(i,j-1));
T(i,j)=(term1*Tprev(i,j)+ H+V)*omega+(1-omega)*Told(i,j);
end
end
error3=max(max(abs(Told-T)));
Error3(c)=error3;
Told=T;
SR(c)=SOR;
SOR=SOR+1;
c=c+1;
time3=toc;
end
Tprev=T;
end
figure(3)
colormap(jet);
contourf(x,y,T,'showText','on')
set(gca,'YDir','reverse')
tit2=sprintf('Number of iteration=%d\n Simulation Time=%d s',SOR,time3)
title({'SOR Iter solver for implicit',tit2})
colorbar
pause(0.3)
figure(4)
semilogy(JI,Error1,GS,Error2,'r',SR, Error3,'k');
xlabel('ITeration')
ylabel('log of absolute error')
title('Comparison of error with iterations')
legend('Jacobi','Gauss Seidel','SOR')
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Week - 4
Task 1 - Washing Machine Aim:- To implement Control Logic of a Washing Machine that would function as follows:- If the power supply is available, the system gets activated If the Water supply is not available, stop the process & indicate through LED Soaking time should be 200s followed by Washing time of 100s.…
20 Jan 2022 06:31 AM IST
Week -2
Model of a Doorbell:- The model of the door bell used for the simulation is given below. The details of the components are as follows 1. Pulse Generator:- This block generates a pulse of amplitude 1 for a duration of 2 seconds. This signal is converted to a physical signal using a converter block 2. Physical Signal…
18 Jan 2022 04:32 AM IST
Week-11 : Discretization of 3D intake manifold using GEM-3D
Part 1. 1) The study is done on a single cylinder diesel engine Discretization length : Specifies the length of each sub volume where quantities are calculated (Pressure, temperature, mass fractions etc) There are two case setup namely 40mm and 0.1mm Comparison of results We analyse the…
02 Sep 2021 03:19 PM IST
Week 9 - Senstivity Analysis Assignment
Aim:- The aim of this project is to find 10 most sensitive reactions affecting temperature of methane air combustion. Introduction:- Chemical reactions comprise a number of intermediary reactions and species. Attempting to simulate the detailed intermediary steps is computationally expensive. An alternative, to this approach…
17 Aug 2021 05:30 AM IST
Related Courses
0 Hours of Content
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.