+ All Categories
Home > Documents > More Elementary Aspects of Numerical Solutions of PDEsgtryggva/CFD-Course/2013-Lecture-3.pdf ·...

More Elementary Aspects of Numerical Solutions of PDEsgtryggva/CFD-Course/2013-Lecture-3.pdf ·...

Date post: 06-Jun-2020
Category:
Upload: others
View: 1 times
Download: 0 times
Share this document with a friend
8
Computational Fluid Dynamics More Elementary Aspects of Numerical Solutions of PDEs Grétar Tryggvason Spring 2013 http://www.nd.edu/~gtryggva/CFD-Course/ Computational Fluid Dynamics In this lecture we continue to examine the elementary aspects of numerical solutions of partial differential equations. Here we will examine: Stability of the linear advection-diffusion equation Multidimensional linear advection-diffusion equation Steady state (boundary value problems) Outline Computational Fluid Dynamics As long as accuracy is reasonable, integration at larger time steps is more efficient and desirable. Can we increase the time step indefinitely? Lets repeat the 1-D advection-diffusion equation with larges time step. Use Δt = 0.2, instead of Δt = 0.05 Stability Computational Fluid Dynamics Evolution for U=1; D=0.05; k=1 N=21 Δt=0.2 Exact Numerical Stability Computational Fluid Dynamics Instead of decaying as it should, the amplitude of the numerical solution keeps increasing. Indeed, if we continued the calculations, we would eventually produce numbers larger than the computer can handle. This results in an overflowor NaN(Not a Number). Stability Computational Fluid Dynamics Ordinary Differential Equation Stability
Transcript
Page 1: More Elementary Aspects of Numerical Solutions of PDEsgtryggva/CFD-Course/2013-Lecture-3.pdf · elementary aspects of numerical solutions of partial differential equations. Here we

Computational Fluid Dynamics

More Elementary Aspects of

Numerical Solutions of PDEs!

Grétar Tryggvason!Spring 2013!

http://www.nd.edu/~gtryggva/CFD-Course/!Computational Fluid Dynamics

In this lecture we continue to examine the elementary aspects of numerical solutions of partial differential equations. Here we will examine:!

! !!Stability of the linear advection-diffusion equation!

! !!Multidimensional linear advection-diffusion equation!

! !!Steady state (boundary value problems)!

Outline!

Computational Fluid Dynamics

As long as accuracy is reasonable, integration at larger time steps is more efficient and desirable. !!Can we increase the time step indefinitely?!!Let’s repeat the 1-D advection-diffusion equation with larges time step.!!Use Δt = 0.2, instead of Δt = 0.05!

Stability!Computational Fluid Dynamics

Evolution for!U=1; D=0.05; k=1 N=21 Δt=0.2

Exact!

Numerical!

Stability!

Computational Fluid Dynamics

Instead of decaying as it should, the amplitude of the numerical solution keeps increasing. !!Indeed, if we continued the calculations, we would eventually produce numbers larger than the computer can handle. This results in an “overflow” or “NaN” (Not a Number).!

Stability!Computational Fluid Dynamics

Ordinary Differential Equation!Stability!

Page 2: More Elementary Aspects of Numerical Solutions of PDEsgtryggva/CFD-Course/2013-Lecture-3.pdf · elementary aspects of numerical solutions of partial differential equations. Here we

Computational Fluid Dynamics ODE—Example!

Take:! dfdt

= − f

f t( ) = e−tThe exact solution is!

with initial condition! f (0) = 1

f n+1 = (1 − Δt) f nf n+1 = f n − f nΔtForward Euler!

f n+1

f n≤1 only if!

Δt ≤ 2

Computational Fluid Dynamics

0 5 10 15 20-5

-4

-3

-2

-1

0

1

2

3

4

5

Δt=0.5!Δt=1.5!

Δt=2.5!

f n+1

f n≤1 only if!

Δt ≤ 2

f n+1 = (1 − Δt) f n

ODE—Example!

Computational Fluid Dynamics

f n+1

f n= 1(1+ Δt)

f n+1 = f n − f n+1ΔtBackward Euler!

f n+1 = (1−Δt) f n = (1−Δt)2 f n−1

= ………… = (1−Δt)n f 1

However!

for all Δt

Δt ≤1

f n+1

f n≤1

Obviously, f oscillates unless!

