0% found this document useful (0 votes)
44 views8 pages

Lecture 07.05.2024

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views8 pages

Lecture 07.05.2024

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

COMPUTATIONAL FLUID DYNAMICS: FDM: Multi-dimensional Derivatives

Lecture 14
MULTIDIMENSIONAL DERIVATIVES

14.1 MULTIDIMENSIONAL FINITE DIFFERENCE FORMULAE


Multidimensional finite difference formulae can be easily written using one dimensional
formulae. For example, the formulae for first order derivative using forward difference
scheme (FDS) are

 f  fi 1, jk  f ijk
    O  x  (14.1)
 x i , j , k x
 f  f  fijk
   i , j 1, k  O  y  (14.2)
 y i , j ,k y
 f  f i , j ,k 1  fijk
    O  z  (14.3)
 z i , j ,k z
Similarly, second order central difference formulae for the second order derivatives are:

 2 f  f i 1, jk  fi 1, jk  2 f ijk


 2    O  x 2  (14.4)
 x ijk  x 
2

 2 f  fi , j 1,k  fi , j 1,k  2 fijk


 2   O  y 2  (14.5)
  y 
2
 y ijk
 2 f  f i , j ,k 1  fi , j , k 1  2 f ijk
 2    O  z 2  (14.6)
 z ijk  z 
2

14.2 APPROXIMATION OF MIXED DERIVATIVES


In thermo-fluid problems, mixed derivatives are encountered in two situations: (a) heat
conduction in anisotropic medium, and (b) the transport equations expressed in non-
orthogonal coordinate systems. Mixed derivatives can be treated by combining one
dimensional approximation in the same way as described earlier for second order derivative.
For example, the mixed derivative  2 f / xy can be re-written as

2 f   f 
   (14.7)
xy x  y 

Using CDS for approximation of the outer derivative, we obtain

 f   f 
 y   
 2 f   i 1, j  y i 1, j
    O  x 2  (14.8)
 xy i , j 2x

14.1
COMPUTATIONAL FLUID DYNAMICS: FDM: Multi-dimensional Derivatives

We can also use CDS for approximation of f / y , i.e.

 f  f  f  f
 i 1, j 1 i 1, j 1  O  y 2  ,    i 1, j 1 i 1, j 1  O  y 2 
f f
  (14.9)
 y i 1, j 2 y  y i 1, j 2 y

Combining Eq. (14.8) and Eq. (14.9), we get

 2 f  fi 1, j 1  fi 1, j 1  fi 1, j 1  fi 1, j 1


    O  x 2 , y 2  (14.10)
 xy i , j 4xy

14.3 IMPLEMENTATION OF BOUNDARY CONDITIONS


Numerical solution of a partial differential equation (PDE) using FDM requires finite
difference approximation of the PDE at every interior grid point. Further, boundary
conditions specified on the domain boundaries must be imposed to obtain a unique solution
of the continuum problem. The boundary conditions of the Dirichlet-type (i.e. specified value
of the variable) can be incorporated directly. However, the boundary conditions which
involve the gradient of a variable would require the use of one sided difference formulae
(forward or backward, depending on the location of the boundary node) for approximation of
derivatives at the boundary. For example, at the boundary node x1 the simplest approximation
of the derivative is given by the forward difference scheme

 f  f 2  f1
   (14.11)
 x 1 x2  x1

which is first order accurate. For more accurate approximation, we can use higher order one-
sided difference formulae involving function values at the boundary node and interior grid
points. For instance, use of quadratic polynomial fit involving function values at boundary
point x1 and interior nodes x2 and x3 leads to the following second order approximation
(Ferziger and Peric, 2003):

 f  ( x2  x1 ) f 3  ( x3  x1 ) f 2  ( x3  x1 )  ( x2  x1 )  f1
2 2 2 2

   (14.12)
 x 1 ( x2  x1 )( x3  x1 )( x3  x2 )

On a uniform grid, the preceding approximation reduces to

 f  3  42  31


   (14.13)
 x i 2x

One-sided difference formulae (14.11)-(14.13) would also be useful in post processing, e.g.
in evaluation of heat flux from computed temperature field.

14.2
COMPUTATIONAL FLUID DYNAMICS: FDM: Multi-dimensional Derivatives

14.4 FINITE DIFFERENCE DISCRETE ALGEBRAIC SYSTEM


