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

Computational Fluid Dynamics for Incompressible Flows

Professor. Amaresh Dalal


Department of Mechanical Engineering
Indian Institute of Technology, Guwahati

Lecture 3
Finite difference in non-uniform grid

Hello, everyone, so today we will study Finite Difference in Non-Uniform Grid. So in earlier
lectures we used uniform grid, and we used finite difference approximation of derivatives.
But today we will use the non-uniform grid and we will write the finite difference
approximation of derivatives.

(Refer Slide Time: 00:59)

First let us write the finite difference approximation of first derivative, in uniform rate using
forward differencing approximation:
𝜕𝑓 𝑓𝑖+1 − 𝑓𝑖
= + 𝑂(∆𝑥)
𝜕𝑥 ∆𝑥
So, here you can see that the truncation error not only depends on the step size delta x, but
also on the derivative. So, obviously, you can see that if you have the flow variations in a
domain, then the gradient will be different at different places, and you will not get uniform
error. Hence, we need to use non-uniform grid, so we will use smaller delta x, where you
have larger gradients in the domain and we will use higher delta x where you have smooth
gradient in the region.
To have uniform error in any domain, you can use very small Δx where you have larger
gradients which eventually means using very fine mesh where you have large gradients and
vice versa.

So, this is known as non-uniform grid, so you are using smaller Δx where you have larger
gradients in the domain and you are using larger Δx, where you have smaller gradient in the
domain so as to get a uniform error in the domain.

So, to use it now, you can see there are many examples in the flow physics, where you can
see that near to the solid region obviously, we have higher flow gradients. Say velocity
gradient will be more. So, consider flow over flat plate, it is in undergraduate fluid mechanics
course it is a you have learned this problem flow over flat plate and what is the boundary
layer edge of the boundary layer will go like this.

So, you can see that what is the variation of the velocity? So, if you have a uniform velocity,
free stream velocity. So, obviously outside this boundary layer edge you will have the U
infinity, so, there will be no variation in the velocity outside, but inside this boundary layer
edge velocity is changing, so, you have more gradients of velocity.

If you find that del U by del x it will be more, in two different places you can see that inside
the, into different x location, x 1 and x 2 inside the boundary layer you have more gradient of
velocity. So, obviously near to the solid region, you need to use more finer mesh that means
smaller delta x. So, that you can capture accurately this flow gradients.

There are many other examples, so flow over a wing, flow over aerofoil, flow over aerofoil,
you can see. So, obviously there will be boundary layer development on this surface and you
can use very finer mesh near to the region, solid region.

Now, so, let us see how we can generate non-uniform grid first. So, you have this region, x
equal to 0 and x equal to L, we want to generate finer mesh, let us say near to the x equal to 0
region and coarse mesh where delta x is larger near to the x equal to L region. So, if you find,
so obviously there will be more gradients and gradually it will vary.

So, you can see it gradually it is varying. So, these are the grid points. So, this is your i is
equal to 1 and this is your I is equal to M I . In simple way you can find x i at any point i by L
is equal to i minus 1 divided by M I minus 1 to the power n, you can use this relation to
generate non-uniform grid. So, for n greater than 1, finer mesh you will get near x equal to 0,
and n less than 1 you will get finer mesh near x equal to L, so this way you can generate.

(Refer Slide Time: 09:04)

This is another method. Refer to the domain shown above where we want to generate finer
mesh near x = 0 and x = L. There are 2 solid boundaries at x = 0 and x=L.

For this we can use the expression ;


𝐿⁄
∆𝜂1 = 2
𝐴
where, L is the total length of the x direction and A is given by;

𝑅 𝑁𝐶𝐴𝐿−1 − 1 𝑅 𝑁𝐶𝐴𝐿−1
𝐴=[ + ]
𝑅−1 2
𝑁𝐼 − 1
𝑁𝐶𝐴𝐿 =
2
where R is your expansion factor, expansion factor for grid step length. So, here generally for
this expansion factor R you can use 1 to 1.2
(Refer Slide Time: 12:17)

