Diffpack Books

Computational Partial Differential Equations
Numerical Methods and Diffpack Programming

by Hans Petter Langtangen « Book Overview


Back Cover Text

The target audience of this book is students and researchers in computational sciences who need to develop computer codes for solving partial differential equations. The exposition is focused on numerics and software related to mathematical models in solid and fluid mechanics. The book teaches finite element methods, and basic finite difference methods from a computational point of view. The main emphasis regards development of flexible computer programs, using the numerical library Diffpack. The application of Diffpack is explained in detail for problems including model equations in applied mathematics, heat transfer, elasticity, and viscous fluid flow. Diffpack is a modern software development environment based on C++ and object-oriented programming.

Excerpt from Introduction

During the last decades there has been a tremendous advancement of computer hardware, numerical algorithms, and scientific software. Engineers and scientists are now equipped with tools that make it possible to explore real-world applications of high complexity by means of computer simulation. Experimentation based on numerical simulation has become fundamental in engineering and many of the traditional sciences. A common feature of mathematical models in physics, geology, astrophysics, mechanics, geophysics, as well as in most engineering disciplines, is the appearance of systems of partial differential equations (PDEs). This text aims at equipping the reader with tools and skills for formulating solution methods for PDEs and producing associated running code.

Successful problem solving by means of mathematical models in science and engineering often demands a synthesis of knowledge from several fields. Besides the physical application itself, one must master the tools of mathematical modeling, numerical methods, as well as software design and implementation. In addition, physical experiments or field measurements might play an important role in the derivation and the validation of models. This book is written in the spirit of computational sciences as interdisciplinary activities. Although it would be attractive to integrate subjects like mathematics, physics, numerics, and software in book form, few readers would have the necessary broad background to approach such a text. We have therefore chosen to focus the present book on numerics and software, with some optional material on the physical background for models from fluid and solid mechanics.

The main goal of the text is to educate the reader in developing simulation programs for a range of different applications, using a common set of generic algorithms and software tools. This means that we mainly address readers who are or want to become professional programmers of numerical applications. As the resulting codes for solving PDEs tend to be very large and complicated, the implementational work is indeed nontrivial and time consuming. This fact calls for a careful choice of programming techniques.

During the 90s the software industry has experienced a change in programming technologies towards modern techniques such as object-oriented programming. In a number of contexts this has proved to increase the human efficiency of the software development and maintenance process considerably. The interest in these new techniques has grown significantly also in the numerical community. The software tools and programming style in this book reflect this modern trend. One of our main goals with the present text is in fact to explore the advantages of programming with objects in numerical contexts. The resulting programming is mainly on a high abstraction level, close to the numerical formulation of the PDE problem. We can do this because we build our PDE solvers on the Diffpack software.

Diffpack is a set of libraries containing building blocks in numerical methods for PDEs, for example, arrays, linear systems, linear and nonlinear solvers, grids, scalar and vector fields over grids, finite elements, and visualization support. Diffpack utilizes object-oriented programming techniques to a large extent and is coded in the C++ programming language. This means that we must write the PDE solvers in C++. If you do not already know C++, this text will motivate you to pick up the perhaps most popular programming language of the 90s. Most of the knowledge as a C++ programmer can be reused as a C, Java, or even Fortran 90/95 programmer as well, so we speak about a fortunate investment. You do not need to study a textbook on C++ before continuing with the present text, because experience shows that one can get started as a Diffpack programmer without any experience in C++ and learn the language gently as one proceeds with numerical algorithms, the software guide, and more advanced example codes. This book comes with a large number of complete Diffpack solvers for a range of PDE problems, and one can often adapt an existing solver to one's particular problem at hand.