Finite difference approximation of derivatives in a partial differential equation (PDE) leads to
an algebraic equation at each node in terms of the variable values at the node and its
neighbouring nodes. This equation is linear for a linear PDE, and non-linear for non-linear
PDEs. In the latter case, the non-linear equation would require linearization in the process of
its numerical solution. This quasi-linear equation obtained from the finite difference
discretization of a PDE of a generic scalar  at a grid point can be represented as (Ferziger
and Peric, 2003)
APP   All  QP (14.14)
l
where index P represents the node at which the PDE is approximated and l denotes the
neighbouring node involved in finite difference approximation. Coefficients Al and AP are
functions of grid size and material properties. The node P and its neighbours form the so-
called computational molecule (or stencil). In the finite difference and the finite volume
methods, compass notation is usually employed, i.e. for a node  i, j  , node  i  1, j  is
denoted by E (eastern neighbour), node  i, j 1 is denoted by S (southern neighbour), and so
on. Figure 9.5 depicts the computational molecules in 1D and 2D.

W P E
Figure 9.5 Central difference computational molecules (1D and 2D)

Collection of algebraic equation (14.14) at all the computational nodes leads to a system of
algebraic equations given by
AΦ  Q (14.15)
where A is the coefficient matrix, Φ is the vector of unknown nodal values of  and Q is the
vector containing terms on RHS of Eq. (14.14). Matrix A is sparse. However, its structure
depends on ordering of variables in vector Φ.

For structured grids, variables are usually ordered starting from a corner and
traversing line after-line in a regular manner. This ordering scheme is called lexicographic
ordering and results in a poly-diagonal structure for matrix A. Note that this ordering is not
unique as it depends on the order of line traversal in different directions. For example, if we
start ordering the entries in vector Φ starting from southwest corner of the domain, proceed
eastward along each grid line, and then northward across the domain, we get the ordering of
indices as given in Table 14.1.

14.3
COMPUTATIONAL FLUID DYNAMICS: FDM: Multi-dimensional Derivatives

Table 14.1 Conversion of  i, j, k  grid indices to one dimensional storage locations in vector
Φ.

Grid location Compass notation Storage location


i, j , k P l   k 1 Ni N j   j 1 Ni  1
i  1, j , k W l 1
i  1, j , k E l 1
i, j  1, k S l  Ni
i, j  1, k N l  Ni
i, j , k  1 B l  Ni N j
i, j , k  1 T l  Ni N j

Because matrix A is sparse and has a poly-diagonal structure for structured grids, it is
preferable to store it as a set of one dimensional arrays instead of a full two-dimensional
array. We can use the directional connection in naming these 1D arrays (calling them as
AP , AW etc.), and thus write the algebraic equation (14.14) for a two dimensional problem as
AWW  ASS  APP  ANN  QP (14.16)

At present, most of the programming languages (including Fortran 90) support user-
defined data types. An alternative storage scheme for matrix A can be adopted using records
or structure data types wherein the matrix A is stored as an array of records (or struct). Each
element of this record contains the number of modes connected to a given node, nodal
connectivity (i.e. indices of neighbouring nodes) and corresponding matrix entries. This
scheme can be used not only for the system matrix arising from finite difference
discretization on structured grids, but also for the matrix resulting from finite volume/finite
element method on structured as well as unstructured grids. A sample implementation of
such a record in C is as follows:

struct Matrix
{
int nn; // number of neighbours of the node
double AP; // matrix entry AP
double *AL; // array to hold coefficients Al
int *nc; // array to hold connectivity information
}

On structured grids, we can omit storage of connectivity information by adopting an implicit


indexing for neighbouring nodes.

Note that the indexing scheme described above is primarily required if one plans to
use a direct solver which require specification of an algebraic system in the standard form Ax
= b. In practical CFD applications, large size of the system matrix normally dictates use of
iterative solvers (even for linear systems).

REFERENCE
Ferziger, J. H. And Perić, M. (2003). Computational Methods for Fluid Dynamics. Springer.

14.4
COMPUTATIONAL FLUID DYNAMICS: FDM: Applications to Scalar Transport Problems

Lecture 15
APPLICATIONS OF FDM TO SCALAR TRANSPORT
PROBLEMS

15.1 ONE DIMENSIONAL HEAT CONDUCTION


Let us consider steady state heat conduction in a slab of width L with thermal conductivity k
and heat generation qg . The governing equation for this problem is
 2T
k  qg  0 (15.1)
x 2
Suppose that the left end of the slab is maintained at constant temperature and the right end of
the slab is losing heat by convection to surroundings. Thus, boundary conditions are

T  0  T (15.2)
dT
k  h T  Ta  (15.3)
dx x L

