Homework 3

advertisement
ECE 103
HM
ENGINEERING PROGRAMMING
HW 3
HomeWork 3, Heat Transfer Function, 100 Points
Due Date:
Subject:
Total Points:
PSU
(6/5/2015)
Wednesday 7/22/2015
Write a C program computing temperature changes over a 2D area
100. Suitable commenting counts for a significant part of these points
General Rule: Implement your homework in C. Write well structured, readable, source programs.
Use helpful comments and apply them liberally, expressing ideas not immediately visible from the
source code. E.g. articulate solution ideas, list sources of algorithms, note caveats, explain goals.
Only individual work counts. Submit via email by the due date before the start of class, using
subject line: ECE 103 HW3 –with the 3 alluding to homework 3. Include in your email C source,
output, and if applicable input files; preferred for simple assignments is a single source file, and
single output file. For full credit, send only raw ASCII form, not processed files; i.e. do not send
Windows ZIP files, do not use Unix tar files, no shar utilities, or makefiles.
Credit: This programming sample was gratefully stolen, almost verbatim, from Prof. P. Wong in
the PSU ECE Dept.
Summary: The temperature distribution in a thin, square, metal plate with isothermal
temperatures on each side can be modeled using a two-dimensional grid, as shown in Figure 1.
We’ll use a simple 5 * 5 interior grid-point pattern.
Figure 1: Metal Plate with defined, constant temperatures on each of the 4 sides
Detail: A thin, square heat conductive plate is embedded on all 4 sides in a medium with fixed
temperatures. The sides are called Top, Bottom, Left, and Right. All interior points are of 0 oC
degree initially, but may change over time as heat flows. At the start of execution you enter the 4
temperatures of the 4 sides within reasonable physical limits (i.e. >= -273 and <= 1538 oC), yet
all points on any same side have the same, constant temperature. Time is simulated via an outer
loop, that progresses in discrete time steps. Each interior point changes its temperature as a
function of the average of its 4 adjacent neighbors up, down, left, and right; you don't need to
consider the diagonal points. When two successive iterations at grid point [1][1] show no more
than a predefined ΔT of temperatures the simulation stops. (Note that selecting grid points like
[1][1] for temperature change tests is arbitrary and imprecise, yet is allowed as a simplification.)
If the interior points are initially zero, and there exists at least one side whose temperature is not
zero, then the system is in a non-equilibrium state. Heat will flow from areas of higher to areas of
lower temperature until thermal equilibrium is achieved and the temperature of all plate points
becomes constant.
1
HW 3
ECE 103
HM
ENGINEERING PROGRAMMING
HW 3
PSU
Programming hint: two separate 2D arrays should be used. One array contains the current
iteration's grid temperatures, while the other array holds the next grid temperatures, which are
computed using the data from the current iteration. After the new state has been calculated, it
will become the current state for the next iteration.
Table 1: Required Test Cases, Temperatures in oC
Case
1
2
3
4
Top
100
75
50
Your data
Bottom
10
0
50
Your data
Left
100
10
50
Your data
Right
200
-25
50
Your data
Write a C program to model the temperature distribution for a plate with 5×5 interior grid points:
 Prompt the user to enter the temperature (in degrees Celsius) of each of the 4 sides; these
must be >= -273 oC, and <= 1,538 oC. Check for correctness.
 All grid points along any one side have the same, constant temperature.
 Each side can have a temperature that is different from any of the other sides, provided it is
within legal range, but they may also be the same.
 Use ΔT = 10-2 ºC as the limit to stop further iterations.
 At each iteration display the iteration number and the current temperature state in a nicely
formatted table.
 Show temperatures to two decimal places.
 The output should include both the side and interior temperatures of the plate.
