Weighted Residual Method

Embed Size (px)

Citation preview

  • 8/13/2019 Weighted Residual Method

    1/37

    Chapter 6

    Weighted Residual Methods

    Weighted residual methods (WRM) assume that a solution can be approximated analytically or

    piecewise analytically. In general a solution to a PDE can be expressed as a superposition of a base

    set of functions

    T(x, t) =

    Nj=1

    aj(t)j(x)

    where the coefficients aj are determined by a chosen method. The method attempts to minimizethe error, for instance, finite differences try to minimize the error specifically at the chosen grid

    points. WRMs represent a particular group of methods where an integral error is minimized in

    a certain way and thereby defining the specific method. Depending on the maximization WRM

    generate

    the finite volume method,

    finite element methods,

    spectral methods, and also

    finite difference methods.

    6.1 General Formulation

    The starting point for WRMs is an expansion in a set of base or trial functions. Often these are

    analytical in which case the numerical solution will be analytical

    T(x, y, z, t) = T0(x, y, z, t) +Nj=1

    aj(t)j(x,y,z) (6.1)

    81

  • 8/13/2019 Weighted Residual Method

    2/37

    CHAPTER 6. WEIGHTED RESIDUAL METHODS 82

    with the trial functionsj(x,y,z). T0(x, y, z, t)is chosen to satisfy initial or boundary conditionsand the coefficientsaj(t)have to be determined. possible trial functions are

    j(x) =xj1 orj(x) = sin(jx).

    The expansion is chosen to satisfy a differential equation L(T) = 0(whereTis the exact solution),

    e.g.,

    L(T) =T

    t

    2T

    x2 = 0

    However, the numerical solution is an approximate solution, i.e., T= Tsuch that the operatorLapplied toTproduces a residual

    L(T) =R

    The goal of WRMs is to choose the coefficients aj

    such that the residualRbecomes small (in fact0) over a chosen domain. In integral form this can be achieved with the condition

    Wm(x,y,z)Rdxdydz= 0 (6.2)

    whereWm is a set of weight functions (m= 1,...M)which are used to evaluate (6.2). The exactsolution always satisfies (6.2) if the weight functions are analytic. This is in particular true also for

    any given subdomain of the domain for which a solution is sought.

    There are four main categories of weight or test functions which are applied in WRMs.

    i) Subdomain method: Here the domain is divided inM subdomainsDmwhere

    Wm=

    1 in Dm0 outside

    (6.3)

    such that this method minimizes the residual error in each of the chosen subdomains. Note that the

    choice of the subdomains is free. In many cases an equal division of the total domain is likely the

    best choice. However, if higher resolution (and a corresponding smaller error) in a particular area

    is desired, a non-uniform choice may be more appropriate.

    ii) Collocation method: In this method the weight functions are chosen to be Dirac delta func-

    tions

    Wm(x) =(x xm) (6.4)

    such that the error is zero at the chosen nodes xm.

  • 8/13/2019 Weighted Residual Method

    3/37

    CHAPTER 6. WEIGHTED RESIDUAL METHODS 83

    iii) Least squares method: This method uses derivatives of the residual itself as weight functions

    in the form

    Wm(x) = R

    am. (6.5)

    The motivation for this choice is to minimize

    R2dxdydzof the computational domain. Notethat this choice of the weight function implies

    am

    R2dxdydz= 0

    for all values ofam.

    iv) Galerkin method: In this method the weight functions are chosen to be identical to the base

    functions.

    Wm(x) =m(x)

    In particular if the base function set is orthogonal (

    m(x)n(x) = 0 ifm = n), this choice ofweight functions implies that the residualRis rendered orthogonal with the condition (6.2) for allbase functions.

    NotethatM weight functions yieldMconditions (or equations) from which to determine the Ncoefficientsaj . To determine these N coefficients uniquely we need N independent condition(equations).

    Example: Consider the ordinary differential equation

    dy

    dx y = 0 (6.6)

    for0 x 1withy(0) = 1. Let us assume an approximate solution in the form of polynomials

    y= 1 +N

    j=1ajx

    j (6.7)

    where the constant1 satisfies the boundary condition. Substituting this expression into the differ-ential equation (6.6) gives the residual

    R= 1 +Nj=1

    ajjxj1 xj

    (6.8)

    We can now compute the coefficientsaj with the various methods.

  • 8/13/2019 Weighted Residual Method

    4/37

    CHAPTER 6. WEIGHTED RESIDUAL METHODS 84

    Galerkin method:

    Here we use the weight functionsWm= xm1. The maximization implies with (6.2)

    1

    0

    xm1 1 +N

    j=1 aj jxj1 xj dx= 0or

    10

    xm1dx+Nj=1

    aj

    j

    10

    xm1xj1dx

    10

    xm1xjdx

    = 0

    which yields after integration

    1

    m+

    N

    j=1aj

    j

    m+j 1

    1

    m +j = 0 (6.9)

    With the matrix S(with elements smj = jm+j1

    1m+j

    ) and the vector D (with the elements

    dm= 1m

    ) we can rewrite (6.9) as

    SA = D (6.10)

    The solution A of this set of equations requires to invertS. ForN= 3the system becomes

    1/2 2/3 3/41/6 5/12 11/20

    1/12 3/10 13/30

    a1a2a3

    =

    11/21/3

    For this set the approximate solution becomes

    y= 1 + 1.0141x + 0.4225x2 + 0.2817x3

    Least squares method:

    Here the weight functions are

    Wm(x) = R

    am=mxm1 xm

    This gives the residual condition

    10

    mxm1 xm

    1 +

    Nj=1

    ajjxj1 xj

    dx =

    1 + 1

    m+ 1+

    Nj=1

    aj

    10

    mxm1 xm

    jxj1 xj

    dx

    = 0

  • 8/13/2019 Weighted Residual Method

    5/37

    CHAPTER 6. WEIGHTED RESIDUAL METHODS 85

    or

    1 + 1

    m+ 1+

    Nj=1

    aj

    jm

    m +j 1

    j + m

    m +j+

    1

    m+j+ 1

    = 0

    Subdomain method:

    Weight functions:

    Wm =

    1 x (m1N ,

    mN]

    0 outside

    Condition for the residual error:

    mN

    m1N 1 +

    N

    j=1 aj jxj1 xj dx= 0Collocation method:

    Collocation point (for the Dirac delta function): xm= m1N

    .

    Condition for the residual error:

    10

    (x xm)

    1 +

    Nj=1

    ajjxj1 xj

    dx= 0

    6.2 Finite Volume Method

    This section illustrate the use of the finite volume method first for a PDE involving first order

    derivatives and later for second order derivatives. The program FIVOL will be introduced which

    can be used to solve Laplaces equation or Poissons equation, i.e, equations of the elliptic type.

    6.2.1 First order derivatives

    Let us consider the equationq

    t+

    F

    x +

    G

    y = 0 (6.11)

    which is to be solved with the subdomain method on a domain given by coordinate line (j, k)describing a curved coordinate system. This equation is a typical continuity equation like the

    equations for conservation of mass, momentum etc.

  • 8/13/2019 Weighted Residual Method

    6/37

    CHAPTER 6. WEIGHTED RESIDUAL METHODS 86

    k-1

    k

    k+1

    j-1

    j

    j+1

    A

    B

    C

    D

    x

    y

    Figure 6.1: Illustration of the coordinate system to solve equation (6.11) with the finite volume

    method.

    Equation (6.11) is to be solved as an integral over any areaABCDas illustrated in Figure 6.1 =>ABCD

    q

    t+

    F

    x +

    G

    y

    dxdy= 0.

    With H = (F, G) such that F/x+ G/y = H this equation becomes (using Gaussstheorem)

    d

    dt ABCD qdV + ABCDH nds= 0In Cartesian coordinates the surface element vector ds = (dx, dy) such that the normal vectornds = (dy, dx) and H nds = F dy Gdx. Thus the integral of (6.11) For the areaABCDbecomes

    d

    dt(Arqjk) +

    ABCD

    (Fy Gx) = 0

    withAr =area ofABCD. Using the notationsyAB = yB yA, xAB = xB xA, and theaveragesFAB = 0.5 (Fj,k1+ Fj,k),GAB = 0.5 (Gj,k1+ Gj,k)and applying these to all sections

    ofABCDwe obtain

    Ardqjkdt

    +0.5 (Fj,k1+ Fj,k) yAB 0.5 (Gj,k1+ Gj,k) xAB+0.5 (Fj,k+ Fj+1,k) yBC 0.5 (Gj,k+ Gj+1,k) xBC+0.5 (Fj,k+ Fj,k+1) yCD 0.5 (Gj,k+ Gj,k+1) xCD+0.5 (Fj1,k+ Fj,k) yDA 0.5 (Gj1,k+ Gj,k) xDA = 0

    (6.12)

  • 8/13/2019 Weighted Residual Method

    7/37

    CHAPTER 6. WEIGHTED RESIDUAL METHODS 87

    In case of a uniform grid parallel to the x, and the y axes the area isAr = xy and equation(6.12) reduces to

    dqjkdt

    +Fj+1,k Fj1,k

    2x +

    Gj+1,k Gj1,k2y

    = 0

    where the spatial derivative is equal to that for the centered space finite difference approximation.

    6.2.2 Second order derivatives

    To introduce the finite volume second derivatives let us consider Laplaces equation

    2

    x2+

    2

    x2 = 0 (6.13)

    k-1

    k

    k+1

    j-1

    j

    j+1

    A

    B

    C

    D

    x

    y

    A

    B

    C

    D

    x

    y

    XW

    Y

    Z

    rWZ

    rXY

    (A)

    (B)

    Figure 6.2: Illustrations of the domain for the solution of Laplaces equation (A), and of the grid

    geometry to evaluate the second derivatives for the finite volume method.

    We are seeking a solution for this equation in a domain as illustrated by the shaded area in

    Figure~6.2. The appropriate coordinate system for this domain is a polar coordinate system with

    the variabler and . The boundary conditions are

    = 0at boundaryW X,

    = sin /rxy at boundaryXY,

    = 1/ryz at boundaryY Z,

    = sin /rwz at boundaryW Z.

  • 8/13/2019 Weighted Residual Method

    8/37

  • 8/13/2019 Weighted Residual Method

    9/37

    CHAPTER 6. WEIGHTED RESIDUAL METHODS 89

    Figure 6.3: Illustration of the geometry of the elementsABCD.

    and similar forx. Figure 6.3 shows that the area is approximated by

    SAB =SABCD = (xAB xk1,k)(yAB+ yk1,k)

    xAByAB+ xk1,kyk1,k

    = xAByk1,k yABxk1,k

    With this we obtain:

    x

    j,k1/2

    = yAB(j,k1 j,k) + yk1,k(B A)

    SAB

    y

    j,k1/2

    = xAB(j,k1 j,k) + xk1,k(B A)

    SAB

  • 8/13/2019 Weighted Residual Method

    10/37

    CHAPTER 6. WEIGHTED RESIDUAL METHODS 90

    Similarly we obtain

    x

    j+1/2,k

    = yBC(j+1,k j,k) + yj+1,j(C B)

    SBC

    y j+1/2,k = xBC(j+1,k j,k) + xj+1,j(C B)SBC

    x

    j,k+1/2

    = yCD(j,k+1 j,k) + yk+1,k(D C)

    SCD

    y

    j,k+1/2

    = xCD (j,k+1 j,k) + xk+1,k(D C)

    SCD

    x

    j1/2,k

    = yDA(j1,k j,k) + yj1,j(A D)

    SDA

    y j1/2,k=

    xDA(j1,k j,k) + xj1,j(A D)

    SDA

    Substitution back into equation (6.15) gives

    QAB(j,k1 j,k) + QBC(j+1,k j,k) + QCD(j,k+1 j,k) + QDA(j1,k j,k)

    +PAB(B A) + PBC(C B) + PCD(D C) + PDA(A D) = 0

    with

    QAB =

    x2AB+ y2AB

    /SAB , PAB = (xABxk1,k+ yAByk1,k) /SAB

    QBC=

    x2BC+ y

    2BC

    /SBC , PBC= (xBCxj+1,j+ yBCyj+1,j) /SBC

    QCD = x2CD + y2CD /SCD , PCD = (xCDxk+1,k+ yCDyk+1,k) /SCDQDA =

    x2DA+ y

    2DA

    /SDA , PDA = (xDAxj1,j + yDAyj1,j) /SDA

    Finally we evaluateA,xA, andyAas the average over the surrounding nodes, e.g.,

    A= 0.25(j,k+ j1,k+ j1,k1+ j,k1)

    Substitution into our main equation then yields

    0.25 (PCD PDA) j1,k+1+ 0.25 (PBC PCD) j+1,k+1

    +0.25 (PAB

    PBC

    ) j+1,k

    1+ 0.25 (P

    DA P

    AB) j

    1,k

    1+ [QCD + 0.25 (PBC PDA)] j,k+1+ [QDA+ 0.25 (PCD PAB)] j1,k

    + [QAB+ 0.25 (PDA PBC)] j,k1+ [QBC+ 0.25 (PAB PCD)] j+1,k

    (QAB+ QBC+ QCD + QDA) j,k = 0 (6.16)

    Here the coefficients can be determined initially and then used during the computation. Equation

    (6.16) is solved in the program FIVOL using successive over-relaxation (SOR). The estimate for is determined from (6.16)

  • 8/13/2019 Weighted Residual Method

    11/37

    CHAPTER 6. WEIGHTED RESIDUAL METHODS 91

    j,k = {0.25 (PCD PDA) j1,k+1+ 0.25 (PBC PCD) j+1,k+1 (6.17)

    +0.25 (PAB PBC) j+1,k1+ 0.25 (PDA PAB) j1,k1

    + [QCD + 0.25 (PBC PDA)] j,k+1+ [QDA+ 0.25 (PCD PAB)] j1,k

    + [QAB+ 0.25 (PDA PBC)] j,k1+ [QBC+ 0.25 (PAB PCD)] j+1,k}n

    / (QAB+ QBC+ QCD + QDA)

    The iteration step is completed with

    n+1j,k =nj,k+ (

    j,k

    nj,k) (6.18)

    Note that the discretized equation (6.16) reduces to centered finite differences on a uniform rect-

    angular grid

    j1,k 2j,k+ j+1,kx2

    +j,k1 2j,k+ j,k+1

    y2 = 0 (6.19)

    6.2.3 Program Fivol

    The finite volume method as described above is implemented in the program Fivol. The program

    parameter used are summarized in Table (6.1).

    Table 6.1: Program parameter for the program Fivol.

    Parameter Description

    nr,ntheta Number of grid points inr and directionsniter Maximum number of iterations

    eps Tolerance for the iterated solution

    om Relaxation parameterrms RMS error

    rw, rx, ry, rz radial distance to points w, x, y, and z

    theb, then Min and max values in the directionx,y xand y coordinates of the grid

    r,theta r and coordinatesdr,dtheta increments in ther and directions

    qab, pab, qbc, pbc, qcd, pcd, qda, pda Weights for the iterationsphi Iterated solution

    phix Exact solution

    The program reads the input parameters niter, rw, rx, ry, rz, theb, then, eps, om from the data

    file fivol.dat. Program parameters are defined in the include file fivin. The program then writes

    parameters to a data file fivol.out, generates the grid, initializes the iteration through an initial state

    (for phi), boundary conditions, and calculates the matrix coefficients. Subsequently a subroutine

  • 8/13/2019 Weighted Residual Method

    12/37

    CHAPTER 6. WEIGHTED RESIDUAL METHODS 92

    SOR is called until the iterated solution tolerance is reached. The result is written to a binary file

    which can serve as input for the plotting routine plofivol.

    The solution error for the finite volume method is listed in Table (6.2) for different number of grid

    points in the same domain. The table illustrates that the solution error is second order. This is to

    be expected from the centered differences to which the finite volume method reduces on a uniform

    rectangular grid. However, for strongly distorted grids the solution error is larger than second

    order.

    Table 6.2: Solution errors for the finite volume method in program Fivol2.f

    Grid | exact|rms No of iterations

    66 0.1326 151111 0.0471 192121 0.0138 51

    The finite volume method is well suited for for somewhat irregular grid domains and does not

    require an orthogonal grid. The number of iterations for convergence depends on the domain size.

    6.3 Finite Element Method

    Finite element methods are used mostly in engineering. For many problems the finite element

    method can be interpreted as a maximization of the potential energy of a system. In most applica-

    tions the finite element method is used with the Galerkin formulation for the weighted residuals.

    The approximating functions are simple polynomials defined in local domains.

    T=Nj=1

    Tjj(x,y,z) (6.20)

    Where for a suitable set of functions the local domains can be of any shape. Since the finite element

    method is used with local coordinates the domains can be subdivided (into same shape domains)

    to increase the resolution where it is desired. The interpolating functions are called trial or shape

    functions.

    6.3.1 Basic formulation

    a) Linear Interpolation

    The linear interpolation uses linear functions which are 1 at the nodal point, assume 0 at the neigh-

    boring points, and are identical to 0 outside the domains (xj1, xj+1)as illustrated in Figure 6.4.

    The shape function for the nodal pointj is

  • 8/13/2019 Weighted Residual Method

    13/37

    CHAPTER 6. WEIGHTED RESIDUAL METHODS 93

    Figure 6.4: Illustration of one-dimensional linear finite elements.

    j =

    xxj1xjxj1

    f or xj1 x xj (element A)xj+1x

    xj+1xjf or xj x xj+1 (element B)

    (6.21)

    and j = 0 outside of elements A and B. The shape function j overlaps only with its directneighbors and the superposition of elements between nodal points yields a linear function in these

    regions

    in A: T =Tj1j1+ Tjj (6.22)

    in B : T =Tjj+ Tj+1j+1 (6.23)

    In any given element only two shape functions overlap. In element A j is given element by (6.21)andj1is given by

    j1= xj x

    xj xj1

    Similar for any element Bj is given element by (6.21) andj+1is given by

    j+1= x xjxj+1 xj

    .

    The particular form of the trial functions makes it straightforward to use them to approximate any

    given functionf(x).Since the trial functions are 1 at the nodal points and all except for one trialfunctions are 0 at any nodal point Thus the expansion of a function f(x) in terms of the shapefunctions is given by

    f(x) =Nj=1

    fjj(x) (6.24)

    with the coefficients

    fk = f(xk) (6.25)

  • 8/13/2019 Weighted Residual Method

    14/37

    CHAPTER 6. WEIGHTED RESIDUAL METHODS 94

    where thexk are the nodal points. Formally this is seen byf(xk) =Nj=1 fjj(xk) =fk

    The method is illustrated using the function

    f(x) = 1 + cos(x/2) + sin(x) (6.26)

    f

    x

    2.0

    1.0

    0.5 1.0

    quadraticinterpolation

    linear interpolation

    Figure 6.5: Linear (dashed)and quadratic (dotted) finite element approximation of function (6.26).

    in the range [0, 1]. With two elements and nodal points at(0, 0.5, 1.0) the expansion coefficientsaref1 = 2,f2 = 2.7071, andf3 = 0. Figure (6.5) shows the functionf(x)and the finite elementinterpolation for linear and quadratic elements.

    b) Quadratic interpolation

    Quadratic interpolation requires simple quadratic polynomials for trial function. Again a trial

    function should be 1 only at the corresponding nodal point and 0 at all other nodes.

    Figure 6.6: Illustration of one-dimensional linear finite elements.

    Following the illustration 6.6 the trial functions are defined by

    j =

    0 f or x xj2, x xj+2

    xxj2xjxj2

    xxj1xjxj1

    f or xj2 x xj , element Axxj+2xjxj+2

    xxj+1xjxj+1

    f or xj x xj+2, element B(6.27)

    With this form j(xj) = 1 and j(xj2) = j(xj1) = j(xj+1) = j(xj+1) = 0. The trialfunctions of this form extend over 5 nodes. such that in a given interval 4 trial functions overlap

  • 8/13/2019 Weighted Residual Method

    15/37

    CHAPTER 6. WEIGHTED RESIDUAL METHODS 95

    if they were all chosen of the same form. This is improved by choosing different trial functions at

    xj1and atxj+1of the form:

    j = x xj1xj xj1

    x xj+1xj xj+1

    for xj2 x xj (6.28)

    and 0 otherwise. Note that this creates a structure where all odd nodes have elements of the form

    of (6.27) and all even elements are of the form (6.28) where we start with an index of 1 for the first

    node (xmin boundary).

    Similar to the linear elements it is straightforward to expand any given function in term of these

    shape functions

    f(x) =Nj=1

    fjj(x)

    with the coefficientsfk =f(xk)as in the case of the linear elements.

    withTj = f(xj). With these functions the interpolation in elements A and B take the followingform

    T =

    Tj2j2+ Tj1j1+ Tjj in element ATjj+ Tj+1j+1+ Tj+2j+2 in element B

    The specific form of the shape functions which are nonzero in any element A is

    j2 = x xjxj2 xj

    x xj1xj2 xj1

    j1 =

    x xj2xj1 xj2

    x xjxj1 xj

    j =

    x xj2xj xj2

    x xj1xj xj1

    For the special function (6.26) with only three nodes we have only one element A and no element

    B. As before the expansion coefficients aref1 = 2,f2 = 2.7071, andf3 = 0.

    The errors for the linear and quadratic finite element approximation of function (6.26) is listed inTable 6.3. While the linear approximation scales quadratic in the error the quadratic interpolation

    scales cubic in the resolution (inverse number of nodes).

    c) Two-dimensional interpolation

    Linear elements: The particular strength of finite elements is there flexibility in two and three

    dimensions. Based on the previous introduction we want to illustrate the use of linear and quadratic

  • 8/13/2019 Weighted Residual Method

    16/37

    CHAPTER 6. WEIGHTED RESIDUAL METHODS 96

    Table 6.3: Error for linear and quadratic finite element interpolation for the function in (6.26).

    Linear Interpolation Quadratic interpolation

    No of elements RMS error No of elements RMS error

    2 0.18662 1 0.04028

    4 0.04786 2 0.015996 0.02138 3 0.00484

    8 0.01204 4 0.00206

    finite elements in two and three dimensions. In two dimensions a trial function centered at (xj , yj)spans four elements A, B, C, and D. The approximate solution in this region can be conveniently

    written with local element based coordinates(, )as

    T =

    4

    l=1Tll(, ) (6.29)

    with 1 1and 1 1. The approximating functionsl(, )in each element are ofthe form

    l(, ) = 0.25(1 + l)(1 + l) (6.30)

    withl = 1andl = 1or explicit

    1 = 0.25(1 )(1 )

    2 = 0.25(1 + )(1 )

    3 = 0.25(1 + )(1 + )

    4 = 0.25(1 )(1 + )

    The nodal geometry and local coordinate systems are illustrated in Figure 6.7.

    =1 =1

    =1

    =1

    Figure 6.7: Illustration of the nodal geometry and sketch of the two-dimensional linear trial func-

    tions.

  • 8/13/2019 Weighted Residual Method

    17/37

    CHAPTER 6. WEIGHTED RESIDUAL METHODS 97

    A solution is constructed separate in each element A, B, C, and D where continuity is provided by

    the overlapping shape functions. For instance a solution in element A implies that shape functions

    with values of 1 along the boundary to element B overlap into the region of element B and similar

    for all other boundaries of element A.

    Bi-quadratic elements:

    Similar to the bilinear elements the approximate solution for bi-quadratic elements in this region

    can be conveniently written with local element based coordinates (, )as

    T =9l=1

    Tll(, ) (6.31)

    with 1 1and 1 1. The approximating functionsl( )in each element dependon the location.

    Figure 6.8: Illustration of the nodal geometry for bi-quadratic elements.

    Specifically the form of the shape function depends on how they are centered, i.e., where they

    assume a value of 1.

    l(, ) = 0.25l(1 + l)l(1 + l) corner nodes (6.32)

    l(, ) = 0.5(1 2)l(1 + l) midside nodes (l = 0) (6.33)

    l(, ) = 0.5(1

    2

    )l(1 + l) midside nodes (l = 0) (6.34)

    l(, ) = 0.5(1 2)(1 2) internal nodes (6.35)

    Again solutions are constructed in each element A, B, C, and D where the shape functions on the

    side and corner nodes overlap into the adjacent region. Note that quadratic elements require at 3

    nodes in each direction and the total number of nodes has to be odd to accommodate quadratic

    elements.

  • 8/13/2019 Weighted Residual Method

    18/37

    CHAPTER 6. WEIGHTED RESIDUAL METHODS 98

    6.3.2 Finite element method applied to the Sturm-Liouville equation

    Here we will use the Galerkin finite element method to discretize and solve the Sturm-Liouville

    equation

    d2ydx2

    + y= F(x) (6.36)

    subject to boundary conditionsy(0) = 0anddy/dx(1) = 0and

    F(x) = Ll=1

    alsin ((l 0.5)x) . (6.37)

    The exact solution to this problem forF(x)is given by

    y(x) =

    Ll=1

    al

    1 ((l 0.5))2sin ((l 0.5)x) . (6.38)

    The trial solution is as before

    y= Nj=1

    yjj.

    Linear Interpolation:

    In an element based coordinate system we use local coordinates with

    j = 0.5(1 + ) and = 2x

    xj1+xj

    2 xj

    for element A

    j = 0.5(1 ) and = 2x

    xj+xj+1

    2

    xj+1

    for element B

    withxj =xj xj1, andxj+1= xj+1 xj . The residual is

    R= d2ydx2

    + y F(x)and the weight function for the weighted residual is wm= mwhich yields the equation 1

    0

    m(x)d2y

    dx2+ y F(x) dx= 0

    One can integrate the first term brackets by parts 10

    md2ydx2

    dx=

    m

    dydx

    10

    10

    dmdx

    dydx

    dx

  • 8/13/2019 Weighted Residual Method

    19/37

    CHAPTER 6. WEIGHTED RESIDUAL METHODS 99

    because the boundary conditions imply1 = 0anddy/dx(1) = 0 such that

    mdeydx

    10

    = 0 such

    that the residual equation becomes

    N

    j=1 yj

    1

    0

    dmdx

    djdx

    + mj

    dx

    =

    1

    0

    mF(x)dx

    or in matrix form

    BY = G

    with the elements

    bmj =

    10

    dmdx

    djdx

    + mj

    dx

    gm =

    10

    mF(x)dx.

    In the computation of these elements it is convenient to make use of the local coordinates. It

    should also be noted that the residual equation only has contributions for j =m 1,j =m, andm= j + 1. With the transformation to local coordinates we have in element A

    d

    dx =

    d

    dx

    d

    d =

    2

    xj

    d

    d

    dx = dx

    dd=

    xj2

    d

    and in element B

    d

    dx =

    d

    dx

    d

    d =

    2

    xj+1

    d

    d

    dx = dx

    dd=

    xj+12

    d

    withxj =xj xj1and xj+1= xj+1 xj .

    Elementbm,m1: A contribution exists only in region A for node m (corresponding to a region Bfor nodem 1). Thus

    bm,m1 = 10dmdx dm1dx + mm1 dx

    =

    11

    dAdx

    dAd

    dBd

    + dx

    dAAB

    d

    = 1

    2xm

    11

    d+xm

    8

    11

    (1 2)d

    = 1

    xm+

    xm6

  • 8/13/2019 Weighted Residual Method

    20/37

    CHAPTER 6. WEIGHTED RESIDUAL METHODS 100

    Similar the element bm,m+1 involves only overlap in region B of element m with region A ofelementm+1. The expression is the same only that it regards the intervalxm+1. Thus

    bm,m+1 = 1

    xm+1+

    xm+16

    Elementbm,m: Here we have overlap ofmwith itself in regions A and B:

    bm,m =

    10

    dmdx

    dmdx

    + mm

    dx

    =

    11

    d

    dx

    dAd

    2+

    dx

    d2A

    A

    d+

    11

    d

    dx

    dBd

    2+

    dx

    d2B

    B

    d

    = 1

    1 2

    xm 1

    22

    +xm

    2 1 +

    2 2

    A d+

    11

    2

    xm+1

    1

    2

    2+

    xm+12

    1

    2

    2A

    d

    = 1

    xm

    1

    xm+1+

    xm8

    11

    (1 + )2d+xm+1

    8

    11

    (1 )2d

    = 1

    xm

    1

    xm+1+

    xm+ xm+13

    In summary the nonzero elementsbmj for2 m N 1are

    bm,m1 = 1

    xm+

    xm6

    bm,m =

    1

    xm+

    1

    xm+1

    +

    xm+ xm+13

    bm,m+1 = 1

    xm+1+

    xm+16

    form= N

    bN,N1 = 1

    xN+

    xN6

    bN,N = 1

    xN+

    xN6

    bN,N+1 = 0.

  • 8/13/2019 Weighted Residual Method

    21/37

    CHAPTER 6. WEIGHTED RESIDUAL METHODS 101

    The inhomogeneityF(x)is known analytically such that one can evaluate10

    mF(x)dxdirectly.However, in more complex situations it is more convenient to interpolate F(x) through the trialfunctions

    F(x) =

    N

    j=1Fjj.

    such that

    gm=Nj=1

    Fj

    10

    mjdx

    For the linear interpolation this yields

    gm=xm

    6 Fm1+

    xm+ xm+13

    Fm+xm+1

    6 Fm+1

    Finally consider the special case of a uniform grid with xm = xm+1 = x. In this case theequation for the coefficients becomes

    ym1 2ym+ ym+1x2

    +

    1

    6ym1+

    2

    3ym+

    1

    6ym+1

    =

    1

    6Fm1+

    2

    3Fm+

    1

    6Fm+1

    Exercise: Determine the elements at the min and max boundary, i.e., b1,1,b1,2, andb2,1.

    Elements withm = 1(y1 = 0): There is no equation for y1 needed becausey1 = 0such that the

    indices for the array dimensions decrease by 1.

    Elements withm= 2

    y2

    10

    d2dx

    d2dx

    + 22

    dx + y3

    10

    d2dx

    d3dx

    + 23

    dx=

    10

    2F(x)dx

    Elements withm= N

    yN

    1 1

    0 dNdx dN1dx + NN1 dx + yN 1

    0 dNdx dNdx + NN dx= 1

    0

    N

    F(x)dx

    Quadratic interpolation:

    The program offers the possibility to use a linear or quadratic finite element interpolation. For the

    second case the equations for thebmj are

  • 8/13/2019 Weighted Residual Method

    22/37

    CHAPTER 6. WEIGHTED RESIDUAL METHODS 102

    bm,m2 = 1

    6xm

    xm15

    bm,m1 = 4

    3xm

    +2xm

    15bm,m =

    7

    6

    1xm

    + 1

    xm+1

    +

    4

    15(xm+ xm+1)

    bm,m+1 = 4

    3xm+1+

    2xm+115

    bm,m+1 = 1

    6xm+1+

    xm+115

    and

    gm = xm

    15 Fm2+

    2xm15

    Fm1+ 4

    15(xm+ xm+1) Fm

    +2xm+1

    15 Fm+1

    xm15

    Fm+2

    A the boundarym= None obtains

    bN,N2 = 1

    6xN

    xN15

    bN,N1 = 43xN

    +2xN15

    bN,N = 7

    6

    1

    xN+

    4

    15xN

    gN = xN

    15 FN2+

    2xN15

    FN1+ 4

    15xNFN

    For the equations at midside nodes one obtains

    bm,m1 = 4

    3xm +2xm

    15

    bm,m = 8

    3xm+

    16xm15

    bm,m+1 = 4

    3xm+1+

    2xm+115

    gm = 2xm

    15 Fm1+

    16xm15

    Fm+2xm

    15 Fm+1

  • 8/13/2019 Weighted Residual Method

    23/37

    CHAPTER 6. WEIGHTED RESIDUAL METHODS 103

    The program Sturm solves the Sturm-Liouville equation (6.36) for the boundary condition and

    the inhomogeneity defined at the beginning of this section. The parameter int determines linear

    or quadratic finite element interpolation. The matrix inversion forBY = G is solved with theThomas algorithm (explained in Chapter 7) which is a special case of Gauss elimination for the

    case of tridiagonal banded matrices. The subroutines Bianca and ban sol factorize and solve banded

    matrices (tridiagonal or pentadiagonal;. The program can be downloaded from the website. Forthe program the following values for aiwere chosen:

    a1= 1.0, a2= 1.3, a3= 0.8, a4= 0.2, a5= 1.6

    The RMS error is defined as

    ||y yexact|| =

    1

    N 1

    N1i=1

    (yi yexact,i)2

    1/2

    Table summarizes the solution error for the Sturm-Liouville equation.

    Table 6.4: RMS solution error for the Sturm Liouville equation.

    Gridx Linear interpolation Quadratic interpolation

    1/4 0.014 0.30

    1/8 0.0039 0.0017

    1/16 0.00093 0.000072

    1/24 0.00040 0.000022

    Notes:

    Higher order interpolation on a coarse grid is not much better or can be worse than linearinterpolation.

    The solution error for linear interpolation decreases approximately with x2 and for quadraticinterpolation it decreases with x3.

    Smaller grid spacing than listed in the table requires higher machine accuracy (i. e., variablesneed to be defined as double precision.

    Sturm-Liouville problem, fem: quadratic interpolation

    nx= 9 a= 0.10E+01 -0.13E+01 0.80E+00 -0.20E+00 0.16E+01

    i= 2 x=0.12500 y=0.11654 yex+0.11611 dy=0.00044i= 3 x=0.25000 y=0.21361 yex+0.21262 dy=0.00099

    i= 4 x=0.37500 y=0.31541 yex+0.31575 dy=-.00034

    i= 5 x=0.50000 y=0.43428 yex+0.43608 dy=-.00180

    i= 6 x=0.62500 y=0.54579 yex+0.54528 dy=0.00051

    i= 7 x=0.75000 y=0.64174 yex+0.63904 dy=0.00270

    i= 8 x=0.87500 y=0.72503 yex+0.72543 dy=-.00040

    i= 9 x=1.00000 y=0.76235 yex+0.76568 dy=-.00333

    rms= 0.171E-02 nx= 9

  • 8/13/2019 Weighted Residual Method

    24/37

    CHAPTER 6. WEIGHTED RESIDUAL METHODS 104

    Table 6.5: Parameters used in program Sturm.f

    Parameter Description

    nx number of grid points

    nterm number of terms in the inhomogeneity

    x grid forxy, yex numerical and exact solutionb coefficients matrix

    g coefficients for the inhomogeneity

    f function F

    a coefficients a

    fd only used in ban sol

    6.3.3 Further applications of the finite element method

    Diffusion equation

    Consider the diffusion equation

    T

    t

    2T

    x2 = 0

    and linear finite element interpolation on a uniform grid. In this case the second derivative is treated

    as the second derivative in the Sturm-Liouville equation. The time derivative can be taken out of

    the integrals for the shape functions such that it is treated as the second term or the inhomogeneity

    in the Sturm-Liouville equation. Thus the linear finite element method leads to the equation

    1

    6

    dT

    dt

    i1

    +2

    3

    dT

    dt

    i

    +1

    6

    dT

    dt

    i

    x2(Ti1 2Ti+ Ti+1) = 0

    Here the form of the time derivative has not yet been specified. Also this form allows the freedom

    to evaluate the second derivative at a suitable time level. Defining Tn+1 =Tn+1 Tn and timederivatives asdT/dt= Tn+1/tand using a parameterto control the time level at which thesecond derivative is evaluated we obtain

    1

    6

    Tn+1i1t +

    2

    3

    Tn+1it +

    1

    6

    Tn+1i+1t

    (1 )

    Tni1 2Tni + T

    ni+1

    x2 +

    Tn+1i1 2Tn+1i + T

    n+1i+1

    x2

    = 0 (6.39)

    Defining operators

  • 8/13/2019 Weighted Residual Method

    25/37

    CHAPTER 6. WEIGHTED RESIDUAL METHODS 105

    Mx =

    1

    6, 2

    3, 1

    6

    Lxx =

    1

    x2

    , 2

    x2

    , 1

    x2

    we can write (6.39) in a more compact form

    MxTn+1i

    t

    (1 ) LxxT

    ni + LxxT

    n+1i

    = 0 (6.40)

    Comparison with the finite difference method suggests that the main difference to the finite ele-

    ment method is the distribution of the time derivative over adjacent nodes. The above equation is

    reminiscent of the general two-level scheme introduced earlier. This scheme is recovered by using

    the finite difference mass operator

    Mfdx = (0,1, 0)

    Finally (6.40) can be cast into the equation

    (Mx tLxx) Tn+1i = [Mx t (1 ) Lxx] T

    ni (6.41)

    which is an implicit equation forTn+1. Note

    for= 0the finite difference method generates an explicit method while the finite elementmethod yields an implicit algorithm;

    the matrix defined byMx tLxx is tridiagonal and can be solved by the Thomas algo-rithm (as in the case of Sturm.f);

    the symmetry ofMxand Lxx allows to construct an explicit scheme for t= x2/ (6);

    equation (6.41) is consistent with the diffusion equation and unconditionally stable for 0.5.

    Viscous flow

    Stationary viscous flow through a rectangular cross section (in the x, y plane, Figure ) can bedescribed by the thezcomponent of the momentum equation

    p

    z =

    2w

    x2 +

    2w

    y2

    (6.42)

    where the first term is the pressure gradient which drives the flow and w is the velocity profile ofthe flow. The problem is actual three-dimensional but is the pressure gradient is known or can be

  • 8/13/2019 Weighted Residual Method

    26/37

    CHAPTER 6. WEIGHTED RESIDUAL METHODS 106

    prescribed one can use (6.42) to determine the flow profile in the cross section of the duct. In many

    problems it is an advantage to normalize the basic equation. Sincex [a, a]and y [b, b]weuse as normalization

    x= xa , y= yb , w= ww0substitution in (6.42) yields

    p

    z =

    w0b2

    b

    a

    22 wx2 + 2 wy2

    such that the choicew0= / (b

    2p/z)yields

    b

    a2

    2

    w

    x2 +2

    w

    y2 + 1 = 0 (6.43)with the boundary conditionsw= 0at x= 1and y = 1.

    Similar to the procedure for the Sturm-Liouville equation and the diffusion equation we introduce

    the solution

    w= Ni=1

    wii(x, y)

    This yields the residualR =N

    i=1 wi

    (b/a)2 2i/x2 + 2i/y

    2

    + 1 and using the Galerkinmethod generates the equation

    Ni=1

    wi 11

    11

    ba2 2i

    x2 +

    2

    iy2

    mdxdy = 11

    11

    mdxdy

    orNi=1

    wi

    11

    b

    a

    2ix

    m

    x=1x=1

    dy+

    11

    iy

    m

    y=1y=1

    dx

    Ni=1

    wi

    11

    11

    b

    a

    2ix

    mx

    + i

    y

    my

    dxdy =

    11

    11

    mdxdy.

  • 8/13/2019 Weighted Residual Method

    27/37

    CHAPTER 6. WEIGHTED RESIDUAL METHODS 107

    For the chosen boundary conditions the first two integral are zero such that the resulting equation

    can be written as

    BW = G (6.44)

    with

    bmi =

    11

    11

    b

    a

    2ix

    mx

    + i

    y

    my

    dxdy (6.45)

    gm =

    11

    11

    mdxdy (6.46)

    In the following we replace the single index iwith a pairk, lrepresenting thexandy coordinates.The indicesk andl range from 2 to nx1 and from 2 to ny1 respectively because the boundary

    condition imply that the coefficient of the shape function at the boundaries is zero. Thex integra-tion of the first term in (6.45) yields the operator Lxx and they integration of this term yield theoperatorMy with

    Lxxwk,l = wk1,l 2wk,l+ wk+1,l

    x2 (6.47)

    Mywk,l = 1

    6wk,l1+

    2

    3wk,l+

    1

    6wk,l+1 (6.48)

    such that equation (6.44) assumes the form

    ba

    2My Lxx+ Mx Lyy

    wk,l = 1 (6.49)

    with

    My Lxxwk,l = 1

    6

    wk1,l1 2wk,l1+ wk+1,l1

    x2

    +

    2

    3

    wk1,l 2wk,l + wk+1,l

    x2

    +

    1

    6

    wk1,l+1 2wk,l+1+ wk+1,l+1

    x2

    (6.50)

    Mx Lyywk,l = 16wk1,l1 2wk1,l+ wk1,l+1

    y2 +2

    3wk,l1 2wk,l + wk,l+1

    y2

    +1

    6

    wk+1,l1 2wk+1,l+ wk+1,l+1

    y2

    (6.51)

    and similar for MxLyywk,l. In a corresponding finite difference approach we would have Mx,fd =(0, 1, 0).

    Notes:

  • 8/13/2019 Weighted Residual Method

    28/37

    CHAPTER 6. WEIGHTED RESIDUAL METHODS 108

    The operator Lxx and My are commutative. The result does not depend on the order theintegration in (6.47) is executed.

    The method provides a straightforward way to employ finite element methods similar tofinite difference methods.

    The result provides a simple equation which can be used with SOR to solve the coefficients for the

    shape functions. Solving equation (6.49) for wk,l yields

    wk,l = 3

    4c0[1. + c1(wk1,l1+ wk+1,l1+ wk1,l+1+ wk+1,l+1)

    +c2(wk1,l+ wk+1,l) + c3(wk,l1+ wk,l+1)]

    with

    c0 =

    b

    a

    21

    x2+

    1

    y2

    c1 = 1

    6c0

    c2 =

    b

    a

    22

    3x2

    1

    3y2

    c3 =

    b

    a

    21

    3x2+

    2

    3y2

    With the usual SOR method the solution is iterated using

    wn+1k,l =wnk,l+

    wk,l w

    nk,l

    The program duct.f can be found on the course web page. To provide a reference for the approxi-

    mate solution the exact solution is given by

    w= 8

    22 N

    i=1,3,5..N

    j=1,3,5.. (1)(i+j)/21

    ij iba 2 +j2cosix

    2 cosjy

    2 A second important measure for this problem is the total flow rate q, i.e., the flow integrated overthe cross sectional area

    q= 2

    8

    2

    3 Ni=1,3,5..

    Nj=1,3,5..

    1i2j2

    iba

    2+j2

  • 8/13/2019 Weighted Residual Method

    29/37

    CHAPTER 6. WEIGHTED RESIDUAL METHODS 109

    Table 6.6: Input parameters for the program duct.f

    Variable Value Description

    me 2 method: 1-linear elements, 2-3pt cent dif:

    nem 25 no terms in exact solution

    ipr 1 ipr=0, prints solutions to the output file duct.outniter 800 max no iterations for SOR

    bar 1.0e-0 aspect ratio a/b for channel

    eps .1e-5 tolerance par for SOR

    om 1.5e0 relaxation parameter (SOR),

    The structure is similar to that of Fivol.f. The program package uses an include file ductin which

    declares all variables and common blocks and it make use of a parameter file duct.dat. Variables

    declared in the parameter file are summarized in Table 6.6.

    Additional variables used in the program are listed in Table 6.7.

    Table 6.7: Other variables used in the program duct.f

    Variable Description

    nx, ny Number of nodes in thexandy directionsx, y xandy coordinates

    dx, dy grid separation in thexandy directionsflow, flowex iterated flow rate and exact flow rate

    f, fexact iterated and exact solutions

    rms RMS error

    The program generates an ASCII output file which lists basic parameter and results including the

    iterated solution and the exact solution and the correspond flow rates and errors. In addition the

    program generates a binary file which can be used as input for graphics routines. The supplied IDL

    program product.pro reads this this file and plots the iterated and exact solutions.

    The results of this program indicate that the error decreases with x2 andy2. The result for usingthe finite element method (fem) are very similar to those of the finite difference method (fdm). The

    error is very similar with slightly smaller errors for fdm while the flow rate is slightly closed to the

    exact flow rate for fem.

    Distorted computational domains - Isoparametric mapping

    The finite element method is very comparable to finite differences for Cartesian grids. However the

    strength or the finite element method is the ease to apply it to distorted domains and complicated

    geometries. It is illustrated that the introduction of local coordinates is a particular strength to eval-

    uate the integrals involving shape functions. There are various geometries to choose basic elements

    such as triangular, rectangular, or tetrahedral. The various method allow a simple grid refinement

    technique by just dividing a basic element into several new element of the same geometry.

  • 8/13/2019 Weighted Residual Method

    30/37

    CHAPTER 6. WEIGHTED RESIDUAL METHODS 110

    The advantage of the finite element method is that the coordinates themselves can be described by

    the shape functions. Figure shows a distorted grid with rectangular elements and the mapping into

    a local(, )coordinate system.

    =1 =+1

    =1

    =+1

    Figure 6.9: Isoparametric mapping.

    The transformation between(x, y)coordinates and(, )can be defined by

    x=

    4l=1

    l(, ) xl and y=

    4l=1

    l(, ) yl (6.52)

    with(xl, yl)as the x, ycoordinates of the corner numbered land l(, )is the shape function withthe value of 1 at the cornerl. The transformation affects the evaluation of the weighted residualintegral. Consider Laplaces equation = 0 as an example. The Galerkin fem produces a

    system of linear equations

    BW = G

    with

    bm,i =

    area

    ix

    mx

    + i

    y

    my

    dxdy

    Let us consider the first term

    I=

    ix

    mx

    dxdy

    The derivative /xcan be computed as

    =

    x

    x+

    y

    y

  • 8/13/2019 Weighted Residual Method

    31/37

    CHAPTER 6. WEIGHTED RESIDUAL METHODS 111

    such that/xand/y are related to/and / by

    //

    = [J]

    /x/y

    (6.53)

    with [J] = x/ y/

    x/ y/

    (6.54)

    where[J] is the Jacobian. The derivatives in the Jacobian can easily be computed from the map-ping (6.52), e.g.,

    y

    =

    4l=1

    l

    (, )

    yl

    From (6.53) one can determine the following explicit formulation for/x

    ix

    = 1

    detJ

    y

    i

    y

    i

    (6.55)

    Exercise: Derive equation (6.55).

    Usingdxdy= detJ ddone obtains

    I= 1

    1 1

    1

    1

    detJ y

    i

    y

    i

    y

    m

    y

    m

    ddAll derivatives in this formulation are known because of the simple form that thel assume. Theintegral can evaluated numerically or analytically.

    6.4 Spectral method

    The Galerkin spectral method is similar to the traditional Galerkin method but uses a suitable set

    of orthogonal functions such that

    kldx

    = 0 for k =l= 0 for k = l

    Example for such functions are Fourier series, Legendre, or Chebyshev polynomials. In this sense

    the spectral methods can be considered global methods rather than local as in the case of finite

    differences or finite elements.

  • 8/13/2019 Weighted Residual Method

    32/37

    CHAPTER 6. WEIGHTED RESIDUAL METHODS 112

    6.4.1 Diffusion equation

    Consider as an example the diffusion equation

    T

    t =

    2T

    x2

    forx [0, 1]and the boundary and initial conditions

    T(0, t) = 0, T(1, t) = 1, and T(x, 0) = sin (x) + x

    Approximate solution

    T= sin (x) + x+N

    j=1 aj(t)sin(jx)where the aj(t)are the unknown coefficients which need to be determined. This yields the residual

    R=Nj=1

    dajdt

    + (j)2 aj

    sin(jx) + 2 sin(x)

    Evaluation of the weighted integral

    R sin(mx) dxyields

    Nj=1

    dajdt

    + (j)2 aj 1

    0

    sin(jx)sin(mx) dx+ 2 10

    sin(x)sin(mx) dx= 0

    The integral yield

    10

    sin(jx)sin(mx) dx =

    1/2 for j=m

    0 for j =m

    1

    0

    sin(x)sin(mx) dx = 1/2 for m= 1

    0 for m = 1

    which yields

    damdt

    + (j)2 am+ rm = 0, m= 1,...,N

    rm =

    2 for m= 1

    0 for m = 1

  • 8/13/2019 Weighted Residual Method

    33/37

    CHAPTER 6. WEIGHTED RESIDUAL METHODS 113

    with the solution

    a1 = e2t 1

    am = 0

    The solution forT is therefore

    T= sin (x) e2t + x

    This is in fact the exact solution, however, this has been obtained for this particular set of initial

    and boundary conditions. For a more realistic case of

    T(x, 0) = 5x 4x2

    and replacingsin (x) + xwith5x 4x2 in the trial solution one obtains

    rm=

    16m for m= 1, 3, 5,...0 for m= 2, 4, 6,...

    With forward time differencingdam/dt= (an+1m a

    nm) /tone obtains

    an+1m =anm t

    (j)2 anm+ rm

    Table 6.8: Value of the solution at x= 0.5for different times

    t N=1 N=3 n=5 Exact solution

    0 1.5 1.5 1.5 1.5

    0.1 0.851 0.889 0.881 0.885

    0.2 0.610 0.648 0.640 0.643

    Table 6.8 shows the value ofT for selected times and different values ofN atx = 0.5. Note thatthe error is caused by two sources one of which is the limited accuracy of the representation in

    terms of the base functions and the other is the error in the temporal integration.

    Notes:

    The spectral method achieves relatively high accuracy with relatively few unknowns.

    For Dirichlet conditions the method reduces the problem to a set of ordinary differentialequations

    Treatment of nonlinear terms is not yet clear (and can be difficult)

  • 8/13/2019 Weighted Residual Method

    34/37

    CHAPTER 6. WEIGHTED RESIDUAL METHODS 114

    6.4.2 Neumann boundary conditions

    Let us now consider the diffusion equation again, however, for Neumann boundary conditions.

    Specifically the initial and boundary conditions are

    T(x, 0) = 3 2x 2x2 + 2x3,

    T

    x(0, t) = 2.0 and T(1, t) = 1.0

    Different from the prior example it is not attempted to incorporate the initial and boundary condi-

    tions into the approximate solution. Rather a general trial solution is used

    T(x, t) =b0(t) +N

    j=1[aj(t)sin(j2x) + bj(t)cos(j2x)]

    The boundary conditions require the following relations for the coefficients

    Nj=1

    aj2j = 2 ,Nj=0

    bj = 1

    which can be used to eliminateaN andbNfrom the the approximate solution:

    aN= 1N

    N

    1j=1

    ajjN

    , bN= 1 N

    1j=0

    bj

    This yields for the approximate solution

    T(x, t) = cos (N2x) 1

    Nsin(N2x) +

    N1j=1

    aj(t)

    sin(j2x)

    j

    Nsin(N2x)

    +

    N1

    j=0

    bj(t)[cos(j2x) + cos (N2x)]

    This implies that the terms in square brackets now need to be considered as the base functions or

    wma = sin (m2x) m

    Nsin(N2x) , 1 m N 1

    wmb = cos (m2x) + cos (N2x) , 0 m N 1

  • 8/13/2019 Weighted Residual Method

    35/37

    CHAPTER 6. WEIGHTED RESIDUAL METHODS 115

    Substitution into the the diffusion equation yields the residual

    R =N1

    j=1 dajdt

    + (2j)2 aj

    sin(2jx)

    dajdt

    + (2N)2 aj

    j

    Nsin (2N x)

    +

    N1j=0

    dbjdt

    + (2j)2 bj

    cos (2jx) +

    dbjdt

    + (2N)2 bj

    cos(2N x)

    + (2N)2 cos (2N x) 4Nsin (2N x)

    Evaluating the weighted residuals yields

    damdt

    + (2m)2 am+m

    N

    N1

    j=1j

    N dajdt

    + (2N)2 aj = 4N (6.56)

    dbmdt

    + (2m)2 bm+N1j=0

    dbjdt

    + (2N)2 bj

    = (2N)2 (6.57)

    2db0dt

    +N1j=0

    dbjdt

    + (2N)2 bj

    = (2N)2 (6.58)

    Equations (6.56) foramare linearly independent from equations (6.57) and can be solved indepen-dently. To solve for the time integration it is necessary, however, to factorize the the system and

    carry out a matrix multiplication for each time step. Start values foramand bmare easily obtained

    using the trial solution for the initial condition.Note, since the problem is linear the factorization is only needed once because the subsequent time

    steps always use the same matrix (coefficients in equations (6.56) to (6.58) are constant).

    6.4.3 Pseudospectral method

    Main disadvantage of spectral method is large computational effort particularly for nonlinear prob-

    lems. An alternative to Galerkin method which basically solve the diffusion equation in spectral

    space is to use a mixture of spectral and real space. An frequently used method in this category is

    the pseudospectral approach which uses the collocation method. The example is again the diffusion

    equation

    u

    t

    2u

    x2 = 0

    subject to the boundary and initial conditions

    u (1, t) = 1, u (1, t) = 1, u (x, 0) = sin x+ x

  • 8/13/2019 Weighted Residual Method

    36/37

    CHAPTER 6. WEIGHTED RESIDUAL METHODS 116

    When compared to the spectral method, the pseudospectral method does not determine the solution

    entirely in spectral space. Recall that the solution for the Galerkin spectral method is found by

    integrating the spectral coefficients. For a linear problem this is feasible but a nonlinear problem

    requires the inversion of a large matrix for each time step.

    The pseudo spectral method often uses an expansion

    u (x, t) =N+1k=1

    ak(t) Tk1(x)

    consists of three basic steps:

    Given a solution unj one determines the spectral coefficientsak. This transforms the problemfrom physical to spectral space. Using Chebichev Polynomials the step can be done with a

    fast Fourier Transform (FFT) if the collocation points arexj = cos (j1)N

    (time efficient

    with number of operations proportional toNlog N).

    The next step is to evaluate the second derivative 2u/x2 from the coefficients ak whichmakes use of recurrence relations and is also very efficient:

    u

    x =

    N+1k=1

    a(1)k Tk1(x)

    2u

    x2 =

    N+1

    k=1a(2)k Tk1(x)

    The final step then is to integrate in time. Different from the Galerkin spectral method this is

    done in real space directly for u: un+1j =unj +t

    2ux2

    nj

    thereby avoiding to have to solve

    a large system of equations for the time derivatives ofdak/dt.

    6.5 Summary on different weighted residual methods:

    local approximations: finite difference, finite volume, finite element

    irregular domains

    variable grid resolution

    boundary conditions relatively simple

    global base function: spectral methods

    high accuracy

  • 8/13/2019 Weighted Residual Method

    37/37

    CHAPTER 6. WEIGHTED RESIDUAL METHODS 117

    arbitrary often differentiable

    Galerkin method computationally expensive for nonlinear problems

    Pseudospectral method employs spectral space only to determine spatial derivatives

    (much more efficient)