34
Introduction to Computational Fluid Dynamics Lecture 4 Finite Difference Method. Introduction. One spatial variable parabolic equations 1 FINITE DIFFERENCES METHOD - part I Introduction (very short) Partial differential equations are widely used in mathematical modelling, many of them coming from different conservation law (particular properties of isolated physical system don’t change when the system evolves) Examples conservation of mass (the mass of a closed system remains constant) conservation of energy (the total amount of energy in an isolated system remains constant, first law of thermodynamics) conservation of linear momentum (the total momentum of a closed system, which has no interactions with external sources is constant) conservation of electric charge (the total electric charge of an isolated system remains constant)

Introduction to Computational Fluid Dynamicsmath.ubbcluj.ro/~tgrosan/2018IntroCFD_C4.pdf · 2018-10-31 · Introduction to Computational Fluid Dynamics Lecture 4 –Finite Difference

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introduction to Computational Fluid Dynamicsmath.ubbcluj.ro/~tgrosan/2018IntroCFD_C4.pdf · 2018-10-31 · Introduction to Computational Fluid Dynamics Lecture 4 –Finite Difference

Introduction to Computational Fluid Dynamics

Lecture 4 –Finite Difference Method. Introduction. One spatial variable parabolic equations 1

FINITE DIFFERENCES METHOD - part I

Introduction (very short)

Partial differential equations are widely used in mathematical modelling, many of them

coming from different conservation law (particular properties of isolated physical system

don’t change when the system evolves)

Examples

• conservation of mass (the mass of a closed system remains constant)

• conservation of energy (the total amount of energy in an isolated system remains

constant, first law of thermodynamics)

• conservation of linear momentum (the total momentum of a closed system, which has

no interactions with external sources – is constant)

• conservation of electric charge (the total electric charge of an isolated system remains

constant)

Page 2: Introduction to Computational Fluid Dynamicsmath.ubbcluj.ro/~tgrosan/2018IntroCFD_C4.pdf · 2018-10-31 · Introduction to Computational Fluid Dynamics Lecture 4 –Finite Difference

Introduction to Computational Fluid Dynamics

Lecture 4 –Finite Difference Method. Introduction. One spatial variable parabolic equations 2

Consider the most general form for a 2D linear partial differential equation:

2

2

22

2

2

,,, R

Dyxyxgfu

y

ue

x

ud

y

uc

yx

ub

x

ua

where ,...,, cba are constants, and g a known function. PDE are classified by the main

part of the operator:

2

22

2

2

y

uc

yx

ub

x

ua

in elliptic, parabolic and hyperbolic.

Page 3: Introduction to Computational Fluid Dynamicsmath.ubbcluj.ro/~tgrosan/2018IntroCFD_C4.pdf · 2018-10-31 · Introduction to Computational Fluid Dynamics Lecture 4 –Finite Difference

Introduction to Computational Fluid Dynamics

Lecture 4 –Finite Difference Method. Introduction. One spatial variable parabolic equations 3

Elliptic: 042 acb

yxgAuy

u

x

u,

2

2

2

2

where 1,0 A .

Particular cases: Laplace ( 0A , 0g ), Poisson ( 0A , 0g )

Page 4: Introduction to Computational Fluid Dynamicsmath.ubbcluj.ro/~tgrosan/2018IntroCFD_C4.pdf · 2018-10-31 · Introduction to Computational Fluid Dynamics Lecture 4 –Finite Difference

Introduction to Computational Fluid Dynamics

Lecture 4 –Finite Difference Method. Introduction. One spatial variable parabolic equations 4

Helmholtz ( 1A , 0g )

Page 5: Introduction to Computational Fluid Dynamicsmath.ubbcluj.ro/~tgrosan/2018IntroCFD_C4.pdf · 2018-10-31 · Introduction to Computational Fluid Dynamics Lecture 4 –Finite Difference

Introduction to Computational Fluid Dynamics

Lecture 4 –Finite Difference Method. Introduction. One spatial variable parabolic equations 5

Parabolic: 042 acb

yxgy

u

x

u,

2

2

(diffusion or heat equation)

