Upload
others
View
19
Download
0
Embed Size (px)
Computational Fluid Dynamics
Computational Fluid Dynamics
http://www.nd.edu/~gtryggva/CFD-Course/
Grétar Tryggvason
Lecture 13March 6, 2017
Computational Fluid Dynamics
Numerical Methodsfor
Elliptic Equations-I
http://www.nd.edu/~gtryggva/CFD-Course/
Computational Fluid Dynamics
Examples of elliptic equationsElementary Iterative MethodsNote on Boundary ConditionsSOR on vector computersIteration as Time IntegrationConvergence of Iterative Methods—elementary considerationsMultigrid methodsFast Direct MethodConvergence of Iterative Methods—Formal DiscussionADI for elliptic equationsKrylov MethodsResources
Computational Fluid Dynamics
∂∂x
F = −S
Elliptic equations often arise due to the application of conservation principles to quantities whose fluxes are proportional to their gradient
where the flux is given by F = −α ∂ f∂x
gives ∂∂x
α ∂ f∂x
= S
∇ ⋅F = −SF = −α∇f
⎫⎬⎪
⎭⎪⇒∇ ⋅α∇f = S
In 2 or 3 dimension:
α∇2 f = S
If the transport coefficient is constant:
Computational Fluid Dynamics
�
∂∂xa∂f∂x
+ b∂f∂x
+ cf = s
One-Dimensional Boundary Value Problems
�
∂f∂xor f given
�
∂f∂xor f given
periodic
Notice that if f is not given on the boundary, f is not uniquely determined
Computational Fluid Dynamics
�
∂ 2 f∂x 2
+ ∂ 2 f∂y 2
= 0; ∇2 f = 0
�
∂∂xa∂f∂x
+ ∂∂yb∂f∂y
= S; ∇ ⋅ φ∇f = S
Laplace’s Equation
Poisson’s Equation
Two-Dimensional
SfSyf
xf =∇=
∂∂+
∂∂ 2
2
2
2
2
;
On the boundaries (BC) ),(
),(
0
0
yxgnf
yxff
=∂∂= Dirichlet
Neumann
Computational Fluid Dynamics
∂ 2 f∂x2
+∂ 2 f∂y2
+∂ 2 f∂z2
= 0
∂ 2 f∂x2
+∂ 2 f∂y2
+∂ 2 f∂z2
= s
∂∂xa∂f∂x
+∂∂yb∂f∂y
+∂∂zc∂f∂z
= s
Laplace’s Equation
Poisson’s Equation
Three-Dimensional
Computational Fluid Dynamics
ωψ −=∇2
Examples of Elliptic Equations
2-D stream function equation
Projection method(Step 2)
tjihjih t
P ,,2 1 u⋅∇
Δ=∇
kqT
−=∇2 Steady conduction equation
�
u ⋅ ∇f −∇2 f = 0 Steady state advection/diffusion
�
∇4 f = 0 Biharmonic equation
Computational Fluid Dynamics
Elementary Iterative Methods
Computational Fluid Dynamics
Solving the discrete Poisson equation
jijijijijijiji S
yfff
xfff
,21,,1,
2,1,,1 22
=Δ
+−+
Δ+− −+−+
(x, y)
i-1 i i+1
j+1 jj-1
�
fi, jn+1 = 1
4f i+1, jn + f i−1, j
n + fi, j+1n + f i, j−1
n − h2Si, j[ ] Jacobi
�
fi, jn+1 = 1
4f i+1, jn + f i−1, j
n+1 + fi, j+1n + f i, j−1
n+1 − h2Si, j[ ] Gauss-Seidel
SOR
�
fi, jn+1 = β
4f i+1, jn + f i−1, j
n+1 + fi, j+1n + f i, j−1
n+1 − h2Si, j[ ] + 1−β( ) fi, jn
Computational Fluid Dynamics
The most elementary iteration can be accelerated somewhat by Successive Over-Relaxation
j
j-1
j+1
i i+1i-1
for j=1:mfor i=1:n iterateendend
�
fi, jn+1 = β
4( f i+1, j
n + f i−1, jn+1 + fi, j+1
n + f i, j−1n+1 − h2Si, j
n )
+ (1−β) f i, jn
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.
Computational Fluid Dynamics
The iteration must be carried out until the solution is sufficiently accurate. To measure the error, define the residual:
�
Ri, j =f i+1, j + f i−1, j + fi, j−1 + f i, 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
Computational Fluid Dynamics
Example
Computational Fluid Dynamics
5 10 15 20 25 30 35 40
5
10
15
20
25
30
35
40
f=0.0
�
∂2 f∂x 2
+ ∂2 f∂y 2
= 0
f=1.0
Average absolute error: 0.001Number of iterationsJacobi: 1989Gauss-Seidler: 986
SOR (1.5): 320SOR (1.7): 162SOR (1.9): 91SOR (1.95): 202
Computational Fluid Dynamics
Note on Boundary Conditions
Computational Fluid Dynamics
1,if=
Boundary Conditions for Iterative Method
Dirichlet conditions are easily implemented.For Neumann condition, the simplest approach is
00 1,0, =−⇒=∂∂
ii ffnf
(1st order)
Update interior points and then set,,, 3,2,1, iii fff 1,0, ii ff =
This generally does not converge.
Instead, incorporate BC directly into the equations
�
fi,1 = 14
f i−1,1 + fi+1,1 + f i,2 + f i,0 − h2Si, j[ ]
�
fi,1 = 13f i−1,1 + fi+1,1 + f i,2 − h
2Si, j[ ]
Computational Fluid Dynamics
With only a few exceptions, Iterative Methods are used to solve systems of equations resulting from the discretization of elliptic equations or implicit methods in CFD
Computational Fluid Dynamics
SOR on Vector Computers
Computational Fluid Dynamics
�
fi, j = β4
f i−1, j + fi, j−1 + f i+1, j + f i, j+1[�
−h2Si, j ] + 1−β( ) fi, j
Coloring Scheme (Red & Black)
In large computer application (vector or parallel platform),SOR faces difficulties in using constantly updated values. Remedy: Two separate grid system (red & black)
�
fi, j = β4
f i−1, j + fi, j−1 + f i+1, j + f i, j+1[do i =1, nx, 2
do i=2, nx, 2
�
−h2Si, j ] + 1−β( ) fi, j
enddo
enddo
Computational Fluid DynamicsSuccessive Line Overrelaxation (SLOR) - 1
Line Relaxation Method (Line Gauss-Seidel Method)
Adding one more coupling
è Thomas algorithm
�
fi, jn+1 = 1
4f i−1, jn+1 + f i, j−1
n+1 + fi+1, jn + f i, j+1
n − h2Si, j[ ]
�
fi, jn+1 = 1
4f i−1, jn+1 + f i, j−1
n+1 + fi+1, jn+1 + f i, j+1
n − h2Si, j[ ]
�
− 14fi−1, jn+1 + f i, j
n+1 − 14f i+1, jn+1 = 1
4fi, j−1n+1 + f i, j+1
n − h2Si, j[ ]
New
New New
Old
Old
New
New New
Old
New
Computational Fluid Dynamics
SLOR = Line Relaxation + Overrelaxation
Apply line relaxation for intermediate solution
and then overrelax
which is no more complicated than line relaxation.
�
fi, jn +1 = β ˜ f i, j + 1−β( ) f i, j
n
�
− 14
˜ f i−1, j + ˜ f i, j −14
˜ f i+1, j = 14
f i, j−1n +1 + f i, j +1
n − h2Si, j[ ]
Successive Line Overrelaxation (SLOR) - 2Computational Fluid Dynamics
Although the iterative methods discussed here are important for understanding iterative methods, they are rarely used for practical applications due to their slow convergence rate.
The exception is the SOR method, which was widely used in the 70’s and early 80’s. Due to its simplicity, it is an excellent choice during code development or for runs where programming time is of more concern than computer time.
Computational Fluid Dynamics
Iteration versus time integration
Computational Fluid Dynamics
Jacobi as a time integration
∂ 2 f∂x2
+∂ 2 f∂y2
= 0
fi , jn+1 − fi , j
n
Δt=fi+1, jn + fi−1, j
n + fi, j−1n + fi, j+1
n − 4 fi, jn
h2
∂f∂t
=∂ 2 f∂x 2
+∂ 2 f∂y2
The solution of:
can be thought of as the steady-state solution of
Using the discretization derived earlier:
Boundary Value Problems
Computational Fluid Dynamics
fi , jn+1 = fi , j
n +Δth2
⎛ ⎝
⎞ ⎠ fi+1, j
n + fi−1, jn + fi, j−1
n + fi, j+1n − 4 fi, j
n( )or
fi , jn+1 = 1− 4Δt
h2⎛ ⎝
⎞ ⎠ fi , j
n +Δth2
⎛ ⎝
⎞ ⎠ fi+1, j
n + fi−1, jn + fi, j−1
n + fi, j+1n( )
Δth2
=14
Rearrange:
Select the maximum time step:
fi , jn+1 =
14
fi+1, jn + fi−1, j
n + fi , j−1n + fi, j+1
n( )Which is exactly the Jacobi iteration
Boundary Value ProblemsComputational Fluid Dynamics
While iterative methods can sometimes be viewed as integration in time, the fact that we are only interested in the “steady-state” solution allows us to take “short cuts” to get there as fast as possible.
Initial guess
Solution“time accurate” solution
Optimal path
Computational Fluid Dynamics
Convergence of Iterative Methods
Computational Fluid Dynamics
A One Dimensional Example
)(xFx =
for which convergence is achieved when
An equation in the form
can be solved by iterative procedure:
)(1 nn xFx =+
nn xx ≈+1 or ε<−+
11
n
n
xx
Convergence
When does the iteration converge?
Computational Fluid Dynamics
The above figure suggests that
Convergence
1≤dxdF for convergence
nx
1+nx
1<dxdF
1>dxdF
)(xFx =
Computational Fluid Dynamics
A One Dimensional Example
Convergence
For the linear equation
�
xn+1 = axn
�
a ≤1
We must have:
for convergence
Computational Fluid Dynamics
For multidimensional problems we have:
�
xα+1 =Mxα
For symmetric M it can be shown that its eigenvectors form a complete and orthogonal set and span the space of x. It is therefore possible to write:
�
x = y1v1 + y2v2 + = y jv jj∑
�
Mv j = λ jv j j =1…M × N
where
ConvergenceComputational Fluid Dynamics
Hence it is possible to write
�
y1α+1v1 + y2
α+1v2 + =M y1αv1 + y2
αv2 +( )= y1
αMv1 + y2αMv2 +
= y1αλ1v1 + y2
αλ2v2 +or
�
xα+1 =Mxα
as
�
y1α+1 = λ1y1
α
y2α+1 = λ2y2
α
Which are the same as for the 1-D example. Therefore:
�
λmax ≤1for convergence
Convergence
Computational Fluid Dynamics
MultigridMethods
Computational Fluid Dynamics
So far we have covered elementary iterative methods to solve elliptic equations. Of those the SOR method is the most useful, particularly for code development and debugging.
However, considerable effort has been devoted to the solution of elliptic equations and currently there exist a number of much more efficient methods. For codes intended for large problems where runtime is important you should use such a method
Multigrid methods are among the more popular ones
Multigrid Methods
Computational Fluid DynamicsMultigrid Methods
Basic Idea
Suppose we want to solve a 1-D elliptic equation
02
2
=−∂∂
gxf
An iterative process is analogous to solving an unsteadyproblem
⎟⎟⎠
⎞⎜⎜⎝
⎛−
∂∂=
∂∂
gxf
tf
2
2
α
And take it to the limit ∞→t
Computational Fluid Dynamics
Analytic Solution of
The equation can be solved by Fourier series
∑=k
ikxk etaf )(
and assume that can be expanded as
⎟⎟⎠
⎞⎜⎜⎝
⎛−
∂∂=
∂∂
gxf
tf
2
2
α
Substituting into the equation,
g
∑=k
ikxk ekbg 2
�
dakdtk
∑ eikx = −α ak (t) − bk( )k∑ k 2eikx
Multigrid Methods
Computational Fluid Dynamics
Solving for each
Therefore,
Rate of convergence
kk bta =∞→ )(
( )kkk btakdtda −−= )(2α
k
�
ak (t) − bk = ak (0) − bk( )e−αk 2t
⎟⎠⎞⎜
⎝⎛ = 2
2 1~k
k c ατα
High wave number modes damps out faster.
�
εk = ε0e−αk 2t( )
Multigrid Methods Computational Fluid Dynamics
For iterative method to solve elliptic equations,there are high wave number and low wave number components of errors that need to be damped out.
Consider a domain discretized by points1=L N
1 N
kL=2π
kH=2πN
Multigrid Methods
Computational Fluid Dynamics
This can also be visualized by following the decay of a initial conditions composed of two wavesf (x) = sin(2πx) + sin(10πx)
Multigrid Methods Computational Fluid Dynamics
For explicit time step, stability condition yields
If the error at various wave number decays at
where
αα
2;21 2
2
htht =Δ=Δ
tke2
0αεε −=
α2
2nhtnt =Δ=
( )2/exp/ 220 nhk−=εεè
( ) NkhNn HH ππεε
2forexp 222
0
=−=
( ) ππεε
2forexp 22
0
=−= LL khn
Short-wave errorsdecay much faster
Multigrid Methods
Computational Fluid Dynamics
1 Nt = 0
t = 5Δt
ε
1 N
ε
1 N
ε
t = 500Δt
Multigrid Methods Computational Fluid Dynamics
Multigrid Method – the Idea
- A low wave number component on a fine grid becomes a high wave number component on a coarse grid
- Use a coarse grid system to converge low wave number component of the solution rapidly- Map it onto the fine grid system to converge high wave number component.
( )220 exp/ hnL πεε −=
Multigrid Methods
Computational Fluid Dynamics
1D Example
Multigrid Methods Computational Fluid Dynamics
Example
d2 fdx2
= −g
�
fi+1 + f i−1 − 2 fih2
= −gi
Approximate by finite differences
Solve for fi
�
Ri = h2gi
�
fi = 12f i+1 + fi−1 + h2gi( ) = 1
2f i+1 + f i−1 + Ri( )
Multigrid Methods
Computational Fluid Dynamics
�
fi = 12f i+1 + fi−1 + h2gi( ) = 1
2f i+1 + f i−1 + Ri( )
Iterate until convergence is “slow” on a fine grid
giving an approximate solution (but not fully converged). Write the fully converged solution as the approximate solution plus a correction:
�
f = ˜ f + Δf
Substitute into
d2 fdx2
= −g
Multigrid Methods Computational Fluid Dynamics
The decomposition
�
d2Δfdx 2 + d2 ˜ f
dx 2 = −g
fj = ˜ f j + Δfj
gives
The correction is unknown, but the second derivative of the approximate solution is known, along with the source.Solve for the correction on a coarser grid
�
Δf ji
j
�
fi
Multigrid Methods
Computational Fluid Dynamics
On the coarser grid the correction is the unknown, but the second derivative of the approximate solution found on the finer grid is known
�
Δf ji
j
�
fi
�
Δf j+1 + Δf j−1 − 2Δf j4h2
= − f i+1 + fi−1 − 2 f ih2
− g j
The discretization is therefore:
Which can be solved iteratively as before
Multigrid Methods Computational Fluid Dynamics
Introduce
�
Δf ji
j
�
xi = fi, x j = Δf j , xk = ΔΔfk,…
�
fi�
ΔΔfkk
This approach can be generalized so that we solve for the correction to the correction on even coarser grids.
Where the x refers to f or the various corrections, depending on which grid we are working on
Multigrid Methods
Computational Fluid Dynamics
Δfj =12Δf j+1 + Δfj−1 + 4 h
2gj + fi+1 + fi−1 − 2 fi( )[ ]Δfj =
12Δf j+1 + Δfj−1 + Rj[ ]
Rj = 4 h2gj + fi+1 + fi−1 − 2 fi( )
On the j-grid, write:
or
where
�
Δf ji
j
�
fi
Multigrid Methods Computational Fluid Dynamics
�
Δx j = 12Δx j+1 + Δx j−1 + 4 2m h2g j + xi+1 + xi−1 − 2xi( )[ ]
�
Δx j = 12Δx j+1 + Δx j−1 + R j[ ]
�
R j = 4 2m h2g j + xi+1 + xi−1 − 2xi( )
or
where
�
Δx j
i
j
�
xi
This can be generalized to the coarser grids
Multigrid Methods
Computational Fluid Dynamics
when grid points overlap
xi = xi + Δxj
xi+1 = xi+1 + 0.5 Δxj + Δxj+1( )
i
j
when grid points do not overlap
Once the correction has been found, the solution on the finer grid can be corrected:
Transferring the source term to the coarser grid
Multigrid Methods Computational Fluid Dynamics
c 1D multigrid example from c MUDPACK c Solve f''(t)=-1, f(0)=f(1)=0 c--------------------------- real r(518),f(518),d0,d1,s,t,u Integer i,it,j,k,l,ll,m,n,nl k=6 n=2**k it=4 t=0.0001 u=0.7 c--------------------------- c input right side c--------------------------- do 10 i=1,n 10 r(i)=1.0 c--------------------------- c initialize c--------------------------- s=(1.0/n)**2 do 20 i=1,n 20 r(i)=s*r(i) m=n l=1 ll=n nl=n+n+k-2 do 30 i=1,nl 30 f(i)=0.0 d1=0.0 40 j=0
c--------------------------- c Gauss-Seidel Iteration c--------------------------- 50 d0=d1 d1=0.0 j=j+1 i=l 60 i=i+1 s=0.5*(f(i-1)+f(i+1)+r(i)) d1=d1+abs(s-f(i)) f(i)=s if(i .lt. ll) goto 60 write(*,*)' DIFF: ',d1 if(j .lt. it) goto 50 if(d1 .lt. t) goto 100 if((d1/d0) .lt. u) goto 50 if(n .eq. 2) goto 50 c--------------------------- c coarse mesh---slow convergence c--------------------------- i=ll+2 80 l=l+2 i=i+1 if(l .gt. ll)goto 90 f(i)=0.0 r(i)=4.0*(r(l)+f(l-1)-2*f(l)+f(l+1)) go to 80 90 n=n/2 write(*,*)' NUMBER OF MESH & INTERVALS: ',n ll=ll+n+1 l=l+1 go to 40
c--------------------------- c finer mesh---faster convergence c--------------------------- 100 if(n .eq. m)goto 120 i=l-3 j=ll 110 f(i)=f(i)+f(j) f(i+1)=f(i+1)+0.5*(f(j)+f(j+1)) i=i-2 j=j-1 if(j .gt. l)go to 110 n=n+n write(*,*)' NUMBER OF MESH & INTERVALS: ',n ll=l-2 l=i f(i+1)=f(i+1)+0.5*f(j+1) go to 40 c--------------------------- c print answer c--------------------------- 120 m=n+1 do 130 i=1,m j=i-1 s=j/float(n) 130 write(*,*)j,s,f(i) end
Multigrid Methods
Computational Fluid Dynamics
DIFF: .0151367188 DIFF: .0148925781 DIFF: .0147094727 DIFF: .0145568857 NUMBER OF MESH INTERVALS: 32 DIFF: .0283034556 DIFF: .02759392 DIFF: .0269906037 DIFF: .0264589582 NUMBER OF MESH INTERVALS: 16 DIFF: .0499347299 DIFF: .0472503528 DIFF: .0449317507 DIFF: .042871654 NUMBER OF MESH INTERVALS: 8 DIFF: .0743431076 DIFF: .0642947108 DIFF: .0558491573 DIFF: .0485739484 NUMBER OF MESH INTERVALS: 4 DIFF: .0656985492 DIFF: .0391116515 DIFF: .0212108791 DIFF: .0106054395 DIFF: .00530272722 DIFF: .00265136361 DIFF: .00132568181 DIFF: .000662840903 DIFF: .000331416726 DIFF: .000165700912 DIFF: 8.28504562E-05
1 .015625 .0076798778 2 .03125 .0151156718 3 .046875 .022309484 4 .0625 .0292593613 5 .078125 .0359672531 6 .09375 .04243109 7 .109375 .0486528128 8 .125 .0546303391 9 .140625 .06036558 10 .15625 .0658564717 11 .171875 .0711049736 12 .1875 .0761090368 13 .203125 .0808705986 14 .21875 .0853876173 15 .234375 .0896620676 16 .25 .0936919153 17 .265625 .0974791124 18 .28125 .101021625 19 .296875 .10432145 20 .3125 .107376538 21 .328125 .110188864 22 .34375 .112756386 23 .359375 .115081109 24 .375 .117160991 25 .390625 .118997991 26 .40625 .120590076 27 .421875 .121939234 28 .4375 .123043418 29 .453125 .123904586 30 .46875 .124520674 31 .484375 .124893673 32 .5 .125021532
33 .515625 .124906182 34 .53125 .124545574 35 .546875 .12394169 36 .5625 .123092458 37 .578125 .12199983 38 .59375 .12066175 39 .609375 .119080193 40 .625 .11725311 41 .640625 .115182482 42 .65625 .112866275 43 .671875 .110306486 44 .6875 .10750109 45 .703125 .104452103 46 .71875 .101157524 47 .734375 .0976193547 48 .75 .0938355625 49 .765625 .0898081064 50 .78125 .0855348781 51 .796875 .0810178071 52 .8125 .0762547851 53 .828125 .0712477341 54 .84375 .0659945831 55 .859375 .0604973249 56 .875 .0547549129 57 .890625 .0487679914 58 .90625 .0425367951 59 .921875 .0360607132 60 .9375 .0293390807 61 .953125 .0223717391 62 .96875 .0151590388 63 .984375 .00770158973 64 1. 0.
NUMBER OF MESH INTERVALS: 8 DIFF: .0155412592 DIFF: .00427171588 DIFF: .0011620149 DIFF: .000314570963 DIFF: .000181354582 DIFF: .000105820596 DIFF: 5.63040376E-05 NUMBER OF MESH INTERVALS: 16 DIFF: .0141811594 DIFF: .00453080423 DIFF: .00144574605 DIFF: .00047971122 DIFF: .000185795128 DIFF: .000103279948 DIFF: 9.19029117E-05 NUMBER OF MESH INTERVALS: 32 DIFF: .00879248697 DIFF: .00288156606 DIFF: .000945105217 DIFF: .000314788893 DIFF: .000117543153 DIFF: 6.65616244E-05 NUMBER OF MESH INTERVALS: 64 DIFF: .00484465947 DIFF: .00160129415 DIFF: .000529795885 DIFF: .000176671892 DIFF: 6.28554262E-05 0 0. 0.
Multigrid Methods Computational Fluid Dynamics
2D Example
Multigrid Methods
Computational Fluid Dynamics
Suppose we are solving a Laplace equation:
jijijijijijiji
ji Ry
fffx
fffLf ,2
1,,1,2
,1,,1,
22=
Δ+−
+Δ
+−= −+−+
and iterate until residual becomes smaller than tolerance 0, →jiR
Define ji
njiji fff ,,, Δ+=
ji
nji
ji
ff
f
,
,
,
Δ
Converged solutionSolution after n-th iterationCorrection
Multigrid Methods Computational Fluid Dynamics
Since
we have
0,,, =Δ+= jinjiji fLLfLf
and ji
nji RLf ,, =
jiji RfL ,, −=Δ Coarse grid correction
Steps: Fine grid solution è Interpolation onto coarse grid (restriction)è Coarse grid correctionè Interpolated onto fine grid (prolongation)è Converge on fine grid
Multigrid Methods
Computational Fluid Dynamics
Two-Level Multigrid Method - (nx+1, ny+1); (nx/2+1, ny/2+1)
1. Do n iterations on the fine grid (n = 3~4) using G-S
2. If then stop.3. Interpolate the residual onto the coarse grid
(restriction, injection)4. Iterations on the coarse grid
5. Interpolate the correction onto the fine grid
(prolongation)6. Go to 1.
jinji RLf ,, =
jiR ,
jiji RfL ,, −=Δjif ,Δ
ε<jiR ,
jinjiji fff ,,, Δ+=
Multigrid Methods Computational Fluid Dynamics
Details on ProlongationCoarse GridFine grid
jif ,Δ jif ,2+Δ
2, −Δ jif
jif ,2−Δ
2, +Δ jif Δfi+1, j =12
Δfi, j + Δfi+2, j( )Δfi, j+1 =
12
Δfi, j + Δfi, j+2( )Δfi+1, j+1
=14
Δfi+1, j + Δfi, j+1 + Δfi+1, j+2 + Δfi+2, j+1( )=14
Δfi, j + Δfi+2, j + Δfi, j+2 + Δfi+2, j+2( )
Multigrid Methods
Computational Fluid Dynamics
The process can be extended to multi-level grids(nx+1,ny+1), (nx/2+1,ny/2+1), (nx/4+1,ny/4+1), …, (3,3)
Various Strategies
V-Cycle W-Cycle
exact solution
Fine
Coarse
Multigrid Methods Computational Fluid Dynamics
Example: 4-Level V-Cycle
1. Iterate on Grid 1 for n times2. Restriction by injection to Grid 23. Iterate on Grid 2 (Save )4. Restriction by injection to Grid 35. Iterate on Grid 3
(Save )6. Restriction by injection to Grid 47. Iterate on Grid 4
1,, 0 ji
nji RLf ⇒=
1,
21 jiRI
1,
21,2 )( jiji RIfL −=Δ
1,
21,2 ,)( jiji RIfΔn
jijiji fLRIR ,21,
21
2, )(Δ+=
2,
32 jiRI2,
32,3 )( jiji RIfL −=Δ
2,
32,3 ,)( jiji RIfΔ
Fine è Coarse
njijiji fLRIR ,3
2,
32
3, )(Δ+=
3,
43,4 )( jiji RIfL −=Δ
3,
43 jiRI
Multigrid Methods
Computational Fluid Dynamics
1. Prolongate from Grid 4 to Grid 3
2. Iterate on Grid 3 (saved)3. Prolongate from Grid 3 to Grid 2
4. Iterate on Grid 2 (saved)5. Prolongate from Grid 2 to Grid 1
6. Iterate on Grid 17. If then stop. Else, repeat the entire cycle.
njifI ,4
34 )(Δ
2,
32,3 )( jiji RIfL −=Δ
Coarse è Fine
nji
nji
nji fIff ,4
34,3,3 )()()( Δ+Δ=Δ
njifI ,3
23 )(Δnji
nji
nji fIff ,3
23,2,2 )()()( Δ+Δ=Δ
1,
21,2 )( jiji RIfL −=Δ
njifI ,2
12 )(Δ
nji
nji
nji fIff ,2
12,, )(Δ+=
0, =jiLfε<jiR ,
Multigrid Methods Computational Fluid Dynamics
Test Problem (Tannehill et al, p. 170)- Laplace equation in a square domain - Dirichlet conditions on four boundaries- 5 Levels of resolution
9×9, 17×17, 33×33, 65×65, 129×129- 4 Methods
1. Conventional Gauss-Seidel (GS)2. Gauss-Seidel-SOR with optimal ω (GSopt )3. Multigrid with 2-level grids (MG2)4. Multigrid with maximum levels of grid (MGMAX)
Multigrid Methods
Computational Fluid Dynamics
Grid size GS GSωopt MG2 MGMAX9×9 62 19 19 17
17×17 215 40 40 19 33×33 715 75 95 20 65×65 2282 137 258 20
129×129 6826 282 732 21
Multigrid Methods “Equivalent” fine grid iterations (from Tannehill et al)
Computational Fluid Dynamics
A number of packages exist already and usually it is not necessary to write your own multigrid solver, particularly for simple geometries.
Multigrid methods are also used to solve steady-state problems such as flow over airplanes
See, for example:MUDPACK: Multigrid Software for Elliptic Partial Differential EquationsFortran Code with OpenMP Directives for Shared Memory Parallelismby John C. Adamshttp://www.cisl.ucar.edu/css/software/mudpack/
Multigrid Methods
Computational Fluid Dynamics
Algebraic Multigrid
Computational Fluid Dynamics
The multigrid algorithm discussed here is often referred to as Geometric Multigrid, since the coarsening is done on the grid used to discretize the equations
In some cases, particularly for for anisotropic coefficients, it is smoothing needs to account for the structure of the algebraic equations and the magnitude of the coefficients.
For complex unstructured meshes it can be difficult to identify a viable coarsening strategy
Algebraic Multigrid methods have been developed to deal with these situations by working directly with the coefficient matrix and ignoring all geometric information
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)
�
∂ 2 f∂x 2
+ ∂ 2 f∂y 2
= S
�
∂∂xa(x,y)∂f
∂x+ ∂∂yb(x,y)∂f
∂y= S
separable
non-separable
Computational Fluid Dynamics
The fast Fourier transform
�
f j ≡ ˆ f lei 2π
Nl j
l=1
N
∑
Can be evaluated in 2N log2N operations
inverse
�
ˆ f l ≡ f je− i 2π
Nlj
l=1
N
∑
The Cooley-Tukey algorithm
Computational Fluid Dynamics
Write
�
Δfk, j ≡ fk+1, j + fk−1, j + fk, j+1 + fk, j−1 − 4 fk, j( ) = bk, j
Take the double Fourier Transform
�
fk, j ≡ ˆ f l,mei 2π
Nkl + jm( )
m=1
N
∑l=1
N
∑
�
Δfk, j ≡ ˆ f l ,mei 2π
Nkl + jm( )
ei 2π
Nl
+ e−i 2π
Nl
+ ei 2π
Nm
+ e− i 2π
Nm− 4
⎛
⎝ ⎜
⎞
⎠ ⎟
m=1
N
∑l=1
N
∑
2cos
2πN
l + 2cos2πN
m − 4⎛⎝⎜
⎞⎠⎟
Computational Fluid Dynamics
Have
bk , j = b̂l ,mei 2πN
kl+ jm( )
m=1
N
∑l=1
N
∑
Δfk , j = −2 f̂l ,mei 2πN
kl+ jm( )2 − cos 2π
Nl + cos 2π
Nm⎛
⎝⎜⎞⎠⎟m=1
N
∑l=1
N
∑
�
Δfk, j = bk, j
f̂l ,m =−b̂l ,m
2 2 − cos 2πNl + cos 2π
Nm⎛
⎝⎜⎞⎠⎟
also
but
Solve:
Computational Fluid Dynamics
The algorithm is1 Find by FFT
2 Find as shown before3 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
Examples of elliptic equationsElementary Iterative MethodsNote on Boundary ConditionsSOR on vector computersIteration as Time IntegrationConvergence of Iterative Methods—elementary considerationsMultigrid methodsFast Direct MethodConvergence of Iterative Methods—Formal DiscussionADI for elliptic equationsKrylov MethodsResources