The divergence theorem (Gauss's theorem) from vector calculus says
I am interested in the case where the vector field is derived from a scalar potential F = ∇u:
This theorem is for a continuous system in ℝ3. However, numerical algorithms often operate on discrete grids in ℤd where d = 2 or 3. I will now derive a discrete version of this theorem.
Let u be a scalar field on the grid u: ℤd → ℝ, x ↦ ux.
Let x, y ∈ ℤd. We'll use the Manhattan metric |x - y| = Σi |xi - yi|. Cells x and y are called adjacent if and only if |x - y| = 1. Note that diagonal cells are not adjacent.
Let V be a subset of ℤd. V' is the complement of V in ℤd.
Let nx be the number of cells adjacent to x in V. Therefore, nx = Σy∈V, |x-y|=1 1.
Let the second-order finite difference Laplacian be given by Lx = - 2d ux + Σy, |x-y|=1 uy.
Note that right-hand side involves only points on the boundary of V. These correspond to first-order finite difference derivatives. There is one term for each arrow in this diagram:
Starting from the left-hand side, expand the Laplacian to get a sum of field terms:
Σx∈V Lx = Σx cx ux,
where cx are constant coefficients. From the definition of the Laplacian, we can see that cx = nx - 2d if x∈V, or cx = nx if x∈V':
= Σx∈V ux (nx - 2d) + Σx∈V' ux nx. (1)
Since each cell is adjacent to 2d others,
2d = Σy, |x-y|=1 1
= Σy∈V, |x-y|=1 1 + Σy∈V', |x-y|=1 1
= nx + Σy∈V', |x-y|=1 1
2d - nx = Σy∈V', |x-y|=1 1.
Now put this into (1):
Σx∈V Lx
= - Σx∈V, y∈V', |x-y|=1 ux + Σx∈V', y∈V, |x-y|=1 ux
= Σx∈V, y∈V', |x-y|=1 (uy - ux). ■