You are on page 1of 14

Machine Exercise No.

2
Acosta, Timothy John S.
August 4,2011

Abstract
This report tackles the 2nd Machine Exercise given by Professor Sargado during the
1 semester of SY 2011-12. This Machine Exercise (Mx) covers the Finite Difference Method
for Elliptic Partial Differential Equations. The partial differential equation given was that
for a 2D steady heat transfer.
2
2
+
=0
dx2
y 2
st

The problem tackles a square plate that is insulated at one edge, heated at the
opposide edge (constant flux) and kept at constant but different temperatures at two remaining edges. The temperature distribution is described by the governing equation and the
following boundary value conditions:


= 0
y y=0


= 10
y y=100
(0, y) = 50
(10, y) = 100
The problem was solved by a numerical solution using the 5-point stencil Finite
Difference Method for Laplace equations. A O(h2 ) central difference formula was used for
the approximations of the 2nd derivatives. In result, a system of equations was formed by
the FDM approximation. For this, the Gauss-Seidel Method (also known as the Liebmanns
Method) was used to solve for the unknowns. The stopping criterion for the iterative method
used was governed by the following:


new old
i,j
i,j
|i,j | =
100 0.01

new
i,j

Chapter 1
The Laplacian Difference Equation
The steady heat transfer within a two-dimensional domain is governed by the equation:
2
2
+
=0
dx2
y 2

(1.1)

In order to solve the problem, the central difference formula (2nd order) was used for the
approximations of the 2nd derivatives.

Figure 1.1: A grid used to visualize the finite difference solution

CHAPTER 1. THE LAPLACIAN DIFFERENCE EQUATION


Based on the grid scheme from Figure 1, we get
2
i+1,j 2i,j + i1,j
=
2
x
x2
2

i,j+1 2i,j + i,j1
=
y
x
y 2
Substituting these equations into equation 1.1 gives
i+1,j 2i,j + i1,j i,j+1 2i,j + i,j1
+
=0
x2
y 2

(1.2)

