3D graphics eBook - Course Materials Repository
3D graphics eBook - Course Materials Repository
3D graphics eBook - Course Materials Repository
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Stencil codes 196<br />
Stencil codes<br />
Stencil codes are a class of iterative kernels [1] which update array<br />
elements according to some fixed pattern, called stencil [2] . They are<br />
most commonly found in the codes of computer simulations, e.g. for<br />
computational fluid dynamics in the context of scientific and<br />
engineering applications. Other notable examples include solving<br />
partial differential equations [1] , the Jacobi kernel, the Gauss–Seidel<br />
method [2] , image processing [1] and cellular automata. [3] The regular<br />
structure of the arrays sets stencil codes apart from other modeling<br />
methods such as the Finite element method. Most finite difference<br />
codes which operate on regular grids can be formulated as stencil<br />
codes.<br />
Definition<br />
Stencil codes perform a sequence of sweeps (called timesteps) through<br />
a given array. [2] Generally this is a 2- or 3-dimensional regular grid. [3]<br />
The shape of a 6-point <strong>3D</strong> von Neumann style<br />
The elements of the arrays are often referred to as cells. In each timestep, the stencil code updates all array<br />
elements. [2] Using neighboring array elements in a fixed pattern (called the stencil), each cell's new value is<br />
computed. In most cases boundary values are left unchanged, but in some cases (e.g. LBM codes) those need to be<br />
adjusted during the course of the computation as well. Since the stencil is the same for each element, the pattern of<br />
data accesses is repeated. [4]<br />
stencil.<br />
More formally, we may define stencil codes as a 5-tuple with the following meaning: [3]<br />
• is the index set. It defines the topology of the array.<br />
• is the (not necessarily finite) set of states, one of which each cell may take on on any given timestep.<br />
• defines the initial state of the system at time 0.<br />
• is the stencil itself and describes the actual shape of the neighborhood. (There are elements in the<br />
stencil.<br />
• is the transition function which is used to determine a cell's new state, depending on its neighbors.<br />
Since I is a k-dimentional integer interval, the array will always have the topology of a finite regular grid. The array<br />
is also called simulation space and individual cells are identified by their index . The stencil is an ordered set<br />
of relative coordinates. We can now obtain for each cell the tuple of its neighbors indices<br />
Their states are given by mapping the tuple to the corresponding tuple of states :<br />
This is all we need to define the system's state for the following time steps with :<br />
Note that is defined on and not just on since the boundary conditions need to be set, too. Sometimes the<br />
elements of may be defined by a vector addition modulo the simulation space's dimension to realize toroidal