Week 5.1 - Mid term project - Solving the steady and unsteady 2D heat conduction problem
AIM:
To solve 2D heat conduction equation for steady and transient state using various iterative techniques such as Jacobi, Gauss Seidel and Successive over relaxation methods using MATLAB.
Steady-state analysis:
The 2D Transient equation: ππππ‘∝(π2πππ₯2+π2πππ¦2)=0
The Steady-state equation: (π2πππ₯2+π2πππ¦2)=0
Assume that the domain is a unit square.
Now assigning boundary conditions.
Temperatures for steady-state
T_L=400; %Temp at left boundary
T_T=600; %Temp at top boundary
T_R=800; %Temp at right boundary
T_B=900; %Temp at bottom boundary
From the above Boundary conditions, we can calculate the central temperature of the domain
(ππ)=1/πΎβ((ππΏ ππ
/ππ₯2)+(ππ+ππ΅/ππ¦2))
For 2D heat conduction equation we are using the following method:
- JACOBI-In this method, the 2D heat conduction equation solves using calculating the value of temperature at inner nodes using several iterations, in which each values of temperature will be previously assigned temperature values at nodes.
- GAUSS-SEIDEL-In this method, the 2D heat conduction equation solves, we are calculating the value of temperatures at inner nodes using several iterations, in which every value of temperature will be updated successively with respect to the previous iteration.
- SUCCESSIVE OVER-RELAXATION-In this method, the 2D heat conduction equation solves. We are calculating the value of temperatures at inner nodes using several iterations, in which respect to the previous iteration And also “Relaxation factor” multiplies to the algebraic equation to alter the path of the iteration.
When RF<1 under relax
When RF<1 over relax
The Value of Relaxation factor can be taken as 1.1 or 1.2
The Relaxation factor plays a vital role in determining the rate of convergence for CFD simulation
MATLAB Coding for Steady state equation:
clear allclose allclc%COd to solve second order 2-dimensional heat conduction equation%Steady-state Analysis : d^2t/dx^2+d^2/dy^2=0%InputsL=1;%The domain is a unit squarenx=10;ny=nx;%grid points along x and y directiondx=L/(nx-1);%Change of x wrt x co-ordinatedy=L/(ny-1);%change of y wrt y co_ordinatex=linspace(0,1,nx);y=linspace(0,1,ny);%assigning boundry conditions% temperatures for stedy and transient caseT_L=400;T_T=600;T_R=800;T_B=900;T=ones(nx,ny); %temperature array%updating value of temperaturesT(:,1)=T_L;T(:,end)=T_R;T(1,:)=T_T;T(end,:)=T_B;3Told=T;[x y]=meshgrid(x,y);%w=2*((dx^2+dy^2)/(dx^2*dy^2));iterative_solver=1;error=9e9;tol=1e-4;%tolerance value%jacobi methodtic;jacobi_iter=1;while(error>tol)for i=2:nx-1for j=2:ny-1T(i,j)=0.25*((Told(i-1,j)+Told(i+1,j)))+0.25*((Told(i,j-1)+Told(i,j+1)));endenderror=max(max(abs(Told-T)));Told=T;jacobi_iter=jacobi_iter+1;endA=toc;figure(1)contourf(x,y,T, 'ShowText','on');colormap(jet);colorbar;title_text=sprintf('JACOBI, Iteration number=%d, computation time=%f', jacobi_iter, A);title(title_text);xlabel('X-axis');ylabel('Y-axis');set(gca,'YDIR','reverse')pause(0.003);%GS method%InputsL=1;%The domain is a unit squarenx=10;ny=nx;%grid points along x and y directiondx=L/(nx-1);%Change of x wrt x co-ordinatedy=L/(ny-1);%change of y wrt y co_ordinatex=linspace(0,1,nx);y=linspace(0,1,ny);%assigning boundry conditions% temperatures for stedy and transient caseT_L=400;T_T=600;T_R=800;T_B=900;4T=ones(nx,ny);%temperature array%updating value of temperaturesT(:,1)=T_L;T(:,end)=T_R;T(1,:)=T_T;T(end,:)=T_B;Told=T;[x y]=meshgrid(x,y);%w=2*((dx^2+dy^2)/(dx^2*dy^2));iterative_solver=1;error=9e9;tol=1e-4;%tolerance valuetic;gs_iter=1;while(error>tol)for i=2:nx-1for j=2:ny-1T(i,j)=0.25*((T(i-1,j)+Told(i+1,j)))+0.25*((T(i,j-1)+Told(i,j+1)));endenderror=max(max(abs(Told-T)));Told=T;gs_iter=gs_iter+1;endB=toc;figure(2)contourf(x,y,T, 'ShowText','on');colormap(jet);colorbar;title_text=sprintf('GS, Iteration number=%d, computation time=%f', gs_iter, B);title(title_text);xlabel('X-axis');ylabel('Y-axis');set(gca,'YDIR','reverse')pause(0.003);% Successive over relaxation method%InputsL=1;%The domain is a unit squarenx=10;ny=nx;%grid points along x and y directiondx=L/(nx-1);%Change of x wrt x co-ordinatedy=L/(ny-1);%change of y wrt y co_ordinatex=linspace(0,1,nx);y=linspace(0,1,ny);5%assigning boundry conditions% temperatures for stedy and transient caseT_L=400;T_T=600;T_R=800;T_B=900;T=ones(nx,ny);%temperature array%updating value of temperaturesT(:,1)=T_L;T(:,end)=T_R;T(1,:)=T_T;T(end,:)=T_B;Told=T;[x y]=meshgrid(x,y);%w=2*((dx^2+dy^2)/(dx^2*dy^2));iterative_solver=1;error=9e9;tol=1e-4;%tolerance value%jacobi methodtic;sor_iter=1;omega=1.1%relaxation factorwhile(error>tol)for i=2:nx-1for j=2:ny-1T(i,j)= (1-omega)*Told(i,j)+omega*(0.25*((T(i-1,j)+Told(i+1,j)))+0.25*((T(i,j-1)+Told(i,j+1))));endenderror=max(max(abs(Told-T)));Told=T;sor_iter=sor_iter+1;endC=toc;figure(3)contourf(x,y,T, 'ShowText','on');colormap(jet);colorbar;title_text=sprintf('SOR, Iteration number=%d, computation time=%f', sor_iter, A);title(title_text);xlabel('X-axis');ylabel('Y-axis');set(gca,'YDIR','reverse')pause(0.003);
Temperature plots:
Jacobi method:

