Вы находитесь на странице: 1из 26

Introduction to Computational Fluid Dynamics

FINITE DIFFERENCES METHOD part II

Parabolic equations - two (or three) spatial variables

The explicit method

Consider the heat equation in a square domain D  0, X   0, Y 

u   2 u  2u 
   2  2 ,   0
t  x  y 
along with the Dirichlet type boundary conditions, i.e. the values u  x, y, t  D and
u  x, y,0 D are known and  is a constant positive number.

Lecture 5 –Finite Difference Method. Two (or three) spatial variables’ parabolic equations 1
Introduction to Computational Fluid Dynamics
Consider also the mesh with the steps x and y in Ox and Oy directions:
X Y
x  , y 
Nx Ny

where N x and N y represent the nodes number in Ox and Oy directions.

We note the approximation of the initial


solution in a point i, j  of the mesh at the time
step n with

U in, j  u xi , y j , t n ,
i  0, 1, ..., N x , j  0, 1, ..., N y .

Lecture 5 –Finite Difference Method. Two (or three) spatial variables’ parabolic equations 2
Introduction to Computational Fluid Dynamics
We note the approximation of the initial solution in a point i, j  of the mesh at the time
step n with
U in, j  u xi , y j , t n , i  0,1, ..., N x , j  0,1, ..., N y .
By using progressive finite differences for the temporal derivative and central finite
differences for the spatial derivatives the following explicit scheme is obtained:
U in, j 1  U in, j U in1, j  2U in, j  U in1, j U in, j 1  2U in, j  U in, j 1 
  
t  x 2
y 2

(o)
We observe that the
unknown value
U in, j 1 can be
calculated because
all values
U in, j are known.

Lecture 5 –Finite Difference Method. Two (or three) spatial variables’ parabolic equations 3
Introduction to Computational Fluid Dynamics
We introduce the truncation error in similar way with the 1D case:
 t u  x, t   x u  x , t   y u  x , t  
T  x, t      2 
t    x  2
  y  
and using the Taylor expansion we get:
1 1
 t u  x, t   ut t  utt t   uttt t   ...
2 3

2 6
1
2
   
 x u x, t  u xx x  utttt x 4  ...
2

12
1 1

T  x, t   t utt   x  u xxxx  y  u yyyy  ...
2 12
2 2

and the maximum convergence error:
1 1

E n    t M tt   x 2 M xxxx  y 2 M yyyy t F
2 12 
is obtained if the bi-dimensional mesh satisfy the severe condition:
 t  t
1
 x  y  2  2 
x x 2 (*)
Lecture 5 –Finite Difference Method. Two (or three) spatial variables’ parabolic equations 4
Introduction to Computational Fluid Dynamics
In order to study the stability we will consider the von Neumann method where the
Fourier mode has the form:
U n   n ExpI k x x  k y y  (**)

Substituting this form into the numerical explicit scheme the amplification factor is:
 
   k x , k y   1  4  x sin 2  k x x    y sin 2  k y y 
1 1
 2  2 
from where the condition (*) for stability is obtained.

 t  t
1
 x  y  2  2 
x x 2

Lecture 5 –Finite Difference Method. Two (or three) spatial variables’ parabolic equations 5
Introduction to Computational Fluid Dynamics
The implicit method
The implicit method is given by:
U in, j 1  U in, j U in11, j  2U in, j 1  U in11, j U in, j 11  2U in, j 1  U in, j 11 
  
t  x 2
y 2
 (oo)
and it leads to the following system:
 xU in11, j   xU in11, j  2 x  2 y  1U in, j 1   yU in, j 11   yU in, j 11  U in, j (oo)

Lecture 5 –Finite Difference Method. Two (or three) spatial variables’ parabolic equations 6
Introduction to Computational Fluid Dynamics
It is worth mentioning that the structure of the system (oo) does not allow us to solve it
easy.

The implicit scheme (oo) is stable no matter the temporal and spatial steps’ dimensions.

In order to find the unknowns U in, j 1 it is necessary to solve an algebraic sparse linear

