Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Problem statement

It is required to obtain the steady-state temperature distribution on a 2D rectangular plate as


shown below.

Dirichlet B.C.: y = 0, T = T1; x = 0, T = T2; y = H, T = T3; x = L, T = T4;


(T1 = 100oC, T2 = T3 = T4 = 0)

Obtain the steady state solution through time-marching of the following governing equation
for unsteady 2D heat conduction without heat generation:
T   2T  2T 
=  2 + 2  (1)
t  x y 

where  is the thermal diffusivity.

• Use the Crank-Nicholson scheme for time-integration and the second order central differencing
technique for the space-discretization. Select constant spatial step sizes ∆x = ∆y = 0.05 m, in
which case imax = 21 and jmax = 41. In the discretized equation use
T T 1 (2)
= =
( x ) ( y )
2 2
2

• Write a computer code to find out the steady state temperature distribution in the plate.

• Give a brief write-up on the physical and mathematical behavior of the governing equation, its
discretization and a plot of the steady state temperature distribution along with the tabulated
results.

Compare the temperatures along the vertical symmetry line of the plate computed by solving the
equation that governs the steady-state-temperature profile and also by obtaining the steady state by
solving the discretized for of equation (1) using the Forward-in-Time and Centred-in-Space (FTCS)
scheme.

Page 1 of 10
Solution
The governing equation is

𝜕𝑇 𝜕2𝑇 𝜕2𝑇
= 𝛼 ( 2 + 2) (i)
𝜕𝑡 𝜕𝑥 𝜕𝑦
Applying the Crank-Nicholson scheme for the time-integration of eq. (i) we get the semi-discrete form
as
𝑛 𝑛+1
𝑇 𝑛+1 − 𝑇 𝑛 𝛼 𝜕 2 𝑇 𝜕 2 𝑇 𝜕 2𝑇 𝜕2𝑇
= [( + ) + ( 2 + 2) ] (ii)
∆𝑡 2 𝜕𝑥 2 𝜕𝑦 2 𝜕𝑥 𝜕𝑦

where the superscript 𝑛 represents an arbitrary time level and ∆𝑡 is the time step. Applying the second-
order central-difference scheme for spatial discretization of eq. (ii), we get the fully-discrete form of
eq. (i) at any arbitrary node (𝑖, 𝑗 ) as
𝑛+1 𝑛 𝑛 𝑛 𝑛 𝑛 𝑛 𝑛
𝑇𝑖,𝑗 − 𝑇𝑖,𝑗 𝛼 𝑇𝑖−1,𝑗 − 2𝑇𝑖,𝑗 + 𝑇𝑖+1,𝑗 𝑇𝑖,𝑗−1 − 2𝑇𝑖,𝑗 + 𝑇𝑖,𝑗+1
= [ + ]
∆𝑡 2 (∆𝑥)2 (∆𝑦)2
𝑛+1 𝑛+1 𝑛+1 𝑛+1 −2𝑇 𝑛+1 +𝑇 𝑛+1 (iii)
𝛼 𝑇𝑖−1,𝑗 −2𝑇𝑖,𝑗 +𝑇𝑖+1,𝑗 𝑇𝑖,𝑗−1 𝑖,𝑗 𝑖,𝑗+1
+ [ (∆𝑥)2
+ (∆𝑦)2
]
2
Eq. (iii) can be recast in the form:
𝑛+1 𝑛+1 𝑛+1 𝑛+1 𝑛+1 𝑛
𝑎𝑆 𝑇𝑖,𝑗−1 + 𝑎𝑊 𝑇𝑖−1,𝑗 + 𝑎𝑃 𝑇𝑖,𝑗 + 𝑎𝐸 𝑇𝑖+1,𝑗 + 𝑎𝑁 𝑇𝑖,𝑗+1 = 𝑏𝑖,𝑗
(iv)

where