Page 6: Introduction to Computational Fluid Dynamicsmath.ubbcluj.ro/~tgrosan/2018IntroCFD_C4.pdf · 2018-10-31 · Introduction to Computational Fluid Dynamics Lecture 4 –Finite Difference

Introduction to Computational Fluid Dynamics

Lecture 4 –Finite Difference Method. Introduction. One spatial variable parabolic equations 6

Hyperbolic: 042 acb

yxgBuy

u

x

u,

2

2

2

2

(III.4)

where 0B or 1. ( 0B - wave equation, 1B - Klein-Gordon linear equation)

Different types of equations = Different numerical methods

A non-periodic solitary

wave traveling along x-axis

to the right with constant

speed v.

At t = 0 the wave is given

by the function f (x) of x,

at t=t0 by f (x−vt0),

etc.

Page 7: Introduction to Computational Fluid Dynamicsmath.ubbcluj.ro/~tgrosan/2018IntroCFD_C4.pdf · 2018-10-31 · Introduction to Computational Fluid Dynamics Lecture 4 –Finite Difference

Introduction to Computational Fluid Dynamics

Lecture 4 –Finite Difference Method. Introduction. One spatial variable parabolic equations 7

Parabolic equations (one spatial variable)

(K.W. Morton, D.F. Mayers, Numerical solution of PDE, 2nd ed, Cambridge University Press, New York, 2005)

Heat equation

10,0,2

2

xt

x

u

t

u

1,0,,0 0 xxuxu

0,01,0, ttutu

Analytic

1

sin,2

k

tkk xkeatxu

1

0

0 sin)(2 dxxkxuak

Difficulties: - infinite series, ka can be determined for some particular cases

Page 8: Introduction to Computational Fluid Dynamicsmath.ubbcluj.ro/~tgrosan/2018IntroCFD_C4.pdf · 2018-10-31 · Introduction to Computational Fluid Dynamics Lecture 4 –Finite Difference

Introduction to Computational Fluid Dynamics

Lecture 4 –Finite Difference Method. Introduction. One spatial variable parabolic equations 8

Explicit Scheme

Domain: ]1,0[],0[ ft divided in a mesh (grid)

Grid:

txni NnNitntxix ,...,1,0,,...,1,0,, ) (III.10)

Notation

nini txuU , (III.11)

t

(i,n)

x

t

(i+1, n)

(i, n-1)

x

Page 9: Introduction to Computational Fluid Dynamicsmath.ubbcluj.ro/~tgrosan/2018IntroCFD_C4.pdf · 2018-10-31 · Introduction to Computational Fluid Dynamics Lecture 4 –Finite Difference

Introduction to Computational Fluid Dynamics

Lecture 4 –Finite Difference Method. Introduction. One spatial variable parabolic equations 9

Derivatives approximation

t

txutxutx

t

u ninini

,,, 1

211

2

2 ,,2,,

x

txutxutxutx

x

u nininini

Using the derivatives approximations we get:

211

1 2

x

UUU

t

UU ni

ni

ni

ni

ni

(o)

or:

ni

ni

ni

ni

ni UUUUU 11

1 2 (o)

where

2x

t

.

Thus, we obtained an explicit method with finite differences.

Page 10: Introduction to Computational Fluid Dynamicsmath.ubbcluj.ro/~tgrosan/2018IntroCFD_C4.pdf · 2018-10-31 · Introduction to Computational Fluid Dynamics Lecture 4 –Finite Difference

Introduction to Computational Fluid Dynamics

Lecture 4 –Finite Difference Method. Introduction. One spatial variable parabolic equations 10

Using the BC:

1,...,2,1,00 xi NixuU

...,2,1,0,00 nUU nN

n

x

It is possible to march in time:

Example: For

1,2

1,1

2

1,0,

0

xx

xx

xu

the analytic solution is given by:

122

2

sin2

1sin

14,

k

tkexkkk

txu

Page 11: Introduction to Computational Fluid Dynamicsmath.ubbcluj.ro/~tgrosan/2018IntroCFD_C4.pdf · 2018-10-31 · Introduction to Computational Fluid Dynamics Lecture 4 –Finite Difference

Introduction to Computational Fluid Dynamics