system of dimension  N x  1  N y  1 .  
Example: Consider the implicit scheme:
(K. Hoffmann, S. Chiang, Computational Fluid Dynamics, 4th ed, EES, Wichita, 2000)

Lecture 5 –Finite Difference Method. Two (or three) spatial variables’ parabolic equations 7
Introduction to Computational Fluid Dynamics
where

We note the coefficients with a, b, c, d, e and f:

Lecture 5 –Finite Difference Method. Two (or three) spatial variables’ parabolic equations 8
Introduction to Computational Fluid Dynamics
Matrix form

Lecture 5 –Finite Difference Method. Two (or three) spatial variables’ parabolic equations 9
Introduction to Computational Fluid Dynamics
It should be noted that it is possible to obtain many implicit schemes depending on the
assumption made on the spatial derivatives. An example is the Crank-Nicolson method
(see Morega, 1998):

U in, j 1  U in, j n 1 n 1 n 1
  U i 1, j  2U i , j  U i 1, j U in, j 11  2U in, j 1  U in, j 11 
  
t 2  x 2  y 2 
 
  U i 1, j  2U i , j  U i 1, j U in, j 1  2U in, j  U in, j 1 
n n n
  
2  x 2  y 2 
 

Lecture 5 –Finite Difference Method. Two (or three) spatial variables’ parabolic equations 10
Introduction to Computational Fluid Dynamics
Alternating direction implicit (ADI) method
Due to the fact that the explicit schemes are restrictive and the implicit schemes are
computationally costly, schemes implicit in one spatial direction and explicit in the other
directions were looked for.

An example of such a scheme is:


U in, j 1  U in, j  U in11, j  2U in, j 1  U in11,j U in, j 1  2U in, j  U in, j 1 
   (ooo)
t   x  2
  y  2 
 
In order to calculate the solution we have to solve for each step in y direction a tri-
diagonal system of order N x  1. Using (**) into the scheme (ooo) the amplification factor
is obtain:

Lecture 5 –Finite Difference Method. Two (or three) spatial variables’ parabolic equations 11
Introduction to Computational Fluid Dynamics
1  1 
1  2 x sin 2  k x x   4 y sin 2  k y y 
 k x , k y   2  2 
1 
1  2 x sin 2  k x x 
2 
 t 1
As expected regarding the stability there is the restriction  , and for the term
y 2 2
 t
we have no restriction.
x 
2

It is possible to obtain efficient methods by combining two such methods each of which
being implicit in one direction. This is the principle of the alternating direction implicit
methods. The first such scheme was proposed by Paceman and Rachford (1955) and was
used for solving partial differential equations that model the flow in oil tanks.

Lecture 5 –Finite Difference Method. Two (or three) spatial variables’ parabolic equations 12
Introduction to Computational Fluid Dynamics
We introduce an intermediary time step, n  1 / 2 , and we get:

U in, j 1/ 2  U in, j n 1 / 2 n 1 / 2 n 1 / 2
  U i 1, j  2U i , j  U i 1, j U i , j 1  2U i , j  U i , j 1 
n n n
  (ADI_x)
t 2   x  2
 y  2 

U in, j 1  U in, j 1 / 2 n 1 / 2 n 1 / 2 n 1 / 2
  U i 1, j  2U i , j  U i 1, j U in, j 11  2U in, j 1  U in, j 11 
  (ADI_y)
t 2   x 2  y  2 

If the values U n are known from Eq. (ADI_x) it is possible to calculate U n1/ 2 and then
using (ADI_y) the values of U n1 are found.

Lecture 5 –Finite Difference Method. Two (or three) spatial variables’ parabolic equations 13
Introduction to Computational Fluid Dynamics
In order to calculate U n1/ 2 we need the values of U n but also the values from the
boundary marked with “”, and for U n 1 we need the values of U n1/ 2 and the values
from the boundary marked with “”