𝛼∆𝑡
𝑎𝑆 = 𝑎𝑁 = −
2(∆𝑦)2
𝛼∆𝑡
𝑎𝑊 = 𝑎𝐸 = −
2(∆𝑥)2
(v)
𝛼∆𝑡 𝛼∆𝑡
𝑎𝑃 = 1 + [ + ]
(∆𝑥)2 (∆𝑦)2
𝑛 𝑛 𝛼∆𝑡 𝑛 𝑛 𝑛 𝛼∆𝑡
𝑏𝑖,𝑗 = 𝑇𝑖,𝑗 + [𝑇𝑖−1,𝑗 − 2𝑇𝑖,𝑗 + 𝑇𝑖+1,𝑗 ]+ [𝑇 𝑛 − 2𝑇𝑖,𝑗
𝑛 𝑛
+ 𝑇𝑖,𝑗+1 ]
2(∆𝑥) 2 2(∆𝑦)2 𝑖,𝑗−1
𝑛 𝑛 𝑛 𝑛 𝑛 𝑛
= 𝑇𝑖,𝑗 − 𝑎𝑆 𝑇𝑖,𝑗−1 − 𝑎𝑊 𝑇𝑖−1,𝑗 − (𝑎𝑃 − 1)𝑇𝑖,𝑗 − 𝑎𝐸 𝑇𝑖+1,𝑗 − 𝑎𝑁 𝑇𝑖,𝑗+1
For our chosen combination of temporal and spatial discretization schemes, it can be shown that
the discrete eq. (iv) is unconditionally stable. It is known that for the first-order Euler-explicit method
for time integration and second-order central-difference approximation for spatial discretization (also
known as the Forward-in-Time, Central-in-Space approximation, abbreviated as FTCS scheme) the
stability condition is

𝛼∆𝑡 𝛼∆𝑡 1
2
+ 2
≤ (vi)
(∆𝑥) (∆𝑦) 2

However, since our chosen scheme is unconditionally stable, we can choose a larger time step for a
given grid. Accordingly, let us choose

Page 2 of 10
𝛼∆𝑡 𝛼∆𝑡 (vii)
2
+ = 12
(∆𝑥) (∆𝑦)2
𝐿 1 𝐻 2
For the given problem, we have ∆𝑥 = 𝑖 = 21−1 = 0.05 and ∆𝑦 = 𝑗 = 41−1 = 0.05.
𝑚𝑎𝑥 −1 𝑚𝑎𝑥 −1
Therefore, we have ∆𝑥 = ∆𝑦. Hence, from eq. (vii) we can write

2𝛼∆𝑡
= 12
(∆𝑥)2

𝛼∆𝑡 𝛼∆𝑡
2
= =6
(∆𝑥) (∆𝑦)2 (viii)

Now, from eqs. (v) and (viii) one obtains

𝛼∆𝑡
𝑎𝑆 = 𝑎𝑁 = − = −3
2(∆𝑦)2
𝛼∆𝑡
𝑎𝑊 = 𝑎𝐸 = − = −3 (ix)
2(∆𝑥)2
𝛼∆𝑡 𝛼∆𝑡
𝑎𝑃 = 1 + [ + ] = 13
(∆𝑥)2 (∆𝑦)2

The system of linear algebraic equations of the form given by eq. (iv) can be solved by any of the
iterative methods. Here we choose the Gauss-Seidel method. The iterative formula for eq. (iv) by the
Gauss-Seidel method becomes
𝑛 𝑘+1 𝑘+1 𝑘 𝑘 𝑘
𝑘+1 𝑘
𝑏𝑖,𝑗 − (𝑎𝑆 𝑇𝑖,𝑗−1 + 𝑎𝑊 𝑇𝑖−1,𝑗 + 𝑎𝑃 𝑇𝑖,𝑗 + 𝑎𝐸 𝑇𝑖+1,𝑗 + 𝑎𝑁 𝑇𝑖,𝑗+1 )
𝑇𝑖,𝑗 = 𝑇𝑖,𝑗 + (x)
𝑎𝑃

where the superscript 𝑘 represents an arbitrary-iteration level. Now, in order to obtain the solution at
each interior node (𝑖, 𝑗 ) at each new time level (𝑛 + 1) we have to carry out iterations using eq. (x) till
convergence is achieved. Mathematically, the convergence criteria may be set as
𝑗𝑚𝑎𝑥 −1
𝑖𝑚𝑎𝑥 −1
𝑘+1 𝑘
∑ ∑ |𝑇𝑖,𝑗 − 𝑇𝑖,𝑗 | ≤ 𝜀1 (xi)
𝑖=2
𝑗=2

