You are on page 1of 9

School of Mechanical Aerospace and Civil Engineering

Introduction
TPFE MSc CFD-1
◮ In this lecture we consider the process of discretizing the governing
partial differential equations of a fluid flow.

◮ Discretization is the process of approximating the differential equations


by a system of algebraic ones linking the (discrete) nodal values of
Finite Difference Schemes velocity, pressure, etc.

T. J. Craft ◮ There are three broad methods employed for discretizing the governing
George Begg Building, C41 partial differential equations of a fluid flow:
◮ Finite Difference (FD)
◮ Finite Element (FE)
Reading: ◮ Finite Volume (FV)
J. Ferziger, M. Peric, Computational Methods for Fluid
Dynamics ◮ Although there are obvious similarities in the resulting set of discretized
H.K. Versteeg, W. Malalasekara, An Introduction to
Computational Fluid Dynamics: The Finite Volume algebraic equations, the methods employ different approaches to
Method obtaining these. As a result, there can be differences in both the
S.V. Patankar, Numerical Heat Transfer and Fluid Flow accuracy and ease of application of the various methods.
Notes: http://cfd.mace.manchester.ac.uk/tmcfd
- People - T. Craft - Online Teaching Material
Finite Difference Schemes 2010/11 2 / 35

◮ Finite difference schemes can generally be ◮ Finite element approaches are traditionally used in solid mechanics.
applied to regular-shaped domains using These can be adapted to fluid problems, but finite volume schemes tend
body-fitted grids (curved grid lines, following to be the more popular choice in CFD (and are currently used in most, if
domain boundaries). not all, of the major commercial packages).

◮ Large grid distortions need to be avoided, and ◮ We will examine finite volume schemes later. However, to begin with we
the schemes cannot easily be applied to very consider how finite difference schemes can be devised.
complex flow geometry shapes.
◮ Despite not being generally used in industrial codes, finite difference
◮ Finite element and finite volume schemes are both based on dividing the schemes are useful for introducing the ideas of accuracy, truncation error,
flow domain into a (large) number of small cells, or volumes. These can stability and boundedness in a well-defined and fairly transparent way.
be of any shape (triangles, quadrilaterals, etc. in 2-D; tetrahedra, prisms,
cubes, etc. in 3-D). They are thus more suitable for application to
complex flow geometries.

Finite Difference Schemes 2010/11 3 / 35 Finite Difference Schemes 2010/11 4 / 35


Approximating Derivatives ◮ Many problems involve rather more complex expressions than simply
derivatives of φ itself.
◮ For illustration, a simple equation to consider, related to the more
f(x)
complex Navier-Stokes system, is the 1-D convection-diffusion problem: ◮ We therefore consider some arbitrary function
∂ ρUφ ∂

∂φ
 f (x ), and suppose we can evaluate it at the
= Γ (1) uniformly spaced grid points x1 , x2 , x3 , etc. as
∂x ∂x ∂x
shown. x
◮ φ is the variable transported by the flow (ie. the quantity we need to solve x1 x2 x3 x4

for), U is the convective velocity and Γ the diffusivity.


◮ If, for example, φ represents fluid temperature, this equation describes
the 1-D problem of temperature changes due to convection by the fluid
and diffusion by molecular action.
◮ We store φ at a number of fixed grid points (x1 ,
φ
x2 , x3 , etc).
◮ To approximate equation (1) by a set of
algebraic equations relating the values of φ at
x1 , x2 , etc. we need to approximate the various x
derivatives in terms of these nodal values of φ .
x1 x2 x3 x4

Finite Difference Schemes 2010/11 5 / 35 Finite Difference Schemes 2010/11 6 / 35

Taylor Series Approximation ◮ If we take ∆x as the uniform grid spacing, so ∆x = xi+1 − xi , then we get
the approximation
◮ Taylor series expansions can often be used to develop and/or analyse the f (xi+1 ) − f (xi )
f ′ (xi ) = + O(∆x ) (4)
accuracy of numerical approximations for derivatives. ∆x
which we will write in shorthand form as
◮ Writing a Taylor series expansion to evaluate f at positions x close to xi :
fi+1 − fi
(∆x )2 ′′ (∆x )3 ′′′ fi′ = + O(∆x ) (5)
f (xi + ∆x ) = f (xi ) + ∆xf ′ (xi ) + f (xi ) + f (xi ) + O(∆x 4) (2) ∆x
2! 3!
where fi represents f evaluated at xi , etc.