Now we will discuss about the guidelines of non-uniform grid. So, you can see the errors due
to the grid non uniformity will be minimized for smoothly varying grids defined in such a
way that the size variation between the consecutive cells is of second order of the grid size.
∆𝑥𝑖+1 − ∆𝑥𝑖 = 𝑂(∆𝑥𝑖 )2

The errors are also proportional to some derivative, so the impact of the errors due to the grid
non-uniformity will depend on the local flow properties that we have already discussed. So,
when you are generating non-uniform grid please take care about these points, avoid
discontinuities in grid size of adjacent cells. So, it should progressively increase or decrease,
you should not have a abrupt change in the grid size.

Always use laws for the grid size variation defined by analytical, continuous function of the
associated coordinates to minimize numerical errors. And pay particular attention to the grid
smoothness and grid density in the region of strong flow variations. So, it may not be only
near to the solid region that you have very high gradients of the flow, but in some other
regions also it may be there due to its flow physics, so that you have to identify and generate
the non-uniform grid accordingly.
(Refer Slide Time: 14:13)

So, now let us consider a non-uniform grid

𝑓𝑖+1 = 𝑓(𝑥 + ∆𝑥𝑖+1 )


Using Taylor series expansion to expand the functions:

𝜕𝑓 (∆𝑥𝑖+1 )2 𝜕 2 𝑓 (∆𝑥𝑖+1 )3 𝜕 3 𝑓
𝑓𝑖+1 = 𝑓𝑖 + ∆𝑥𝑖+1 + + +⋯
𝜕𝑥 2! 𝜕𝑥 2 3! 𝜕𝑥 3
𝜕𝑓 2
(∆𝑥𝑖 )2 𝜕 2 𝑓 3
(∆𝑥𝑖 )3 𝜕 3 𝑓
𝑓𝑖+1 = 𝑓𝑖 + 𝑅∆𝑥𝑖 +𝑅 +𝑅 +⋯
𝜕𝑥 2! 𝜕𝑥 2 3! 𝜕𝑥 3
Similarly we can write:

𝑓𝑖+1 = 𝑓(𝑥 − ∆𝑥𝑖+1 )


𝜕𝑓 (∆𝑥𝑖+1 )2 𝜕 2 𝑓 (∆𝑥𝑖+1 )3 𝜕 3 𝑓
𝑓𝑖−1 = 𝑓𝑖 − ∆𝑥𝑖+1 + − +⋯
𝜕𝑥 2! 𝜕𝑥 2 3! 𝜕𝑥 3
Forward differencing:
𝜕𝑓 𝑓𝑖+1 − 𝑓𝑖
= + 𝑂(∆𝑥𝑖+1 ) … … … … … … … (𝐩)
𝜕𝑥 ∆𝑥𝑖+1
Backward differencing:
𝜕𝑓 𝑓𝑖 − 𝑓𝑖−1
= + 𝑂(∆𝑥𝑖 ) … … … … … … … (𝐪)
𝜕𝑥 ∆𝑥𝑖
Central differencing by performing (p) - (q) :

𝜕𝑓 𝑓𝑖+1 − 𝑓𝑖−1 (∆𝑥𝑖+1 )2 − (∆𝑥𝑖 )2 𝜕 2 𝑓


= + +⋯
𝜕𝑥 ∆𝑥𝑖+1 + ∆𝑥𝑖 2(∆𝑥𝑖+1 + ∆𝑥𝑖 ) 𝜕𝑥 2
𝜕𝑓 𝑓𝑖+1 − 𝑓𝑖−1
= + 𝑂[(𝑅 − 1)∆𝑥𝑖 ]
𝜕𝑥 (𝑅 + 1)∆𝑥𝑖
We can see that if we put R=1,we will the formulae for uniform grid.
(Refer Slide Time: 23:00)

