Example: Heatflow in one dimension
This is an example of
efficient prototyping of recurrences
applied to a simple partial differential equation.
The 1-dimensional heat flow equation describes the heat distribution u(x,t) in
a one-dimensional object along the x-axis at time t. Alpha is a physical constant describing the heat transfusion properties of the object.
To turn this into a recurrence relation we may use the finite difference
The c is a numerical constant, relating the size of the time steps to the size of the
object grid. If the quotient is larger than c we loose numerical stability of the
method. Abstracting the stencil, we may express the recurrence
as a recursive program with the explicit stencil
The kernel of the program actually compiled follows, where we take into account
the boundary conditions (a constant temperature given at the start of the
The actual computation is defined on an integer grid
if(right_boundary(n) or left_boundary(n)
x int * t int
rather than in real coordinates. The opposite of the stencil becomes
where nx is the number of nodes in the discretisation of the object (with
length X) in the x-direction, nt is the number of nodes in the
discretisation of the simulated time (with length T). The number of time
nodes nt is related to the number of space node nx by the given formula.
The following is a sequence of snapshots of the actual computation generated
by the compiler.
The temperature has been encoded using colours. Initially the rod is hot (yellow),
with a constant cold temperature (blue) being applied at the ends. During time
the rod cools off from the edges (hues of green).
After sending initial values:
You can watch an animated demo of this if your
browser supports Java.
In the parallel case all nodes at the same timestep would be computed
simultaneously. An animated demo
of this has also been prepared as a Java applet.
Below the temperature of the object has been plotted against time in
a wireframe image. You may view this as a
rotatable image written in Java.
This was an example of efficient prototyping of recurrences.
© 1997 Magne Haveraaen, University of Bergen, Norway.