where f denotes the derivative df /dx , f

f ′′ the second derivative d 2 f /dx 2 etc.


◮ The approximation suggested by f
equation (5),
x
◮ Rearranging gives xi
∆x

fi′ ≈ (fi+1 − fi )/∆x (6)


f (xi + ∆x ) − f (xi ) ∆x ′′ (∆x )2 ′′′
f ′ (xi ) = − f (xi ) − f (xi ) + O(∆x 3) x
∆x 2! 3! is known as a forward difference. xi x i+1

f (xi + ∆x ) − f (xi )
= + O(∆x ) (3)
∆x ◮ This is a first order scheme, since the error is proportional to ∆x , so
where O(∆x ) means the leading term is proportional to ∆x . decreases linearly with grid spacing.
Finite Difference Schemes 2010/11 7 / 35 Finite Difference Schemes 2010/11 8 / 35
◮ Alternatively, we could use equation (2) to evaluate f at a point xi − ∆x : ◮ We could combine the two Taylor series approximations above:
(∆x )2 ′′ (∆x )3 ′′′ (∆x )2 ′′ (∆x )3 ′′′
f (xi − ∆x ) = f (xi ) − ∆xf ′ (xi ) + f (xi ) − f (xi ) + O(∆x 4) (7) f (xi+1 ) = f (xi ) + ∆xf ′ (xi ) + f (xi ) + f (xi ) + O(∆x 4) (11)
2! 3! 2! 3!
(∆x )2 (∆x )3
◮ Taking ∆x as the grid spacing now leads to f (xi−1 ) = f (xi ) − ∆xf ′ (xi ) + f ′′ (xi ) − f ′′′ (xi ) + O(∆x 4) (12)
2! 3!
(∆x )2 ′′ (∆x )3 ′′′
f (xi−1 ) = f (xi ) − ∆xf ′(xi ) + f (xi ) − f (xi ) + O(∆x 4) (8) ◮ Subtracting one from the other results in
2! 3!
(∆x )3 ′′′
◮ Rearranging leads to the approximation f (xi+1 ) − f (xi−1 ) = 2∆xf ′ (xi ) + 2 f (xi ) + O(∆x 5) (13)
3!
f (xi ) − f (xi−1 ) Rearranging gives the approximation
f ′ (xi ) = + O(∆x ) (9) ◮
∆x
f (xi+1 ) − f (xi−1 )
f ′ (xi ) = + O(∆x 2) (14)
2∆x
◮ This approximation, f
◮ This approximation
f
fi′ ≈ (fi − fi−1 )/∆x (10)
fi′ ≈ (fi+1 − fi−1 )/(2∆x ) (15)
is referred to as a backward differencing
scheme. is referred to as a centred difference. xi-1 xi x i+1
x
x
xi-1 xi
◮ This is a second order approximation, since the error reduces as (∆x )2 : if
◮ It is again a first order scheme. the grid spacing is halved, the error goes down by a factor of 4.
Finite Difference Schemes 2010/11 9 / 35 Finite Difference Schemes 2010/11 10 / 35

