UNDERGRADUATE COMPUTATIONAL ENGINEERING AND SCIENCE

UCES

"Block Tridiagonal Matrices and Heat Diffusion in 2D"

Course:   Methods and Analysis in UCES

Prerequisites:

  1. Math:   Calculus 3 and matrices
  2. Computing:   Maple, nested loops
  3. Science:   Physics

Objectives:

  1. Math:   Existence
  2. Computing:   SOR algorithm
  3. Science:   Heat transfer in two directions

General Information: This is the first model for diffusion in two directions. In the next section we will present similar models which are related to fluid flow.

Contact Person:   R. E. White, NCSU, white@math.ncsu.edu

Revision Date:   8-3-94

Copyright ©1994, R. E. White. All rights reserved.

Return to Table of Contents


3.4   Block Tridiagonal Matrices and Diffusion in 2D

3.4.1.   Introduction.

This section contains an introduction to heat transfer models with diffusion in two directions. Such models generate block tridiagonal algebraic systems. We present several algorithms for solving such problems.

3.4.2.   Applied Area.

In the previous sections we considered a thin and long cooling fin so that one could assume heat diffusion is in only one direction moving normal to the mass to be cooled. If the fin is thick (large T) or if the fin is not long (small W), then the temperature will significantly vary as one moves in the z or y directions.

Figure: Diffusion in Two Directions

In order to model the temperature, we will first assume temperature is given along the 2D boundary and that the thickness T is small. Consequently, there will be diffusion in just the x and y directions. Consider a small mass within the above plate whose volume is (dx dy T). This volume will have heat sources or sinks via the two (dx T) surfaces, two (dy T) surfaces, and two (dx dy) surfaces as well as any internal heat equal to f (heat/ (vol. time)). The top and bottom surfaces will be cooled by a Newton-like law of cooling to the surrounding region whose temperature is usur. The heat flowing through the four vertical surfaces will be given by the Fourier heat law applied to each of the two directions:

change in heat of (dx dy T) = 0 ~ f(x,y) (dx dy T) dt

+ (2 dx dy) dt c(usur - u)

+ (dx T) dt (Kuy(x,y + dy) - Kuy(x,y))

+ (dy T) dt (Kux(x + dx,y) - Kux(x,y)).

This approximation gets more accurate as dx and dy go to zero. So, divide by (dx dy T) dt and let dx and dy go to zero. This gives a differential equation with partial derivatives, and (1) is an example of a partial differential equation.

Steady State 2D Diffusion.

0 = f(x,y) + (2c/T)(usur - u) + (Kux(x,y))x + (Kuy(x,y))y (1)
for (x,y) in (0,L)×(0,W), and where

f(x,y) is the internal heat source,
K is the thermal conductivity,
T is the small thickness of the plate and
c is the ability to transfer heat the surrounding region.


3.4.3.   Model.

The above partial differential equation is usually associated with boundary conditions which may or may not have derivatives of the solution. For the present we will assume the temperature is given as a constant on the boundary of (0,L)×(0,W), L = W = 1, K = 1, f(x,y) = 0 and T = 2. So, we are considering

-uxx - uyy + cu = cusur . (2)

Let uij be the approximation of u(ih, jh) where h = dx = dy = 1.0/n. Approximate the second order derivatives by centered finite differences.

Finite Difference Model of (2)

-[(ui+1,j - uij )/h - (uij - ui-1,j )/h]/h - [(ui,j+1 - uij )/h - (uij - ui,j-1 )/h]/h + cuij = cusur
where 1 i,j n - 1.

There are (n - 1)2 equations for (n - 1)2 unknowns uij . This can be put into matrix form by multiplying the equations by h2 and listing the unknowns starting with the smallest y values and moving from the smallest to the the largest x values. The first grid row of unknowns is denoted by U1 = (u11 , u21 , u31 , u41 )T for n = 5.

Figure: Grid for 2D Diffusion

Hence, the block form of the above system is

The above block tridiagonal system is a special case of the following block tridiagonal system where all entries are N×N matrices (N = 4). The block system has N2 blocks, and so there are N2 unknowns. If the full version of the Gaussian elimination algorithm were used, it would require (N2 )3 /3 = N6/3 operations.

.


3.4.4.   Method.

We present three alternatives to the Gaussian elimination algorithm. The first method is a block version of the tridiagonal algorithm. It requires only order 3N4 operations and less storage than the full version of the Gaussian elimination algorithm. The other two algorithms are variations on the SOR method and can require, for proper choice of SOR parameter, fewer operations and less storage.

In the block tridiagonal algorithm all entries are matrices. The "divisions" for the point form must be replaced by matrix solves, and one must be careful to preserve the proper order of matrix multiplication. The derivation of the following is similar to the derivation of the point form.