𝜕𝑓 (∆𝑥𝑖 )2 𝜕 2 𝑓 (∆𝑥𝑖 )3 𝜕 3 𝑓
𝑓𝑖+1 = 𝑓𝑖 + 𝑅∆𝑥𝑖 + 𝑅2 + 𝑅 3
+⋯ (𝟏)
𝜕𝑥 2! 𝜕𝑥 2 3! 𝜕𝑥 3
𝜕𝑓 (∆𝑥𝑖+1 )2 𝜕 2 𝑓 (∆𝑥𝑖+1 )3 𝜕 3 𝑓
𝑓𝑖−1 = 𝑓𝑖 − ∆𝑥𝑖+1 + − +⋯ (𝟐)
𝜕𝑥 2! 𝜕𝑥 2 3! 𝜕𝑥 3
Performing the operation (1)-R2*(2):

2
𝜕𝑓 (∆𝑥𝑖 )3 𝜕 3 𝑓
𝑓𝑖+1 − 𝑅 𝑓𝑖−1 = (1 − 𝑅 2 )𝑓𝑖 + (𝑅 + 𝑅 2 )∆𝑥𝑖 + (𝑅 3
+𝑅 2)
+⋯
𝜕𝑥 3! 𝜕𝑥 3
𝜕𝑓 𝑓𝑖+1 − (1 − 𝑅 2 )𝑓𝑖 − 𝑅 2 𝑓𝑖−1 (𝑅 3 + 𝑅 2 ) (∆𝑥𝑖 )2 𝜕 3 𝑓
| = − +⋯
𝜕𝑥 𝑖 𝑅(1 + 𝑅)∆𝑥𝑖 𝑅(1 + 𝑅) 3! 𝜕𝑥 3
So, you can see that with these finite difference approximation you will get the second order
accurate approximation.
(Refer Slide Time: 29:37)

Let us consider polynomial approximation method to find out the 1st and 2nd order derivative
using 3 points.
Considering a 2nd order polynomial:

𝑓(𝑥) = 𝐴𝑥 2 + 𝐵𝑥 + 𝐶
𝑥𝑖 = 0(𝑠𝑎𝑦) ; 𝑥𝑖−1 = −∆𝑥𝑖 ; 𝑥𝑖+1 = 𝑅∆𝑥𝑖

𝑓𝑖 = 𝐴𝑥 2 𝑖 + 𝐵𝑥𝑖 + 𝐶 => 0 + 0 + 𝐶 => 𝐶 = 𝑓𝑖

𝑓𝑖+1 = 𝐴𝑥 2 𝑖+1 + 𝐵𝑥𝑖+1 + 𝐶 = 𝐴(𝑅∆𝑥𝑖 )2 + 𝐵(𝑅∆𝑥𝑖 ) + 𝑓𝑖 => 𝑓𝑖+1 − 𝑓𝑖 = 𝐴(𝑅∆𝑥𝑖 )2 + 𝐵(𝑅∆𝑥𝑖 )________(𝐦)

𝑓𝑖−1 = 𝐴𝑥 2 𝑖−1 + 𝐵𝑥𝑖−1 + 𝐶 = 𝐴(𝑅∆𝑥𝑖 )2 − 𝐵(𝑅∆𝑥𝑖 ) + 𝑓𝑖 => 𝑓𝑖−1 − 𝑓𝑖 = 𝐴(∆𝑥)2 − 𝐵(∆𝑥)_____(𝐧)

Performing the operation (𝐦) + (𝐧) :

𝑓𝑖+1 − (𝑅 + 1)𝑓𝑖 + 𝑅𝑓𝑖−1 𝑓𝑖+1 + (𝑅 2 − 1)𝑓𝑖 − 𝑅 2 𝑓𝑖−1


𝐴= ; 𝐵=
𝑅(1 + 𝑅)(∆𝑥𝑖 )2 𝑅(1 + 𝑅)∆𝑥𝑖
Substituting the values of the coefficients :

𝑓(𝑥) = 𝐴𝑥 2 + 𝐵𝑥 + 𝐶