For a time step we have to solve N y  1 tri-diagonal systems (for the nodes marked with
“”) of order N x  1, and then to solve N x  1 tri-diagonal systems (for the nodes marked
with “”) of order N y  1. This process needs less time than solving a system of order
 N x  1  N y  1 with a non tri-diagonal structure.
It is worth mentioning that it is possible to demonstrate, using a Fourier analysis, the ADI
scheme is unconditionally stable (see Morton and Mayers, 1994).

Lecture 5 –Finite Difference Method. Two (or three) spatial variables’ parabolic equations 14
Introduction to Computational Fluid Dynamics
Solving the heat equation using ADI method

Consider a square plate of length 1 having the boundary maintained at the dimensionless
temperature 0. We suppose that at the initial moment (t = 0) a region of the plate having a
cross form has the temperature T and the rest of the plate has the temperature 0. For the
sake of simplicity we took   1.

The heat equation is discretized using the ADI method for a rectangular mesh with the
steps x and y and the Eqs. (ADI) are obtained. These equations can be written in the
form:

Lecture 5 –Finite Difference Method. Two (or three) spatial variables’ parabolic equations 15
Introduction to Computational Fluid Dynamics
1 1 1
1 n n 1 n
  xU i 1, j  1   x U i , j   xU i 1,2j  Cin, j
2 2
2 2
1
n
  yU i , j 1  1   y U i , j   yU i , j 1  Di , j 2
1 n 1 n 1 1 n 1
2 2

t t
where  x  ,y  , and:
x  2
y  2

Cin, j   yU in, j 1  1  y U in, j 1   yU in, j 11


1 1
2 2
1 1 1 1
n 1 n n 1 n
Di , j 2   xU i 1,2j  
1  x U i , j 2   xU i 1,2j
2 2

Lecture 5 –Finite Difference Method. Two (or three) spatial variables’ parabolic equations 16
Introduction to Computational Fluid Dynamics

Lecture 5 –Finite Difference Method. Two (or three) spatial variables’ parabolic equations 17
Introduction to Computational Fluid Dynamics
Matlab program:
%Solve the heat equation in a rectangular domain
%[0,X]x[0,Y] using ADI method

X=1; while (timp<=0.01)


Y=1; timp=timp+dt
dt=0.0001; C=InitC(U,Nx,Ny,aa,bb);
dx=0.01; for j=1:Ny-1
dy=0.01; U(:,j)=A\C(:,j);
Nx=X/dx end;
Ny=Y/dy D=InitD(U,Nx,Ny,a,b);
a=-0.5*dt/dx^2; for i=1:Nx-1
b=dt/dx^2; UU=B\D(i,:)';
aa=-0.5*dt/dy^2; U(i,:)=UU';
bb=dt/dy^2; end;
A=InitA(a,b,Nx,Ny); end;
B=InitB(aa,bb,Nx,Ny); surfl(U);hold on;
U=InitU(Nx,Ny); view(-40,60);
surfl(U); contour3(U,4);
view(-50,60); view(-50,60);
shading interp; shading interp;
colormap(pink); colormap(pink);
axis('off'); axis('off');
pause; hold off;
timp=0

Lecture 5 –Finite Difference Method. Two (or three) spatial variables’ parabolic equations 18
Introduction to Computational Fluid Dynamics
function A=InitA(a,b,Nx,Ny) function U=InitU(Nx,Ny)
A=zeros(Nx-1,Ny-1); T=0.5
for i=1:Nx-1 U=zeros(Nx-1,Ny-1);
A(i,i)=1+b; for i=Nx/5:4*Nx/5
end; for j=2*Ny/5:3*Ny/5
for i=1:Nx-2 U(i,j)=T;
A(i+1,i)=a; end;
end; end;
for i=1:Nx-2 for i=2*Nx/5:3*Nx/5
A(i,i+1)=a; for j=Ny/5:4*Ny/5
end; U(i,j)=T;
end;
end;
function B=InitB(aa,bb,Nx,Ny)
B=zeros(Nx-1,Ny-1);
for i=1:Nx-1 function C=InitC(U,Nx,Ny,aa,bb)
B(i,i)=1+bb; C=zeros(Nx-1,Ny-1);
end; for i=1:Nx-1
for i=1:Nx-2 C(i,1)=-aa*U(i,2)+(1-bb)*U(i,1);
B(i+1,i)=aa; C(i,Ny-1)=-aa*U(i,Ny-2)+(1-
end; bb)*U(i,Ny-1);
for i=1:Nx-2 for j=2:Ny-2
B(i,i+1)=aa; C(i,j)=-aa*U(i,j+1)+(1-bb)*U(i,j)-
end; aa*U(i,j-1);
end;
end;

