2.2. Methods For Obtaining FD Expressions: 2.2.1. Taylor Series Expansion Method
2.2. Methods For Obtaining FD Expressions: 2.2.1. Taylor Series Expansion Method
2.2. Methods For Obtaining FD Expressions: 2.2.1. Taylor Series Expansion Method
= lim
x0 , y0
x 0
u ( x0 + x, y0 ) u ( x0 , y0 )
x
The Taylor series approach works backwards want to approximate u/x by a discrete difference, i.e., for finite x.
Given u(x0 , y0 ), we can write a Taylor series expansion for u(x0 +x, y0 ), as
u ( x0 + x) = u ( x0 ) + x
u
x
+
x0 , y0
( x) 2 2u
2
2! x
+
x0 , y0
(x )3 3u
3
3! x
( x) n nu
n
n ! x
n= 0
+ ... =
x0 , y0
=
x0 , y0
u ( x0 + x, y0 ) u ( x0 , y0 )
x
x 2 u
2
2! x
x0 , y0
( x) 2 3u
3
3! x
+ ...
(1)
x0 , y0
The first term on the RHS is simply the slope of the function u(x,y,), using the current and the points to the right.
Therefore,
u
x
u ( x0 + x, y0 ) u ( x0 , y0 )
x
x0 , y0
+ O( x ) .
=
x0 , y0
u ( x0 , y0 ) u( x0 x , y0 )
x
x 2 u
2
2! x
x0 , y0
( x) 2 3u
3
3! x
+ ...
(2)
x0 , y0
Both (1) and (2) provides an expression for u/x, but numerically the answers will be different.
(1) is called a forward difference
(2) is called a backward difference
No information is coming from the +x direction. This of course depends on the sign of c. If C<0, then upstream means the left side of
the current point.
Note that upstream or upstream-biased schemes are usually better choices in CFD (obviously we are talking about hyperbolic
equations that represent propagations!).
We will see later, that 1st-order downstream difference is absolutely unstable for the above problem.
We can get another discrete approximation to u/x by adding (1) and (2):
u
x
=
x0 , y0
ui+1 ui1 ( x ) 2 3u
3
2 x
3! x
+ ...
(3)
x0 , y0
This is called Centered Difference. Note, it doesn't even use value of u at the current point i. It approximates the slope using two
neighboring points:
Note that this will not be accurate if u has very sharp gradient (). Note also that the extra term in (3) are different they control the
accuracy.
We can build many different approximations to the derivatives through linear combinations of various T.S. expansions.
u (x ) 2 2u ( x ) 3 3u
+
+
+ ...
x
2! x 2
3! x 3
(4)
2u
u
from (4), but we don't want to have the unknown
.
2
x
x
We can replace it with one of the earlier approximations to it, or make use of the following:
We can solve for
u ( x x ) = u ( x ) x
u ( x ) 2 2u ( x )3 3u
+
+ ...
x
2! x 2
3! x3
(5)
2u
:
x 2
2u u ( x + x) 2u ( x) + u ( x x)
=
+ O( x 2 )
2
2
x
( x)
2u
which is a centered difference for 2 .
x
Truncation Error
The high-order terms (H.O.T.) of O(xn ) are called the Truncation Error, and are a measure of the error associated with representing a
PDE by a truncated T.S. we can't retain all terms, so we neglect the terms of order O(x2 ) and above, for example.
PDE = FDE +
ui ui 1
is first-order accurate in space
x
because =
x 2 u
+ ... = O( x1)
2
2! x
Comments on :
(1) If there are several independent variables, each has a truncation error, e.g., O(x2 + t), we say it's first order in time and
second order in space.
(2) The order of a scheme also depends on the local properties of the function, it may be much less than the formal or theoretical
order near sharp gradients. Recall that Taylor series are valid only for smooth and continuous functions.
(3) Typically, we prefer higher-order scheme because is smaller. However, is not necessarily related to accuracy because, for a
given x, a first-order scheme may give more accurate results because the coefficient is smaller. What does tells us is how
the error will change as we change the resolution. Higher order decreases faster when we decreases x.
e.g., = (x)3 versus = x.
Remember that includes , which might be
4u
, etc and it matters.
x 4
mu (x ) m
ui+1 = m
m!
m= 0 x i
Now, suppose we want to use a 3-point stencil at i-1, i, i+1. Then, we can write a generic expression (PDE = FDE + ) as:
u
= aui1 + bui + cui+1 + O( x) m
x
where a, b and c are unknown constants to be determined and m is the order of the approximation. (General rule: If F.D. spans n points,
you can derive an n-1 order F.D. scheme).
Using our Taylor series for ui-1 , ui and ui+1 , we can write
u ( x ) 2 2u ( x ) 3 3u
+
+ ...)
x
2! x 2
3! x 3
+ bui
u ( x ) 2 2u ( x ) 3 3u
+
+
+ ...)
x
2! x 2
3! x 3
u
( x) 2 2u
( x) 3 3u
= (a + b + c )ui + ( a + c) x + ( a + c )
+
(
a
+
c
)
+ ... (6)
x
2! x 2
3! x 3
c (ui + x
u
+ O ( x ) m , therefore we set
x
(a+b+c) =0,
(-a+c)x=1
a+c=0.
From them we can find b=0, c = -a = 1/(2x), therefore
u ui+1 ui1
=
+ O ( x) 3
x
2 x
10
Goal: Find a, b and c. Note that the grid spacing need not be uniform.
Applying the polynomial to those three points gives
ui-1 = a x2 i-1 + b xi-1 + c
ui = a x2 i + b xi + c
ui+1 = a x2 i+1 + b xi+1 + c
Solve for a, b, c, we obtain
( x xi )( x xi+1 )
( x xi1 )( x xi +1 )
u ( x ) = ui1
+ ui
( xi 1 xi )( xi1 xi+1)
(xi xi1 )( xi xi +1 )
( x xi )(x xi1 )
+ ui+1
11
u
x
by differentiating the expression for u(x). First, let us define x xi+1 - xi = xi xi-1 => 2 x =
xi
because we used a 2nd order polynomial. To obtain FD formulation for third order derivative, we have to use 3rd- or higher- order
polynomial.
The 2nd order case can be interpreted physically as the derivative of derivative, or the difference between two slopes
u 2 u
=
x x x 2
or
ui +1 ui ui ui 1
x
x
x
12
i.e., the difference between the slope centered at i+1/2 and slope centered at i-1/2.
Higher-order approximations tend to introduce noises into the solution because the higher-order derivatives may be large,
particularly near sharp gradients.
Beyond 2nd-order, the polynomial method is not identical to the Taylor series method.
( c > 0andconstant)
Let's draw a space-time diagram, using discrete points in space and time:
13
In general, u* won't coincide with grid points but we know only values at the grid points. So we need interpolation from the grid points
to *.
We are free to use as many points as we want, more points higher order.
Indeed, the interpolation used determines the order of accuracy of the solution.
With simple linear interpolation, we get (see figure)
u =
*
x n x n
ui 1 + 1
ui .
x
x
14
ct n
ct n
ui1 + uin
ui
x
x
or
uin+1 uin
u n uin1
+c i
=0
t
x
This is a familiar first-order upstream method using a forward-in-time scheme!
As we will see later, this scheme is strongly damping, therefore inaccurate. This is because linear interpolation always under-estimate
the peak values in the solution.
This scheme yields exact solution if c = constant and t = x/c. For general problem this condition is hard to meet, however.
If we new include point i+1 in our interpolation, we end up fitting a parabola to the points and obtain
u*n = uin+1 = uin
where =
n
2 n
(ui+1 uin1 ) +
(ui+1 2uin + uin1)
2
2
c t
.
x
15
scheme is absolutely unstable (i.e., the numerical solution will grow without bound in computer problems, you will quickly run into
floating-point overflow error).
16