Order of Approximation ◮ Note this does not mean a second order solution on one particular grid
will always be more accurate than a first order one (although this will
usually be the case for a sufficiently fine grid).
◮ At this point it is worth considering exactly what is meant by the order of
accuracy of a discretization approximation. ◮ It does, however, imply that as we refine the grid the error in the higher
order scheme goes down more rapidly, so we expect the higher order
◮ As we refine the grid, for any useful scheme, errors associated with the scheme to reach a grid independent solution on a coarser grid than
discretization approximation can be expected to reduce. would be required for a lower order scheme.
◮ We reach a grid independent solution when any further grid refinement ◮ It is worth noting that the behaviour described above for a particular
produces no significant difference in the computed solution. At this stage scheme can only be expected on a reasonably fine grid.
the discretization errors are small enough that they can be neglected.
◮ The reason for this can be seen from the Taylor series expansion. For
◮ We have defined the order of a scheme in terms of the leading order error example, in the first order backward difference scheme we have
term in the Taylor series expansion. f −f ∆x ′′ (∆x )2 ′′′
fi′ = i i−1 + f (xi ) − f (xi ) + O(∆x 3) (16)
∆x 2! 3!
◮ This should, therefore, determine at what rate the error reduces as the
grid is refined. If the first term in the truncation is to be the leading error term, then ∆x
has to be small enough so that
◮ For a first order scheme, if the grid spacing is halved the error is halved;
∆x ′′
′′
(∆x )2 ′′′

f (x )
for a second order scheme the error would reduce by a factor of 4. |f (xi )| << |f (xi )| or ∆x << 3 ′′′ i (17)
3! 2! f (xi )
Finite Difference Schemes 2010/11 11 / 35 Finite Difference Schemes 2010/11 12 / 35
Polynomial Approximation ◮ On a uniform grid with xi+1 − xi = xi − xi−1 = ∆x and xi+1 − xi−1 = 2∆x this
becomes
◮ The above approximations for the derivatives could also have been (x − xi )(x − xi+1) (x − xi−1)(x − xi+1) (x − xi )(x − xi−1)
f (x ) = fi−1 − fi + fi+1
derived by fitting a polynomial to the function f through xi and surrounding 2(∆x )2 (∆x )2 2(∆x )2
points and then differentiating this polynomial to get its gradient. (19)
◮ Differentiating with respect to x then gives
◮ The forward and backward difference schemes arise from fitting a first
order polynomial (a straight line) through the points (xi , xi+1 ) and (xi−1 , (x − xi + x − xi+1) (x − xi−1 + x − xi+1) (x − xi + x − xi−1 )
f ′ (x ) = fi−1 − fi + fi+1
xi ) respectively. 2(∆x )2 (∆x )2 2(∆x )2
(20)
and thus
◮ The centred difference scheme can be f

obtained by fitting a quadratic curve −∆x 0 ∆x (f − f )


f ′ (xi ) = fi−1 − fi + fi+1 = i+1 i−1 (21)
through the points xi−1 , xi and xi+1 . The 2(∆x )2 (∆x )2 2(∆x )2 2∆x
resulting polynomial approximation for f
can be written as x ◮ The above procedure does not immediately show us what order the
xi-1 xi x i+1
truncation error is.
(x − xi )(x − xi+1 )fi−1 (x − xi−1)(x − xi+1)fi (x − xi )(x − xi−1 )fi+1
f (x ) = + + ◮ However, the order of the scheme can be determined by expressing fi+1
(xi−1 − xi )(xi−1 − xi+1) (xi − xi−1)(xi − xi+1) (xi+1 − xi )(xi+1 − xi−1 )
and fi−1 as Taylor series expansions about xi as before, and substituting
(18)
these into the right hand side expression of equation (21).
Finite Difference Schemes 2010/11 13 / 35 Finite Difference Schemes 2010/11 14 / 35

Approximating Higher Order Derivatives ◮ Note the computational stencil (the nodal points used) is now larger,
because we need more points to give information about curvature etc.
◮ Taylor series expansions or polynomial fits can also be used to derive ◮ In many fluids related problems the second derivative that requires
approximations to higher order derivatives. approximation is a diffusion term of the form
∂ ∂f
 
2 2
◮ For example, to approximate the second derivative d f /dx we could, as Γ (26)
before, write: ∂x ∂x
(∆x )2 ′′ (∆x )3 ′′′ This can be approximated using central f
f (xi+1 ) = f (xi ) + ∆xf (xi ) +
′ ◮
f (xi ) + f (xi ) + O(∆x 4) (22)
2! 3! differences to estimate df /dx at the
(∆x )2 ′′ (∆x )3 ′′′ mid-points xi+1/2 and xi−1/2 , followed by a
f (xi−1 ) = f (xi ) − ∆xf (xi ) +