Quality and Resulting Points: Only homework that works correctly receives a passing grade.
Proper commenting is crucial for a good solution. Describe in a brief paragraph each library you
included. Also, for each function of a library you used, provide a single paragraph synopsis. If you
did not include any library, explain, e.g. why <stdio.h> or the like is not needed. Test your
running as long as the required precision (delta of temperature differences) has not yet been
reached. (Note that the output below shows all 5 * 5 interior grid points, but also displays the
neighboring rows and columns 0 and 6 for the sake of completeness; yet points [0][0], [0][6] etc.
are never recomputed as a simplification.)
Table 2: Plausible input / Output
Enter temperatures (-273 oC .. 1538 oC) for all 4 sides of a plate below.
Enter Top temperature: 100
You entered 100.00 for Top side.
Enter Bottom temperature: 50
You entered 50.00 for Bottom side.
Enter Left temperature: 10
You entered 10.00 for Left side.
Enter Right temperature: 20
You entered 20.00 for Right side.
Iteration # 0
0
1
0:
0.00 100.00
1:
10.00
27.50
2:
10.00
2.50
3:
10.00
2.50
4:
10.00
2.50
5:
10.00
15.00
6:
0.00
50.00
2
100.00
25.00
0.00
0.00
0.00
12.50
50.00
3
100.00
25.00
0.00
0.00
0.00
12.50
50.00
2
4
100.00
25.00
0.00
0.00
0.00
12.50
50.00
5
100.00
30.00
5.00
5.00
5.00
17.50
50.00
6
0.00
20.00
20.00
20.00
20.00
20.00
0.00
HW 3
ECE 103
HM
ENGINEERING PROGRAMMING
HW 3
PSU
Iteration # 1
0
1
0:
0.00 100.00
1:
10.00
34.38
2:
10.00
10.00
3:
10.00
3.75
4:
10.00
6.88
5:
10.00
18.75
6:
0.00
50.00
2
100.00
38.12
6.88
0.62
3.75
19.38
50.00
3
100.00
37.50
6.25
0.00
3.12
18.75
50.00
4
100.00
38.75
7.50
1.25
4.38
20.00
50.00
5
100.00
37.50
13.75
7.50
10.62
21.88
50.00
6
0.00
20.00
20.00
20.00
20.00
20.00
0.00
Iteration # 2
0
1
0:
0.00 100.00
1:
10.00
39.53
2:
10.00
13.75
3:
10.00
6.88
4:
10.00
9.06
5:
10.00
21.56
6:
0.00
50.00
2
100.00
44.69
13.75
3.59
7.50
22.81
50.00
3
100.00
45.78
12.97
2.81
6.72
23.12
50.00
4
100.00
45.62
15.00
4.84
8.75
23.75
50.00
5
100.00
43.12
18.12
11.41
13.44
25.16
50.00
6
0.00
20.00
20.00
20.00
20.00
20.00
0.00
Iteration # 3
0
1
0:
0.00 100.00
1:
10.00
42.11
2:
10.00
17.54
3:
10.00
9.10
4:
10.00
11.48
5:
10.00
22.97
6:
0.00
50.00
2
100.00
49.77
18.75
7.73
10.55
25.55
50.00
3
100.00
50.82
19.34
7.03
10.55
25.82
50.00
4
100.00
50.98
20.39
9.49
12.19
26.76
50.00
5
100.00
45.94
22.38
14.10
16.33
26.80
50.00
6
0.00
20.00
20.00
20.00
20.00
20.00
0.00
Iteration # 4
0
1
0:
0.00 100.00
1:
10.00
44.33
2:
10.00
19.99
2
100.00
52.92
23.59
3
100.00
55.02
24.25
4
100.00
54.29
25.55
5
100.00
48.34
25.11
6
0.00
20.00
20.00
. . . . more
Table 3: Distribution of points
Number
1
2
3
4
5
6
Credit
Hand in only C source programs as text files, no
executable no binary, no .zip, no .shar, not
compressed, not massaged in any way; ideally with
.c or .cpp or .txt suffix
Suitable commenting; do not practice redundant
commenting; use only comments for ideas not
immediately visible from the source; include your
name, the term, date, school, etc.
Properly prompt for input of 4 side temperatures
Describe inside a C comment the design, how you
compute a new matrix of temperatures, but know
the old value, so the temperature delta can be
measured
Argue convincingly that you have practiced an effect
design methodology; perhaps top-down, rapid
programming, or other.
Use a readable programming style; includes proper
naming of objects, use of symbolic constants
3
Points
10
10
10
20
10
10
HW 3
ECE 103
HM
ENGINEERING PROGRAMMING
HW 3
7
(macros), use typedefs where applicable, group
logically connected areas of code together
Program runs correctly, input processed correctly,
output well formatted, until the correct temperature
delta is achieved
Total
PSU
30
100
What to turn in and how: Submit homework via email to the grader and cc herb, using subject
line: ECE 103 HW3. Keep a copy of original email, in case there is a need to re-submit later.
4
HW 3
Download