Gauss-seidel method:

Successive Over Relaxation method:

STEADY STATE RESULTS:
Method Iteration No Computation time
Jacobi 217 0.013008
Gauss-seidel 117 0.007118
Successive-over 96 0.013008
Relaxation
Transient thermal analysis:
Transient thermal analysis is the analysis of the change in properties of the substance that occur due to change in temperature calculated over a particular period of time.
The 2D Transient equation: π π/ππ‘ ∝(π^2 π/ππ₯^2+d^2 π/πy^2)=0
For explicit method
Difference equation ad Re-arranging:
ππ(π+1)=ππ(π)+πΎ1β(ππΏ −2βππ+ππ
)(π)+πΎ2β(ππ−2βππ+ππ΅)(π)
Where K1 &K2 are CFL values in x and y direction.
πΎ1=πΌβππ‘/ππ₯2 ; πΎ2=(πΌβππ‘)βππ¦2
For explicit term the CFL value should <=0.5 to make the solution stable.
MATLAB Coding for Explicit method:
clear allclose allclc%COd to solve second order 2-dimensional heat conduction equation_EXPLICIT_METHOD%unSteady-state Analysis : (dT/dt)-alphad^2T/dx^2+d^2/dy^2=0%InputsL=1;%The domain is a unit squarenx=10;ny=nx; %grid points along x and y directiondx=L/(nx-1); %Change of x wrt x co-ordinatedy=L/(ny-1); %change of y wrt y co_ordinatealpha=1.4; %heat conduction coeficientdt=1e-3; %time stept=1.2; %time initializationnt=t/dt; %no of timestepsx=linspace(0,1,nx);y=linspace(0,1,ny);%assigining boundary conditions%temperatures for steady and transient caseT_L=400; %Temp at left boundaryT_T=600; %Temp at top boundaryT_R=800; %Temp at right boundaryT_B=900; %Temp at bottom boundaryT=ones(nx,ny); %temperature array%updating values of temperaturesT(:,1)=T_L;T(:,end)=T_R;T(1,:)=T_T;T(end,:)=T_B;Told=T;[x y]=meshgrid(x,y);%w=2*((dx^2+dy^2)/(dx^2*dy^2));%9% iterative_solver=1;% error=9e9;% tol=1e-4; %tolerance valuealpha=1.4; %heat transfer coeficient%CFL numbersk1=(alpha*dt)/dx^2;k2=(alpha*dt)/dy^2;%explicit methodstic;% explicit_iter=1;% while(error>tol)for k=1:ntfor i=2:nx-1for j=2:ny-1T(i,j)=Told(i,j)+k1*(Told(i-1,j)-2*Told(i,j)+Told(i+1,j))+k2*(Told(i,j-1)-2*Told(i,j)+Told(i,j+1));endenderror=max(abs(Told-T));Told=T;% explicit_iter=explicit_iter+1;endtime=toc;figure(1)contourf(x,y,T,'ShowText','on');colormap(jet)colorbar;title_text=sprintf('EXPLICIT, Iteration number=%d,Computation time=%f',nt,time);title(title_text);xlabel('X-axis');ylabel('Y-axis');set(gca,'YDIR','reverse')pause(0.003);
Plot:

