CS 2073, Fall 2005
 Program 9
 Numerical Solution of
 Laplace's Equation

 Due (on time): 2005-11-14  23:59:59
 Due (late):        2005-11-16  23:59:59

Program 9 must be emailed to: nrwagner@cs.utsa.edu
following directions for: running and submitting a C program, with deadlines:
  • 2005-11-14  23:59:59 (that's Monday, 14 November 2005, 11:59:59 pm) for full credit.
  • 2005-11-16  23:59:59 (that's Wednesday, 16 November 2005, 11:59:59 pm) for 75% credit.


Introduction: For this assignment, please first read the informal program description, taken from a 1978 Fortran textbook: A FORTRAN Coloring Book, by Roger E. Kaufman, MIT Press. This assignment starts with a region filled with liquid. There are fixed temperatures maintained on the boundaries. An iterative method determines the final steady-state temperature distribution. The portion studied is just a two-dimensional slice through the liquid-filled region. Please study this nine page write-up carefully because, along with the bad jokes, it describes the program very well.


Details:
  1. In this write-up, I assume that the 2-dimensional arrays are 61-by-61, that is, with indexes going from 0 to 60 inclusive.

  2. You should use a named constant for the size of the box:

  3. Here are possible declarations for the two 2-dimensional arrays that are needed:

  4. Here are possible prototypes for functions that you should use:

  5. When you run your program, use 0.25 degrees for the criterion for deciding when to terminate, as discussed by Kaufman. Print the number of steps needed to meet the criterion.

  6. Finally, your program should use letters from A to Z to indicate the temperature range in the final output, inserting the proper character in the array t, and the printing c. You should use as a temperature key the one below, which shows which letter is used for a given temperature range.

    Temperature key, temperature followed by letter
        32    Z
        36    Y
        40    Y
        44    X
        48    X
        52    W
        56    W
        60    V
        64    V
        68    U
        72    T
        76    T
    
        80    S
        84    S
        88    R
        92    R
        96    Q
       100    Q
       104    P
       108    O
       112    O
       116    N
       120    N
    
       124    M
       128    M
       132    L
       136    L
       140    K
       144    J
       148    J
       152    I
       156    I
       160    H
       164    H
       168    G
    
       172    G
       176    F
       180    E
       184    E
       188    D
       192    D
       196    C
       200    C
       204    B
       208    B
       212    A
    

  7. The constant M should be divisible by 3, such as 30 or 60. Here is a diagram of the grid for M == 30. Notice that in this diagram, the black labels on the top and left are in terms of a general value M, while the red labels on the bottom and right show what it would look like with M == 30.

    Above, the white boundary cells are not allowed to change value, while the cyan interior cells are the ones that change.

  8. Here is sample output: Sample output.


Hints and getting started: If you are asking yourself, "Geez, where do I begin?" you can follow some of these hints and suggestions.

  1. Start by assembling the suggested code above into sort of an "outline", using what are called stubs (empty functions) for the functions. I've done that for you, and here is one such result: stubs.c

    This "stubs" program actually compiles and runs, but it doesn't do anything. Most of the bodies of the functions are empty, but step ought to return something, so I just returned 0. (What would happen if you return 1 instead? Try it out and see.)

  2. Now you need to fill in code for the functions. Start with initialize. This is easy, even if a little annoying. Refer up to the cyan diagram above to keep things straight. Here's one way you could proceed:

  3. Next do the store function. This function looks at every cell of the t array, and based on its value, decides on a corresponding char to put into the c array. We want to use an 'A' for temperature 32.0, down to a 'Z' for temperature 212.0, with intermediate letters for intermediate temperatures. First declare a string:

    Notice that 'A' is the same as alf[0] and 'Z' is the same as alf[25]. So we just want a linear function f such that f(32) = 25 and f(212) = 0. But this is easy:

  4. Next write the display function, that just prints the c array, row-by-row, using a %c format for each char. At this point you can test your functions so far without using the step function at all. When you call initialize, store, and display, this is what the result should be (roughly, assuming M == 30): Output.
  5. Finally, we have the step function. This uses Kaufman's "magic" formula:

    It is all-important that you apply the formula only to the cells colored cyan above. The boundary cells must not be touched. This is very clever on Kaufman's part: since the formula reaches out to cells outside the given cell, we would have to worry about an array subscript out of range if we had not kept the boundary as a "buffer".

    Often in applications like this one, it's important to make use only of "old" values" (before the step), and then all at once change over to all the new values. In this case, though, it doesn't matter, and the end result will be the same either way.


What to turn in: You should do the following:

  1. Run the program for M == 30.
  2. Run the program again for M == 60.


What you should email: Refer to the submissions directions and to deadlines at the top of this page. The text file that you submit should first have Your Name, the Course Number, and the Program Number. The rest of the file should have the following in it, in the order below, and clearly labeled, including at the beginning the appropriate item letters: a, b, c, etc.

 Contents of email submission for Program 9:

Last Name, First Name; Course Number; Program Number.

  1. The source code for your program.
  2. Results of a run for M == 30, include the number of steps needed.
  3. Results of a run for M == 60, include the number of steps needed.


Revision date: 2005-11-02. (Please use ISO 8601, the International Standard.)