Sei sulla pagina 1di 7

FINITE DIFFERENCE METHODS

LONG CHEN

The best known methods, finite difference, consists of replacing each derivative by a difference quotient in the classic formulation. It is simple to code and economic to compute.
In a sense, a finite difference formulation offers a more direct approach to the numerical
solution of partial differential equations than does a method based on other formulations.
The drawback of the finite difference methods is accuracy and flexibility. Standard finite
difference methods requires more regularity of the solution (e.g. u C 2 ()) and the triangulation (e.g. uniform grids). Difficulties also arises in imposing boundary conditions.
1. F INITE DIFFERENCE FORMULA
In this section, for simplicity, we discuss Poisson equation posed on the unit square
= (0, 1) (0, 1). Variable coefficients and more complex domains will be discussed
in finite element methods. Furthermore we assume u is smooth enough to enable us use
Taylor expansion freely.
Given two integer m, n 2, we construct a rectangular grids Th by the tensor product
of two grids of (0, 1): {xi = (i 1)hx , i = 1, m, hx = 1/(m 1)} and {yj =
(j 1)hy , j = 1, n, hy = 1/(n 1)}. Let h = max{hx , hy } denote the size of Th .
We denote h = {(xi , yj ) } and boundary h = {(xi , yj ) }.
We consider the discrete function space given by Vh = {uh (xi , yj ), 1 i m, 1
j n} which is isomorphism to RN with N = m n. It is more convenient to use
sub-index (i, j) for the discrete function: ui,j := uh (xi , yj ). For a continuous function
u C(), the interpolation operator Ih : C() Vh maps u to a discrete function and
will be denoted by uI . By the definition (uI )i,j = u(xi , yj ). Note that the value of a
discrete function is only defined at grid points. Values inside each cell can be obtained by
interpolation of values at grid points.
Similar definitions can be applied to one dimensional case. Choose a mesh size h and
u Vh (0, 1). Popular difference formulas at an interior node xj for a discrete function
u Vh include:
uj uj1
The backward difference: (D u)j =
;
h
uj+1 uj
The forward difference: (D+ u)j =
;
h
uj+1 uj1
The centered difference: (D u)j =
;
2h
uj+1 2uj + uj1
The centered second difference: (D2 u)j =
.
h2
It is easy to prove by Talyor expansion that
(D u)j u0 (xj ) = O(h),

(D+ u)j u0 (xj ) = O(h),

(D u)j u0 (xj ) = O(h2 ),

(D2 u)j u00 (xj ) = O(h2 ).

Date: Updated October 12, 2013.


1

LONG CHEN

We shall use these difference formulation, especially the centered second difference to
approximate the Laplace operator at an interior node (xi , yj ):
2
2
(h u)i,j = (Dxx
u)i,j + (Dyy
u)i,j
ui+1,j 2ui,j + ui1,i
ui,j+1 2ui,j + ui,j1
=
+
.
2
hx
h2y

It is called five point stencil since only five points are involved. When hx = hy , it is
simplified to
4ui,j ui+1,j ui1,i ui,j+1 ui,j1
h2
and can be denoted by the following stencil symbol

1
1 4 1 .
1
(1)

(h u)i,j =

For the right hand side, we simply take node values i.e. fi,j = (fI )i,j = f (xi , yj ).
The finite difference methods for solving Poisson equation is simply
(2)

(h u)i,j = fi,j ,

1 i m, 1 j n,

with appropriate processing of boundary conditions. Here in (2), we also use (1) for boundary points but drop terms involving grid points outside of the domain.
Let us give an ordering of N = m n grids and use a single index k = 1 to N for
uk = ui(k),j(k) . For example, the index map k (i(k), j(k)) can be easily written out
for the lexicographical ordering. With any choosing ordering, (2) can be written as a linear
algebraic equation:
(3)

Au = f ,

where A RN N , u RN and f RN .
Remark 1.1. There exist different orderings for the grid points. Although they give equivalent matrixes up to permutations, different ordering does matter when solving linear algebraic equations.
2. B OUNDARY CONDITIONS
We shall discuss how to deal with boundary conditions in finite difference methods.
The Dirichlet boundary condition is relatively easy and the Neumann boundary condition
requires the ghost points.
Dirichlet boundary condition. For the Poisson equation with Dirichlet boundary condition
(4)