where T is specified temperature, h is convection heat transfer coefficient and Ta is ambient


temperature.

For finite difference formulation, let us use a uniform grid of size x  L / N where N
denotes the number of divisions in the grid. Thus, there are (N+1) grid points. Using CDS for
approximation of the second order derivative, discretized form of Eq. (15.1) at an internal
node x  xi becomes
Ti 1  Ti 1  2Ti qg ,i q g , i x 2
 0 or  Ti 1  2Ti  Ti 1  (15. 4)
x 2 k k

Using the matrix notation introduced in the previous section, the preceding equation can be
written as

APi TP  AWi Ti 1  AEi Ti 1  Qi (i  2,3,.., N ) (15.5)

where AP  2, AW  AE  1, and Qi  qgi x / k.


i i i 2

At the left boundary node (i  1), T1  T  0  T . Hence, AP1  1, AW


1
 AE1  0, and
Q1  Ta . At the right boundary node (i  N  1) , use of a backward difference approximation
(say, first order BDS) yields

TN 1  TN k  k 
k  h TN 1  Ta  i.e.  TN  1   TN 1  Ta (15.6)
x hx  hx 

Thus, APN 1  1  k / ( hx), AEN 1  0, AWN 1   k / ( hx) and QN  Ta . The linear algebraic
system obtained for this problem is tri-diagonal and can be easily solved using TDMA (tri-
diagonal matrix algorithm) discussed in a later section.

15.1
COMPUTATIONAL FLUID DYNAMICS: FDM: Applications to Scalar Transport Problems

15.2 TWO DIMENSIONAL HEAT CONDUCTION


Steady state heat conduction in a two dimensional domain without heat source or sink is
governed by Laplace equation

 2T  2T
 0 (15.7)
x 2 y 2

Governing equation (15.7) involves second order derivatives which can be approximated
using central difference scheme. Associated boundary conditions may involve first order
derivatives (in case Neumann or convective boundary conditions), which would require the
use of one-sided difference formula.

Using of central difference scheme based on a five point computational molecule


yields the following discretized form of Eq. (15.7):

Ti 1, j  Ti 1, j  2Tij Ti , j 1  Ti , j 1  2Tij


 0 (15.8)
x 2
y 2

which can be rewritten as

APTP  AETE  AWTW  ANTN  ASTS  QP (15.9)

where AP  2 / x 2  2 / y 2 , AE  AW  1/ x 2 , AN  AS  1 / y 2 and QP  0. Discretized


equations for boundary nodes can be written using the approach used in 1-D heat conduction
problem discussed earlier. The resulting linear algebraic system is penta-diagonal, and can be
solved using a suitable direct solver (e.g. Gaussian elimination) or an iterative solver (SOR,
conjugate gradient etc.).

15.3 ONE DIMENSIONAL ADVECTION-DIFFUSION


One dimensional advection-diffusion problem for a scalar variable  is governed by
d
  u    
d d
(15.10)
dx dx  dx 

where u is specified velocity, ρ is density, and  is diffusivity. Suppose values of  are


specified at both ends of the domain of length L, i.e. the boundary conditions are
  0  0 and   L   L (15.11)

Let us employ a non-uniform grid with a total of N+1 grid points (nodes 1 and N+1
represent the boundary nodes x  0 and x  L respectively) for finite difference solution of
this problem. We can discretize Eq. (15.10) using finite difference scheme based on a there
point computational molecule. The resulting discretized equation for an interior node i can be
represented as

APi P  AWi i 1  Ei Ti 1  Qi (i  2,3,.., N ) (15.12)

15.2
COMPUTATIONAL FLUID DYNAMICS: FDM: Applications to Scalar Transport Problems

where coefficients A contain contributions from both the convective and diffusive terms, i.e.
A  Ad  Ac (in which superscripts d and c indicate contribution from diffusive and
convective terms respectively).

Central difference scheme (CDS) is commonly used for approximation of the diffusive term
(for inner as well as the outer derivative). Thus,

 d   d  i 1  i i  i 1
    i  1  i  1
d  d   dx i  1  dx i  1 2 xi 1  xi 2 x  x
  2 2
 i i 1
(15.13)
dx  dx  i 1
( xi 1  xi 1 )
1
( xi 1  xi 1 )
2 2

Therefore, contributions of the diffusive term to the coefficients of algebraic equation (15.12)
are
2 i  1 2 i  1
AEd  2
, AWd  2
, APd    AEd  AWd  (15.14)
 xi 1  xi 1  xi 1  xi   xi 1  xi 1  xi  xi 1 
