Finite Di erence Method

17
Finite Difference Method Applied to a two-dimensional, steady-state, heat transfer problem MEMS1055, Computer Aided Analysis in Transport Phenomena Dr. Peyman Givi Seth Strayer 2/12/19

Transcript of Finite Di erence Method

Page 1: Finite Di erence Method

Finite Difference Method

Applied to a two-dimensional, steady-state, heat transfer problem

MEMS1055, Computer Aided Analysis in Transport PhenomenaDr. Peyman Givi

Seth Strayer2/12/19

Page 2: Finite Di erence Method

Contents

1 Introduction 1

2 Formulation 22.1 Deriving the Heat Diffusion Equation for Finite Difference . . . . . . . . . . . . . . . 22.2 Iterative Solving Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22.3 Heat Transfer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

3 Results 43.1 Temperature Distribution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43.2 Method Trends . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43.3 Mesh Dependence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53.4 Heat Transfer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

4 Conclusion 8

5 Appendix 95.1 SOR Method MATLAB Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

i

Page 3: Finite Di erence Method

1 Introduction

In this report, we wish to use the finite difference method to solve for the steady-state temperaturedistribution in a pipe whose cross-section is shown in Figure 1. Three different iterative methodswill be used to solve this problem, namely, the Jacobian, Gauss-Seidel, and Successiveover-relaxation (SOR) methods. The boundary conditions for this problem, outlined in Figure 1,are as follows:

Figure 1: Problem Layout Describing Geometry and Boundary Conditions

• Dirichlet boundary condition of Th = 300[K] applied to the upper-left and upper-right sides

• Dirichlet boundary condition of Tc = 200[K] applied the middle side joining the two arcsegments

• Neumann boundary condition applied to the bottom and lower-right sides

Furthermore, the following physical parameters for the system are assumed:

• Internal heat generation of q̇ = 5e+ 7[W/m3]

• Thermal conductivity coefficient of k = 20[W/m ·K]

Given these parameters, we would like to use the finite difference method to solve for thesteady-state temperature distribution in the rod. Particularly, we wish to:

• Create contour plots of the steady-state temperature distribution

• Calculate the total heat transfer per unit length [W/m] from the rod

• Comment on the differences between the Jacobian, Gauss-Seidel, and SOR methods

• Determine an optimum δR and δθ - i.e., determine the optimum ”step size”

• Determine if our system satisfies the First Law of Thermodynamics

1

Page 4: Finite Di erence Method

Additionally, the residual error (E) will be closely monitored. In this report, residual error refersto the maximum, absolute value of the difference between any two corresponding elements of thecurrent iterations temperature matrix and the previous iterations temperature matrix. Namely,

E = max | T ki,j − T k−1

i,j | (1)

for i = {1, 2, ...,m}, j = {1, 2, ..., n} and k = {1 : N}, where m and n are the number of rows andcolumns, respectively, and N is the total number of iterations. The residual will first be monitoredas a function of the number of iterations, and second, as a function of the mesh grid size. It isexpected that as the number of iterations increases and the mesh grid size decreases (moreelements used), the residual error will decrease.

2 Formulation

2.1 Deriving the Heat Diffusion Equation for Finite Difference

In this subsection, the steady-state, heat diffusion equation in terms of the finite difference methodis derived. Consider the general form of the Laplace equation under steady-state conditions,assuming a constant thermal conductivity, k, and internal heat generation q̇. In polar coordinates,this is given by:

∂2u

∂r2+

1

r

∂u

∂r+

1

r2∂2u

∂θ2=q̇

k(2)

First and second order central finite difference methods show that, in general:

∂u

∂x=ui+1,j − ui−1,j

2δx(3)

∂2u

∂x2=ui−1,j − 2ui,j + ui+1,j

δx2(4)

Note that Equations 3 and 4 ignore any truncation error associated with the method. Then interms of the finite difference method, the Laplace Equation (2) can be written as:

ui−1,j − 2ui,j + ui+1,j

(δr)2+

1

iδr

ui+1,j − ui−1,j2δr

+1

(iδr)2ui−1,j − 2ui,j + ui+1,j

(δθ)2=q̇

k(5)

By rearranging the terms in Equation 5 and solving for ui,j , we have means of implementing aniterative algorithm to solve for the temperatures present at each node in the system. Note that inorder to solve using the finite difference method, there must be some initial guess for all unknowntemperatures in the system. We will assume an initial guess of zero for all unknown nodes. This isaccomplished by using the MATLAB command

T = zeros(rows, cols)

where T is the temperature matrix, rows is the number of gridpoints in the radial direction, andcols is the number of gridpoints in the angular direction.

2.2 Iterative Solving Methods

In general, when solving for the nodal temperatures in our system, we are trying to solve a systemof n linear equations, where n is the total number of nodes in the system. This system is easilydescribed by:

2

Page 5: Finite Di erence Method

Ax = b (6)

where A is a n x n matrix of coefficients, x is a vector of n unknown values, and b is a vector of nconstants. Rather than solving these equations directly, methods such as Jacobian, Gauss-Seidel,and SOR solve these equations iteratively, which is very desirable for large systems. In general, theJacobian method is given by:

