Numerical Solution of the Poisson Equation_mae237_1

Embed Size (px)

Citation preview

  • 8/8/2019 Numerical Solution of the Poisson Equation_mae237_1

    1/15

    Numerical Solution of the Poisson Equation

    MAE 237 Computational Fluid Dynamics

    Homework 1

    Roy Culver

    Department of Mechanical and Aerospace Engineering

    University of California, Irvine

    Irvine, CA 92612

    January 24, 2005

  • 8/8/2019 Numerical Solution of the Poisson Equation_mae237_1

    2/15

    Table of Contents

    1 Introduction 1

    2 Analytical Solution 2

    3 Numerical Methods 5

    3.1 Central Difference Discretization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

    3.2 Point Iterative Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

    3.2.1 Jacobian Iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

    3.2.2 Gauss-Siedel Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

    3.2.3 S.O.R. (Successive Over Relaxation) . . . . . . . . . . . . . . . . . . . . . . . . . 6

    3.3 Line Iterative Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

    3.3.1 S.L.O.R. (Successive Line Over Relaxation) . . . . . . . . . . . . . . . . . . . . . . 7

    3.3.2 A.D.I (Alternate Direction Implicit) . . . . . . . . . . . . . . . . . . . . . . . . . . 7

    3.4 Direct Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

    4 Results 9

    4.1 Numerical Convergence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

    4.2 Solution Accuracy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

    i

  • 8/8/2019 Numerical Solution of the Poisson Equation_mae237_1

    3/15

    List of Figures

    1 Duct geometry considered . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

    2 Plot of the Analytical Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

    3 Grid nodes used in our discretization scheme . . . . . . . . . . . . . . . . . . . . . . . . . 5

    4 Residual convergence history for different grids . . . . . . . . . . . . . . . . . . . . . . . . 9

    5 Time of convergence versus grid size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

    6 Error history between analytical solution and numerical solution . . . . . . . . . . . . . . . 11

    7 R.M.S. error versus x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

    8 Comparison of Analytical and Numerical Solutions to Poisson Equation . . . . . . . . . . . 12

    ii

  • 8/8/2019 Numerical Solution of the Poisson Equation_mae237_1

    4/15

    1 Introduction

    This paper presents a solution to the Poisson Equation representing steady, laminar flow through a square

    duct with a no slip boundary condition at the walls. For this type of flow, the governing equation is the axial

    momentum equation which can be simplified as seen in Equation 1 for the geometry shown in Figure 1.

    p

    z=

    2w

    x2+

    2w

    y2

    (1)

    where w(x, y) may be solved for with a given pressure gradient, pz

    and viscosit, . For constant pressure

    gradient and viscosity, we can nondimentionalize Equation 1 to arrive at

    Re =2w

    x2+

    2w

    y2(2)

    where Re is the corresponding Reynolds number. The no-slip boundary condition translates to

    w = 0 at x = 1, y = 1.

    1

    1

    Z

    X

    Y

    1

    1

    Figure 1: Duct geometry considered

    In this paper, solutions for the velocity distribution, w(x, y), for Re = 1000 will be obtained analytically

    and numerically. The numerical methods considered here include:

    1. Jacobi Iteration

    2. Gauss-Siedel Method

    3. S.O.R. (Successive Over Relaxation)

    4. S.L.O.R. (Successive Line Over Relaxation)

    5. A.D.I (Alternate Direction Implicit)

    Details of the numerical schemes used are given. Convergence histories for each numerical scheme

    are presented, and comparson to the analytical solution is made. Cacluations are conducted on different

    numerical grids of sizes 33 33, 65 65, 129 129, and 257 257.

    1

  • 8/8/2019 Numerical Solution of the Poisson Equation_mae237_1

    5/15

    2 Analytical Solution

    The governing equation for laminar, viscous, steady flow through a square duct is a linear P.D.E. in two

    dimensions. Analagous to solving an O.D.E., one method of solving this P.D.E. is to first find a particular

    solution which satisfies the full P.D.E. and assiciated boundary conditions, then solve the P.D.E. in homo-

    geneous form and combine the two solutions. There are several options for a particular solution, but one ofthe more simple forms is

    wp(x, y) =Re

    2(1 x2). (3)

    By simple examination we see that Equation 3 satisfies Equation 2 and its associated boundary conditions.

    Next we must solve the homogeneous form of the original P.D.E. which is exactly the Laplace equation

    in 2 dimensions. There are several ways to solve this, here we will use the seperation of variables. This

    method assumes that the solution is seperable and that it is of the form

    wh(x, y) = X(x)Y(y).

    If we assume this form of solution, we may substitute into the homogeneous form of Equation 2 to arrive at

    X(x)Y(y) + X(x)Y(y) = 0. (4)

    Rearranging Equation 4, we arrive at

    X(x)

    X(x)=

    Y(y)

    Y(y)= 2 (5)

    where is called a seperation constant. We know that the left hand side is a function of x only and the

    middle is a function of y only. If they are equal to each other than they must both be equal to a constant.

    The choice of2 is simply for conveneice.

    Rearranging once again, we now arrive at two seperate O.D.E.s which is the goal of the method. Those

    O.D.E.s are

    X(x) + 2X(x) = 0 (6)

    and

    Y(y) 2Y(y) = 0 (7)

    For Equation 6, we see that for non trivial solutions (i.e. X(x) = 0) we get solutions of the form

    X(x) = asin(x) + bcos(x).

    If we apply the boundary conditions that X(1) = 0, and X(1) = 0, and recognize that sin and cos areodd and even functions respectively, we may arrive at either of the two relations

    asin() =0

    bcos() =0

    From here we realize that we are forced to find a solution in terms of a seriese expansion. Since the only

    2

  • 8/8/2019 Numerical Solution of the Poisson Equation_mae237_1

    6/15

    values of a or b which satisfy this relation are 0, we make use of the periodicity of sin and cos to chose

    which satisfy the relation. For constant we can only satisfy one of these relations, so for this solution we

    arbitrarily chose bcos() = 0 and arrive at as

    = 2n+12 f or n = 0, 1, 2...etc. (8)

    Similar to the O.D.E. for X(x), for Equation 7, we see that for non trivial solutions (i.e. Y(y) = 0) we

    get solutions of the form

    Y(Y) = dsinh(y) + ecosh(y).

    Again, we must chose by which function we are to expand the solution, and for this solution we will use

    cosh. Combining our solutions, we now have a general solution for the homogeneous equation as

    wh(x, y) =

    n=0

    Cncosh(ny)cos(nx)

    where Cn is a distinct constant for each n such that the boundary conditions are satisfied, and n is given

    by Equation 8. If we now combine the homogenous and particular solutions we can apply the boundary

    conditions and solve for the constants Cn.

    w(x, y) =Re

    2(1 x2) +

    n=0

    Cncosh(ny)cos(nx) (9)

    Applying the boundary condtion w(x, 1) = 0, we can rearrange to get

    Re

    2(1 x2) =

    n=0

    Cncosh(n)cos(nx)

    Here we make use of the identity

    ll

    cosmx

    l

    cos

    nxl

    dx =

    0 m = n

    l m = n = 0

    to solve for the Cn coefficients. First we multiply by cos(mx) and integrate over the range 0 to 1.

    Re

    2

    10

    (1 x2)cos(mx)dx =n=0

    Cncosh(n)

    10

    cos(nx)cos(mx)dx (10)

    We then notice that the integral on the right hand side is equal to zero for all values of m = n, thus the

    summation dissapears and we are left with

    Re

    2

    10

    (1 x2)cos(nx)dx =Cn

    2cosh(n) (11)

    where we have changed the subscripts to n for simplicity. Evaluating the integral on the right by integration

    3

  • 8/8/2019 Numerical Solution of the Poisson Equation_mae237_1

    7/15

  • 8/8/2019 Numerical Solution of the Poisson Equation_mae237_1

    8/15

    3 Numerical Methods

    3.1 Central Difference Discretization

    y

    x

    (i,j1)

    (i+1,j)

    (i,j+1)

    (i1,j) (i,j)

    Figure 3: Grid nodes used in our discretization scheme

    There are many options for discretizing P.D.E.s to make them convenient to solve numerically. For our

    numerical solution to the Poisson Equation, we have chosen a second order central difference scheme to

    discretize the orignal governing equation. The resulting discretized form of Equation 1 is then

    w(i1,j) 2w(i,j) + w(i+1,j)

    x2+

    w(i,j1) 2w(i,j) + w(i,j+1)

    y2= q(i, j) (13)

    for all (i, j) within the domain of our solution. Here q(i, j) represents the source term which is exactly

    Re for our case. We note that this discretized equation approximates the original P.D.E., but it does not

    replicate it. As we solve Equation 13 numerically, we will see that the solution approaches the analytical

    solution as the grid resolution tends to infinity. That is

    limx0

    wnumerical = wanalytical

    Five different methods were used to solve Equation 13 and they will be described in the following

    section.

    3.2 Point Iterative Methods

    Point iterative methods start from an initial guess for the solution of the equation and evaluate the discretized

    equation for each w(i, j) in the domain. At this point, a residual defined by

    R(i, j) = w(i1,j) 2w(i,j) + w(i+1,j) + w(i,j1) 2w(i,j) + w(i,j+1) + q(i,j)h2 (14)

    is calculated for everypoint to be used as a measure of the convergence of the solution. Here we have

    replaced x and y with h to signify that we use only uniform grids for this solution (i.e. x = y)

    5

  • 8/8/2019 Numerical Solution of the Poisson Equation_mae237_1

    9/15

    As you can see by comparing Equations 13 and 14, when the residual approaches zero, we approach the

    solution to the central difference equation. From here we take the newly calculated values for w(i, j) as the

    initial guess and begin the process again.

    The methods presented here vary slightly in the way that they chose to evaluate the neighboring points

    as well as the replace old values with new ones.

    3.2.1 Jacobian Iteration

    The Jacobi Iteration method is the most straight forward of the iterations discussed here. As discussed above,

    the method starts from an initial guess, timestep (n), and uses the central difference equation to calculate

    new values, timestep (n + 1) of the solution as

    w(n+1)(i,j) =

    1

    4

    w(n)(i1,j) + w

    (n)(i+1,j) + w

    (n)(i,j1) + w

    (n)(i,j+1)

    +

    1

    4q(i,j)h

    2 (15)

    for the entire domain. Next a residual is calculated at each point in the domain. Next, timestep (n + 1)

    becomes timestep (n), and the process is repeated until the r.m.s. residual for the domain reaches the

    convergence criteria. For double precision caculations this criteria is generally used as

    Rcriteria = 1 1010

    3.2.2 Gauss-Siedel Method

    The Gauss-Siedel Method is very similar to Jacobian Iteration. The only difference is the way in which

    the neighboring values are collected. Whereas in the Jacobian method, only neighboring values from the

    previous timestep were used to calculated w(n+1)(i,j)

    , the Gauss-Siedel method includes neighboring values

    which have already been updated in the computation of each new value. The governing formula now looks

    like

    w(n+1)(i,j) =14

    w(n+1)(i1,j) + w

    (n)(i+1,j)

    + w(n+1)(i,j1) + w(n)(i,j+1)

    + 1

    4q(i,j)h

    2, (16)

    where w(i1,j) and w(i,j1) represent neighbors which have already been updated and may be used as

    updated values in computing w(n+1)(i,j)

    . Again, residuals are calculated after all w(i,j) have been computed,

    and the process is repeated until residual reach the convergence criteria. Because of the use of faster updating

    of the neighboring values, the Gauss-Siedel method converges faster than the Jacobian iteration method.

    3.2.3 S.O.R. (Successive Over Relaxation)

    The S.O.R. method employs the concept of over relaxation to point iteration. It may be encorporated with

    either Jacobian or Gauss-Siedel Iteration. For the solution computed here, we have used the Gauss-Siedel

    method of the base of the S.O.R. method to increase the speed of iteration.

    The method is based on the assumption that for certain well behaved functions, we may be able

    to overestimate our solution for each iteration and thus increase the speed of solution convergence. This

    assumption proves to be invalid for many nonlinear sets of equations, but for linear elliptic equaitons such

    as we have here, it is a good assumption. The method is implemented by changing the way in which we

    chose to update each value after a new value is computed. Instead of a newly computed value becoming the

    6

  • 8/8/2019 Numerical Solution of the Poisson Equation_mae237_1

    10/15

    value for the next time step, it becomes an intermediate value, w(), and we use the equation

    wn+1i,j = (1 )wni,j + w

    i,j

    where is called a relaxation parameter, to update the values at timestep (n + 1). For our equations, may

    take a value between 0 and 2. There is an optimal value, but since it is often difficult to compute, we havetested several values and chosen = 1.7 as it seems to work well for most of the computations perfomed

    here.

    3.3 Line Iterative Methods

    Line iterative methods differ from point iterative method in the respect that they iterate on a whole line of

    values at once as opposed to a single point. For the Poisson Equation, this makes the solution more implicit

    and requires the solution of a tridiagonal matrix at each line. The resulting formula is

    w(n+1)(i1,j)

    2w(n+1)(i,j) + w

    (n+1)(i+1,j) = w

    (n)(i,j1) + 2w

    (n+1)(i,j)

    w(n)(i,j+1)

    q(i,j)h2 (17)

    where the line is considered in the i direction and those neighbors in the j direction are considered as

    boundary conditions.

    In general, the matrix resulting from Equation 17 can be solved directly, but to save computational effort

    and make use of the orderly nature of a tridiagonal matrix, the Thomas Algorithm is used here.

    While direct solution of matricies can be very time consuming for large grid sizes, the Thomas Algorithm

    greatly reduces this time, and convergenece may be greatly accelerated due to the fact that many fewer

    iterations are needed to reach a converged solution than for point iterative methods. The concepts of Jacobian

    iteration, Gauss-Siedel iteration or over relaxation can easily be implimented with line iterative methods. To

    speed up the convergence of the solution, the Gauss-Siedel method was used as the base iteration scheme

    for both Line methods presented here, and overrelaxation was also used.

    3.3.1 S.L.O.R. (Successive Line Over Relaxation)

    The S.L.O.R. method as implemented here uses the Gauss-Siedel scheme as the base iteration scheme, and

    incorporates the concept over overrelaxation when replacing successive lines. After each matrix is solved,

    overrelaxed values replace the line of values. Once a sweep has covered the whole domain, residuals are

    calculated and the process is repeated until the residual reaches the convergence criteria.

    Without implimenting further convergence acceleration techniques, S.L.O.R. actually takes longer to

    converge than S.O.R. and thus it should not be used. Several acceleration techniques are discussed in the

    references.

    3.3.2 A.D.I (Alternate Direction Implicit)

    The A.D.I. method is a slight modification to the S.L.O.R. method in that two sweeps of the domain are

    conducted for each iteration. The first sweep is conducted in the i direction over each row, and all the row

    values are replaced. Next, a sweep is conducted in the j direction over each column, and the column values

    are replaced.

    7

  • 8/8/2019 Numerical Solution of the Poisson Equation_mae237_1

    11/15

    This method is significantly faster than the S.L.O.R. method and may be used to increase convergence

    time over S.O.R. without need for further convergence acceleration techniques.

    3.4 Direct Methods

    Direct methods for solving Equation 13 require solving a pentadiagonal matrix. Methods such as Gaussianelimination and specific pentadiagonal matrix solvers are common apporaches to this. While this can in

    principle be done, it is often very time consuming and less useful than iterative methods. For the sake of

    brevity these will not be discussed here. Please refer to the references.

    8

  • 8/8/2019 Numerical Solution of the Poisson Equation_mae237_1

    12/15

    4 Results

    4.1 Numerical Convergence

    Solutions were computed using all five numerical schemes discussed in Section 3. Convergence histories for

    five different grid resolutions are shown in Figure 4.1. Here we can see that the order of convergence stays

    constant for all cases. As we expect, increasing the implicitness and incorporate acceleration techniques

    makes the solution take fewer and fewer iterations to converge.

    i

    re

    s

    0 1000 2000 3000 400010

    -11

    10-9

    10-7

    10-5

    10-3

    10-1 Jacobian

    Gauss-Seidel

    SO R

    SLOR

    ADI

    Convergence Criteria

    (a) Grid size 33 33

    i

    res

    0 5000 10000 1500010

    -11

    10-9

    10-7

    10-5

    10-3

    10-1 Jacobian

    Gauss-SeidelSORSLORADI

    Convergence Criteria

    (b) Grid size 65 65

    i

    res

    0 10000 20000 30000 40000 5000010

    -11

    10-9

    10-7

    10-5

    10-3

    10-1 Jacobian

    Gauss-SeidelSOR

    SLORADI

    Convergence Criteria

    (c) Grid size 129 129

    i

    res

    0 50000 100000 15000010

    -11

    10-9

    10-7

    10-5

    10-3

    10-1 Jacobian

    Gauss-SeidelSOR

    SLORADI

    Convergence Criteria

    (d) Grid size 257 257

    Figure 4: Residual convergence history for different grids

    The time of computation is perhaps more important than the total number of iterations as very long

    iterations can be as inneficient as many very short iterations. Figure 5 is a plot of the time of convergence

    versus grid size for each method used. We notice that the fastest method is actually one of the point methods

    (S.O.R.) when used for the largest grid.

    9

  • 8/8/2019 Numerical Solution of the Poisson Equation_mae237_1

    13/15

    0 50 100 150 200 250 300Grid Size (Nx)

    0.01

    1

    100

    10000

    Time(Seconds)

    JacobianGauss-SiedelS.O.R.S.L.O.R.A.D.I.

    Figure 5: Time of convergence versus grid size

    4.2 Solution Accuracy

    The overall accuracy of the solution is in the end limited by the order of accuracy of the discretization

    scheme. Since we have used a second order discretization scheme we expect the error to be related to x2.

    In Figure 4.2 we see the error convergence histories at four different grid resolutions for each method used.

    We note that the final asmptotic error value decreases as we increas the resolution of the grid

    Figure 7 shows the converged root mean squared error values as a function of x. Here we see that

    the R.M.S. error actually seems to decrease by O(x3). Perhaps this is due to the number of fourier terms

    included in the analytical solution. For the analytical solution used for comparison here, the number of

    fourier terms used was 10. Taking more terms we should expect a more accurate analytical solution, which

    may explain the unexpected trend in error.

    Finally Figure 4.2 shows both the analytical solution a converged numerical solution given on the same

    grid using the A.D.I. method.

    10

  • 8/8/2019 Numerical Solution of the Poisson Equation_mae237_1

    14/15

    i

    e

    rr

    0 500 1000 1500 2000 2500 300010

    -3

    10-2

    10-1

    100

    101

    Jacobian

    Gauss-Seidel

    SO R

    SLOR

    ADI

    (a) Grid size 33 33

    i

    err

    0 2000 4000 6000 8000 1000010

    -4

    10-3

    10-2

    10-1

    100

    101

    Jacobian

    Gauss-Seidel

    SOR

    SLOR

    ADI

    (b) Grid size 65 65

    i

    err

    0 10000 20000 30000 40000 5000010

    -5

    10-4

    10-3

    10-2

    10-1

    100

    101

    Jacobian

    Gauss-Seidel

    SOR

    SLOR

    ADI

    (c) Grid size 129 129

    i

    err

    0 50000 100000 15000010

    -5

    10-4

    10-3

    10-2

    10-1

    100

    101

    Jacobian

    Gauss-Seidel

    SOR

    SLOR

    ADI

    (d) Grid size 257 257

    Figure 6: Error history between analytical solution and numerical solution

    References

    1. Stanley J. Farlow. Partial Differential Equations for Scientists and Engineers. Dover Publications Incorporated,

    1993.

    2. C.A.J. Fletcher. Computational Techniques for Fluid Dynamics, Vol. 1 and 2. Springer-Verlag, 1991.

    3. C. Hirsch. Numerical Computation of Internal and External Flows, Vol. 1 and 2. John Wiley, 1990.

    4. Feng Liu. Computational fluid dynamics. In Course Notes for MAE 237. University of California, Irvine, Depart-

    ment of Mechanial and Aerospace Engineering, 2005.

    11

  • 8/8/2019 Numerical Solution of the Poisson Equation_mae237_1

    15/15