𝜕𝑓 𝑓𝑖+1 + (𝑅 2 − 1)𝑓𝑖 − 𝑅 2 𝑓𝑖−1


| = 2𝐴𝑥 + 𝐵 = 0 + 𝐵 = 𝐵 =
𝜕𝑥 𝑖 𝑅(1 + 𝑅)∆𝑥𝑖
𝜕 2𝑓 𝑓𝑖+1 − (𝑅 + 1)𝑓𝑖 + 𝑅𝑓𝑖−1
| = 2𝐴 =
𝜕𝑥 2 𝑖 𝑅(1 + 𝑅)
(∆𝑥𝑖 )2
2

Now, let us use 3 forward points and find the finite difference approximation using non-
uniform grid and using this polynomial method.

(Refer Slide Time: 35:31)

Considering a 2nd order polynomial:

𝑓(𝑥) = 𝐴𝑥 2 + 𝐵𝑥 + 𝐶
𝑥𝑖 = 0(𝑠𝑎𝑦) ; 𝑥𝑖+1 = ∆𝑥𝑖 ; 𝑥𝑖+2 = (1 + 𝑅)∆𝑥𝑖

𝑓𝑖 = 𝐴𝑥 2 𝑖 + 𝐵𝑥𝑖 + 𝐶 => 0 + 0 + 𝐶 => 𝐶 = 𝑓𝑖


𝑓𝑖+1 = 𝐴𝑥 2 𝑖+1 + 𝐵𝑥𝑖+1 + 𝐶 = 𝐴(∆𝑥𝑖 )2 + 𝐵(∆𝑥𝑖 ) + 𝑓𝑖 => 𝑓𝑖+1 − 𝑓𝑖 = 𝐴(∆𝑥𝑖 )2 + 𝐵(∆𝑥𝑖 )________(𝐠)
2
𝑓𝑖+2 = 𝐴𝑥 2 𝑖+2 + 𝐵𝑥𝑖+2 + 𝐶 = 𝐴((1 + 𝑅)∆𝑥𝑖 ) − 𝐵((1 + 𝑅)∆𝑥𝑖 ) + 𝑓𝑖
2
=> 𝑓𝑖+2 − 𝑓𝑖 = 𝐴((1 + 𝑅)∆𝑥𝑖 ) − 𝐵((1 + 𝑅)∆𝑥𝑖 )_____(𝐡)

(Refer Slide Time: 45:05)


Performing the operation (1 + 𝑅 2 ) ∗ (𝐠) − (𝐡) :

−𝑓𝑖+2 + (1 − 𝑅 2 )𝑓𝑖+1 − 𝑅(2 + 𝑅)𝑓𝑖


𝐵=
𝑅(1 + 𝑅)∆𝑥𝑖

Performing the operation (𝐡) − (1 + R) ∗ (𝒈):


𝑓𝑖+2 − (𝑅 + 1)𝑓𝑖+1 + 𝑅𝑓𝑖
𝐴=
𝑅(1 + 𝑅)(∆𝑥𝑖 )2
Substituting the values of the coefficients :

𝑓(𝑥) = 𝐴𝑥 2 + 𝐵𝑥 + 𝐶

𝜕𝑓 −𝑓𝑖+2 + (1 − 𝑅 2 )𝑓𝑖+1 − 𝑅(2 + 𝑅)𝑓𝑖


| = 2𝐴𝑥 + 𝐵 = 0 + 𝐵 = 𝐵 = 𝐵 =
𝜕𝑥 𝑖 𝑅(1 + 𝑅)∆𝑥𝑖

𝜕 2𝑓 𝑓𝑖+2 − (𝑅 + 1)𝑓𝑖+1 + 𝑅𝑓𝑖


| = 2𝐴 =
2
𝜕𝑥 𝑖 𝑅(1 + 𝑅)
(∆𝑥𝑖 )2
2
The first order is second order accurate while the second derivative is first order accurate.

You might also like