Lecture 4 –Finite Difference Method. Introduction. One spatial variable parabolic equations 11

Matlab program

dt=0.0013; dx=0.05;

Nx=1/(dx)+1;

x=0:dx:1;

tf=0.1;

Nt=tf/dt;

Uo=zeros(Nx,1);

Un=zeros(Nx,1);

%initialization

for i=1:round(Nx/2)

Uo(i)=(i-1)*dx;

end

for i=round(Nx/2):Nx

Uo(i)=1-(i-1)*dx;

end

n=0;

while (n<Nt)

n=n+1;

for i=2:Nx-1

Un(i)=Uo(i)+…

dt/(dx*dx)*(Uo(i-1)-

2*Uo(i)+Uo(i+1));

end

Uo=Un;

end

plot(x,Uo,'.-r')

hold on

%analitical solution

U=HeatAnalytic(x,tf);

plot(x,U,'b')

function rez=HeatAnalytic(x,t)

rez=0;

for k=1:100

rez=rez+4/(k*pi)^2*sin(k*pi/2)*

sin(k*pi*x)*exp(-k^2*pi^2*t);

end

Page 12: Introduction to Computational Fluid Dynamicsmath.ubbcluj.ro/~tgrosan/2018IntroCFD_C4.pdf · 2018-10-31 · Introduction to Computational Fluid Dynamics Lecture 4 –Finite Difference

Introduction to Computational Fluid Dynamics

Lecture 4 –Finite Difference Method. Introduction. One spatial variable parabolic equations 12

0t 005.0t

05.0t 1.0t

Page 13: Introduction to Computational Fluid Dynamicsmath.ubbcluj.ro/~tgrosan/2018IntroCFD_C4.pdf · 2018-10-31 · Introduction to Computational Fluid Dynamics Lecture 4 –Finite Difference

Introduction to Computational Fluid Dynamics

Lecture 4 –Finite Difference Method. Introduction. One spatial variable parabolic equations 13

Truncation error

Notations:

- forward differences:

txutxxutxu

txuttxutxu

x

t

,,,

,,,

- backward differences:

txxutxutxu

ttxutxutxu

x

t

,,,

,,,

- central differences:

txxutxxutxu

ttxuttxutxu

x

t

,2

1,

2

1,

2

1,

2

1,,

txxutxutxxutxux ,,2,,2

Page 14: Introduction to Computational Fluid Dynamicsmath.ubbcluj.ro/~tgrosan/2018IntroCFD_C4.pdf · 2018-10-31 · Introduction to Computational Fluid Dynamics Lecture 4 –Finite Difference

Introduction to Computational Fluid Dynamics

Lecture 4 –Finite Difference Method. Introduction. One spatial variable parabolic equations 14

Using Taylor series we have:

...12

1,

...6

1

2

1,

422

32

xuxutxu

tutututxu

xxxxxxx

ttttttt

(*)

We define the truncation error for the scheme:

211

1 2

x

UUU

t

UU ni

ni

ni

ni

ni

the function

2,,

,x

txu

t

txutxT xt

We notice that the above relation is the difference between the left hand term and the right

hand term of the numerical scheme where niU is replaced by ni txu , and operator notation

is used.

Page 15: Introduction to Computational Fluid Dynamicsmath.ubbcluj.ro/~tgrosan/2018IntroCFD_C4.pdf · 2018-10-31 · Introduction to Computational Fluid Dynamics Lecture 4 –Finite Difference

Introduction to Computational Fluid Dynamics

Lecture 4 –Finite Difference Method. Introduction. One spatial variable parabolic equations 15

Using (*) we get:

...12

1

2

1...

12

1

2

1,

22

xutuxutuuutxT xxxxxttxxxxxttxxt

where the Taylor expansion of the form:

ttttxututxuttxu ttt ,,2

1,,

2

was used. We obtain:

xxxtttxtutxutxT xxxxxtt ,,,12

1,

2

1,

2

and if u and its derivatives are bounded ( xxxxxxxxtttt MuMu , ) then we have:

xxxxtt MMttxT

6

1

2

1, (**)

