Project 1
  Heated Plate Design Study

Summary

For this project, you are asked to undertake a design study examining the tradeoffs in implementing a simulation program. The program simulates the spreading of heat through a uniform two-dimensional metal plate. You will prepare five versions of the program, compare them and write a report describing what you learned.

Diffusion

Diffusion is a pervasive concept of scientific computation. Diffusion is the process by which a substance spreads as a result of its spontaneous movement from a region of higher to a region of lower concentration. The archtypical example of diffusion is the spreading of the molecules of one gaseous substance within another. Other examples include the spreading of heat through a uniform medium, the spreading of an organism through an ecology, the spread of disease through a population, and the spread of ideas.

Physicists model diffusion using Fick's Law: Fick's Law. Fick's Law state that the rate of change over time of the concentration C of some substance is proportional to a constant D (called the Diffusion Constant) times the second derivative of concentration with respect to distance x. In other words, concentration of a substance changes faster where the concentration gradiant is higher. In the case of Fick's Law, an analytic solution is known that takes the following form: Gaussian Curve, where S reflects the initial conditions, and t is time. That is, the concentration in space decreases exponentially in time, taking the form of what is called a Gaussian distribution.
Lattice Point



In most cases, computers are unable to solve differential equations. Instead, they approximate solutions using a discrete representation called a difference equation. In the case of a two-dimensional diffusion, the approximation takes the form of a rectangular lattice of points, where each interior point in the lattice is bounded orthogonally by four others.




This model leads to a particularly simple simulation of the heated plate. Just carve up the plate into a rectilinear grid. Then for each interior point in the grid, compute its temperature as the average of its four neighbors. Assuming that the edge values provide the initial conditions, then after a reasonable number of iterations, the interior values stabilize.

Pseudo Code

The following pseudo code illustrates one way the computation might be performed on a square grid of dimension d.
    // Create arrays oldPlate and newPlate with linear dimension d
// plus two extra
rows and columns to hold edge temperatures
oldPlate = new double[d + 2][d + 2];
newPlate = new double[d + 2][d + 2];

// Initialize the temperatures of the edge values and the plate itself
initialize(oldPlate, top, bot, left, right);
initialize(newPlate, top, bot, left, right);

// Loop until exit criteria are met, updating each newPlate cell from the
// average temperatures of the corresponding neighbors in oldPlate
while (! done()) {
for (int i = 1; i <= d; i++) {
for (int j = 1; j <= d; j++) {
// Compute lattice point temperature as average of neighbors
newPlate[i][j] = (oldPlate[i + 1][j] + oldPlate[i - 1][j] +
oldPlate[i][j + 1] + oldPlate[i][j - 1]) / 4.0;
}
}

// Swap the plates and continue
swap(oldPlate, newPlate);
}

Non-Functional Considerations

Software design problems are dominated by tradeoffs among non-functional constraints. For this problem, we will examine the following concerns:
Designing a satisficing solution requires trading these factors off against each other. For example, increased precision may degrade performance. It is the designer's job to determine the appropriate mix that will best satisfy the customer. Determining this mix may require the designer to build multiple prototypes and compare them. Doing this systematically is called conducting a design study.

Deliverables

This project has three deliverables: a series of programs, a description of the programs' designs and a design-study report. The programs each perform a heated-plate simulation using different design approaches; the description conveys the design and the choices it implements; and the report compares the approaches taken.

Programs

You should prepare five programs. The first four should produce textual output; the fifth should have a graphical user interface (GUI). Each program should be contained in its own package according to the names given in parentheses below. (The naming convention is the following: the first letter 't' or 'g' indicates whether a textual or graphical interface is provided. The second letter 'p' or 'w' indicates whether the data type used to hold temperature values is primitive or wrapped. The third letter 'd' or 'f' indicated whether double precision or single precision floating point computations are provided. The fourth letter 'a' of 'o' indicates whether array indexing or object references are used to access neighboring elements. The last two letters denote that a heating of plate is being simulated. For the fifth program, the letters 'all' are interpolated to indicate that the interface is capable of invoking multiple different simulations.)
  1. Implement the simple algorithm described above where all computations are performed in double precision using a two-dimensional array of doubles to represent the plate (tpdahp)
  2. Implement the same algorithm using floating point computations on an array of floats (tpfahp).
  3. Implement the same algorithm using floating point computations on an array of Floats (twfahp).
  4. Implement the algorithm with each lattice point representing an object that communicates with its four neighbors. That is, object references instead of array indices are used to access neighbors. Use doubles to hold temperature values (tpdohp).
  5. Implement a GUI version that enables the user to execute any of the four previous versions and see a visualization of the results (gallhp).
You are welcome but not required to implement and study the other four variants (twdahp, tpfohp, twdohp, twfohp).

It is tempting to implement the first four programs above as a single executable. Because you will need to measure lines of code and byte code size for each variant, you should avoid this temptation. However, when you  produce the fifth program, you must not only incorporate the first four programs, but you should make every effort to compactly combine them using good object-oriented design techniques such as inheritance.
 
Your programs should be written in Java, as applications not as applets. Compiling them should not require any compiler options to be set and should not require any non-standard libraries. Program build should require invoking javac without any arguments. Each of the programs should conform to the protocol description below.

Program invocation (for Java) consists of program name followed by arguments.

First Four Programs 

Invocation: Invocation of the programs should take the form
java <packageName>.Demo -d # -l # -r # -t # -b #
packageName is one of the four alternatives given above: tpdahp, tpfahp, twfahp, tpdohp. The -d flag indicates that the next argument is the dimension of the square lattice (number of rows and columns). It is a positive integer value greater than zero. The -l, -r, -t, and -b options respectively denote the edge temperatures for the left, right, top, and bottom edges. Their values are any integer between zero and one hundred, inclusive. The Demo class should contain only enough code (e.g. main method) to start up the program and process the command line arguments.  All other code for each program should be placed in separate classes

Output: The output of the program is printed onto the standard output as a table of temperature values, given to two decimal points of precision, for the lattice points. The table should be output one row per line; do not include the edge values in the output table.

Fifth Program

The fifth program you are asked to build adds a graphical user interface (GUI) to the heated plate simulation. It should be invoked with the command java gallhp.Demo. Whereas the specifications of the first four programs are tightly constrained, you are free to design and build whatever GUI you feel satisfies the following objectives:
That is, you should build a GUI that allows a user to specify a simulation and display the results. The display can be animated, or it can just show the final results.

Notes

You may assume that all plate temperatures are in the range [0.0, 100.0] inclusive. Your plate should be initialized with a temperature of 0.0 at all (non-edge) points. The algorithm takes some number of iterations for the temperatures in the plate to reach their final values. The finer the lattice, the more iterations it takes. Make sure that you allow your programs enough steps to get a meaningful final value.

There are two ways to control termination: lack of change and iteration count. Lack of change means that the temperatures of the grid cells have not changed significantly since the last iteration; that is, no progress has been made. You may also wish to have a fixed limit on the number of iterations as a safeguard against failure to stabilize due to bugs or round-off errors.

Design Description

Describe your design for program five. This should include the following items.
This Design Description should take no more than five pages, not counting the tables and diagrams.

Design Study

You should perform and report on a design study of your five programs. Design studies are described here. Using the approach described there, you should address the following items.
Limit the Design Study to eight pages, not counting any tables, graphs or diagrams..

Demonstration

In addition to the programs and the reports, you should prepare a fifteen minute presentation and demo. The demo should include actually running the fifth program. The presentation should present your design and the major conclusions from your design study

Mechanics

Grading

Notes