Lecture 07.05.2024
Lecture 07.05.2024
Lecture 14
MULTIDIMENSIONAL DERIVATIVES
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
(14.7)
xy x y
f f
y
2 f i 1, j y i 1, j
O x 2 (14.8)
xy i , j 2x
14.1
COMPUTATIONAL FLUID DYNAMICS: FDM: Multi-dimensional Derivatives
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
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 )
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
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
Φ.
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
AWW ASS APP ANN 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
}
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
T 0 T (15.2)
dT
k h T Ta (15.3)
dx x L
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
TN 1 TN k k
k h TN 1 Ta i.e. TN 1 TN 1 Ta (15.6)
x hx hx
Thus, APN 1 1 k / ( hx), AEN 1 0, AWN 1 k / ( hx) 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
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.
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
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
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
REFERENCES
Chung, T. J. (2010). Computational Fluid Dynamics. 2nd Ed., Cambridge University Press,
Cambridge, UK.
15.4