Page 16: Introduction to Computational Fluid Dynamicsmath.ubbcluj.ro/~tgrosan/2018IntroCFD_C4.pdf · 2018-10-31 · Introduction to Computational Fluid Dynamics Lecture 4 –Finite Difference

Introduction to Computational Fluid Dynamics

Lecture 4 –Finite Difference Method. Introduction. One spatial variable parabolic equations 16

It can be seen that 0, txT when 0, tx for every Fttx ,1,0, . We say that

the explicit scheme is unconditionally consistent and t appears at the power one that

the accuracy order is tO or the scheme is first order accurately.

The convergence of the explicit scheme

Suppose we obtain approximations of the exact solutions for the same initial data for

different grids ( 0t and 0x ) but with the same value for the parameter

2xt .

Will say that the scheme (o) is convergent if for every point Fttx ,01,0, **

** , ttxx ni involve ** , txuU ni

We introduce a superior limit for the truncation error:

TT ni

where nin

i txTT ,

Page 17: Introduction to Computational Fluid Dynamicsmath.ubbcluj.ro/~tgrosan/2018IntroCFD_C4.pdf · 2018-10-31 · Introduction to Computational Fluid Dynamics Lecture 4 –Finite Difference

Introduction to Computational Fluid Dynamics

Lecture 4 –Finite Difference Method. Introduction. One spatial variable parabolic equations 17

and the error

nini

ni txuUe ,

But niU is the approximative solution while ni txu , is the exact solution and using (o) we

get:

ni

ni

ni

ni

ni UUUUU 11

1 2

tTtxutxutxutxutxu nininininini ,,2,,, 111

and by subtraction we obtain:

tTeeeee ni

ni

ni

ni

ni

ni

111 2

or

tTeeee ni

ni

ni

ni

ni

111 21

Page 18: Introduction to Computational Fluid Dynamicsmath.ubbcluj.ro/~tgrosan/2018IntroCFD_C4.pdf · 2018-10-31 · Introduction to Computational Fluid Dynamics Lecture 4 –Finite Difference

Introduction to Computational Fluid Dynamics

Lecture 4 –Finite Difference Method. Introduction. One spatial variable parabolic equations 18

Supposing 2

1 and considering the maximum of the error for one time step,

xni

n NieE ,...,1,0,max , we have:

tTEtTEEEe nni

nnnni 211

where in the triangle inequality the modulus notation was dropped. Eq. takes place for

1,...,2,1 xNi and thus:

tTEE nn 1

From the initial condition we have 00 E and it is possible to demonstrate by

mathematical induction that tTnE n .

Using Eq. (**) and taking into account that the final time tntF we get:

06

1

2

1

Fxxxxtt

n tMMtE

when 0 t

Page 19: Introduction to Computational Fluid Dynamicsmath.ubbcluj.ro/~tgrosan/2018IntroCFD_C4.pdf · 2018-10-31 · Introduction to Computational Fluid Dynamics Lecture 4 –Finite Difference

Introduction to Computational Fluid Dynamics

Lecture 4 –Finite Difference Method. Introduction. One spatial variable parabolic equations 19

A refinement path is a sequence of pairs of mesh sizes, Δx and Δt, each of which tends to

zero:

0,0;...,,1,0,, jjjj txjtxMR

Theorem: If a refinement path satisfies

2

12

j

jj

x

t for all sufficiently large values of

j and the positive numbers jn and ji are such that:

0 ttn jj and 1,0 xti jj

and if xxxxxxxx Mu uniformly in Ft,01,0 then the approximations jn

iU

generated by the explicit difference scheme (o) for ...,2,1,0j converge to the

solution txu , of the differential equation uniformly in the region.

Page 20: Introduction to Computational Fluid Dynamicsmath.ubbcluj.ro/~tgrosan/2018IntroCFD_C4.pdf · 2018-10-31 · Introduction to Computational Fluid Dynamics Lecture 4 –Finite Difference

Introduction to Computational Fluid Dynamics

Lecture 4 –Finite Difference Method. Introduction. One spatial variable parabolic equations 20

Such a convergence theorem is the least that one can expect of a numerical scheme; it

shows that arbitrarily high accuracy can be attained by use of a sufficiently fine mesh. Of