u = f in ,

u = g on = ,

the value on the boundary is given by the boundary conditions. Namely ui,j = g(xi , yj )
for (xi , yj ) and thus not unknowns in the equation. There are several ways to impose
the Dirichlet boundary condition.
One approach is to let aii = 1, aij = 0, j 6= i and fi = g(xi ) for nodes xi . Note
that this will destroy the symmetry of the corresponding matrix. Another approach is to
modify the right hand side at interior nodes and solve only equations at interior nodes. Let

FINITE DIFFERENCE METHODS

us consider a simple example with 9 nodes. The only unknowns is u5 with the lexicographical ordering. By the formula of discrete Laplace operator at that node, we obtain the
adjusted equation
1
4
u5 = f5 + 2 (u2 + u4 + u6 + u8 ).
2
h
h
We use the following Matlab code to illustrate the implementation of Dirichlet boundary
condition. Let bdNode be a logic array representing boundary nodes: bdNode(k)=1 if
(xk , yk ) and bdNode(k)=0 otherwise.
1
2
3
4
5

freeNode = bdNode;
u = zeros(N,1);
u(bdNode) = g(node(bdNode,:));
f = f-A*u;
u(freeNode) = A(freeNode,freeNode)\f(freeNode);

The matrix A(freeNode,freeNode) is symmetric and positive definite (SPD) (see


Exercise 1) and thus ensure the existence of the solution.
Neumann boundary condition. For the Poisson equation with Neumann boundary condition
u
u = f in ,
= g on ,
n
there is a compatible condition for f and g:
Z
Z
Z
Z
u
dS =
g dS.
(5)
f dx =
u dx =

n
A natural approximation to the normal derivative is a one sided difference, for example:
u
u1,j u2,j
(x1 , yj ) =
+ O(h).
n
h
But this is only a first order approximation. To treat Neumann boundary condition more
accurately, we introduce the ghost points outside of the domain and next to the boundary.
We extend the lattice by allowing the index 0 i, j n + 1. Then we can use center
difference scheme:
u
u0,j u2,j
(x1 , yj ) =
+ O(h2 ).
n
2h
The value u0,j is not well defined. We need to eliminate it from the equation. This is
possible since on the boundary point (x1 , yj ), we have two equations:
(6)
(7)

4u1,j u2,j u0,j u1,j+1 u1,j1 = h2 f1,j

u0,j u2,j = 2h g1,j .

From (7), we get u0,j = 2h g1,j + u2,j . Substituting it into (6) and scaling by a factor 1/2,
we get an equation at point (x1 , yj ):
2u1,j u2,j 0.5 u1,j+1 0.5 uj1 = 0.5 h2 f1,j + h g1,j .
The scaling is to preserve the symmetry of the matrix. We can deal with other boundary
points by the same technique except the four corner points. At corner points, even the

LONG CHEN

norm vector is not well defined. We will use average of two directional derivatives to get
an approximation. Taking (0, 0) as an example, we have
(8)
(9)

4u1,1 u2,1 u0,1 u1,1 u1,0 = h2 f1,1 ,


u0,1 u2,1 = 2h g1,1 ,

(10)

u1,0 u1,2 = 2h g1,1 .

So we can solve u0,1 and u1,0 from (9) and (10), and substitute them into (8). Again to
maintain the symmetric of the matrix, we multiply (8) by 1/4. This gives an equation for
the corner point (x1 , y1 )
u1,1 0.5 u2,1 0.5 u1,1 = 0.25 h2 f1,1 + h g1,1 .

Similar technique will be used to deal with other corner points. We then end with a linear
algebraic equation
Au = f .
It can be shown that the corresponding matrix A is still symmetric but only semi-definite
(see Exercise 2). The kernel of A consists of constant vectors i.e. Au = 0 if and only if
u = c. This requires a discrete version of the compatible condition (5):
N
X

(11)

fi = 0