Lecture 5 –Finite Difference Method. Two (or three) spatial variables’ parabolic equations 19
Introduction to Computational Fluid Dynamics
function D=InitD(U,Nx,Ny,a,b)
D=zeros(Nx-1,Ny-1);
for j=1:Ny-1
for i=2:Nx-2
D(i,j)=-a*U(i+1,j)+(1-b)*U(i,j)-
a*U(i-1,j);
end;
D(1,j)=-a*U(2,j)+(1-b)*U(1,j);
D(Ny-1,j)=-a*U(Ny-2,j)+(1-b)*U(Ny-
1,j);
end; t = 0.001

t = 0.004 t = 0.01
Lecture 5 –Finite Difference Method. Two (or three) spatial variables’ parabolic equations 20
Introduction to Computational Fluid Dynamics
Fractional step method

Lecture 5 –Finite Difference Method. Two (or three) spatial variables’ parabolic equations 21
Introduction to Computational Fluid Dynamics
Extensions to three-space dimensions

Lecture 5 –Finite Difference Method. Two (or three) spatial variables’ parabolic equations 22
Introduction to Computational Fluid Dynamics
where

Lecture 5 –Finite Difference Method. Two (or three) spatial variables’ parabolic equations 23
Introduction to Computational Fluid Dynamics

Linearization
The investigated models until this moment were linear. However, the real phenomena are
not linear and in order to solve them some linearization methods must be used.

Further will give some examples for the non-linear term from Navier Stokes equations:
u
u
x
Lagging method: (a intarzaierii) The non-linear term can be discretized in the following
way:
n
n 1 ui 1, j  uin, j
ui , j
x
where n  1 is the previous time step, and n is the time step for which the unknown must
be calculated.
Lecture 5 –Finite Difference Method. Two (or three) spatial variables’ parabolic equations 24
Introduction to Computational Fluid Dynamics

Iterations method: The linearized term obtained using the lagging method is corrected
using an internal iteration until the desired accuracy is reached.
uik11, j  ui , j
uik1, j
x

For k  1 the value for the previous step is used and then the iterative process continues
until a stop criteria is fulfilled:

uik11, j  uik1, j
uik11, j  uik1, j   or 
uik1, j

Lecture 5 –Finite Difference Method. Two (or three) spatial variables’ parabolic equations 25
Introduction to Computational Fluid Dynamics
Newton linearization method:
Consider the product A  B and the modification for two successive iterations:
A  A k 1  A k and B  B k 1  B k .
Thus:
  
Ak 1  B k 1  Ak  A B k  B  Ak B k  B k A  Ak B  AB
We suppose that AB is small and we get:
   
Ak 1  B k 1  Ak B k  B k Ak 1  Ak  Ak B k 1  B k  Ak B k 1  Ak 1B k  Ak B k .
For the Navier-Stokes term we have
k 1 k k
u  u   u   u 
u  u k    u k 1    u k  
x  x   x   x 
Using forward finite differences we obtain:
k 1
 u  ui 1, j  ui , j k 1 ui
k
1, j  ui , j ui
k
1, j  ui , j
 u   ui 1, j  ui 1, j  ui 1, j
k k
 x i , j x x x


1  k
x 

2ui 1, j uik11, j  uik1, j   ui, juik11,j 
2

Lecture 5 –Finite Difference Method. Two (or three) spatial variables’ parabolic equations 26

Вам также может понравиться