xk+1i =

1

aii(bi −

∑j 6=i

aijxkj ) (7)

where xk is the kth iteration of x and i = 1, 2, ..., n. The Gauss-Seidel method employs forwardsubstitution and is given by:

xk+1i =

1

aii(bi −

i−1∑j=1

aijxk+1j −

n∑j=i+1

aijxkj ) (8)

for i = 1, 2, ..., n. The SOR method is very similar to the Guass-Seidel method except for the factthat it employs a relaxation factor, ω, to achieve faster convergence.

xk+1i = (1− ω)xki +

ω

aii(bi −

i−1∑j=1

aijxk+1j −

n∑j=i+1

aijxkj ) (9)

for i = 1, 2, ..., n, and 0 < ω < 2. In all three cases, iterations are performed until the differencebetween iterations reaches a specified tolerance. By definition of these iterative methods, wepredict that the SOR method will converge most rapidly while the Jacobian method will convergeleast rapidly.

2.3 Heat Transfer

There is an internal heat generation of q̇ = 5 · 107[W/m3]. The total heat generated per unit lengthis given by:

q′gen = q̇Ac (10)

Where Ac is the total cross-sectional area, given by a summation of the two arc segments:

Ac =1

2R2

1θ1 +1

2R2

2θ2

Ac =1

2(0.007)2(0.43633) +

1

2(0.010)2(0.78540) = 4.996 · 10−5 (11)

Then from Equations 10 and 11:

q′gen = (5 · 107)(4.996 · 10−5) ≈ 2500[W/m] (12)

From the First Law of Thermodynamics, the internal heat generated should be equal in magnitudeto the total heat flux across the Dirichlet boundaries, namely:

˙Egen = ˙Eout (13)

This energy balance will be verified in the MATLAB script to ensure that our system satisfies theFirst Law. Results are given in Section 3.4.

3

Page 6: Finite Di erence Method

3 Results

3.1 Temperature Distribution

A contour plot of the steady-state temperature distribution in the rod is shown in Figure 2.

Figure 2: Steady-State Temperature Distribution in the Rod

This temperature distribution was solved for using an initial temperature guess of zero for allunknown nodes and a tolerance of tol = 1e− 004. Thus, the solution is reached at the firstiteration where the residual satisfies:

E < 1e− 004 (14)

Note that, in general, the temperature distribution will be the same regardless of which method isused. However, the number of iterations associated with reaching this tolerance is highlydependent on the method used, as will be discussed in the following section.

3.2 Method Trends

This section will discuss the effects that the varying finite difference methods have on convergencerate. This study used a constant step size of dr = dt = 1. For the SOR method, a relaxation factorof ω = 1.94 was used. This optimum value was determined via a ”guess-and-check” method, whereω was altered until the number of iterations was minimized. Note that the optimum value of ω willchange based on the step size. A table summarizing convergence rates for each type of method isshown on the following page.

4

Page 7: Finite Di erence Method

Method Iterations, N Residual, E Solution Time [s]Jacobian 15854 9.999313e-05 18.40

Gauss-Seidel 8594 9.994095e-05 10.42SOR 279 4.456120e-05 0.91

Table 1: Convergence Rate of Finite Difference Methods

Table 1 indicates that, in regards to convergence rate, SOR peforms most effectively and Jacobianmethod performs least effectively, which verifies the prediction made in Section 2.2. Figure 3 showsa semi-log plot of residual error versus the first 500 iterations . We see that, at first, there is alarger residual associated with the SOR method. However, while the slope of the Jacobian andGauss-Seidel methods plateau, the slope of the SOR method remains steep. This indicatesfavorable convergence times for the SOR method. I.e., the reduction in residual error per iterationof the SOR method remains relatively high compared to that of the Jacobian and Gauss-Seidelmethods. Note that, in general, we are satisfied with the results portrayed in Figure 3. The plotverifies that as the number of iterations increases, the residual error decreases.

Figure 3: Residual Error vs. Number of Iterations; N = 0:500

3.3 Mesh Dependence

Having proved that the residual error decreases as the number of iterations increases, we wouldnext like to pick a set number of iterations and examine how the residual behaves with decreasingmesh size (more elements used). For this study, only the Jacobian and Gauss-Seidel methods willbe examined, since the relaxation factor associated with the SOR method is dependent upon themesh grid size. If the SOR method was to be examined, an optimum relaxtion factor would haveto be calculated for each mesh size. A set number of iterations, namely N = 100, was used for thisstudy. The mesh grid size was halved until a mesh grid size factor, β, of 16 was achieved. For

5

Page 8: Finite Di erence Method

equal step sizes in the radial and angular directions (which is assumed for this study), this factor isgiven by Equation 15:

β =1

dr=

1

dt=

1

h(15)

Thus, the smallest step size used was dr = dt = 0.0625. A semi-log plot of the normalized residualerror (residual divided by the total number of grid points) versus mesh grid size factor is shown inFigure 4.

Figure 4: Residual Error vs. Mesh Grid Size Factor