where 𝜀1 is a very small number, say 𝜀1 = 10−6 . Once convergence is achieved, we can assign
𝑛+1 𝑘+1
𝑇𝑖,𝑗 = 𝑇𝑖,𝑗 (xii)
In order to obtain the steady-state solution of eq. (i) using time-marching an “outer iteration” must be
carried out till the outer loop converges. This can be mathematically stated as
𝑗𝑚𝑎𝑥 −1
𝑖𝑚𝑎𝑥−1
𝑛+1 𝑛
∑ ∑ |𝑇𝑖,𝑗 − 𝑇𝑖,𝑗 | ≤ 𝜀2 (xiii)
𝑖=2
𝑗=2

where 𝜀2 is another small number. We can consider, say 𝜀2 = 𝜀1 = 10−6 . It is evident that in order to
obtain the steady state solution of eq. (i) using eq. (iv) two iteration loops are required, viz., one outer

Page 3 of 10
loop and one inner loop. The pseudocode for the entire procedure can be summarized in the following
steps.
1. Define the grid and all the geometric parameters including the coefficients.
2. Define the boundary conditions.
3. Make the initial guess for the solution, i.e. guess the solutions at all the interior nodes at time
𝑡 = 0, i.e. the time level 𝑛 = 1.
𝑘 𝑛
4. Assign 𝑇𝑖,𝑗 = 𝑇𝑖,𝑗 for all the nodes.
𝑘+1
5. Obtain 𝑇𝑖,𝑗 using eq. (x).
𝑖 −1
6. Check whether ∑𝑖=2
𝑚𝑎𝑥
∑𝑗𝑗=2
𝑚𝑎𝑥 −1 𝑘+1
|𝑇𝑖,𝑗 𝑘
− 𝑇𝑖,𝑗 𝑛+1
| ≤ 𝜀1 . If yes 𝑇𝑖,𝑗 𝑘+1
= 𝑇𝑖,𝑗 and go to step 7, else
𝑘 𝑘+1
assign 𝑇𝑖,𝑗 = 𝑇𝑖,𝑗 and go back to step 5.
𝑖𝑚𝑎𝑥−1 𝑗𝑚𝑎𝑥 −1 𝑛+1 𝑛 𝑛 𝑛+1
7. Check whether ∑𝑖=2 ∑𝑗=2 |𝑇𝑖,𝑗 − 𝑇𝑖,𝑗 | ≤ 𝜀2 . If yes then stop, else assign 𝑇𝑖,𝑗 = 𝑇𝑖,𝑗
and go back to step 4.
A C-code implementing the pseudocode is given in the Appendix.

Page 4 of 10
APPENDIX
#include<stdio.h>
#include<math.h>
#include<time.h>
#define L 1.0
#define H 2.0
#define nx 21
#define ny 41
#define m 30
#define n 50

int i,j,count1,count2;
double
dx,dy,x[m][n],y[m][n],Told[m][n],Tnew[m][n],Told_time[m][n],Tnew_time[m][n],b_old[m][n];
double Res1,Res2,ae,aw,ap,as,an,sum1,sum2;
clock_t start,end;
double cpu_time_used;
//FILE *fp1;