course, it is also somewhat impractical. As the mesh becomes finer, more and more steps

of calculation are required, and the effect of rounding errors in the calculation would

become significant and would eventually completely swamp the truncation error.

Fourier analysis of the error

We have already expressed the exact solution of the heat equation as a Fourier series; this

expression is based on the observation that a particular set of Fourier modes are exact

solutions. In order to study the stability of the scheme (14) we consider the numerical

solution in a point xi at the time step n of the form:

xikInni eU

where 1I .

Page 21: Introduction to Computational Fluid Dynamicsmath.ubbcluj.ro/~tgrosan/2018IntroCFD_C4.pdf · 2018-10-31 · Introduction to Computational Fluid Dynamics Lecture 4 –Finite Difference

Introduction to Computational Fluid Dynamics

Lecture 4 –Finite Difference Method. Introduction. One spatial variable parabolic equations 21

Using this form in (o) and simplifying with xikIne we get:

xkxkeek xkIxkI

2

1sin41cos12121 2

where k is the amplification factor. By taking mk , as in the exact solution we can

therefore write our numerical approximation in the form

nximI

mni meAU

This equation gives a good approximation to the exact solution of the differential equation

given by the Fourier series of the exact solution for small values of m .

But ni

ni UU 1

In order to limit the truncation error propagation it is necessary that:

1

and thus, we obtain:

12

1sin411 2 xk for every point xk

Page 22: Introduction to Computational Fluid Dynamicsmath.ubbcluj.ro/~tgrosan/2018IntroCFD_C4.pdf · 2018-10-31 · Introduction to Computational Fluid Dynamics Lecture 4 –Finite Difference

Introduction to Computational Fluid Dynamics

Lecture 4 –Finite Difference Method. Introduction. One spatial variable parabolic equations 22

from where we have the condition: 2

12

x

t ()

The implicit scheme

Eq. () is a very severe restriction, and implies that very many time steps will be

necessary to follow the solution over a reasonably large time interval. If we need good

approximations we need small steps in space and the amount of work involved increases

very rapidly, since we shall also have to reduce the time step.

In order to avoid this we introduce the scheme

txni NnNitntxix ,...,1,0,,...,1,0,, )

2

11

111

1 2

x

UUU

t

UU ni

ni

ni

ni

ni

Page 23: Introduction to Computational Fluid Dynamicsmath.ubbcluj.ro/~tgrosan/2018IntroCFD_C4.pdf · 2018-10-31 · Introduction to Computational Fluid Dynamics Lecture 4 –Finite Difference

Introduction to Computational Fluid Dynamics

Lecture 4 –Finite Difference Method. Introduction. One spatial variable parabolic equations 23

It can be seen that in order to calculate the value of U at the time step 1nt it is necessary to

march in time starting from the initial condition

1,...,2,1,00 xi NixuU

and solving a tri-diagonal system of equations:

ni

ni

ni

ni UUUU

1

111

1 21 (oo)

along with with the boundary conditions

...,2,1,0,00 nUU n

N

n

x

In this case we say that the method is implicit and the form of the system is given by:

Page 24: Introduction to Computational Fluid Dynamicsmath.ubbcluj.ro/~tgrosan/2018IntroCFD_C4.pdf · 2018-10-31 · Introduction to Computational Fluid Dynamics Lecture 4 –Finite Difference

Introduction to Computational Fluid Dynamics