If the convection term is also discretized using CDS, then
d  (  u )i 1  (  u )i 1
 dx   u    xi 1  xi 1
(15.15)
i
and its contributions to the coefficients of Eq. (15.12) are
(  u )i 1 (  u )i 1
AEc  , AWc   , APc  0 (15.26)
xi 1  xi 1 xi 1  xi 1
Use of CDS for convective term can result in spurious wiggles or oscillations in numerical
solution if the local Peclet number, Pe (   u x / )  2. To reduce/eliminate these
oscillations, upwind difference is usually employed for convective term. However, first order
upwind scheme (based on FDS/BDS) is highly diffusive. Hence, higher order TVD (total
variation diminishing schemes) should be preferred for discretization of the convective terms
(Versteeg and Malalasekera, 2007; Chung, 2010).

Example 15.1
Consider the steady state heat conduction in a slab of width l = 0.5 m with heat generation.
The left end of the slab (x = 0) is maintained at T = 373 K. The right end of the slab (x = 0.5
m) is being heated by a heater for which the heat flux is 1 kW/m2. The heat generation in the
slab is temperature dependent and is given by Q = (1273 – T) W/m3. Thermal conductivity is
constant at k = 1 W/(m-K).Write down the governing equation and boundary conditions for
the problem. Use the finite difference method (central difference scheme) to obtain an
approximate numerical solution of the problem. For the first order derivative, use forward or
backward difference approximation of first order. Choose Δx = 0.1, and use the TDMA.
Solution
Governing equation for the steady state heat conduction with constant heat generation:
d 2T
k 2 Q 0 (i)
dx
Given: Q = 1273 – T. Thus, Eq. (i) becomes
d 2T
k 2  T  1273 (ii)
dx

15.3
COMPUTATIONAL FLUID DYNAMICS: FDM: Applications to Scalar Transport Problems

Left end of the slab is maintained at constant temperature; hence


T (0)  373 (iii)
At the right end, heat influx is specified. Thus, boundary condition at this end is
dT
k  1000 (iv)
dx
Using central difference scheme, the discretized form of (ii) at an internal node x = xi can be
expressed as
Ti 1  Ti 1  2Ti
 Ti  1273 (v)
x 2
Using given values of k = 1 and Δx = 0.1, the preceding equation simplifies to

Ti 1  2.01Ti  Ti 1  12.73, i  2,3,4,5 (vi)


Hence, the coefficients in the standard equation AWi Ti 1  APi Ti  AEi Ti 1  bi are:
AWi
 1, APi
 2.01, AEi
 1, bi  12.73, i  2,3, 4,5 (vii)
Temperature boundary condition (iii) at the first node implies
T1  373, i.e. AW1  0, AP1  1, AE1  0, b1  373 (viii)
Discretization of the flux boundary (iv) requires use of backward difference, which yields
T6  T5  100, i.e. AW6  1, AP6  1, AE6  0, b6  100 (ix)
Therefore, the discrete system obtained from finite difference discretization is

1 0 0 0 0 0  T1   373 
 1 2.01 1
 0 0 0  T2  12.73
0 1 2.01 1 0 0  T3  12.73
     
0 0 0
-1 2.01 1 0  T4  12.73 (x)
0 0 0 1 2.01 1 T5  12.73
    
 0 0 0 0 1 1  T6   100 

Numerical calculations using TDMA are given in the following table:

AWi AEi 1 * AWi bi*1 bi*  AEi Ti 1 Tex


AWi AEi APi  APi  b  b  Ti 
i APi bi APi 1
i i
APi 1 APi

1 0 1.00 0 373 1 373 373.0000 373.00


2 -1 2.01 -1 12.73 2.01 385.73 497.2893 498.95
3 -1 2.01 -1 12.73 1.512487 204.6355 613.8216 617.18
4 -1 2.01 -1 12.73 1.34883754 148.02734 723.7617 728.85
5 -1 2.01 -1 12.73 1.26862087 122.47438 828.2096 835.08
6 -1 1.00 0 100 0.21174243 196.54136 928.2096 936.92

REFERENCES
Chung, T. J. (2010). Computational Fluid Dynamics. 2nd Ed., Cambridge University Press,
Cambridge, UK.

Versteeg, H. K. and Malalasekera, W. M. G. (2007). Introduction to Computational Fluid


Dynamics: The Finite Volume Method. Second Edition (Indian Reprint) Pearson Education.

15.4

You might also like