f (xi ) − f (xi ) + O(∆x 4) (23) central difference between these values to
2! 3! x
estimate the second derivative term: xi-1 xi x i+1
◮ Adding the two equations and rearranging now results in x i-1/2
xi+1/2

f (xi+1 ) − 2f (xi ) + f (xi−1 ) df f −f df f −f
′′
f (xi ) = + O((∆x )2 ) (24) ≈ i i−1 ≈ i+1 i (27)
(∆x )2 dx i−1/2
∆x dx i+1/2
∆x
This gives the central difference approximation for the second derivative ∂ ∂f Γi+1/2 (fi+1 − fi ) − Γi−1/2(fi − fi−1 )

 
Γ ≈ (28)
fi+1 − 2fi + fi−1 ∂x ∂x (∆x )2
fi′′ ≈ (25)
(∆x )2 ◮ Note that interpolation may be required to estimate values of Γ at the
which is again second order accurate when applied on a uniform grid. midpoints xi+1/2 and xi−1/2 .
Finite Difference Schemes 2010/11 15 / 35 Finite Difference Schemes 2010/11 16 / 35
Non-Uniform Grids ◮ Hence we obtain
f (xi+1 ) − f (xi−1 ) f ′′ (xi )
f ′ (xi ) = + (∆xi − ∆xi−1) + O(∆x 2) (32)
◮ In most CFD applications non-uniform grids are employed, allowing the ∆xi + ∆xi+1 2!
grid to be more refined in regions where strong gradients are expected. ◮ Note that formally the central difference fi′ = (fi+1 − fi−1 )/(∆xi + ∆xi−1) is
now only first order accurate.
f
◮ In such a case, the simple forward/backward
differences are clearly still first order. ◮ In practice, one should avoid using rapidly expanding grids, so typically
∆xi = r ∆xi−1 with grid expansion ratio r not too far from unity. The factor
◮ Analysis of the central difference scheme, (∆xi − ∆xi−1 ) = ∆xi (1 − r ) in the leading order error can then still be
however, is a little different. ∆ x i-1 ∆xi x essentially second order.
xi-1 xi xi+1

◮ Using Taylor series expansions we can now write:


◮ The approximation derived from the polynomial fit of equation (18) still
gives a formally second order approximation.
(∆xi )2 ′′ (∆xi )3 ′′′
f (xi+1 ) = f (xi ) + ∆xi f ′ (xi ) + f (xi ) + f (xi ) + O((∆xi )4 ) (29) ◮ In this case we get
2! 3!
2 (x − xi )(x − xi+1)fi−1 (x − xi−1)(x − xi+1)fi (x − xi )(x − xi−1)fi+1
(∆x i−1 ) (∆xi−1 )3 ′′′ f (x ) = − +
f (xi−1 ) = f (xi ) − ∆xi−1f ′ (xi ) + f ′′ (xi ) − f (xi ) + O((∆xi−1)4 ) (∆xi−1 )(∆xi + ∆xi−1) ∆xi ∆xi−1 (∆xi )(∆xi + ∆xi−1 )
2! 3! (33)
(30)
◮ Subtracting gives
◮ Differentiating leads to
(x − xi + x − xi+1 )fi−1 (x − xi−1 + x − xi+1 )fi (x − xi + x − xi−1)fi+1
f (xi+1 ) − f (xi−1 ) = (∆xi + ∆xi−1 )f ′ (xi ) + (∆xi2 − ∆xi−1
2
)f ′′ (xi ) + O(∆x 3 ) (31) f ′ (xi ) = + +
(∆xi−1 )(∆xi + ∆xi−1 ) ∆xi ∆xi−1 (∆xi )(∆xi + ∆xi−1)
(34)
Finite Difference Schemes 2010/11 17 / 35 Finite Difference Schemes 2010/11 18 / 35

◮ Hence we obtain the approximation The Convection-Diffusion Problem


−∆xi ∆x − ∆xi−1 ∆xi−1
fi′ ≈ f + i f + f (35) The 1-D convection-diffusion equation for a transported variable is
(∆xi−1 )(∆xi + ∆xi−1) i−1 ∆xi ∆xi−1 i (∆xi )(∆xi + ∆xi−1) i+1