Figure 4 shows that as the mesh grid size is decreased (more elements used), the relative residualerror decreases. Thus, a smaller grid size implies less error associated with the solution. However,decreased mesh size leads to significantly longer run-times, so, in practical settings, there must besome balance between the two. The ”true” ideal mesh grid size occurs when round-off error meetstruncation error in a graph of error versus grid resolution. At this point, maximum error will be ata minimum while achieving the most effective run-time.

3.4 Heat Transfer

To verify the accuracy of our solution, it suffices to show that the magnitude of internal heatgeneration (per unit length) is equal to the magnitude of the heat flux across the Dirichletboundaries. By doing so, we are verifying that our system satisfies the First Law ofThermodynamics (Section 2.3). Recall that the magnitude of the internal heat generation, givenby Equation 12, is:

q′gen ≈ 2500[W/m]

The corresponding code used to calculate the total heat flux is given in the Appendix, Section 5.1,lines 230-270. Note that due to roundoff/truncation errors when calculating the temperature

6

Page 9: Finite Di erence Method

matrix values, the total heat flux may vary between different methods. However, we do not expectthese variations to be considerable. The SOR method was used for this study since it has afavorable convergence rate and since the converged temperature matrix does not depend on therelaxation factor. Using the SOR method with initial step size dr = dt = 1 and ω = 1.94, wecalculate a total heat flux (heat loss) of:

q′ = 1050[W/m]

This is nearly a 58% error with the anticipated heat generation. Having ensured that the code iscorrectly calculating the heat flux across the boundaries, we next hypothesize that the grid aspectratio is the cause of the high error. I.e., since heat is only leaving through the cold boundary, it isnecessary to have a sufficient amount of nodes in the radial direction. Employing a radial step sizeof dr = 0.5 and an angular step size of dt = 1, we find that:

q′ = 2098[W/m]

which maintains only a 16.08% error with the calculated heat generation term. A tablesummarizing different mesh grid sizes and their corresponding percent errors is shown in Table 2.

Method dr dt Heat Flux [W/m] Percent ErrorSOR 1 1 1050 58.00SOR 0.5 1 2098 16.08SOR 0.25 1 2908 16.32SOR 0.25 0.5 -1427 157.08SOR 0.125 0.5 -1304 152.16SOR 0.0625 0.5 -1232 149.28

Table 2: Mesh Grid Sizes and their Corresponding Heat Flux

At dr = 0.5 and dt = 1, the aspect ratio is well defined such that there is more heat leaving thecold boundary than is entering the system from the hot boundaries. Decreasing the grid size in theradial direction any further (dr = 0.25, dt = 1) allows too much net heat to leave, and decreasingthe grid size in the angular direction would only result in a lower net heat loss (more heat flux overthe hot boundaries). Furthermore, if we significantly decrease the mesh size in the radial direction,the inward heat flux across the hot boundary over a radius of r = 1 : 10 [mm] will overcome theoutward heat flux across the cold boundary. Thus, we conclude that this problem is somewhatill-posed, based on the boundary conditions. The optimum grid size in terms of satisfying the FirstLaw of Thermodynamics is dr = 0.5 and dt = 1, yielding a total heat flux of

q′ = 2098[W/m] (16)

with an associated percent error of:

Error =2500− 2098

2500· 100 = 16.08% (17)

7

Page 10: Finite Di erence Method

4 Conclusion

In this report, the finite difference method was used to solve for the steady-state temperaturedistribution in a pipe whose cross-section is shown in Figure 1. Three different iterative schemeswere used, including the Jacobian, Gauss-Seidel, and Successive Over-Relaxation (SOR) methods.The temperature distribution was solved through the use of MATLAB, and the contour plot of thesteady-state temperature distribution adhering to a tolerance of tol = 1e− 004 is shown in Figure2. Some of the key findings obtained through this report are as follows:

• Total heat transfer per unit length from the rod is q′gen ≈ 2500[W/m]

• SOR method performs most favorably in terms of convergence rate, while Jacobian perfromsleast favorably

– SOR performs the fewest number of iterations to achieve convergence, with the shortestrun-time

– Jacobian performs the largest number of iterations to achieve convergence, with thelongest run-time

• Residual Error is a function of the number of iterations performed and the mesh grid size

– Residual Error decreases as number of iterations increases (Figure 3)

– Relative Residual Error decreases as mesh grid size is refined (Figure 4)

• Total heat flux is dependent upon the mesh grid size

– Optimum step sizes, in terms of satisfying the First Law of Thermodynamics, aredr = 0.5 and dt = 1 (Table 2)

Overall, we are satisfied with the results, and have implemented the finite difference method alongwith three different iterative solver schemes to solve a steady-state heat transfer problem.

8

Page 11: Finite Di erence Method

5 Appendix

5.1 SOR Method MATLAB Code

9

Page 12: Finite Di erence Method

10

Page 13: Finite Di erence Method

11

Page 14: Finite Di erence Method

12

Page 15: Finite Di erence Method

13

Page 16: Finite Di erence Method

14

Page 17: Finite Di erence Method

15