Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Lecture 22 GEL 161: Introduction to Finite Difference Methods

The goal of this next week is to learn a bit about the Finite Difference Method and how
to use it to solve the Diffusion Equation for a bunch of different geologic problems.
The Finite Difference Method illustrates many of the concepts used in the type of nu-
merical modelling used in oil industry, engineering applications, environmental hazards
assessment and geophysics in general.
The Diffusion Equation in one dimension includes two derivatives, a first derivative
of the variable of interest (T, H, C) in time, and a second derivative of the variable of
interest in space. Let’s use the variable u to represent any one of the variables used in
the three types of diffusion problems we’ve considered:
∂u 2
∂t = κ ∂∂xu2
where κ is the diffusivity or diffusion constant.

Analytic versus Numerical Solutions


Numerical solutions to diffusion equation will differ from analytic solution in three
important ways:

• Analytic Solutions

1. are Continuous in space and time. The solution u(x,t) can be evaluated at
any x and any t.

2. are Exact for specific set of boundary conditions (BCs) and initial condi-
tions (ICs).

3. are Limited in that an analytic solution can only be found for a limited set
of BCs and ICs.

• Numerical Solutions

1. are Discrete in space and time. Numerical solution divide up the spatial

1
domain (x-axis) into discrete segments of width ∆x, called the grid or mesh
spacing. The solution is found at the segment boundaries, the positions x j ,
called node points. Imagine dividing up the x-axis into M − 1 segments,
then there will be M node points. The list of node points at which the
solution is found, is then given by:
x = [x1 x2 x2 3 . . . x j . . . xM−1 xM ],
where j = 1–M. The time axis can also be divided into increments of time
∆t called time-steps, with N − 1 segments separated by N times given by:
t = [t1 t2 t3 . . .tn . . .tN−1 tN ],
where n = 1–N.

2. are Approximate. Except for a solution that ends up being exactly a


straight line, even if you solve for the exact solution at all the grid points,
the value of the solution between the grid points would depend on the ac-
curacy of the estimates for the derivatives at each grid point (see below).
The approximation to the true solution is found by estimating the value of
the derivatives (continuous functions) using information you already have
at discrete grid points.
Estimates of derivatives can be first order, second order, third order ... First
order implies that you have an accurate estimate of the local slope (the first
derivative of the function), but not any higher order information about the
local shape of the function.
Second order implies that you have an accurate estimate of the local slope
and the local curvature (concave up, concave down, or horizontal).

3. are Flexible. If you specify a complete set of boundary conditions and ini-
tial conditions (for 1-D, 2 BCs and 1 IC), the a solution to the diffusion

2
equation can be found. This means that unlike analytic solutions that may
only work for boundary conditions that are uniform in time, with the nu-
merical method, you can define boundary conditions that are constant, vary
smoothly with time, vary in time with jumps or steps, etc...
Note that in general ∆x can vary along the profile, giving you higher reso-
lution (more accuracy) in a region that you expect to have more variation
(steeper slopes), and ∆t can also vary in at different times in the calcula-
tion, perhaps starting out with smaller steps and increasing step size as the
diffusion process slows down. We will stick to using constant ∆x and ∆t.

Approximating Derivatives
When you learned calculus, you were introduced to the idea of approximating the
derivatives of a continuous function by dividing up the function into segments and
looking at how the slope (first derivative) varied between segments. Consider a
function u(x), divided along the x-axis into segments of width ∆x. Consider one
grid point (segment boundary) near the center at grid point at position x given by
x j . The point to the left at x − ∆x is grid point x j−1 and the point to the right is
at x + ∆x is at grid point x j+1 . You want to extract information about the first and
second derivative of the function u(x) from the information just and grid points.

• Taylor Series Expansion


The Taylor series expansion relates the value of the function u(x) to values at
adjacent points (x + ∆x or x − ∆x) and the derivatives of u(x). For example:
2 ∂2 u 3 3
u(x + ∆x) = u(x) + ∆x ∂u ∆x
∂x + 2 ∂x2
+ ∆x6 ∂∂xu3 + · · ·
and
2 ∂2 u ∆x3 ∂3 u
u(x − ∆x) = u(x) − ∆x ∂u ∆x
∂x + 2 ∂x 2 − 6 ∂x3 + · · ·

3
• First Derivatives (∂u/∂x)
Note that either of the Taylor Series expansions above can be solved for the
first derivative on the right-hand side...

1. Forward Difference
If we keep only the first two terms of the expansion for u(x + ∆x), then
u(x+∆x)−u(x)
∂u/∂x = ∆x

This is a first order accurate solution, denote O(∆x). It is called the forward
difference since it finds the derivative in the positive (forward) direction of
the profile from the point at x.

2. Backward Difference If we keep only the first two terms of the expansion
for u(x − ∆x), then
u(x)−u(x−∆x)
∂u/∂x = ∆x

This is a first order accurate solution, denote O(∆x). It is called the back-
ward difference since it finds the derivative in the negative (backward) di-
rection of the profile from the point at x.

3. Centered Difference To get a more accurate representation the first deriva-


tive, find the difference between u(x + ∆x) and u(x − ∆x):
2∂2 u ∆x2 ∂2 u
u(x + ∆x) − u(x − ∆x) = u(x) + ∆x ∂u ∆x
∂x + 2 ∂x 2 − u(x) + ∆x ∂u
∂x − 2 ∂x2

Note that the u(x) terms cancel, as do the ∆x2 terms leaving:
u(x+∆x)−u(x−∆x)
∂u/∂x = 2∆x

This is a second order accurate solution (I included the ∆x2 terms, they just
happen to cancel out) - O(∆x2 ). It is called a centered difference, because
it is centered at the position x, but uses information from both adjacent
points.

• Second Derivatives (∂2 u/∂x2 )

4
For the diffusion equation, we actually need the second derivative. Again we
can use the Taylor series expansions, this time using the sum of u(x + ∆x) and
u(x − ∆x):
2 ∂2 u ∆x2 ∂2 u
u(x + ∆x) + u(x − ∆x) = u(x) + ∆x ∂u ∆x
∂x + 2 ∂x2
+ u(x) − ∆x ∂u
∂x + 2 ∂x2

This time only the ∆x terms cancel, leaving:


2
u(x + ∆x) + u(x − ∆x) = 2u(x) + ∆x2 ∂∂xu2
∂2 u
Solving for ∂x2
:
∂2 u u(x+∆x)−2u(x)+u(x−∆x)
∂x2
= ∆x2
This is again a centered difference, but it also uses information about u at po-
sition x. It is second order accurate, O(∆x2 ).

Note that this is different from what you’d get if you just guessed at the second
derivative based on the equation for the first derivative, by taking the second
derivative of the expression for ∂u/∂x, by dividing by another ∆x. DO NOT
DO THIS. You really do need to go through the processes of using the Taylor
series expansion and solving for the derivative you need.

Ways to Improve Accuracy

1. Decrease ∆x: This is the easiest and fastest way to improve accuracy, but it
comes with a computational cost and taking more time and memory.

2. Decrease ∆t: This will only get you from a not accurate solution to an accurate
solution. You should estimate ∆t using the diffusion time-scale (see next lec-
ture), and then check that if you make ∆t smaller the solution doesn’t change.

3. Include more information: You can improve accuracy by including informa-


tion on the derivatives of u at grid points further away from x. For example,
take the Taylor Series expansion for u(x + 2∆x) and combine it with the ex-
pression for u(x + ∆x). This give you more information about the shape of the

5
curve.

You might also like