sufficient to demonstrate some of the advantages and weaknesses that
◮ If we express fi+1 and fi−1 as Taylor series expansions about xi the above can be encountered with the numerical approximations outlined above.
approximation implies
◮ It can be written as
∂ ρUφ ∂ ∂φ
 
(∆xi−1 )2 ′′ (∆xi−1 )3 ′′′
 
−∆xi = Γ (36)
fi′ ≈ f − ∆xi−1fi′ + fi − fi + O(∆x 4 ) ∂x ∂x ∂x
(∆xi−1 )(∆xi + ∆xi−1) i 2! 2!
∆x − ∆xi−1 φ is the variable being transported by the flow, which could be
+ i f ◮
∆xi ∆xi−1 i temperature, chemical species concentration, etc. U is the fluid velocity
∆xi−1

(∆xi )2 ′′ (∆xi )3 ′′′
 which, for simplicity, we take as constant.
+ f + ∆xi fi′ + f + f + O(∆x 4)
(∆xi )(∆xi + ∆xi−1) i 2! i 2! i
◮ The fluid density, ρ , and Γ, the diffusivity of φ , are also taken as
∆xi ∆xi−1 ′′′ constants.
= fi′ + fi + O(∆x 3)
3!
◮ The left hand side of the equation represents the transport effect of φ
Thus showing that the approximation of equation (35) is indeed second being convected by the fluid. The right hand side represents the
order. molecular diffusion of φ .

Finite Difference Schemes 2010/11 19 / 35 Finite Difference Schemes 2010/11 20 / 35


◮ As an example, we consider the above equation, applied on the interval ◮ Discretizing this convection-diffusion equation on a uniform grid using
0 ≤ x ≤ L, with boundary conditions φ = 0 at x = 0 and φ = 1 at x = L. central differences for both convective and diffusive terms, we get
φi+1 − φi−1 φ − 2φi + φi−1
   
The exact solution to this problem is ρU = Γ i+1 (38)

2∆x ∆x 2
given by
or, on rearranging:
exp(xPe/L) − 1
φ (x ) = (37) ρU Γ ρU Γ
   

exp(Pe) − 1 φi−1 − − + 2 φi + φi+1 − =0 (39)
2∆x ∆x 2 ∆x 2∆x ∆x 2
where Pe = ρ UL/Γ is the Peclet
number. ◮ φ1 and φn are known from the boundary
conditions (φ1 = 0 and φn = 1). Hence the
x1 x2 xn−1 x n
◮ Notice that the Peclet number gives a measure of the ratio of convective discretized equations at nodes 2 and n − 1
effects to diffusive ones. can be simplified to

As the Peclet number increases (diffusive effects become weaker), the ρU Γ


 
◮ 2Γ
region over which most of the variation in φ occurs becomes thinner, and φ2 + φ3 − =0 (40)
∆x 2 2∆x ∆x 2
the gradients of φ across it become correspondingly larger.
ρU Γ ρU Γ
   

φn−2 − − + 2 φn−1 = − − (41)
2∆x ∆x 2 ∆x 2∆x ∆x 2

Finite Difference Schemes 2010/11 21 / 35 Finite Difference Schemes 2010/11 22 / 35

◮ The discretized form of equations can thus be represented in the ◮ In this case, rearranging equation (39) to solve for φi gives
tri-diagonal matrix form:
φ ρ U∆x φ ρ U∆x
   
φi = i+1 1 − + i−1 1 +
φ2 2 2Γ 2 2Γ
    
b1 c1 0 . . . . . . . . . . . . . . . . . . . . . . . . . 0
 φ  
a2 b2 c2 0 . . . . . . . . . . . . . . . . . . 0 φ φ
   
Pex Pex
 
3 
= i+1 1 − + i−1 1 + (43)
 
 . .
 0 a3 b3 c3 0 . . . . . . . . . . .  .   ..
  
  2 2 2 2
 .  

 
.
where Pex is the cell Peclet number, Pex = ρ U∆x /Γ.
. .. .. .. ...   ..  =  ..
  
 ..
 
 . . . . 


.
  
  ..  
 ..