Lecture 4 –Finite Difference Method. Introduction. One spatial variable parabolic equations 24

)(

1

1

)1(

1

1

0

0

...

...

0

...

...

1

21

21

21

1n

Nx

i

n

Nx

Nx

i

U

U

U

U

U

U

U

U

The system can be solved using a known method (e.g. the Thomas algorithm).

We will apply the implicit scheme to the above example, and we will compare the result

with the explicit method and with the analytic solution.

Page 25: Introduction to Computational Fluid Dynamicsmath.ubbcluj.ro/~tgrosan/2018IntroCFD_C4.pdf · 2018-10-31 · Introduction to Computational Fluid Dynamics Lecture 4 –Finite Difference

Introduction to Computational Fluid Dynamics

Lecture 4 –Finite Difference Method. Introduction. One spatial variable parabolic equations 25

%Matlab progam:

dt=0.0013;dx=0.05;

niu=dt/(dx*dx);

Nx=1/(dx)+1;

x=0:dx:1;

tf=0.1;

Nt=tf/dt;

Uo=zeros(Nx,1); Un=zeros(Nx,1);

%initialization

for i=1:round(Nx/2)

Uo(i)=(i-1)*dx;

end

for i=round(Nx/2):Nx

Uo(i)=1-(i-1)*dx;

End

A=zeros(Nx,Nx);b=zeros(Nx,1);

n=0;

while (n<Nt)

n=n+1;

A(1,1)=1;b(1)=0;

for i=2:Nx-1

A(i,i-1)=-niu;

A(i,i)=1+2*niu;

A(i,i+1)=-niu;

b(i)=Uo(i);

end

A(Nx,Nx)=1;b(Nx)=0;

Un=A\b;

Uo=Un;

end

plot(x,Uo,'o:k')

hold on

Page 26: Introduction to Computational Fluid Dynamicsmath.ubbcluj.ro/~tgrosan/2018IntroCFD_C4.pdf · 2018-10-31 · Introduction to Computational Fluid Dynamics Lecture 4 –Finite Difference

Introduction to Computational Fluid Dynamics

Lecture 4 –Finite Difference Method. Introduction. One spatial variable parabolic equations 26

We used 0013.0t and 05.0 x , and the analytic solution (full line), the explicit

solution („”) and the implicit solution („o”) are given. We observe that the implicit

solution is stable.

05.0t 1.0t

Page 27: Introduction to Computational Fluid Dynamicsmath.ubbcluj.ro/~tgrosan/2018IntroCFD_C4.pdf · 2018-10-31 · Introduction to Computational Fluid Dynamics Lecture 4 –Finite Difference

Introduction to Computational Fluid Dynamics

Lecture 4 –Finite Difference Method. Introduction. One spatial variable parabolic equations 27

Using again the Fourier mode in the implicit scheme we get:

xkee xkIxkI

2

1sin421 2

or

xk

2

1sin41

1

2

We notice that, we have 10 and thus, the implicit method is unconditionatelly

stable.

Page 28: Introduction to Computational Fluid Dynamicsmath.ubbcluj.ro/~tgrosan/2018IntroCFD_C4.pdf · 2018-10-31 · Introduction to Computational Fluid Dynamics Lecture 4 –Finite Difference

Introduction to Computational Fluid Dynamics

Lecture 4 –Finite Difference Method. Introduction. One spatial variable parabolic equations 28

Crank-Nicolson method

John Crank (1916-2006) Phyllis Nicolson (1917-1968)

Another method was proposed by Crank and Nicolson in 1947. They use the trapezoidal rule and a

central finite difference in space and obtain a scheme of order two:

211

2

11

111

1 22

2

1

x

UUU

x

UUU

t

UU ni

ni

ni

ni

ni

ni

ni

ni

Page 29: Introduction to Computational Fluid Dynamicsmath.ubbcluj.ro/~tgrosan/2018IntroCFD_C4.pdf · 2018-10-31 · Introduction to Computational Fluid Dynamics Lecture 4 –Finite Difference

Introduction to Computational Fluid Dynamics

Lecture 4 –Finite Difference Method. Introduction. One spatial variable parabolic equations 29

The scheme reduces to the following tri-diagonal system of linear equations:

ni

ni

ni

ni

ni

ni UUUUUU 11

11

111 1212

along with the initial and boundary conditions.

We will apply the Crank -Nicolson scheme to the heat equation and we will compare the

solution with the analytic solution and that obtained using the implicit scheme.

Page 30: Introduction to Computational Fluid Dynamicsmath.ubbcluj.ro/~tgrosan/2018IntroCFD_C4.pdf · 2018-10-31 · Introduction to Computational Fluid Dynamics Lecture 4 –Finite Difference

Introduction to Computational Fluid Dynamics

Lecture 4 –Finite Difference Method. Introduction. One spatial variable parabolic equations 30

Matlab program:

dt=0.0013;dx=0.05;

niu=dt/(dx*dx);

Nx=1/(dx)+1;

x=0:dx:1;

tf=0.1;

Nt=tf/dt;

Uo=zeros(Nx,1); Un=zeros(Nx,1);

%initialization

for i=1:round(Nx/2)

Uo(i)=(i-1)*dx;

end

for i=round(Nx/2):Nx

Uo(i)=1-(i-1)*dx;

end

A=zeros(Nx,Nx);b=zeros(Nx,1);

n=0;

while (n<Nt)

n=n+1;

A(1,1)=1;b(1)=0;

for i=2:Nx-1

A(i,i-1)=-niu;

A(i,i)=2+2*niu;

A(i,i+1)=-niu;

b(i)=niu*Uo(i-1)+

(2-2*niu)*Uo(i)+niu*Uo(i+1);

end

A(Nx,Nx)=1;b(Nx)=0;

Un=A\b;

Uo=Un;

end

plot(x,Uo,'o:k')

hold on

Page 31: Introduction to Computational Fluid Dynamicsmath.ubbcluj.ro/~tgrosan/2018IntroCFD_C4.pdf · 2018-10-31 · Introduction to Computational Fluid Dynamics Lecture 4 –Finite Difference

Introduction to Computational Fluid Dynamics

Lecture 4 –Finite Difference Method. Introduction. One spatial variable parabolic equations 31

Time implicitexact UU NicolsonCrankexact UU

0.00 0 0

0.05 0.000732 0.002992

0.10 0.004491 0.001476

0.20 0.002990 0.000734

0.30 0.001609 0.000342

0.40 0.000785 0.000153

0.50 0.000362 0.000066

We notice that the Crank – Nicolson solution is “better” than the implicit solution.

Page 32: Introduction to Computational Fluid Dynamicsmath.ubbcluj.ro/~tgrosan/2018IntroCFD_C4.pdf · 2018-10-31 · Introduction to Computational Fluid Dynamics Lecture 4 –Finite Difference

Introduction to Computational Fluid Dynamics

Lecture 4 –Finite Difference Method. Introduction. One spatial variable parabolic equations 32

method

Following the above described methods we can give a general method:

211

2

11

111

1 21

2

x

UUU

x

UUU

t

UU ni

ni

ni

ni

ni

ni

ni

ni

where usually 10 .

For 0 the general method reduces to the implicit scheme, for 2

1 to the Crank-

Nicolson scheme, while for 1 the implicit scheme is obtained.

Using the scheme leads like in implicit and Crank-Nicolson schemes to tri-diagonal

systems of linear equations.

Page 33: Introduction to Computational Fluid Dynamicsmath.ubbcluj.ro/~tgrosan/2018IntroCFD_C4.pdf · 2018-10-31 · Introduction to Computational Fluid Dynamics Lecture 4 –Finite Difference

Introduction to Computational Fluid Dynamics

Lecture 4 –Finite Difference Method. Introduction. One spatial variable parabolic equations 33

Using the Fourier analysis for the scheme we get:

xkee xkIxkI

2

1sin41211 2

or

xk

xk

2

1sin41

2

1sin141

2

2

Because 0 and 10 we always have 1 . Thus, the scheme will be unstable for

1 , namely

xkxk

2

1sin41

2

1sin141 22 or

2

1

2

1sin21 2 xk

Page 34: Introduction to Computational Fluid Dynamicsmath.ubbcluj.ro/~tgrosan/2018IntroCFD_C4.pdf · 2018-10-31 · Introduction to Computational Fluid Dynamics Lecture 4 –Finite Difference

Introduction to Computational Fluid Dynamics

Lecture 4 –Finite Difference Method. Introduction. One spatial variable parabolic equations 34

Using this equation the stability condition is deduced:

2

121

Then the method is stable for:

- 2

10 and

212

1

- 12

1 and for every .

It is possible to show that the truncation error on the node 2/1, ni is given by (see

Morton and Meyers, 2005):

....8

1

24

1

12

1

2

1 2222/1

xxtttttxxxxxxtn

i ututuxutT

For 2

1 (Crank-Nicolson case) the truncation error is of the order 22 xOtO , thus

the scheme is always second order accurate.