i=1

and can be satisfied by the modification f = f - mean(f).


3. E RROR ESTIMATE
In order to analyze the error, we need to put the problem into a norm space. A natural
norm for the finite linear space Vh is the maximum norm: for v Vh ,
kvk,h =

max {|vi,j |}.

1in+1,
1jm+1

The subscript h indicates this norm depends on the triangulation since for different h, we
have different numbers of vi,j . Note that this is the l norm for RN .
We shall prove 1
h : (Vh , k k,h ) (Vh , k k,h ) is stable uniform to h. The
proof will use the discrete maximal principal and barrier functions.
Theorem 3.1 (Discrete Maximum Principle). Let v Vh satisfy
h v 0.

Then
max v max v,
h

and the equality holds if and only if v is constant.


Proof. Suppose maxh v > maxh v. Then we can take an interior node x0 where the
maximum is achieved. Let x1 , x2 , x3 , and x4 be the four neighbors used in the stencil.
Then
4
4
X
X
4v(x0 ) =
v(xi ) h2 h v(x0 )
v(xi ) 4v(x0 ).
i=1

i=1

Thus equality holds throughout and v achieves its maximum at all the nearest neighbors
of x0 as well. Applying the same argument to the neighbors in the interior, and then to
their neighbors, etc, we conclude that v is constant which contradicts to the assumption

FINITE DIFFERENCE METHODS

maxh v > maxh v. The second statement can be proved easily by a similar argument.

Theorem 3.2. Let uh be the equation of
(12)

h uh = fI at h \h ,

uh = gI at h .

Then
(13)

kuh k,h

1
kfI k,h \h + kgI kh , .
8

Proof. We introduce the comparison function


1h
1
1 i
= (x )2 + (y )2 ,
4
2
2

which satisfies h I = 1 at h \h and 0 1/8. Set M = kfI k,h \h . Then


h (uh + M I ) = h uh + M 0,
so
1
max uh max(uh + M I ) max(uh + M I ) max gI + M.
h
h
h
h
8
Thus uh is bounded above by the right-hand side of (13). A similar argument applies to
uh giving the theorem.

Corollary 3.3. Let u be the solution of the Dirichlet problem (4) and uh the solution of
the discrete problem (12). Then
kuI uh k,h

1
kh uI (u)I k,h \h .
8

The next step is to study the consistence error kh uI (u)I kh, . The following
Lemma can be easily proved by Taylor expansion.
Lemma 3.4. If u C 4 (), then
kh uI (u)I k,h \h

h2
4u
4u
max{k 4 k,h \h , k 4 k,h \h }.
6
x
y

We summarize the convergence results on the finite difference methods in the following
theorem.
Theorem 3.5. Let u be the solution of the Dirichlet problem (4) and uh the solution of the
discrete problem (12). If u C 4 (), then
kuI uh k,h Ch2 ,
with constant
C=

4u
4u
1
max{k 4 k , k 4 k }.
48
x
y

In practice, the second order of convergence can be observed even the solution u is
less smooth than C 4 (), i.e. the requirement u C 4 (). This restriction comes from the
point-wise estimate. In finite element method, we shall use integral norms to find the right
setting of function spaces.

~ =0
u

on @

~ = (f1 , f2 )t .
~ = (u, v)t , and f
where u
2. MAC D ISCRETIZATION

LONG CHEN

( A ) index for p
F IGURE 1. A cell centered uniform grid

( B ) index for u

( C ) index for v

F IGURE 1. Index for p, u, v.


4. C ELL C ENTERED F INITE D IFFERENCE M ETHODS

