Computational Heat Transfer ME673 Mini Project 2 Revised

Embed Size (px)

Citation preview

  • 8/12/2019 Computational Heat Transfer ME673 Mini Project 2 Revised

    1/14

    1

    Numerical Heat Transfer ME673

    Mini-Project 2

    Second Semester 1435

    Due date Wednesday April 23rd

    Consider the two-dimensional steady state heat conduction in an isotropic medium,

    Defined over the domain .Subject to the following boundary conditions:

    Where,

    1. Obtain an expression for evaluating the boundary condition at x=0.2. Discretize the PDE using a five-point stencil3. Use Gauss-Seidel iterative scheme to obtain the steady-state temperature distribution.

    Use the convergence criteria below. Develop a computer code to do the calculations.

    4. Plot temperature contours at steady state.5. Investigate over-relaxation on convergence acceleration.

    Convergence CriteriaConvergence can be assumed when the convergence parameter, p, is less than .Wherepis defined as,

    [ ]

    Note: All submitted work should be entirely yours. Include source code in your report.

  • 8/12/2019 Computational Heat Transfer ME673 Mini Project 2 Revised

    2/14

    2

    In order to evaluate the boundary condition at x = 0, the following condition is used.

    (1)

    The R.H.S of Eq. (1) will be discretized by using a ghost node/point (a point outside the

    domain) as shown inFigure 1.Furhtermore, a second order central difference scheme will be

    used on the R.H.S of this equation (see Eq.(2) and Figure 1).

    ( )

    (2)

    Then, by means of this point, the final difference equation for the boundary condition

    can be constructed in conjunction with the five-stencil FDE of the corresponding PDE that

    will be developed later. For this reason, the discussion on the expression for the convection

    boundary condition will be postponed until the five-point stencil has been developed in the

    next discussion/question. It should be mentioned that in this report the index count starts from

    (i , j) = (1 , 1) on the lower-left-corner of the domain.

    Figure 1: Showing the points and indices used to develope the expression for the convection boundary

    condition, Eq.(1).Note: The total number of nodes is only an example.

  • 8/12/2019 Computational Heat Transfer ME673 Mini Project 2 Revised

    3/14

    3

    In the next question (question no.2), it is asked to discretize the PDE considered using

    a five-point stencil. The PDE is shown below, Eq.(3).

    (3)

    Figure 2: Showing the points and indices used in developing the FDE of the correspondingPDE, Eq.(3).Note: The total number of nodes in this figure is only an example.

    Based onFigure 2,we will develop the five-point stencil finite difference equation (FDE) as

    follows.

    (4)

    (5)

  • 8/12/2019 Computational Heat Transfer ME673 Mini Project 2 Revised

    4/14

    4

    Substitute Eq.(4),and(5) into Eq.(3)

    (6)

    The truncation error of the FDE, Eq.(6),is O[,]. Collecting and re-arranging termswe obtain the following.

    (7)

    In order to simplify, Eq.(7) can be written as shown below.

    (8)

    where

    (9)

    Continuing the previous discussion regarding question no.1, i.e., obtaining expression

    for evaluation the convection boundary condition, the FDE of Eq.(8) will be utilized together

    with Eq.(2).In the following derivation, points and indices inFigure 1 are used.

    Solving Eq.(2) for the ghost point, , Eq.(10) will be obtained.

    {( ) } (10)

    Now, Eq. (8) will be applied on point (i,j) in Figure 1 in order to get the other equation.

    Afterwards, Eq.(10) will be substituted into this equation to get:

  • 8/12/2019 Computational Heat Transfer ME673 Mini Project 2 Revised

    5/14

    5

    {( ) }

    (11)

    After collecting terms and solving for, , we obtain the final expression, Eq. (12), fortreating the convection boundary condition.

    (12)

    Next, the above equation are written into FORTRAN code to be solved using

    Successive Over Relaxation (SOR) method. The code can be seen at the end of this report. In

    order to verify the code, a test was conducted by comparing the results of a simple (low

    number of segments) mesh with 2x2 segments (Figure 3) obtained by means of the

    FORTRAN code with that of manual calculation. The results show a very good agreement

    between both calculation methods as can be seen inTable 1.

    Figure 3: Schematic of the mesh used for verification of the FORTRAN code

    Table 1: Comparison between the results obtained by manual calculation andFORTRAN code for 2x2 segments mesh

    Nodes Manual calculation (C) FORTRAN code (C)

    (i,j) = (1,2) 287.9 287.9(i,j) = (2,2) 172 172

  • 8/12/2019 Computational Heat Transfer ME673 Mini Project 2 Revised

    6/14

    6

    In task no.4 and 5, it is required that the temperature contours be plotted and over-

    relaxation on convergence acceleration/speed be investigated. We, firstly, will address the

    latter, i.e., the effect of relaxation factor, , on the speed of convergence.Calculations were done for several segments of mesh with various relaxation factors

    () as can be seen in theTable 2.It can be seen clearly from the table that increasing the to

    a value of greater than one will increase the convergence speed. This founding is consistent

    with the rule that . However, it was also found that there is a limit whereincreasing beyond that value will decrerase the convergence speed. This can be seen in thetable for 10x10, 20x20, and 200x200 segments. Hence, an optimum value ofexists. Also,it is found that at the calculation is not converging even up to 500 iterations for 20x20mesh.

    Table 2: The various calculation parameter settings

    Next, the contour plot of the temperature is presented with constant omega ( but changing the number of segments. FromFigure 4 -Figure 7,it can be observed that the

    Number of segments Omega No. of iterations

    1 95

    1.2 65

    1.4 41

    1.6 21

    1.8 52

    1 321

    1.2 225

    1.4 151

    1.6 90

    1.8 55

    1.9 121

    2Still not converge

    for 500 iterations

    50 x 50 1.6 470100 x 100 1.6 1528

    1.8 2453

    1.95 697

    1.97 401

    1.98 630

    1.99 1201

    10 x 10

    20 x 20

    200 x 200

  • 8/12/2019 Computational Heat Transfer ME673 Mini Project 2 Revised

    7/14

    7

    trend of the temperature distribution for all number of segments presented are the same. The

    difference is only that the least number of segments (10x10) gives coarser temperature

    contour. It becomes smoother when the number of segments increased.

    Figure 4: Temperature contour plot for mesh of 10x10 segments

    Figure 5: Temperature contour plot for mesh of 20x20 segments

  • 8/12/2019 Computational Heat Transfer ME673 Mini Project 2 Revised

    8/14

    8

    Figure 6: Temperature contour plot for mesh of 50x50 segments

    Figure 7: Temperature contour plot for mesh of 100x100 segments

  • 8/12/2019 Computational Heat Transfer ME673 Mini Project 2 Revised

    9/14

    9

    The FORTRAN Code

    PROGRAM Steady_2D_heat_equation

    IMPLICIT NONE

    INTEGER :: i,j,iter,m,n,max_iter

    !m is number of segments in x direction

    !n is number of segments in y direction grid points

    !iter is for iteration number (count from 0)

    !max_iter is the possible maximum iteration

    REAL, PARAMETER :: h=250.d0, Tamb=300.d0, k=5.d0

    !h is the convection HTC (W/m^2.C)

    !Tamb is the ambient temperature (C)

    !k is the thermal conductivity of the material (W/m.C)

    REAL, PARAMETER :: T_bottom = 50.d0, T_right = 200.d0, T_top = 150.d0

    !The Ts above are the temp. of boundaries

    REAL :: xsize, ysize, p, omega

    !xsize is size of the domain in x dir

    !ysize is size of the domain in y dir

    !omega is the over/under relaxation factor

    REAL :: dx, dy, a, b, c

    !dx is the size of the segment in x direction

    !dy is the size of the segment in y direction

  • 8/12/2019 Computational Heat Transfer ME673 Mini Project 2 Revised

    10/14

    10

    DOUBLE PRECISION, ALLOCATABLE :: T(:,:), T_old(:,:)

    !T is the temperature (C). It is designated to be

    !allocatable, i.e., 2D matrix with adjustable size.

    WRITE(*,10,ADVANCE='no')

    READ(*,*) xsize

    WRITE(*,11,ADVANCE='no')

    READ(*,*) ysize

    WRITE(*,12,ADVANCE='no')

    READ(*,*) m

    WRITE(*,13,ADVANCE='no')

    READ(*,*) n

    WRITE(*,15,ADVANCE='no')

    READ(*,*) omega

    WRITE(*,14,ADVANCE='no')

    READ(*,*) max_iter

    WRITE(*,*)

    WRITE(*,*) 'The values that you have entered are:'

    WRITE(*,*)

    WRITE(*,*) 'x =', xsize

    WRITE(*,*) 'y =', ysize

    WRITE(*,*) 'm =', m

    WRITE(*,*) 'n =', n

    WRITE(*,*) 'omega =', omega

    WRITE(*,*) 'max_iter =', max_iter

    WRITE(*,*)

    !Calculate dx, dy, a, b, and c

    dx = xsize/m

    dy = ysize/n

    a = 1/(dy*dy)

  • 8/12/2019 Computational Heat Transfer ME673 Mini Project 2 Revised

    11/14

    11

    b = 1/(dx*dx)

    c = -2*(a + b)

    WRITE(*,*) 'Thus, the value of dx, dy, a, b, and c obtained are as follows'

    WRITE(*,*)

    WRITE(*,*) 'dx=',dx

    WRITE(*,*) 'dy=',dy

    WRITE(*,*) 'a=',a

    WRITE(*,*) 'b=',b

    WRITE(*,*) 'c=',c

    WRITE(*,*)

    WRITE(*,*) 'Where a = 1/dx^2, b = 1/dy^2, and c = -2(a+b)'

    WRITE(*,*)

    OPEN (unit = 1 , file = "result_2D_steady_cond")

    WRITE(1,*) 'The values that you have entered are:'

    WRITE(1,*)

    WRITE(1,*) 'x =', xsize

    WRITE(1,*) 'y =', ysize

    WRITE(1,*) 'm =', m

    WRITE(1,*) 'n =', n

    WRITE(1,*) 'omega =', omega

    WRITE(1,*) 'max_iter =', max_iter

    WRITE(1,*)

    WRITE(1,*) 'Thus, the value of dx, dy, a, b, and c obtained are as follows'

    WRITE(1,*)

    WRITE(1,*) 'dx=',dx

    WRITE(1,*) 'dy=',dy

    WRITE(1,*) 'a=',a

    WRITE(1,*) 'b=',b

    WRITE(1,*) 'c=',c

    WRITE(1,*)

  • 8/12/2019 Computational Heat Transfer ME673 Mini Project 2 Revised

    12/14

    12

    WRITE(1,*) 'Where a = 1/dx^2, b = 1/dy^2, and c = -2(a+b)'

    WRITE(1,*)

    !Allocate the size of T and T_old

    ALLOCATE(T(0:m+1,0:n+1))

    ALLOCATE(T_old(0:m+1,0:n+1))

    !initialize

    T(:,:) = 0.d0

    T_old(:,:) = 0.d0

    !Define the boundary conditions

    T(:,1) = T_bottom

    T(:,n+1) = T_top

    T(m+1,:) = T_right

    !Calculate the Temperature distribution

    iter = 0 !iteration counter

    p = 1 !first guess for p (any number > 1e-5)

    DO WHILE (p >= 1.d-5 .AND. iter

  • 8/12/2019 Computational Heat Transfer ME673 Mini Project 2 Revised

    13/14

    13

    T(i,j) = T(i,j) + omega*(1/c*(-a*T(i,j-1) - b*T(i-1,j) - b*T_old(i+1,j) -

    b*T_old(i,j+1)) - T(i,j))

    ENDIF

    ENDDO

    ENDDO

    p = ABS(MAXVAL(T(1:n,2:m)-T_old(1:n,2:m))/MAXVAL((T(1:n,2:m))))

    iter=iter+1

    ENDDO

    WRITE(1,*)'The temperature distribution:'

    WRITE(1,*)

    WRITE(1,*)' i=1 i=2 i=3 ...(so on if available)'

    DO j=1,n+1

    WRITE(1,22,ADVANCE='no') 'j =',j

    WRITE(1,22,ADVANCE='no')' '

    DO i=1,m+1

    WRITE(1,21,ADVANCE='no') T(i,j)

    ENDDO

    WRITE(1,*)

    ENDDO

    WRITE(1,*)

    WRITE(1,*) 'The residual =', p

    WRITE(1,*)

    WRITE(1,*) 'Number of iteration =', iter

    10 FORMAT('The size of the domain in x direction, x = ')

  • 8/12/2019 Computational Heat Transfer ME673 Mini Project 2 Revised

    14/14

    14

    11 FORMAT('The size of the domain in y direction, y = ')

    12 FORMAT('The number of segments in x direction, m = ')

    13 FORMAT('The number of segments in y direction, n = ')

    14 FORMAT('Maximum iteration, max_iter = ')

    15 FORMAT('Over/under relaxation factor, omega = ')

    21 FORMAT(F6.1)

    !FORMAT no.21 is to let the value using this format to be Real decimal form (for 'F') and

    !the last digit is written at the 6th space (for '6') and consist of 1 decimal number after point

    (for .1)

    22 FORMAT(A3,I4)

    END PROGRAM Steady_2D_heat_equation