Difference equation for implicit scheme:
ππ(π+1)=ππ(π+1)+πΎ1β(ππΏ −2βππ+ππ )(π+1)+πΎ2β(ππ−2βππ+ππ΅)(π+1)
MATLAB Coding Implicit Method:
clear allclose allclc%COd to solve second order 2-dimensional heat conduction equation_IMPLICIT_METHOD%unSteady-state Analysis : (dT/dt)-alphad^2T/dx^2/dy^2=0%InputsL=1;%The domain is a unit squarenx=10;ny=nx; %grid points along x and y directiondx=L/(nx-1); %Change of x wrt x co-ordinatedy=L/(ny-1); %change of y wrt y co_ordinatealpha=1.4; %heat conduction coeficientdt=10; %time stept=1000; %time initializationnt=t/dt; %no of timestepsalpha=1.4; %heat transfer coeficientCFL=(alpha*dt)/dx^2;x=linspace(0,1,nx);y=linspace(0,1,ny);%assigining boundary conditions%temperatures for steady and transient case11T_L=400; %Temp at left boundaryT_T=600; %Temp at top boundaryT_R=800; %Temp at right boundaryT_B=900; %Temp at bottom boundaryT=ones(nx,ny); %temperature array%updating value of temperaturesT(:,1)=T_L;T(:,end)=T_R;T(1,:)=T_T;T(end,:)=T_B;Told=T;T_previous=T;[x y]=meshgrid(x,y);%w=2*((dx^2+dy^2)/(dx^2*dy^2));% iterative_solver=1;error=9e9;tol=1e-4;%CFL numbersk1=(alpha*dt)/dx^2;k2=(alpha*dt)/dy^2;% assigining the termsterm1=(1+2*k1+2*k2)^-1;term2=k1*term1;term3=k2*term1;prompt= 'Choose solver 1 = jacobi, 2 = GS, 3 = SORn';method = input(prompt);%Jacobi methodstic;if method==1jacobi_iter=1;% error=9e9;%% tol=1e-4;for k=1:ntwhile(error>tol)for i=2:nx-1for j=2:ny-1H=(Told(i-1,j)+Told(i+1,j));V=(Told(i,j-1)+Told(i,j+1));T(i,j)=(term1*T_previous(i,j))+(term2*H)+(term3*V);endenderror=max(max(abs(Told-T)));Told=T;jacobi_iter=jacobi_iter+1;12endT_previous=T;endtime=toc;figure(1)contourf(x,y,T, 'ShowText','on');colormap(jet);colorbar;title_text=sprintf('JACOBI, Iteration number=%d, computation time=%f, CFL=%f', jacobi_iter,time,CFL);title(title_text);xlabel('X-axis');ylabel('Y-axis');set (gca,'YDIR','reverse')pause(0.003);end%GS methodsif method==2tic;gs_iter=1;for k=1:ntwhile(error>tol)for i=2:nx-1for j=2:ny-1H=(T(i-1,j)+Told(i+1,j));V=(T(i,j-1)+Told(i,j+1));T(i,j)=(term1*T_previous(i,j))+(term2*H)+(term3*V);endenderror=max(max(abs(Told-T)));Told=T;gs_iter=gs_iter+1;endT_previous=T;endtime=toc;figure(2)contourf(x,y,T, 'ShowText','on');colormap(jet);colorbar;title_text=sprintf('GAUSS-SEIDEL, Iteration number=%d, computation time=%f, CFL=%f', gs_iter,time,CFL);13title(title_text);xlabel('X-axis');ylabel('Y-axis');set (gca,'YDIR','reverse')pause(0.003);end%Successive over relaxation methodsif method==3tic;omega=1.4; %relaxation factorsor_iter=1for k=1:ntwhile(error>tol)for i=2:nx-1for j=2:ny-1H=(T(i-1,j)+Told(i+1,j));V=(T(i,j-1)+Told(i,j+1));T(i,j)=((1-omega)*Told(i,j))+(omega*((term1*T_previous(i,j)+(term2*H)+(term3*V))));endenderror=max(max(abs(Told-T)));Told=T;sor_iter=sor_iter+1;endT_previous=T;endtime=toc;figure(3)contourf(x,y,T, 'ShowText','on');colormap(jet);colorbar;title_text=sprintf('SOR, Iteration number=%d, computation time=%f, CFL=%f', sor_iter,time,CFL);title(title_text);xlabel('X-axis');ylabel('Y-axis');set(gca,'YDIR','reverse')pause(0.003);end
PLOTS:
Jacobi Method:

Gauss Seidel methods:
Successive over relaxation methods:

Unsteady state results:
TRANSIENT STATE RESULTS:
Method Iteration NO Computation time
Jacobi 216 0.009385
Gauss-seidel 116 0.010209
Successive-over 47 0.507227
Relaxation
Inference from the Explicit and Implicit Graph:
Explicit Approach:
Relatively simple to program. However, for a given value of dx, dt must be very less than some limit imposed by stability constraints. Hence the CFL no along x and y direction should be less than 0.5 to get stable solutions.
Implicit Approach:
Stability can be maintained over a larger value of dt, hence CFL can be larger, which does not affect the solutions, hence using considerable fever time steps to make calculations for a given interval of t. this results in less computer time. However, it is more complicated to program.
Since large dt can be taken, the truncation error is large, and the use of implicit methods to follow the exact transients (time variation of the independent variable) may not be as accurate as an explicit approach.
However, for a time-dependent solution in which the steady-state is the desired solutions, this relative time wise inaccuracy is not important.
link:
https://documentcloud.adobe.com/link/review?uri=urn:aaid:scds:US:c3ef9f57-eaf4-4d4c-b4df-594c6e062850