Numerical Methods For Elliptic Equations
Numerical Methods For Elliptic Equations
Examples of elliptic equations! Direct Methods for 1D problems! Elementary Iterative Methods! Iteration as Time Integration! Example! Boundary Conditions! Convergence of Iterative Methods! !1D Example! !Formal Discussion!
Elliptic equations often arise due to the application of conservation principles to quantities whose uxes are proportional to their gradient!
! #f F = " S where the ux is given by! F = !" !x #x
! !f !f a + b + cf = s !x !x !x
!f or f given !x
gives!
! !f " =S !x !x
In 2 or 3 dimension:!
! " F = #S % & ) ! " $!f = S F = #$!f ( '
!f or f given !x periodic!
Two-Dimensional!
!2 f !2 f + = 0; " 2 f = 0 !x 2 !y 2
" f " f + = S; "x 2 "y 2
2 2
Laplace"s Equation!
Three-Dimensional!
!2 f = S
Poisson"s Equation!
!2 f ! 2 f ! 2 f + + =0 !x 2 !y 2 !z2
!2 f ! 2 f ! 2 f + + =s !x 2 !y 2 !z2
Laplace"s Equation!
! !f ! ! f a + b = S; " # $"f = S !x !x !y ! y
On the boundaries (BC) !
Poisson"s Equation!
f = f 0 ( x, y ) !f = g 0 ( x, y ) !n
Dirichlet! Neumann!
! !f ! !f ! !f a + b + c =s !x !x !y !y !z !z
" 2T = !
! q k
Steady conduction equation! 2-D stream function equation! Projection method! (Step 2)! Steady state ! advection/diffusion! Biharmonic equation!
$ 2" = #!
"2 hP i, j =
1 " h ! u ti , j #t
u ! "f # " 2 f = 0 !4 f = 0
!f !2 f "D 2 =0 !x !x
a j f j !1 ! d j f j + c j f j +1 = b j
Write out!
f !f f ! 2 f i + f i!1 U i +1 i!1 ! D i +1 =0 2h h2 R ( f i +1 ! f i!1) ! ( f i +1 ! 2 f i + f i!1 ) = 0 2 ! 1 $ ! 1 $ #1 + R& f i'1 ' 2 f i + #1 ' R& f i +1 = 0 " 2 % " 2 %
a j !1 f j !1 ! d j f j + c j +1 f j +1 = b j
d1 f1 + c1 f 2 a2 f1 + d2 f 2 + c 2 f 3
= b1 = b2
Uh R= D
! aN !1 f N ! 2 + dN !1 f N !1 + c N !1 f N = bN !1 aN f N !1 + dN f N = bN
If the endpoints are given!
b1 = ! a1 f 0 bN = !c N f N +1
Computational Fluid Dynamics I! One-Dimensional Boundary Value Problems! Matlab functions! For simple problems MATLAB has a number of functions to deal with matrices.! Help matfun: general! Help sparfun:sparse matrices!
( x, y )
!2 f !2 f + =S !x 2 !y 2
Applying central differencing!
f i , j +1 " 2 f i , j + f i , j "1 !y 2
= Si , j
Computational Fluid Dynamics I! Iterative Method! Discretized Poisson Equation! f i +1, j + f i !1, j + f i , j +1 + f i , j !1 ! 4 f i , j = h 2 Si , j Rearranging for ! f i , j 1 f i, j = [ f i +1, j + f i!1, j + f i, j +1 + f i, j !1 ! h 2 Si, j ] 4
The Jacobi iteration can be improved somewhat by using new values as soon as they become available.! j+1! j! j-1! i-1! i! i+1!
for j=1:m! for i=1:n! iterate! end! end!
1 n [ f i+1, j + f i!n1, j + f i,nj +1 + f i,nj!1 ! h 2Si, j ] 4 1 n [ f i+1, j + f i!n1,+1j + f i,nj +1 + f i,nj+!11 ! h 2Si, j ] 4
Jacobi ! Gauss-Seidel !
The Gauss-Seidler iteration can be accelerated even further by various acceleration techniques. The simplest one is the Successive Over-Relaxation (SOR) iteration!
The iteration must be carried out until the solution is sufciently accurate. To measure the error, dene the residual:!
f i,nj+1 =
Ri, j =
The SOR iteration is very simple to program, just as the Gauss-Seidler iteration. The user must select the coefcient. It must be bounded by 1<#<2. #=1.5 is usually a good starting value.!
At steady-state the residual should be zero. The pointwise 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 I! Boundary Value Problems! Jacobi as a time integration! The solution of: !
!2 f ! 2 f + =0 !x 2 !y 2
!f ! 2 f ! 2 f = + !t !x 2 !y 2
Using the discretization derived earlier: !
n+1
" !t n+1 n fi , j = fi , j + # 2 $ ( f n + f n + f in, j &1 + fi,nj +1 & 4 fin, j ) h % i +1, j i &1, j " t n # "t % n # = $1 ! 4 2 % f + (f + f n + f n + f n ) h & i , j $ h2 & i +1, j i !1, j i, j !1 i, j +1
Rearrange:!
Example !
n+1 i,j
!t 1 = h2 4
fi , j =
n+1
1 n ( f + f n + f n + fn ) 4 i+1, j i !1, j i , j !1 i, j +1
40
!2 f !2 f + =0 !x 2 !y 2
T=1.0!
35
30
25
20
T=0.0!
15
10
10
15
20
25
30
35
40
% two-dimensional steady-state problem by SOR! n=40;m=40;nstep=5000;alpha=0.05;length=2.0;h=length/(n-1);! T=zeros(n,m);bb=1.7;! T(10:n-10,1)=1.0; ! for l=1:nstep,! 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,end! end;! contour(T);!
40
35
Average absolute error: 0.001! !Number of iterations! Jacobi: ! 1989! Gauss-Seidler: 986! SOR (1.5): ! SOR (1.7): ! SOR (1.9): ! SOR (1.95): 320! 162! 91! 202!
30
25
20
15
10
10
15
20
25
30
35
40
0.8 0.6
0.4 0.2 0 40 30 20 10 0 0 20 10 30 40
Computational Fluid Dynamics I! Boundary Conditions for Iterative Method! Dirichlet conditions are easily implemented.! For Neumann condition, the simplest approach is !
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!
f i,1 =
1 [ f i!1,1 + f i+1,1 + f i,2 + f i,0 ! h 2Si, j ] 4 1 f i,1 = [ f i!1,1 + f i +1,1 + f i,2 ! h 2 Si, j ] 3
= f i ,1
Examples of elliptic equations! Direct Methods for 1D problems! Elementary Iterative Methods! Iteration as Time Integration! Example! Boundary Conditions! Convergence of Iterative Methods! !1D Example! !Formal Discussion!
Computational Fluid Dynamics I! Convergence! A One Dimensional Example! An equation in the form!
x = F ( x)
can be solved by iterative procedure:!
x n +1 = F ( x n )
for which convergence is achieved when !
x n +1 ! x n
or!
x n +1 "1 < ! xn
dF >1 dx dF <1 dx
x = F ( x)
x n +1 = ax n
We must have:!
a !1
The above gure suggests that!
dF !1 dx
xn
for convergence!
for convergence!
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: ! as!
x ! +1 = Mx !
! +1 +1 ! ! y1 v1 + y ! 2 v 2 + ! = M( y1 v1 + y 2 v 2 + !) ! = y1 Mv1 + y ! 2 Mv 2 + ! ! = y1 "1v1 + y ! 2 "2 v 2 + !
x = y1v1 + y 2 v 2 + ! = ! y j v j
j
or!
! +1 ! y1 = "1 y1
where!
Mv j = ! j v j
j = 1 M " N
! +1 2
=" y !
! 2 2
!max " 1
for convergence!
0 0 " 1 0 " " " # & f1,1 # & S1,1 # &' 4 1 $S ! $ 1 ' 4 1 0 " 0 1 " " " !$ f ! $ 1, 2 ! $ ! $ 1, 2 ! $ ! ! $0 1 ' 4 1 " " 0 1 " " !$ ! ! ! $ ! $ !$ $ S1, J ! $ ! ! $ f1, J ! $ S 2,1 ! $ ! ! $ f 2,1 ! ! = h2 $ ! $ !$ 0 $ S 2, 2 ! $1 ! $ f 2, 2 ! $ ! ! $0 !$ ! ! 1 ! $ ! $ !$ 0 1 $ ! ! $0 !$ ! ! ! $S ! $ !$ f $ I , J '1 ! $ ! $ I , J '1 ! $ f I ,J " ! $ SI ,J " ! $ !% 0 1 ' 4" % %
A few denitions:!
Ultimately, the difference form of the Poisson equation! boils down to solving for!
a 0 0 0 b d 0 0 c$ & e& f& & 0% !0 # a [L] = # #b # "d 0 0 c e 0 0 0 f 0$ & 0& 0& & 0%
!a # 0 [D] = # #0 # "0
0 b 0 0
0 0 c 0
!0 # 0 [U ] = # #0 # "0
[ A]f = b
Hence,!
f = [ A] b
!1
Diagonal!
Upper triangular!
Lower! triangular!
Direct method:! - Solving inverse matrix directly (Cramer"s rule)! - Inverting matrix more cleverly (Gaussian elimination)! - Other (L-U decomposition, Thomas algorithm)!
Computational Fluid Dynamics I! Convergence Multi Dimensional -1! General iterative procedure!
Gaussian Elimination! -$ Pivoting: rearranging equations to put the largest! coefcient on the main diagonal.! -$ Eliminate the column below main diagonal.! -$ Repeat until the last equation is reached.! -$ Back-substitution!
a11 f1 + a12 f 2 + !! = c1 a21 f1 + a22 f 2 + !! = c2 " " an1 f1 + an 2 f 2 + !! = cn a11 f1 + a12 f 2 + "" = c1 ! f 2 + "" = c2 a22 ! ! ! f n = cn ann
[ A]f = b
Let!
[ A] = [ A1 ] ! [ A2 ] [ A1 ]f = [ A2 ]f + b
[ A1 ]f n +1 = [ A2 ]f n + b
For example, !
Computational Fluid Dynamics I! Convergence Multi Dimensional -3! Condition for convergence!
[ A1 ]f n +1 = [ A2 ]f n + b
Requirements:! 1.$ [ A1 ] should be invertible.! 2.$ Iteration should converge, i.e.! lim f n = f
n !"
lim e n = 0
n !"
#1
[ A2 ])
=0
This is achieved if the modulus of the eigenvalues are ! less than unity.! Therefore, the convergence condition becomes:!
[ A1 ]e n +1 = [ A2 ]e n
e n +1 = [ A1 ]
!1
[ A2 ]e n
n
# = "i
max
!1
e n = [ A1 ]
!1
[ A2 ])
e0
Computational Fluid Dynamics I! Convergence Jacobi Method -1! Jacobi Iteration Method for Poisson Equation! !(2nd order central difference with uniform mesh)! 1 n n n 2 f i,nj+1 = [ f in +1, j + f i!1, j + f i, j +1 + f i, j !1 ! h S i, j ] 4
Computational Fluid Dynamics I! Convergence Jacobi Method -2! For a large matrix!
*mn ,max =
[ A1 ]
!1
= [ I]
and using a discrete analog of separation of variables, ! it can be shown that the eigenvalues of [A2 ] are!
)mn
Thus, for a large matrix, !mn ,max is only slightly less! than unity.! ! Very slow convergence!
Therefore,
Computational Fluid Dynamics I! Convergence Gauss-Seidel -1! Gauss-Seidel Iteration Method for Poisson Equation! !(2nd order central difference with uniform mesh)! 1 n +1 n n +1 2 f i,nj+1 = [ f in +1, j + f i!1, j + f i, j +1 + f i, j !1 ! h S i, j ] 4
Computational Fluid Dynamics I! Convergence Gauss-Seidel -2! It can be shown that the eigenvalues of matrix! [ A1 ] [ A2 ] are simply square of the eigenvalues of Jacobi method !
!1
[ A1 ] = [D] ! [L], [ A2 ] = [U ]
"4 0 0 $ $!1 4 0 $ 0 !1 4 $ $ 0 0 !1 $" " " $ #0 ! !
n +1% "0 0%" f1,1 '$ n +1' $ 0'$ f1,2 ' $0 0'$ " ' $0 '=$ '$ 0'$ " ' $" ! " '$ " ' $" ' $ '$ 0 !1 4&# f In,J+1& #0
(mn ,max =
0 0 0 4
! ! ! !
n % " S1,1 % 0 ! 0%" f1,1 $ ' '$ n ' 0 ! 0'$ f1,2 ' $ S1,2 ' 1 ! 0'$ " ' 2 $ " ' '! h $ ' '$ " " '$ " ' $ " ' $ " ' " 0 " '$ " ' $ ' '$ n ' 0 0 0 ! 0&# f M #SM ,N & ,N &
1 0 0 "
0 1 0 "
A1!
A2!
Computational Fluid Dynamics I! Successive Overrelaxation - 1! Successive Overrelaxation! Consider the Gauss-Seidel method!
Computational Fluid Dynamics I! Successive Overrelaxation - 2! Hence, SOR rst uses Gauss-Seidel to compute ! ~ intermediate solution, !f
([D] ! [L])f n +1 = [U ]f n + b
If Gauss-Seidel is an attempt to change the solution as!
([D] ! [L])f = [U ]f n + b
= [ L ]f + [U ]f + b or! [ D]f
n
n +1
=f +d
n
! + (1 " ! ) f n ! " f n = !f f n +1 = f n + ! f
f n + 1 = f n + ! d, ! > 1
f n +1 =
! ([L]f + [U ]f n + b) + (1 " ! )f n c
since ! [ D] = c [ I ]
Computational Fluid Dynamics I! Successive Overrelaxation - 3! Example: Poisson Equation (2nd order CD, uniform mesh) !
f i +1, j + f i !1, j + f i , j +1 + f i , j !1 ! 4 f i , j = h 2 Si , j
G-S!
= [ L ]f + [U ]f n + b [D]f
f i,nj+1 =
Combining!
= [ L ]f + [U ]f n + b [D]f
f n +1 =
! ([L]f + [U ]f n + b) + (1 " ! )f n c
n +1 i, j
!1
+ [ I ] ! " [ D]
!1
!1
Computational Fluid Dynamics I! Successive Overrelaxation - 5! For the discretized Poission operator, it can be shown that that eigenvalues of the SOR matrix are:!
Computational Fluid Dynamics I! Successive Overrelaxation - 6! For problems with irregular geometry and non-uniform ! mesh, ! opt must be found by trial and error.! Typical Comparison Chart !
1/ 2 =
! !max ( max ) Iterations Jacobi! Gauss-Seidel! 0.9945 ! 0.9890 ! 0.7906 ! 1250 ! 625 ! 29 !
if ! = 1 (Gauss-Seidel) ! Typically!
2 max
" opt =
2 1+ 1# !
SOR!
"max ! 1
Examples of elliptic equations! Direct Methods for 1D problems! Elementary Iterative Methods! Iteration as Time Integration! Example! Boundary Conditions! Convergence of Iterative Methods! !1D Example! !Formal Discussion! SOR on vector computers!
Computational Fluid Dynamics I! Coloring Scheme (Red & Black)! In large computer application (vector or parallel platform),! SOR faces difculties in using constantly updated values. ! Remedy: Two separate grid system (red & black)! do i =1, nx, 2! ! f i, j = [ f i"1, j + f i, j "1 + f i +1, j + f i, j +1 4 !h 2 Si, j ] + (1 ! " ) f i, j enddo! do i=2, nx, 2! ! f i, j = [ f i"1, j + f i, j "1 + f i +1, j + f i, j +1 4 !h 2 Si, j ] + (1 ! " ) f i, j enddo!
Computational Fluid Dynamics I! Successive Line Overrelaxation (SLOR) - 1! Line Relaxation Method (Line Gauss-Seidel Method)!
Computational Fluid Dynamics I! Successive Line Overrelaxation (SLOR) - 2! SLOR = Line Relaxation + Overrelaxation! Apply line relaxation for intermediate solution!
f i,nj+1 =
+ (1 " ! ) f n f i,nj+1 = ! f i, j i, j
which is no more complicated than line relaxation. !
Computational Fluid Dynamics I! Successive Line Overrelaxation (SLOR) - 3! Notes on SLOR! -$ Exact eigenvalues are unknown.! -$ To ensure convergence, !" ! 2 -$ Converges approximately twice as fast as Gauss-Seidel.! -$ May be faster than pointwise SOR, but each iteration! takes longer with Thomas algorithm.! -$ Improved convergence is due to the direct effect of the! boundary condition in each row.!
Computational Fluid Dynamics I! Alternating-Direction Implicit - 1! ADI for elliptic equation is analogous to ADI in parabolic! equation! # !2 f !2 f & !f ="% 2 + 2 ()S !t !y ' $ !x In discrete form!
[( f [( f
n +1/ 2 i +1, j
"!t n -$ Iteration parameter # n = usually varies with iteration! 2 -$ For example (Wachspress)!
n +1/ 2 i +1, j
or!
(1 ! " # ) f
n yy
n +1
= (1 + " n#xx ) f
n +1/ 2
! Si$$ ,j
(k (1)/ (n (1)
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. !