Block Tridiagonal Algorithm.


    alpha(1) = A(1)
    solve alpha(1)*gamma(1) = C(1)
    solve alpha(1)*Y(1) = D(1)
    for i = 2, n
        alpha(i) = A(i)- B(i)*gamma(i-1)
        solve alpha(i)*gamma(i) = C(i)
        solve alpha(i)*Y(i) = D(i) - B(i)*Y(i-1)
    endloop
    X(n) = Y(n)
    for i = n - 1,1
        X(i) = Y(i) - gamma(i)*X(i+1)
    endloop.

The block or line version of the SOR algorithm also requires a matrix solve step in place of a "division." Note the matrix solve has a point tridiagonal matrix for the problem in (2).

Block SOR Algorithm.


    for m = 1,maxit
        for i = 1,n
            solve A(i) Xtemp = D(i) - B(i)*X(i-1) - C(i)*X(i+1)
            X(i) = (1-w)*Xtemp + w*X(i)
        endloop
        test for convergence
    endloop.

The point version of SOR for the problem in (2) can be very effectively implemented because we know exactly where and what the nonzero components are in each row of the coefficient matrix. In the following note how the test for convergence is done and how the storage is kept to a minimum.

Point SOR Algorithm for -(uxx + uyy ) + cu = f(x,y) on Omega = (0,1)×(0,1) and u given on Boundary of Omega.


    define w, n, eps
    h = 1/n
    tol = eps*h*h
    for m = 1,maxit
        numi = 0
        for j = 1,n-1
            for i = 1,n-1
                utemp = (h*h*f(i*h,i*h) + u(i,j-1) + u(i-1,j) +
                               u(i+1,j) + u(i,j+1))/(4 + h*h*c)
                utemp = (1 - w)*u(i,j) + w*utemp
                error = abs(utemp - u(i,j))
                u(i,j) = utemp
                if error < tol then
                   numi = numi + 1
                endif
             endloop
        endloop
        if numi = (n-1)*(n-1) go to end
    endloop
    end.

3.4.5.   Implementation.

Maple is used to code the point SOR algorithm for a cooling plate which has a fixed temperature at its boundary. Two sets of outputs are graphed. The first one is with the cooling constant c = 1.0, and the graph indicates the trace curves in the x and y directions. The second output is for c = 10.0, and one can see the plate has been cooled to a lower temperature. Also, we have graphed the temperature by indicating the equal temperature curves or contours.

Maple Code for a Cooled Plate and Point SOR.


   Input Data:
        > with(linalg):
	> with(plots):
        > c:=.4:
        > usur:= 70:
        > eps:=.1:
        > n:= 8:
        > w:=1.4:
        > f:=(x,y)->c*usur:

   Procedure BVP2D and SOR is Defined:
        > BVP2D:=proc(f,c,n,w,eps):
        > u:=matrix(n+1,n+1,200):
        > h:=1/n:
        > maxit:=400:
        > tol:=eps*h*h:
        > for m from 1 to maxit do
        >     numi:=0:
        >     for j from 2 to n do
        >         for i from 2 to n do
        >             utemp:= evalf((h*h*f(i*h,j*h) + u[i,j-1] + u[i-1,j]
                                         + u[i+1,j] + u[i,j+1])/(4 + h*h*c)):
        >             utemp:= (1-w)*u[i,j] + w*utemp:
        >             error:= abs(utemp - u[i,j]):
        >             u[i,j]:= utemp:
        >             if error < tol then 
                            numi:=numi + 1
                      fi:
        >         od:
        >     od:
        >     if numi = (n-1)*(n-1) then break fi:
        > od:
        > end:

   Output Data:
        > BVP2D(f,1.,8,1.4,.1):
        > matrixplot(u,style=wireframe,axes=boxed);

Figure: Temperature of Cooled Plate, c = 1.0 and x and y Trace Curves

        > numi;
        49
        > m;
        19
        > BVP2D(f,10.,8,1.4,.1):
        > matrixplot(u,style=wireframe,axes=boxed);

Figure: Temperature of Cooled Plate, c = 10.0 and Contour Curves

The following Matlab code for the numerical solution of

-uxx -uyy = pisin(pix) pisin(piy) on (0,1)×(0,1) with u = 0 on the boundary

illustrates the SOR algorithm and how it depends on the choice of the SOR parameter, omega.

Matlab Code and SOR.


   function [w,soriter] = sor2d(n,w)
   h = 1./n;
   tol =.1*h*h;
   maxit = 500;
   u = zeros(n+1);
   f = zeros(n-1);
   for i=2:n
       for j=2:n
             f(i,j) = h*h*pi*pi*sin(pi*(i-1)*h)*sin(pi*(j-1)*h);
         end
     end
     for iter =1:maxit
         numi = 0;
         for j = 2:n
             for i = 2:n
                 utemp = (f(i,j) + u(i,j-1) + u(i-1,j) + u(i+1,j) + u(i,j+1))*.25;
                 utemp = (1. - w)*u(i,j) + w*utemp;
                 error = abs(utemp- u(i,j));
                 u(i,j) = utemp;
                 if error<tol
                    numi = numi + 1;
                 end
             end
         end
         if numi==(n-1)*(n-1) 
            break;
         end
     end
     w;
     soriter = iter;