In the past, Diffpack was distributed with a pure software guide as the only documentation. It soon became apparent that successful utilization of numerical software like Diffpack requires (i) a good understanding of the particular formulation of numerical methods that form the theoretical foundations of the package and (ii) a guide to the software tools, exemplified first in detail on simple problems and then extended, with small modifications, to more advanced engineering applications. The software guide can be significantly improved by providing precise references to the suitable generic description of various numerical algorithms. Although this generic view on methods is to a large extent available in the literature, the material is scattered around in textbooks, journal papers, and conference proceedings, mostly written for specialists. It was therefore advantageous to write down the most important numerical topics that must be mastered before one can develop PDE solvers in a programming environment like Diffpack, and tailor the exposition to a programmer.

Our decision to include brief material on the background for and derivation of a model helps the reader with physical knowledge and interest to more clearly see the link between our software-oriented numerical descriptions and comprehensive specialized text on the physics of a problem. Much of the literature on applications, and also on numerical analysis, works with formulations of equations that are not directly suited for numerical implementation. Our chapters on mechanical applications therefore emphasizes a combined physical, mathematical, and numerical framework that aids a flexible software implementation.

The present text has been used in a computationally oriented PDE course at the University of Oslo. Experience from the course shows that whether the aim is to teach numerical methods or software issues, both subjects can benefit greatly from an integrated approach where theory, algorithms, programming, and experimentation are combined. The result is that people use less time to grasp the theory and much less time to produce running code than what we have experienced in the past.

Table of Contents
  1. Getting Started
  2. Introduction to Finite Element Discretization
  3. Programming Finite Element Solvers
  4. Nonlinear Problems
  5. Solid Mechanics Applications
  6. Fluid Mechanics Applications
  7. Coupled Problems
  1. Mathematical Topics
  2. Diffpack Topics
  3. Iterative Methods for Sparse Linear Systems
  4. Software Tools for Solving Linear Systems