ODE—Example!Computational Fluid Dynamics

Stability Analysis of the!Advection-Diffusion Equation:!

Von Neumann Method!

Computational Fluid Dynamics

Generally, stability analysis of the full nonlinear system of equations is too involved to be practical, and we study a model problem that in some way mimics the full equations.!The linear advection-diffusion equation is one such model equation, and we will apply von Neumann's method to check the stability of a simple finite difference approximation to that equation.!

Stability!Computational Fluid Dynamics

2

2

xf

Dxf

Utf

∂∂

∂∂

∂∂ =+

21111

1 22 h

fffD

hff

Utff n

jnj

nj

nj

nj

nj

nj −+−++ +−

=−

+Δ−

Consider the 1-D advection-diffusion equation:!

In finite-difference form:!

Stability!

f jn

= ε jn

Look at the evolution of a small perturbation!

Page 3: More Elementary Aspects of Numerical Solutions of PDEsgtryggva/CFD-Course/2013-Lecture-3.pdf · elementary aspects of numerical solutions of partial differential equations. Here we

Computational Fluid Dynamics

22

21111

1

hD

hU

t

nj

nj

nj

nj

nj

nj

nj −+−++ +−

=−

+Δ− εεεεεεε

The evolution of the perturbation is governed by:!

Write the error as a wave (expand as a Fourier series):!

∑∞

−∞=

==k

ikxnkj

nnj

