forked from johannesgerer/jburkardt-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
heated_plate.html
365 lines (315 loc) · 10.3 KB
/
heated_plate.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
<html>
<head>
<title>
HEATED_PLATE - 2D Steady State Heat Equation in a Rectangle
</title>
</head>
<body bgcolor="#EEEEEE" link="#CC0000" alink="#FF3300" vlink="#000055">
<h1 align = "center">
HEATED_PLATE <br> 2D Steady State Heat Equation in a Rectangle
</h1>
<hr>
<p>
<b>HEATED_PLATE</b>
is a C++ program which
solves the steady state heat equation in a 2D
rectangular region, and is intended as
a starting point for implementing an OpenMP parallel version.
</p>
<p>
The final estimate of the solution is written to a file in a format
suitable for display by <b>GRID_TO_BMP</b>.
</p>
<p>
The sequential version of this program needs approximately
18/epsilon iterations to complete.
</p>
<p>
The physical region, and the boundary conditions, are suggested
by this diagram:
<pre>
W = 0
+------------------+
| |
W = 100 | | W = 100
| |
+------------------+
W = 100
</pre>
</p>
<p>
The region is covered with a grid of M by N nodes, and an N by N
array W is used to record the temperature. The correspondence between
array indices and locations in the region is suggested by giving the
indices of the four corners:
<pre>
I = 0
[0][0]-------------[0][N-1]
| |
J = 0 | | J = N-1
| |
[M-1][0]-----------[M-1][N-1]
I = M-1
</pre>
</p>
<p>
The steady state solution to the discrete heat equation satisfies the
following condition at an interior grid point:
<blockquote>
W[Central] = (1/4) * ( W[North] + W[South] + W[East] + W[West] )
</blockquote>
where "Central" is the index of the grid point, "North" is the index
of its immediate neighbor to the "north", and so on.
</p>
<p>
Given an approximate solution of the steady state heat equation, a
"better" solution is given by replacing each interior point by the
average of its 4 neighbors - in other words, by using the condition
as an ASSIGNMENT statement:
<blockquote>
W[Central] <= (1/4) * ( W[North] + W[South] + W[East] + W[West] )
</blockquote>
</p>
<p>
If this process is repeated often enough, the difference between successive
estimates of the solution will go to zero.
</p>
<p>
This program carries out such an iteration, using a tolerance specified by
the user, and writes the final estimate of the solution to a file that can
be used for graphic processing.
</p>
<h3 align = "center">
Usage:
</h3>
<p>
<blockquote>
<b>heated_plate</b> <i>epsilon</i> <i>output_file</i>
</blockquote>
where
<ul>
<li>
<i>epsilon</i> is the error tolerance used to halt the iteration. This
is an absolute error tolerance, and is applied pointwise. A value of
0.1 might be reasonable for the built in problem.
</li>
<li>
<i>output_filename</i> is the name of the file into which the final
estimate of the solution will be written, for possible display by
<b>GRID_TO_BMP</b>.
</li>
</ul>
</p>
<h3 align = "center">
Licensing:
</h3>
<p>
The computer code and data files described and made available on this web page
are distributed under
<a href = "../../txt/gnu_lgpl.txt">the GNU LGPL license.</a>
</p>
<h3 align = "center">
Languages:
</h3>
<p>
<b>HEATED_PLATE</b> is available in
<a href = "../../c_src/heated_plate/heated_plate.html">a C version</a> and
<a href = "../../cpp_src/heated_plate/heated_plate.html">a C++ version</a> and
<a href = "../../f77_src/heated_plate/heated_plate.html">a FORTRAN77 version</a> and
<a href = "../../f_src/heated_plate/heated_plate.html">a FORTRAN90 version</a> and
<a href = "../../m_src/heated_plate/heated_plate.html">a MATLAB version</a>.
</p>
<h3 align = "center">
Related Data and Programs:
</h3>
<p>
<a href = "../../cpp_src/fd2d_heat_steady/fd2d_heat_steady.html">
FD2D_HEAT_STEADY</a>,
a C++ program which
uses the finite difference method (FDM) to solve the
steady (time independent) heat equation in 2D.
</p>
<p>
<a href = "../../m_src/fd1d_plot/fd1d_plot.html">
FD1D_PLOT</a>,
a MATLAB program which
plots the output from the FD1D program;
</p>
<p>
<a href = "../../m_src/fem_50_heat/fem_50_heat.html">
FEM_50_HEAT</a>,
a MATLAB program which
implements a finite element calculation specifically for the heat equation.
</p>
<p>
<a href = "../../m_src/fem1d_heat/fem1d_heat.html">
FEM1D_HEAT</a>,
a MATLAB program which
uses the finite element method to solve the 1D Time Dependent
Heat Equations.
</p>
<p>
<a href = "../../cpp_src/fem2d_heat/fem2d_heat.html">
FEM2D_HEAT</a>,
a C++ program which
solves the 2D time dependent heat equation on the unit square.
</p>
<p>
<a href = "../../cpp_src/grid_to_bmp/grid_to_bmp.html">
GRID_TO_BMP</a>,
a C++ program which
reads a text file of data on a rectangular grid
and creates a BMP file containing a color image of the data.
</p>
<p>
<a href = "../../cpp_src/heat_mpi/heat_mpi.html">
HEAT_MPI</a>,
a C++ program which
solves the 1D Time Dependent Heat Equation using MPI.
</p>
<p>
<a href = "../../cpp_src/heated_plate_openmp/heated_plate_openmp.html">
HEATED_PLATE_OPENMP</a>,
a C++ program which
solves the steady (time independent) heat equation in a 2D
rectangular region, using OpenMP to run in parallel.
</p>
<p>
<a href = "../../cpp_src/md/md.html">
MD</a>,
a C++ program which
carries out a molecular dynamics simulation, and is intended as
a starting point for implementing an OpenMP parallel version.
</p>
<p>
<a href = "../../cpp_src/mxm_serial/mxm_serial.html">
MXM_SERIAL</a>,
a C++ program which
sets up a matrix multiplication problem A=B*C,
intended as a starting point for implementing a parallel version.
</p>
<p>
<a href = "../../cpp_src/poisson_serial/poisson_serial.html">
POISSON_SERIAL</a>,
a C++ program which
computes an approximate solution to the Poisson equation in a rectangle,
and is intended as the starting point for the creation of a parallel version.
</p>
<p>
<a href = "../../cpp_src/prime_serial/prime_serial.html">
PRIME_SERIAL</a>,
a C++ program which
counts the number of primes between 1 and N,
intended as a starting point for the creation of a parallel version.
</p>
<p>
<a href = "../../cpp_src/quad_serial/quad_serial.html">
QUAD_SERIAL</a>,
a C++ program which
approximates an integral using a quadrature rule,
and is intended as a starting point for parallelization exercises.
</p>
<p>
<a href = "../../cpp_src/search_serial/search_serial.html">
SEARCH_SERIAL</a>,
a C++ program which
searches the integers from A to B for a value J such that F(J) = C.
this version of the program is intended as a starting point for
a parallel approach.
</p>
<p>
<a href = "../../cpp_src/stochastic_heat2d/stochastic_heat2d.html">
STOCHASTIC_HEAT2D</a>,
a C++ program which
implements a finite difference method (FDM) for the steady
(time independent) 2D heat equation,
with a stochastic heat diffusivity coefficient,
using gnuplot to illustrate the results.
</p>
<h3 align = "center">
Reference:
</h3>
<p>
<ol>
<li>
Michael Quinn,<br>
Parallel Programming in C with MPI and OpenMP,<br>
McGraw-Hill, 2004,<br>
ISBN13: 978-0071232654,<br>
LC: QA76.73.C15.Q55.
</li>
</ol>
</p>
<h3 align = "center">
Source Code:
</h3>
<p>
<ul>
<li>
<a href = "heated_plate.cpp">heated_plate.cpp</a>, the source code.
</li>
<li>
<a href = "heated_plate.sh">heated_plate.sh</a>,
commands to compile the source code.
</li>
</ul>
</p>
<h3 align = "center">
Examples and Tests:
</h3>
<p>
The program has a built in grid of M = 500, N = 500. It is only necessary to
alter these definitions and recompile in order to run the problem on a different
grid. Here are the output files and solution files from two runs.
<ul>
<li>
<a href = "output_100x500.txt">output_100x500.txt</a>
the output from a run on a 100x500 grid.
</li>
<li>
<a href = "sol_100x500.txt">sol_100x500.txt</a>
the solution on a 100x500 grid.
</li>
<li>
<a href = "../../cpp_src/grid_to_bmp/sol_100x500.png">sol_100x500.png</a>
a PNG image of the solution on a 100x500 grid.
</li>
<li>
<a href = "output_500x500.txt">output_500x500.txt</a>
the output from a run on a 500x500 grid.
</li>
<li>
<a href = "sol_500x500.txt">sol_500x500.txt</a>
the solution on a 500x500 grid.
</li>
<li>
<a href = "../../cpp_src/grid_to_bmp/sol_500x500.png">sol_500x500.png</a>
a PNG image of the solution on a 500x500 grid.
</li>
</ul>
</p>
<h3 align = "center">
List of Routines:
</h3>
<p>
<ul>
<li>
<b>MAIN</b> is the main program for HEATED_PLATE.
</li>
<li>
<b>CPU_TIME</b> returns the current reading on the CPU clock.
</li>
</ul>
</p>
<p>
You can go up one level to <a href = "../cpp_src.html">
the C++ source codes</a>.
</p>
<hr>
<i>
Last revised on 22 July 2008.
</i>
<!-- John Burkardt -->
</body>
<!-- Initial HTML skeleton created by HTMLINDEX. -->
</html>