NumMethPDEs

Embed Size (px)

Citation preview

  • 8/6/2019 NumMethPDEs

    1/14

    Numerical Methods for time-dependent Partial

    Differential Equations

    J.W.Haverkort

    April 2009

    Abstract

    This is a summary of the course Numerical Methods for time-dependent

    Partial Differential Equations by P.A. Zegeling of spring 2009.

    Contents

    1 General 2

    1.1 Classification of PDEs . . . . . . . . . . . . . . . . . . . . . . . . 21.2 Fourier domain . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.3 Method of undetermined coefficients . . . . . . . . . . . . . . . . 21.4 Equivalence theorem . . . . . . . . . . . . . . . . . . . . . . . . . 31.5 Method of lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.6 Stability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

    1.6.1 Eigenvalue method . . . . . . . . . . . . . . . . . . . . . . 31.6.2 Von Neumann stability analysis . . . . . . . . . . . . . . . 4

    1.7 Numerical diffusion . . . . . . . . . . . . . . . . . . . . . . . . . . 41.8 CFL condition . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

    2 Various schemes 6

    2.1 Heat equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62.2 Linear Advection equation . . . . . . . . . . . . . . . . . . . . . . 72.3 Non-linear advection equation . . . . . . . . . . . . . . . . . . . . 92.4 Wave equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92.5 Advection-diffusion equation . . . . . . . . . . . . . . . . . . . . 10

    3 Higher order methods 11

    3.1 Finite Differences . . . . . . . . . . . . . . . . . . . . . . . . . . . 113.2 Spectral methods . . . . . . . . . . . . . . . . . . . . . . . . . . . 113.3 Non-uniform grids . . . . . . . . . . . . . . . . . . . . . . . . . . 11

    4 Adaptive Mesh Refinement 12

    4.1 Mapping method . . . . . . . . . . . . . . . . . . . . . . . . . . . 124.2 Equidistribution principle . . . . . . . . . . . . . . . . . . . . . . 134.3 Choices of Monitor functions . . . . . . . . . . . . . . . . . . . . 134.4 Possible Problems . . . . . . . . . . . . . . . . . . . . . . . . . . 13

    1

  • 8/6/2019 NumMethPDEs

    2/14

    1 General

    1.1 Classification of PDEs

    Second order equations of the form

    auxx + buxy + cuyy = f(ux, uy, x , y) (1)

    can be categorized on the basis of the discriminant b2 4ac:

    b2 < 4ac: elliptic, e.g. a Poisson equation uxx + uyy = f(x, y)

    b2 > 4ac: hyperbolic, e.g. wave equation utt uxx/c2 = 0

    b2 = 4ac: parabolic, e.g. (advection-)diffusion ut + cux = uxx

    Parabolic equations often use a mixed set of conditions, namely an initialcondition combined with a boundary condition. In order to solve a hyperbolicequation, two sets of initial conditions must be specified. Elliptic equationsdiffer from the other two types of PDEs in that they typically involve onlyspatial coordinates. Because of this, the initial conditions become boundaryconditions, i.e., the value of the function along the boundaries is completelyspecified.

    1.2 Fourier domain

    One can Fourier-transform the quantities u(x) = u()e

    ixd of a linearPDE to arrive at an ODE, which can then be solved and transformed back toarrive at the solution of the initial PDE.

    hyperbolic - advection-equation: ut + cux = 0 ut(, t) + ciu(, t) u(, t) = u(, 0)()eict u(x, t) = 1

    2

    u(, 0)()e

    i(xct)d. Thesolution moves to right without changing shape, only the phase of modesis modified

    parabolic - heat equation: ut = uxx = 0 ut(, t) = 2u(, t)showing exponential decay, with the highest decay rate for the highestfrequencies

    1.3 Method of undetermined coefficients

    In this method derivatives are approximated by a linear combination of function

    values and the coefficients are chosen such that the result is exact for certainsimple functions (linear, quadratic, etc). Expanding in Taylor series aroundx = x0

    ui+1 = ui + hux,i + h2uxx,i + .. (2)

    ui = ui (3)

    ui1 = ui hux,i + h2uxx,i + .. (4)

    such that uxx|i Aui+1 + Bui + Cui1 = A(ui + hux,i + h2uxx,i + ..) +Bui + C(ui hux,i + h2uxx,i + ..). Collecting coefficients by their order in h:A + B + C = 0, Ah + 0 Ch = 0 and Ah2/2 + 0 + Ch2/2 = 1 such that

    2

  • 8/6/2019 NumMethPDEs

    3/14

    uxx|i

    ui+1 2ui + ui1

    h2 (5)

    The error term or local truncation error (LTE) = Ah4/24+0+Ch4/24)uxxxx,i =h2/12uxxxx,i + ... This finite difference (FD) scheme is said to be of order twoin space, or O(x2). Here

    f(s) = O((s)) if a constant A such that |f(s)| A |(s)| s S (6)

    Note that A can be very large, especially in problems where the solutionschanges rapidly in time. A scheme is said to be consistent if in the limit x 0the finite difference operators converge to the continuous operators.

    1.4 Equivalence theorem

    The Lax Equivalence theorem for linear PDEs: consistency (local error)+ stability convergence (global error)

    Lax-Richtmeyer Equivalence theorem: given a well-posed linear hyperbolicPDE and its FD approximation which satisfies the consistence condition,then stability is the necessary and sufficient condition for convergence

    1.5 Method of lines

    In this method one discretizes in space first and then integrates in the timedirection to obtain the solution. It is easy to implement, just use your favourite

    time integration method, it is transparent for understanding stability aspectsbut it is not as efficient as specially designed methods that discretize in spaceand time simultaneously. As an illustration of this method, the FTCS schemefor the heat equation (see Ch. 2) can be written u(t) = Au(t) which can beintegrated to yield u(t). As an example one can use Euler Forward (EF):

    u(t + t) u(t)

    t= Au(t) (7)

    1.6 Stability

    1.6.1 Eigenvalue method

    Consider the eigenvalue problem u(t) = u(t) with u(0) = u0 with the exact

    solution consisting of oscillations or exponential growth/decay depending on C. Discretizing using EF gives at a time t = nt the solution un = u0(1+t)

    n.This solution by EF is stable for |1 + t| 1 constituting a circular stabilityregion centred around z t = 1. After discretizing a particular equationin space one generally obtains a matrix analogue of the discussed 1D-example:u = Au. In this case a similar stability analysis can be made, but now usingthe eigenvalues of the matrix A:

    A method is stable of t S, where is any eigenvalue of A and S =stability region of the ODE method.

    3

  • 8/6/2019 NumMethPDEs

    4/14

    The eigenvalues of the matrix A depend on the equation you are solving and

    the scheme that is used. For the Forward in Time Central in Space (FTCS)discretization of the heat equation the eigenvalues are p =4x2 sin

    2 px2 along

    the negative real axis. The method using EF is therefore stable for tx2 12

    ,constituting a severe restriction.

    The following examples are discussed further in Ch. 2. Here we just notethe stability region of the time integration with z t

    FTCS: S = {z C| |1 + z| 1}

    Crank-Nicolson: S = {z C|{z} 0}

    BTCS: S = {z C| 1|1z| 1}

    1.6.2 Von Neumann stability analysisAssume the distribution of errors along the coordinate x at time level n is givenby a Fourier series in x:

    n(x) = eat

    m0eimx (8)

    When the finite difference equations are linear, the behaviour of each sepa-rate term of the series behaviour of the whole series. Just dealing with oneterm of the series, one inserts nm = e

    ateimx in the FD equation. We have

    g

    n+1mnm

    = eat (9)

    where the amplification factor should be g 1 for stability. As an examplewe consider the FTCS discretization of the heat equation. We assume unj =Unj +

    nj with U the exact solution of the discretized equation and

    nj the round-

    off error. Inserting uj into the discretized equations and subtracting the sameequation, only now with the exact solution Unj inserted, yields by linearity onlythe difference

    n+1j nj

    t=

    nj+1 2nj +

    nj1

    (x)2(10)

    Inserting nj = eateimx and dividing by eateimx gives

    eat 1

    t =

    eimx 2 + eimx

    (x)2 (11)

    The growth factor is thus eat = 1 4t(x)2 sin(mx/2)2, thereby yielding the

    same result for stability as the eigenvalue method. The criterion g 1 yieldst/(x)2 1/2, the familiar result.

    1.7 Numerical diffusion

    Several FD schemes that are consistent with the equation they are intended tosolve actually solve a modified equation with an extra diffusion-like term. Forpositive diffusion constant this enhances the stability properties of the scheme.

    4

  • 8/6/2019 NumMethPDEs

    5/14

    When this numerical diffusion constant however becomes negative, the scheme

    is rendered unconditionally unstable. Some examples of occuring numericaldiffusion constants are in the Lax-Friedrichs scheme (LF), the Lax-Wendroffscheme (LW) and the upwind scheme (upw)

    LF =(x)2

    2t, LW =

    c2t

    2, upw =

    cx

    2(12)

    1.8 CFL condition

    Courant-Friedrichs-Lewy (1928) stated that for stability: the CFL number = ct/x has to be chosen such that the domain of dependence of thePDE, the characteristic lines has to be within the domain of dependence ofthe FD-scheme. This implies that the FD-scheme must include all physical in-

    formation which influences the system at xj, t

    n+1

    . The collection of points in(x,t)-space needed in the evaluation of one new value of the solution is calledthe stencil of the scheme. By the CFL criterion the width of the stencil inthe x-direction at a time t t, cannot be larger than ct

    This criterion is necessary, not sufficient for stability. It is however sufficientfor LF and upwind. Usually it overlaps with the stability criterion resultingfrom a von Neumann analysis.

    5

  • 8/6/2019 NumMethPDEs

    6/14

    2 Various schemes

    2.1 Heat equation

    ut = uxx (13)

    Forward Time Centred Space (FTCS):

    un+1i uni

    t=

    uni+1 2uni + u

    ni1

    x2(14)

    = O(t, x2)

    Backward Time Centred Space (BTCS):

    un+1i uni

    t

    = un+1i+1 2u

    n+1i + u

    n+1i1

    x2(15)

    This is an implicit method. It is unconditionally stable, as is easily ob-tained using a von Neumann stability analysis. Each time step the matrixequation Aun+1 = un has to be solved, where A is a tridiagonal matrixwith non-zero elements , 1 + 2 and , where = t/(x)2

    Leapfrog:un+1i u

    n1i

    2t=

    uni+1 2uni + u

    ni1

    x2(16)

    = O(t2, x2) For this three-level scheme extra starting values areneeded. It can be shown to be unconditionally unstable for the heatequation. It is however still occasionally used by some people, and itmight work for small times.

    Dufort-Frankel:

    un+1i un1i

    2t=

    uni+1 un+1i u

    n1i + u

    ni1

    x2(17)

    This scheme is inconsistent for t/x = constant. It actually solvesut + 2utt = uxx. = O(t2, x2) utt|

    ni

    2

    Crank-Nicolson (or trapezoidal).

    un+1i uni

    t=

    2

    (uni+1 2u

    ni + u

    ni1

    )+(

    un+1i+1 2un+1i + u

    n+1i1

    )x2

    (18)

    = O(t2

    , x2

    ). This scheme is implicit, one needs to solve a tridiagonallinear system for un+1i .

    In two dimensions one just uses the same second derivative discretization asone would use in one dimension to evaluate 2u, keeping the y-index j fixed inevaluating uxx and keeping the x-index i fixed in evaluating uyy to obtain a FDequation for unij . Using EF on a rectangular grid with grid size h yields a stability

    criterion oft/h2 1/4, i.e. two times as strict as in one dimension. A betterchoice would be a trapezoidal (CN) time integration, which is unconditionallystable and second order accurate in time. This requires, however, an expensivematrix inversion with a sparse matrix which is no longer tridiagonal, but consistsof three non-zero element bands. Perhaps a better option is

    6

  • 8/6/2019 NumMethPDEs

    7/14

    Alternative direction scheme. This is an example of a splitting method

    which uses two half-time steps

    un+1/2j,k u

    nj,k

    t/2=

    (x)22xu

    n+1/2j,k +

    (y)22yu

    nj,k (19)

    un+1j,k un+1/2j,k

    t/2=

    (x)22xu

    n+1/2j,k +

    (y)22yu

    n+1j,k (20)

    where in the first step un+1/2j,k has to be found implicitly, but can then be di-

    rectly used in the second half-time step where un+1/2j,k is obtained implicitly.

    One thus has to solve a tridiagonal matrix equation twice. Although bothsteps separately have their own stability criterion, the combined methodfor a full time step is unconditionally stable.

    2.2 Linear Advection equation

    u

    t+ c

    u

    x= 0 (21)

    When the advection speed c is a function ofx, discontinuities can arise. Takee.g. c(x) = sin x. The solution then has characteristics X(t) = t sin x + X(0)because, using the chain rule, u(X(t), t) is constant in time. Take e.g. twocharacteristics with X(0) = and X(0) = such that for t = /(sin )the two characteristics meet. I.e. starting from different initial conditions,the two solutions converge to the same point leading to a discontinuity.

    Forward Time Centred Space (FTCS):un+1i u

    ni

    t+

    c

    2x

    (uni+1 u

    ni1

    )= 0 (22)

    Although consistent, this scheme is unconditionally unstable. This canbe understood from evaluating the LTE = t2 utt|

    nj + .. which, with from

    the advection equation itselfutt = c2uxx, implies some numerical diffusionwith a negative sign, i.e. trouble.

    Lax-Friedrichs:

    un+1i =1

    2(unj1 + u

    nj+1)

    ct

    2x

    (uni+1 u

    ni1

    )(23)

    This scheme is obtained by replacing uni with an average value un+1j =

    12

    (unj1 + unj+1) in the FTCS method. Because

    12

    (unj1 + unj+1) = u

    nj +

    12(u

    nj1 2u

    nj + u

    nj+1) some artificial diffusion is added and one actu-

    ally solves the advection-diffusion equation with diffusion constant =(x)2/2t. The method can be written as u(t) = Bu(t) with B a matrixconsisting of c/2x times the skew-symmetric tridiagonal (-1,0,1) ma-trix plus /(x)2 times the symmetric (1,-2,1) matrix, yielding eigenvaluesp =

    icx sin2px

    2(x)2 (1 cos2px). The eigenvalues no longer lie

    along the imaginary axis in the z = t-plane, but form an ellipse withcentre and radius given by 2t

    (x)2such that for ct/x 1 they all lie

    within the EF stability region, rendering the method conditionally stable.

    7

  • 8/6/2019 NumMethPDEs

    8/14

    Some second order in space and time options

    Crank Nicolson trapezoidal method for u = Au

    Two-level explicit:

    un+1j = unj

    ct

    2x(unj+1 u

    nj1) +

    c2(t)2

    8(x)2(unj+2 2u

    nj + u

    nj2) (24)

    This scheme has a five-point stencil and requires additional boundary con-ditions. The method is obtained from taking another time derivative of thesystem u = Au yielding u = A2u(t) which gives a second order methodun + 1 = un + tAun + 12(t)

    2A2u(t)

    Lax-Wendroff

    un+1j = unj ct2x

    (unj+1 unj1) + c

    2(t)22(x)2

    unj+1 2unj + unj1(x)2

    (25)

    This scheme can be obtained by Taylor expanding the advection equa-tion, replacing ut by cux and utt by c2uxx using central FDs and in thetime direction EF. This scheme actually solves the equation ut + cux =(1/6)c(x)2(1 (ct/x)2uxxx to third order, thereby showing someartificial numerical dispersion due to the non-zero right hand side. Theresulting oscillations lag behind the solution due to the negative sign, andare damped by a term proportional to uxxxx in the modified equation.

    Upwind methods use different spatial discretizations depending on the (local)sign of c.

    First order upwind. For c > 0 it is just FTFS

    un+1j = unj

    ct

    x(unj u

    nj1) (26)

    When c > 0, FTBS is used. The scheme is only first order accurate inboth space and time. Note that the right hand side can be written asunj

    ct2x

    (unj+1 unj1) +

    ct2x

    (unj+1 2unj u

    nj1) so that a numerical

    diffusion term with diffusion coefficient upw = cx/2 is introduced. Onecan even show that upwind schemes for the advection equation, to firstorder, actually solve a modified advection-diffusion equation to secondorder accuracy. Note that for c < 0 this becomes negative diffusion,showing that the displayed FTBS can only stably be used for c > 0.

    Beam-Warming method: second order upwind. Again, for c > 0

    un+1j = unj

    ct

    2x(3unj 4u

    nj1+u

    nj2)+

    1

    2c2

    t

    x

    2 (unj 2u

    nj1 + u

    nj2

    )(27)

    The derivation goes analogously to that of the Lax-Wendroff scheme, usinga one-sided approximation for spatial derivatives. It is stable for 0 ct/x 2. The modified equation for this equation is ut + cux =16

    c(x)2(2 3ctx +(

    ctx

    )2)uxxx

    Note that it can be proven that there exist no explicit unconditionally stableFD schemes for solving hyperbolic PDEs.

    8

  • 8/6/2019 NumMethPDEs

    9/14

  • 8/6/2019 NumMethPDEs

    10/14

    therefore better to use u1j = fj +tgj +c2(t)2

    2(x)2 (fj+1 2fj + fj1) =12

    2fj+1+

    (1 2)fj + 122fj1 + tgj preserving the O(x2) + O(t2) accuracy of thecentral difference scheme.

    2.5 Advection-diffusion equation

    ut + cux uxx = 0 (34)

    For the standard CD discretization it can be proven that a sufficient crite-

    rion for which unj remains positive is t (x)2

    2and the mesh Peclet number

    P em |c|x/ 2.

    The steady state version has, with u(0) = 0 and u(1) = 1, as exact solutionu(x)(ecx/ 1)/(ec/ 1) yielding a boundary layer of O(/c). The cor-

    responding FD scheme using central differences has the exact solution uj =Pj 1/(PN 1) with Pj = (1+ P ejm)/(1 P e

    jm). For P e

    jm > 1 one has P

    j < 0so that the numerical solution shows oscillations or wiggles, which can be shownto be associated with the combination of first and second derivatives in the orig-inal equation. The solution, circumventing the use of very small grid sizes, isusing an upwind scheme with the same exact solution but with Pj = 1 + P ejm.The wiggles are then absent, but at the cost of introducing some numericaldiffusion.

    10

  • 8/6/2019 NumMethPDEs

    11/14

    3 Higher order methods

    3.1 Finite Differences

    Using Taylor expansions, higher order approximations can be found. As anexample, an approximation of uxx using the five values uj2 to uj+2 has anerror term of O(x6). At the boundaries one now needs additional values,which over determines the system rendering it ill-posed. Another downside isthat the matrix becomes less sparse, making it computationally more expensiveto invert.

    3.2 Spectral methods

    Finite element methods or spectral methods can also be used to obtain higher

    order accuracy. Spectral methods can be used when the function to be ob-tained is periodic over a certain interval, allowing a Fourier expansion to beinserted into the DE. Differentiating the expansion analytically yields an extrapre factor 2ik/L while performing the differentiation by a central FD yields(iN/L)sin2k/N showing that a sufficient number of terms should be includedfor these two expressions to match. Applying the method to the heat equationyields for the coefficients ak(t) = e

    k2tak(0) where the initial coefficients can beobtained from an inverse FT. One can show that

    u(x, t) uN(x, t)

    =

    k=N

    ak(0)eikxek

    2t max0x2

    |ak(0)|

    N

    etx2

    dx (35)

    The convergence is thus determined by the complimentary error function.

    3.3 Non-uniform grids

    Using Taylor expansions to find a FD approximation to a first derivative yieldsa two point stencil ui = (ui+1 ui1)/(hi+1 + hi) where, with hi xi xi1,the denominator is xi+1 xi1. The local truncation error is h3i /6(hi+1 + hi) h3i+1/6(hi+1 + hi) + .. allowing one to choose the hi such that the lowest ordererror term vanishes. This technique makes the error of higher order, which iscalled supra convergence.

    11

  • 8/6/2019 NumMethPDEs

    12/14

    4 Adaptive Mesh Refinement

    Several types of Adaptive Mesh Refinement (AMR) variants exist

    H-refinement - specific cells are split up into smaller cells

    p-refinement - using finite elements, the degree of piecewise polynomialsis varied per element

    r-refinement - nodes are moved around, while keeping the number of nodesconstant

    4.1 Mapping method

    The idea considered here is to devise a mapping based on the numerical solution,

    which maps a non-uniform mesh in the physical space to a uniform grid onwhich the FD discretization is performed. Consider e.g. the advection-diffusionequation

    ux = uxx (36)

    with u(0) = 0 and u(1) = 1. Define a transformation x [0, 1] withv() u(x()) such that

    vx

    =

    x

    [v x vx

    x

    2]

    (37)

    Now when one chooses v() = , such that a uniform distribution of yieldsa uniform distribution in v() = u(x()), the equation becomes x

    + x2

    = 0

    and x(0) = 0 and x(1) = 1. One has in general v = uxx such that theparticular mapping v() = satisfies xux = 1. I.e. x is inversely proportionalto the grid point concentration, where ux is large x is small as is desirable.This example leads to a principle that could be used for other equations as well:

    x = 1 or (x) = 0 (38)

    with > 0 a monitor function that is ideally some measure of the numeri-cal error.

    Using dx/d = (d/dx)1 one obtains d/dx = c or, with (xR) (xL) = 1,after integrating c = 1/ dx or

    ddx =

    RxRxL

    dxfrom which the inverse transfor-

    mation is obtained

    (x) =

    xxL

    (x)dxxRxL

    (x)dx(39)

    The Jacobian of the transformation dx/d > 0 such that the transformationis regular, or non-singular. Note that the principle (x) = 0 is equivalent to

    minimization of the functional F =10

    x2 d, which can easily be derived fromthe Euler-Lagrange equations. The discussed principle is therefore analogous tothe minimization of the energy of a spring system between the mesh points.

    12

  • 8/6/2019 NumMethPDEs

    13/14

    4.2 Equidistribution principle

    In discrete terms the application of such a transformation d/dx = c impliesfor the mesh size xi = c/i. Because

    xi+1xi

    dx = c independent of ixi+1xi

    dx =1

    N

    xRxL

    dx (40)

    showing that is equally distributed over all subintervals, a principle calledthe equidistribution principle. The equidistribution of the monitor functionensures xi is small where i is large.

    4.3 Choices of Monitor functions

    = ux In this case x = x(v/x) = v such that the same change in

    the solution u occurs over each mesh interval. The downside is that themesh elements become infinitely large when there is no variation in thesolution

    =

    1 + u2x From ds2 = dx2 + du2 = dx2(1 + u2x) this can be seen to be

    the arc length of the solution curve, thereby circumventing the problemof diverging mesh element sizes

    4.4 Possible Problems

    Big jumps in mesh size can deteriorate the accuracy of the scheme. TheLTE of ux,i (ui+1 ui1)/(xi + xi1), for example, is given by12uxx,i(1 rxi)

    12

    uxxx,i(1r + r2)x2i + .. such that, when the grid

    size ratio or local stretching factor r xi1/xi, is r = 1 + O(xi)the method is of second order. When r becomes too large, however, themethod becomes first order. Now r = (xi xi1)/(xi+1 xi) = (x 12

    2x,i)/(x +12

    2x,i) + .. = 1 xix,i/x2,i + .. such that

    xix,i/x2,i should be of order one to maintain the uniform-grid accuracy

    of the scheme. The grid is said to be quasi uniform.

    Taking the time-derivative of the following form of the equidistribution

    principlexi(t)

    xLdx =

    (i

    N

    ) gives xi +

    xi(t)xL

    tdx = (i/N)(t). In-troducing small perturbations xi on the grid points xi yields, up to firstorder, xi+(x)xixi+(t)xi = 0, equivalent with (d/dt)[xi] = 0,or

    xi(t) =(xi(0), 0)

    (xi(t), t)xi(0) (41)

    From this we see that (xi(0), 0)/(xi(t), t) should be smaller than oneto ensure stability. A possibly resulting instability may be prevented byadding a small delay-term to the equidistribution principle.

    The solution to these problems is to apply some type of smoothing of themesh in both space, to ensure quasi-uniformity, and time, to ensure stability.This is exemplified by the following numerical implementation involving spa-tial and temporal smoothing parameters and s. Consider a 1D linear time

    13

  • 8/6/2019 NumMethPDEs

    14/14