CSCI 297 Assignment I

Temperatures on a Plate

In this assignment, we are looking at changing temperatures on a rectangular metal plate.

We will model the rectangular plate as a 2-dimensional array of REAL values. Some parts of the plate are maintained externally at constant temperatures (by a heat source or a refrigerated source). We will start with initial values and run through a sequence of generations. In each generation, the non-constant values are calculated as the average of the location's neighbors' temperatures. We stop when two successive generations give us the same array of values (within some margin).

To simplify matters we will always use a plate of the same size and shape, and we will stick to temperatures between 0.0 and 400.0.


Where do we start?

We will use a derived data type:

TYPE :: CELL
  REAL :: Temp
  LOGICAL :: Constant
  INTEGER :: NbrCount
  INTEGER, DIMENSION(4) :: Nbrs
END TYPE CELL

If X is a CELL, we can refer to X%Temp, X%Constant, etc.

We will need a 2-dimensional array of CELL. Let's have 30 rows and 12 columns. (When we print this, we will have 12 numbers across a line.) We actually need two such arrays. For now, I will refer to these as Current and Next.

Define the arrays so the subscripts star at 0, not 1, as in:

CELL, DIMENSION(0:11,0:29)

We will sometimes refer to a CELL by a single INTEGER = 12 * row + column. (This arithmetic is simplified by starting at 0.)

Here the components of CELL are:

Read the input file (by input redirection). Use the data to initialize all the Temp and Constant values in the Current array.

Use a subroutine to initialize all the NbrCount and Nbrs values in the Current array.


Input file

We will use two input files. The format of each is the following:

initial temperature   (for most of the plate; this might be 30.0, for instance)
cell number   temperature  (these are all fixed)
cell number   temperature 
...

The input files are called "dataIA.txt" and "dataIB.txt". You can find them on the web site.


What happens in a generation?

The idea is to compute Next from Current. Using loops, we check for each row R and column C whether Current(R, C)%Constant is .TRUE. If so, then Next(R, C) = Current(R, C). If not, we compute Next(R, C)%Temp as the average of the Current Temp values for the neighbors of Current(R, C).

We now need to find out how far apart Current and Next are. Compute HOWFAR = DIFF(Current, Next), using the function DIFF mentioned below.

Now set Current = Next and call a subroutne to print Current.

Our loop ends when HOWFAR is less than some cutoff value such as 0.1. Use a named constant for the value 0.1.

By the way, we are counting generations and when we print out Current, we will also print out the number of generations so far.


Notes

You will need a function ROW to compute from an INTEGER designating a location the row for that location, and you need another function COLUMN to compute the column.

You will need a function DIFF to compute the maximum of ABS(Current(R, C) - Next(R,C)) for all rows R and columns C.

You will need a subroutine to print the contents of Current. Include the number of the generation in a heading and print 12 numbers across a line with 2 or maybe 3 spaces between them. (We don't want the line to wrap around.)

If we end up with a large number of generations, it might be better to print out Current every 5 generations instead of every time.

You may want to use more subroutines or functions as well.

You need to compile and link your program as usual.