Gain experience with 2-dimensional arrays and loops while solving a real-world problem (“steady state analysis”).
In this assignment you will compute the steady state temperature distribution over a piece of metal. This steady state analysis solves a system of partial differential equations numerically and is used in solving many physics problems. Similar matrix algorithms are also used in analyzing airplane wing and automobile pressure distributions through fluid flow dynamics simulations.
The problem is to determine the temperature distribution for a two-dimensional plate with constant boundary conditions. Use a 20 X 20 two dimensional array of numbers to represent the temperature at different places on the plate. The elements on the boundaries have fixed temperatures. The elements on the top and bottom row have a fixed temperature of 100 degrees. The elements on the leftmost and rightmost columns have a temperature of zero degrees. (The corner elements have a temperature of zero degrees.)
The job of the algorithm is to find the steady-state temperature distribution of the interior elements which are constantly changing to be an average of the temperature of their neighbors. Steady state means that the temperature of any cell is virtually unchanging and approximately equal to the average of the temperatures of its four neighbors on the north, south, east, and west directions. Note that the steady state temperatures will be the same regardless of what the beginning temperatures are for the interior elements.
To calculate the new temperature value of an array element, take the average of the values in the 4 direct neighbors of that cell.
For example, the cell at position array[1][2] currently has a value of 60.6 degrees. At the next iteration, it will be set to the average of its 4 neighbors (100.0 + 66.3 + 34.0 + 45.2)/4.
You should continue to iterate until no cell in the array changes more than 0.1 degree, calculating the temperature for all interior cells on each iteration. Your program should monitor the largest change for any cell in the array in order to determine when to stop iterating (See Common Loop Algorithms in section 4.7 of the book for ideas).
When you are finished, you should write your two dimensional array out to a comma separated values file like this:
0.0,100.0,100.0,100.0, 0.0,45.1,60.6,66.2,0, 0.0,45.1,60.6,66.2,0, 0.0,100.0,100.0,100.0,0,
You can import this csv file into a spreadsheet like excel and format it as a 3d graph in order to check your work.
You should think about how you could break the program up into methods to make each task smaller and easier to accomplish.
Work through some small examples by hand and think about the array index you will have to use to get to adjacent array elements.
Think about how you will check to see if your code is performing correctly. Decide on what the overall answer should be and then write tests that will make sure that your methods are performing appropriately.
You can find out more about how to write to a file in example FileIO
Start by writing a method to print out your array, then write the code to initialize the boundaries, then write the iteration code and progressively solve small pieces of your problem.
To graph your data, import the csv file into excel as a csv file, then select the data and create a 3d chart. Follow this tutorial if you're unfamiliar with Excel: Export To Excel
Some students find that xcode doesn't create a file when they use ofstream. To fix this, do the following
When you have your program working, you will need to show it to a TA. The TA will evaluate your code based on the following criteria: