Implementation of Alternating Direction Implicit Method to Solve Two Dimensional Heat Conduction with Mathematica

Scott Beckman
August 2000

University of California at Berkeley
Material Science and Engineering Department
577 Evans Hall #1760
Berkeley, CA 94720
sbeckman@uclink.berkeley.edu

Introduction  1

Alternating Direction Method  1.1

The alternating direction implicit, ADI, method is a common algorithm used in finite difference methods.  Below it is demonstrated how to implement ADI with Mathematica.  Although Mathematica isn't the most efficient package for finite difference problems, it is an excellent tool for visualizing how ADI works.  Large scale application should inevitably involve translating the below into C or FORTRAN code/

Parabolic partial differential equation, PDE, can be expressed at implicit finite difference equations.  When such a PDE is has two spatial dimensions, the number of terms in the equation are too large to be solved efficiently.  The basic gist of ADI is to break a large implicit finite difference equation, over time step δt, into two step, each over the time step [Graphics:Images/ADI_gr_1.gif].  The first step implicitly solves for heat conduction in one direction only.  The input to this step are the current temperatures T(x,y,n) and the results from this step are an intermediate temperature distribution, called [Graphics:Images/ADI_gr_2.gif], which is sometimes incorrectly referred to as T(x,y,n+[Graphics:Images/ADI_gr_3.gif]).  The second step solves implicitly for the heat conduction in the other directional only.  The input to this step is, [Graphics:Images/ADI_gr_4.gif] and the resulting output is the temperature at n+1, T(x,y,n+1).

So thermal conduction in 2D

[Graphics:Images/ADI_gr_5.gif]

expressed as a finite difference equation

[Graphics:Images/ADI_gr_6.gif]

can be broken down to

[Graphics:Images/ADI_gr_7.gif]

[Graphics:Images/ADI_gr_8.gif]

The former of the above two is first solved for [Graphics:Images/ADI_gr_9.gif] and the result is substituted in to the latter equation to find T(x,y,n+1).  Notice that upon arranging the first equation to find [Graphics:Images/ADI_gr_10.gif] the expression is an implicit finite different equation in the x direction only.  The second equation, rearranged is an implicit equation in the y direction only.

Details of the ADI method, such as error and proof of stability, can be found in Carnahan's text.

    Carnahan, Luther,and Wilkes.  Applied Numerical Methods. New York: John Wiley & Sons, Inc., 1969.

Difference Equations and Boundary Conditions  1.2

As shown above, the first derivative is written

[Graphics:Images/ADI_gr_11.gif]

Similarly second derivatives are written

[Graphics:Images/ADI_gr_12.gif]

Boundary conditions require a special formulation of the spatial derivative.  For our problem we will be using Newton's law of cooling as our boundary condition

[Graphics:Images/ADI_gr_13.gif]

which can be arranged to the form

[Graphics:Images/ADI_gr_14.gif]

Carnahan shows that the second derivative of this boundary condition, which he calls, "third condition," is written

[Graphics:Images/ADI_gr_15.gif]

Solving this problem is now a matter of substituting the appropriate approximations for the derivatives and solving the resulting matrices, which will be tridiagonal.  

Conventions and Initiation  2

To reduce the number of constants that are carried throughout this problem, the following grouping conventions will be used.

[Graphics:Images/ADI_gr_16.gif]

[Graphics:Images/ADI_gr_17.gif]

[Graphics:Images/ADI_gr_18.gif]

The below commands turn off the error code [General::spell] which is a common warning given in this notebook because of the naming scheme selected.  For debugging purposes this can be turned back on with the command On[General::spell]

[Graphics:Images/ADI_gr_19.gif]
[Graphics:Images/ADI_gr_20.gif]

The below add-on Mathematica add-on packages are needed for this problem.

[Graphics:Images/ADI_gr_21.gif]

We define the number of x step Nx and number of y step Ny so (1≤x≤Nx) and (1≤y≤Ny)

[Graphics:Images/ADI_gr_22.gif]

Set the temperature, T to be the function Tfct.  Note that the hold operator is being used only for the convenience of demonstration.  The actual electrothermal does not need such.  

[Graphics:Images/ADI_gr_23.gif]

Implicit in X Direction  3

Prepare Input to TridiagonalSolve  3.1

Mathematica has a function, TridiagonalSolve which will be used.  For an exact explanation of this function, the reader is referred to the Mathematica on-line use guide.  In short the TridiagonalSolve function operates as

[Graphics:Images/ADI_gr_24.gif]

T=TridiagonalSolve[A,B,C,D]

where T,A,B,C, and D are vectors