jex εεε )(

Dropping the subscript!jikxnn

j eεε =

Stability!

eikx = coskx + isinkxRecall:!

Computational Fluid Dynamics

ε jn = εneikx j

ε j+1n = εneikx j+1 = εneik (x j + h) = εneikx j eikh

The error at node j is:!

The error at j+1 and j -1 can be written as!

ε j−1n = ε neikx j−1 = ε neik (x j −h) = ε neikx j e−ikh

Stability!

Computational Fluid Dynamics

ε j+1n = ε neikx j eikh

ε n+1eikx j − ε neikx j

Δt+U εn

2h(eikheikx j − e− ikheikx j ) =

Dε n

h2(eikheikx j − 2eikx j + e− ikheikx j )

Substituting!

ε j−1n = ε neikx j e−ikh

ε jn+1 − ε j

n

Δt+U

ε j+1n − ε j−1

n

2h= D

ε j+1n − 2ε j

n + ε j−1n

h2

ε jn = εneikx j

into!

yields!

Stability!Computational Fluid Dynamics

ε n+1 − εn

Δ t+U

ε n

2h(eikh − e− ikh) = D

ε n

h2(eikh − 2 + e−ikh )

The equation for the error is:!

)2()(2

1 2

1ikhikhikhikh

n

n

eehtDee

htU −−

+

+−Δ+−Δ−=εε

Solving for the ratio of the errors:!

Stability!

Computational Fluid Dynamics

)2()(2

1 2

1ikhikhikhikh

n

n

eehtDee

htU −−

+

+−Δ+−Δ−=εε

=1−UΔth

isinkh + DΔth2

2(coskh −1)

=1− 4 DΔth2

sin2 k h2− iUΔt

hsinkh

Dividing by the error amplitude at n:!amplification factor!

Stability!

eikh + e−ikh = 2coskh; eikh − e− ikh = i2sinkh;Using:!

2sin2θ =1− cos2θ

Computational Fluid Dynamics

εn+1

εn=1− 4 DΔt

h2sin2 k h

2− iUΔt

hsinkh

ε n+1

ε n≤ 1

Stability requires that!

Since the amplification factor is a complex number, and k, the wave number of the error, can be anything, the determination of the stability limit is slightly involved.!!We will look at two special cases: (a) U = 0 and (b) D = 0

The ratio of the error amplitude at n+1 and n is:!

Stability!

Page 4: More Elementary Aspects of Numerical Solutions of PDEsgtryggva/CFD-Course/2013-Lecture-3.pdf · elementary aspects of numerical solutions of partial differential equations. Here we

Computational Fluid Dynamics

ε n+1

ε n= 1− 4

DΔth2

sin2 kh2

Since the amplification factor is always less than 1, and we find that it is bigger than -1 if!

sin2 () ≤ 1

(a) Consider first the case when U = 0, so the problem reduces to a pure diffusion!

DΔth2

≤12

−1≤1− 4 DΔth2

≤1

Stability!Computational Fluid Dynamics

Since the amplification factor has the form 1+i() the absolute value of this complex number is always larger than unity and the method is unconditionally unstable for this case.!

εn+1

εn=1− iUΔt

hsinkh

(b) Consider now the other limit where D = 0 and we have a pure advection problem.!

iUΔthsinkh

1

ε n+1

ε n

Stability!

Computational Fluid Dynamics

For the general case we must investigate the stability condition in more detail. We will not do so here, but simply quote the results:!

Notice that high velocity and low viscosity lead to instability according to the second restriction.!!

Δ tDh2

≤12

U2ΔtD

≤ 2and!

Stability!Computational Fluid Dynamics

ε i, jn = ε nei(kxi +ly j )

41

2 ≤ΔhtD

4|)||(| 2

≤Δ+D

tVUand!

DΔth2

≤ 16

and!

(|U |+ |V |+ |W |)2ΔtD

≤ 8

For a two-dimensional problem, assume an error of the form!

A stability analysis gives:!

For a three-dimensional problem we get:!

Stability!

Computational Fluid Dynamics

Convergence – the solution to the finite-difference equation approaches the true solution to the PDE having the same initial and boundary conditions as the mesh is refined.!

Lax’s Equivalence Theorem!Given a properly posed initial value problem and a finite-difference approximation to it that satisfies the consistency condition, stability is the necessary and sufficient condition for convergence.!

Stability – Now you know!!

Stability!Computational Fluid Dynamics

Two-Dimensional Advection-Diffusion Equation!

Page 5: More Elementary Aspects of Numerical Solutions of PDEsgtryggva/CFD-Course/2013-Lecture-3.pdf · elementary aspects of numerical solutions of partial differential equations. Here we

Computational Fluid Dynamics

∂f∂t

+U∂f∂x

+ V∂f∂y

= D∂ 2 f∂x 2

+∂ 2 f∂y2

⎛ ⎝ ⎜ ⎞

We will use the model equation:!

to demonstrate how to solve a partial equation (initial value problem) numerically.!

The extension to two-dimensions is relatively straight forward, once the one-dimensional problem is fully understood.!

Multidimensional Equations!Computational Fluid Dynamics

For a two-dimensional flow discretize the variables on !a two-dimensional grid!

fi , j = f (x,y)

fi+1, j = f (x + h, y)

fi , j+1 = f (x, y + h)(x, y)

i -1 i i+1

j+1 j j-1

Multidimensional Equations!

Computational Fluid Dynamics

fi, jn+1 − fi, j

n

Δt= −U

fi+1, jn − fi−1, j

n

2h

⎝⎜

⎠⎟ −V

fi, j+1n − fi, j−1

n

2h

⎝⎜

⎠⎟ +

Dfi+1, j

n + fi−1, jn − 2 fi, j

n

h2 +fi, j+1

n + fi, j−1n − 2 fi, j

n

h2

⎝⎜

⎠⎟

∂ f∂t

+U∂ f∂x

+V∂ f∂ y

= D∂ 2 f∂x2 +

∂ 2 f∂ y2

⎝⎜⎞

⎠⎟

The discrete equation is:!

Multidimensional Equations!Computational Fluid Dynamics

fi, jn+1 = fi, j

n + Δt −Ufi+1, j

n − fi−1, jn

2h

⎝⎜

⎠⎟ −V

fi, j+1n − fi, j−1

n

2h

⎝⎜

⎠⎟ +

⎣⎢⎢

Dfi+1, j

n + fi−1, jn + fi, j+1

n + fi, j−1n − 4 fi, j

n

h2

⎝⎜

⎠⎟⎤

⎦⎥⎥

Solve for !fi , jn+1

fi, jn+1 = fi, j

n −ΔtU2h

fi+1, jn − fi−1, j

n( ) − ΔtV2h

fi, j+1n − fi, j−1

n( )+ΔtDh2 fi+1, j

n + fi−1, jn + fi, j+1

n + fi, j−1n − 4 fi, j

n( )

or!

Multidimensional Equations!

Δ tDh2

≤14

(|U | + | V |) 2ΔtD

≤ 4and!A stability analysis gives:!

Accuracy:!O Δt,h2( )

Computational Fluid Dynamics

Example!

Computational Fluid Dynamics

f=1.0!

∂f∂x

= 0∂f∂y

= 0

f=0.0!

f=0.0!

∂ f∂t

+U∂ f∂x

+V∂ f∂ y

= D∂ 2 f∂x2 +

∂ 2 f∂ y2

⎝⎜⎞

⎠⎟

U=-1!V=0!

Uniform flow through the domain!

Multidimensional Equations!

Page 6: More Elementary Aspects of Numerical Solutions of PDEsgtryggva/CFD-Course/2013-Lecture-3.pdf · elementary aspects of numerical solutions of partial differential equations. Here we

Computational Fluid Dynamics

i=1! i=2! i=NX!j=1!j=2!

j=NY!

fi , jstored at each grid point!

fi, jn +1 = fi, j

n −ΔtU2h

fi+1, jn − fi−1, j

n( ) +ΔtDh2

fi+1, jn + fi−1, j

n + fi, j+1n + fi, j−1

n − 4 fi, jn( )

∂ f∂n

for!

given on the boundary!

Multidimensional Equations!Computational Fluid Dynamics

Boundary conditions!Where f is given, we simply specify its value!

Where the normal derivative is specified, we approximate the value at the boundary by one-sided differences!

∂ f∂ y

= 0At the i=1 boundary, for example,!

∂ f∂ y

≈fi,2

n − fi,1n

h= 0and by using!

we find that:! fi,2

n = fi,1n

Multidimensional Equations!

Computational Fluid Dynamics

% two-dimensional unsteady diffusion by the FTCS scheme %------------------------------------------------------------ n=32;m=32;nstep=120;D=0.025;length=2.0;h=length/(n-1); dt=1.0*0.125*h*h/D;f=zeros(n,m);fo=zeros(n,m);time=0.0; u=-0.0; v=-1.0; f(12:21,n)=1.0; for l=1:nstep,l,time hold off;mesh(f); axis([0 n 0 m 0 1.5]);pause; fo=f; for i=2:n-1, for j=2:m-1 f(i,j)=fo(i,j)-(0.5*dt*u/h)*(fo(i+1,j)-fo(i-1,j))-...

(0.5*dt*v/h)*(fo(i,j+1)-fo(i,j-1))+... (D*dt/h^2)*(fo(i+1,j)+ fo(i,j+1)+fo(i-1,j)+fo(i,j -1)-4*fo(i,j)); end,end for i=1:n, f(i,1)=f(i,2);end;for j=1:m,f(1,j)=f(2,j);f(m,j)=f(m-1,j);end; time=time+dt; end;

Multidimensional Equations!Computational Fluid Dynamics

The unsteady evolution of the solution!

Multidimensional Equations!

Computational Fluid Dynamics

Multidimensional Boundary Value

Problems!(Steady-State)!

Computational Fluid Dynamics

∂ 2 f∂x2

+∂ 2 f∂y2

= S

This equation has a solution if f or is specified on the boundary!

Boundary Value Problems!

Consider the Poisson Equation:!

Use standard finite differences to discretize:!

fi+1, j + f i−1, j − 2 fi, jh2

+f i, j−1 + f i, j+1 − 2 f i, j

h2= Si, j

∂f ∂n

Page 7: More Elementary Aspects of Numerical Solutions of PDEsgtryggva/CFD-Course/2013-Lecture-3.pdf · elementary aspects of numerical solutions of partial differential equations. Here we

Computational Fluid Dynamics

fi , j

= 14

f i+1, j + fi−1, j + f i, j−1 + f i, j+1 − h2Si, j( )

Solve for fi,j:!

fi+1, j + fi−1, j + fi, j−1 + fi, j+1 − 4 fi, j

h2 = S

can be written as!

For uniform grids:!

fi+1, j + fi−1, j − 2 fi, j

h2 +fi, j−1 + fi, j+1 − 2 fi, j

h2 = Si, j

Boundary Value Problems!Computational Fluid Dynamics

fi , j

α+1 = 14

f i+1, jα + f i−1, j

α + fi, j−1α + f i, j+1

α − h2Si, j( )

Solve for fi,j and use the right hand side to compute a new value. Denote the old values by α and the new ones with α+1

This iteration process—Jacobi iteration—is very robust but many iterations are required to reach an accurate solution.!

Boundary Value Problems!

Computational Fluid Dynamics

The iteration must be carried out until the solution is sufficiently accurate. To measure the error, define the residual:!

Ri, j =

fi+1, j + fi−1, j + fi, j−1 + fi, j+1 − 4 fi, j

h2 − Si, j

At steady-state the residual should be zero. The point-wise residual or the average absolute residual can be used, depending on the problem. Often, simpler criteria, such as the change from one iteration to the next is used!

Boundary Value Problems!Computational Fluid Dynamics

Although the Jacobi iteration is a very robust iteration technique, it converges VERY slowly. !!We therefore seek a way to ACCELERATE the convergence to steady-state, making use of the fact that it is only the steady-state that is of interest.!!Here we introduce the Gauss-Seidler method and the Successive Over-Relaxation (SOR) method.!

Boundary Value Problems!

Computational Fluid Dynamics

fi, jα+1 = 1

4( f i+1, j

α + f i−1, jα+1 + fi, j+1

α + f i, j−1α+1 − h2Si, j )

The Jacobi iteration can be improved somewhat by using new values as soon as they become available.!

j!

j-1!

j+1!

i! i+1!i-1!

for j=1:mfor i=1:n iterateendend

From a programming point of view, Gauss-Seidler iteration is even simpler than Jacobi iteration since only one vector with f values is needed.!

Boundary Value Problems!Computational Fluid Dynamics

fi, jα+1 = β

4( f i+1, j

α + f i−1, jα+1 + fi, j+1

α + f i, j−1α+1 + h2Si, j )

+ (1−β) f i, jα

The Gauss-Seidler iteration can be accelerated even further by various acceleration techniques. The simplest one is the Successive Over-Relaxation (SOR) iteration!

The SOR iteration is very simple to program, just as the Gauss-Seidler iteration. The user must select the coefficient. It must be bounded by 1<β<2. β=1.5 is usually a good starting value.!

Boundary Value Problems!

Page 8: More Elementary Aspects of Numerical Solutions of PDEsgtryggva/CFD-Course/2013-Lecture-3.pdf · elementary aspects of numerical solutions of partial differential equations. Here we

Computational Fluid Dynamics

Example!

Computational Fluid Dynamics

5 10 15 20 25 30 35 40

5

10

15

20

25

30

35

40

f=1.0! f=0.0!

∂ 2 f∂x 2

+∂ 2 f∂y2

= 0

Boundary Value Problems!

Computational Fluid Dynamics

% two-dimensional steady-state problem by SORn=40;m=40;iterations=5000;length=2.0;h=length/(n-1);T=zeros(n,m);bb=1.7;T(10:n-10,1)=1.0; for l=1:iterations, for i=2:n-1, for j=2:m-1 T(i,j)=bb*0.25*(T(i+1,j)+... T(i,j+1)+T(i-1,j)+T(i,j-1))+(1.0-bb)*T(i,j); end,end % find residual res=0; for i=2:n-1, for j=2:m-1 res=res+abs(T(i+1,j)+... T(i,j+1)+T(i-1,j)+T(i,j-1)-4*T(i,j))/h^2; end,end l,res/((m-2)*(n-2)) % Print iteration and residual if (res/((m-2)*(n-2)) < 0.001), break,endend;contour(T);

Boundary Value Problems!Computational Fluid Dynamics

Average absolute error: 0.001!! Number of iterations!

Jacobi: ! 1989!Gauss-Seidler: !986!!SOR (β =1.5): 320!SOR (β = 1.7): !162!SOR (β = 1.9): ! 91!SOR (β = 1.95): 202!

The program is easily modified for the Jacobi and the Gauss-Seidler iteration:!

Boundary Value Problems!

Computational Fluid Dynamics

5 10 15 20 25 30 35 40

5

10

15

20

25

30

35

40

The converged solution:!

∂ 2 f∂x 2

+∂ 2 f∂y2

= 0

Boundary Value Problems!

010

2030

40

0

10

20

30

400

0.2

0.4

0.6

0.8

1

Computational Fluid Dynamics

Stability—introduced the von Neumann method. Fairly mechanical process, we will provide more insight by the finite volume point of view!!Multidimensional advection-diffusion equation. Essentially the same as the one-dimensional problem!!Iterative methods for boundary value problems. Elementary approaches to steady state problems!

Summary!


Recommended