Output in Graphical Form:

     >>for i = 1:20
           [x(i),y(i)] = sor(20,1. + (i-1)*.05);
          end
     >>plot(x,y)

Figure: Iterations for Convergence versus omega


3.4.6.   Assessment.

In the above first 2D heat diffusion model we kept the boundary conditions simple. However, in the 2D model of the cooling fin one should consider the heat that passes through the edge portion of the fin. This is similar to what was done for the cooling fin with diffusion in just the x direction. There the heat flux at the tip was given by the boundary condition Kux (L) = c(usur - u(L)). For the 2D steady state cooling fin model we have similar boundary conditions on the edge of the fin that is away from the mass to be cooled.

0 = f(x,y) + (2c/T)(usur - u) + (Kux(x,y))x + (Kuy (x,y))y ,

    Kux (L,y) = c(usur - u(L,y)),
    -Kuy (x,0) = c(usur - u(x,0)),
    Kuy(x,W) = c(usur - u(x,W)) and
    u(0,y) = given temperature of the mass to be cooled.

Figure: Cooling Fin with Boundary Conditions

The finite difference model must have additional equations for the cells near the edge of the fin. So, in the above figure there are 10 equations for the (dx dy) cells, 5 equations for the (dx/2 dy) cells, 4 equations for the (dx dy/2) cells and 2 equations for the corner (dx/2 dy/2) cells. For example, the cells at the right most side with (dx/2 dy) the finited difference equations are for i = n and 1 < j < n

0 = f(L,j dy) (dx/2 dy T) dt

      + (2 dx/2 dy) dt c(usur - unj )

      + (dx/2 T) dt [K(un,j+1 - unj )/dy - K(un,j - un,j-1 )/dy]

      + (dy T) dt [c(usur - unj ) - K(unj - un-1,j )/dx].

The other portions of the boundary are similar.

Another question is related to the existence of solutions. Note the diagonal components of the coefficient matrix are much larger than the off-diagonal components. For each row the diagonal component is strictly larger than the sum of the absolute value of the off-diagonal components. In the finite difference model for (2) the diagonal component is 4/h2 + c and the four off-diagonal components are -1/h2.

Definition. Let A = [aij ]. A is called strictly diagonally dominant if and only if for all i

Examples. The one and two dimensional models of heat diffusion give strictly diagonally dominant matrices.

Existence Theorem. Consider Ax = d and assume A is strictly diagonally dominant. If there is a solution, it is unique. Moreover, there is a solution.

Proof. Let x and y be two solutions. Then A(x - y) = 0. If x - y is not zero, then we can choose i so that |xi - yi | = max |xj - yj| > 0.

Divide by (xi - yi ) and use the triangle inequality to contradict the strict diagonal dominance.

The existence follows from the uniqueness. Since the matrix is square, we can find elementary matrices such that Ax = d is equivalent to EAx = Ux = Ed where U is upper triangular and E is a product of elementary matrices. If U has a zero diagonal component, then there will be more than one solution, which cannot happen. So, U must have all nonzero diagonal components, and we can construct via back substitution a solution of Ux = Ed, that is, a solution of Ax = d.


3.4.7.   Homework.

  1. Consider the Maple code for the point SOR algorithm. Experiment with the convergence parameter eps and observe the number of iterations required for convergence.

  2. Consider the Maple code for the point SOR algorithm. Experiment with the parameter omega and observe the number of iterations for convergence. Do this for n = 4, 8, 16 and find the omega that gives the smallest number of iterations for convergence.

  3. Consider the Matlab code for the point SOR algorithm. Let c = 0, f(x,y) = pi2 sin(pix) sin(piy) and require u to be zero on the boundary of (0,1)×(0,1). Show the solution is u(x,y) = sin(pix) sin(piy). Compare it with the numerical solution with n = 4, 8, 16. Observe the error is of order h2.

    Why have we used a convergence test with tol = eps*h2 ?

  4. Implement the block tridiagonal algorithm for the problem in 3.

  5. Implement the block SOR algorithm for the problem in 3.

  6. Consider the cooling fin problem with derivative boundary conditions. Find the numerical solution when T = 0.1, W = 10.0, L = 4.0, variable c, dx = L/4 and dy = W/10. Graph the temperature and discuss the accuracy of this model.

  7. Complete the proof of uniqueness for strictly diagonally dominant matrices.