◮ For a given bulk Peclet number, ρ UL/Γ, as we divide the domain into a
. . . . . . . 0 an−3 bn−3 cn−3 0  . 
  
larger number of intervals, the cell Peclet number ρ U∆x /Γ decreases.
 
an−2 bn−2 cn−2  φn−2  
 0
. . . . . . . . . . . .
  
0
ρU

Γ
.................. 0 an−1 bn−1 φn−1 (∆x ) 2 − 2∆x ◮ For uniform grids with 3 gnd 5 grid nodes, the x=0 x=L
(42) cell Peclet numbers, Pex , at different bulk x1 x2 x3
ρU ρU
where ai = − 2∆x − (∆xΓ )2 , bi = (∆x 2Γ
)2
, ci = 2∆x − (∆xΓ )2 . Peclet numbers, Pe, are given in the table. x1 x2 x3 x4 x5

◮ This system of equations can be solved by a variety of methods, some of ∆x Pe = 0.5 Pe = 1.5 Pe = 3 Pe = 5 Pe = 10
which will be examined later. 3 nodes L/2 0.25 0.75 1.5 2.5 5
5 nodes L/4 0.125 0.375 0.75 1.25 2.5
◮ The values of φ at the nodes can be found by solving equation (43) at
each node, and the results are shown in the following graphs.
Finite Difference Schemes 2010/11 23 / 35 Finite Difference Schemes 2010/11 24 / 35
◮ At Pe = 1.5 both the 3 node and 5 node central difference solutions give
a good approximation to the exact result.

◮ At Pe = 3 the coarser grid solution (with Pex = 1.5) is becoming less


accurate.

◮ At Pe = 5 the finer grid solution (with Pex = 1.25) is still satisfactory, but
with Pex = 2.5 the estimated value of φ at x /L = 0.5 is now negative.

◮ At Pe = 10 both solutions with Pex = 2.5 and 5 give negative values of φ


at some nodes.

◮ This is an example of an unbounded scheme. If φ represented a species


concentration, for example, or some other physically positive quantity,
then the under/overshoots would imply a solution returning physically
unrealizable results.

◮ It can be shown that Pex < 2 is a sufficient condition to ensure the centred
difference scheme does not produce under/overshoots in this problem.

Finite Difference Schemes 2010/11 25 / 35 Finite Difference Schemes 2010/11 26 / 35

◮ However, this is not a necessary condition. If a non-uniform grid were Upwinding


used, large cells with Pex > 2 could be placed towards the left hand side
of the domain (where d φ /dx is small) without having an adverse effect on
◮ A similar set of solutions can be generated using the first order upwind
the solution.
scheme (a backward difference) for approximating the convective terms.
◮ Generally, the centred convection scheme will produce under and ◮ The discretized equation is then
overshoots when the cell Peclet number is large and the solution has
φi − φi−1 φ − 2φi + φi−1
   
steep gradients.
ρU = Γ i+1 (44)
(What exactly is large, or steep, can be problem-dependent). ∆x ∆x 2

◮ Rearranging leads to
ρU Γ ρU Γ
     

φi−1 − − + φi + + φi+1 − 2 = 0 (45)
∆x ∆x 2 ∆x ∆x 2 ∆x
and introducing the cell Peclet number, Pex , results in
φi−1 (1 + Pex ) + φi+1
φi = (46)
2 + Pex

◮ The results of solving these equations on the same grids as those used
earlier for the central difference scheme are also shown in the graphs.
Finite Difference Schemes 2010/11 27 / 35 Finite Difference Schemes 2010/11 28 / 35
◮ As might be expected, once the grid is reasonably fine (Pex not too large) Numerical Diffusion
the first order upwind solution is not as accurate as the second order
central difference one. ◮ As seen in the above example, the first order upwind scheme always
returns a bounded solution. However, it is not particularly accurate.
◮ However, the upwind solution is always bounded.
◮ The Taylor series expansions examined earlier show that
◮ Whereas the central difference gives under/overshoots when the cell
Peclet number is large, the upwind scheme does not. Instead, it appears φi − φi−1 ∆x ′′ ∆x 2 ′′′
to underestimate the gradients in φ . = φi′ − φ + φ + O(∆x 3) (47)
∆x 2! i 3! i
φi−1 − 2φi + φi+1 2∆x 2 ′′′′
= φi′′ + φ + O(∆x 4) (48)
∆x 2 4! i

