Computational Fluid Dynamics Numerical Methods for Elliptic Equations-III Grétar Tryggvason Spring 2011 http://www.nd.edu/~gtryggva/CFD-Course/ Computational Fluid Dynamics Examples of elliptic equations Direct Methods for 1D problems Elementary Iterative Methods Note on Boundary Conditions SOR on vector computers Iteration as Time Integration Convergence of Iterative Methods—elementary considerations Multigrid methods Convergence of Iterative Methods—Formal Discussion ADI for elliptic equations Krylov Methods Fast Direct Method Resources Computational Fluid Dynamics ADI Methods for Elliptic Equations Computational Fluid Dynamics Alternating-Direction Implicit - 1 ADI for elliptic equation is analogous to ADI in parabolic equation ∂f ∂t = α ∂ 2 f ∂x 2 + ∂ 2 f ∂y 2 ⎡ ⎣ ⎢ ⎤ ⎦ ⎥ − S f i, j n +1 − f i, j n = αΔt δ xx f + δ yy f [ ] + S In discrete form and take it to the limit to obtain the steady solution. ⎟ ⎠ ⎞ ⎜ ⎝ ⎛ = ∂ ∂ 0 t f Computational Fluid Dynamics Alternating-Direction Implicit - 2 ADI for f i, j n +1 − f i, j n = αΔt δ xx f + δ yy f [ ] − S is written as f n +1/2 − f n = αΔt 2h 2 f i +1, j n +1/2 − 2 f i, j n +1/2 + f i−1, j n +1/2 ( ) + f i, j +1 n − 2 f i, j n + f i, j −1 n ( ) [ ] − ′ S i, j f n +1 − f n +1/2 = αΔt 2h 2 f i +1, j n +1/2 − 2 f i, j n +1/2 + f i−1, j n +1/2 ( ) + f i, j +1 n +1 − 2 f i, j n +1 + f i, j −1 n +1 ( ) [ ] − ′ ′ S i, j or 1 − ρ n δ xx ( ) f n +1/2 = 1 + ρ n δ yy ( ) f n − ′ S i, j 1 − ρ n δ yy ( ) f n +1 = 1 + ρ n δ xx ( ) f n +1/2 − ′ ′ S i, j ⎟ ⎠ ⎞ ⎜ ⎝ ⎛ Δ = 2 n n t α ρ Computational Fluid Dynamics Alternating-Direction Implicit - 3 Convergence of ADI - Iteration parameter usually varies with iteration - For example (Wachspress) lower bound eigenvalue 2 n n t Δ = α ρ ( )( ) n k b a b h t h n k k k , , 1 , 2 1 / 1 2 2 = ⎟ ⎠ ⎞ ⎜ ⎝ ⎛ = Δ = − − α ρ a b upper bound eigenvalue - Comparison with SOR is difficult - ADI can be efficient if appropriate parameters are found.
9
Embed
Direct Methods for 1D problems Numerical Methodsgtryggva/CFD-Course/2011-Lecture-21.pdf · Direct Methods for 1D problems! Elementary Iterative Methods! Note on Boundary Conditions!
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Examples of elliptic equations!Direct Methods for 1D problems!Elementary Iterative Methods!Note on Boundary Conditions!SOR on vector computers!Iteration as Time Integration!Convergence of Iterative Methods—elementary considerations!Multigrid methods!Convergence of Iterative Methods—Formal Discussion!ADI for elliptic equations !!Krylov Methods!Fast Direct Method!Resources!
Non Stationary Iterative Methods!!Conjugate Gradient (CG)!
!Minimal Residual (MINRES)!!Generalized Minimal Residual (GMRES)!!And Many Others!!
Computational Fluid Dynamics
Most of these methods are formulized as minimization techniques, where the following function is minimized!
�
F = xTAx − xT b
The search direction and the step are selected in a “best” way!
Computational Fluid Dynamics
Many methods work only for symmetric systems. While the pressure equation is usually symmetric, implicit methods usually do not lead to symmetric matrices.!
Usually the system is PRECONDITIONED to make it better behaved.!
Computational Fluid Dynamics
Preconditioning!
Iterative methods generally converge faster if we have a matrix A that is “close” to the identity matrix I!
�
Ax = b
�
A−1Ax =A−1b
�
Ix = x =A−1b�
A−1A = I
If the inverse of the matrix A was known, then the solution could be written down in a straight forward way!
Computational Fluid Dynamics
And should be easier to solve!
�
Ax = b�
MAx =Mb
If we have a matrix M that is in some way close to the inverse of A, then the system !
Has the same solution as the original system!
Computational Fluid Dynamics
Finding the “best” preconditioner is an active research topic, but the simples choice is:!
Computational Fluid Dynamics The conjugate gradient method!
Compute r(0) = b - A x(0) for some initial guess x(0) for i=1,2,… solve M z(i-1) = r(i-1) ρi-1 = r(i-1)T z(i-i) if i = 1 p(i)=z0 else βi -1 = ρi-1 / ρi-2 p(i)= z(i-1)- βi -1 p(i-1) end if q = Ap(i) αi = ρi-1 /p(i) q(i) x(i)= x(i-1)+ αi p(i) r(i)= r(i-1)- αi q(i) Check convergence; continue if needed end
x(i) ith iterate r(i) residual at ith step p(i) search direction αi multiple of the search
direction vector
One of the oldest non-stationary iterative method is the conjugate gradient method!
For M=I we have the unpreconditioned version!
Computational Fluid Dynamics
Generally iterative methods generate a sequence of approximations that are used to construct a new approximation. Ideally, we only need to keep a few approximations, but one of the more popular technique, GMRES, requires all the previous iterates. This leads to the restarted GMRES!
Computational Fluid Dynamics
At the present time there does not seem to be a “best” Krylov method. In addition to the relatively simple early methods like the conjugate gradient method, GMRES is fairly popular (particularly the restarted version) and BiCGSTAB has been used by a number of people.!
Computational Fluid Dynamics
http://www.netlib.org/templates/Templates.html!
From: Templates for the Solution of Linear Systems: Building Blocks for Iterative Methods!
Preconditioned !Bi-CGSTAB!
Computational Fluid Dynamics
Books:!
Barrett, Berry, Chan, Dellel, Donato, Dongarra, Eijkhout, Pozo, Romine, and Van der Vorst!Templates for the Solution of Linear Systems:!Building Blocks for Iterative Methods!http://www.netlib.org/templates/Templates.html!
Y. Saad. Iterative methods for sparse linear systems (2nd edition)!http://www-users.cs.umn.edu/~saad/books.html!
Computational Fluid Dynamics
Fast Direct Methods!
Computational Fluid Dynamics
Although iterative methods are the dominant technique for solutions of elliptic equations in CFD, Fast Direct Methods exists for special cases. The methods require simple domains (rectangles), simple equations (separable), and simple boundary conditions (periodic, or the derivative or the function equal to zero at each boundary)!
1 Find by FFT!2 Find as shown before!3 find by FFT!
�
ˆ b l ,m
�
ˆ f l ,m
�
fk, j
Computational Fluid Dynamics
As outlined the method is applicable to periodic boundaries only. Other simple boundary conditions can be handled by simple changes (using cosine or sine series).!
Other fast direct methods, such as Cyclic Reduction, are based on similar ideas!
See FISHPACK!
Computational Fluid Dynamics
subroutine hwscrt (a,b,m,mbdcnd,bda,bdb,c,d,n,nbdcnd,bdc,bdd, 1 elmbda,f,idimf,pertrb,ierror,w) c * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * c * f i s h p a k * c * * c * a package of fortran subprograms for the solution of * c * separable elliptic partial differential equations * c * (version 3.1 , october 1980) * c * by * c * john adams, paul swarztrauber and roland sweet * c * of * c * the national center for atmospheric research * c * boulder, colorado (80307) u.s.a. * c * which is sponsored by * c * the national science foundation * c * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * c * * * * * * * * * purpose * * * * * * * * * * * * * * * * * * c subroutine hwscrt solves the standard five-point finite c difference approximation to the helmholtz equation in cartesian c coordinates: c c (d/dx)(du/dx) + (d/dy)(du/dy) + lambda*u = f(x,y).
Computational Fluid Dynamics
Resources!
Computational Fluid Dynamics
A large number of pre-written software packages for the solution of elliptic equations is available!
Netlib is a collection of mathematical software, papers and databases. !
http://www.netlib.org/!
Computational Fluid Dynamics
Examples of elliptic equations!Direct Methods for 1D problems!Elementary Iterative Methods!Note on Boundary Conditions!SOR on vector computers!Iteration as Time Integration!Convergence of Iterative Methods—elementary considerations!Multigrid methods!Convergence of Iterative Methods—Formal Discussion!ADI for elliptic equations !!Krylov Methods!Fast Direct Method!Resources!
Computational Fluid Dynamics
The Advection-Diffusion equation!
The Cell Reynolds number!
Computational Fluid Dynamics
�
UΔt2D
≤1 & DΔth2
≤ 12
�
∂f∂t
+U ∂f∂x
= D∂ 2 f∂x 2
�
f jn+1 − f j
n
Δt+U
f j+1n − f j−1
n
2h= D
f j+1n − 2 f j
n + f j−1n
h2
1D Advection/diffusion equation!
Forward in time/centered in space (FTCS)!
Stability limits!R =
ULD
�
Δt = 2DU
& Δt = h2
2D
�
Δt→ 0 For high and low D!
Computational Fluid Dynamics
�
∂f∂t
+U ∂f∂x
= D∂ 2 f∂x 2
�
O Δt,h2( )FTCS!
�
UΔt2D
≤1 & DΔth2
≤ 12
�
O Δt,h( )Upwind!
�
UΔth
+ 2DΔth2
≤1
�
O Δt 2,h2( )L-W!
�
UΔth
⎛ ⎝ ⎜
⎞ ⎠ ⎟ 2
≤ 2 DΔth2
⎛ ⎝ ⎜
⎞ ⎠ ⎟ ≤1
�
O Δt 2,h2( )C-N! Unconditionally stable!
Computational Fluid Dynamics
Steady state solution to the advection/diffusion equation!
U ∂f∂x
= D∂ 2 f∂x2
Exact solution!
�
f =exp RL x /L( ) −1exp RL( ) −1
�
RL = ULD
�
f = 0
�
f =1
�
U
�
L
Computational Fluid Dynamics
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
RL=1!RL=5!RL=10!RL=20!
Computational Fluid Dynamics
�
U ∂f∂x
= D∂ 2 f∂x 2
�
Uf j+1 − f j−12h
= Df j+1 − 2 f j + f j−1
h2
Centered difference approximation!
Numerical solution of:!
�
Uf j − f j−1h
= Df j+1 − 2 f j + f j−1
h2
Upwind!
Computational Fluid Dynamics
Ufj+1 − f j−12h
= Df j+1 − 2 f j + f j−1
h2
Uh2
2hDfj+1 − fj−1( ) = fj+1 − 2 fj + fj−1
R =UhD
Where:!
Rearrange:!
Rearrange:!
R− 2( ) fj+1 + 4 fj − R + 2( ) fj−1 = 0
Centered difference approximation!
Computational Fluid Dynamics
fj = qj
Divide by !
Solution!
Substitute:!
R− 2( )qj+1 + 4qj − R+ 2( )qj−1 = 0
R− 2( )q2 + 4q1 − R+ 2( ) = 0
q j−1
R− 2( ) fj+1 + 4 fj − R + 2( ) fj−1 = 0
Computational Fluid Dynamics
Solving for q gives two solutions:!
q1 =1 and!
The general solution is:!
R− 2( )q2 + 4q1 − R+ 2( ) = 0
q2 =2 + R2 − R
fj = C1q1j + C2q2
j
fj = C1 + C22 + R2 − R
⎛ ⎝
⎞ ⎠
jor!
Computational Fluid Dynamics
Apply the boundary conditions!
f0 = C1 + C22 + R2 − R
⎛ ⎝
⎞ ⎠
0
= C1 + C2 = 0
fN = C1 + C22 + R2 − R
⎛ ⎝
⎞ ⎠
N
= 1
fj =
2 + R2 − R
⎛ ⎝
⎞ ⎠
j
−1
2 + R2 − R
⎛ ⎝
⎞ ⎠
N +1
−1
The final solution is:!
Computational Fluid Dynamics
�
Uf j − f j−1h
= Df j+1 − 2 f j + f j−1
h2
�
R + 2( ) f j − R +1( ) f j−1 − f j+1 = 0R =
UhD
�
f j = q j
�
q2 − R + 2( )q1 + R +1( ) = 0
�
f j =1− 1+ R( ) j
1− 1+ R( )NSolution!
Upwind!
Try solutions!
giving!
or!
Computational Fluid Dynamics
fj =
2 + R2 − R
⎛ ⎝
⎞ ⎠
j
−1
2 + R2 − R
⎛ ⎝
⎞ ⎠
N +1
−1
�
f =exp RL x /L( ) −1exp RL( ) −1
�
RL = ULD
R =UhD
Exact solution!
Centered differences!
Upwind!
�
f j =1− 1+ R( ) j
1− 1+ R( )N
Computational Fluid Dynamics
Upwind!
Exact!Centered!
Computational Fluid Dynamics
Upwind!
Exact!Centered!
Computational Fluid Dynamics
Upwind!
Exact!Centered!
Computational Fluid Dynamics
When centered differencing is used for the advection/diffusion equation, oscillations may appear when the Cell Reynolds number is higher than 2. For upwinding, no oscillations appear. In most cases the oscillations are small and the cell Reynolds number is frequently allowed to be higher than 2 with relatively minor effects on the result.!
�
R = UhD
< 2
Computational Fluid Dynamics
2D example!
�
∂f∂t
+U ∂f∂x
+V ∂f∂y
= D ∂ 2 f∂x 2
+ ∂ 2 f∂y 2
⎛
⎝ ⎜
⎞
⎠ ⎟
�
f =1Flow!
�
f = 0
�
f = 0
Compuitations using centered differences on a 32 by 32 grid!