book3

531
Numerical Solution of Partial Differential Equations John A. Trangenstein 1 December 6, 2006 1 Department of Mathematics, Duke University, Durham, NC 27708-0320 [email protected].

Upload: jiten-ahuja

Post on 06-Nov-2015

216 views

Category:

Documents


1 download

DESCRIPTION

book 3

TRANSCRIPT

  • Numerical Solution of Partial Differential Equations

    John A. Trangenstein1

    December 6, 2006

    1Department of Mathematics, Duke University, Durham, NC 27708-0320 [email protected].

  • 2

  • Contents

    1 Introduction to Partial Differential Equations 11.1 Types of Second-Order Partial Differential Equations . . . . . . . . . . . . . 11.2 Physical Examples of Diffusion . . . . . . . . . . . . . . . . . . . . . . . . . 3

    1.2.1 Heat Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.2.2 Electrical Wave Propagation in the Heart . . . . . . . . . . . . . . . 51.2.3 Miscible Displacement Model . . . . . . . . . . . . . . . . . . . . . . 61.2.4 Buckley-Leverett Model . . . . . . . . . . . . . . . . . . . . . . . . . 91.2.5 Thin Films . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141.2.6 Incompressible Fluid Flow . . . . . . . . . . . . . . . . . . . . . . . . 151.2.7 Summary of Physical Examples . . . . . . . . . . . . . . . . . . . . . 16

    2 Parabolic Equations 172.1 Theory of Linear Parabolic Equations . . . . . . . . . . . . . . . . . . . . . 17

    2.1.1 Fourier Transform Methods . . . . . . . . . . . . . . . . . . . . . . . 172.1.2 Reflection and Superposition . . . . . . . . . . . . . . . . . . . . . . 202.1.3 Maximum Principle . . . . . . . . . . . . . . . . . . . . . . . . . . . 212.1.4 Bounded Domains and Separable Solutions . . . . . . . . . . . . . . 22

    2.2 Finite Difference Methods in One Dimension . . . . . . . . . . . . . . . . . 242.2.1 Continuous-In-Time Methods . . . . . . . . . . . . . . . . . . . . . . 242.2.2 Explicit Centered Differences . . . . . . . . . . . . . . . . . . . . . . 312.2.3 Programs for Explicit Centered Differences . . . . . . . . . . . . . . 33

    First Explicit Centered Difference Program . . . . . . . . . . . . . . 33Second Explicit Centered Difference Program . . . . . . . . . . . . . 34Third Explicit Centered Difference Program . . . . . . . . . . . . . . 35Fourth Explicit Centered Difference Program . . . . . . . . . . . . . 36Fifth Explicit Centered Difference Program . . . . . . . . . . . . . . 37

    2.2.4 Implicit Centered Differences . . . . . . . . . . . . . . . . . . . . . . 382.2.5 Higher-Order Temporal Discretization . . . . . . . . . . . . . . . . . 41

    2.3 Consistency, Stability and Convergence . . . . . . . . . . . . . . . . . . . . 46

    i

  • ii CONTENTS

    2.3.1 Stability of Explicit and Implicit Centered Differences . . . . . . . . 472.3.2 Error Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 482.3.3 Stability of the Crank-Nicolson Scheme . . . . . . . . . . . . . . . . 522.3.4 Lax Convergence Theorem . . . . . . . . . . . . . . . . . . . . . . . 54

    2.4 Fourier Analysis of Finite Difference Schemes . . . . . . . . . . . . . . . . . 562.4.1 Constant Coefficient Equations and Waves . . . . . . . . . . . . . . 572.4.2 Dimensionless Groups . . . . . . . . . . . . . . . . . . . . . . . . . . 582.4.3 Linear Finite Differences and Diffusion . . . . . . . . . . . . . . . . . 592.4.4 Fourier Analysis of Finite Difference Schemes . . . . . . . . . . . . . 612.4.5 Lax Equivalence Theorem . . . . . . . . . . . . . . . . . . . . . . . . 69

    2.5 Measuring Accuracy and Efficiency . . . . . . . . . . . . . . . . . . . . . . . 842.6 Finite Difference Methods in Multiple Dimensions . . . . . . . . . . . . . . 90

    2.6.1 Unsplit Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 902.6.2 Operator Splitting Methods . . . . . . . . . . . . . . . . . . . . . . . 91

    3 Iterative Linear Algebra 993.1 Relative Efficiency of Implicit Computations . . . . . . . . . . . . . . . . . . 993.2 Neumann Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1033.3 Perron-Frobenius Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . 1083.4 M Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1173.5 Iterative Improvement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125

    3.5.1 Richardsons Iteration . . . . . . . . . . . . . . . . . . . . . . . . . . 1273.5.2 Jacobi Iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1333.5.3 Gauss-Seidel Iteration . . . . . . . . . . . . . . . . . . . . . . . . . . 1373.5.4 Successive Over-Relaxation . . . . . . . . . . . . . . . . . . . . . . . 1413.5.5 Termination Criteria for Iterative Methods . . . . . . . . . . . . . . 147

    3.6 Incomplete Factorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1503.6.1 Block Factorization of Block Tridiagonal Matrices . . . . . . . . . . 1503.6.2 Approximate Factorization . . . . . . . . . . . . . . . . . . . . . . . 1523.6.3 Banded Part of an Inverse . . . . . . . . . . . . . . . . . . . . . . . . 1543.6.4 Approximate Factorization and Iterative Improvement . . . . . . . . 1553.6.5 Incomplete Factorization for Three-Dimensional Problems . . . . . . 1563.6.6 Incomplete Factorization Software . . . . . . . . . . . . . . . . . . . 156

    3.7 Conjugate Gradients . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1573.7.1 Self-Adjoint Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . 1583.7.2 Preconditioned Conjugate Gradients . . . . . . . . . . . . . . . . . . 167

    3.8 Minimum Residual Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . 1703.8.1 Orthomin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1703.8.2 GMRES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177

    3.9 Nonlinear Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184

  • CONTENTS iii

    3.9.1 Newton Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . 1843.9.2 Nonlinear Krylov Algorithms . . . . . . . . . . . . . . . . . . . . . . 185

    3.10 Algebraic Multigrid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1903.10.1 Algebraic Multigrid Algorithm . . . . . . . . . . . . . . . . . . . . . 1903.10.2 Multigrid Error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1913.10.3 Coarse Grid Correction . . . . . . . . . . . . . . . . . . . . . . . . . 1933.10.4 Pre Smoothing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1963.10.5 Prolongation and Restriction . . . . . . . . . . . . . . . . . . . . . . 1973.10.6 Steady-State Diffusion in One Dimension . . . . . . . . . . . . . . . 1983.10.7 Heat Equation in One Dimension . . . . . . . . . . . . . . . . . . . . 2023.10.8 2D Laplace Equation . . . . . . . . . . . . . . . . . . . . . . . . . . . 2053.10.9 Work Estimates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2073.10.10Multigrid Debugging Techniques . . . . . . . . . . . . . . . . . . . . 208

    4 Finite Element Methods 2114.1 Galerkin Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211

    4.1.1 Weak Formulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2124.1.2 Galerkin Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218

    4.2 Finite Element Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2204.2.1 Finite Elements in 1D . . . . . . . . . . . . . . . . . . . . . . . . . . 2214.2.2 Triangular Finite Elements . . . . . . . . . . . . . . . . . . . . . . . 228

    4.3 Elliptic Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2374.3.1 Multi-Indices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2374.3.2 Elliptic Differential Operators . . . . . . . . . . . . . . . . . . . . . . 2384.3.3 Dirichlet Problems for Elliptic Operators . . . . . . . . . . . . . . . 240

    4.4 Elliptic Regularity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2424.4.1 Function Norms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2424.4.2 Function Spaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2444.4.3 Sobolev Spaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2474.4.4 Sobolev Imbedding Theorems . . . . . . . . . . . . . . . . . . . . . . 2484.4.5 Hilbert Scales and Fractional-Order Sobolev Spaces . . . . . . . . . 2514.4.6 Sobolev Trace Theorems . . . . . . . . . . . . . . . . . . . . . . . . . 253

    4.5 Elliptic Differential Operators . . . . . . . . . . . . . . . . . . . . . . . . . . 2594.5.1 Gardings Inequality . . . . . . . . . . . . . . . . . . . . . . . . . . . 2594.5.2 Existence and Uniqueness for Weak Problems . . . . . . . . . . . . . 2604.5.3 Higher-Order Dependence on the Data . . . . . . . . . . . . . . . . . 265

    4.6 Piecewise Polynomial Approximation . . . . . . . . . . . . . . . . . . . . . . 2684.6.1 Bramble-Hilbert Lemma . . . . . . . . . . . . . . . . . . . . . . . . . 2684.6.2 Polynomial Approximation on Star-Shaped Domains . . . . . . . . . 275

    4.7 Galerkin Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282

  • iv CONTENTS

    4.7.1 Well-Posedness of Galerkin Equations . . . . . . . . . . . . . . . . . 2834.7.2 Approximation Assumption . . . . . . . . . . . . . . . . . . . . . . . 2874.7.3 Hm Error Estimates . . . . . . . . . . . . . . . . . . . . . . . . . . . 2884.7.4 Convergence for Rough Problems . . . . . . . . . . . . . . . . . . . . 2894.7.5 H0 Error Estimates . . . . . . . . . . . . . . . . . . . . . . . . . . . 2904.7.6 Non-Positive Weak Forms . . . . . . . . . . . . . . . . . . . . . . . . 297

    5 Finite Element Implementations 3035.1 Computational Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3035.2 Finite Element Assumptions . . . . . . . . . . . . . . . . . . . . . . . . . . . 3045.3 Finite Elements in 1D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306

    5.3.1 Essential and Natural Boundary Conditions . . . . . . . . . . . . . . 3145.3.2 Higher Order Finite Elements . . . . . . . . . . . . . . . . . . . . . . 3175.3.3 Hierarchical Elements . . . . . . . . . . . . . . . . . . . . . . . . . . 333

    5.4 Approximation Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3375.4.1 Piecewise Linear Approximation . . . . . . . . . . . . . . . . . . . . 3375.4.2 Continuous Piecewise Quadratic Approximation . . . . . . . . . . . 3475.4.3 Higher Order Piecewise Polynomial Approximation . . . . . . . . . . 3475.4.4 Barycentric Coordinates . . . . . . . . . . . . . . . . . . . . . . . . . 3505.4.5 Coordinate Transformations . . . . . . . . . . . . . . . . . . . . . . . 353

    5.5 Triangular Finite Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . 3555.5.1 Quadrature Rules for Triangles . . . . . . . . . . . . . . . . . . . . . 3555.5.2 Linear Lagrange Element . . . . . . . . . . . . . . . . . . . . . . . . 3565.5.3 Quadratic Lagrange Element . . . . . . . . . . . . . . . . . . . . . . 3575.5.4 Cubic Lagrange Element . . . . . . . . . . . . . . . . . . . . . . . . . 3585.5.5 General Lagrange Elements . . . . . . . . . . . . . . . . . . . . . . . 3595.5.6 Hermite Cubics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3605.5.7 Hierarchical Triangular Elements . . . . . . . . . . . . . . . . . . . . 364

    5.6 Quadrilateral Finite Elements . . . . . . . . . . . . . . . . . . . . . . . . . . 3665.6.1 Quadrature Rules for Quadrilaterals . . . . . . . . . . . . . . . . . . 3675.6.2 Tensor Product Linears: V01 . . . . . . . . . . . . . . . . . . . . . . . 3675.6.3 Biquadratics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3705.6.4 Bicubics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3705.6.5 Hermite Bicubics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3715.6.6 Serendipity Quadratics . . . . . . . . . . . . . . . . . . . . . . . . . . 3715.6.7 Hierarchical Quadrilateral Elements . . . . . . . . . . . . . . . . . . 371

    5.7 Three-Dimensional Finite Elements . . . . . . . . . . . . . . . . . . . . . . . 3725.7.1 3D Rectangular Finite Elements . . . . . . . . . . . . . . . . . . . . 3725.7.2 3D Tetrahedral Finite Elements . . . . . . . . . . . . . . . . . . . . . 3765.7.3 3D Wedge Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . 377

  • CONTENTS v

    5.8 Error Estimates for Linear Elements . . . . . . . . . . . . . . . . . . . . . . 3785.9 Condition Number Estimates for Linear Elements . . . . . . . . . . . . . . . 3885.10 Interpolation Error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399

    5.10.1 Low-Order Polynomials on Triangles . . . . . . . . . . . . . . . . . . 3995.10.2 General Interpolation Errors . . . . . . . . . . . . . . . . . . . . . . 401

    5.11 Numerical Quadrature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4035.12 Interpolated Boundary Conditions . . . . . . . . . . . . . . . . . . . . . . . 4125.13 Finite Elements and Multigrid . . . . . . . . . . . . . . . . . . . . . . . . . 417

    5.13.1 Full Multigrid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4175.13.2 Weak Formulation of the Problem . . . . . . . . . . . . . . . . . . . 4185.13.3 Linear Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4195.13.4 Smoothers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4265.13.5 Multigrid Error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4305.13.6 Matrix-Vector Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . 435

    5.14 Mixed and Hybrid Finite Elements . . . . . . . . . . . . . . . . . . . . . . . 4455.14.1 Review of Quadratic Programming . . . . . . . . . . . . . . . . . . . 4455.14.2 Mixed Formulation of Physical Problems . . . . . . . . . . . . . . . 447

    5.15 Mixed and Hybrid Finite Elements . . . . . . . . . . . . . . . . . . . . . . . 4485.15.1 Lowest Order Mixed Finite Element Method . . . . . . . . . . . . . 4505.15.2 Hybrid Mixed Finite Element Method . . . . . . . . . . . . . . . . . 4525.15.3 Mathematical Formulation of the Hybrid Mixed Finite Element Method4535.15.4 Positive-Definiteness of the Linear System . . . . . . . . . . . . . . . 4545.15.5 Numerical Implementation of the Hybrid Mixed Finite Element Method4555.15.6 Comments on the Hybrid Mixed Finite Element Method . . . . . . . 4585.15.7 Constrained Minimization and Lagrangians . . . . . . . . . . . . . . 4705.15.8 Well-Posedness of the Weak Mixed Problem . . . . . . . . . . . . . . 4715.15.9 Galerkin Approximations for the Mixed Problem . . . . . . . . . . . 4785.15.10Raviart-Thomas Spaces . . . . . . . . . . . . . . . . . . . . . . . . . 4835.15.11Lowest Order Mixed Finite Element Method . . . . . . . . . . . . . 4855.15.12Hybrid Mixed Finite Element Method . . . . . . . . . . . . . . . . . 4875.15.13Mathematical Formulation of the Hybrid Mixed Finite Element Method4875.15.14Positive-Definiteness of the Linear System . . . . . . . . . . . . . . . 4895.15.15Convergence Estimates for the Hybrid Mixed Finite Element Method 4905.15.16Numerical Implementation of the Hybrid Mixed Finite Element Method4905.15.17Comments on the Hybrid Mixed Finite Element Method . . . . . . . 492

    6 Finite Element Methods for Parabolic Equations 4956.1 Well-Posedness of Parabolic Problems . . . . . . . . . . . . . . . . . . . . . 495

    6.1.1 Existence and Uniqueness of Generalized Solutions . . . . . . . . . . 4966.1.2 Continuous Dependence on the Data . . . . . . . . . . . . . . . . . . 498

  • vi CONTENTS

    6.2 Galerkin Methods for Parabolic Problems . . . . . . . . . . . . . . . . . . . 5006.2.1 Continuous-Time Galerkin Method . . . . . . . . . . . . . . . . . . . 5006.2.2 Existence of the Continuous-Time Galerkin Approximation . . . . . 5016.2.3 Finite Element Approximations for Parabolic Problems . . . . . . . 502

    6.3 Error Estimates for Parabolic Galerkin Methods . . . . . . . . . . . . . . . 507

    Index 520

  • Chapter 1

    Introduction to Partial DifferentialEquations

    1.1 Types of Second-Order Partial Differential Equations

    Partial differential equations arise in a number of physical problems, such as fluid flow,heat transfer, solid mechanics and biological processes. These equations often fall into oneof three types. Hyperbolic equations are most commonly associated with advection, andparabolic equations are most commonly associated with diffusion. Elliptic equationsare most commonly associated with steady-states of either parabolic or hyperbolic problems.

    It is reasonably straightforward to determine the type of a general second-order partialdifferential equation. Consider the equation

    dj=1

    di=1

    Aij2u

    xixj+

    di=1

    biu

    xi+ cu = 0 .

    Without loss of generality, we can assume that A is symmetric, by averaging the coefficientsof the i, j and j, i derivative terms. By performing a linear coordinate transformation

    = Fx

    we hope to transformation the equation into a simpler form. We will find a way to choosethe transformation matrix F below.

    1

  • 2 CHAPTER 1. INTRODUCTION TO PARTIAL DIFFERENTIAL EQUATIONS

    Note that

    ixj

    = Fij

    u

    xi=

    dj=1

    u

    j

    jxi

    =dj=1

    u

    jFji

    2u

    xixj=

    d`=1

    dk=1

    kxi

    2u

    k`

    `xj

    =d`=1

    dk=1

    Fki2u

    k`F`j

    After the coordinate transformation, the differential equation takes the form

    0 =dj=1

    di=1

    Aij

    [d`=1

    dk=1

    Fki2u

    k`F`j

    ]+

    di=1

    bi

    dj=1

    u

    jFji

    + cu=

    d`=1

    dk=1

    dj=1

    di=1

    FkiAijF`j

    2uk`

    +dj=1

    [di=1

    Fjibi

    ]u

    j+ cu

    We would like to choose the matrix F so that D = FAF> is diagonal. Recall that wecan diagonalize a symmetric matrix by means of an orthogonal change of variables. In otherwords, we can choose F to be an orthogonal matrix.

    IfD has nonzero diagonal entries all of the same sign, the differential equation is elliptic.The canonical example of an elliptic equation is the Laplace equation x xu = 0. If Dhas nonzero diagonal entries with one entry of different sign from the others, then thedifferential equation is hyperbolic. The canonical example of a hyperbolic equation is thewave equation

    2ut2

    x xu = 0. We will discuss simple hyperbolic equations in chapter??, and general hyperbolic equations in chapter ??. If D has one zero diagonal entry, theequation may be parabolic. The canonical example of a parabolic equation is the heatequation ut + x xu = 0.

    Example 1.1-1: Consider the differential equation

    2u

    x21+2u

    x22

    2u

    x3x4= 0

    which arises in the Khokhlov-Zabolotskaya-Kuznetsov (KZK) equation for biomedical imag-ing. In this case, the coefficient matrix is

    A =

    1 0 0 00 1 0 00 0 0 1/20 0 1/2 0

  • 1.2. PHYSICAL EXAMPLES OF DIFFUSION 3

    A coordinate transformation that diagonalizes A is given by

    F =

    1 0 0 00 1 0 00 0 1/

    2 1/

    2

    0 0 1/2 1/2

    and the new coefficient matrix is

    D =

    1 0 0 00 1 0 00 0 1/2 00 0 0 1/2

    In this case, we see that the KZK equation is hyperbolic.

    1.2 Physical Examples of Diffusion

    1.2.1 Heat Flow

    The simplest model of heat flow is based on three principles: conservation of energy,Fouriers law of cooling and a constitutive law. The simplest constitutive law assumes thatthe total energy per volume e satisfies

    e = c(T T0) ,

    where is the density, c is the heat capacity and T is the temperature. We assume thatother forms of energy, such as kinetic energy, are negligible. Fouriers Law of Coolingstates that the flux of the energy is proportional to the temperature gradient,

    f = kxT ,

    with proportionality factor k called the thermal conductivity. Finally, conservation ofenergy gives us the conservation law

    e

    t+ x f = 0 .

    When we substitute the expressions for the energy and the energy flux into the conservationlaw, we obtain the partial differential equation

    cT

    t+ x (kxT ) = 0 .

  • 4 CHAPTER 1. INTRODUCTION TO PARTIAL DIFFERENTIAL EQUATIONS

    For water, we have c 4 103 Joules per kilogram per degree Celcius, k 0.6 Joules permeter per second per degree Celcius, and 103 kilograms per cubic meter. For ice, wehave c 2 103 Joules per kilogram per degree Celcius, k 2 Joules per meter per secondper degree Celcius, and 103 kilograms per cubic meter.

    In order to specify a unique solution to the problem, we must provide additional in-formation. Initially, let us consider a one-dimensional material. The initial temperaturedistribution is assumed to be given throughout the problem domain:

    T (x, 0) = T0(x) , x .In one dimension, we could provide boundary conditions in a variety of ways. For example,we could specify the energy flux at the left-hand side

    kTx

    (0, t) = f0(t) ,

    and the temperature at the right-hand side

    T (L, t) = TL(t) .

    These boundary conditions are intended as examples; other boundary conditions are pos-sible. For boundary conditions in multiple dimensions, we might consider a region withspecified heat flux:

    x t > 0 , kn xT (x, t) = f(x, t)where n is the unit outer normal to at x. Alternatively, we might consider a materialcontained in a heat bath at specified temperature T :

    x t > 0 , T (x, t) = T .When the density , heat capacity c and the thermal conductivity k are constants, we

    can use these constants to non-dimensionalize the problem. If L is some characteristiclength of the problem domain , let the dimensionless distance and dimensionless time be(respectively)

    =xL

    , =kt

    cL2.

    As a function of dimensionless variables, the temperature will be

    T (, ) = T (L, cL2/k) .

    Then it is easy to see that conservation of energy can be written

    T

    = T , L , 0 < . (1.2-1)

  • 1.2. PHYSICAL EXAMPLES OF DIFFUSION 5

    This dimensionless equation is commonly called the heat equation. Note that the initialand boundary conditions are also easy to write in dimensionless variables.

    As presented here, the heat equation is a purely parabolic equation. Solutions of theheat equation are instantly smooth, in spite of initial discontinuities. The solutions alsotend toward a steady-state, unless forced by time-dependent boundary conditions.

    Exercises 1.2.11. Show that the heat equation is parabolic (see the definition of parabolic in the introduction).

    2. Show how to write the initial and boundary conditions for heat conservation in terms of dimensionlessvariables.

    3. For heat transfer in mixtures of water and ice, the latent heat of fusion must be considered. Inthis case, the temperature T is related to the energy per volume e by

    T =

    8 334 Joules / kilogram0, 0 < e/ < 334 334 Joules / kilogram

    Write down the equations describing the temperature distribution in an insulated glass of water.

    1.2.2 Electrical Wave Propagation in the Heart

    The FitzHugh-Nagumo model [55] is designed to represent the qualitative featuresof electrical wave propagation in the heart:

    t

    [vr

    ]=[x (Dxv) + f(v, r)

    g(v, r)

    ]x t > 0[

    vr

    ](x, 0) =

    [v0r0

    ](x) x ,

    n Dxv(x, t) = 0 x t > 0 .Here v represents the electrical potential, and r is a recovery variable that represents theaction of cell membranes in controlling the flow of ions. The functions f and g describe thelocal kinetics:

    f(v, r) = Hv(v V0)(Vm v) r ,g(v, r) = av br .

    In this model H, Vm, V0, a and b are constants.This model is a simple reaction-diffusion system. The reactions are represented by the

    functions f and g. Typically f is a fast reaction, meaning that fv is large. This fast reactiontends to drive v rapidly to steady-state values determined by r, while the diffusion tendsto spread discontinuities. Under appropriate circumstances, the combined effect producestraveling waves [44, 55, 64].

    Exercises 1.2.2

  • 6 CHAPTER 1. INTRODUCTION TO PARTIAL DIFFERENTIAL EQUATIONS

    1. Find the stationary points of the FitzHugh-Nagumo reactions f and g. Which of these are stable?

    2. Suppose that D = 0, 0 < V0 + (Iv>v vv>) tv + Ic

    ]xc .

    Here, ` and t are the longitudinal and transverse mixing lengths, c is the diffusivity ofthe tracer and is the tortuosity of the rock. The equation for the flux of water is similar:we replace c by 1 c to get

    fw = (1 c)v +[v`vv

    > + (Iv>v vv>) tv + Ic

    ]xc .

    We must have equations representing the conservation of mass for water and the tracer.It is easy to see that the mass of tracer per bulk (rock) volume is c, and the mass of waterper bulk volume is (1 c). Thus conservation of the tracer and water can be written

    c

    t+ x (fc) = 0 , (1.2-3a)

    (1 c)t

    + x (fw) = 0 . (1.2-3b)

    If we add the tracer and water conservation equations together, we obtain

    0 = x v = x {K [xp+ g(c)] 1

    (c)

    }. (1.2-4)

    It is interesting to note that the coefficients (c) and (c) in this problem are functions ofthe variable tracer concentration. Since the tracer concentration c can change in time, socan the pressure p. This completes the description of the miscible displacement model.

    Next, let us restrict our discussion to one dimension. Since

    vx

    = 0 ,

    we see that the Darcy velocity v is independent of position x. The transverse mixing lengtht has no effect in one dimension, so the tracer flux simplifies to

    fc = cv {|v|` + c

    }c

    x.

  • 8 CHAPTER 1. INTRODUCTION TO PARTIAL DIFFERENTIAL EQUATIONS

    Given the Darcy velocity, the two mass conservation equations become redundant. It willsuffice to work with conservation of the tracer:

    c

    t+vcx

    =

    x

    {(|v|` + c

    )c

    x

    }. (1.2-5)

    In the typical case, we specify the total fluid velocity v(t) and the tracer concentrationc(xL, t) at inflow. In this case, the equations for conservation of mass of the tracer (1.2-5)and for the fluid pressure (1.2-4) decouple; the solution of the pressure equation can bedetermined by specifying the fluid pressure at outflow. Suppose that we are given p(xR, t) =pR(t) at the right-hand boundary. Since the one-dimensional pressure equation says that

    K[px

    + g]1= v

    is equal to the inflow fluid velocity, the solution of the pressure equation is

    p(x, t) = pR(t) g xRx

    (c(x, t)) dx v(t) xrx

    (c(x, t))K(x)

    dx .

    Some common test problems choose the fluid velocity to be around 30 centimeters perday, the porosity to be 0.25, and the longitudinal mixing length L to be 0.01 times theproblem length. Normally, molecular diffusion is negligible unless we are working on veryfine scales (close to the scale of the rock pores):

    c |v|`

    .

    Note that the mass conservation law (1.2-5) involves convection due to the Darcy veloc-ity, and diffusion due to the molecular diffusion and convective mixing. The diffusive termsappear on the right-hand side of the equation. The diffusion due to convective mixing isrelated to the fluid velocity and is not isotropic. Typically, these diffusive fluxes are verysmall compared to the convective fluxes. Nevertheless, the mass conservation equation isa convection-diffusion equation, and its efficient numerical solution will use techniques forboth hyperbolic and parabolic equations.

    Also note that the incompressibility condition on the velocity field represents the limit,as the compressibility of the fluid becomes small, of a compressible equation. We will notpresent that more general equation here. Instead, we will remark that the incompressibilitycondition is equivalent to the steady-state of the compressible parabolic equation.

    The solutions of the miscible displacement problem can show either stable transport ofthe tracer with slight spreading due to diffusive Fickian forces, or unstable viscous fingeringif the tracer reduces the fluid viscosity significantly. Heterogeneities in the permeability canproduce flow channels that look like viscous fingers in space but behave quite differently intime.

    Exercises 1.2.3

  • 1.2. PHYSICAL EXAMPLES OF DIFFUSION 9

    1. Show that for fixed tracer concentration c, equation (1.2-4) is an elliptic equation in pressure p.

    2. Show that for fixed velocity v, equation (1.2-5) is a parabolic equation in tracer concentration c. Ifthe mixing lengths and diffusivity are zero, show that this equation is hyperbolic.

    1.2.4 Buckley-Leverett Model

    The Buckley-Leverett model for flow of two immiscible incompressible phases in aporous medium is important to models of oil reservoirs and contaminated aquifers. In thismodel, we assume that the fluid consists of two distinct phases, oil and water. It is assumedthat the chemicals forming these two phases do not interact or move from one phase to theother. Since the fluid is incompressible and the chemical composition of the phases is fixed,the phase densities o and w are constants. Since the chemical composition of each phaseremains constant, the viscosities w and o are constant.

    As in the miscible displacement model (described in section 1.2.3), the porosity (x) isdimensionless, and the permeability K(x) is a symmetric nonnegative matrix with units ofarea. Neither the permeability nor the porosity need be continuous functions.

    The saturations of the phases so and sw are the ratios of the phase volumes to thefluid volume. By definition,

    sw + so = 1 .

    Typically, water is the wetting phase, meaning that it prefers to move along the surfaceof the rock pores. Oil is the non-wetting phase, and prefers to sit as disconnected dropletsin the center of cell pores, or move as ganglia when the droplets can connect. Thus thepresence of both oil and water reduces the flow of the other. This effect is often modeled bya relative permeability, which is a dimensionless modification to the total permeabilityK. Typically, relative permeability of a phase is chosen to be an empirical function ofthat phase saturation. Thus the relative permeability of oil is ro(so), and the relativepermeability of water is rw(sw). We must have

    ro(0) = 0 = rw(0) ,

    because neither phase can flow if it occupies no volume in the fluid. We must also have

    ro(1) 1 and rw(1) 1 ,

    because neither phase can flow more easily than the total permeability permits. Finally, wemust have

    ro(so) 0 so [0, 1] and rw(sw) 0 sw [0, 1] ,because an increase in relative volume of a phase makes it easier for that phase to flow.

    The velocities of the phases are typically modeled by Darcys law. In the miscibledisplacement model, described in section 1.2.3, Darcys law for a single phase was written

  • 10 CHAPTER 1. INTRODUCTION TO PARTIAL DIFFERENTIAL EQUATIONS

    in the form (1.2-2). For two-phase flow, Darcys law is usually modified to take the forms

    vo = K [xpo + go] roo

    ,

    vw = K [xpw + gw] rww

    .

    Note that for two-phase flow the pressures in the phases are not necessarily the same.Typically, the oil-phase pressure po is related to the water-phase pressure pw by

    po = pw + Pc(sw) ,

    where Pc(sw) is the capillary pressure between the phases. Capillary pressure arises fromthe interfacial tension between the phases and the narrow flow paths available to the fluids.Typically, capillary pressure is a strictly decreasing function of water saturation, and a verylarge pressure is required to drive the water saturation to zero. See Figure 1.2-1 for a typicalcapillary pressure curve.

    It will simplify notation if we define the phase mobilities

    o(so) ro(so)o

    , w(sw) rw(sw)w

    .

    Then the two-phase modification of Darcys law can be written

    vo = K [xpo + go]o ,vw = K [xpw + gw]w .

    Finally, we have equations representing the conservation of mass for oil and water. It iseasy to see that the mass of oil per bulk (rock) volume is oso, and the mass of water perbulk volume is wsw. The volumetric flux of oil is ovo, and the flux of water is wvw.Thus conservation of oil and water can be written

    oso

    t+ x (ovo) = 0 ,

    wsw

    t+ x (wvw) = 0 .

    This completes the description of the Buckley-Leverett model.Next, we need to manipulate these equations into a conservation law in one dimension.

    We can divide the mass conservation equations by the constant phase densities to get

    so

    t+vox

    = 0 ,

    sw

    t+vwx

    = 0 .

  • 1.2. PHYSICAL EXAMPLES OF DIFFUSION 11

    Pc

    sw

    Figure 1.2-1: Capillary Pressure Curve

  • 12 CHAPTER 1. INTRODUCTION TO PARTIAL DIFFERENTIAL EQUATIONS

    Next, we can add these two equations to get

    vo + vwx

    = 0 .

    This is an expression of the incompressibility of the flow: the total fluid velocity has zerodivergence. Given the total fluid velocity, the two mass conservation equations becomeredundant. It will suffice to work with conservation of oil.

    We can use the two-phase flow modification of Darcys law to represent the total fluidvelocity as a function of the water phase pressure and the oil saturation:

    vT vo + vw = K[(pw + Pc)

    xo pw

    xw + g(oo + ww)

    ].

    Since the total fluid velocity is divergence-free, in one dimension it is a constant in space.Thus this equation can be viewed as providing a relationship between the gradient of thewater-phase pressure and the oil saturation:

    pwx

    =vT /K g(oo + ww) + oPc/x

    o + w.

    This equation allows us to eliminate the pressure gradient from the expression for the Darcyvelocity for oil

    vo =[vT +Kgw(o w)KPc

    xw

    ]o

    o + w.

    This means that conservation of oil can be written

    so

    t+

    x

    {[vT +Kgw(o w)] o

    o + w

    }=

    x

    (Kowo + w

    Pcx

    ). (1.2-6)

    This has the form of a conservation law. The capillary pressure term introduces a physicaldiffusion; this diffusion term is nonlinear. In most oil recovery problems, the capillarypressure gradient is small compared to the fluid pressure gradient.

    Oil is less dense than water and more viscous. A porosity = 0.25 is typical. Problemlengths might be 100 meters, with a total fluid velocity vT = 30cm meters / day. In testproblems, the permeability K can be defined in terms of the gravity number

    Kg(o w)/wvT

    .

    Some typical values for the densities and viscosities are contained in Table 1.2-1The Buckley-Leverett flux function is neither convex nor concave. With zero total fluid

    velocity, the flux function formed solely by the action of gravity is shaped like a script

  • 1.2. PHYSICAL EXAMPLES OF DIFFUSION 13

    (a) vT = 1, g = 0 (b) vT = 0, g = 10

    (c) vT = 1, g = 10

    Figure 1.2-2: Buckley-Leverett Flux Function: f(s) = (vT+g(1s)2)s2/(s2+(1s)2)o/wwith o/w = 1

  • 14 CHAPTER 1. INTRODUCTION TO PARTIAL DIFFERENTIAL EQUATIONS

    fluid density (g/cc) viscosity (gm/sec/cm)water 0.998 0.0114diesel fuel 0.729 0.0062kerosene 0.839 0.0230prudhoe bay crude 0.905 0.6840

    Table 1.2-1: Density and Viscosity of Fluids

    V. This model is especially interesting when both the total fluid velocity and gravity arenonzero. Figure 1.2-2 shows some examples of the Buckley-Leverett flux function.

    Solutions of the Buckley-Leverett equations typically exhibit sharp travelling wave frontsin oil saturation, followed by smooth variation. The sharpness of the oil front depends onthe capillary pressure, and can be quite impressive in actual oil recovery.

    Exercises 1.2.41. Show that for fixed total fluid velocity vT , equation (1.2-6) is parabolic, and hyperbolic if Pc = 0.

    Note that in this case, the capillary pressure contributes a nonlinear second-order diffu-sion to the equation for conservation of oil. Some common models for mobility and capillarypressure are due to Corey:

    o = ommax{0, so sr,o}ow = wmmax{0, 1 so sr,w}wPc = cpmax{0, so sr,o}

    Here sr,o is a known constant, representing the residual saturation of oil that is trapped inthe pores by the wetting phase (water). Also sr,w is a constant, representing the irreduciblesaturation of water that cannot be driven out of the pores by oil under realizable pressures.The constants om and wm are the maximum mobilities of oil and water, respectively. Theexponents o and w are positive constants. The exponent is also constant.

    1.2.5 Thin Films

    A model for the motion of thin liquid films on a solid surface with fluid-solid interfacedriven by surface tension is

    h

    t+ x [f(h)xx xh] = 0 x t > 0 .

    Here h represents the height of the thin film and f is a factor multiplying the surface tension.In all of the models,

    f(h) ch as h 0 .

  • 1.2. PHYSICAL EXAMPLES OF DIFFUSION 15

    As a result, the thin film model is a degenerate fourth-order diffusion equation. Solutionsof the thin film equation are smooth wherever h > 0, but can develop discontinuities inthe derivatives of h as h 0. The exponent depends on the boundary conditions at thefluid-solid interface. No-slip conditions imply that = 3, while slip conditions imply that < 3. This problem is computationally difficult because the diffusion is both nonlinearand fourth-order.

    1.2.6 Incompressible Fluid Flow

    The Navier-Stokes equation for incompressible flow are [24]

    vt

    + (v x)v = 1xp+ (x x)v (1.2-7a)

    x v = 0 . (1.2-7b)Here is the density of the fluid, and is assumed to be constant. Also is the coefficientof kinematic viscosity, which is the fluid viscosity divided by the density.

    It is common to rewrite these equations in dimensionless form Let L be a problem lengthand s a problem speed; for flow past a sphere, L could be the diameter of the sphere and scould be the magnitude of the velocity at infinity. Let the dimensionless position and timebe

    x = x/L , t = ts/L .

    We also define the dimensionless velocity and pressure to be

    v = v/s , p = p/(s2) .

    Finally, we define the Reynolds number by

    R = Ls/ . (1.2-8)

    Then the Navier-Stokes equations can be written in the dimensionless form

    vt

    + (v x)v = xp+ 1R(x x)v

    x v = 0 .Exercises 1.2.61. For small Reynolds number R, it is acceptable to ignore the inertial term (v x)v relative to the

    viscous term 1R(x x) in the dimensionless Navier-Stokes equations. Show that the result Stokes

    equations

    v

    t= xp+ 1

    R(x x) (1.2-9a)

    x v = 0 (1.2-9b)are parabolic.

  • 16 CHAPTER 1. INTRODUCTION TO PARTIAL DIFFERENTIAL EQUATIONS

    1.2.7 Summary of Physical Examples

    Most physical problems involve some diffusion. However, the diffusion is not alwayslinear. Usually, the diffusion drives the solution of a system to a steady state. In some cases,diffusion can lead to travelling waves, such as in reaction-diffusion systems or in problemsinvolving sub-diffusion (where the diffusive coefficient tends to zero for some parameters).

  • Chapter 2

    Parabolic Equations

    In this chapter we will study finite difference methods for the numerical solution ofparabolic partial differential equations. These methods are simple to describe for problemson rectangular domains, but are difficult to extend to general domains or to high-order.We will see that explicit time integration of these problems will lead to severe restrictionson the timestep for numerical stability, but implicit treatment of will require the solutionof large sparse systems of equations. This discussion will motivate later development ofiterative methods for solving linear systems of equations in the next chapter. In chapter 6,we will discuss more robust discretizations based on finite element methods.

    2.1 Theory of Linear Parabolic Equations

    In order to begin our discussion of diffusion problems, we wil consider the simplestdiffusion equation, namely the heat equation ut = x xu.

    2.1.1 Fourier Transform Methods

    The analytical solution of the heat equation is well-known; for additional information,see [42, 66, 82, 90].

    17

  • 18 CHAPTER 2. PARABOLIC EQUATIONS

    Lemma 2.1-1: If u0 L2(Rn), then the solution of the initial-value problem for the heatequation,

    u

    t= x xu x Rn t > 0

    u(x, 0) = u0(x) x Rn ,

    is

    u(x, t) =Rn

    Gn(x s; t)u0(s) ds ,

    where the heat kernel is

    Gn(x, t) 1(4pit)n/2 ex2/(4t) .

    Proof: We will restrict our discussion to one dimension. For simplicity, wewill assume that the initial data u0 has compact support (meaning that it iszero outside some bounded interval). The Fourier transform of the initial datais

    u0() =12pi

    exu0(x) dx ,

    and the Fourier transform of the solution of the heat equation is

    u(, t) =12pi

    exu(x, t) dx .

    When we apply the Fourier transform to the heat equation, we obtain

    u

    t= 2u (,) t > 0 ,

    and

    u(, 0) = u0() (,) .

    This gives us a continuum of initial value problems for u, each an ordinarydifferential equation in time for fixed frequency . The solution is

    u(, t) = e2tu0() .

  • 2.1. THEORY OF LINEAR PARABOLIC EQUATIONS 19

    This equation shows that all nonzero Fourier modes decay, and modes associatedwith large frequencies decay faster than modes associated with small frequencies.

    In order to solve this equation for u, we apply the inverse Fourier transform:

    u(x, t) =

    exe2tu0() d =

    12pi

    ex2t

    esu0(s) ds d .

    Next, we can interchange the order of integration to obtain

    u(x, t) =12pi

    u0(s)

    e(xs)2t d ds .

    Completing the square gives us

    u(x, t) =12pi

    e(xs)2/(4t)u0(s)

    e(t(xs)/(2t))2 d ds .

    It is also well-known from complex analysis that the integral of an analyticfunction over a closed curve is zero; this implies that

    e(

    t(xs)/(2t))2 d =

    e2t d .

    Finally, we can change variables to obtain

    e2t d =

    1t

    e2d =

    1t

    e2122 d1 d2

    =1t

    2pi0

    0

    er2r dr d =1t

    0

    er22r dr =pit.

    Thus our formula for the solution of the heat equation on an unbounded intervalis

    u(x, t) =14pit

    e(xs)2/(4t)u0(s) ds

    G1(x s; t)u0(s) ds = (G1(; t) u0)(x) .

    2

    Since the heat kernelG1(x, t) 1

    4pitex

    2/(4t)

    is smooth, this formula shows that u(x, t) is smooth for t > 0, no matter how rough theinitial data u0 might be. Furthermore, as t for fixed x, we must have that u(x, t) 0.Note that if u0 is an odd function, then so is u(x, t); similarly, if u0 is even, so is u.

  • 20 CHAPTER 2. PARABOLIC EQUATIONS

    2.1.2 Reflection and Superposition

    The solution of the heat equation on some semi-bounded domains can be obtained byreflection principles [82]. We will illustrate some of these ideas.

    Lemma 2.1-2: The solution of the heat equation on the half-line with homogeneousDirichlet data,

    u

    t=2u

    x2,x > 0 t > 0

    u(0, t) = 0 t > 0 , u(x, 0) = u0(x) x > 0 ,

    is the same as the solution of the heat equation on the line with odd extension of the initialdata:

    u

    t=2u

    x2,x (,) t > 0

    u(x, 0) ={

    u0(x) x > 0u0(x) x < 0 .

    Lemma 2.1-3: The solution of the heat equation on the half-line with homogeneousNeumann data,

    u

    t=2u

    x2,x > 0 t > 0

    u

    x(0, t) = 0 t > 0 , u(x, 0) = u0(x) x > 0 ,

    is the solution of the heat equation on the line with even extension of the initial data:

    u

    t=2u

    x2,x (,) t > 0

    u(x, 0) ={

    u0(x) x > 0u0(x) x < 0 .

  • 2.1. THEORY OF LINEAR PARABOLIC EQUATIONS 21

    Lemma 2.1-4: The solution of the inhomogeneous heat equation on the unbounded line,

    u

    t

    2u

    x2= f(x, t) ,x (,) t > 0 .

    u(x, 0) = u0(x) ,

    is

    u(x, t) = (G1(; t) u0)(x) + t0

    G1(x y; t s)f(y, s) dy ds .

    Proof: This solution is a superposition of the solution of the homogeneousheat equation with inhomogeneous initial data u0, and the solution of the inho-mogeneous heat equation with homogeneous initial data. 2

    Lemma 2.1-5: If u is the solution of the heat equation on the half-line with inhomoge-neous Dirichlet data,

    u

    t

    2u

    x2= f(x, t) ,x > 0 t > 0 .

    u(0, t) = 0(t) t > 0 , u(x, 0) = u0(x) x > 0 ,

    then u(x, t) 0(t) solves the inhomogeneous heat equation with source f(x, t) 0(t),initial data u0(x) (0) and homogeneous Dirichlet data at x = 0.

    Lemma 2.1-6: If u is the solution of the heat equation on the half-line with inhomoge-neous Neumann data,

    u

    t

    2u

    x2= f(x, t) ,x > 0 t > 0 .

    u

    x(0, t) = 0(t) t > 0 , u(x, 0) = u0(x) x > 0 ,

    then u(x, t) x0(t) is the solution of the heat equation on the line with source f(x, t)x0(t), initial data u0(x) x0(0) and homogeneous Neumann data.

    2.1.3 Maximum Principle

    It is easy to show that the solution of the heat equation on an unbounded domain

    u

    t=2u

    x2, x (,)

  • 22 CHAPTER 2. PARABOLIC EQUATIONS

    achieves its maximum at t = 0. At a local maximum, the gradient of u would satisfy[utux

    ]= 0.

    Furthermore, the matrix of second derivatives would be negative definite; this would implythat

    2ux2

    < 0. Since ut = 0 and2ux2

    < 0 at an interior maximum, the heat equation couldnot be satisfied there.

    A stronger form of the maximum principle is also known on bounded domains [41, 42]:

    Theorem (Maximum Principle) 2.1-7: If u(x, t) satisfies the homogeneous heatequation for 0 x 1 and 0 t T , then the maximum of u occurs either at t = 0 orat x = 0 or at x = 1.

    By replacing u with u, we see that the minimum of the solution of the heat equation mustalso occur in the initial or boundary data.

    The maximum principle can also be used to prove the uniqueness of the solution of theheat equation. If two solutions of the heat equation have the same initial and boundarydata, then their difference solves the heat equation with zero initial and boundary data. Themaximum principle shows that the difference of the two solutions must be zero everywhere.

    2.1.4 Bounded Domains and Separable Solutions

    It is useful to construct analytical solutions to the heat equation on intervals, in orderto provide test problems for numerical computations. Consider the problem

    u

    t=2u

    x2x (0, 1) t > 0

    u(0, t) = 0 = u(1, t) t > 0 ,u(x, 0) = u0(x)x (0, 1) .

    Suppose that this problem with homogeneous initial data has separable solutions of theform

    u(x, t) = T (t)X(x) .

    If we substitute this expression into the heat equation, we obtain

    T

    T=X

    X.

    Since the left side of this equation is a function of t and the right side is a function of x,both sides of this equation are constant. The homogeneous boundary conditions imply that

    X(x) = sin(kpix)

  • 2.1. THEORY OF LINEAR PARABOLIC EQUATIONS 23

    for some integer k. It follows that

    u(x, t) = ek2pi2t sin(kpix)

    is a solution of the homogeneous heat equation on the bounded interval.General solutions to heat equations with inhomogeneous initial data are linear combi-

    nations of these separable solutions:

    u(x, t) =k=1

    kek2pi2t sin(kpix) .

    In order to determine the coefficients k, we note that the initial data must satisfy

    u0(x) =k=1

    k sin(kpix) .

    Since the sine functions are orthogonal, 10u0(x) sin(kpix) dx = k

    10sin2(kpix) dx =

    12k .

    For the purpose of developing test problems, however, it is more common to define theinitial data u0 by selecting the values of the k. Typically, all but one of the k are chosento be zero in simple test problems.

    Similarly, it is easy to find analytical solutions to the heat equation with zero Neumannboundary data, or with periodic boundary data.

    Exercises 2.11. Construct the general solution to the heat equation on (0, 1) (0,) with zero heat flow at the

    boundaries:u

    x(0, t) = 0 =

    u

    x(1, t) t > 0 .

    2. Construct the general solution to the heat equation on (0, 1) (0,) with zero Neumann data atx = 0 and zero Dirichlet data at x = 1:

    u

    x(0, t) = 0 t > 0 ,

    u(1, t) = 0 t > 0 .

    3. Construct the general solution to the heat equation on (0, 1)(0,) with period boundary conditions

    u(0, t) = u(1, t) t > 0u

    x(0, t) =

    u

    x(1, t) t > 0 .

  • 24 CHAPTER 2. PARABOLIC EQUATIONS

    2.2 Finite Difference Methods in One Dimension

    Numerical solutions of parabolic partial differential equations commonly involve dis-cretization in space and time. However, it will be advantageous to consider these discretiza-tions separately.

    2.2.1 Continuous-In-Time Methods

    Suppose that we want to solve

    u

    tD(x)

    2u

    x2= f(x, t) x (0, 1) t > 0 (2.2-1a)

    u(0, t) = 0(t) , D(1)u

    x(1, t) = 1(t) t > 0 , (2.2-1b)

    u(x, 0) = w0(x) x (0, 1) . (2.2-1c)

    We will select a finite difference mesh

    0 = x0 < x1 < . . . < xJ < 1

    as shown in figure 2.2-1. We will also define the cell widths by

    4xj+1/2 = xj+1 xj for 0 j < J ,4xJ+1/2 = 2(1 xJ) .

    and the cell centers byxj+1/2 = xj + 4xj+1/2/2 .

    Note that xJ+1/2 = 1.For each t, we will approximate the solution of the heat equation by

    uj(t) u(xj , t) 0 j J . (2.2-2)

    Also for each t, we will approximate the spatial derivative by second-order centered finitedifferences to get the system of ordinary differential equations

    ujt

    D(xj+1/2)

    uj+1(t)uj(t)4xj+1/2 D(xj1/2)

    uj(t)uj1(t)4xj1/2

    (4xj+1/2 + 4xj1/2)/2= f(xj , t) 0 < j J t > 0

    uj(0) = w0(j4x) 0 < j < J

    In order to satisfy the boundary data at the left side, we will take

    u0(t) = 0(t) .

  • 2.2. FINITE DIFFERENCE METHODS IN ONE DIMENSION 25

    Figure 2.2-1: Spatial discretization

    In order to satisfy the boundary data at the right side, we will require

    uJt

    1(t)D(xJ1/2)uJ (t)uJ1(t)4xJ1/2

    (4xJ+1/2 + 4xJ1/2)/2= f(xJ , t) .

    We can rewrite these ordinary differential equations in the form

    Mdudt

    = Ku+ f ,

    where the vector of mesh functions is

    u

    u1u2...

    uJ1uJ

    ,

  • 26 CHAPTER 2. PARABOLIC EQUATIONS

    and the vector of inhomogeneities is

    f

    f(x1, t) + 1/20(t)

    f(x2, t)...

    f(xJ1, t)f(xJ , t) +D(xJ+1/2)1(t)

    .

    Here we are using the notation

    j+1/2 =2D(xj+1/2)4xj+1/2

    , 0 j < J .

    The coefficient matrix multiplying the time derivatives is

    M

    4x1/2 + 4x3/2

    4x3/2 + 4x5/2. . .

    4xJ3/2 + 4xj1/24xJ1/2 + 4xJ+1/2

    ,

    and the coefficient matrix performing the spatial differences is

    K

    1/2 + 3/2 3/23/2 3/2 + 5/2 . . .

    . . . . . . . . .. . . J3/2 + j1/2 J1/2

    J1/2 J1/2

    .

    Note that K is diagonal and M is tridiagonal; both are symmetric and positive definite.We can rewrite the system of ordinary differential equations for the numerical solution

    in the formdM1/2udt

    = [M1/2KM1/2

    ]M1/2u+M1/2f .

    Note that M1/2KM1/2 is symmetric positive-definite. The analytical solution of thisordinary differential equation is

    M1/2u(t) = eM1/2KM1/2tM1/2u(0) +

    t0eM

    1/2KM1/2(ts)M1/2f(s) ds .

    Our purpose in this expression is not to provide a useful computational form; rather, wewould like to see how the numerical solution depends on the parameters in the problem.

  • 2.2. FINITE DIFFERENCE METHODS IN ONE DIMENSION 27

    The finite size ofM andK gives the continuous-in-time equations a finite set of decay rates,corresponding to the eigenvalues ofM1/2KM1/2. It is reasonable to expect that smallestof these eigenvalues to approximate the slowest decay rates of the heat equation, but thelargest of these eigenvalues may not be accurate.

    Although non-uniform meshes can be useful computationally, they can complicate thediscussion. On a uniform mesh with constant diffusion coefficient D, we can solve for thesolution derivative to get

    d

    dt

    u1u2u3...

    uJ1uJ

    = D

    4x2

    2 1 0 . . . 0 01 2 1 0 00 1 2 . . . 0 0...

    . . . . . . . . .

    0 0 0. . . 2 1

    0 0 0 . . . 1 1

    u1u2u3...

    uJ1uJ

    +

    f(x1, t) +D0(t)4x2

    f(x2, t)f(x3, t)

    ...f(xJ1, t)

    f(xJ , t) +1(t)4x

    (2.2-3)

    This can be rewritten in the matrix-vector form

    dudt

    = (A D4x2

    )u+ f ,

    where A is symmetric, positive definite and independent of the cell width or diffusionconstant. The analytical solution of this ordinary differential equation is

    u(t) = eAtD/4x2u(0) +

    t0eA(st)D/4x

    2f(s) ds .

    Let us determine the eigenvalues of A.

    Lemma 2.2-1: The J J matrix

    A =

    2 1 0 . . . 0 01 2 1 0 00 1 2 . . . 0 0...

    . . . . . . . . .

    0 0 0. . . 2 1

    0 0 0 . . . 1 1

    has eigenvalues

    k = 4 sin2[k + 1/2J + 1/2

    pi

    2

    ], 0 k < J

  • 28 CHAPTER 2. PARABOLIC EQUATIONS

    Proof: Note that the Gerschgorin circle theorem implies that the eigenvaluesof of A satisfy 0 4. Also note that the eigenvector equation

    2 1 0 . . . 0 01 2 1 0 00 1 2 . . . 0 0...

    . . . . . . . . .

    0 0 0. . . 2 1

    0 0 0 . . . 1 1

    u1u2u3...

    uJ1uJ

    =

    u1u2u3...

    uJ1uJ

    implies that

    u2 = u1(2 )[uj+1uj

    ]=[2 11 0

    ] [ujuj1

    ], 2 j < J ,

    uJ1 = uJ(1 ) .

    In order to solve the linear recurrence, we note that the eigenvector equation

    [2 11 0

    ] [1y

    ]=[1y

    ]

    implies that the eigenvalue solves a quadratic equation, with the product ofthe eigenvalues equal to the determinant of this matrix, i.e. one. By solvingthis quadratic equation, we find that the eigenvalues have the form

    =2 (2 )2 4

    2=

    2 (4 )2

    e

    where

    2 = 2Re() = 2 cos .

    An easy calculation for the eigenvector shows that

    [2 11 0

    ] [1 1e e

    ]=[

    1 1e e

    ] [e 00 e

    ].

  • 2.2. FINITE DIFFERENCE METHODS IN ONE DIMENSION 29

    Thus the solution of the linear recurrence is[ujuj1

    ]=[2 11 0

    ]j2 [u2u1

    ]=[

    1 1e e

    ] [e 00 e

    ]j2 [ 1 1e e

    ]1 [u2u1

    ]=[

    1 1e e

    ] [e(j2) 0

    0 e(j2)

    ] [e 1e 1

    ] [u2u1

    ]1

    e e

    =[

    1 1e e

    ] [e(j2) 0

    0 e(j2)

    ] [e 1e 1

    ] [e + e

    1

    ]u1

    2 sin

    =[

    1 1e e

    ] [e(j2) 0

    0 e(j2)

    ] [e2

    e2]

    u12 sin

    =[

    1 1e e

    ] [ej

    ej]

    u12 sin

    =[

    2 sin j2 sin(j 1)

    ]u1

    2 sin

    =[

    sin jsin(j 1)

    ]u1sin

    In other words, the eigenvectors have the form

    uj = sin j ,

    where = u1/ sin , and the permissible values of are to be determined.

    The final equation uJ = uJ1 + uJ in the system of equations for an eigen-vector of A implies that

    2[1 cos ] sinJ = sin(J ) + sin J= sinJ cos + cos J sin + sinJ= [1 cos ] sinJ + cos J sin .

    This implies that

    0 = sinJ sinJ cos cos J sin = sinJ sin(J + 1) = 2 sin

    2cos[J +

    12] .

    We should not choose so that sin 12 = 0, because that will imply that uj = 0for all j. In order to obtain nontrivial eigenvectors and eigenvalues, we choose so that cos(J + 1/2) = 0:

    k =k + 1/2J + 1/2

    pi , 0 k < J .

  • 30 CHAPTER 2. PARABOLIC EQUATIONS

    Similar values of outside this range for j lead to repetitions of the eigenvectors.This gives us J distinct eigenvalues, of the form

    k = 2[1 cos k] = 4 sin2 k2 = 4 sin2

    [k + 1/2J + 1/2

    pi

    2

    ].

    The smallest eigenvalue is

    0 = 4 sin2pi

    2J + 1 4pi

    2

    (2J + 1)2,

    and the largest eigenvalue is

    J = 4 sin2[J 1/2J + 1/2

    pi

    2

    ] 4 .

    2

    Note that spatial discretization has produced a large system of coupled ordinary dif-ferential equations. The solution of this system involves exponential decay of the portionof the solution due to the initial data, since the matrix A is positive definite. For finediscretization (i.e., J large) this system is stiff, since the ratio of the largest to smallesteigenvalues of A is large, with value approximately equal to [4/(pi4x)]2.

    However, numerical methods also involve evaluation of the approximate solution atdiscrete times. This will be performed by numerical methods for time integration.

    Exercises 2.2.11. Find the eigenvalues and eigenvectors of266666666664

    1 1 0 . . . 0 01 2 1 0 00 1 2 . . . 0 0...

    . . .. . .

    . . .

    0 0 0. . . 2 1

    0 0 0 . . . 1 1

    377777777775This matrix corresponds to the finite difference discretization of the heat equation with Neumann(flux) boundary conditions at both boundaries.

    2. Find the eigenvalues and eigenvectors of266666666664

    2 1 0 . . . 0 01 2 1 0 00 1 2 . . . 0 0...

    . . .. . .

    . . .

    0 0 0. . . 2 1

    0 0 0 . . . 1 2

    377777777775This matrix corresponds to the finite difference discretization of the heat equation with Dirichlet(specified value) boundary conditions at both boundaries.

  • 2.2. FINITE DIFFERENCE METHODS IN ONE DIMENSION 31

    2.2.2 Explicit Centered Differences

    The simplest numerical discretization of the one-dimensional heat equation (2.2-1) isthe explicit centered difference scheme

    4xj1/2 + 4xj+1/22

    un+1j unj4tn+1/2

    [D(xj+1/2)

    unj+1 unj4xj+1/2

    D(xj1/2)uj unj14xj1/2

    ]=4xj1/2 + 4xj+1/2

    2f(xj , tn) 1 j < J n 0 .

    This scheme uses a second-order centered difference in space, and the first-order forwardEuler scheme in time. With boundary conditions given by (2.2-1b), we take the numericalsolution at the left boundary to be

    un0 = 0(tn)

    and write the scheme at the right boundary in the form

    4xJ1/2 + 4xJ+1/22

    un+1J unJ4tn+1/2

    [1(tn)D(xJ1/2)

    unJ unJ14xJ1/2

    ]=4xJ1/2 + 4xJ+1/2

    2f(xJ , tn) .

    If we solve the difference equations for un+1j , we get

    un+1j =2D(xj1/2)4tn+1/2

    (4xj1/2 + 4xj+1/2)4xj1/2unj1 +

    [1 2D(xj1/2)4t

    n+1/2

    (4xj1/2 + 4xj+1/2)4xj1/2 2D(xj+1/2)4t

    n+1/2

    (4xj1/2 + 4xj+1/2)4xj+1/2

    ]unj +

    2D(xj+1/2)4tn+1/2

    (4xj1/2 + 4xj+1/2)4xj+1/2unj+1 + f(xj , t

    n)4tn+1/2 .

    In the absence of internal heat sources or sinks (i.e. f = 0), the new numerical solution isa weighted average of the old solution values provided that

    24tn+1/2

    4xj1/2 + 4xj+1/2

    [D(xj+1/2)4xj+1/2

    +D(xj1/2)4xj1/2

    ] 1 .

    Solving this inequality for 4tn+1/2 gives us

    4tn+1/2 4xj1/2 + 4xj+1/22

    1D(xj+1/2)

    4xj+1/2 +D(xj1/2)4xj1/2

    .

    If the timestep is chosen in this way, then the numerical scheme satisfies a maximumprinciple for problems with no internal heat sources or sinks. To see this, suppose that the

  • 32 CHAPTER 2. PARABOLIC EQUATIONS

    maximum value of un+1j is un+1i . Then for all j,

    maxjun+1j = u

    n+1i =

    2D(xi1/2)4tn+1/2

    (4xi1/2 + 4xi+1/2)4xi1/2uni1 +

    [1 2D(xi1/2)4t

    n+1/2

    (4xi1/2 + 4xi+1/2)4xi1/2 2D(xi+1/2)4t

    n+1/2

    (4xi1/2 + 4xi+1/2)4xi+1/2

    ]uni +

    2D(xi+1/2)4tn+1/2

    (4xi1/2 + 4xi+1/2)4xi+1/2uni+1

    2D(xi1/2)4tn+1/2

    (4xi1/2 + 4xi+1/2)4xi1/2maxjunj +

    [1 2D(xi1/2)4t

    n+1/2

    (4xi1/2 + 4xi+1/2)4xi1/2 2D(xi+1/2)4t

    n+1/2

    (4xi1/2 + 4xi+1/2)4xi+1/2

    ]maxjunj +

    2D(xi+1/2)4tn+1/2

    (4xi1/2 + 4xi+1/2)4xi+1/2maxjunj+1

    = maxjunj .

    Similarly, we can establish a minimum principle; these prevent the numerical method fromestablishing new extrema, and imply numerical stability.

    Away from the boundaries on a uniform mesh with constant diffusion coefficient, theexplicit centered difference scheme can be rewritten in the form

    un+1j = unj+1 + (1 2)unj + unj1 + fnj 4t, 0 < j J n 0 (2.2-4)

    where the decay number is

    D4t4x2

    .

    For boundary value problem (2.2-1), we obtain a linear recurrenceun+11un+12...

    un+1J

    =1 2 1 2 . . .

    . . . . . . 1

    un1un2...unJ

    +

    fn1 4t+ 0(n4t)fn2 4t...

    fnJ4t+ 1(n4t)4t/4x

    which can be written in matrix-vector form

    un+1 = (IA)un + fn .It is not hard to see that the explicit centered difference scheme differs from the continuous-in-time method by approximating the matrix exponential by

    eA I A .Note that if f = 0 and 0 < < 12 , then equation (2.2-4) shows that the solution

    at the new time is a weighted average of the solution at the old time. As we saw inthe discussion above for non-uniform grids, this implies a discrete maximum principle,and therefore numerical stability. On a uniform grid, the timestep restriction also impliesmonotonicity. If unj+1 unj > 0 for all j, then

    un+1j+1 un+1j = (unj+2 unj+1) + (1 2)(unj+1 unj ) + (unj unj1) > 0 .

  • 2.2. FINITE DIFFERENCE METHODS IN ONE DIMENSION 33

    Monotonicity corresponds to choosing 4t small enough that IA4t is positive definite, sothat the approximation to the matrix exponential is positive definite.

    However, 0 < < 12 implies that we have chosen the timestep to be small:

    4t 4x2

    2D.

    This restriction typically requires an unacceptably large number of timeseps, unless the dif-fusion constant D is very small. On the other hand, any attempt to balance the spatial andtemporal truncation errors would choose 4t = O(4x2), since we have used a second-orderfinite difference approximation to the spatial derivative and a first-order finite differenceapproximation to the temporal derivative.

    2.2.3 Programs for Explicit Centered Differences

    Explicit centered differences are easy to program. Nevertheless, in order to assist thestudent with code organization, visualization and debugging, we have provided five exampleprograms. These programs will increase the complexity in the main program and makefile,but typically share subroutines that compute the solution of the heat equation. Whenwe begin to experiment with different integration schemes and differential equations fromwithin this text, we will use the the last of these programs.

    To prepare to obtain copies of these codes, perform the following steps:

    1. Type cd to return to your home directory.

    2. Type mkdir parabolic to make a directory to contain the program code in thischapter.

    3. Type cd parabolic to enter the new directory.

    4. Download Program 2.2-2: tarfile from the web page.

    5. Type tar -xvf tarfile to unbundle the codes in your new parabolic directory.

    6. Type rm tarfile to remove the code bundle in your parabolic directory. Theunbundled code will remain.

    First Explicit Centered Difference Program

    The first program is designed to be as simple as possible. It consists of the singlemain program Program 2.2-3: main.f, written in Fortran. This program is specificallydesigned to solve the heat equation with a given diffusion constant. It also uses a uniformmesh, specifies a fixed value for the solution at the left boundary and zero derivative for

  • 34 CHAPTER 2. PARABOLIC EQUATIONS

    the solution at the right boundary, and uses piecewise-constant initial data. The timeevolution of the solution is terminated by exceeding either a specified number of timestepsor a specified simulation time. The program prints the final results for use by a separateplotting program. Instructions for using the program can be found in the accompanyingProgram 2.2-4: README.

    Second Explicit Centered Difference Program

    The second program is designed to be more modular than the first program. Thisprogram consists of several pieces:

    Program 2.2-5: heatmain.f Fortran main program for solving the heat equationover some specified time or number of timesteps.

    Program 2.2-6: heat.f Fortran routines for initializing the solution and mesh, andintegrating the heat equation;

    Program 2.2-7: const.i Fortran common block for machine dependent parameters,and parameter statements for some common constants;

    Program 2.2-8: GNUmakefile Makefile to compile and load the Fortran files.It is strongly suggested that the student maintain this basic style of organization for thecode. The separation of initial and boundary conditions from the time integration will makethe experimentation with alternative numerical schemes easier. It will also make it easierfor us to apply the methods to a variety of differential equations, or to different initial valuesor boundary conditions.

    File heat.f contains six routines, initialize, explict centered, implicit centered,forward euler fem, implicit centered periodic and crank nicolson. Subroutine initializeinitializes the temperature and mesh for the heat equation. The other routines implementdifferent schemes for integrating the heat equation in time.

    To run a copy of this code, perform the following steps:

    1. Type cd to return to your home directory.

    2. Type cd parabolic/PROGRAM1 to enter the directory for this program.

    3. Type make to compile the program files and make the executable flinearad.

    4. Type heat > output; heat runs the program and > output redirects the resultsto the file output.

    5. Type xmgrace output to plot the computational results.

  • 2.2. FINITE DIFFERENCE METHODS IN ONE DIMENSION 35

    The final step will show a graph of the numerical solution plotted as a function of space, atthe final time in the simulation.

    There are several difficulties with this simple Fortran code. One is that whenever wewant to change the input parameters, such as the number of grid cells or timesteps, wehave to recompile the main program. Another problem is that the arrays have to be givena fixed size, because Fortran 77 does not perform dynamic memory allocation. We will fixthese problems with the next program.

    Third Explicit Centered Difference Program

    Our third program is more sophisticated, employing a mixture of C++and Fortran. Thisprogram consists of several pieces that we have already seen, namely heat.f and const.i.However, we have a different main program, a different make file and a new input file:

    Program 2.2-9: HeatMain.C C++main program; Program 2.2-10: GNUmakefile Makefile to compile and load the mixed-languageprogram;

    Program 2.2-11: input the input file for executing the program.The C++file, HeatMain.C, has several important features. Since C++is strongly typed, thisfile contains function prototypes for the Fortran routines; these can be found in the externC block. Next, this C++file also defines C++structures for the Fortran common block,namely machine common; this allow us to refer to the data in the Fortran common blocksfrom within the main program.

    Inside the main program itself, we provide values for the machine-dependent constantsin the Fortran common block machine. Afterward, we read the parameters from the inputfile.

    After this preliminary work, the main program is prepared for computation. It allocatesmemory for the computational arrays, and defines array bounds for the Fortran subroutinecalls. Next, the main program initializes the array entries to IEEE infinity; if the programuses an entry before it is given a proper value, then the resulting values will be obviouslywrong. This initialization is useful in debugging; think of it as defensive programming.

    Now that the problem parameters are known and the data arrays have been allocated,the main program calls initialize to set the initial values. At the end of the computation,the main program writes out the final results.

    To run a copy of this code, perform the following steps:

    1. Type cd to return to your home directory.

    2. Type cd parabolic/PROGRAM2 to enter the directory for this program.

  • 36 CHAPTER 2. PARABOLIC EQUATIONS

    3. Type make to compile the program files and make the executable linearad.

    4. Type heat input > output to run the program and redirect the results to the fileoutput.

    5. Type xmgrace output to plot the computational results.

    There are still difficulties with this program. Since we cannot see the numerical resultsduring execution, it is difficult to see the time evolution of the computation. Further, weare not fully able to perform other important aspects of defensive programming that wewill introduce in the next program.

    Fourth Explicit Centered Difference Program

    Our fourth program is even more sophisticated, employing a mixture of C++and Fortran,together with some references to external libraries. This program consists of several piecesthat we have already seen, namely heat.f and const.i. However, the main program, inputfile and make file are different:

    Program 2.2-12: HeatMain.C C++main program; Program 2.2-13: GNUmakefile Makefile to compile the mixed-language programand link with libraries;

    Program 2.2-14: input the input file for executing the program.The first change in HeatMain.C is that we construct a MemoryDebugger to watch for out-

    of-bounds writes and unfreed pointers. Later, we define InputParameters for everythingwe would like to read from our input file. Each InputParameter knows the location of thevariable to be assigned, a character string identifier and lower/upper bounds on permissiblevalues. After defining the InputParameters, we read the parameters from the input file.

    The biggest change to the main program is our use of interactive graphics to plot thesolution. To do this, we compute the upper and lower bounds on the mesh and the solu-tion. Then we construct an XYGraphTool that will plot our results. The arguments to theXYGraphTool constructor are the title to appear on the graphics window, the user coordi-nates for the window, a pointer to the colormap, and the desired size of the window as afraction of the screen size. Next, we set the colors for the background and foreground, anddraw the axes. Afterward, we draw plus signs at the cell centers for the numerical solution.During the loop over timesteps, we also plot the new results.

    The makefile is necessarily complicated, because we are linking with other libraries formemory debugging, graphics, and graphical user interfaces. At the beginning of makefile,we include macros.gnu, which contains machine-dependent macros to describe the compiler

  • 2.2. FINITE DIFFERENCE METHODS IN ONE DIMENSION 37

    names and options. Next, we set some internal macros for compiling and linking. Afterward,we make a list of routines needed by our program.

    The trickiest part of the makefile is how we provide different targets to construct codefor debugging or optimized performance. We can choose whether we will make debug oroptimized code by setting the OPT OPTIONS flag in GNUmakefile. The choice d will generatecode for debugging with no optimization, while the choice o will generate optimized code.During code development, you will want to work with debug code. Once your code hasbeen tested, you can create optimized code for greater execution speed.

    To run a copy of this code, perform the following steps:

    1. Type cd to return to your home directory.

    2. Type cd parabolic/PROGRAM3 to enter the directory for this program.

    3. Type make to compile the program files and make the executable 1d/linearad.

    4. Type 1d/linearad input to run the program.

    When the program is run, the user will see a movie of the simulation, showing the conservedquantity plotted as a function of space at each time in the movie.

    The directory 1d refers to code written in one dimension, for debugging. Optimizedcode is compiled and loaded in directory 1o. Figure 2.2-2 contains some example resultswith this program, at the final time in each simulation.

    In order to capture the graphics into a file for printing, you can create a shell script, suchas Program 2.2-15: eps4paper This command first copies the contents of a window toa .gif file, then converts that file to .pdf form.

    Fifth Explicit Centered Difference Program

    Our fifth and final version of our upwind finite difference program is designed to be runfrom within this book. For this purpose, it is necessary that the user be able to changeall input parameters interactively, from within a graphical user interface. This programconsists of several pieces that we have already seen, namely heat.f and const.i. However,the main program, input file and make file are different:

    Program 2.2-16: HeatMainGUI.C C++main program and C++auxiliary proce-dures;

    Program 2.2-17: GNUmakefile Makefile to compile the mixed-language programand link with libraries;

    Program 2.2-18: input the input file for executing the program.

  • 38 CHAPTER 2. PARABOLIC EQUATIONS

    In order to work with the graphical user interface, the main program basically performssome preliminary work before entering an event loop. The event loop calls various routinesin response to user interaction with the graphical user interface. One of these callbackroutines is runMain in HeatMainGUI.C; this routine contains most of the statements thatappeared in the main program of the previous example. The event loop allows the user toperform one simulation, adjust the input parameters, and then perform another simulation,all in the same run of the program. However, because of the separate threads used for theevents, such a program is more difficult to debug than the previous examples.

    To run a copy of this code, perform the following steps:

    1. Type cd to return to your home directory.

    2. Type cd parabolic to enter the directory for this program.

    3. Type make to compile the program files and make the executable 1d/guiheat.

    4. Type 1d/guiheat input to run the program.

    The directory 1d refers to code written in one dimension, for debugging. Optimized codeis compiled and loaded in directory 1o. You can also run the executable by clicking on thefollowing: Executable 2.2-19: guiheat The latter will use a graphical user interface forparameter input. Pull down on View and release the mouse on Main. Click on any ofthe arrows to see current values of either the Problem Parameters, Numerical MethodParameters or Graphics Parameters. After selecting your values, click on Start RunNow in the original graphical user interface. As with the executable 1d/guiheat, you willget a window displaying a movie of the temperature plotted as a function of space duringsimulation time.

    In figure 2.2-2 we show computational results with the explicit centered difference schemefor the boundary value problem (2.2-1) with homogeneous boundary data and piecewise-constant initial data

    u(x, 0) ={

    1, 1/3 < x < 2/30, otherwise

    (2.2-5)

    The computation uses a uniform grid of 100 cells, a diffusion constant of D = 1, and thetimestep chosen so that the decay number is = 0.51. Thus, this computation is numericallyunstable. The numerical oscillations grow until they eventually dominate the form of thesolution and exceed the ability of the computer to store floating-point numbers.

    2.2.4 Implicit Centered Differences

    Our next numerical discretization of the heat equation is the implicit centered dif-ference scheme

    4xj1/2 + 4xj+1/22

    un+1j unj4tn+1/2

    = D(xj+1/2)un+1j+1 un+1j4xj+1/2

    D(xj1/2un+1j un+1j14xj1/2

    +f(xj , tn+1) 1 j < J n 0 .

  • 2.2. FINITE DIFFERENCE METHODS IN ONE DIMENSION 39

    (a) step 10 (b) step 20

    (c) step 30 (d) step 40

    Figure 2.2-2: Explicit centered differences with = 0.51: onset of instability

  • 40 CHAPTER 2. PARABOLIC EQUATIONS

    With boundary conditions given by (2.2-1b), we take the numerical solution at the leftboundary to be

    un+10 = 0(tn+1)

    and write the scheme at the right boundary in the form

    4xJ1/2 + 4xJ+1/22

    un+1J unJ4tn+1/2

    =[1(tn+1)D(xJ1/2)

    un+1J un+1J14xJ1/2

    ]+

    4xJ1/2 + 4xJ+1/22

    f(xJ , tn+1) .

    This scheme uses a second-order centered difference in space, and the first-order backwardEuler scheme in time.

    The implicit centered scheme satisfies a maximum principle without any restriction onthe timestep. Suppose that un+1i = maxj u

    n+1j occurs in the interior of the grid, and that

    f = 0. Then the numerical scheme implies that

    maxjun+1j = u

    n+1i = u

    ni

    24tn+1/2

    4xi1/2 + 4xi+1/2

    [D(xi+1/2)4xi+1/2

    (un+1i un+1i ) +D(xi1/2)4xi1/2

    (un+1i un+1i1 )] uni max

    junj .

    We can establish a minimum principle in a similar fashion. The maximum principle impliesunconditional numerical stability. The maximum principle also implies that in each timestepthe linear system for the implicit centered difference scheme has a unique solution. This isseen by taking unj = 0 for all j and using the maximum principle to show that u

    n+1j = 0 for

    all j, so the only solution to the homogeneous linear system in the implicit centered schemeis identically zero.

    On a uniform grid with constant diffusion coefficient D, the implicit centered schemecan be rewritten in the form

    un+1j+1 + (1 + 2)un+1j un+1j1 = unj + fn+1j 4t 0 < j J n 0 .

    where D4t4x2 is the decay number. In matrix-vector form, this can be written

    (I+A)un+1 = un + fn+1 .

    Implicit centered differences correspond to approximating the matrix exponential by

    eA (I+A)1 .

    Note that since A is positive definite, this approximation to the matrix exponential ispositive definite for any positive decay number , and thus for any 4t > 0.

  • 2.2. FINITE DIFFERENCE METHODS IN ONE DIMENSION 41

    One advantage of the implicit centered difference scheme is that its numerical solutiontends to the steady state solution of the heat equation as 4t . This is known asL-stability in the numerical solution of ordinary differential equations.

    In figure 2.2-3 we show computational results with the implicit centered differencescheme for the boundary value problem (2.2-1) with homogeneous boundary data, andinitial data given by (2.2-5). The computation uses a uniform grid of 100 cells, a diffusionconstant of D = 1, and several choices of the timestep.

    2.2.5 Higher-Order Temporal Discretization

    In order to construct higher-order temporal discretizations for parabolic equations, wecan use our knowledge of numerical methods to solve initial-value problems for ordinarydifferential equations. We will restrict our examples to methods that produce second-ordertemporal discretization, since our centered difference is second-order in space.

    On way to achieve second-order accuracy in both space and time is to average theexplicit and implicit centered difference schemes:

    4xj+1/2 + 4xj1/22

    un+1j unj4t

    =D(xj+1/2)4xj+1/2

    [un+1j+1 un+1j4xj+1/2

    +unj+1 unj4xj+1/2

    ]D(xj1/2)

    4xj1/2

    [un+1j un+1j14xj1/2

    +unj unj14xj1/2

    ]+f(xj , tn+1) + f(xj , tn

    )2 .

    This corresponds to using centered differences in space, and the trapezoidal rule in time.On a uniform mesh for a problem with constant diffusion coefficient D, this can be writtenin matrix-vector form(

    I+A

    2

    )un+1 =

    (IA

    2

    )un +

    (fn + fn+1

    ) 12,

    where is the decay number.The Crank-Nicolson scheme approximates the matrix exponential by

    eA (I+A

    2

    )1 (IA

    2

    ).

    Note that as , this approximation tends to I rather than zero. If 4x2 is aneigenvalue of A and 4x2 = D4t is large, then the corresponding decay mode of thediscretized equation does not decay monotonically. This indicates that the timestep in theCrank-Nicolson scheme should be chosen with some care. For example, in order that theexponential approximation be positive-definite, we must choose 4t small so that IA/2is positive-definite. This leads to a small timestep, although twice as large as with explicitcentered differences. We say that the timestep is small, because notions of balancing thetemporal and spatial truncation errors would suggest that 4t = O(4x).

    In section 2.3.3, we will use energy estimates to show that the Crank-Nicolson schemeis unconditionally stable. Later, in section 2.4.4, we will use a Fourier analysis to see that

  • 42 CHAPTER 2. PARABOLIC EQUATIONS

    (a) = 0.1, 1000 steps (b) = 1., 100 steps

    (c) = 10., 10 steps (d) = 100., 1 step

    Figure 2.2-3: Unconditional stability with implicit centered differences, t = 0.01.

  • 2.2. FINITE DIFFERENCE METHODS IN ONE DIMENSION 43

    the Crank-Nicolson scheme is unconditionally diffusive. However, the lack of monotonicitycan produce annoying numerical oscillations when the initial data has significant high-frequency components and when the decay number satisfies max > 2, where max is thelargest eigenvalue of A.

    In figure 2.2-4 we show computational results with the Crank-Nicolson scheme for theboundary value problem (2.2-1) with homogeneous boundary data, and initial data givenby (2.2-5). The computation uses a uniform grid of 100 cells, a diffusion constant of D = 1,and the timestep chosen so that the decay number is = 10.0. Thus, this computation isnumerically stable. However, since the Crank-Nicolson scheme is not monotone, the high-frequency components of the initial data oscillate as they decay. The results are shown attime t = 0.001.

    In practice, the Crank-Nicolson scheme is often combined with a smoothing step, simi-lar to the smoothing used in the modified midpoint method for ordinary differential equa-tions [28]. Let unj represent the numerical values computed by the Crank-Nicolson schemewith smoothing. First, we compute the provisional new value un+1j by the Crank-Nicolsonscheme:

    un+1j unj4t

    =D

    2un+1j+1 2un+1j + un+1j1

    4x2+D

    2unj+1 2unj + unj1

    4x2.

    Afterward, we smooth the previous result by computing

    unj =14[un+1j + 2u

    nj + u

    n1j ] .

    Another way to avoid non-monotone behavior is to take small timesteps until the highfrequency components of the initial data have decayed, then increase the timestep until thetemporal errors match the spatial errors.

    Using well-known techniques for solving ordinary differential equations, we can constructother fully discrete methods for the heat equation from the continuous-in-time discretizationof the heat equation using second-order spatial discretization. Here are a few examples onuniform grids with constant diffusion coefficient.

    Example 2.2-20: The second-order Adams-Bashforth method gives us the scheme

    un+1j unj4t

    =3D24x2

    [unj+1 2unj + unj1]D

    24x2[un1j+1 2un1j + un1j1 ] .

    As we will see in section 2.4.4.4, stability requires that with this scheme we choose thetimestep even smaller than with explicit centered differences.

    Example 2.2-21: The second-order Adams-Moulton method gives us the scheme

    un+1j unj4t

    =D

    24x2[unj+1 2unj + unj1] +

    D

    24x2[un+1j+1 2un+1j + un+1j1 ] .

  • 44 CHAPTER 2. PARABOLIC EQUATIONS

    (a) t = 0.002 (b) t = 0.004

    (c) t = 0.006 (d) t = 0.008

    Figure 2.2-4: Crank-Nicolson with = 10: lack of monotonicity.

  • 2.2. FINITE DIFFERENCE METHODS IN ONE DIMENSION 45

    This is the Crank-Nicolson scheme.Example 2.2-22: The second-order backward differentiation formula gives us the scheme

    32u

    n+1j 2unj + 12un1j

    4t=

    D

    4x2[un+1j+1 2un+1j + un+1j1 ] .

    We will see in section 2.4.4.5 that this scheme is unconditionally stable.Example 2.2-23: The second-order DIRK (Diagonally Implicit Runge-Kutta) scheme

    for solving dydt = f takes the form

    k1 = f(tn + 4t , yn + 4tk1) ,k2 = f(tn + (1 )4t , yn + (1 2)4tk1 + 4tk2) ,

    yn+1 = yn +4t2(k1 + k2) .

    Here = 11/2. If we apply this DIRK to the heat equation, we get the schemek1,j = D

    unj+1 2unj + unj14x2

    + D4tk1,j+1 2k1,j + k1,j1

    4x2

    k2,j = Dunj+1 2unj + unj1

    4x2+D4t(1 2)k1,j+1 2k1,j + k1,j1

    4x2

    + D4tk2,j+1 2k2,j + k2,j1

    4x2

    un+1j = unj +

    4t2[k1,j + k2,j ] .

    Thus k1 and k2 are determined by solving systems of linear equations, each involving thesame coefficient matrix. By design, this Runge-Kutta scheme is second-order accurate, L-stable and A-stable; see example 2.4.4.6 below.

    Exercises 2.2.51. Consider the continuous-in-time scheme for the one-dimensional heat equation with Neumann data at

    both boundaries. Write the spatially-discretized system in the form of a system of ordinary differentialequations

    du

    dt= Au+ f

    and carefully describe the entries of u, A and f . Is A symmetric? Is A positive-definite?

    2. Program explicit centered differences, implicit centered differences and the Crank-Nicolson schemefor the heat equation

    u

    t

    2u

    x2= 0

    in one dimension with periodic boundary values. Consider initial data given by the lowest Fouriermode of the heat equation, or by the square wave

    u0(x) =

    1, 1/3 < x < 2/30, otherwise

  • 46 CHAPTER 2. PARABOLIC EQUATIONS

    Compare numerical results for these schemes with 10, 100 and 1000 cells at time t = 0.03, which isroughly the time at which the spatial maximum of the analytical solution has decayed to 50% of itsinitial value. Describe carefully how you chose 4t for each scheme.

    3. Program the second-order BDF and the DIRK scheme for the problem in exercise 2. Compare theaccuracy and efficiency of these schemes. Describe carefully how you chose 4t.

    2.3 Consistency, Stability and Convergence

    Numerical schemes are stable if they produce bounded perturbations in the numeri-cal solution as a result of perturbations in the data, such as initial conditions, boundaryconditions, or forcing function in the interior. Numerical schemes are consistent if theirdiscretization produces a small error in approximating the differential equation in eachtimestep. Numerical schemes are convergent if the numerical solution converges to the truesolution of the differential equation as the mesh and timestep are refined, in the absence ofcomputer rounding errors.

    First, let us describe what we mean by schemes. We assume that the numerical methodcan be written

    un+1 = Qn+1/2un

    where Qn+1/2 is some operator on the solution vector. Note that the solution vector maybe defined at an infinite number of points, for the purposes of this analysis. It will typicallybe convenient to use the shift operators

    (S+u)nj = unj+1 and (Su)

    nj = u

    nj1 ,

    to define Qn+1/2 in specific schemes.Example 2.3-1: The explicit centered scheme can be written

    un+1j = n+1/2j1/2 u

    nj1 +

    (1 n+1/2j1/2

    n+1/2j+1/2

    )unj +

    n+1/2j+1/2 u

    nj+1 (2.3-1)

    where n+1/2j+1/2 = D4tn+ 1

    2 /4x2j+1/2 is the decay number. In this case, we have

    Qn+1/2 = Sn+1/21/2 + I

    (1 n+1/21/2

    n+1/2+1/2

    )+ S+

    n+1/2+1/2 .

    Example 2.3-2: The implicit centered scheme can be written

    n+1/2j1/2 un+1j1 +(1 + n+1/2j1/2

    n+1/2j+1/2

    )un+1j n+1/2j+1/2 un+1j+1 = unj . (2.3-2)

    In this case, we have

    Qn+1/2 =[Sn+1/2j1/2 + I

    (1 + n+1/2j1/2

    n+1/2j+1/2

    ) S+n+1/2j+1/2

    ]1.

  • 2.3. CONSISTENCY, STABILITY AND CONVERGENCE 47

    2.3.1 Stability of Explicit and Implicit Centered Differences

    Next, let represent some norm on the solution vector. For example, we could use

    un supj|unj |

    orun

    j

    |unj |4xj .

    The induced norm on Qn+1/2 is defined by

    Qn+1/2 supun

    Qn+1/2unun .

    Lemma 2.3-3: Let be any norm on the solution vector such that

    Su u uS+u u u .

    Suppose that we have a uniform spatial grid, and that the decay numbers satisfy

    n+1/2 =D4tn+

    12

    4x2 1

    2n 0 .

    Then the solution operator Qn+1/2 for the explicit centered scheme (2.3-1) satisfies

    Qn+1/2 1 .

    Proof: Using the triangle inequality for norms, we compute

    Qn+1/2u = (Su)nn+1/2 + (1 2n+1/2)un + (S+u)nn+1/2 (Su)nn+1/2 + un(1 2n+1/2) + (S+u)nn+1/2 unn+1/2 + un(1 2n+1/2) + unn+1/2 = un .

    2

    Thus the explicit centered difference scheme is stable