= 10) and
Since for the given square plate that is to be heated at one end (denoted by
y

2
2
insulated at the other (denoted by y = 0), as shown in Figure 1, x and y are equal

Figure 1.2: Problem domain, boundary conditions and discretization


This reduces equation (1.2) to
i1,j 4i,j + i+1,j + i,j1 + i,j+1 = 0
"
#
1
i,j =
i1,j + i+1,j + i,j1 + i,j+1
4

(1.3)

Equation (1.3) is then used to determine the temperature() at the given coordinate (i,j )
throughout the square plate. This relationship which holds for all interior points on the
plate, is referred to as the Laplacian difference equation
2

CHAPTER 1. THE LAPLACIAN DIFFERENCE EQUATION


The equations for each node are then assembled into matrix form

411 21
0
12 . . .
... ...
11 421 31
0
22
. . . . . .

4
0
0

21
31
32

. . . = Boundary Conditions
11

0
0
412 22
0

..
0
.

21
12
22
32

..
..
..
..
..
..
..
.
.
.
.
.
.
.
For the given problem, we would be producing 5 x 5 equations to be describing
each node for the square plate. But the unknown nodes for the given problem are 6 x 6.
Therefore in oder to reduce the number of unknowns, we go into the boundary conditions.
The temperatures for the right and left side of the square is given. But only the flux
(1st derivative) of the temperature is given for the upper and lower part of the square.


= 0
y y=0


= 10
y y=100
Still using a 2nd order central difference method, we get the approximation for the 1st derivatives along the y-axis

i,j+1 i,j1

y
2y
i,j1 = i, j + 1 2y

This now gives a relationship for i,j1 that includes the derivative. It is then substituted
to equation (1.3) to give
2i,j+1 2y
i,j

+ i+1,j 4i,j = 0
y



1

= 2i,j+1 2y
+ i1,j + i+1,j
4
y

(1.4)

This now give us 5 x 5 equations and unknowns. Making it now possible to solve the system
of equations.

Chapter 2
Iterative Method
2.1

The Liebmann Method

Since the system of equations is too big, it would be impractical to solve through linear
algebraic equations. Therefore, we iterate equation (1.3) for all the nodes (i=1 to 6 and j=1
to 6). Because the matrix produced by the system of equations is diagonally dominant, this
procedure will eventually converge to a stable solution. Equation (1.3) would be iterated for
all the nodes inside the square plate while equation (1.4) would be iterated for all the nodes
along the upper and lower boundaries of the square plate.
"
#
1
i1,j + i+1,j + i,j1 + i,j+1
i,j =
4


1

bc
+ i1,j + i+1,j
i,j =
2i,j+1 2y
4
y

2.2

Successive Overrelaxation

For the conventional Gauss-Seidel method, the iterations are repeated until the absolute
value of all the percent relative errors i,j are less than 0.01. Which is computed by the
following equation:


new old
i,j
i,j
|i,j | =
100 0.01
new

i,j
Aside from the conventional Gauss-Seidel method, we can employ overrelaxation to increase
the rate of convergence. Where instead of just directly putting the new value, the new value
is computed by the following formula:
new
old
new
i,j = i,j + (1 )i,j

; where 0 < < 2

(2.1)

2.3. THE SOURCE CODE

2.3
1
2
3
4
5

CHAPTER 2. ITERATIVE METHOD

The Source Code

#include"files.h"
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<conio.h>

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

void main()
{
double k,error;
int ctr=0,ctr1;
matrix A=defmatrix(6,6);
matrix B=defmatrix(6,6);
matrix C=defmatrix(6,6);
matrix D=defmatrix(6,6);
matrix E=defmatrix(6,6);
double **a=A.elems;
double **b=B.elems;
double **c=C.elems;
double **d=D.elems;
double **e=E.elems;
scanf("%lf",&k);
/*Setting Boundary Conditions*/
for(int i=0;i<6;i++)
{
a[i][0]=50;
a[i][5]=100;
}
/*Iteration Using Gauss-Seidel Method*/
do{
ctr++;
/*1st derivative boundary condition*/
for(int j=1;j<5;j++){
a[0][j]=((2*a[1][j])+a[0][j+1]+a[0][j-1])/4;
a[5][j]=((2*a[4][j])+(20*2*10)+a[5][j+1]+a[5][j-1])/4;
}
/*Computing for Unknowns*/
for(int i=1;i<5;i++){
for(int j=1;j<5;j++)
{
b[i][j]=a[i][j];
a[i][j]=((a[i-1][j]+a[i+1][j]+a[i][j+1]+a[i][j-1])/4);
a[i][j]=(a[i][j]*k)+(b[i][j]*(1-k));

43
44
45
46
47
48
49

e[i][j]=abs(((a[i][j]-b[i][j])/a[i][j]))*100;
}
}
ctr1=0;
for(int i=1;i<5;i++)
for(int j=1;j<5;j++){

2.3. THE SOURCE CODE

CHAPTER 2. ITERATIVE METHOD

if(e[i][j]>0.01)
{
error=e[i][j];
ctr1++;
}
}

50
51
52
53
54
55
56
57

}while(ctr1>0);

58
59
60
61
62
63
64
65

printf("\ne=%lf\n",error);
printf("\ncounter=%d\n",ctr);
/*Flux Computation*/
/*X-Direction*/
for(int i=0;i<6;i++)
for(int j=1;j<5;j++)
c[i][j]=(a[i][j-1]-a[i][j+1])/(2*20);

66
67
68
69
70
71
72
73
74

/*Y-Direction*/
for(int j=0;j<5;j++)
{
d[0][j]=0;
d[5][j]=10;
}
for(int i=1;i<5;i++)
for(int j=0;j<6;j++)
d[i][j]=(a[i+1][j]-a[i-1][j])/(2*20);

75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97

/*STORING DATA*/
FILE*data = fopen("mx2.txt", "w");
fprintf(data, "parameter=%lf" ,k);
fprintf(data, "\nTEMPERATURE DISTRIBUTION:\n");
for(int i=0;i<6;i++)
{fprintf(data, "\n");
for(int j=0;j<6;j++)
fprintf(data, "
%.10lf " ,a[i][j]);
}
fprintf(data, "\nFLUX along X-AXIS:\n");
for(int i=0;i<6;i++)
{fprintf(data, "\n");
for(int j=0;j<6;j++)
fprintf(data, "
%.10lf " ,c[i][j]);
}
fprintf(data, "\nFLUX along Y-AXIS:\n");
for(int i=0;i<6;i++)
{fprintf(data, "\n");
for(int j=0;j<6;j++)
fprintf(data, "
%.10lf " ,d[i][j]);
}
}

2.3. THE SOURCE CODE


CHAPTER 2. ITERATIVE METHOD
The program starts by asking the user to input the parameter which is to be used for
successive overrelaxation. It then sets the Boundary Conditions along the two edges of the
square plate, wherein the heat is maintained at 50 at one edge and 100 at the other. The
equation (1.4) is then iterated for the sides along the heated and insulated edges of the
square plate.
21,j + 0,j+1 + 0,j1
4
24,j + 200 + 5,j+1 + 5,j1
=
4

bottom
=
0,j

(2.2)

top
5,j

(2.3)

It is assumed that the square plate is heated from the top. Thus, the / y along the top
edge is equal to positive 10. This would indicate a heat flow into the square. Equation (1.3)
is then iterated over the nodes within the boundaries of the square plate. As the iteration
continues, the value of the error for each node is also computed. The iterations stop when
the values for the error of each node are less than 0.01. The program then computes for
the partial derivatives along the x and y axis. Once done, the program stores the heat
distribution, heat flux along the x and y axis and the number of iterations made due to the
parameter chosen.

Chapter 3
Results and Discussion
3.1

Overrelaxation

The program was used 19 times to get the number of iterations per increase of 0.1 in the
parameter value (0 < < 2). The table below shows the data gathered.
Parameter Value Number of Iterations
0.1
445
0.2
244
0.3
167
0.4
126
0.5
101
0.6
82
0.7
69
0.8
59
0.9
50
1
44
1.1
38
1.2
33
1.3
29
1.4
25
1.5
22
1.6
19
1.7
20
1.8
29
1.9
42
Table 3.1: Data gathered per parameter value
As you can see in the table above, the greatest number of iterations is seen for a parameter
8

3.2. TEMPERATURE DISTRIBUTION CHAPTER 3. RESULTS AND DISCUSSION


value of 1.6. Therefore, it converges fastest for a parameter of 1.6 for overrelaxation. To
better understand the relationship, we plot a graph of the parameter value vs the number
of iterations.

Figure 3.1: Number of Iterations vs Parameter Value

3.2

Temperature Distribution

For the square plate, our first assumption is that the left and right edges are kept at constant
temperatures 50 and 100 respectively. The second assumption is that the top part of the
square plate is heated while the bottom part is insulated. In order to visualize the heat
distribution, countour map is made to show the different levels of heat for certain areas of
the square plate.

Figure 3.2: Countour Map for Temperature Distribution

3.3. FLUX DISTRIBUTION


CHAPTER 3. RESULTS AND DISCUSSION
Our assumptions correspond with our countour map. Wherein, the highest temperatures
are located along the edge where there is a inward flux of 10 along the y-axis ( / y).

3.3

Flux Distribution

To get the flux distribution along the x-axis, we take the partial differentiation of the equation
along the corresponding axis. Which is equation (1.4). Using the program, the flux is
generated in matrix form. It is then converted to a 3-Dimensional graph to visualize the flux
distribution along the axis chosen.

Figure 3.3: Flux Distribution along the X-Axis


Likewise, to get the flux distribution along the y-axis, the partial derivative with respect
to the y-axis is taken for each node in the square. This gives the following 3-Dimensional
Surface:

Figure 3.4: Flux Distribution along the Y-Axis


10

3.3. FLUX DISTRIBUTION


CHAPTER 3. RESULTS AND DISCUSSION
This surface also confirms our assumption wherein the top edge ,which is heated, has the
most dramatic change in flux because it is heated. As the nodes go farther from the heat
source, the nodes become more unaffected by the heat source, thus a smaller flux. Therefore,
we can conclude that our assumptions for the phenomenon is correct.

Figure 3.5: Flux Distribution along the square in both axes


The 3-Dimensional surface above describes the change in flux throughout the square plate
in the x and y axis.

Figure 3.6: Countour Map showing the flux distribution


A countour map is also shown for visualization purpose of the change in flux distribution
throughout the square.

11

Bibliography
[1] Chapra Canale: Numerical Methods for Engineers, 6th Edition (2009)
[2] Joe D. Hoffmann: Numerical Methods for Engineers and Scientists, 2nd Edition (2001)
[3] J.M Sargado: Machine Exercise II, Finite Difference Method for Elliptic PDEs (2011)

12

You might also like