1Getting Started
1.1The First Diffpack Encounter
1.1.1What is Diffpack?
1.1.2A Trivial C++ Program
1.1.3A Trivial Diffpack Program
1.2Overview of Application Examples
1.1.1Very Simple Introductory Program Examples
1.1.2Finite Difference Simulators
1.1.3Finite Element Simulators
1.1.3More Advanced Applications
1.3Steady 1D Heat Conduction
1.3.1The Physical and Mathematical Model
1.3.2A Finite Difference Method
1.3.3Implementation in Diffpack
1.3.4Dissection of the Program
1.3.5Tridiagonal Matrices
1.3.6Variable Coefficients
1.3.7A Nonlinear Heat Conduction Problem
1.4Simulation of Waves
1.4.1Modeling Vibrations of a String
1.4.2A Finite Difference Method
1.4.4Visualizing the Results
1.4.5A 2D Wave Equation with Variable Wave Velocity
1.4.6A Model for Water Waves
1.5.1A Uni-Directional Wave Equation
1.5.2Centered Differences for a Boundary-Layer Problem
1.5.3Upwind Differences for a Boundary-Layer Problem
1.6About Programming with Objects
1.6.1Motivation for the Object Concept
1.6.2Example: Implementation of a Vector Class in C++
1.6.3Arrays in Diffpack
1.6.4Example: Design of an ODE Solver Environment
1.6.5Abstractions for Grids and Fields
1.7Coding the PDE Simulator as a Class
1.7.1Steady 1D Heat Conduction Revisited
1.7.2Nonlinear 1D Heat Conduction Revisited
1.7.3Empirical Investigation of the Numerical Method
1.7.4Simulation of 1D Waves Revisited
1.7.5Simulation of 2D Waves Revisited
1.7.6Transient Heat Conduction
1.8.1Transient Flow Between Moving Plates
1.8.2Transient Channel Flow
1.8.3Coupled Heat and Fluid Flow
1.8.4Difference Schemes for Transport Equations
1.8.53D Sound Waves
2Introduction to Finite Element Discretization
2.1Weighted Residual Methods
2.1.1Basic Principles
2.1.2Example: A 1D Poisson Equation
2.1.3Treatment of Boundary Conditions
2.2Time Dependent Problems
2.2.1A Wave Equation
2.2.2A Heat Equation
2.3Finite Elements in One Space Dimension
2.3.1Piecewise Polynomials
2.3.2Handling of Essential Boundary Conditions
2.3.3Direct Computation of the Linear System
2.3.4Element-By-Element Formulation
2.3.5Extending the Concepts to Quadratic Elements
2.3.6Summary of the Element-By-Element Algorithm
2.4Example: A 1D Wave Equation
2.4.1The Finite Element Equations
2.4.2Interpretation of the Discrete Equations
2.4.3Accuracy and Stability
2.5Naive Implementation
2.6.1Steady Heat Conduction with Cooling Law
2.6.2Stationary Pipe Flow
2.6.3Transient Pipe Flow
2.6.4Retardation of a Well-Bore
2.7Higher-Dimensional Finite Elements
2.7.1The Bilinear Element and Generalizations
2.7.2The Linear Triangle
2.7.3Example: A 2D Wave Equation
2.7.4Other Two-Dimensional Element Types
2.7.5Three-Dimensional Elements
2.8Calculation of derivatives
2.8.1Global Least-Squares Smoothing
2.8.2Flux Computations in Heterogeneous Media
2.9Convection-Diffusion Equations
2.9.1A One-Dimensional Model Problem
2.9.2Multi-Dimensional Equations
2.9.3Time-Dependent Problems
2.10Analysis of the Finite Element Method
2.10.1Weak Formulations
2.10.2Variational Problems
2.10.3Results for Continuous Problems
2.10.4Results for Discrete Problems
2.10.5A Priori Error Estimates
2.10.6Numerical Experiments
2.10.7Adaptive Finite Element Methods
3Programming of Finite Element Solvers
3.1A Simple Program for the Poisson Equation
3.1.2Basic Parts of a Simulator Class
3.2Increasing the Flexibility
3.2.1A Generalized Model Problem
3.2.2Using the Menu System
3.2.3Creating the Grid Object
3.3Some Visualization Tools
3.3.1Storing Fields for Later Visualization
3.3.2Filtering Simres Data
3.3.3Visualizing Diffpack Data in Plotmtv
3.3.4Visualizing Diffpack Data in Gnuplot
3.3.5Visualizing Diffpack Data in Matlab
3.3.6Visualizing Diffpack Data in Vtk
3.3.7Visualizing Diffpack Data in IRIS Explorer
3.3.8Plotting Fields Along Lines
3.4Some Useful Diffpack Features
3.4.1The Menu System
3.4.2Multiple Loops
3.4.3Computing Numerical Errors
3.4.5Computing Derivatives of Finite Element Fields
3.4.6Specializing Code in Subclass Solvers
3.5Introducing More Flexibility
3.5.1Setting Boundary Condition Information in the Grid
3.5.2Line and Surface Integrals
3.5.3Simple Mesh Generation Tools
3.5.4Grid Generation by Super Elements
3.5.6Automatic Report Generation
3.5.7Specializing Code in Subclass Solvers
3.5.8Overriding Menu Answers in the Program
3.5.9Estimating Convergence Rates
3.5.10Axisymmetric Formulations and Cartesian 2D Code
3.6Step-by-Step Development of a Diffpack Solver
3.6.1Physical and Mathematical Problem
3.6.2Editing and Writing Source Code
3.6.3A Simplified Test Case
3.6.4Creating the Grid
3.6.5Running Some Initial 2D Simulations
3.6.6Running Real Simulations
3.7Adaptive Grids
3.7.1Grid Classes with Local Mesh Refinements
3.7.2How to Extend an Existing Simulator
3.7.3Organization of Refinement Criteria
3.7.4Grid Refinements as a Preprocessor
3.7.5Example: Corner-Flow Singularity
3.7.6User-Defined Refinement Criteria
3.7.7Transient Problems
3.8.1Flow in an Open Inclined Channel
3.8.2Stress Concentration due to Geometric Imperfections
3.8.3A Poisson Problem with Pure Neumann Conditions
3.8.4Lifting Airfoil
3.9A Convection-Diffusion Solver
3.10A Heat Equation Solver
3.11A More Flexible Heat Equation Solver
3.11.1About the Model Problem and the Simulator
3.11.2Variable Time Step size
3.11.3Applying a Transient Solver to a Stationary PDE
3.11.4Thermal Conditions During Welding
3.12Visualization of Time-Dependent Fields
3.12.1Filtering Time-Dependent Simres Data
3.12.2Storing Fields at Selected Time Points
3.12.3Time Series at Selected Spatial Points
3.12.4Using ImageMagick Tools
3.12.5Animation Using Plotmtv
3.12.6Animation Using Vtk
3.12.7Animation Using Matlab
3.12.8Real-Time Visualization
3.12.9Handling Simulation and Visualization from a Script
3.12.10Heat Transfer Exercises
3.13A Transient Heat Transfer Application
3.13.1The Mathematical and Physical Model
3.13.3Testing and Debugging the Initial State
3.13.4Creating the Grid
3.13.5Running Time-Dependent Simulations
3.13.6A Scripting Interface for Automating Simulations
3.14.1Transient Heat Transfer in a Two-Material Structure
3.14.2Transient Flow with Non-Circular Cross Section
3.14.3Transient Groundwater Flow
3.15Efficient Solution of the Wave Equation
3.15.3Extensions of the Model Problem
3.15.4Flexible Representation of Variable Coefficients
4Nonlinear Problems
4.1Discretization and Solution of Nonlinear PDEs
4.1.1Finite Difference Discretization
4.1.2Finite Element Discretization
4.1.3The Group Finite Element Method
4.1.4Successive Substitutions
4.1.5Newton-Raphson's Method
4.1.6A Transient Nonlinear Heat Conduction Problem
4.1.7Iteration Methods at the PDE Level
4.1.8Continuation Methods
4.2Software Tools for Nonlinear Finite Element Problems
4.2.1A Solver for a Nonlinear Heat Equation
4.2.2Extending the Solver
4.3.1Operator Splitting for a Reaction-Diffusion Model
4.3.2Compressible Potential Flow
5Solid Mechanics Applications
5.1Linear Thermo-Elasticity
5.1.1The Physical and Mathematical Problem
5.1.2A Finite Element Method
5.1.3Engineering Finite Element Notation
5.1.6Elastic Vibrations
5.2.1Basic Physical Features of Elasto-Viscoplasticity
5.2.2A Three-Dimensional Elasto-Viscoplastic Model
5.2.3Simplification; a Forward Scheme in Time
5.2.4Numerical Handling of Yield Criteria
6Fluid Mechanics Applications
6.1Convection-Diffusion Equations
6.1.1The Physical and Mathematical Model
6.1.2A Finite Element Method
6.1.3Incorporation of Nonlinearities
6.1.4Software Tools
6.1.5Melting and Solidification
6.2Shallow Water Equations
6.2.1The Physical and Mathematical Model
6.2.2Finite Difference Methods on Staggered Grids
6.2.4Nonlinear and Dispersive Terms
6.2.5Finite Element Methods
6.3An Implicit Finite Element Navier-Stokes Solver
6.3.1The Physical and Mathematical Model
6.3.2A Finite Element Method
6.3.3Solution of the Nonlinear Systems
6.4A Classical Finite Difference Navier-Stokes Solver
6.4.1Operator Splitting
6.4.2Finite Differences on 3D Staggered Grids
6.4.3A Multigrid Solver for the Pressure Equation
6.5A Fast Finite Element Navier-Stokes Solver
6.5.1Operator Splitting and Finite Element Discretization
6.5.2An Optimized Implementation
6.6.1Analysis of Discrete Shallow Water Waves
6.6.2Approximating the Navier-Stokes Equations by a Laplace Equation
7Coupled Problems
7.1Fluid-Structure Interaction; Squeeze-Film Damping
7.1.1The Physical and Mathematical Model
7.1.2Numerical Methods
7.2Fluid Flow and Heat Conduction in Pipes
7.2.1The Physical and Mathematical Model
7.2.2Numerical Methods
7.3.1Transient Spherical-Symmetric Thermo-Elasticity
7.3.2Transient 2D/3D Thermo-Elasticity
7.3.3Convective-Diffusive Transport in Viscous Flow
7.3.4Chemically Reacting Fluid
AMathematical Topics
A.1Scaling and Dimensionless Variables
A.2Indicial Notation
A.3Compact Notation for Difference Equations
A.4Stability and Accuracy of Difference Approximations
A.4.1Typical Solutions of Simple Prototype PDEs
A.4.2Physical Significance of Parameters in the Solution
A.4.3Analytical Dispersion Relations
A.4.4Solution of Discrete Equations
A.4.5Numerical Dispersion Relations
A.4.9Truncation Error
A.4.10Traditional von Neumann Stability Analysis
A.4.11Example: Analysis of the Heat Equation
A.5Exploring the Nature of Some PDEs
A.5.1A Hyperbolic Equation
A.5.2An Elliptic Equation
A.5.3A Parabolic Equation
A.5.4The Laplace Equation Solved by a Wave Simulator
A.5.5Well Posed Problems
BDiffpack Topics
B.1Brief Overview of Important Diffpack Classes
B.2Diffpack-Related Operating System Interaction
B.3Combining Diffpack with Other Types of Software
B.3.1Calling Other Software Packages from Diffpack
B.3.2Calling Diffpack from Other Types of Software
B.4Basic Diffpack Features
B.4.1Diffpack man pages
B.4.2Standard Command-Line Options
B.4.3Generalized Input and Output
B.4.4Automatic Verification of a Code
B.5Visualization Support
B.5.2Scalar and Vector Fields
B.6Details on Finite Element Programming
B.6.1Basic Functions for Finite Element Assembly
B.6.2Using Functors for the Integrands
B.6.3Integrating Quantities over the Grid or the Boundary
B.6.4Class Relations in the Finite Element Engine
B.7Optimizing Diffpack Codes
B.7.1Avoiding Repeated Matrix Factorizations
B.7.2Optimizing the Assembly Process
B.7.3Optimizing Array Indexing
CIterative Methods for Sparse Linear Systems
C.1Classical Iterative Methods
C.1.1A General Framework
C.1.2Jacobi, Gauss-Seidel, SOR, and SSOR Iteration
C.2Conjugate Gradient-Like Iterative Methods
C.2.1Galerkin and Least-Squares Methods
C.2.2Summary of the Algorithms
C.2.3A Framework Based on the Error
C.3.1Motivation and Basic Principles
C.3.2Classical Iterative Methods as Preconditioners
C.3.3Incomplete Factorization Preconditioners
C.4Multigrid and Domain Decomposition Methods
C.4.1Domain Decomposition
C.4.2Multigrid Methods
DSoftware Tools for Solving Linear Systems
D.1Storing and Initializing Linear Systems
D.1.1Vector and Matrix Formats
D.1.2Detailed Matrix Examples
D.1.3Representation of Linear Systems
D.2Programming with Linear Solvers
D.2.1Gaussian Elimination
D.2.2A Simple Demo Program
D.2.3A 3D Poisson Equation Solver
D.3Classical Iterative Methods
D.4Conjugate Gradient-like Methods
D.4.1Symmetric Systems
D.4.2Nonsymmetric Systems
D.5Preconditioning Strategies
D.6Convergence History and Stopping Criteria
D.7Example: Implicit Methods for Transient Diffusion
D.8High-Level Stencil Programming of Finite Difference Schemes
D.8.1Finite Difference Stencils
D.8.2Basic Structure of a Stencil-Based Simulator
D.8.3Defining the Stencils