void main()
{
FILE *fp1, *fp2, *fp3, *fp4,*fp5;
fp1=fopen("Temp_Distr.plt","w");
fp2=fopen("Residue_inner.plt","w");
fp3=fopen("Residue_outer.plt","w");
fp4=fopen("Vertical_symmetry_line.plt","w");
fp5=fopen("cpu_time.plt","w");
start=clock();
dx=L/(nx-1);
dy=H/(ny-1);

/****Grid gerenration***/
for(i=1;i<=nx;i++)

Page 5 of 10
{
for(j=1;j<=ny;j++)
{
x[i][j]=(i-1.0)*dx;
y[i][j]=(j-1.0)*dy;
}
}
aw=ae=-3.0;
as=an=-3.0;
ap=13.0;

/***Initial guess***/
for(i=2;i<=nx-1;i++)
{
for(j=2;j<=ny-1;j++)
{
Told_time[i][j]=0.0;
}
}

/***Gauss-Seidal Iterations**/
Res2=1.0;
count2=1;
while(Res2>=pow(10,-6))
{
/***Bottom and top boundary condition***/
for(i=1;i<=nx;i++)
{
Tnew_time[i][1]=100.0;
Tnew_time[i][ny]=0.0;
Told_time[i][1]=100.0;
Told_time[i][ny]=0.0;

Page 6 of 10
Tnew[i][1]=100.0;
Told[i][ny]=0.0;

}
/***Left and right boundary condition***/
for(j=1;j<=ny;j++)
{
Tnew_time[1][j]=0.0;
Tnew_time[nx][j]=0.0;
Told_time[1][j]=0.0;
Told_time[nx][j]=0.0;
Tnew[1][j]=0.0;
Told[nx][j]=0.0;
}
/***Inner Loop begins here***/
for(i=2;i<=nx-1;i++)
{
for(j=2;j<=ny-1;j++)
{
Told[i][j]=Told_time[i][j];
}
}

for(i=2;i<=nx-1;i++)
{
for(j=2;j<=ny-1;j++)
{
b_old[i][j]=Told_time[i][j]-as*Told_time[i][j-1]-aw*Told_time[i-1][j]-(ap-
1.0)*Told_time[i][j]-ae*Told_time[i+1][j]-an*Told_time[i][j+1];
}
}

Res1=1.0;

Page 7 of 10
count1=1;
while(Res1>pow(10,-6))
{
for(i=2;i<=nx-1;i++)
{
for(j=2;j<=ny-1;j++)
{
Tnew[i][j]=Told[i][j]+(b_old[i][j]-(as*Tnew[i][j-1]+aw*Tnew[i-
1][j]+ap*Told[i][j]+ae*Told[i+1][j]+an*Told[i][j+1]))/ap;
}
}
sum1=0.0;
for(i=2;i<=nx-1;i++)
{
for(j=2;j<=ny-1;j++)
{
sum1=sum1+fabs(Tnew[i][j]-Told[i][j]);
}
}
Res1=sum1;
for(i=2;i<=nx-1;i++)
{
for(j=2;j<=ny-1;j++)
{
Told[i][j]=Tnew[i][j];
}
}
fprintf(fp2,"\n%d \t%lf",count1,Res1);
count1++;

}
for(i=2;i<=nx-1;i++)
{

Page 8 of 10
for(j=2;j<=ny-1;j++)
{
Tnew_time[i][j]=Tnew[i][j];
}
}
sum2=0.0;
for(i=2;i<=nx-1;i++)
{
for(j=2;j<=ny-1;j++)
{
sum2=sum2+fabs(Tnew_time[i][j]-Told_time[i][j]);
}
}
Res2=sum2;
for(i=2;i<=nx-1;i++)
{
for(j=2;j<=ny-1;j++)
{
Told_time[i][j]=Tnew_time[i][j];
}
}
printf("\n%d \t%lf",count2,Res2);
fprintf(fp3,"\n%d \t%lf",count2,Res2);
count2++;
}

fprintf(fp1,"ZONE T=BLOCK1, I=%d, J=%d",ny,nx);

for(i=1;i<=nx;i++)
{
for(j=1;j<=ny;j++)

Page 9 of 10
{
fprintf(fp1,"\n%lf \t%lf \t%lf",x[i][j],y[i][j],Tnew_time[i][j]);
}
}
for(j=1;j<=ny;j++)
{
fprintf(fp4,"\n%lf \t%lf",y[(nx+1)/2][j],Tnew_time[(nx+1)/2][j]);
}
fclose(fp1);
fclose(fp2);
fclose(fp3);
fclose(fp4);
end=clock();
cpu_time_used=((double)(end-start))/CLOCKS_PER_SEC;
fprintf(fp5,"Total CPU time used=%0.12lf",cpu_time_used);
fclose(fp5);
}

Page 10 of 10

You might also like