Stencil (numerical analysis)

In mathematics, especially the areas of numerical analysis concentrating on the numerical solution of partial differential equations, a stencil is a geometric arrangement of a nodal group that relate to the point of interest by using a numerical approximation routine. Stencils are the basis for many algorithms to numerically solve partial differential equations (PDE). Two examples of stencils are the five-point stencil and the Crank–Nicolson method stencil.

Stencils are classified into two categories: compact and non-compact, the difference being the layers from the point of interest that are also used for calculation.

In the notation used for one-dimensional stencils n-1, n, n+1 indicate the time steps where timestep n and n-1 have known solutions and time step n+1 is to be calculated. The spatial location of finite volumes used in the calculation are indicated by j-1, j and j+1.

Etymology
Graphical representations of node arrangements and their coefficients arose early in the study of PDEs. Authors continue to use varying terms for these such as "relaxation patterns", "operating instructions", "lozenges", or "point patterns". The term "stencil" was coined for such patterns to reflect the concept of laying out a stencil in the usual sense over a computational grid to reveal just the numbers needed at a particular step.

Calculation of coefficients
The finite difference coefficients for a given stencil are fixed by the choice of node points. The coefficients may be calculated by taking the derivative of the Lagrange polynomial interpolating between the node points, by computing the Taylor expansion around each node point and solving a linear system, or by enforcing that the stencil is exact for monomials up to the degree of the stencil. For equi-spaced nodes, they may be calculated efficiently as the Padé approximant of $$x^s \cdot (\log x)^m$$, where $$m$$ is the order of the stencil and $$s$$ is the ratio of the distance between the leftmost derivative and the left function entries divided by the grid spacing.