A 2D compact stencil using all 8 adjacent nodes, plus the center node (in red). source ↗
In mathematics , especially in the areas of numerical analysis called numerical partial differential equations , a compact stencil is a type of stencil that uses only nine nodes for its discretization method in two dimensions. It uses only the center node and the adjacent nodes. For any structured grid utilizing a compact stencil in 1, 2, or 3 dimensions the maximum number of nodes is 3, 9, or 27 respectively. Compact stencils may be compared to non-compact stencils . Compact stencils are currently implemented in many partial differential equation solvers, including several in the topics of CFD, FEA, and other mathematical solvers relating to PDE's1 2
Two Point Stencil Example
The two point stencil for the first derivative of a function is given by:
f
′
(
x
0
)
=
f
(
x
0
+
h
)
−
f
(
x
0
−
h
)
2
h
+
O
(
h
2
)
.
{\displaystyle f'(x_{0})={\frac {f{\left(x_{0}{+}h\right)}-f{\left(x_{0}{-}h\right)}}{2h}}+{\mathcal {O}}{\left(h^{2}\right)}.}
This is obtained from the Taylor series expansion of the first derivative of the function given by:
f
′
(
x
0
)
=
f
(
x
0
+
h
)
−
f
(
x
0
)
h
−
f
″
(
x
0
)
2
!
h
−
f
(
3
)
(
x
0
)
3
!
h
2
−
f
(
4
)
(
x
0
)
4
!
h
3
+
⋯
.
{\displaystyle f'(x_{0})={\frac {f{\left(x_{0}{+}h\right)}-f(x_{0})}{h}}-{\frac {f''(x_{0})}{2!}}h-{\frac {f^{(3)}(x_{0})}{3!}}h^{2}-{\frac {f^{(4)}(x_{0})}{4!}}h^{3}+\cdots .}
Replacing
h
{\displaystyle h}
with
−
h
{\displaystyle -h}
, we have:
f
′
(
x
0
)
=
−
f
(
x
0
−
h
)
−
f
(
x
0
)
h
+
f
″
(
x
0
)
2
!
h
−
f
(
3
)
(
x
0
)
3
!
h
2
+
f
(
4
)
(
x
0
)
4
!
h
3
+
⋯
.
{\displaystyle f'(x_{0})=-{\frac {f{\left(x_{0}{-}h\right)}-f(x_{0})}{h}}+{\frac {f''(x_{0})}{2!}}h-{\frac {f^{(3)}(x_{0})}{3!}}h^{2}+{\frac {f^{(4)}(x_{0})}{4!}}h^{3}+\cdots .}
Addition of the above two equations together results in the cancellation of the terms in odd powers of
h
{\displaystyle h}
:
2
f
′
(
x
0
)
=
f
(
x
0
+
h
)
−
f
(
x
0
)
h
−
f
(
x
0
−
h
)
−
f
(
x
0
)
h
−
2
f
(
3
)
(
x
0
)
3
!
h
2
+
⋯
f
′
(
x
0
)
=
f
(
x
0
+
h
)
−
f
(
x
0
−
h
)
2
h
−
f
(
3
)
(
x
0
)
3
!
h
2
+
⋯
=
f
(
x
0
+
h
)
−
f
(
x
0
−
h
)
2
h
+
O
(
h
2
)
.
{\displaystyle {\begin{aligned}2f'(x_{0})&={\frac {f{\left(x_{0}{+}h\right)}-f(x_{0})}{h}}-{\frac {f{\left(x_{0}{-}h\right)}-f(x_{0})}{h}}-2{\frac {f^{(3)}(x_{0})}{3!}}h^{2}+\cdots \\[1ex]f'(x_{0})&={\frac {f{\left(x_{0}{+}h\right)}-f{\left(x_{0}{-}h\right)}}{2h}}-{\frac {f^{(3)}(x_{0})}{3!}}h^{2}+\cdots \\&={\frac {f{\left(x_{0}{+}h\right)}-f{\left(x_{0}{-}h\right)}}{2h}}+{\mathcal {O}}{\left(h^{2}\right)}.\end{aligned}}}
Three Point Stencil Example
For example, the three point stencil for the second derivative of a function is given by:
f
″
(
x
0
)
=
f
(
x
0
+
h
)
+
f
(
x
0
−
h
)
−
2
f
(
x
0
)
h
2
+
O
(
h
2
)
.
{\displaystyle f''(x_{0})={\frac {f{\left(x_{0}{+}h\right)}+f{\left(x_{0}{-}h\right)}-2f(x_{0})}{h^{2}}}+{\mathcal {O}}{\left(h^{2}\right)}.}
This is obtained from the Taylor series expansion of the first derivative of the function given by:
f
′
(
x
0
)
=
f
(
x
0
+
h
)
−
f
(
x
0
)
h
−
f
″
(
x
0
)
2
!
h
−
f
(
3
)
(
x
0
)
3
!
h
2
−
f
(
4
)
(
x
0
)
4
!
h
3
+
⋯
.
{\displaystyle f'(x_{0})={\frac {f{\left(x_{0}{+}h\right)}-f(x_{0})}{h}}-{\frac {f''(x_{0})}{2!}}h-{\frac {f^{(3)}(x_{0})}{3!}}h^{2}-{\frac {f^{(4)}(x_{0})}{4!}}h^{3}+\cdots .}
Replacing
h
{\displaystyle h}
with
−
h
{\displaystyle -h}
, we have:
f
′
(
x
0
)
=
−
f
(
x
0
−
h
)
−
f
(
x
0
)
h
+
f
″
(
x
0
)
2
!
h
−
f
(
3
)
(
x
0
)
3
!
h
2
+
f
(
4
)
(
x
0
)
4
!
h
3
+
⋯
.
{\displaystyle f'(x_{0})=-{\frac {f{\left(x_{0}{-}h\right)}-f(x_{0})}{h}}+{\frac {f''(x_{0})}{2!}}h-{\frac {f^{(3)}(x_{0})}{3!}}h^{2}+{\frac {f^{(4)}(x_{0})}{4!}}h^{3}+\cdots .}
Subtraction of the above two equations results in the cancellation of the terms in even powers of
h
{\displaystyle h}
:
0
=
f
(
x
0
+
h
)
−
f
(
x
0
)
h
+
f
(
x
0
−
h
)
−
f
(
x
0
)
h
−
2
f
(
2
)
(
x
0
)
2
!
h
−
2
f
(
4
)
(
x
0
)
4
!
h
3
+
⋯
.
f
(
2
)
(
x
0
)
=
f
(
x
0
+
h
)
+
f
(
x
0
−
h
)
−
2
f
(
x
0
)
h
2
−
2
f
(
4
)
(
x
0
)
4
!
h
2
+
⋯
.
f
(
2
)
(
x
0
)
=
f
(
x
0
+
h
)
+
f
(
x
0
−
h
)
−
2
f
(
x
0
)
h
2
+
O
(
h
2
)
.
{\displaystyle {\begin{aligned}0&={\frac {f{\left(x_{0}{+}h\right)}-f(x_{0})}{h}}+{\frac {f{\left(x_{0}{-}h\right)}-f(x_{0})}{h}}-2{\frac {f^{(2)}(x_{0})}{2!}}h-2{\frac {f^{(4)}(x_{0})}{4!}}h^{3}+\cdots .\\[1ex]f^{(2)}(x_{0})&={\frac {f{\left(x_{0}{+}h\right)}+f{\left(x_{0}{-}h\right)}-2f(x_{0})}{h^{2}}}-2{\frac {f^{(4)}(x_{0})}{4!}}h^{2}+\cdots .\\[1ex]f^{(2)}(x_{0})&={\frac {f{\left(x_{0}{+}h\right)}+f{\left(x_{0}{-}h\right)}-2f(x_{0})}{h^{2}}}+{\mathcal {O}}{\left(h^{2}\right)}.\end{aligned}}}
See also
See also
References
References