For the ADI method, solving for A,B,C, and D vectors is a matter of substituting equations and rearranging.  In this example, the solution for each instance will not be given.  As it will be shown below, it is possible for the reader to use this notebook to back out the system of equations for each point in space.  In the accompanying notebook, Implementation of Brian's Method to Solve Three Dimensional Heat Conduction with Mathematica, it is shown how to use Mathematica to derive the vectors for input to the TridiagonalSolve function.  

[Graphics:Images/ADI_gr_25.gif]
[Graphics:Images/ADI_gr_26.gif]
[Graphics:Images/ADI_gr_27.gif]
[Graphics:Images/ADI_gr_28.gif]

Check the Input  3.2

We can now extract columns from the matrices to check that the solution we entered matches the solution achieved when solving by hand.

For the case middle of the region, (1<i<Nx) and (1<j<Ny), take values, say

[Graphics:Images/ADI_gr_29.gif]
[Graphics:Images/ADI_gr_30.gif]
[Graphics:Images/ADI_gr_31.gif]
[Graphics:Images/ADI_gr_32.gif]
[Graphics:Images/ADI_gr_33.gif]
[Graphics:Images/ADI_gr_34.gif]
[Graphics:Images/ADI_gr_35.gif]
[Graphics:Images/ADI_gr_36.gif]
[Graphics:Images/ADI_gr_37.gif]

Which, when substituted, should match the equation

[Graphics:Images/ADI_gr_38.gif]

In this manner, all of the systems of equations can be verified.

Assign Values to Constants  3.3

To achieve a numerical answer from the TridiagonalSolve function, values must be assigned to the constants

[Graphics:Images/ADI_gr_39.gif]

Loop Over Entire Region  3.4

[Graphics:Images/ADI_gr_40.gif]

Implicit in Y Direction  4

Prepare Input to Tridiagonal Solve  4.1

Clearing values so the correctness of step two can be verified symbolically.

[Graphics:Images/ADI_gr_41.gif]

Writing the equations for the second step ones notices that there is a direct parallelism between the first and second step.  Take for instance the equation which is comparable to the sample given in section 3.2

[Graphics:Images/ADI_gr_42.gif]

This suggests that the vector inputs to the TridiagonalSolve function can be created by manipulating the existing Xstar matrices.

For Astar, Bstar, and Cstar this is a matter of substituting ϕy for ϕx adding a rows, removing a columns, and then tranposing

[Graphics:Images/ADI_gr_43.gif]
[Graphics:Images/ADI_gr_44.gif]
[Graphics:Images/ADI_gr_45.gif]

Dstar, unfortunately isn't as easy to rearrange because the function's conditionals also change.  Rather than transform the Dstar matrix, we'll just rewrite the function exchanging x for y and correcting the order direction of the T values from the y direction to the x direction.  

[Graphics:Images/ADI_gr_46.gif]

Check the Input  4.2

We can now extract columns from the matrices to check that the solution we entered matches the solution achieved when solving by hand.

For the case middle of the region, (1<i<Nx) and (1<j<Ny), take values, say

[Graphics:Images/ADI_gr_47.gif]
[Graphics:Images/ADI_gr_48.gif]
[Graphics:Images/ADI_gr_49.gif]
[Graphics:Images/ADI_gr_50.gif]
[Graphics:Images/ADI_gr_51.gif]
[Graphics:Images/ADI_gr_52.gif]
[Graphics:Images/ADI_gr_53.gif]
[Graphics:Images/ADI_gr_54.gif]
[Graphics:Images/ADI_gr_55.gif]

Which, when substituted, should match the equation

[Graphics:Images/ADI_gr_56.gif]

In this manner,all of the systems of equations can be verified.

Assign Values to Constants  4.3

[Graphics:Images/ADI_gr_57.gif]

Loop Over Entire Region  4.4

[Graphics:Images/ADI_gr_58.gif]

Multiple Loops and Results  5

Although the particular nature of the engineering problem designates the values used for the constants and the exact method which the ADI is employed, below is a brief example of using a loop to solve for the evolution of the temperature distribution with time.  

[Graphics:Images/ADI_gr_59.gif]

[Graphics:Images/ADI_gr_60.gif]

[Graphics:Images/ADI_gr_61.gif]

[Graphics:Images/ADI_gr_62.gif]

[Graphics:Images/ADI_gr_63.gif]

[Graphics:Images/ADI_gr_64.gif]

[Graphics:Images/ADI_gr_65.gif]

[Graphics:Images/ADI_gr_66.gif]

[Graphics:Images/ADI_gr_67.gif]

[Graphics:Images/ADI_gr_68.gif]

[Graphics:Images/ADI_gr_69.gif]


Converted by Mathematica      August 4, 2000