In some applications,
computational
fluid we
dynamics
the Poisson
2.1.notable
MACthe
Scheme.
Suppose
have a(CFD),
rectangular
decomposition, for each cell,
equation is solved on gree
slightly
different
grids.
In
this
section,
we
consider
FDM
for
the edge centers and horizont
of freedoms for u and v are located on the vertical
Poisson equation at cell centers; see Fig 4.
centers, respectively, and the degree of freedoms for pressure p are located at cell c
At interior nodes, the standard (4, 1, 1, 1, 1) but boundary conditions will be
Thedistance
MAC in
scheme
is written
as (interior
= 1) nodes is still h but
treated differently. The
axis direction
between
i 1,j boundary)
i,j away
1
i,j+1the
the near boundary nodes (centers of4u
thei,jcellsutouching
ui+1,j isuh/2
ufrom
pi,j pi,j 1
(2.1)
+
= f1i,j
boundary. One can then
easily verify that for Neumann boundary
condition,
the
stencil
for
2
h
h
near boundary nodes is (3, 1, 1, 1) and for corner cells (2, 1, 1). Of course the
i,j
i 1,j
i+1,j
i,j 1
i,j+1
i 1,j
4v and moved
v
v right handv side.
v
p
pi,j
boundary condition g should be evaluated
to the
(2.2)
+
= f2i,j
2
The Dirichlet boundary condition is more subtle for cell h
centered
difference. We can
h
still introduce the ghost grid points and use standard (4, 1, 1, 1)ui,j+1
stencil for
near v i,j
ui,j
v i+1,j
boundary nodes. But (2.3)
no grid points are on the boundary. The ghost value can be elim-+
=0
h.
h
inated by linear extrapolation, i.e, requiring (u0,j + u1,j )/2 = g(0, yj ) := g1/2,j

Its easy to see that the above scheme


has second order truncation
2g1/2,j
5u1,j u2,j u1,j1 u1,j+1
=
f
+
.
1,j
1
h2
h2
The stencil will be (5, 1, 1, 1, 2) for near boundary nodes and (6, 1, 1, 2, 2)
for corner nodes. The symmetry of the corresponding matrix is still preserved.
However, this treatment is of low order (see Exercise 3). To obtain a better truncation
error, we can use the quadratic extrapolation, that is, use u1/2,j , u1,j , u2,j to fit a quadratic
function and evaluate at u0,j , we get u0,j = 2u1,j + 31 u2,j + 83 u1/2,j , and obtain the
modified boundary scheme should be:
(14)

8
6u1,j 34 u2,j u1,j1 u1,j+1
3 g1/2,j
=
f
+
.
1,j
h2
h2
We denote the near boundary stencil by (6, 43 , 1, 1, 83 ). The quadratic extrapolation will lead to a better rate of convergence since the truncation error is improved. The
disadvantage of this treatment is that the symmetry of the matrix is destroyed.
For the Poisson equation, there is another way to keep the second order truncation error
and symmetry. For simplicity, let us consider the homogenous Dirichlet boundary condition, i.e., u| = 0. Then the tangential derivatives along the boundary is vanished, in
particular, t2 u = 0. Assume the equation u = f holds also on the boundary condition. Note that on the boundary, the operator can be written as t2 + n2 . We then get
n2 u = f on . The sign is determined by if the norm direction is the same as the
axis direction. Then we can use u1 , u1/2 = 0 and n2 u = f to fit a quadratic function and

(15)

error.

FINITE DIFFERENCE METHODS

extrapolate to get an equation for the ghost point


u1,j + u0,j =

h2
f1/2,j
4

and modify the boundary stencil as


1
5u1,j u2,j u1,j1 u1,j+1
= f1,j + f1/2,j .
(16)
h2
4
5. E XERCISES
(1) Prove the following properties of the matrix A formed in the finite difference methods for Poisson equation with Dirichlet boundary condition:
(a) it is symmetric: aij = aji ;
PN
(b) it is diagonally dominant: aii j=1,j6=i aij ;
(c) it is positive definite: ut Au 0 for any u RN and ut Au = 0 if and only if
u = 0.
(2) Let us consider the finite difference discritization of Poisson equation with Neumann boundary condition.
(a) Write out the 9 9 matrix A for h = 1/2.
(b) Prove that in general the matrix corresponding to Neumann boundary condition is only semi-positive definite.
(c) Show that the kernel of A consists of constant vectors: Au = 0 if and only if
u = c.
(3) Check the truncation error of schemes (14), (15) and (16) for different treatments
of Dirichlet boundary condition in the cell centered finite difference methods.

Potrebbero piacerti anche