◮ Hence the differential equation actually being solved when using the first
order upwind scheme is

d φ ∆x d 2 φ ∆x 2 d 3 φ d φ 2∆x 2 d 4 φ
   2 
ρU − + =Γ + + O(∆x 4 ) (49)
dx 2! dx 2 3! dx 3 dx 2 4! dx 4

Finite Difference Schemes 2010/11 29 / 35 Finite Difference Schemes 2010/11 30 / 35

◮ If we retain only leading order error terms, this can be written as Boundary Conditions
dφ ρ U∆x d 2 φ Pex d 2 φ
   
ρU = Γ+ = Γ 1+ (50) ◮ As in the example examined earlier, the form of the difference equation to
dx 2! dx 2 2! dx 2
be solved often has to be modified at the edges of the domain to account
for boundary conditions.
◮ The error introduced by the upwind scheme is seen to be equivalent to
increasing the diffusivity.
◮ Dirichlet boundary conditions (where the
◮ The error is thus referred to as diffusive, and generally acts to ”smear” the value of the variable is fixed) can usually
x1 x2 xn−1 x n
solution. This tends to exert a stabilizing influence on the numerical be implemented by simply setting the
solution, although as seen it has an adverse effect on accuracy. appropriate value at the boundary node.

◮ Terms involving this boundary node in the discretized equations at


neighbouring nodes can then be moved to the source term on the right
hand side, as was done in the example earlier. The values of φ to be
solved for are then φ2 , φ3 ,. . . ,φn−1 .

◮ If high order schemes with computational stencils covering more than


three points are used, it may be necessary to modify these at the
near-boundary nodes (to avoid referencing non-existent nodes).
Finite Difference Schemes 2010/11 31 / 35 Finite Difference Schemes 2010/11 32 / 35
◮ Neumann boundary conditions (the gradient of φ being prescribed) can Extension to Multiple Dimensions
be implemented by using a discretized form of the boundary condition.
◮ Suppose, for example, we have the condition d φ /dx = 0 at x = 0. ◮ Although the finite difference methods outlined have been presented in
terms of 1-D problems, the extension to 2 or 3 dimensions is fairly
◮ A first order one-sided difference would give
straightforward.
d φ φ − φ1

≈ 2 so φ1 = φ2 (51)
dx 1 ∆x ◮ If, for example, we discretize the 2-D Poisson
(i,j+1)
equation
◮ A quadratic fit through the boundary and two neighbouring points on
a uniform grid would give ∂ 2φ ∂ 2φ (i−1,j) (i,j) (i+1,j)
+ = f (x , y ) (53)
∂x2 ∂y2
d φ −3φ1 + 4φ2 − φ3

≈ so φ1 = (4/3)φ2 − (1/3)φ3 (52) (i,j−1)
dx 1 2∆x on a uniform grid as shown, using central
differences for the derivatives, we obtain
◮ Note the above expressions both use one-sided differences. Central
differences can sometimes be applied by adding ‘imaginary’ nodes φi−1,j − 2φi,j + φi+1.j φi,j−1 − 2φi,j + φi.j+1
+ = fi,j (54)
beyond the domain boundary (see problem sheet example). (∆x )2 (∆y )2

◮ These expressions can then be used to modify the discretized equation


at the near-boundary nodes.
Finite Difference Schemes 2010/11 33 / 35 Finite Difference Schemes 2010/11 34 / 35

◮ Note that we now have a five point stencil, with a


difference equation of the form N

ap φP = ae φE + aw φW + an φN + as φS + Su (55) W P E

where the subscripts P, E, W , N, S denote the


nodal positions and the coefficients and source S
term are:

2 2
ae = aw = 1/(∆x ) an = as = 1/(∆y )
ap = ae + aw + an + as Su = −fi,j

Finite Difference Schemes 2010/11 35 / 35

You might also like