Published by World Scientific Publishing Co. Pte. Ltd. 5 Toh Tuck Link, Singapore 596224 USA office: 27 Warren Street, ...
98 downloads
1001 Views
1MB Size
Report
This content was uploaded by our users and we assume good faith they have the permission to share this book. If you own the copyright to this book and it is wrongfully on our website, we offer a simple DMCA procedure to remove your content from our site. Start by pressing the button below!
Report copyright / DMCA form
Published by World Scientific Publishing Co. Pte. Ltd. 5 Toh Tuck Link, Singapore 596224 USA office: 27 Warren Street, Suite 401– 402, Hackensack, NJ 07601 UK office: 57 Shelton Street, Covent Garden, London WC2H 9HE
British Library Cataloguing-in-Publication Data A catalogue record for this book is available from the British Library.
COMPUTATIONAL METHODS FOR PDE IN MECHANICS Series on Advances in Mathematics for Applied Sciences — Vol. 67 Copyright © 2004 by World Scientific Publishing Co. Pte. Ltd. All rights reserved. This book, or parts thereof, may not be reproduced in any form or by any means, electronic or mechanical, including photocopying, recording or any information storage and retrieval system now known or to be invented, without written permission from the Publisher.
For photocopying of material in this volume, please pay a copying fee through the Copyright Clearance Center, Inc., 222 Rosewood Drive, Danvers, MA 01923, USA. In this case permission to photocopy is not required from the publisher.
ISBN 981-256-037-8
Printed in Singapore.
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
To my wife Silvana and my daughters Lucia and Erica
v
wsdac04
July 3, 2004
23:17
vi
WSPC/Book Trim Size for 9in x 6in
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Preface
Several physical phenomena are governed by partial differential equations. Obviously, this is not a mere chance. Indeed, scientists and technicians, following the scientific method introduced by Galilei, know very well that every natural event can be analyzed by means of a related mathematical model. This is very often based on partial differential equations. A celebrated and historical example is given by the Maxwell equations, which admirably describe the electro-magnetic field. Other emblematic, not less important, models are: Fourier (heat) equation, D’Alembert (wave) equation, Laplace/Poisson (potential) equation, Euler/Stokes (fluid) equations. Mathematical modeling has been successively adopted by researchers working in several other fields and so, at present, partial differential equations can help to explain phenomena occurring in Biology, Medicine, Economy, Sociology, and so on. During the last two hundred years, applied mathematician involved in the above topic have never ended. The first pioneers concentrated their efforts on the exact solutions. Next, the attention was focused on the qualitative analysis in order to obtain information on the solutions even when these could not be explicitly found. In the last sixty years, also the quantitative analysis has been strongly developed in parallel with the great growth of computers power. At present, numerical methods provide a powerful approach for solving partial differential equations and their knowledge becomes more and more a necessary cultural luggage of applied researchers and technicians. This book is an elementary introduction to computational methods, based on the finite differences, for parabolic, hyperbolic and elliptic partial differential equations. The numerical discussion of each type of equation is always preceded by the introduction of models in Mechanics, which are
vii
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
viii
carefully derived. In particular, the role of the initial and boundary conditions is pointed out with reference to physical situations. The numerical analysis is concerned with the most used finite-difference methods for each type of equation. Several examples are solved and exercises proposed to give the Reader the opportunity to practice. Since there is no numerical method without approximations, the accuracy of the schemes is also analyzed. Special attention is devoted to the propagation of rounding errors, which inevitable arise during the computational process. This leads to discuss the basic concepts of stability, consistency and convergence, which are illustrated by inductive procedures and then formalized. Dealing with applied numerical methods sooner or later requires that own programs have to be developed. Therefore, some examples are provided by using the C++ language. The classic C language was evolved after 1970 by B. W. Kernigham and D. M. Ritchie. C++, developed by B. Stroustrup in 1980s, is an extension of C. It provides the capabilities of object-oriented programming. It is considered the most powerful and flexible language. The Visual C++ 1 compiler is quickly introduced and Windows 2 programs are built step by step. These programs can be easily fitted to other situations, with small changes. The codes of the programs developed in this book are also supplied with the enclosed CD-Rom. Chapter 1 deals with the most used finite-difference approximations of derivatives. In particular, the forward, central and backward approximations are derived. Chapter 2 presents the classical model of heat conduction in solids, based on Fourier law. Also, phase-change problems are illustrated. Chapter 3 introduces the classical explicit method for the one-dimensional heat equation. The concepts of stability, consistency and convergence are applied. Developing programs in C++, related to the heat equation, is the topic of Chapters 4 and 5. Chapter 6 describes numerical methods for parabolic equations. Some nonlinear case is also considered and a melting problem is discussed. Furthermore, the classical explicit method is generalized to the heat equation in two and three space dimensions. A program related to this case is developed in Chapter 7. Chapter 8 is devoted to wave motions. At first, the wave equation is derived from the model of one-dimensional continuum. Next, we introduce the equations governing the motions of general continuous systems. As special cases the elastic and fluid media are examined in order to point out wave phenomena. Finally, a free-boundary value problem is presented. Explicit and implicit finite1 Visual
C++ is a registered trademark of Microsoft Corporation is a registered trademark of Microsoft Corporation
2 Windows
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Preface
wsdac04
ix
difference methods for the wave equation are illustrated in Chapter 9. An example of third-order equation is provided. Chapter 10 deals with finitedifference methods for linear and nonlinear hyperbolic systems. Elliptic equations are considered in Chapter 11. The motions of fluids through porous media are examined. In Appendix A the classification of partial differential equations is given for second-order equations and general systems of first-order equations. Elements of Linear Algebra are briefly provided in Appendix B. The author is grateful to Professor N. Bellomo for encouraging him to write this book and the pertinent suggestions, for reading the manuscript and making various useful criticisms. Especial thanks are due to World Scientific Publishing Co. B. D’Acunto University of Naples “Federico II”, 2004.
July 3, 2004
23:17
x
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Contents
Preface
vii
1. Finite differences 1.1 1.2 1.3 1.4
1
Function discretization . . . . . . . . . . . . . Finite-difference approximation of derivatives Approximation for higher-order derivatives . Finite-difference operators . . . . . . . . . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
2. Fourier model of heat conduction 2.1 2.2 2.3 2.4 2.5 2.6
Fourier model of heat conduction . . . Heat equation . . . . . . . . . . . . . . Initial and boundary conditions . . . . Phase-change problems . . . . . . . . . Heat conduction in a moving medium Fick’s law and diffusion . . . . . . . .
9 . . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
3. An explicit method for the heat equation 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8
Non-dimensional form of the heat equation The classical explicit method . . . . . . . . Matrix form . . . . . . . . . . . . . . . . . . Stability . . . . . . . . . . . . . . . . . . . . Consistency . . . . . . . . . . . . . . . . . . Convergence . . . . . . . . . . . . . . . . . . Neumann boundary conditions . . . . . . . Boundary conditions of the third kind . . . xi
2 3 5 7
10 10 13 14 17 17 21
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
22 23 24 25 28 30 31 33
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
xii
4. A Windows program 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9
35
Introduction . . . . . . . . . Creating a new project . . . Equation data . . . . . . . . Initial data . . . . . . . . . Boundary data . . . . . . . Numerical results . . . . . . Analysis of data . . . . . . Graphical results. Examples Icons . . . . . . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
5. The Heat2 project 5.1 5.2 5.3 5.4 5.5 5.6 5.7
Introduction . . . . . . . . The project . . . . . . . . Document class . . . . . . Equation class . . . . . . Initial and boundary data View class . . . . . . . . . Examples . . . . . . . . .
67 . . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
6. Parabolic equations 6.1 A simple implicit method . . . . . . . . . . . . . 6.2 Crank-Nicolson method . . . . . . . . . . . . . . 6.3 Von Neumann stability . . . . . . . . . . . . . . . 6.4 Combined scheme . . . . . . . . . . . . . . . . . . 6.5 An example of unstable method . . . . . . . . . . 6.6 DuFort-Frankel method . . . . . . . . . . . . . . 6.7 Matrix stability . . . . . . . . . . . . . . . . . . . 6.8 Stability analysis by the energy method . . . . . 6.9 Variable diffusivity coefficient . . . . . . . . . . . 6.10 Heat equation in two and three space dimensions 6.11 Diffusion-convection equation . . . . . . . . . . . 6.12 Nonlinear equation . . . . . . . . . . . . . . . . . 6.13 A free boundary problem . . . . . . . . . . . . . 7. The Heat3 project
36 37 40 45 50 55 59 60 66
68 69 70 74 80 83 91 93
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
94 97 101 106 107 108 112 116 121 121 123 126 128 133
7.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 7.2 Main menu . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Contents
7.3 7.4 7.5 7.6
xiii
Implementing the document class Dialog resources . . . . . . . . . Implementing the view class . . . Using the program . . . . . . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
8. Wave motions 8.1 8.2 8.3 8.4 8.5 8.6
One-dimensional continuum Flexible strings . . . . . . . Wave equation . . . . . . . Waves in elastic solids . . . Motion of fluids . . . . . . . Free piston problem . . . .
138 143 157 171 175
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
9. Finite-difference methods for the wave equation
176 179 179 182 186 189 191
9.1 Courant-Friederichs-Lewy method . . . . . . . . . . . . . . 192 9.2 Implicit methods . . . . . . . . . . . . . . . . . . . . . . . . 196 9.3 Perturbed wave equation . . . . . . . . . . . . . . . . . . . . 201 10. Hyperbolic equations
209
10.1 First-order equations. Explicit methods 10.2 Implicit methods . . . . . . . . . . . . . 10.3 Systems of first-order equations . . . . . 10.4 Nonlinear systems . . . . . . . . . . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
11. Elliptic equations 11.1 Historic model . . . . . . . . . . 11.2 Porous media . . . . . . . . . . . 11.3 Dirichlet problem . . . . . . . . . 11.4 Curved boundary . . . . . . . . . 11.5 Three-dimensional applications . 11.6 Green’s identities. Consequences 11.7 Neumann problem . . . . . . . . 11.8 Third boundary value problem . Appendix A Classification of PDEs
210 218 221 226 229
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
230 230 233 239 241 242 245 251 255
A.1 Second-order partial differential equations . . . . . . . . . . 256 A.2 Systems of first-order PDEs . . . . . . . . . . . . . . . . . . 258
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
xiv
Appendix B Elements of linear algebra
263
B.1 Eigenvalues and eigenvectors . . . . . . . . . . . . . . . . . 264 B.2 Vector and matrix norms . . . . . . . . . . . . . . . . . . . 269 Bibliography
273
Index
277
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Chapter 1
Finite differences
The scientific community agrees that finite-difference schemes were first used by Euler (1707-1783) to find approximate solutions of differential equations. The technique is known as Euler method. However, only after 1945 systematic research activity on the above topic has been strongly developed, when high-speed computers began to be available. At present, finite-difference methods provide a powerful approach to solve differential equations and are widely used in any field of applied sciences. Equations with variable coefficients and even nonlinear problem can be treated by these techniques. Generally, the error of an approximating solution can be made arbitrary small. Rounding errors, which inevitably arise during the computational process, can be controlled by a preliminary analysis of the numerical stability of finite-difference schemes. Furthermore, numerical solutions can give suggestions to more general questions. This chapter introduces to the most used finite-difference approximations of derivatives. In particular, the well-known forward, central and backward approximations are presented. The analysis systematically starts from Taylor’s series expansion so that the truncation error can be immediately pointed out. Firstly, the approximation of first-order derivatives is dealt with, and, subsequently, the analysis is developed for higher-order derivatives. Exercises are proposed to give the Reader the opportunity to practice. Finally, we present some finite-difference operators, which are frequently found in literature. Their use can help to shorten long formulas in some cases.
1
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
2
1.1
Function discretization
Let us consider a function u(x, t) depending on two variables x ∈ [0, L] and t ∈ [0, T ]. A discretization of function u is obtained by considering only the values ui,j on a finite number of points (xi , tj ) ui,j = u(xi , tj ) = u(i∆x, j∆t), i = 0, ..., m, j = 0, ..., n,
(1.1.1)
where ∆x = L/m, ∆t = T /n, fig. 1.1.1. Usually, instead of ui,j , the notation uji is also used.
Fig. 1.1.1
Space-time grid
The formula for a function of one variable is immediately derived from (1.1.1). In addition, generalizing it in obvious way yields the case regarding a function of three or more variables. A basic role to estimate the error involved in finite-difference approximations of function derivatives is played by the well-known Taylor’s series expansion f (x + ∆x) = f (x) +
n−1
f (h) (x)
h=1
(∆x)h (∆x)n + f (n) (x + θ∆x) , h! n!
(1.1.2)
where 0 < θ < 1 and f (h) denotes the hth derivative of f . Noting that the last term is of order (∆x)n , (1.1.2) can also be written as
f (x + ∆x) = f (x) +
n−1 h=1
f (h) (x)
(∆x)h + O((∆x)n ), h!
(1.1.3)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Finite differences
wsdac04
3
where the symbol O (big o) has been used, defined as follows g(y) = O(y n ), y ∈ Ω ⇔ |g(y)| ≤ cy n , ∀y ∈ Ω,
(1.1.4)
where c is a positive constant. 1.2
Finite-difference approximation of derivatives
Let us define the forward approximation for the partial derivative ut . Applying Taylor’s series expansion (1.1.3) to u(xi , tj + ∆t) gives u(xi , tj + ∆t) = u(xi , tj ) + ut (xi , tj )∆t + O((∆t)2 )
(1.2.1)
which, by using notation (1.1.1), is written as ui,j+1 = ui,j + (ut )i,j ∆t + O((∆t)2 ),
(1.2.2)
that is, (ut )i,j =
ui,j+1 − ui,j + O(∆t). ∆t
(1.2.3)
Hence, it follows the approximation formula for the partial derivative of u with respect to t, called forward approximation, (ut )i,j ≈
ui,j+1 − ui,j . ∆t
(1.2.4)
Formula (1.2.4) evidently implies a leading error of order ∆t. Similarly, from ui+1,j − ui,j (ux )i,j = + O(∆x) (1.2.5) ∆x it follows the forward approximation for ux (ux )i,j ≈
ui+1,j − ui,j , ∆x
(1.2.6)
with a leading error of order ∆x. The backward approximation is inferred in analogous way. Applying Taylor’s expansion (1.1.3) to u(xi , tj − ∆t) and u(xi − ∆x, tj ) implies, respectively, the following (ut )i,j ≈
ui,j − ui,j−1 , ∆t
(1.2.7)
(ux )i,j ≈
ui,j − ui−1,j , ∆x
(1.2.8)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
4
which give the backward approximations for the first partial derivatives, with the same leading error of the last case. Let us define the central approximation. Applying Taylor’s expansion (1.1.3) with n = 4 yields ui,j+1 = ui,j +(ut )i,j ∆t+(utt )i,j
ui,j−1 = ui,j −(ut )i,j ∆t+(utt )i,j
(∆t)2 (∆t)3 +(uttt )i,j +O((∆t)4 ), (1.2.9) 2! 3!
(∆t)2 (∆t)3 −(uttt )i,j +O((∆t)4 ). (1.2.10) 2! 3!
Subtracting the second expression from the first gives ui,j+1 − ui,j−1 = 2(ut )i,j ∆t + O((∆t)3 ),
(1.2.11)
that is, (ut )i,j =
ui,j+1 − ui,j−1 + O((∆t)2 ). 2∆t
(1.2.12)
Hence, we obtain the central approximation for ut (ut )i,j ≈
ui,j+1 − ui,j−1 , 2∆t
(1.2.13)
with a leading error of order (∆t)2 . Similarly, it follows (ux )i,j =
ui+1,j − ui−1,j + O((∆x)2 ). 2∆x
(1.2.14)
ui+1,j − ui−1,j , 2∆x
(1.2.15)
Hence, (ux )i,j ≈
which gives the central approximation for ux with the same error. The preceding finite-difference approximations consider the values of a function on two points of the xt grid and are the most used. However, formulas involving three or more grid points can also be deduced with a smaller error, in general. Firstly, let us discuss the three-point forward approximation for ut . Using again Taylor’s expansion (1.1.3) gives ui,j+1 − ui,j = (ut )i,j ∆t + (utt )i,j (∆t)2 /2 + O((∆t)3 ),
(1.2.16)
ui,j+2 − ui,j = (ut )i,j 2∆t + (utt )i,j 2(∆t)2 + O((∆t)3 ),
(1.2.17)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Finite differences
wsdac04
5
which imply (ut )i,j =
4ui,j+1 − 3ui,j − ui,j+2 + O((∆t)2 ). 2∆t
(1.2.18)
Hence it follows the three-point forward approximation 4ui,j+1 − 3ui,j − ui,j+2 , 2∆t
(ut )i,j ≈
(1.2.19)
with a leading error of order (∆t)2 . Similarly, the three-point forward approximation for ux can be obtained (ux )i,j ≈
Exercise 1.2.1
4ui+1,j − 3ui,j − ui+2,j . 2∆x
(1.2.20)
Show the following three-point backward approximations
Exercise 1.2.2 approximations
(ut )i,j ≈
−4ui,j−1 + 3ui,j + ui,j−2 , 2∆t
(1.2.21)
(ux )i,j ≈
−4ui−1,j + 3ui,j + ui−2,j . 2∆x
(1.2.22)
Deduce the following four-point forward and backward
(ut )i,j ≈
−ui,j+2 + 6ui,j+1 − 3ui,j − 2ui,j−1 , 6∆t
(ut )i,j ≈
ui,j−2 − 6ui,j−1 + 3ui,j + 2ui,j+1 , 6∆t
(1.2.23)
(1.2.24)
and verify that the leading error is of order (∆t)3 . Write similar formulas for the partial derivative ux . 1.3
Approximation for higher-order derivatives
Let us introduce the forward approximation for the second derivative utt . Multiply (1.2.16) by 2 and subtract the result to (1.2.17) (utt )i,j =
ui,j+2 − 2ui,j+1 + ui,j + O(∆t). (∆t)2
(1.3.1)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
6
Hence, it follows the quoted approximation (utt )i,j ≈
ui,j+2 − 2ui,j+1 + ui,j (∆t)2
(1.3.2)
with a leading error of order ∆t. A similar result holds for the second derivative uxx (uxx )i,j ≈
ui+2,j − 2ui+1,j + ui,j . (∆x)2
(1.3.3)
By analogous arguments the backward approximations of the same derivatives can be inferred (utt )i,j ≈
ui,j−2 − 2ui,j−1 + ui,j , (∆t)2
(1.3.4)
(uxx )i,j ≈
ui−2,j − 2ui−1,j + ui,j , (∆x)2
(1.3.5)
with a leading error of order ∆t and ∆x, respectively. Summing (1.2.9), (1.2.10) ui,j+1 + ui,j−1 = 2ui,j + (utt )i,j (∆t)2 + O((∆t)4 )
(1.3.6)
and solving with respect to (utt )i,j gives the central approximation (utt )i,j ≈
ui,j+1 − 2ui,j + ui,j−1 . (∆t)2
(1.3.7)
Formula (1.3.7) is more accurate than (1.3.2), (1.3.4), because its leading error is of order (∆t)2 . A similar result holds for uxx (uxx )i,j ≈
ui+1,j − 2ui,j + ui−1,j . (∆x)2
(1.3.8)
When functions of two or more variables are considered, the mixed derivatives must also be discussed. Let us start with the forward approximation to uxt . Applying (1.2.3) to the derivative ux yields (uxt )i,j =
(ux )i,j+1 − (ux )i,j + O(∆t). ∆t
(1.3.9)
Hence, considering (1.2.5) implies (uxt )i,j =
ui+1,j+1 − ui,j+1 − ui+1,j + ui,j + O(∆x) + O(∆t), ∆x∆t
(1.3.10)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Finite differences
wsdac04
7
and, therefore, with a leading error of order O(∆x) + O(∆t), (uxt )i,j ≈
ui+1,j+1 − ui,j+1 − ui+1,j + ui,j . ∆x∆t
(1.3.11)
The same formula is found by applying (1.2.5) to ut and using (1.2.3), as it is easily verified. Similarly, the backward approximation (uxt )i,j ≈
ui−1,j−1 − ui,j−1 − ui−1,j + ui,j , ∆x∆t
(1.3.12)
and the central approximation (uxt )i,j ≈
ui+1,j+1 − ui−1,j+1 − ui+1,j−1 + ui−1,j−1 , 4∆x∆t
(1.3.13)
can be derived with a leading error of order O(∆x)+O(∆t) and O((∆x)2 )+ O((∆t)2 ), respectively. Higher order derivatives can be evaluated by analogous arguments. Exercise 1.3.1 Mix suitably the first derivative approximations and derive the other (six) finite-difference formulas for uxt . 1.4
Finite-difference operators
Sometimes finite-difference formulas can become very long. Using finitedifference operators can be convenient in these situations. With reference to an arbitrary function f (x), frequently used operators are the following ∆fi = fi+1 − fi , (forward),
(1.4.1)
∇fi = fi − fi−1 , (backward),
(1.4.2)
δfi = fi+1/2 − fi−1/2 , central),
(1.4.3)
µfi = (fi+1/2 + fi−1/2 )/2, (average),
(1.4.4)
Efi = fi+1 , (shift).
(1.4.5)
When functions u = u(x, t) depending on two or more variables are considered, the variable which the operator is applied to must be specified;
July 3, 2004
23:17
8
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
for example
Exercise 1.4.1
∆t ui,j = ui,j+1 − ui,j ,
(1.4.6)
∇x ui,j = ui,j − ui−1,j .
(1.4.7)
Verify that δµfi = (fi+1 − fi−1 )/2,
(1.4.8)
δ 2 fi = δδfi = fi+1 − 2fi + fi−1 .
(1.4.9)
Further Reading: [Ames (1992)], [Collatz (1966)], [Lapidus and Pinter (1982)], [Mitchell and Griffiths (1995)], [Morton and Mayers (2002)], [Necati Ozisik (1994)], [Smith (1985)], [Thomas (1995)].
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Chapter 2
Fourier model of heat conduction
The classical model of heat conduction in solids is the main topic of this chapter. It is based on two principles: Fourier’s law and energy balance. The first is an experimental law which is so named in honor of the French scientist who first used it. The second is related to the law of energy conservation. Considering both models yields the so-called heat equation involving only the temperature. Solving this partial differential equation enables us to determine the thermal evolution within a solid when the initial temperature as well as the thermal conditions at the bounding surface of the body are known. The results obtained by Fourier law agree very well with experimental data in most applications. Nevertheless, there exist thermal processes which the heat equation is unable to describe adequately, mainly when extremely high rate of changes of heat flux are involved. Recently, more general models have been introduced. We shall mention them in Chapter 10. Boundary conditions play an important role in solving the heat equation. So, the main kinds of these conditions are introduced and the related physical meaning pointed out. Furthermore, some phase-change processes are considered. Their formalization leads to mathematical problems, which are technically difficult to solve because the moving boundary is another unknown. The last sections are devoted to the heat propagation in a moving medium and to diffusion processes.
9
wsdac04
July 3, 2004
23:17
10
2.1
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
Fourier model of heat conduction
The classical model of the heat propagation in solids is based on Fourier’s law (1822). This phenomenological model follows from observations and experiences which make evident that in homogeneous and isotropic solids, the heat flux is proportional to the thermal gradient and it moves from hot regions towards those cooler. Let us denote by: • q(x, t) the heat flux vector which gives the thermal flow per unit time and per unit isothermal surface; generally, q depends on the time t and the position x in the solid, fig. 2.2.1; • u(x, t) the temperature and ∇u = (∂u/∂x1 , ∂u/∂x2 , ∂u/∂x3 ) its gradient with respect to the space variables. Using these notations Fourier’s law is stated as follows q(x, t) = −k∇u(x, t),
(2.1.1)
where the positive scalar k represents the thermal conductivity of the material. If q is expressed in W/m2 and u in ◦ C, then k is in W/m◦ C. It varies with material and temperature; for example, when u = 0◦ C the thermal conductivity is k = 418.7 W/m◦ C for the silver and k = 2.215 W/m◦ C for the ice. 2.2
Heat equation
This section deals with derivation of the partial differential equation which governs the temperature evolution in a solid B. Let us start from the energy balance equation for a generic control volume V included in B: the rate of energy in V equates the rate of energy production in V plus the heat flow entering into V through the bounding surface ∂V , fig. 2.2.1. Now, this must be formalized. Let us denote by e(x, t) the internal energy per unit mass and ρ(x) the density of the solid, supposed at rest. Then, the time rate of energy in V is ρ(x)et (x, t) dx. (2.2.1) V
The internal energy depends on temperature: e = e(u). For many materials and for a wide range of temperatures, e is expressed by a linear function e = cp u,
(2.2.2)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Fourier model of heat conduction
Fig. 2.2.1
wsdac04
11
Control volume
where cp is the specific heat at constant pressure. Substituting (2.2.2) into (2.2.1) yields cp ρut dx. (2.2.3) V
Furthermore, let F (x, t) be the amount per unit time per unit volume of heat produced by internal sources, as electric resistances, chemical reactions, nuclear radiations or other thermal generators; F is expressed in W/m3 and the total amount in V is F (x, t) dx. (2.2.4) V
Finally, the heat flow entering through the surface ∂V per unit area per unit time is expressed by q · n dS, (2.2.5) − ∂V
where n denotes the exterior unit normal to ∂V at the integration point. Applying the Gauss divergence theorem yields q · n dS = − ∇ · q dx, (2.2.6) − ∂V
V
where ∇ · q = ∂q1 /∂x1 + ∂q2 /∂x2 + ∂q3 /∂x3 denotes the divergence of q with respect to the space variables.
July 3, 2004
23:17
12
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
By using (2.2.3), (2.2.4), (2.2.6) the energy conservation law is written as follows cp ρut dx = F dx − ∇ · q dx. (2.2.7) V
V
V
Hence, considering (2.1.1) gives cp ρut dx − F − ∇ · (k∇u) dx = 0.
(2.2.8)
V
Equality (2.2.8) holds for every V included in B; therefore, if the integrand functions are continuous it follows cp ρut − ∇ · (k∇u) = F.
(2.2.9)
When k is constant, (2.2.9) simplifies in cp ρut − k∆u = F,
(2.2.10)
where ∆ = ∂ 2 /∂x21 + ∂ 2 /∂x22 + ∂ 2 /∂x23 is the Laplace operator. Lastly, by defining the thermal diffusivity α = k/cp ρ,
(2.2.11)
ut − α∆u = f, x ∈ B, 0 < t ≤ T,
(2.2.12)
we obtain the heat equation
where f = F/cp ρ. Solving partial differential equation (2.2.12) yields the unknown function u(x, t) which describes the temperature evolution in solids. Then, the heat flux q is determined by (2.1.1). However, the problem can be successfully solved only when the initial conditions and the boundary conditions are prescribed too. These will be discussed in the next section. If the thermal process depends on one variable, say x, then from (2.2.12) it follows the one-dimensional heat equation ut (x, t) − αuxx (x, t) = f (x, t), 0 < x < L, 0 < t ≤ T,
(2.2.13)
which is used in many applications. When there are no internal heat sources or sinks it is f = 0, and equations (2.2.12), (2.2.13) become homogeneous.
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Fourier model of heat conduction
2.3
wsdac04
13
Initial and boundary conditions
As already mentioned, the complete resolution of (2.2.12) requires the initial condition, which describes the initial temperature distribution in the solid u(x, 0) = ϕ(x), x ∈ B.
(2.3.1)
In particular, in the one-dimensional case u(x, 0) = ϕ(x), 0 < x < L.
(2.3.2)
In addition, in most applications further data are prescribed on the boundary ∂B: the boundary conditions, which we are going to examine. Boundary conditions of the first kind (conditions with given boundary temperature, or Dirichlet boundary conditions): u(x, t) = g(x, t), x ∈ ∂B.
(2.3.3)
In the one-dimensional case u(0, t) = g1 (t), u(L, t) = g2 (t).
(2.3.4)
Boundary conditions of the second kind (boundary conditions with prescribed heat flux, or Neumann boundary conditions, or derivative boundary conditions): k
∂u (x, t) = g(x, t), x ∈ ∂B, ∂n
(2.3.5)
where ∂/∂n denotes the derivative with respect to the outward normal to the boundary surface. In the one-dimensional case −kux (0, t) = g1 (t), kux (L, t) = g2 (t),
(2.3.6)
because at x = 0 the outward normal is opposed to x-direction. Boundary conditions of the third kind (Robin conditions): k
∂u (x, t) + hu(x, t) = g(x, t), x ∈ ∂B. ∂n
(2.3.7)
In the one-dimensional case −kux(0, t) + h1 u(0, t) = g1 (t), kux (L, t) + h2 u(0, t) = g2 (t).
(2.3.8)
July 3, 2004
23:17
14
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
Condition (2.3.7) models the physical situation of a solid dissipating heat through its bounding surface by convection, according to Newton’s law of cooling −k
∂u (x, t) = h[u(x, t) − us (x, t)], x ∈ ∂B, ∂n
(2.3.9)
where us denotes the known surroundings temperature and h is the heat transfer coefficient. Setting hus = g, (2.3.9) reduces to (2.3.7). When g = 0 in (2.3.3), or in (2.3.5), or in (2.3.7), the corresponding boundary condition of the first, second, or third kind is called homogeneous. Also, partial differential equation (2.2.12) is said to be homogeneous in the special case f = 0. Consider an initial-boundary-value problem, defined by (2.2.12), (2.3.1) and (2.3.3), or (2.3.5), or (2.3.7). This problem is referred to as homogeneous problem if both the equation and the boundary condition are homogeneous. Finally, let us mention the problem of solving the heat equation when only the initial data are prescribed, for example, in the one-dimensional case u(x, 0) = ϕ(x), x ∈ IR.
(2.3.10)
This question is very interesting from the mathematical point of view and it is often the first step for solving physical problems. 2.4
Phase-change problems
Some problems of physical interest are such that the boundary can move during the physical process. It cannot be prescribed a priori and represents a further unknown of the problem, to be determined together with the temperature. These problems are called free boundary value problems. The phase-change problems are typical examples where this occurs. Indeed, let us consider the melting process and refer to one-dimensional models, fig. 2.4.1, where the liquid and the solid phases are separated by a sharp interface of equation x = s(t).
(2.4.1)
Assume that there is no internal heat generation and the heat transfer in both phases is by conduction. Then, the temperature evolution in each
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Fourier model of heat conduction
Fig. 2.4.1
wsdac04
15
Phase-change problem
phase is governed by the equations u1t (x, t) = α1 u1xx (x, t), 0 < x < s(t), 0 < t ≤ T,
(2.4.2)
u2t (x, t) = α2 u2xx (x, t), s(t) < x < a, 0 < t ≤ T,
(2.4.3)
where the subscripts 1 and 2 characterize the liquid and the solid phase, respectively. Suitable initial and boundary conditions must be added to the last equations. In a melting process, it is quite reasonable that the boundary x = 0 is heated and the side x = a is kept at a prefixed temperature or insulated; therefore, examples of boundary conditions are u1 (0, t) = g1 (t) > um , 0 ≤ t ≤ T,
(2.4.4)
u2 (a, t) = g2 (t) = um , 0 ≤ t ≤ T,
(2.4.5)
where um denotes the melting temperature. The initial situations are characterized by the following conditions u1 (x, 0) = ϕ1 (x) ≥ um , 0 ≤ x ≤ s(0),
(2.4.6)
u2 (x, 0) = ϕ2 (x) ≤ um , s(0) ≤ x ≤ a.
(2.4.7)
Now, let us examine the liquid-solid interface. The hypothesis that the temperature varies continuously requires u1 (s(t), t) = u2 (s(t), t) = um , 0 ≤ t ≤ T.
(2.4.8)
A further equation is given by the energy balance. The mass of liquid converted from the solid times the latent heat L represents the heat absorbed.
July 3, 2004
23:17
16
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
This must equate the net amount of heat that flows ˙ 0 ≤ t ≤ T, Aq1 (s(t), t) − Aq2 (s(t), t) = AρLs(t),
(2.4.9)
where ρ is the liquid density and A the area of the section perpendicular to x-direction. Considering Fourier’s law (2.1.1), the last equation is rewritten as ˙ 0 ≤ t ≤ T, −k1 u1x (s(t), t) + k2 u2x (s(t), t) = ρLs(t),
(2.4.10)
called Stefan condition. A special case of the preceding problem is obtained when the temperature of the solid phase is constant during the whole melting process. This occurs, for example, if condition (2.4.7) is replaced by the following u2 (x, 0) = um , s(0) ≤ x ≤ a.
(2.4.11)
In such a case problem (2.4.3), (2.4.8), (2.4.11) has the trivial solution u2 (x, t) = um , s(t) ≤ x ≤ a, 0 ≤ t ≤ T,
(2.4.12)
which is also unique under quite general hypotheses on the function s(t). Therefore, we realize that the phase-change process is completely determined by the liquid phase evolution (one-phase Stefan problem). In this situation, only the equations for the liquid phase must be considered ut (x, t) = αuxx (x, t), 0 < x < s(t), 0 < t ≤ T,
(2.4.13)
u(x, 0) = ϕ(x) ≥ um , 0 ≤ x ≤ s(0),
(2.4.14)
u(0, t) = g(t) > um , 0 ≤ t ≤ T,
(2.4.15)
u(s(t), t) = um , 0 ≤ t ≤ T,
(2.4.16)
−kux (s(t), t) = ρLs(t), ˙ 0 ≤ t ≤ T,
(2.4.17)
where u is the liquid temperature. The last equation enables us to determine the unknown free boundary x = s(t) and the interface position. The other equations give the temperature evolution. The difficulty lies in the fact that both problems must be jointly solved.
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Fourier model of heat conduction
2.5
wsdac04
17
Heat conduction in a moving medium
When the thermal process occurs in a moving medium, the heat equation must be modified to consider the convective terms due to the motion. Consequently, if v = x˙ denotes the velocity of the generic particle x, the expression of the heat flux to substitute into (2.2.7) is given by [Carslaw and Jager (1959)] q = −k∇u + ρcp uv.
(2.5.1)
Now, the discussion proceeds as in Section 2.2. By assuming cp = constant, it follows ut +
3 i=1
uxi vi − α∆u = f,
(2.5.2)
which replaces (2.2.12) under the same hypotheses. In this situation the thermal process depends on the heat diffusion, but it is influenced by the heat convection too. For this reason (2.5.2) is called convection-diffusion equation. If the total derivative 3 3 d u(x(t), t) = ut + uxi x˙ i = ut + uxi vi , dt i=1 i=1
(2.5.3)
is introduced into (2.5.2), it follows du − α∆u = f. dt
(2.5.4)
It is obvious that, if the solid motion is known, then (2.5.2) and the initialboundary conditions are enough to determine the temperature evolution. Otherwise, the motion equations of the special system must be associated to (2.5.2). In the one-dimensional case (2.5.2) simplifies in ut + ux v − αuxx = f,
(2.5.5)
where v denotes the only non-vanishing velocity component. 2.6
Fick’s law and diffusion
Diffusion is the process by which the matter is transferred from one part to another in a system (fluid, gas). The phenomenon shows evident analogies with the heat propagation and it is modelled by similar equations. It is
July 3, 2004
23:17
18
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
based on the Fick’s law (1855), which follows from physical experiences showing that the diffusing matter moves from higher concentration regions towards lower concentration zones. Consequently, if q denotes the mass flux vector per unit area per unit time, the direction of q is opposite to that of increasing concentration. In other words, q is opposite to the gradient of the concentration C, defined by the mass per unit volume dissolving into the fluid system. For isotropic medium at rest, all this is summarized by the Fick’s law q = −D∇C,
(2.6.1)
where D is diffusion coefficient. In general, D depends on space, time and concentration too. Relation (2.6.1) is completed by the mass conservation principle, which states that the time rate of mass change in a volume V equates the mass flowing into V , if there is no internal mass production, Ct dx = − q · n dS, (2.6.2) V
∂V
where n denotes the exterior unit normal to the boundary ∂V at the integration point. Applying the Gauss divergence theorem to (2.6.2) gives [Ct + ∇ · q] dx = 0. (2.6.3) V
Hence, since V is arbitrary, Ct + ∇ · q = 0.
(2.6.4)
Now, insert (2.6.1) into (2.6.4) to obtain the diffusion equation Ct = ∇ · (D∇C),
(2.6.5)
which, for constant D, reduces to the heat equation Ct = D∆C.
(2.6.6)
For moving fluids, relationship (2.6.1) is replaced by q = −D∇C + Cv,
(2.6.7)
where v denotes the velocity of the generic particle. Under the same hypotheses as before, from (2.6.4) and (2.6.7) it follows Ct = D∆C − ∇ · (Cv),
(2.6.8)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Fourier model of heat conduction
Ct − D∆C + v · ∇C + C∇ · v = 0.
wsdac04
19
(2.6.9)
Further Reading: [Bellomo and Preziosi (1995)], [Cannon (1984)], [Crank (1979)], [Necati Ozisik (1993)], [Rubinstein (1971)].
July 3, 2004
23:17
20
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Chapter 3
An explicit method for the heat equation
This chapter deals with the classical explicit method for the onedimensional heat equation. This scheme has been widely experienced and applied. It is simple too. So, it seems to be the ideal candidate by which to start the theory of the finite-difference approximations to partial differential equations. Firstly, the heat equation is transformed into dimensionless form. Then, the finite-difference formulas developed in Chapter 1 are used to infer the quoted scheme. Its practical application is shown with reference to a problem with Dirichlet boundary conditions. In addition, the matrix form of the scheme is also introduced. This gives compactness to the numerical method and represents the starting point for further developments. The main questions, related to the correct use of finite-difference methods, are discussed in the following sections. The basic concepts of stability, convergence and consistency are plainly introduced and formalized. Examples are given to illustrate the theory. Approximations of boundary derivatives occur frequently, when the Neumann and Robin problems are considered. The related finite-difference techniques are presented in the last sections.
21
wsdac04
July 3, 2004
23:17
22
3.1
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
Non-dimensional form of the heat equation
Transforming equations to non-dimensional form is always convenient, because this gives them greater generality and reduces the number of variables. If the equations have to be integrated numerically, there is a further reason. Indeed, inessential numerical constants could yield unexpected rounding errors. Consider the following initial-boundary value problem uτ − αuξξ = f, 0 < ξ < L, 0 < τ ≤ τ ∗ ,
(3.1.1)
u(ξ, 0) = u0 (ξ), 0 ≤ ξ ≤ L,
(3.1.2)
−kuξ (0, τ ) + h1 u(0, τ ) = g1 (τ ), 0 ≤ τ ≤ τ ∗ ,
(3.1.3)
kuξ (L, τ ) + h2 u(L, τ ) = g2 (τ ), 0 ≤ τ ≤ τ ∗ .
(3.1.4)
Let us define the new unknown function and variables as follows U = u/u∗ , x = ξ/L, t = ατ /L2 ,
(3.1.5)
where u∗ represents a reference temperature and L is the solid length. Evidently, it is uξξ = Uxx u∗ /L2 , uτ = Ut u∗ α/L2 .
(3.1.6)
Using (3.1.6) in (3.1.1) yields Ut − Uxx = F, 0 < x < 1, 0 < t ≤ T (= τ ∗ α/L2 ),
(3.1.7)
where F = f L2 /u∗ α. Dimensionless process (3.1.5) produces effects on the initial-boundary conditions too. Indeed, it is U (x, 0) = u0 (Lx)/u∗ = U0 (x), 0 ≤ x ≤ 1,
(3.1.8)
−Ux (0, t) + H1 U (0, t) = G1 (t), 0 ≤ t ≤ T,
(3.1.9)
Ux (1, t) + H2 U (1, t) = G2 (t), 0 ≤ t ≤ T,
(3.1.10)
where Hi = Lhi /k, Gi (t) = gi (tL2 /α)L/ku∗ , i = 1, 2.
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
An explicit method for the heat equation
wsdac04
23
Finally, let us remark that other changes of variables can be considered, lightly different from (3.1.5). The choice always depends on the special boundary conditions involved in the problem. 3.2
The classical explicit method
Consider equation (3.1.7) and use the forward approximation for the time derivative Ut and the central approximation for Uxx . From definitions (1.2.3), (1.3.8) it follows ui+1,j − 2ui,j + ui−1,j ui,j+1 − ui,j − = fi,j , ∆t (∆x)2
(3.2.1)
fi,j = F (xi , tj ).
(3.2.2)
where
Note that the solution of finite-difference equation (3.2.1) has been denoted by u to avoid confusion with a solution U of partial differential equation (3.1.7). These notations will always be used in the following chapters. From (3.2.1) it follows ui,j+1 = r (ui+1,j + ui−1,j ) + (1 − 2r) ui,j + ∆tfi,j ,
(3.2.3)
where r = ∆t/∆x2 .
(3.2.4)
Formula (3.2.3) provides an explicit method to evaluate the solution, because the unknown values ui,j+1 can be found directly by those of ui,j , assumed to be available, fig. 3.2.1. Indeed, consider, for example, the
Fig. 3.2.1
Classical explicit scheme
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
24
following initial and boundary conditions for equation (3.1.7)
U (x, 0) = ϕ(x), 0 ≤ x ≤ 1, U (0, t) = g1 (t), U (1, t) = g2 (t), 0 < t ≤ T,
(3.2.5)
which are discretized as
ui,0 = ϕi , i = 0, ..., m, m∆x = 1, u0,j = (g1 )j , um,j = (g2 )j , j = 1, ..., n, n∆t = T,
(3.2.6)
where ϕi = ϕ(xi ), (g1 )j = g1 (tj ), (g2 )j = g2 (tj ). The starting values ui,j , i = 0, ..., m, j = 0 are given by (3.2.6)1 . Next, for every fixed j, the values ui,j+1 , i = 1, ..., m − 1, are computed by means of (3.2.3). Lastly, the values u0,j+1 , um,j+1 are provided explicitly by (3.2.6)2 . However, reliable results are guaranteed only when the method is stable with respect to data perturbations (errors) which inevitably arise during the computational process. Furthermore, the consistency of the finite-difference scheme, as well as the convergence, must be analyzed. All these questions will be discussed in the next sections.
3.3
Matrix form
Formula (3.2.3) can be organized in a more compact form, which will be used later. Indeed, by defining the column vector uj uTj = [u1,j ...um−1,j ] ,
(3.3.1)
and the (m − 1) × (m − 1) matrix A
1 − 2r r r 1 − 2r r · · · A= , · · · r 1 − 2r r r 1 − 2r
(3.3.2)
the following matrix form can be given to (3.2.3) uj+1 = Auj + bj ,
(3.3.3)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
An explicit method for the heat equation
wsdac04
25
where
ru0,j + ∆tf1,j ∆tf2,j . bj = · ∆tfm−2,j rum,j + ∆tfm−1,j This vector is a known term, if boundary conditions (3.2.6)2 have been prescribed.
3.4
Stability
A crucial test for a finite-difference equation is that related to its stability. A stable algorithm tries to vanish rather than to grow any error which is inevitably committed during the computational process. To better understand the problem, consider the classical explicit scheme with fi,j = 0 and simulate an arising round-off error, due, for example, to the computer. Let u be the exact solution of equation (3.2.3) of a special problem and suppose that an error e occurs at the grid point (h, k). It is obvious that the error propagates to the next rows. Its influence can be examined by considering the perturbed solution u∗i,j which coincides with ui,j when j < k and feels the mentioned error when j = k u∗i,j = ui,j , j < k; u∗i,k = ui,k , i = h; u∗h,k = uh,k + e.
(3.4.1)
It is more convenient to analyze the evolution of ei,j defined by ei,j = u∗i,j − ui,j .
(3.4.2)
Since the finite-difference operator is linear from (3.2.3) it follows ei,j+1 = (1 − 2r)ei,j + r(ei+1,j + ei−1,j ).
(3.4.3)
Using this expression we can investigate the error behavior for some values of r, defined by (3.2.4). When r = 1/2, formula (3.4.3) simplifies in ei,j+1 = (ei+1,j + ei−1,j )/2,
(3.4.4)
and the computed values are shown in fig. 3.4.1. Note a decreasing evolution of the error, which tends to damp out; this leads to guess that algorithm
July 3, 2004
23:17
26
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
Fig. 3.4.1
Error propagation: r = 1/2
(3.2.3) is stable in this case. Next, consider r = 2. Formula (3.4.3) becomes ei,j+1 = 2(ui+1,j + ui−1,j ) − 3ui,j ,
(3.4.5)
and the results are shown in fig. 3.4.2. The error grows and its sign oscillates. The solutions obtained in this way are unreliable because the error amplitude is out of control. The algorithm (3.2.3) is unstable when this second value of r is considered. To avoid this undesirable phenomenon,
Fig. 3.4.2
Error propagation: r = 2
restrictive actions must be adopted, such as limiting the mesh size. This is the task of the stability analysis. To formalize the concept, denote by u1 the solution of generic equation (3.5.3) related to an initial-boundary value problem and by u2 the solution of the same equation with the same boundary data, but with perturbed initial conditions. Furthermore, let u
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
An explicit method for the heat equation
wsdac04
27
be the difference u = u1 − u2 .
(3.4.6)
A finite-difference scheme is said to be unconditionally stable with respect to a prefixed norm if there exists a positive constant K, independent of ∆x, ∆t, ||u0 ||, such that ||uj || ≤ K||u0 ||, for j∆t ≤ T.
(3.4.7)
Remark 3.4.1 If (3.4.7) holds, but ∆t is functionally related to ∆x, the scheme is called conditionally stable, or simply, stable. This is just the case of the next example. Consider the classical explicit scheme (3.2.3), with Dirichlet boundary conditions (3.2.6). This scheme is stable under the hypothesis 0 < r = ∆t/∆x2 ≤ 1/2. Indeed, from (3.2.3) and (3.4.6) it follows ui,j+1 = r(ui+1,j + ui−1,j ) + (1 − 2r)ui,j , i ∈ I = 1, ..., m − 1, u0,j = um,j = 0,
(3.4.8)
(3.4.9)
and therefore, |ui,j+1 | ≤ r(|ui+1,j | + |ui−1,j |) + (1 − 2r)|ui,j |.
(3.4.10)
Hence, by using the sup-norm ||uj ||∞ = sup |ui,j |, i∈I
(3.4.11)
|ui,j+1 | ≤ ||uj ||∞ .
(3.4.12)
||uj+1 ||∞ || ≤ ||uj ||∞ ,
(3.4.13)
||uj+1 ||∞ || ≤ ||u0 ||∞ ,
(3.4.14)
it follows
Consequently,
proving the stability, as definition (3.4.7) is satisfied with K = 1.
July 3, 2004
23:17
28
3.5
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
Consistency
The analysis of the consistency gives a measure of the local error which arises when partial differential equation is approximated by the corresponding finite-difference equation. In order to formalize this concept, let us define the differential operator D = ∂t − ∂xx ,
(3.5.1)
so that heat equation (3.1.7) can be written more compactly as DU (x, t) = F (x, t).
(3.5.2)
Next, denote by Li,j the finite-difference operator on the left-hand side of (3.2.1), so that finite-difference equation (3.2.1) can be shortly written as Li,j u = fi,j .
(3.5.3)
For simplicity, notations (3.2.2) and (3.2.3) have been introduced with reference to (3.1.7) and (3.2.1), respectively, but it is clear that they can represent different equations. Let us define the truncation error of a finite-difference scheme at the grid point (i∆x, j∆t). With reference to a generic function v (test function), it is expressed by Ti,j v = Li,j v − fi,j − (Dv − F )i,j .
(3.5.4)
A suitable test function is the solution U of partial differential equation (3.5.2). Indeed, in such a case formula (3.5.4) simplifies in Ti,j U = Li,j U − fi,j ,
(3.5.5)
which is called local truncation error. Now, let us introduce the definition of consistency. A finite-difference scheme is said to be consistent with the approximating partial differential equation if Ti,j U goes to zero as the mesh is refined, that is, ∆x, ∆t → 0. In other words, a consistent scheme approximates the analyzed partial differential and not some other. Instead of consistent, the adjective compatible is also used to express the same concept. The classical explicit method (3.2.1), approximating the heat equation, fulfills such a definition. Indeed, applying Taylor’s series expansion gives Ui,j+1 = Ui,j + (Ut )i,j ∆t + (Utt )i,j
(∆t)2 + O((∆t)3 ), 2
(3.5.6)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
An explicit method for the heat equation
29
Ui,j+1 − Ui,j ∆t = (Ut )i,j + (Utt )i,j + O((∆t)2 ). ∆t 2
(3.5.7)
Similarly, from (1.1.2) it follows Ui+1,j = Ui,j + (Ux )i,j ∆x + (Uxx )i,j
+(Uxxxx )i,j
(∆x)4 (∆x)5 + (Uxxxxx)i,j + O((∆x)6 ), 4! 5!
Ui−1,j = Ui,j − (Ux )i,j ∆x + (Uxx )i,j
+(Uxxxx )i,j
(∆x)2 (∆x)3 + (Uxxx )i,j 2 6 (3.5.8)
(∆x)2 (∆x)3 − (Uxxx )i,j 2 6
(∆x)4 (∆x)5 − (Uxxxxx)i,j + O((∆x)6 ). 4! 5!
(3.5.9)
Hence, (∆x)2 Ui+1,j − 2Ui,j + Ui−1,j +O((∆x)4 ). (3.5.10) = (U ) +(U ) xx i,j xxxx i,j (∆x)2 12 Substituting (3.5.7), (3.5.10) into the expression of Li,j yields Li,j U − fi,j = (Utt )i,j
∆t (∆x)2 − (Uxxxx )i,j + O((∆t)2 + (∆x)4 ), (3.5.11) 2 12
where it has been considered that (Ut − Uxx )i,j = Fi,j = fi,j .
(3.5.12)
Therefore, the principal part of the truncation error is (Utt )i,j
∆t (∆x)2 − (Uxxxx )i,j , 2 12
(3.5.13)
and the explicit method is consistent with the heat equation. Evidently, Ti,j U = O((∆x)2 ) + O(∆t);
(3.5.14)
therefore, the method is accurate of order (2,1). Exercise 3.5.1
Under the hypothesis F = 0, show that Ti,j U = O((∆x)4 ) + O((∆t2 )),
when ∆t = ∆x2 /6.
(3.5.15)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
30
3.6
wsdac04
Convergence
In the last section we analyzed the error which arises when a differential equation is replaced by the approximating difference equation. In this section we discuss the concept of convergence which is related to the comparison of solutions. Denote by U the solution of an initial-boundary value problem for a partial differential equation and assume that the problem is well posed, that is, the solution exists and depends continuously on the data. Furthermore, let ui,j be the solution of the corresponding finite-difference problem. The difference E =U −u
(3.6.1)
of these two solutions, evaluated at the grid point (i, j), represents the discretization error at that point. Clearly, the convergence depends on E. A finite-difference scheme approximating an initial-boundary value problem is said to be convergent at time t if ||Ej || = ||Uj − uj || tends to zero as ∆x, ∆t → 0 and j∆t → t. Here, ||.|| means a suitable norm depending on the problem. When the finite-difference operator Li,j is linear, as the explicit heat operator (3.2.1), then Li,j E = Li,j U − Li,j u = Li,j U − fi,j .
(3.6.2)
Li,j E = Ti,j U.
(3.6.3)
Hence, by (3.2.1)
Considering (3.6.3) enables us to show that the solution of the finitedifference problem (3.2.1), (3.2.6) converges to the solution of the initialboundary value problem (3.1.7), (3.2.5), under the assumption (3.4.8). Indeed, note that (3.5.14) implies |Ti,j U | ≤ A(∆t + (∆x)2 ),
(3.6.4)
where A is the constant related to the symbol O. Then, in formula (3.6.3), use definition (3.2.1) of the operator Li,j to obtain Ei,j+1 = (1 − 2r)Ei,j + r(Ei+1,j + Ei−1,j ) + ∆tTi,j U,
(3.6.5)
where i ∈ I = {1, ..., m − 1}. Furthermore, Ei,0 = 0, i = 0, ..., m, E0,j = 0, Em,j = 0, j = 1, ..., n,
(3.6.6)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
An explicit method for the heat equation
wsdac04
31
because u and U satisfy the same initial and boundary conditions. From (3.6.4) and (3.6.5) it follows |Ei,j+1 | ≤ (1 − 2r)|Ei,j | + r(|Ei+1,j | + |Ei−1,j |) + ∆tA(∆t + (∆x)2 ), (3.6.7) where the hypothesis (3.4.8) has been employed. Hence, by using the supnorm defined by (3.4.11), we obtain |Ei,j+1 | ≤ ||Ej ||∞ + ∆tA(∆t + (∆x)2 ),
(3.6.8)
||Ej+1 ||∞ ≤ ||Ej ||∞ + ∆tA(∆t + (∆x)2 ).
(3.6.9)
||Ej ||∞ ≤ ||E0 ||∞ + j∆tA(∆t + (∆x)2 ).
(3.6.10)
This implies
Finally, considering that j∆t ≤ T , we have the estimate ||Ej ||∞ ≤ T A(∆t + (∆x)2 ),
(3.6.11)
which proves the convergence of the scheme in the sup-norm. Let us emphasize that the arguments, we have just used, are very similar to those developed to prove the stability; also, the hypothesis is exactly the same. Actually, the two concepts are strictly related by a remarkable result. This is Lax equivalence theorem: a consistent, two-level finitedifference method, corresponding to a well-posed linear initial-boundaryvalue problem, is stable if and only if it is convergent. The proof of this theorem can be found, for example, in [Morton and Mayers (2002); Thomas (1995)]. 3.7
Neumann boundary conditions
Consider one-dimensional heat equation (3.1.7) together with initial data (3.1.8) and the boundary conditions −Ux (0, t) = G1 (t), Ux (1, t) = G2 (t).
(3.7.1)
Then, consider the corresponding finite-difference problem. Equation (3.2.3) and discretized initial conditions (3.2.5)1 hold. Then, the conditions approximating (3.7.1) must be given. Use the central approximation for the partial derivatives to obtain −
u1,j − u−1,j = (g1 )j , 2∆x
(g1 )j = G1 (j∆t),
(3.7.2)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
32
um+1,j − um−1,j = (g2 )j , 2∆x
(g2 )j = G2 (j∆t).
(3.7.3)
The fictitious values u−1,j and um+1,j can be eliminated by means of equation (3.2.3). Indeed, under the assumption that the heat equation holds at the boundaries x = 0 and x = 1, from (3.2.3) we obtain u0,j+1 = (1 − 2r)u0,j + r(u1,j + u−1,j ) + ∆tf0,j ,
(3.7.4)
um,j+1 = (1 − 2r)um,j + r(um+1,j + um−1,j ) + ∆tfm,j ,
(3.7.5)
for i = 0 and i = m, respectively. From (3.7.2) and (3.7.4) it follows u0,j+1 = (1 − 2r)u0,j + 2r[u1,j + (g1 )j ∆x] + ∆tf0,j .
(3.7.6)
Similarly, um,j+1 = (1 − 2r)um,j + 2r[um−1,j + (g2 )j ∆x] + ∆tfm,j .
(3.7.7)
Then, the remaining values ui,j+1 , 0 < i < m, are evaluated by (3.2.3). The accuracy of formulas (3.7.6), (3.7.7) is of order O((∆x)2 ). Also in this case, the finite-difference equations can be arranged in matrix form. Indeed, define the column vector uj uTj = [u0,j ...um,j ] , the (m + 1) × (m + 1) matrix A 1 − 2r 2r r 1 − 2r r · · · A= , · · · r 1 − 2r r 2r 1 − 2r and the column vector of known terms 2r(g1 )j ∆x + ∆tf0,j ∆tf1,j . bj = · ∆tfm−1,j 2r(g2 )j ∆x + ∆tfm,j
(3.7.8)
(3.7.9)
(3.7.10)
It is easy to realize that (3.2.3), (3.7.6), (3.7.7) are equivalent to uj+1 = Auj + bj .
(3.7.11)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
An explicit method for the heat equation
wsdac04
33
Finally, we remark that boundary conditions (3.7.1) can be expressed by means of forward and backward approximations −
um,j − um−1,j u1,j − u0,j = (g1 )j , = (g2 )j . ∆x ∆x
(3.7.12)
However, these are less accurate than (3.7.6), (3.7.7), because they are O(∆x).
3.8
Boundary conditions of the third kind
Consider one-dimensional heat equation (3.1.7) together with initial data (3.1.8) and boundary conditions of the third kind −Ux (0, t) + H1 U (0, t) = G1 (t), Ux (1, t) + H2 U (0, t) = G2 (t),
(3.8.1)
where, with the notations of Section 3.1, Hi = Lhi /k, i = 1, 2.
(3.8.2)
As in the last section, using the central approximations gives −
u1,j − u−1,j + H1 u0,j = (g1 )j , 2∆x
um+1,j − um−1,j + H2 um,j = (g2 )j , 2∆x
(g1 )j = G1 (j∆t),
(g2 )j = G2 (j∆t).
(3.8.3)
(3.8.4)
The fictitious values u−1,j and um+1,j can be eliminated by equations (3.7.4), (3.7.5), exactly as in the last section. It results u0,j+1 = [1 − 2r(1 + H1 ∆x)]u0,j + 2r[u1,j + ∆x(g1 )j ] + ∆tf0,j ,
(3.8.5)
um,j+1 = [1 − 2r(1 + H2 ∆x)]um,j + 2r[um−1,j + ∆x(g2 )j ] + ∆tfm,j . (3.8.6) Also, the finite-difference problem can be arranged in matrix form uj+1 = Auj + bj ,
(3.8.7)
July 3, 2004
23:17
34
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
where A is the (m + 1) × (m + 1) 1 − 2r(1 + H1 ∆x) 2r r 1 − 2r · A=
matrix
r · · (3.8.8) · · · r 1 − 2r r 2r 1 − 2r(1 + H2 ∆x)
and uj , bj are defined by (3.7.8), (3.7.10), respectively. Finally, note that forward and backward approximations can also be applied −
um,j − um−1,j u1,j − u0,j + H1 u0,j = (g1 )j , + H2 um,j = (g2 )j . (3.8.9) ∆x ∆x
Further Reading: [Ames (1992)], [Bellomo and Preziosi (1995)], [Collatz (1966)], [Crank (1979)], [DuChateau and Zachmann (1989)], [Lapidus and Pinter (1982)], [Mitchell and Griffiths (1995)], [Morton (1996)], [Morton and Mayers (2002)], [Necati Ozisik (1994)], [Richtmyer and Morton (1967)], [Smith (1985)], [Thomas (1995)].
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Chapter 4
A Windows program
Today complex problems arising in science and in engineering are often solved by computers. Many applications find successful answer by means of powerful packages for computing mathematics. However, many other problems would benefit greatly from using modern programming languages, as C++. This language has recently received increasing attention in numerical applications, as in any other field. In this chapter the Visual++ 1 compiler is used to produce a Windows 2 program for the one-dimensional heat equation. The interested Reader can consult the suggested textbooks to learn more about the quoted compiler, although most of them are not specifically intended for scientific applications. Here, the numerical programs are developed essentially by proceeding by examples, rather than formal definitions.
1 Visual
C++ is a registered trademark of Microsoft Corporation is a registered trademark of Microsoft Corporation
2 Windows
35
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
36
4.1
Introduction
In this chapter a program is developed in C++ language by using the VisualC++ 3 compiler, which is one of the most valid tools. Sufficient information will be provided, so that even the Reader who is not familiar with this tool can work with it. However, it must be outlined that what follows cannot be considered an introduction to the compiler. This task is perfectly handled by several textbooks, for examples, [Bates and Tomkins (1998); Buzzi Ferraris (2000); Chapman (1998); Gregory (1997); Kruglinski, Sheperd and Wingo (1998)], which the interested Reader can consult for detailed expositions. The program deals with the following problem Ut − αUxx = 0, 0 < x < L, 0 < t ≤ T,
(4.1.1)
U (x, 0) = ϕ(x), 0 ≤ x ≤ L,
(4.1.2)
U (0, t) = g1 (t), U (L, t) = g2 (t), 0 < t ≤ T,
(4.1.3)
which, as seen in Chapter 2, models the heat conduction in one-dimensional solids when the initial and the boundary temperatures are given. Considering the explicit method leads to the difference equation ui,j+1 = (1 − 2r)ui,j + r(ui+1,j + ui−1,j ),
(4.1.4)
r = α∆t/∆x2 ,
(4.1.5)
where
and i = 1, ..., nx − 1, j = 0, ..., nt − 1, nx = L/∆x, nt = T /∆t.
(4.1.6)
Furthermore, the discrete version of conditions (4.1.2), (4.1.3) is the following
3 Visual
ui,0 = ϕi , i = 0, ..., nx , (ϕi = ϕ(i∆x)),
(4.1.7)
u0,j = (g1 )j , unx ,j = (g2 )j , j = 1, ..., nt .
(4.1.8)
C++ is a registered trademark of Microsoft Corporation
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
A Windows program
wsdac04
37
The numerical problem (4.1.4)-(4.1.8) is conditionally stable and the stability condition is given by r ≤ 1/2.
(4.1.9)
In object-oriented programming of numerical problems, generally, the object is just the numerical problem and a suitable class is developed for the specific problem. Since we shall use the Document and View classes, provided by the compiler, there is no need to define the new class. In the following sections we shall develop a program which is able to receive data, to compute the solution, to print numerical results and to plot the functions.
4.2
Creating a new project
At first, create a new project. Select New from the File menu. The New dialog box should appear. Click the Project tab to display the list of applications; select MFCAppWizard(exe) to create a Windows executable program; enter C:\Projects\ as Location; in the Project Name box specify the name by entering Heat1; click OK to move to MFCAppWizard Step1 dialog box. Step 1 of 6. Select Single document radio button. The language can be selected too. Click Next. Step 2 of 6. No modification; click Next. Step 3 of 6. Uncheck ActiveX Controls check box and click Next. Step 4 of 6. Uncheck Docking toolbar check box. Uncheck Printing and print preview check box. Uncheck 3D control check box. Click the Advanced button; in the Advanced Options dialog box enter htf as File extension and click Close. Click Next. Step 5 of 6. Select the As a statically linked library radio button and click Next. Step 6 of 6. Select CScrollView from the Base class box and click Finish. The New Project Information box appears to confirm the details of the project; click OK. The new project should be created. After creating the project, the workspace pane shows three tabs: ResourceView, ClassView, FileView, which enable the user to reach any part of the project. Open the file MainFrm.cpp and find the function PreCre-
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
38
ateWindow(CREATESTRUCT& cs). This has to be modified as follows to fix
position and dimensions of the main window of the program we are going to produce. Listing 4.2.1 BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { if( !CFrameWnd::PreCreateWindow(cs) ) return FALSE; cs.x=0; cs.y=0; .................................................... cs.cx=740; cs.cy=520; ............................................. return TRUE; }
[1] [2]
[1] Co-ordinates of the upper left vertex. [2] Co-ordinates of the lower right vertex. Open the il file Heat1View.h and, just before the class definition, add the following lines Listing 4.2.2 #define V1 1 #define V2 371 #define D 5
In the same file, before the line // Generate message ..., declare a new function and two variables of integer type. Listing 4.2.3 protected: void GraphResults(CDC* pDC); ...................................... int m xDocSize,m yDocSize;
[1]
[1] Usually, the name of a member variable starts by m , so that it is quite distinct from a variable declared inside a function. Open the file Heat1View.cpp and initialize the integer variables in the constructor Listing 4.2.4 CHeat1View::CHeat1View() { m xDocSize=100; m yDocSize=100; }
Now, the pen for drawing and the font for the text are necessary. The related instructions have to be added in the OnDraw(CDC* pDC) function,
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
A Windows program
wsdac04
39
whose skeleton was supplied by default. Find this function in the same file and modify it as follows. Listing 4.2.5 void CHeat1View::OnDraw(CDC* pDC) { CHeat1Doc* pDoc = GetDocument(); ASSERT VALID(pDoc); ............................ pDC->SetMapMode(MM LOENGLISH); ............................... CPen pen(PS SOLID, 1, RGB(0,0,0)); CPen* oldPen= pDC->SelectObject(&pen); . . . . . . . . . . . . . . . . . . . . . . . . . . CFont font; font.CreatePointFont(90,”Times”,pDC); ............................. CFont* oldFont=pDC->SelectObject(&font); ........................ GraphResults(pDC); CSize docSize(m xDocSize,m yDocSize); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . SetScrollSizes(MM LOENGLISH,docSize); pDC->SelectObject(oldPen); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . pDC->SelectObject(oldFont); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . }
[1] [2] [3] [4] [5] [6] [7] [7]
[1] Metric mapping mode where the x-axis is directed towards right and the y-axis upwards. [2] Pen with a width of one pixel drawing solid lines of black color. [3] The old pen is saved in order to restore it later. [4] A nine-point Times font is created (the specified point size is in 1/10 of a point). [5] The old font is stored. [6] Document dimensions to pass to the scroll device. [7] The old pen and the old font are restored. Lastly, a first line of code is inserted in the following function. Listing 4.2.6 void CHeat1View::GraphResults(CDC* pDC) { pDC->Rectangle(V1,-V1,V2,-V2); ................................... }
[1]
[1] The first two values are the co-ordinates of the upper left vertex of the rectangle to draw, and the last two are the co-ordinates of the lower right vertex. Compile and execute. The rectangle with the specified vertices is drawn.
July 3, 2004
23:17
40
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
Next, the temperature function will be plotted in this rectangle.
4.3
Equation data
Entering and saving data is a task of the Document class. In a Window program the data are entered by dialog boxes, activated by a menu. Therefore, it is necessary to give a main menu to the program. The compiler supplies a default menu which can be modified to insert new menu headers. In this section we shall add the menu header and the item to activate the dialog box of the equation data. Here is the procedure to follow. 1. Select ResourceView from the workspace pane, expand the Menu item and double-click IDR MAINFRAME to obtain the default menu. 2. Press Alt+Enter to display the Properties box and keep it visible by clicking the pin button. 3. The initial menu already possesses some headers. Also there is the candidate to the new header represented by a blank rectangle. Use the mouse to drag and drop it between View and Help. In the Menu Item Properties box enter Data as Caption. 4. Below the Data header a blank rectangle should appear, ready to become the new item. Click it and enter Equation as Caption. By clicking a different item and then going back to the Equation header, a default resource ID should appear based on item and header names: ID DATA EQUATION. When the Equation item is selected the program sends a message to the handler function to execute the code associated with the item. Until an appropriate item handler is added, the item will be disabled. The handler function will be introduced in the next step. 5. In the View menu Select ClassWizard to display the MFC ClassWizard box. Here, click the Message Maps tab, select CHeat1Doc in the Class name box, select ID DATA EQUATION in the Object IDs box, select COMMAND in the Messages box, click Add Function. In the next Add Member Function box click OK to agree with the name OnDataEquation which is suggested for the new function. By clicking the Edit Code button, the compiler closes ClassWizard and edits the skeleton of the new function that should be implemented. This will be done later. Indeed, at first it is necessary to organize the dialog window to enter the equation data: diffusivity coefficient α, length L of the one-dimensional solid, time interval [0, T ] of the thermal process and, in addition, the num-
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
A Windows program
wsdac04
41
bers nx, nt for the mesh dimensions. The visual elements of a program, as
Fig. 4.3.1
Initial and final look of the dialog window
dialog boxes, are called resources. Creating a dialog resource by the Visual compiler is not a difficult task. 1. Select Resource from the Insert menu; in the next Insert Resource box double-click Dialog to display the dialog box template, fig. 4.3.1. This can be modified as it needs. 2. By Alt+Enter display the Properties box. Here, replace IDD DIALOG1 by IDD EDATA and enter Equation Data as Caption. 3. Enlarge suitably the dialog template and use the mouse to drag the OK and Cancel buttons supplied by default, fig. 4.3.1. 4. On the Controls toolbox select the Static Text box. Move the mouse over the dialog box; note that the cursor will change to a cross; position the cross in the upper left corner of the dialog template and click. The small rectangle of static text should appear. As Caption enter the following string U t = alpha U xx, 0 < x < L, 0 < t < T , fig. 4.3.1. 5. Apply the same procedure to obtain: Alpha=, T=, L=, Nx=, Nt=, fig. 4.3.1. 6. On the Controls toolbox select Edit Box, move the mouse to the right of “alpha=” and click to obtain an edit box control; adjust suitably the size of the box, fig. 4.3.1; in the Properties box replace IDC EDIT1 by IDC AL. 7. Similarly, move other four Edit Box controls to the right of “T=”, “L”, “Nx=”, “Nt=”, respectively. Replace their IDCs by IDC TM, IDC XM, IDC NX and IDC NT, respectively.
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
42
This completes the resource, fig. 4.3.1. Now, create the class to handle the dialog box’s functionality. Activate ClassWizard to display the Adding a Class dialog box. The creation of a new class is suggested; accept by clicking OK. The New Class dialog box appears; enter CEdata in the Name box and click OK. In MFC ClassWizard select the Member Variables tab to declare the variables; double-click IDC AL to obtain the Add Member Variable box; here, in Member variable box name enter m al, and select double in Variable type box; click OK. Apply the same procedure to: IDC NT, Member variable name: m nt, Variable type: int, IDC NX, Member variable name: m nx, Variable type: int, IDC TM, Member variable name: m tM, Variable type: double, IDC XM, Member variable name: m xM, Variable type: double. Click OK to close the MFC ClassWizard box. Lastly, in the Heat1Doc.cpp file insert the code line #include “Edata.h”
just after the other including instructions, so that this file can be seen. Compile. Now, let us introduce the variables to save the data entered by the dialog box. Open the Heat1doc.h file and, just before the line // Generate message ..., declare some new variables together with the handler functions. Listing 4.3.1 protected: int m control, m nx, m nt; double m time, m alpha, m length; public: double GetTime() {return m time;}; double GetAlpha() {return m alpha;}; double GetLength() {return m length;}; int GetNx(){return m nx;}; int GetNt(){return m nt;}; int GetControl(){return m control;};
Then, open the Heat1doc.cpp file and initialize the new variables in the following function. Listing 4.3.2 BOOL CHeat1Doc::OnNewDocument() { if (!CDocument::OnNewDocument()) return FALSE; m alpha=1.0; m time=1.0; m length=1.0;
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
A Windows program
wsdac04
43
m nx=20; m nt=20; m control=0; return TRUE; }
In addition, add the code to store and to restor these variables when the Save and the Open items, respectively, are clicked. Listing 4.3.3 void CHeat1Doc::Serialize(CArchive& ar) { if (ar.IsStoring()) { ar<< m control <<m alpha <<m time <<m length <<m nx <<m nt; } else { ar>> m control >>m alpha >>m time >>m length >>m nx >>m nt; } }
Implement the function invoked when the Equation item is clicked. Listing 4.3.4 void CHeat1Doc::OnDataEquation() { CEdata edata; ............................................. edata.m xM=m length; edata.m nx=m nx; edata.m nt=m nt; edata.m al=m alpha; edata.m tM=m time; if (edata.DoModal()==IDOK) { .......................................... m length=edata.m xM; m nx=edata.m nx; m nt=edata.m nt; m alpha=edata.m al; m time=edata.m tM; m control=11; // add new code here SetModifiedFlag(); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . UpdateAllViews(NULL); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . } }
[1]
[2]
[3] [3]
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
44
[1] The data of dialog box are initialized. [2] The data entered by the user are saved. [3] The modification flag is set and the function updating the view is invoked. This function causes the view to be redrawn. Note that the data m nx and m nt, or at least one of them, can be entered only as suggested values. Indeed, they determine the mesh dimensions dx, dt, which must satisfy the stability condition αdt/(dx)2 ≤ 0.5,
(4.3.1)
dt = T /nt, dx = L/nx.
(4.3.2)
where
If the entered values do not satisfy (4.3.1), the program modifies m nt according to (4.3.1), without changing m nx. This task is handled by the following function, declared in the class definition, in the Heat1doc.h file, public: void Stability();
and implemented in the Heat1Doc.cpp file. Listing 4.3.5 void CHeat1Doc::Stability() { double dx=m length/m nx; double dt=m time/m nt; if (m alpha*dt/(dx*dx)> .5) { do { m nt = m nt+1; dt=m time/m nt; }while (m alpha*dt/(dx*dx) > .5); } }
This function is invoked by the void CHeat1Doc::OnDataEquation() function. Therefore, replace the line // add new code here
by the instruction Stability();
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
A Windows program
wsdac04
45
Then, enter the code necessary to print the equation data. Open the Heat1 View.cpp file and modify the following function. Listing 4.3.6 void CHeat1View::GraphResults(CDC* pDC) { CHeat1Doc* pDoc = GetDocument(); ASSERT VALID(pDoc); CString str=””; int controlv=pDoc->GetControl(), nx=pDoc->GetNx(), nt=pDoc->GetNt(); double alpha=pDoc->GetAlpha(), xM=pDoc->GetLength(); double tM=pDoc->GetTime(), dx=xM/nx, dt=tM/nt, r=alpha*dt/(dx*dx); pDC->Rectangle(V1,-V1,V2,-V2); if (controlv >0) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . [1] { str.Format(”Ut = alpha Uxx; alpha = %g”,alpha); pDC->TextOut(V2+D, -10, str); str.Format(”T = %g”,tM); pDC->TextOut(V2+D, -30, str); str.Format(”L = %g”, xM); pDC->TextOut(V2+D, -50, str); str.Format(”nx = %d”, nx); pDC->TextOut(V2+D, -70, str); str.Format(”nt = %d”,nt); pDC->TextOut(V2+D, -90, str); str.Format(”dx = %lf”,dx); pDC->TextOut(V2+D, -110, str); str.Format(”dt = %lf”,dt); pDC->TextOut(V2+D, -130, str); str.Format(”r = %lf”,r); pDC->TextOut(V2+D, -150, str); } }
[1] If the equation data have been correctly entered, they are shown. Compile and test the dialog box. In particular, by modifying the nx, nt data, verify that suitable values of r are shown, all compatible with the stability condition.
4.4
Initial data
Initial data are entered by a related dialog window, which will be developed in this section. At first, it is necessary to modify the main menu. Following
July 3, 2004
23:17
46
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
the same procedure used for the Equation item, add the Initial item immediately below the Equation item. Automatically, the compiler assigns its resource ID, ID DATA INITIAL, to this new item. Then, we introduce the function which handles the command when the item is clicked. 1. Activate ClassWizard. 2. In MFCClass Wizard box click Message Maps and select CHeat1Doc from Class name box. 3. Select ID DATA INITIAL from Object IDs box and COMMAND from Messages box. 4. Click Add Function to display the Add Member Function box. Here, click OK to agree with the suggested name for the new function: OnDataInitial. Click the Edit Code button to close ClassWizard. The compiler displays the skeleton of the new function, that will be implemented later. Indeed, at first we want to organize a new resource: the dialog window of the initial data. Its final look is shown in fig. 4.4.1. The same resource will also be used for the boundary conditions.
Fig. 4.4.1
Dialog window of the initial and boundary data
1. As already done in the last section, display the dialog template, fig. 4.3.1. 2. Display the Properties box and replace IDD DIALOG1 by IDD IBDATA. As Caption enter Initial and boundary data, fig. 4.4.1. 3. Select Edit Box on the Controls toolbox. Move the mouse to upper left corner of the dialog template and click to obtain a new edit box control. Re-size suitably the blank box. In the Properties box replace IDC EDIT1
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
A Windows program
wsdac04
47
by IDC IBD. Click the Styles tab and, then, check Read-only and uncheck Border, fig. 4.4.1. 4. Select Static Text on the Controls toolbox, move the mouse below the last edit box control, and click to obtain the Static Text box. As Caption enter Check if the function is, fig. 4.4.1. 5. Select Check Box, move the mouse to the right of the Static Text box and click. As caption enter constant. Replace IDC CHECK1 by IDC CONSTANT, fig. 4.4.1. 6. Select Edit Box, move the mouse to the next line and click. Replace IDC EDIT2 by IDC FUNCTION. Click the Styles tab and check Read-only and uncheck Border, fig. 4.4.1. 7. Select Edit Box and create a new edit box to the right of the previous one. Replace IDC EDIT3 by IDC FVALUE, fig. 4.4.1. 8. Select Static Text, move the mouse to the next line and click to display a new static text box. As Caption enter Data no.. Create a new Edit Box to the right of the Static Text box. Replace IDC EDIT4 by IDC DATAN. Click the Styles tab, check Read-only and uncheck Border, fig. 4.4.1. The dialog window is ready. It needs a new class. 9. Activate ClassWizard. In Adding a Class box accept to create a new class. In New Class box enter CIbdata as Name and click OK. 10. In MFC ClassWizard box select Member Variables. Double-click IDC CONSTANT. Declare the first variable: m constant of BOOL type. 11. Similarly, the other variables are declared: m datan of int type, and m function, m fvalue, m ibd, all of CString type. The class is complete. It only remains to insert the code line #include “Ibdata.h” in the Heat1Doc.cpp file. Compile.
Finally, add the array to store the data entered by the user. In the Heat1doc.h file, declare a new variable and the handler function as follows. Listing 4.4.1 protected: CStringArray m u0; public: CString GetU0(int i) {if (i< m u0.GetSize()) return m u0.GetAt(i); else return ””; };
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
48
The array is initialized in the BOOL CHeat1Doc::OnNewDocument() function m u0.SetSize(1);m u0.SetAt(0,”0”);
Furthermore, implement the function, which handles the message when the Initial item is clicked. Listing 4.4.2 void CHeat1Doc::OnDataInitial() { CIbdata ibdata; double dx=m length/m nx; ........................................ ibdata.m ibd=”Initial data”; ibdata.m constant=0; ibdata.m datan=1; ibdata.m fvalue=m u0.GetAt(0); ibdata.m function=”u(0,0)=”; if (ibdata.DoModal()==IDOK) { .................................. m u0.SetAt(0,ibdata.m fvalue); BOOL test=ibdata.m constant; CString str=””; for (int i=1; i< m nx+1; i++) { ............... if (m u0.GetSize()==i) m u0.SetAtGrow(i,”0”); if (test==0) ................................................. { ibdata.m constant=0; ...................................... ibdata.m datan + +; str.Format(”u(%g,0)=”,i*dx); ibdata.m function=str; ............................ ibdata.m fvalue=m u0.GetAt(i); ibdata.DoModal(); } ................................ m u0.SetAt(i,ibdata.m fvalue); } m control=12; } }
[1]
[2]
[3] [4]
[5]
[6]
[7]
[1] The data in the dialog box are initialized. [2] The first entered value is stored. [3] The initial dimension of the array is 1; therefore, the first time the item is activated, the array dimension has to grow together with the number of data. On the contrary, the dimension will not increase when the same item
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
A Windows program
wsdac04
49
is re-activated, for example, to verify or to modify the entered values. [4] If the initial condition is not constant, the dialog box is called again to enter other data. [5] The data number is updated. [6] The value of the initial condition, displayed the first time in the dialog box, is the initialization value. Next, it is updated by the last entered value. [7] The value entered by the user is stored in the array. Note that the initial and boundary data depend on the numbers m nx, m nt. Therefore, these must not be modified by the user any more. The objective is obtained by disabling the related item. The procedure is the following. 1. Activate ClassWizard and, in the MFCClass Wizard box, select the Message Maps tab. 2. In the Class name combo box select CHeat1Doc, in the ObjectIDs list box select ID DATA EQUATION and in the Messages list box select UPDATE COMMAND UI. 3. Click the Add Function button and in the Add Member Function dialog box click OK to agree with the suggested name for the new function: OnUpdateDataEquation. Click the Edit Code button to close ClassWizard and to edit the skeleton of the new function. Its implementation is shown in following listing. Listing 4.4.3 void CHeat1Doc::OnUpdateDataEquation(CCmdUI* pCmdUI) { ....................... if (m control< 12) pCmdUI->Enable(TRUE); else pCmdUI->Enable(FALSE); ..................................... }
[1] [2]
[1] If the initial data have not yet added, the Equation item is enabled, so that the equation data can be entered. [2] After entering the initial data, the Equation item is disabled. A similar problem arises for the Initial item, which is to be enabled only after entering the equation data. Apply the last procedure to ID DATA INITIAL to obtain the new function: OnUpdateDataINITIAL. Implement the new function as follows. Listing 4.4.4
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
50
void CHeat1Doc::OnUpdateDataInitial(CCmdUI* pCmdUI) { if (m control==0) pCmdUI->Enable(FALSE); else pCmdUI->Enable(TRUE); }
The code for saving/loading the initial conditions will be described at the end of the next section. Compile and test.
4.5
Boundary data
The code for the boundary data is very similar to that of the initial data. Use the procedure, described in the last sections, to modify the menu and add two new menu items: Boundary1, Boundary2, immediately below the Initial item. Note that the compiler automatically supplies the corresponding resource IDs: ID DATA BOUNDARY1, ID DATA BOUNDARY2, respectively. Then, we introduce the functions which handle the command when the new items are activated and, also, the functions that can enable/disable the above items. 1. Activate ClassWizard and, in the MFCClass Wizard box, select the Message Maps tab. 2. In the Class name combo box select CHeat1Doc, in the ObjectIDs list box select ID DATA BOUNDARY1 and in Messages list box select COMMAND. 3. Click the Add Function button and, in the Add Member Function dialog box, click OK to agree with the name suggested for the new function: OnDataBoundary1. 4. Next, select UPDATE COMMAND UI in Messages list box, click Add Function and accept the name: OnUpdateDataBoundary1. 5. Repeat the same steps with reference to ID DATA BOUNDARY2. Click the Edit Code button to close ClassWizard and to edit the skeleton of the new functions, which will be implemented later. Indeed, at first it is necessary to declare the arrays, which will store the boundary data, and the related handler functions. Open the CHeat1Doc.h file and add the following code. Listing 4.5.1 protected:
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
A Windows program
wsdac04
51
CStringArray m g1, m g2; public: CString GetG1(int j) {if (j< m g1.GetSize()) return m g1.GetAt(j); else return ””; }; CString GetG2(int j) {if (j< m g2.GetSize()) return m g2.GetAt(j); else return ””; };
In addition, initialize the arrays in the BOOL CHeat1Doc::OnNewDocument() function m g1.SetSize(2); m g1.SetAt(0,”0”); m g1.SetAt(1,”0”); m g2.SetSize(2); m g2.SetAt(0,”0”); m g2.SetAt(1,”0”);
Next, implement the void CHeat1Doc::OnDataBoundary1() function as follows. Listing 4.5.2 void CHeat1Doc::OnDataBoundary1() { CString str=””; double dt=m time/m nt; CIbdata ibdata; ibdata.m ibd=”Boundary data at x = 0”; ibdata.m constant=0; ibdata.m datan= 1; ibdata.m fvalue=m g1.GetAt(1); str.Format(”u(0,%g)=”,dt); ibdata.m function=str; if (ibdata.DoModal()==IDOK) { m g1.SetAt(1,ibdata.m fvalue); BOOL test=ibdata.m constant; for (int j=2; j< m nt+1; j++) { if (m g1.GetSize()==j) m g1.SetAtGrow(j,”0”); if (test==0) { ibdata.m constant=0; ibdata.m datan + +; str.Format(”u(0,%g)=”,j*dt); ibdata.m function=str; ibdata.m fvalue=m g1.GetAt(j); ibdata.DoModal(); } m g1.SetAt(j,ibdata.m fvalue); } m control=12;
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
52
} }
The second function void CHeat1Doc::OnDataBoundary2() is easily implemented, as it is obtained from the first one by replacing g1 by g2 everywhere, and, in addition, replace 1. the code line ibdata.m ibd=”Boundary data at x = 0”;
by str.Format(”Boundary data at x = %g”,m length); ibdata.m ibd=str;
2. the code line str.Format(”u(0,%g)=”,dt);
by str.Format(”u(%g, %g) = ”,m length, dt);
3. the code line str.Format(”u(0,%g)=”,j*dt);
by str.Format(”u(%g,%g) = ”,m length,j*dt);
Lastly, copy the code of the OnUpdateDataInitial function in the two functions OnUpdateDataBoundry1 and OnUpdateDataBoundary1. Now, we can add the code to save and to restore the initial and boundary data. To this end it is necessary to modify the following function. Listing 4.5.3 void CHeat1Doc::Serialize(CArchive& ar) { CString str=””; int i=0, size=1; if (ar.IsStoring()) { ar<< m control << m alpha << m time << m length << m nx << m nt; size=m u0.GetSize(); ar<<size; for (i=0; i<size;i++) { str=m u0.GetAt(i); ar<<str; } size=m g1.GetSize(); ar<<size;
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
A Windows program
wsdac04
53
for (i=0; i<size;i++) { str=m g1.GetAt(i); ar<<str; } size=m g2.GetSize(); ar<<size; for (i=0; i<size;i++) { str=m g2.GetAt(i); ar<<str; }
} else { ar>>m control >> m alpha >> m time >> m length >> m nx >> m nt; ar>>size; for (i=0; i<size;i++) { ar>>str; m u0.SetAtGrow(i,str); } ar>>size; for (i=0; i<size;i++) { ar>>str; m g1.SetAtGrow(i,str); } ar>>size; for (i=0; i<size;i++) { ar>>str; m g2.SetAtGrow(i,str); } } }
Compile and test. Now, one more menu header is added: Results, with two menu items: Graphical and Numerical. 1. Select the Resources View tab, expand the Menu item, and then, doubleclick IDR MAINFRAME. The menu resource should appear. 2. By Alt+Enter activate the Property box and keep it visible by clicking the pin button.
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
54
3. By the mouse drag the blank rectangle between Data and Help. In the Property box enter Results as Caption. 4. Below the Results header a blank rectangle appears, ready to become the new item. Click it and write Graphical as Caption. The compiler provides its resource ID: ID RESULTS GRAPHICAL. 5. Apply Step 4 to obtain Numerical, whose ID should be ID RESULTS NUMERICAL. 6. Activate ClassWizard to declare the functions which handle the command when the new item is clicked. 7. Select the Message Maps tab, select CHeat1Doc in the Class name combo box, select ID RESULTS GRAPHICAL in the ObjectIDs list box. 8. Select COMMAND in the Messages list box, click the Add Function button and, in the Add Member Function dialog box, click OK to agree with the name: OnResultsGraphical. Same steps for UPDATE COMMAND UI to create the new function: OnUpdateResultsGraphical. 9. Repeat all the steps with reference to ID RESULTS NUMERICAL. Clicking the Edit Code button closes ClassWizard and edits the skeleton of the new functions. The code of the first two is the following. Listing 4.5.4 void CHeat1Doc::OnUpdateResultsGraphical(CCmdUI* pCmdUI) { if (m u0.GetSize()>1 && m g1.GetSize()>2 && m g2.GetSize()>2) pCmdUI->Enable(TRUE); ................................. else pCmdUI->Enable(FALSE); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . } void CHeat1Doc::OnResultsGraphical() { m control=21; SetModifiedFlag(); ................................................. UpdateAllViews(NULL); ............................................ }
[1] [2]
[3] [3]
[1] If the dimensions of the initial and boundary arrays are greater than those of initialization, the data have been successfully entered. Therefore, the Graphical item must be enabled. [2] Otherwise, the same item is disabled. [3] The view is updated.
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
A Windows program
wsdac04
55
The same code, with m control=21; replaced by m control=22;, must be added in the other two functions. Compile.
4.6
Numerical results
The View class is implemented in this section. This is even more interesting from the numerical point of view. Open the Heat1View.h file and declare five functions and one variable. Listing 4.6.1 protected: double InitD(int i); double BoundD1(int j); double BoundD2(int j); void FiniteDifference(int j, double r, double u[], int n); void NumResults(CDC* pDC); int m jj;
The variable is initialized in the constructor CHeat1View::CHeat1View(), in the CHeat1View.cpp file: m jj=0;
Then, implement the following function. Listing 4.6.2 double CHeat1View:: InitD(int i) { CHeat1Doc* pDoc = GetDocument(); ASSERT VALID(pDoc); return atof(pDoc->GetU0(i)); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . }
[1]
[1] The function returns the ith value of the initial data, after having transformed it into a double type. Similar code is written in the functions related to the boundary data. Listing 4.6.3 double CHeat1View:: BoundD1(int j) { CHeat1Doc* pDoc = GetDocument(); ASSERT VALID(pDoc); return atof(pDoc->GetG1(j)); } double CHeat1View:: BoundD2(int j)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
56
{ CHeat1Doc* pDoc = GetDocument(); ASSERT VALID(pDoc); return atof(pDoc->GetG2(j)); }
Now, let us implement the function FiniteDifference, where the uj values are calculated. Listing 4.6.4 void CHeat1View::FiniteDifference(int j, double r, double u[], int n) { int i=0; if (j > 0) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . { double *v; v = new double[n+1]; if (v != NULL ) { for (i = 0; i < n+1; i++) v[i]=u[i]; ........................... for (i = 1; i < n; i++) u[i]=(1-2*r)*v[i]+r*(v[i-1]+v[i+1]); ..... u[0]=BoundD1(j); u[n]=BoundD2(j); . . . . . . . . . . . . . . . . . . . . . . . . . . . } delete []v; } else { for (i = 0; i < n+1; i++) u[i]=InitD(i); .......................... } }
[1]
[2] [3] [4]
[1]
[1] If j = 0, the initial data are loaded in the u array. [2] If j is positive, the values are saved in the v array and... [3] ...they are employed in computing the new values by the classical explicit scheme. [4] The boundary data are loaded. Next, let us introduce the function which has the task to show the computed values. Listing 4.6.5 void CHeat1View::NumResults(CDC* pDC) { CHeat1Doc* pDoc = GetDocument();
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
A Windows program
wsdac04
57
ASSERT VALID(pDoc); double *u; int i=0, j=0, xstep=190; CString str=””; int nx=pDoc->GetNx(), nt=pDoc->GetNt(); double alpha=pDoc->GetAlpha(), xM=pDoc->GetLength(); double tM=pDoc->GetTime(), dx=xM/nx, dt=tM/nt, r=alpha*dt/(dx*dx); u = new double[nx+1]; if (u != NULL ) { pDC->TextOut(V1+5, -20, ”Computing...”); for (i = 0; i < nx+1; i++) u[i]=0.; str.Format(”Numerical values of u(x,t)”); pDC->TextOut(V1+5, -20,str); pDC->TextOut(V1, -50,”t =”); pDC->TextOut(V1+70, -50,”x =”); pDC->MoveTo(0,-70); pDC->LineTo(10+xstep*(nx+1),-70); pDC->MoveTo(100,-55); pDC->LineTo(100,-100); str.Format(”%lf”,m jj*dt); pDC->TextOut(V1,-80,str); . . . . . . . . . . . . [1] for (j = 0; j < m jj+1; j++) FiniteDifference(j,r,u,nx); for (i = 0; i < nx+1; i++) { str.Format(”%lf”,i*dx); pDC->TextOut(110+xstep*i,-50,str); str.Format(”%lf”,u[i]); pDC->TextOut(110+xstep*i,-80,str); . . . . . . . . . . . . . . . . . . . . . . . . . . [2] } } else pDC->TextOut(V1+5, -20, ”Insufficient memory”); delete []u; m xDocSize=200*(nx+1); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . [3] }
[1] The values of u at time t = dt ∗ m jj are calculated. [2] The values of u are formatted into a string and are printed on the monitor. [3] Information about the line length for scroll device. The NumResults(pDC) function is invoked by OnDraw(CDC* pDC). Therefore, replace the line code GraphResults(pDC);
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
58
by if (pDoc->GetControl() < 22) GraphResults(pDC); else NumResults(pDC);
Compile and execute the program. Note that only the values of u at time t = 0 are shown. Indeed, they depend on mjj , whose initialization value is just zero. Therefore, it is necessary to increase such a value if we want to print uj for j > 0. To this end the UP and Down keys will be used. Here is the procedure to introduce the function that handles the command when these keys are pressed. 1. Activate Class Wizard and select CHeat1View in the Class name combo box. 2. Double-click WM KEYDOWN in Messages combo box. Clicking the Edit Code button displays the skeleton of new function that must be completed as follows. Listing 4.6.6 void CHeat1View::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { CHeat1Doc* pDoc = GetDocument(); ASSERT VALID(pDoc); if (pDoc->GetControl() >20) { if(nChar==VK UP || nChar==VK DOWN || nChar==VK LEFT || nChar==VK RIGHT) { switch (nChar) { .............................................. case VK UP: if(m jj< pDoc->GetNt()) m jj++; else m jj=0; break; .......................................... case VK DOWN: if ( m jj > 0) m jj- -; else m jj = pDoc->GetNt(); break; // here new code } Invalidate(); } } CScrollView::OnKeyDown(nChar, nRepCnt, nFlags); }
[1]
[2]
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
A Windows program
wsdac04
59
[1] When the UP key is pressed, if the actual time t is less than T , the mjj variable is increased and the temperature at time t + dt is obtained. Instead, if t = T , the initial values are shown. [2] If the Down key is pressed, the mjj variable is decreased and the temperature at time t − dt is printed. If t = 0, the final values are shown.
4.7
Analysis of data
Before going further, let us focus our attention on the analysis of data. Indeed, some data, such as the initial-boundary values, can be left to the user’s full responsibility. On the contrary, the equation data must be carefully verified. The diffusivity constant α, the length L of the solid, the final time T must be strictly positive; in addition, nx and nt must be positive integers. Otherwise, catastrophic errors could arise, as all computations are based on these hypotheses. It is necessary that the program verifies the data and informs the user about possible errors. To this end modify the function of Listing 4.3.4 as follows. Listing 4.7.1 void CHeat1Doc::OnDataEquation() { CEdata edata; edata.m xM=m length; edata.m nx=m nx; edata.m nt=m nt; edata.m al=m alpha; edata.m tM=m time; CString str=””; if (edata.DoModal()==IDOK) { if (edata.m al>0 && edata.m tM>0 && edata.m xM>0 ........................... && edata.m nx>1 && edata.m nt>1) { m length=edata.m xM; m nx=edata.m nx; m nt=edata.m nt; m alpha=edata.m al; m time=edata.m tM; m control=11; Stability(); } else .............................................................
[1]
[2]
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
60
{
str.Format(”Please, alpha, T, L positive; nx, nt integers >1! Try again.”); AfxMessageBox(str); m control=0;
} SetModifiedFlag(); UpdateAllViews(NULL); } }
[1] If alpha, L, T are positive and nx, nt are integers ≥ 2, the equation data are loaded. [2] Otherwise, a message is sent to the user, who is invited to correct his data. Compile and try.
4.8
Graphical results. Examples
This section deals with the code necessary to paint the “function” uj into the prefixed rectangle. Open the Heat1View.h file and declare three new functions and one variable. Listing 4.8.1 protected: double Min(double u[], double m, int n); double Max(double u[], double m, int n); int GraphC(double c, double crd, int origin); int m ii;
The variable is initialized in the constructor Heat1View::CHeat1View() m ii=0;
in the CHeat1View.cpp file. The Min and Max functions return the minimum and the maximum, respectively, of the array which is passed as argument. Listing 4.8.2 double CHeat1View:: Min(double u[], double m, int n) { for (int i = 0; i < n+1; i++) { if (u[i]<m) m=u[i]; }
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
A Windows program
wsdac04
61
return m; } double CHeat1View:: Max(double u[], double m, int n) { for (int i = 0; i < n+1; i++) { if (u[i]>m) m=u[i]; } return m; }
Fig. 4.8.1
Rectangle for graphical results
In this way the minimum m[0] ≤ 0, and the maximum m[1] ≥ 0 of uij are determined. These are essential to paint into the rectangle delimited by the dotted lines in fig 4.8.1. In the same figure there are also shown the axes X and Y , as they are oriented in the metric system, used in the program. The co-ordinates xzero, uzero denote the origin of the axes used to paint. Note that xzero=V1+D, but uzero depends on the function to draw. Indeed, if m[0] = 0, then uij ≥ 0 and it is assumed uzero=-V2+D; instead, if, m[1] = 0, then uij ≤ 0 and it is assumed uzero=-V1-D. Lastly, if m[1] > 0 and m[0] < 0, it is assumed uzero =
(V 1 + D)m[0] − (V 2 − D)m[1] , m[1] − m[0]
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
62
which has been derived by −V 1 − D − uzero m[1] = . uzero + V 2 − D −m[0]
(4.8.1)
The numerical co-ordinates (xi , uij ) must be transformed into graphical coordinates of a point belonging to the quoted rectangle. This task is handled by the following function. Listing 4.8.3 int CHeat1View:: GraphC(double c, double crd, int origin) { return (int)(origin+c*crd); }
...............
[1]
[1] When this function is invoked, the program will pass as origin the xzero value if c = xi , or the uzero value if c = uij . The argument crd denotes a reduction coefficient of co-ordinates. For the x co-ordinate it is evidently xrd = (V 2 − V 1 − 2 ∗ D)/L. In addition, for the u co-ordinate it is urd = −(V 1 + D + uzero)/m[1], if m[0] = 0, urd = −(uzeroV 2 − D)/m[0], if m[1] = 0, urd = −(V 1 + D + uzero)/m[1], if m[0] < 0, m[1] > 0. The last one is equivalent to urd = −(uzero + V 2 − D)/m[0], if m[0] < 0, m[1] > 0, because of (4.8.1). All this is recollected in the following code. Listing 4.8.4 void CHeat1View::GraphResults(CDC* pDC) { ... if (controlv >0) { ... pDC->TextOut(V2+D, -150, str); if (controlv ==21) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . { int i=0,j=0,xzero=V1+D,uzero=-(V1+V2)/2,uunit=30;
[1]
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
A Windows program
wsdac04
63
double *u, xrd=(V2-V1-2*D)/xM, urd=xrd; double m[2]; m[0]=0.,m[1]=0.; u = new double[nx+1]; if (u != NULL ) { pDC->TextOut(V2+30*D, -V2+30*D, ”Computing...”); for (i = 0; i < nx+1; i++) u[i]=0.; for (j = 0; j < nt+1; j++) { FiniteDifference(j,r,u,nx); m[0]=Min(u,m[0],nx); m[1]=Max(u,m[1],nx); } if (m[1]-m[0]>0) { if (m[0]>=0 ) { uzero=-V2+D; urd=(V2-V1-2*D)/m[1]; } else if (m[1]<=0 ) { uzero=-V1-D; urd=-(V2-V1-2*D)/m[0]; } else { uzero=(int)(((V1+D)*m[0]-(V2-D)*m[1])/(m[1]- m[0])); urd=-(V1+D+uzero)/m[1]; } } pDC->MoveTo(xzero,-V2+D); pDC->LineTo(xzero,-V1-D); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . [2] pDC->MoveTo(V2-D,-V2+D); pDC->LineTo(V2-D,-V1-D); ................................. [3] pDC->MoveTo(V1+D,uzero); pDC->LineTo(V2-D,uzero); .................................. [4] for (i = 0; i < nx+1; i++) u[i]=0.; for (j = 0; j < m jj+1; j++) FiniteDifference(j,r,u,nx); pDC->MoveTo(GraphC(0., xrd, xzero), GraphC(u[0], urd, uzero)); [5] for (i = 0; i < nx; i++) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . [6] pDC->LineTo(GraphC((i+1)*dx,xrd,xzero), GraphC(u[i+1],urd,uzero)); pDC->TextOut(V2+30*D, -V2+30*D, ”Computing...OK.”); // add new code here } else pDC->TextOut(V1+D, -10, ”Insufficient memory”);
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
64
delete []u; }
}
}
[1] When the Graphical item is activated, the program applies the classical explicit method. [2] The line of equation x = 0, that is the u-axis, is drawn. [3] The line of equation x = L is drawn. [4] The line of equation u = 0, that is the x-axis, is drawn. [5] The initial point of the temperature graph. [6] The function is painted. Compile and try the UP and DOWN keys to display the temperature evolution. Finally, some useful information is added to make the graphical results more readable. The length scale and the temperature scale are introduced. Also, we draw a small segment, which can move along the x-axis. Its shift is ruled by the LEFT and RIGHT keys. The temperature, corresponding to the position of the moving segment, is printed. All this is obtained by modifying the GraphResults function. Replace the line // add new code here
by the following code. Listing 4.8.5 for (i = 0; i < nx+1; i++) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . { pDC->MoveTo(GraphC(i*dx,xrd,xzero), uzero-2); pDC->LineTo(GraphC(i*dx,xrd,xzero), uzero+2); } ................... pDC->MoveTo(GraphC(m ii*dx, xrd, xzero), uzero-5); pDC->LineTo(GraphC(m ii*dx, xrd, xzero), uzero+5); str.Format(”u(%g, %g) = %g”, m ii*dx,m jj*dt,u[m ii]); pDC->TextOut(V2+D, -350, str); ...................................... str.Format(”X-scale: 1 = %g”, dx); pDC->TextOut(V2+D, -170, str); str.Format(”U-scale: 1 = %g”, uunit/urd); pDC->TextOut(V2+D, -190, str); for (i = uunit; i < -(uzero+V1+D); i=i+uunit) ......................... { pDC->MoveTo(V1+D-1,uzero+i);
[1]
[2]
[3]
[4]
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
A Windows program
wsdac04
65
pDC->LineTo(V1+D+2,uzero+i); } for (i = uunit; i < (uzero+V2-D); i=i+uunit) { pDC->MoveTo(V1+D-1,uzero-i); pDC->LineTo(V1+D+2,uzero-i); }
[1] Length scale. [2] Moving segment. [3] The temperature, corresponding to the position of the moving segment, is printed. [4] Temperature scale. Now, let us modify the OnKeyDown function which handles the message when the LEFT and RIGHT keys are pressed. Replace // add new code here
by the following code Listing 4.8.6 case VK LEFT: if(m ii> 0) m ii- -; else m ii=pDoc->GetNx(); break; case VK RIGHT: if ( m ii < pDoc->GetNx()) m ii++; else m ii = 0; break;
Example 4.8.1
Consider the following initial-boundary-value problem ut − uxx = 0, 0 < x < 1, 0 < t ≤ 1, u(x, 0) = x2 , 0 ≤ x ≤ 1, u(0, t) = 2t, u(1, t) = 1 + 2t, 0 ≤ t ≤ 1.
The solution of the above problem is given by u(x, t) = x2 + 2t, as it is easy to verify. Execute the program. In the Equation Data dialog box enter nx = 10. The program will determine nt = 200, dt = 0.005, r = 0.5. Enter the initial and boundary data. To save time, open the Example481.htf file, supplied
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
66
with the CD. Exploring the program is easy. Pressing the Up and Down keys yields the temperature evolution. Specific values of the temperature are printed by the Left and Right keys. Compare the results with the analytic solution. Example 4.8.2
Consider the following initial-boundary-value problem ut − uxx = 0, 0 < x < 1, 0 < t ≤ 0.1, u(x, 0) = sin(πx), 0 ≤ x ≤ 1, u(0, t) = 0, u(1, t) = 0, 0 ≤ t ≤ 1,
which admits the solution u(x, t) = exp(−π 2 t) sin(πx). Execute the program. Enter nx = 20. The program will give nt = 80, dt = 0.00125, r = 0.5. Enter the other data, or open the Example482.htf file, supplied with the CD. Compare the results with the analytic solution.
4.9
Icons
The program is completed by specializing the four icons. This is a very simple task: open the templates supplied with the compiler and modify them. Further Reading: [Bates and Tomkins (1998)], [Buzzi Ferraris (2000)], [Chapman (1998)], [Gregory (1997)], [Kernigham and Ritchie (1978)], [Kharab and Guenther (2002)], [Kruglinski, Sheperd and Wingo (1998)].
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Chapter 5
The Heat2 project
This chapter deals with a program for the one-dimensional heat equation with boundary conditions of the first, second and third kind. The C++ language is used. The C language was first developed by D. M. Ritchie at AT&T Laboratories in 1972. The classic C language was evolved after 1970 by B. W. Kernigham and D. M. Ritchie. The C++ language, developed by B. Stroustrup in the early 1980s, is an extension of C. It provides the capabilities of object-oriented programming. It is considered the most powerful and flexible language. Furthermore, C++ has become the language of choice for the majority of professional programmers. Students will benefit greatly from learning and using this modern and sophisticated language.
67
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
68
5.1
Introduction
The project developed in this chapter concerns the following initialboundary-value problem for the one-dimensional heat equation Ut − αUxx = 0, 0 < x < L, 0 < t ≤ T,
(5.1.1)
U (x, 0) = ϕ(x), 0 ≤ x ≤ L,
(5.1.2)
−k1 Ux (0, t) + h1 U (0, t) = g1 (t), 0 < t ≤ T,
(5.1.3)
k2 Ux (L, t) + h2 U (L, t) = g2 (t), 0 < t ≤ T.
(5.1.4)
The boundary conditions have been assigned in the general form of the third kind. The boundary conditions of the first and second kind can be recovered by specializing the constants ki , hi , i = 1, 2, in (5.1.3), (5.1.4). Equation (5.1.1) is approximated by the classical explicit method ui,j+1 = (1 − 2r)ui,j + r(ui+1,j + ui−1,j ),
(5.1.5)
where i = 1, ..., nx − 1, j = 0, ..., nt − 1, nx = L/∆x, nt = T /∆t,
(5.1.6)
and r = α∆t/(∆x)2 .
(5.1.7)
Furthermore, initial condition (5.1.2) becomes ui,0 = ϕi , i = 0, ..., nx ,
(5.1.8)
where ϕi = ϕ(i∆x). The boundary conditions are approximated by −k1
k2
u1,j − u−1,j + h1 u0,j = (g1 )j , 2∆x
um+1,j − um−1,j + h2 um,j = (g2 )j . 2∆x
(5.1.9)
(5.1.10)
The fictitious values are eliminated by means of equation (5.1.1). Indeed, by assuming that this equation holds for i = 0 and i = nx , it results u0,j+1 = (1 − 2r)u0,j + r(u1,j + u−1,j ),
(5.1.11)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
The Heat2 Project
unx ,j+1 = (1 − 2r)unx ,j + r(unx +1,j + unx −1,j ).
wsdac04
69
(5.1.12)
From (5.1.9)-(5.1.12) it follows u0,j+1 = [1 − 2r(1 + h1 ∆x/k1 )]u0,j + 2r[u1,j + (g1 )j ∆x/k1 ],
(5.1.13)
unx ,j+1 = [1 − 2r(1 + h2 ∆x/k2 )]um,j + 2r[um−1,j + (g2 )j ∆x/k2 ]. (5.1.14) Problem (5.1.5), (5.1.8), (5.1.13), (5.1.14) will be considered under the stability condition 1 1 , r ≤ min . (5.1.15) 2 + (h1 /k1 )∆x 2 + (h2 /k2 )∆x In the case of boundary conditions of the first kind, formulas (5.1.13), (5.1.14) are replaced by u0,j = (g1 )j , unx ,j+1 = (g2 )j ,
(5.1.16)
and the stability condition is r ≤ 1/2. 5.2
(5.1.17)
The project
Create the new Project Heat2 by following the procedure described in Section 4.2. However, Step 4 must be replaced by Step 4 of 6. Uncheck Docking toolbar check box. Uncheck Printing and print preview check box. Uncheck 3D control check box. Click the Advanced button; in the Advanced Options dialog box enter hts as File extension and click Close. Click Next. After creating the new project, modify the PreCreateWindow(CREATESTRUCT& cs) function in the MainFrm.cpp file as in Listing 4.2.1. The compiler supplies a default menu. Complete it by adding the new items for this specific program. Here is the procedure to follow. 1. Click the ResourceView tab and expand the Menu item. Double-click IDR MAINFRAME to display the menu resource. 2. Press Alt+Enter to display the Properties box and keep it visible by clicking the pin button.
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
70
3. In the menu template note some default menu headers. Also note a blank rectangle to their right. By the mouse drag and drop it between View and Help. In the Properties box enter Data as Caption. 4. Below the Data header a blank rectangle should appear, ready to become the new menu item. Click it and, in the Properties box, enter Equation as Caption. The resource ID is automatically assigned by the compiler: ID DATA EQUATION. 5. Repeat the last step to obtain the new Initial item. The resource ID should be ID DATA INITIAL. 6. Apply the same procedure to obtain the Boundary1 and the Boundary2 items immediately below the Initial item. They will be identified by ID DATA BOUNDARY1 and ID DATA BOUNDARY, respectively. 7. Note a blank rectangle on the right of Help. By the mouse drag and drop it between Data and Help. In the Properties box enter Show as Caption. 8. Below the Show menu header note a blank rectangle, ready to become the new menu item. Click it and, in the Properties box, enter Results as Caption. The resource ID should be: ID SHOW RESULTS.
5.3
Document class
Let us implement the Document class by declaring new member functions and variables. Open the Heat2doc.h file and add the following code before the line // Generate message .... Listing 5.3.1 protected: int m control, m nx, m nt; double m alpha, m length, m time; CStringArray m u0, m g1, m g2, m H, m K; CUIntArray m bckind; public: int GetControl(){return m control;}; int GetNx(){return m nx;}; int GetNt(){return m nt;}; double GetAlpha() {return m alpha;}; double GetLength() {return m length;}; double GetTime() {return m time;}; CString GetU0(int i) {if (i< m u0.GetSize()) return m u0.GetAt(i); else return ””; };
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
The Heat2 Project
wsdac04
71
CString GetG1(int j) {if (j< m g1.GetSize()) return m g1.GetAt(j); else return ””; }; CString GetG2(int j) {if (j< m g2.GetSize()) return m g2.GetAt(j); else return ””; }; CString GetH(int i) {if (i< m H.GetSize()) return m H.GetAt(i); else return ””; }; CString GetK(int i) {if (i< m K.GetSize()) return m K.GetAt(i); else return ””; }; int GetBckind(int i) {if (i< m bckind.GetSize()) return m bckind.GetAt(i); else return -1; }; void Stability(); void TryAgain(CString msg);
In addition, open the Heat2doc.cpp file and initialize the variables. Listing 5.3.2 BOOL CHeat2Doc::OnNewDocument() { if (!CDocument::OnNewDocument()) return FALSE; m control=0; m nx=20; m nt=20; m alpha=1.0; m length=1.0; m time=1.0; m u0.SetSize(1); m u0.SetAt(0,”0”); m g1.SetSize(1); m g1.SetAt(0,”0”); m g2.SetSize(1); m g2.SetAt(0,”0”); .............. m H.SetSize(2); m H.SetAt(0,”1”); m H.SetAt(1,”1”); ............... m K.SetSize(2); m K.SetAt(0,”1”); m K.SetAt(1,”1”); ..... m bckind.SetSize(2); m bckind.SetAt(0,1); m bckind.SetAt(1,1); return TRUE; }
[1] [2] [3]
[1] The constants h1 and h2 will be stored in the m H array. [2] The constants k1 and k2 will be stored in the m K array. [3] The information about the kind of boundary conditions will be stored in the m bckind array. More precisely, the values 1, 2, or 3, will be used for the boundary conditions of the first, second, or third kind, respectively. Let us introduce the functions which handle the command when the menu items are clicked. The procedure is the following. 1. Select ClassWizard in the View menu to obtain the MFC ClassWizard box. Click the Message Maps tab, select CHeat2Doc in the Class name box, select ID DATA EQUATION in the Object IDs box, select COMMAND in the Messages box, click Add Function to display the Add Member Function box. Here, click OK to agree with the suggested name: OnDataEquation. Then, in the Messages box select UPDATE COMMAND UI, click Add
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
72
Function and, in the next box, click OK to agree with the suggested name for the new member function: OnUpdateDataEquation. 2. Apply the same procedure to: ID DATA INITIAL; ID DATA BOUNDARY1; ID DATI BOUNDARY2; ID SHOW RESULTS. Pressing the Edit Code button closes ClassWizard and edits the skeleton of the new functions which will be implemented later. Finally, add the code to save and to restore all the data. Listing 5.3.3 void CHeat1Doc::Serialize(CArchive& ar) { CString str=””; int i=0, b=0, size=1; if (ar.IsStoring()) { ar<< m control << m nx << m nt << m alpha << m length << m time; size=m u0.GetSize(); ar<<size; for (i=0; i<size;i++) { str=m u0.GetAt(i); ar<<str; } size=m g1.GetSize(); ar<<size; for (i=0; i<size;i++) { str=m g1.GetAt(i); ar<<str; } size=m g2.GetSize(); ar<<size; for (i=0; i<size;i++) { str=m g2.GetAt(i); ar<<str; } for (i=0; i<2 ;i++) { str=m H.GetAt(i); ar<<str; } for (i=0; i<2 ;i++)
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
The Heat2 Project
wsdac04
73
{ str=m K.GetAt(i); ar<<str; } for (i=0; i<2 ;i++) { b=m bckind.GetAt(i); ar<
} else { ar>>m control >> m nx >> m nt >> m alpha >> m length >> m time; ar>>size; for (i=0; i<size;i++) { ar>>str; m u0.SetAtGrow(i,str); } ar>>size; for (i=0; i<size;i++) { ar>>str; m g1.SetAtGrow(i,str); } ar>>size; for (i=0; i<size;i++) { ar>>str; m g2.SetAtGrow(i,str); } for (i=0; i<2 ;i++) { ar>>str; m H.SetAt(i,str); } for (i=0; i<2 ;i++) { ar>>str; m K.SetAt(i,str); } for (i=0; i<2 ;i++) { ar>>b; m bckind.SetAt(i,b); }
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
74
} }
Compile and test.
5.4
Equation class
This section deals with the creation of the dialog window to enter the data related to the heat equation: the thermal coefficient α, the length L of the one-dimensional solid, the final time T of the thermal process, the scalars hi , ki , i = 1, 2, involved in the boundary conditions, and the integers nx, nt which characterize the mesh. Here are the steps to follow.
Fig. 5.4.1
Dialog template and final look
1. Select the Resource item from the Insert menu to display the Insert Resource box. Here, double-click Dialog to obtain the dialog template, fig. 5.4.1, which we are going to rearrange. 2. By Alt+Enter open the Property box. Replace IDD DIALOG1 by IDD EDATA and enter Equation data as Caption. 3. Increase suitably the dimensions of the template and by the mouse move the OK and Cancel buttons to lower position, fig. 5.4.1. 4. On the Controls toolbox select the Static Text box. Move the mouse to the upper left corner of the dialog template and click to obtain a static text control. As Caption enter: U t = alpha U xx, 0 < x < L, 0 < t < T . 5. Repeat the last step to obtain T=, Alpha=, L=, Nx=, Nt=, fig. 5.4.1. 6. On the Controls toolbox select the Edit box. Move the mouse to the
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
The Heat2 Project
wsdac04
75
right of “T=” and click to obtain a new edit box, fig. 5.4.1. Re-size the box and in the Properties box replace IDC EDIT1 by IDC TM, fig. 5.4.1. Apply the same procedure to move other four edit boxes to the right of “Alpha=”, “L=”, “Nx=”, “Nt=”. Replace their default IDCs by IDC AL, IDC XM, IDC NX, IDC NT, respectively, fig. 5.4.1. 7. On the Controls toolbox select the Static Text box. Move the mouse to the next line and click to display a new static text box; in the Property box enter Boundary1, kind: as Caption. On the Controls toolbox select the Radio Button box, move the mouse to right of “Boundary1, kind:”, and click to obtain a radio button. In the Property box enter 1 as Caption and check the Group box to specify that this is the first of a group (of three); in addition, replace IDC RADIO1 by IDC BC1. Use the mouse to move another Radio Button to the right of the first and enter 2 as Caption. Similarly, add a last Radio Button and enter 3 as Caption, fig. 5.4.1. 8. Repeat the procedure of Step 7 to create the Static Text box Boundary2 and a second group of three Radio Buttons. In creating the first of this new group replace IDC RADIO4 by IDC BC2 and check the Group box, fig. 5.4.1. 9. Lastly, the controls for the real constants hi , ki , i = 1, 2, are added. On the Controls toolbox select the Static Text box. Move the mouse to the right of the first group of Radio Buttons and click to display a new static text box; in the Property box enter h1 = as Caption. On the right of the previous control create a new Edit box and enter IDC H1 as IDC. Similar procedure is applied to create the static text box k1 = and the corresponding Edit box, whose IDC should be IDC K1, fig. 5.4.1. 10. Repeat the last step with reference to the second boundary condition, fig. 5.4.1. After completing the dialog window, create the class that handles this resource. Select the ClassWizard item from the View menu to display the Adding a Class dialog box; accept to create a new class by clicking OK; in the New Class dialog box enter CEdata in the Name box and click OK. In the MFC ClassWizard box select Member Variables tab to declare the variables; double-click IDC AL to obtain the Add Member Variable box; here, in Member variable name box enter m al, and select double in Variable type box; click OK. Apply the same procedure to: IDC BC1, Member variable name: m bc1, Variable type: int, IDC BC2, Member variable name: m bc2, Variable type: int,
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
76
IDC H1, Member variable name: m h1, Variable type: CString, IDC H2, Member variable name: m h2, Variable type: CString, IDC K1, Member variable name: m k1, Variable type: CString, IDC K2, Member variable name: m k2, Variable type: CString, IDC NT, Member variable name: m nt, Variable type: int, IDC NX, Member variable name: m nx, Variable type: int, IDC TM, Member variable name: m tM, Variable type: double, IDC XM, Member variable name: m xM, Variable type: double. This completes the class. Click OK to close the MFC ClassWizard box. Open the Heat2Doc.cpp file and add the code line #include “Edata.h”
after the other including instructions, so that the file can be seen. Now, implement the OnDataEquation function, which handles the command when the Equation menu item is clicked. Also, complete the simple TryAgain function, that is invoked when the previous function is executed. Listing 5.4.1 void CHeat2Doc::OnDataEquation() { CEdata edata; ............................................. edata.m xM=m length; edata.m nx=m nx; edata.m nt=m nt; edata.m al=m alpha; edata.m tM=m time; edata.m h1=m H.GetAt(0); edata.m h2=m H.GetAt(1); edata.m k1=m K.GetAt(0); edata.m k2=m K.GetAt(1); edata.m bc1=m bckind.GetAt(0)-1; edata.m bc2=m bckind.GetAt(1)-1; m control=0; CString str=””; BOOL test=1; if (edata.DoModal()==IDOK) { ............................................. m alpha=edata.m al; m time=edata.m tM; m length=edata.m xM; m nx=edata.m nx; m nt=edata.m nt; m H.SetAt(0,edata.m h1); m H.SetAt(1,edata.m h2);
[1]
[2]
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
The Heat2 Project
m K.SetAt(0,edata.m k1); m K.SetAt(1,edata.m k2); m bckind.SetAt(0,edata.m bc1+1); m bckind.SetAt(1,edata.m bc2+1); if (edata.m al>0 && edata.m tM>0 && edata.m xM>0 ..................... && edata.m nx>1 && edata.m nt>1) { switch(edata.m bc1) { case 0: if (atof(edata.m h1) <= 0) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . { test=0; str.Format(”h1 positive!”); } break; case 1: ................................. if (atof(edata.m k1) <= 0) { test=0; str.Format(”k1 positive!”); } break; case 2: if (atof(edata.m h1) <= 0 || atof(edata.m k1) <= 0) . . . . . . . . { test=0; str.Format(”h1 and k1 positive!”); } break; } if (test > 0) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . { switch(edata.m bc2) { case 0: if (atof(edata.m h2) <= 0) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . { test=0; str.Format(”h2 positive!”); } break; case 1: if (atof(edata.m k2) <= 0) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . { test=0;
wsdac04
77
[3]
[4]
[4]
[4]
[5]
[6]
[6]
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
78
str.Format(”k2 positive!”); } break; case 2: if (atof(edata.m h2) <= 0 || atof(edata.m k2) <= 0) { test=0; str.Format(”h2 and k2 positive!”); } break;
......
[6]
} if (test > 0) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . [7] { Stability(); ................................................ [8] m control=11; SetModifiedFlag(); UpdateAllViews(NULL); ................................... [9] } else TryAgain(str); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . [10] } else TryAgain(str);
}
}
............................................ } else . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . { str.Format(”Alpha, T, L positive; nx, nt integers >1!”); TryAgain(str); }
void CHeat2Doc::TryAgain(CString msg) { AfxMessageBox(msg+”Try again.”); }
...............................
[10] [10]
[11]
[1] The data of the dialog box are initialized. [2] The entered data are saved. [3] The equation data are verified. If they are OK... [4] ... the constants related to the first boundary condition are verified. [5] If the test is positive... [6] ... the constants related to the second boundary condition are verified too. [7] If all the data are OK...
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
The Heat2 Project
wsdac04
79
[8] the Stability() function is invoked. [9] The modification flag is set and the function updating the view is called. [10] In the case of wrong data, a message is passed to the TryAgain function. [11] The user is invited to modify the incorrect data. Let us emphasize that the values m nx, m nt are involved in the definition r=
αdt αT nx 2 = . 2 (dx) nt L
(5.4.1)
Since r must satisfy stability condition (5.1.15), or (5.1.17), it is apparent that the entered values must be controlled and modified so that the stability restrictions are fulfilled. The program modifies only m nt. The task is handled by the following function. Listing 5.4.2 void CHeat2Doc::Stability() { double dx=m length/m nx; double dt=m time/m nt; if (m alpha*dt/(dx*dx)> .5) { do { m nt = m nt+1; dt=m time/m nt; }while (m alpha*dt/(dx*dx) > .5); } if (m bckind.GetAt(0)==3) { double h1=atof(m H.GetAt(0)), k1=atof(m K.GetAt(0)); if (m alpha*dt/(dx*dx)> 1/(2+dx*h1/k1)) { do { m nt = m nt+1; dt=m time/m nt; }while (m alpha*dt/(dx*dx) > 1/(2+dx*h1/k1)); } } if (m bckind.GetAt(1)==3) {
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
80
}
double h2=atof(m H.GetAt(1)), k2=atof(m K.GetAt(1)); if (m alpha*dt/(dx*dx)> 1/(2+dx*h2/k2)) { do { m nt = m nt+1; dt=m time/m nt; }while (m alpha*dt/(dx*dx) > 1/(2+dx*h2/k2))); }
}
Finally, implement the function that enables and disables the Equation item. Listing 5.4.3 void CHeat2Doc::OnUpdateDataEquation(CCmdUI* pCmdUI) { ....................... if (m control< 12) pCmdUI->Enable(TRUE); else pCmdUI->Enable(FALSE); ..................................... }
[1] [2]
[1] If the initial data have not yet entered, the Equation item is enabled, so that the equation data can be entered. [2] After entering the initial data, the Equation item is disabled.
5.5
Initial and boundary data
This section deals with the part of the program related to the initial and the boundary data. The dialog box we need is exactly the same we employed in the Heat1 project to solve a similar problem. It would be convenient to recover the resource together with the associated class. By Visual we can. Here we describe the steps to follow. 1. Close the Heat2 workspace and open the Heat1 workspace. 2. Select the ClassView tab, right-click CIbdata to display the context menu and click the AddToGallery item. In this way the class and the associated resource are saved in the Gallery. To verify this explicitly, it is sufficient to explore the subdirectory Gallery in the directory where Visual was installed. Note the subdirectory Heat1 and the Ibdata.ogx file, where the above class was saved. 3. Close the old workspace and open the new one.
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
The Heat2 Project
wsdac04
81
4. Click the Project menu header, select the AddToProject item and click the Components and Controls item to display the Components and Controls Gallery box. Here, double-click the Heat1 directory, select Ibdata.ogx and press the Insert button. Confirm the choice by clicking OK. This closes the Components and Controls Gallery box. Class and dialog box are added to the project, as one can easily verify. Open the Heat2Doc.cpp file and add the code line #include “Ibdata.h”
after the other including instructions. Compile. Now, implement the OnDataInitial function, which handles the command when the Initial item is clicked. Considering that class and resource have been copied by the previous project, it is clear that the code is the same. Therefore, simply copy the code of Listing 4.4.2. Furthermore, complete the function that enables and disables the quoted item. Listing 5.5.1 void CHeat2Doc::OnUpdateDataInitial(CCmdUI* pCmdUI) { if (m control==0) pCmdUI->Enable(FALSE); else pCmdUI->Enable(TRUE); }
Use the same code to implement the functions: OnUpdateDataBoundary1, OnUpdateDataBoundary2. Finally, implement the two functions, OnDataBoundary1, OnDataBoundary2, related to the boundary data. The code for the first one is given by the following listing. Listing 5.5.2 void CHeat2Doc::OnDataBoundary1() { CString str=””; double dt=m time/m nt; CIbdata ibdata; str.Format(”Boundary condition at x = 0 of %d kind”,m bckind.GetAt(0)); ibdata.m ibd=str; ibdata.m constant=0; ibdata.m datan= 1; ibdata.m fvalue=m g1.GetAt(0); ibdata.m function=”g1(0)=”; if (ibdata.DoModal()==IDOK) {
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
82
m g1.SetAt(0,ibdata.m fvalue); BOOL test=ibdata.m constant; for (int j=1; j< m nt+1; j++) { if (m g1.GetSize()==j) m g1.SetAtGrow(j,”0”); if (test==0) { ibdata.m constant=0; ibdata.m datan + +; str.Format(”g1(%g)=”,j*dt); ibdata.m function=str; ibdata.m fvalue=m g1.GetAt(j); ibdata.DoModal(); } m g1.SetAt(j,ibdata.m fvalue); } m control=12; } }
The code of the second function is obtained by modifying g1 in g2 everywhere and by replacing the code line str.Format(”Boundary condition at x = 0 of %d kind”,m bckind.GetAt(0));
by str.Format(”Boundary condition at x = L of %d kind”,m bckind.GetAt(1));
The section is concluded by implementing the functions related to the Results item. Listing 5.5.3 void CHeat2Doc::OnUpdateShowResults(CCmdUI* pCmdUI) { if (m u0.GetSize()>1 && m g1.GetSize()>1 && m g2.GetSize()>1) pCmdUI->Enable(TRUE); else pCmdUI->Enable(FALSE); } void CHeat2Doc::OnShowResults() { m control=21; SetModifiedFlag(); UpdateAllViews(NULL); }
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
The Heat2 Project
5.6
wsdac04
83
View class
This section deals with the questions concerning the computational results and their printing on the monitor. Open the Heat2View.h file and add the following instructions before the class definition. Listing 5.6.1 #define V1 1 #define V2 371 #define D 5.
Furthermore, before // Generate message ..., declare new member variables and functions. Listing 5.6.2 protected: int m xDocSize,m yDocSize, m ii, m jj; void Results(CDC* pDC); double InitD(int i); double BoundD1(int j); double BoundD2(int j); void FiniteDifference(int j, double r, double u[], int n, int bck[], double h[], double k[], double dx); double Min(double u[], double m, int n); double Max(double u[], double m, int n); int GraphC(double c, double crd, int origin);
The variables are initialized in the class constructor in the Heat2View.cpp file. Listing 5.6.3 CHeat2View::CHeat2View() { m xDocSize=100; m yDocSize=100; m ii=0; m jj=0; }
In the same file modify the OnDraw function, whose skeleton was supplied with the compiler. Listing 5.6.4 void CHeat2View::OnDraw(CDC* pDC) { CHeat2Doc* pDoc = GetDocument(); ASSERT VALID(pDoc); ............................ pDC->SetMapMode(MM LOENGLISH); ............................... CPen pen(PS SOLID, 1, RGB(0,0,0));
[1] [2]
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
84
CPen* oldPen= pDC->SelectObject(&pen); . . . . . . . . . . . . . . . . . . . . . . . . . . CFont font; font.CreatePointFont(90,”Times”,pDC); ............................. CFont* oldFont=pDC->SelectObject(&font); ........................ Results(pDC); CSize docSize(m xDocSize,m yDocSize); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . SetScrollSizes(MM LOENGLISH,docSize); pDC->SelectObject(oldPen); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . pDC->SelectObject(oldFont); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
[3] [4] [5] [6] [7] [7]
}
[1] Metric mapping mode where the x-axis is directed towards right and the y-axis upwards. [2] Pen with a width of one pixel drawing solid lines of black color. [3] The old pen is saved in order to restore it later. [4] A nine-point Times font is created. [5] The old font is stored. [6] Document dimensions to pass to the scroll device. [7] The old pen and the old font are restored. In addition, let us consider the functions: InitD, BoundD1, BoundD2, Min, Max, GraphC. Their code is the same as that given in the project of Chapter 4. Therefore, copy the listings 4.6.2, 4.6.3, 4.8.2 and 4.8.3. However, take care to replace Heat1 by Heat2. Now, implement the FiniteDifference function to compute the temperature. Listing 5.6.5 void CHeat2View::FiniteDifference(int j, double r, double u[], int n, int bck[], double h[], double k[], double dx) { int i=0; if (j > 0) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . [1] { double *v; v = new double[n+1]; if (v != NULL ) { for (i = 0; i < n+1; i++) v[i]=u[i]; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . [2] for (i = 1; i < n; i++) u[i]=(1-2*r)*v[i]+r*(v[i-1]+v[i+1]); . . . . . . [3] switch(bck[0]) ................................................. [4] { case 1:
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
The Heat2 Project
wsdac04
85
u[0]=BoundD1(j); break; case 2: u[0]=(1-2*r)*v[0]+2*r*v[1]+2*r*dx*BoundD1(j-1)/k[0]; break; case 3: u[0]=(1-2*r*(1+dx*h[0]/k[0]))*v[0]+2*r*v[1] +2*r*dx*BoundD1(j-1)/k[0]; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . [5] break; } switch(bck[1]) { case 1: u[n]=BoundD2(j); break; case 2: u[n]=(1-2*r)*v[n]+ 2*r*v[n-1]+2*r*dx*BoundD2(j-1)/k[1]; break; case 3: u[n]=(1-2*r*(1+dx*h[1]/k[1]))*v[n]+2*r*v[n-1] +2*r*dx*BoundD2(j-1)/k[1]; break; }
} delete []v;
} else { for (i = 0; i < n+1; i++) u[i]=InitD(i); }
...........................
[1]
}
[1] If j = 0 the initial data are stored in the u array. [2] If j > 0 the u values are copied in the v array... [3] ...are used in the classical explicit method. [4] The kind of boundary condition is selected. [5] Formula (5.1.13) is applied. It remains to implement the function that shows the results. Since the UP and DOWN keys will be used, let us introduce the function that handles the messages when these keys are pressed. Here is the procedure. 1. Activate Class Wizard and select CHeat2View in the Class name combo box.
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
86
2. Double-click WM KEYDOWN in Messages combo box. Clicking the Edit Code button edits the skeleton of the new function, that must be completed as follows. Listing 5.6.6 void CHeat2View::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { CHeat2Doc* pDoc = GetDocument(); ASSERT VALID(pDoc); if (pDoc->GetControl() ==21) { if(nChar==VK UP || nChar==VK DOWN || nChar==VK LEFT || nChar==VK RIGHT) { switch (nChar) { case VK UP: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . if(m jj< pDoc->GetNt()) m jj++; else m jj=0; break; ............................................ case VK DOWN: if ( m jj > 0) m jj- -; else m jj = pDoc->GetNt(); break; .............................................. case VK LEFT: if(m ii> 0) m ii- -; else m ii=pDoc->GetNx(); break; ............................................. case VK RIGHT: if ( m ii < pDoc->GetNx()) m ii++; else m ii = 0; break; } Invalidate(); } } CScrollView::OnKeyDown(nChar, nRepCnt, nFlags); }
[1]
[2]
[3]
[4]
[1] When the UP key is pressed the mjj variable is increased and the temperature at time t + dt is displayed; if t = T , the initial values are shown. [2] If the Down key is pressed, the mjj variable is decreased and the temperature at time t − dt is printed. If t = 0, the final values are shown.
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
The Heat2 Project
wsdac04
87
[3] When the LEFT key is pressed, the m ii variable is decreased and the program will print the temperature value at x-dx, where x is the position of the moving segment. [4] When the RIGHT key is pressed, the m ii variable is increased and the program will print the temperature value at x+dx. Finally, implement the following function. Listing 5.6.7 void CHeat2View::Results(CDC* pDC) { CHeat2Doc* pDoc = GetDocument(); ASSERT VALID(pDoc); CString str=””; int controlv=pDoc->GetControl(), nx=pDoc->GetNx(), nt=pDoc->GetNt(); double alpha=pDoc->GetAlpha(), xM=pDoc->GetLength(); double tM=pDoc->GetTime(), dx=xM/nx, dt=tM/nt, r=alpha*dt/(dx*dx); double h[2]; h[0]=atof(pDoc->GetH(0)); h[1]=atof(pDoc->GetH(1)); double k[2]; k[0]=atof(pDoc->GetK(0)); k[1]=atof(pDoc->GetK(1)); int bck[2]; bck[0]=pDoc->GetBckind(0); bck[1]=pDoc->GetBckind(1); pDC->Rectangle(V1,-V1,V2,-V2); ................................... [1] if (controlv >0) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . [2] { str.Format(”Ut = alpha Uxx; alpha = %g”,alpha); pDC->TextOut(V2+D, -30, str); str.Format(”T = %g; L = %g”,tM, xM); pDC->TextOut(V2+D, -50, str); str.Format(”nx = %d; nt = %d”, nx,nt); pDC->TextOut(V2+D, -70, str); str.Format(”dx = %20.16f”,dx); pDC->TextOut(V2+D, -90, str); str.Format(”dt = %20.16f”,dt); pDC->TextOut(V2+D, -110, str); str.Format(”r = %lf”,r); pDC->TextOut(V2+D, -130, str); str.Format(”Boundary1, kind: %d”,bck[0]); pDC->TextOut(V2+D, -150, str); switch(bck[0]) { case 1: str.Format(”h1 = %g”,h[0]); break; case 2: str.Format(”k1 = %g”,k[0]); break;
July 3, 2004
23:17
88
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
case 3: str.Format(”h1 = %g; k1 = %g”,h[0],k[0]); break; } pDC->TextOut(V2+D, -170, str); str.Format(”Boundary2, kind: %d”,bck[1]); pDC->TextOut(V2+D, -190, str); switch(bck[1]) { case 1: str.Format(”h2 = %g”,h[1]); break; case 2: str.Format(”k2 = %g”,k[1]); break; case 3: str.Format(”h2 = %g; k2 = %g”,h[1],k[1]); break; } pDC->TextOut(V2+D, -210, str); if (controlv ==21) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . { int i=0,j=0,xzero=V1+D,uzero=-(V1+V2)/2,uunit=30, xstep=190; double *u, xrd=(V2-V1-2*D)/xM, urd=xrd; double m[2]; m[0]=0.,m[1]=0.; ................................. u = new double[nx+1]; if (u != NULL ) { pDC->TextOut(V2+D, -10, ”Computing...”); for (i = 0; i < nx+1; i++) u[i]=0.; for (j = 0; j < nt+1; j++) { FiniteDifference(j,r,u,nx,bck,h,k,dx); m[0]=Min(u,m[0],nx); ..................................... m[1]=Max(u,m[1],nx); ..................................... } if (m[1]-m[0]>0) ............................................. { if (m[0]>=0) { uzero=-V2+D; urd=(V2-V1-2*D)/m[1]; } else if (m[1]<=0) { uzero=-V1-D;
[3]
[4]
[4] [4] [5]
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
The Heat2 Project
urd=-(V2-V1-2*D)/m[0]; } else { uzero=(int)(((V1+D)*m[0]-(V2-D)*m[1])/(m[1]- m[0])); urd=-(V1+D+uzero)/m[1]; }
wsdac04
89
} pDC->MoveTo(xzero,-V2+D); ............................... [6] pDC->LineTo(xzero,-V1-D); pDC->MoveTo(V2-D,-V2+D); ............................... [7] pDC->LineTo(V2-D,-V1-D); pDC->MoveTo(V1+D,uzero); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . [8] pDC->LineTo(V2-D,uzero); for (i = 0; i < nx+1; i++) u[i]=0.; for (j = 0; j < m jj+1; j++) FiniteDifference(j,r,u,nx,bck,h,k,dx); pDC->MoveTo(GraphC(0., xrd, xzero), GraphC(u[0], urd, uzero)); . . . [9] for (i = 0; i < nx; i++) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . [10] pDC->LineTo(GraphC((i+1)*dx,xrd,xzero),GraphC(u[i+1],urd,uzero)); pDC->TextOut(V2+D, -10, ”Computing...OK.”); for (i = 0; i < nx+1; i++) { pDC->MoveTo(GraphC(i*dx,xrd,xzero), uzero-2); pDC->LineTo(GraphC(i*dx,xrd,xzero), uzero+2); } ....... [11] pDC->MoveTo(GraphC(m ii*dx, xrd, xzero), uzero-5); pDC->LineTo(GraphC(m ii*dx, xrd, xzero), uzero+5); str.Format(”u(%g, %g) = %g”, m ii*dx,m jj*dt,u[m ii]); pDC->TextOut(V2+D, -350, str); str.Format(”Xscale: 1 = %g”, dx); pDC->TextOut(V2+D, -250, str); str.Format(”Uscale: 1 = %g”, uunit/urd); pDC->TextOut(V2+D, -270, str); for (i = uunit; i < -(uzero+V1+D); i=i+uunit) { pDC->MoveTo(V1+D-1,uzero+i); pDC->LineTo(V1+D+2,uzero+i); } for (i = uunit; i < (uzero+V2-D); i=i+uunit) { pDC->MoveTo(V1+D-1,uzero-i); pDC->LineTo(V1+D+2,uzero-i); } pDC->TextOut(V1, -V2-10, ”t”); pDC->TextOut(V1+70, -V2-10, ”x”); pDC->MoveTo(0,-V2-30);
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
90
pDC->LineTo(10+xstep*(nx+1),-V2-30); pDC->MoveTo(100,-V2-5); pDC->LineTo(100,-V2-90); str.Format(”%lf”, m jj*dt); pDC->TextOut(V1, -V2-40,str); for (i = 0; i < nx+1; i++) .................................. { str.Format(”%lf”, i*dx); pDC->TextOut(110+xstep*i, -V2-10,str); str.Format(”%lf”, u[i]); pDC->TextOut(110+xstep*i, -V2-40,str); } m xDocSize=200*(nx+1);
[12]
} else pDC->TextOut(V1+D, -10, ”Insufficient memory”); delete []u; }
}
}
[1] The first two values are the co-ordinates of the upper left vertex of the rectangle where the solution is drawn, and the last two are the co-ordinates of the lower right vertex. [2] If the equation data have been successfully entered, they are shown. [3] If the Results item is clicked, the finite-difference method is applied and the results are shown. [4] A basic role to find the minimum and the maximum values is played by the initialization values: m[0] = 0, m[1] = 0; in this case a minimum m[0] ≤ 0 and a maximum m[1] ≥ 0 will be determined. [5] This condition is not satisfied only if m[0]=m[1]=0; in such a case the variables keep their initialization values. [6] The line of equation x = 0 is drawn (u-axis). [7] The line of equation x = L is drawn. [8] The line of equation u = 0 is drawn (x-axis). [9] The initial point for the graph is fixed. [10] The solution is painted. [11] Moving segment.
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
The Heat2 Project
wsdac04
91
[12] The numerical results are shown. This completes the project. 5.7
Examples
In this section the use of the program is illustrated by examples. Example 5.7.1
Consider the following problem ut − uxx = 0, 0 < x < 1, 0 < t ≤ 1, u(x, 0) = x2 , 0 ≤ x ≤ 1,
−ux (0, t) = 0, ux (1, t) + u(1, t) = 3 + 2t, 0 ≤ t ≤ 1, which admits the solution u(x, t) = x2 + 2t. Execute the program. In Equation Data dialog box enter: nx = 10; Boundary1, kind:2; k1 = 1; Boundary2, kind:3; h2 = 1; k2 = 1. Next, the initial and boundary data should be entered. This could be a boring work. Using the files supplied with the CD can help to save time. Open the Example571.hts file and explore the program. Press the Up and Down keys to show the temperature evolution. Press the Left and Right keys to display specific values of temperature. Example 5.7.2
Consider the following problem ut − uxx = 0, 0 < x < 1, 0 < t ≤ 0.1, u(x, 0) = cos(πx/2), 0 ≤ x ≤ 1, ux (0, t) = 0, u(1, t) = 0, 0 ≤ t ≤ 1,
which has the solution u(x, t) = cos(πx/2) exp(−π 2 t/4). Execute the program and enter nx = 10, nt = 100, so that r = 0.1. Next, enter the other data, or open the Example572.hts file, supplied with the
July 3, 2004
23:17
92
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
CD. Compare the numerical results with the exact solutions and compute the percentage error. Further Reading: [Bates and Tomkins (1998)], [Buzzi Ferraris (2000)], [Chapman (1998)], [Gregory (1997)], [Kernigham and Ritchie (1978)], [Kharab and Guenther (2002)], [Kruglinski, Sheperd and Wingo (1998)].
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Chapter 6
Parabolic equations
This chapter is an introduction to finite-difference methods for parabolic PDEs. Since an explicit method has already been given in Chapter 3, firstly implicit schemes are presented and the related techniques of applications are shown. A three-time-level explicit method is also provided. Next, we consider some generalizations: variable diffusivity coefficient, convectiondiffusion problems, nonlinear situations, equations in two and three space dimensions. A section is devoted to a free boundary problem, discussed by the fixed-grid method. Stability analysis of finite-difference schemes is often a difficult task. Since direct methods rarely work, several other methods have been developed. The Von Neumann criterion, is probably the most used method. The the matrix stability is also an interesting method, as it allows us to point out the role played by the boundary data. Lastly, the energy method is introduced.
93
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
94
6.1
A simple implicit method
An important example of parabolic equation is the heat equation, which in non-dimensional form is written as Ut − Uxx = 0,
(6.1.1)
where it has been assumed F = 0 for simplicity. In Chapter 3 an explicit finite-difference method was discussed for this equation. Now, we introduce an implicit scheme. Refer to the point (i, j + 1) of the space-time grid and use the backward approximation for the time derivative and the central approximation for the space derivative to obtain, fig. 6.1.1,
Fig. 6.1.1
Backward-difference scheme
(ui,j+1 − ui,j )/∆t − (ui+1,j+1 − 2ui,j+1 + ui−1,j+1 )/(∆x)2 = 0.
(6.1.2)
With the usual definition r = ∆t/(∆x)2 ,
(6.1.3)
−rui−1,j+1 + (1 + 2r)ui,j+1 − rui+1,j+1 = ui,j .
(6.1.4)
this equation becomes
Scheme (6.1.4) is called backward-difference scheme for obvious reasons. It is implicit because formula (6.1.4), which defines it, is unable to provide directly ui,j+1 when the values of ui,j are known. To show how such a method works, consider the Dirichlet problem, where the following initial and boundary data are prescribed ui,0 = ϕi , i = 0, ..., m, (6.1.5) u0,j = (g1 )j , um,j = (g2 )j , 1 = 0, ..., n.
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Parabolic equations
wsdac04
95
In this case, for every fixed j ≥ 1, from (6.1.4) we derive m − 1 equations in m − 1 unknowns which enable us to find ui,j , i = 1, ..., m − 1, j ≥ 1; in addition, the values at the ends are given by (6.1.5)2 . To discuss the consistency, let us rewrite (6.1.2) in the following compact form Li,j u = 0,
(6.1.6)
where Li,j denotes the difference operator which appears on the left-hand side of (6.1.2). The truncation error Ti,j , given by Ti,j = Li,j U,
(6.1.7)
has to be evaluated. Using Taylor’s series gives Ui,j = Ui,j+1 − (Ut )i,j+1 ∆t + (Utt )i,j+1
(∆t)2 + O((∆t)3 ), 2
(6.1.8)
and therefore, Ui,j+1 − Ui,j ∆t = (Ut )i,j+1 − (Utt )i,j+1 + O((∆t)2 ). ∆t 2
(6.1.9)
Similarly, Ui+1,j+1 − 2Ui,j+1 + Ui−1,j+1 (∆x)2
= (Uxx )i,j+1 + (Uxxxx)i,j+1
(∆x)2 + O((∆x)4 ). 12
(6.1.10)
Since (Ut − Uxx )i,j+1 = 0, from (6.1.9) and (6.1.10) it follows Li,j U = −(Utt )i,j+1
∆t (∆x)2 − (Uxxxx)i,j+1 + O((∆t)2 + (∆x)4 ). (6.1.11) 2 12
Hence, Ti,j = O((∆x)2 ) + O(∆t), which shows the consistency of the method.
(6.1.12)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
96
To give matrix form to implicit scheme (6.1.4) let us define the vectors uj , bj
u1,j u2,j ·
, uj = um−2,j um−1,j
ru0,j 0 bj = · , 0 rum,j
and the (m − 1) × (m − 1) matrix 1 + 2r −r −r 1 + 2r −r · · · C= . · · · −r 1 + 2r −r −r 1 + 2r
(6.1.13)
(6.1.14)
By considering (6.1.13) and (6.1.14), from (6.1.4) it easily follows Cuj+1 = uj + bj+1 .
(6.1.15)
Finally, let us illustrate how the implicit method is applied in the case of boundary conditions of the third kind −Ux (0, t)+H1 U (0, t) = H1 G1 (t), Ux (1, t)+H2 U (0, t) = H2 G2 (t). (6.1.16) Using the forward and backward approximations in (6.1.16)1 and (6.1.4)2 , respectively, gives two further equations −
u1,j − u0,j + H1 u0,j = H1 (g1 )j , ∆x
um,j − um−1,j + H2 um,j = H2 (g2 )j , ∆x
(6.1.17)
(6.1.18)
which enable us to determine the boundary values on every time step. A more accurate result is provided by using the central approximations −
u1,j+1 − u−1,j+1 + H1 u0,j+1 = H1 (g1 )j+1 , 2∆x
um+1,j+1 − um−1,j+1 + H2 um,j+1 = H2 (g2 )j+1 . 2∆x
(6.1.19)
(6.1.20)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Parabolic equations
wsdac04
97
The unknown value u−1,j+1 in (6.1.19) can be eliminated by considering (6.1.4) for i = 0 −ru−1,j+1 + (1 + 2r)u0,j+1 − ru1,j+1 − u0,j = 0.
(6.1.21)
Similar arguments are applied when i = m. 6.2
Crank-Nicolson method
Another implicit method for equation (6.1.1) is the Crank-Nicolson method. This is even more accurate than the previous one. Assume that the heat equation is satisfied at the point (i, j + 1/2). Apply the central approximation to the time derivative in such a point and approximate the second-order derivative by the average of the central approximations related to the points (i, j) and (i, j + 1). It follows, fig. 6.2.1, (ui,j+1 − ui,j )/∆t − (ui+1,j+1 − 2ui,j+1 + ui−1,j+1 +ui+1,j − 2ui,j + ui−1,j )/2(∆x)2 = 0.
(6.2.1)
Hence,
Fig. 6.2.1
Crank-Nicolson scheme
−rui−1,j+1 + 2(1 + r)ui,j+1 − rui+1,j+1 = rui−1,j + 2(1 − r)ui,j + rui+1,j ,
(6.2.2)
where r is defined by (6.1.3). The method is implicit. Indeed, the values ui,j+1 cannot be found directly by formula (6.2.2) when the values of ui,j are available.
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
98
The Dirichlet problem with data given by (6.1.5) is discussed as in the last section. Also, the problem can be arranged in an interesting matrix form. By defining the vectors uj , bj u1,j u0,j + u0,j+1 u2,j 0 , uj = = r , b (6.2.3) · · j um−2,j 0 um−1,j um,j + um,j+1 and the (m − 1) × (m − 1) matrices 2(1 + 2r) −r −r 2(1 + 2r) −r · · · C= , · · · −r 2(1 + 2r) −r −r 2(1 + 2r) 2(1 − r) r r 2(1 − r) r · · · D= , · · · r 2(1 − r) r r 2(1 − r)
(6.2.4)
(6.2.5)
it follows Cuj+1 = Duj + bj .
(6.2.6)
Now, let us evaluate the truncation error Ti,j for the Crank-Nicolson method Ti,j = Li,j U,
(6.2.7)
where Li,j denotes the finite-difference operator on the left-hand side of (6.2.1). From Taylor’s expansion it follows Ui,j+1 = Ui,j+1/2 + (Ut )i,j+1/2 ∆t/2 + (Utt )i,j+1/2
+(Uttt )i,j+1/2
(∆t/2)2 2
(∆t/2)3 (∆t/2)3 + (Utttt )i,j+1/2 + O((∆t)5 ), 3! 4!
(6.2.8)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Parabolic equations
Ui,j = Ui,j+1/2 − (Ut )i,j+1/2 ∆t/2 + (Utt )i,j+1/2
−(Uttt )i,j+1/2
99
(∆t/2)2 2
(∆t/2)3 (∆t/2)3 + (Utttt )i,j+1/2 + O((∆t)5 ). 3! 4!
(6.2.9)
Subtracting (6.2.9) from (6.2.8) gives (∆t)2 Ui,j+1 − Ui,j = (Ut )i,j+1/2 + (Uttt )i,j+1/2 + O((∆t)4 ). ∆t 24
(6.2.10)
Similarly, Ui+1,j − 2Ui,j + Ui−1,j (∆x)2 +O((∆x)4 ), (6.2.11) = (Uxx )i,j +(Uxxxx)i,j 2 (∆x) 12 and an analogous result holds when j is replaced by j + 1. Summing the last two expressions yields Ui+1,j − 2Ui,j + Ui−1,j Ui+1,j+1 − 2Ui,j + Ui−1,j+1 + = (Uxx )i,j+1 (∆x)2 (∆x)2
+(Uxx )i,j + [(Uxxxx )i,j+1 + (Uxxxx )i,j ]
(∆x)2 + O((∆x)4 ). 12
(6.2.12)
On the other hand, (Uxx )i,j+1 = (Uxx )i,j+1/2 + (Uxxt )i,j+1/2 ∆t/2
+(Uxxtt )i,j+1/2
(∆t/2)2 (∆t/2)3 + (Uxxttt )i,j+1/2 + O((∆t)4 ), 2 3!
(6.2.13)
(Uxx )i,j = (Uxx )i,j+1/2 − (Uxxt )i,j+1/2 ∆t/2
+(Uxxtt )i,j+1/2
(∆t/2)2 (∆t/2)3 − (Uxxttt )i,j+1/2 + O((∆t)4 ). 2 3!
(6.2.14)
Formula (6.2.13) is summed to (6.2.14) (Uxx )i,j+1 + (Uxx )i,j (∆t/2)2 + O((∆t)4 ) , = 2 (Uxx )i,j+1/2 + (Uxxtt )i,j+1/2 2
(6.2.15)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
100
and the result substituted into (6.2.12) Ui+1,j − 2Ui,j + Ui−1,j Ui+1,j+1 − 2Ui,j + Ui−1,j+1 + 2(∆x)2 2(∆x)2
= (Uxx )i,j+1/2 + (Uxxtt )i,j+1/2
+[(Uxxxx )i,j+1 + (Uxxxx)i,j ]
(∆t)2 8
(∆x)2 + O((∆x)4 + (∆t)4 ). 24
(6.2.16)
Since (Ut )i,j+1/2 − (Uxx )i,j+1/2 = 0, from (6.2.10) and (6.2.16) it follows Li,j U = (Uttt )i,j+1/2
(∆t)2 (∆t)2 − (Uxxtt )i,j+1/2 24 8
−[(Uxxxx )i,j+1 + (Uxxxx)i,j ]
(∆x)2 + O((∆x)4 + (∆t)4 ). 24
(6.2.17)
The principal part of the truncation error is explicitly shown. Scheme (6.2.1) is consistent and Ti,j = O((∆x)2 ) + O((∆t)2 ).
(6.2.18)
Now, consider the boundary conditions of the third kind −Ux (0, t) + H1 U (0, t) = H1 G1 (t),
(6.2.19)
Ux (1, t) + H2 U (0, t) = H2 G2 (t),
(6.2.20)
and focus our attention at the end x = 0. Assuming that equation (6.1.1) holds in this point, it follows − −
u1,j − u−1,j + H1 u0,j = H1 (g1 )j , 2∆x
u1,+1j − u−1,j+1 + H1 u0,j+1 = H1 (g1 )j+1 . 2∆x
(6.2.21)
(6.2.22)
Summing the last two expressions gives u−1,j + u−1,j+1 − u1,j − u1,j+1 + 2∆xH1 (u0,j + u0,j+1 ) = 2∆xH1 [(g1 )j + (g1 )j+1 ].
(6.2.23)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Parabolic equations
wsdac04
101
The fictitious term u−1,j + u−1,j+1 can be eliminated with the aid of (6.2.2) written for i = 0 r(u−1,j + u−1,j+1 ) = 2(1 + r)u0,j+1 − 2(1 − r)u0,j − r(u1,j u1,j+1 ). (6.2.24) From (6.2.23), (6.2.24) it is easy to deduce the equation which provides u0,j+1 when u0,j is available. Similar arguments for i = m. Finally, boundary conditions (6.2.19), (6.2.20) can be also approximated by −
u1,j − u0,j + H1 u0,j = H1 (g1 )j , ∆x
um,j − um−1,j + H2 um,j = H2 (g2 )j . ∆x
(6.2.25)
(6.2.26)
This situation is discussed as in the last section.
6.3
Von Neumann stability
Let us begin with a simple example: a Dirichlet problem for the homogeneous heat equation. This is approximated by the explicit method, described in Chapter 3, ui,j+1 = r (ui+1,j + ui−1,j ) + (1 − 2r) ui,j ,
(6.3.1)
where i = 1, ..., m − 1, j = 0, ..., n − 1, and r is defined by (6.1.3). The initial data are the following ui,0 = ϕ(xi ) = ϕi , i = 0, ..., m, ϕ0 = ϕm = 0, m∆x = 1,
(6.3.2)
and the boundary conditions are assumed to be homogeneous u0,j = 0, um,j = 0, j = 1, ..., n.
(6.3.3)
It can be shown that the solution of problem (6.3.1)-(6.3.3) can be expressed by the discrete Fourier series ui,j =
m−1 p=1
j 2 pπ∆x ap 1 − 4r sin sin(pπi∆x), i = 0, ..., m. 2
(6.3.4)
Here, ap , p = 1, ..., m − 1, are unknown constants which can be determined by initial conditions (6.3.4). Indeed, for j = 0 and i = 1, ..., m − 1, formula
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
102
(6.3.4) provides a system of m − 1 equations related to the above constants m−1
ap sin(pπi∆x) = ϕi , i = 1, ..., m − 1.
(6.3.5)
p=1
Next, note that when i = 0 and i = m, from (6.3.4) it follows u0,j = um,j = 0 and this implies that boundary conditions (6.3.3) are verified. Therefore, it remains to show that ui,j , given by (6.3.4), is solution of (6.3.1). This is easier done if the expression of ui,j is suitably modified. From Euler formulas it follows √ √ √ (6.3.6) sin(pπi∆x) = e −1pπi∆x − e− −1pπi∆x /(2 −1). Substituting (6.3.6) into (6.3.4) and defining ξp = 1 − 4r sin2
pπ∆x , 2
(6.3.7)
yields ui,j =
m−1
m−1 √ √ √ √ (ap /2 −1)ξpj e −1pπi∆x − (ap /2 −1)ξpj e− −1pπi∆x . (6.3.8)
p=1
p=1
Hence, ui,j =
m−1
√ √ (ap /2 −1)ξpj e −1pπi∆x
p=1
−
−1
√ √ (a−p /2 −1)ξpj e −1pπi∆x .
(6.3.9)
p=−(m−1)
It is more convenient to give compact form to this expression. By using the notations √ √ bp = ap /2 −1 if p > 0, bp = −a−p /2 −1 if p < 0, b0 = 0, (6.3.10) formula (6.3.9) is rewritten as ui,j =
m−1
bp ξpj e
√ −1pπi∆x
.
p=−(m−1)
As to ξp , defined by (6.3.7), note that ξp = 1 − 2r[1 − cos(pπ∆x)] = 1 − 2r + 2r cos(pπ∆x)
(6.3.11)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Parabolic equations
103
√ √ = 1 − 2r + r e −1pπ∆x + e− −1pπ∆x .
(6.3.12)
From (6.3.11) and (6.3.12) it follows m−1
ui,j+1 =
bp ξp ξpj e
√ −1pπi∆x
p=−(m−1)
=
m−1
bp ξpj e
√ −1pπi∆x
√ √ 1 − 2r + r e −1pπ∆x + e− −1pπ∆x
p=−(m−1)
= (1 − 2r) ui,j + r (ui+1,j + ui−1,j ) ,
(6.3.13)
which is what we were to prove. The Von Neumann approach to the stability is based on the discrete Fourier series of a numerical scheme. In the example, the series is explicitly provided by (6.3.11). If each harmonic of Fourier series is estimated by the initial data, then the numerical solution will not grow without bound when t increases, giving stability. The criterion takes its name from the scientist who first developed and used it. Since it applies easily, it is the most widely used tool for the stability analysis of finite-difference methods. To simulate an arising error, consider two solutions, (u1 )i,j and (u2 )i,j , of a linear finite-difference scheme with the same boundary conditions and perturbed initial conditions. Evidently, the difference ui,j = (u1 )i,j − (u2 )i,j ,
(6.3.14)
is solution of the homogeneous problem. Following the Von Neumann approach, it is enough to consider only one mode of the Fourier series. In other words, we consider ui,j = ξ j e
√ −1βi∆x
,
(6.3.15)
where ξ is called the amplification factor. From (6.3.15) it is apparent that the error does not amplify if |ξ| ≤ 1.
(6.3.16)
This is the well-known Von Neumann condition for the numerical stability. It is quite severe. A less restrictive condition will be given at the end of this section, where the necessary and the sufficiency of the method will be mentioned.
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
104
To show its application, go back to the initial example and derive ξ in this case. Substituting (6.3.15) into (6.3.1) yields ξ j+1 e
√ −1βi∆x
= ξj e
√ −1βi∆x
[1 − 2r + r(e−
√
−1β∆x
+e
√ −1β∆x
)]. (6.3.17)
Hence, ξ = 1 − 2r + 2r cos(β∆x) = 1 − 2r(1 − cos β∆x) = 1 − 4r sin2 (β∆x/2).
(6.3.18)
In this case, formula (6.3.16) gives −1 ≤ 1 − 4r sin2 (β∆x/2) ≤ 1,
(6.3.19)
which is evidently satisfied if r ≤ 1/2.
(6.3.20)
This stability condition coincides with that already found in Chapter 3. Similarly, the Von Neumann analysis of stability can be applied to implicit methods. Consider the backward-difference scheme discussed in Section 6.1. Substitute (6.3.15) into (6.1.4) to obtain −ξre−
√ −1β∆x
+ ξ(1 + 2r) − ξre
√
−1β∆x
= 1.
(6.3.21)
Hence, ξ[1 + 2r − 2r cos(β∆x)] = 1,
(6.3.22)
ξ = 1/(1 + 4r sin2 (β∆x/2)).
(6.3.23)
This shows that condition (6.3.16) is satisfied for any value of r. The implicit method (6.1.4) is stable for any r, that is, unconditionally stable. However, note that the truncation error increases as O((∆x)2 ) + O(∆t). Analogous arguments can be applied to Crank-Nicolson method (6.2.2). The amplification factor is ξ = 1 − 2r sin2 (β∆x/2)/(1 + 2r sin2 (β∆x/2)).
(6.3.24)
It is easy to realize that also in this case condition (6.3.16) is verified for any r. The method is unconditionally stable. Remark 6.3.1 As already mentioned, condition (6.3.16) is too restrictive and in some situations, as in Example 6.3.1, it can become inadequate. A
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Parabolic equations
wsdac04
105
more general condition, under which the numerical solution does not grow without bound, is the following |ξ| = 1 + O(∆t)
⇔
|ξ| ≤ 1 + C∆t,
(6.3.25)
where the constant C is independent of ∆t, ∆x, β. Example 6.3.1
Consider the equation
Ut − aU − αUxx = 0, a = positive constant.
(6.3.26)
This is approximated by the classical explicit method (ui,j+1 − ui,j )/∆t − aui,j − α(ui+1,j − 2ui,j + ui−1,j )/(∆x)2 = 0. (6.3.27) Applying the Von Neumann method to (6.3.27) gives ξ = 1 − 4r sin2 (β∆x/2) + a∆t, r = α∆t/(∆x)2 .
(6.3.28)
Therefore, stability condition (6.3.25) is satisfied if r ≤ 1/2. Note that, by defining V = U exp(−at) ⇔ U = V exp(at),
(6.3.29)
equation (6.3.26) reduces to the heat equation Vt − αVxx = 0.
(6.3.30)
Remark 6.3.2 All examples emphasize that the influence of boundary conditions is completely neglected by the Von Neumann analysis of stability. In Section 6.7 it will be shown that the stability result (6.3.20) is not correct when special boundary conditions are considered. Therefore, it is clear that the Von Neumann criterion only provides a necessary condition for the stability. In other words, only if the boundary data do not introduce instability, the result obtained by this method is also a sufficient condition. Now, the point is: when does this happen? The answer given by [Thomas (1995)] is simple: when the special numerical initial-boundary-value problem can be solved by a finite Fourier series, that is, when it is correct to consider (6.3.15). A wide and detailed discussion on this topic can be found in [Thomas (1995)].
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
106
6.4
wsdac04
Combined scheme
A more general scheme for the heat equation is the following (ui,j+1 − ui,j )/∆t = [p(ui+1,j+1 − 2ui,j+1 + ui−1,j+1 ) +(1 − p)(ui+1,j − 2ui,j + ui−1,j )]/(∆x)2 ,
(6.4.1)
where p is a suitable weighting parameter. When p = 1/2, from (6.4.1) it follows the Crank-Nicolson method. If p = 1, (6.4.1) reduces to the implicit scheme. Furthermore, if p = 0, the classical explicit scheme is recovered. For values of the parameter p such that 0 ≤ p ≤ 1,
(6.4.2)
formula (6.4.1) provides a further method called, for obvious reasons, combined scheme, or variable-weighted scheme. Now, the stability of this method is discussed by Von Neumann criterion. Substituting (6.3.15) into (6.4.1) gives ξ − 1 = r[pξ(e +(1 − p)(e
√
√
−1β∆x
−1β∆x
+ e−
+ e−
√ −1β∆x
√ −1β∆x
− 2)
(6.4.3)
− 2)],
ξ − 1 = r[2pξ(cos(β∆x) − 1) + 2(1 − p)(cos(β∆x) − 1)],
(6.4.4)
ξ − 1 + 4r[pξ sin2 (β∆x/2) + (1 − p) sin2 (β∆x/2)] = 0,
(6.4.5)
ξ = 1 − 4r(1 − p) sin2 (β∆x/2)/(1 + 4rp sin2 (β∆x/2)).
(6.4.6)
Therefore, condition (6.3.16) is satisfied if −1 − 4rp sin2 (β∆x/2) ≤ 1 − 4r(1 − p) sin2 (β∆x/2),
(6.4.7)
that is, if 2r(1 − 2p) ≤ 1.
(6.4.8)
1 − 2p ≤ 0 ⇔ 1/2 ≤ p ≤ 1,
(6.4.9)
In conclusion, when
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Parabolic equations
wsdac04
107
the combined method is unconditionally stable; otherwise, when p < 1/2, the method is stable if r ≤ 1/2(1 − 2p).
(6.4.10)
Note that (6.4.10) becomes r ≤ 1/2 when p = 0. 6.5
An example of unstable method
If both derivatives in equation (6.1.1) are approximated by the central finitedifference formulas, it follows (ui,j+1 − ui,j−1 )/(2∆t) − (ui+1,j − 2ui,j + ui−1,j )/(∆x)2 = 0.
(6.5.1)
Hence, ui,j+1 − ui,j−1 = 2r[ui−1,j − 2ui,j + ui+1,j ],
(6.5.2)
where r is defined by (6.1.3). This explicit scheme is called Richardson method, or leapfrog method. Since three steps in time are involved, it is a three-time-level method, fig. 6.5.1. This important point will be discussed
Fig. 6.5.1
Richardson scheme
in the next section. Use the Von Neumann criterion to analyze the stability. Substituting (6.3.15) into (6.5.2) gives ξ j+1 − ξ j−1 = 2rξ j (e
√ −1β∆x
+ e−
√ −1β∆x
− 2),
(6.5.3)
|ξ|2 − 1 = 4rξ[cos(β∆x) − 1],
(6.5.4)
|ξ|2 + 8rξ sin2 (β∆x/2) − 1 = 0.
(6.5.5)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
108
The roots ξ1 and ξ2 of this equation are such that ξ1 ξ2 = −1, ξ1 + ξ2 = −8r sin2 (β∆x/2).
(6.5.6)
Therefore, the case |ξ1 | < 1 implies |ξ2 | > 1, giving instability. In the other case ξ1 = ±1, ξ2 = ∓1, condition (6.5.6)2 is compatible only with r = 0. The conclusion is that such a method is unstable in any case. The numerical results obtained by (6.5.2) can be influenced by rounding errors of increasing amplitude. The Richardson method is not reliable.
6.6
DuFort-Frankel method
Consider again (6.5.1) and replace the term ui,j by the average ui,j = (ui,j+1 + ui,j−1 )/2.
(6.6.1)
It follows ui+1,j − (ui,j−1 + ui,j+1 ) + ui−1,j ui,j+1 − ui,j−1 − = 0, 2∆t (∆x)2
(6.6.2)
(1 + 2r)ui,j+1 = 2r(ui−1,j + ui+1,j ) + (1 − 2r)ui,j−1 ,
(6.6.3)
with r defined by (6.1.3). Formula (6.6.3) gives an explicit scheme, called DuFort-Frankel method. This is a three-time-level method, fig. 6.6.1.
Fig. 6.6.1
DuFort-Frankel method
The stability can be discussed by the Von Neumann method. It results (1 + 2r)ξ j+1 = 4rξ j cos(β∆x) + (1 − 2r)ξ j−1 ,
(6.6.4)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Parabolic equations
2r cos(β∆x) ±
1 − 4r2 sin2 (β∆x)
109
.
(6.6.5)
If 1 − 4r sin2 (β∆x) < 0, then (6.6.5) yields 2r cos(β∆x) ± I 4r2 sin2 (β∆x) − 1 , ξ= 1 + 2r √ where, I= −1. Hence,
(6.6.6)
ξ=
1 + 2r
|ξ|2 =
4r2 − 1 < 1. 1 + 4r + 4r2
Instead, if 1 − 4r sin2 (β∆x) ≥ 0, then it is easy to realize that −1 − 2r ≤ 2r cos(β∆x) ± 1 − 4r2 sin2 (β∆x) ≤ 1 + 2r,
(6.6.7)
(6.6.8)
which is equivalent to |ξ| ≤ 1.
(6.6.9)
Consequently, the DuFort-Frankel method is unconditionally stable. As already remarked, we are dealing with a three-time-level method. This aspect has to be discussed. Write (6.6.3) for j = 0, 1, (1 + 2r)ui,1 = 2r(ui−1,0 + ui+1,0 ) + (1 − 2r)ui,−1 ,
(6.6.10)
(1 + 2r)ui,2 = 2r(ui−1,1 + ui+1,1 ) + (1 − 2r)ui,0 .
(6.6.11)
Formula (6.6.10) shows that ui,1 cannot be determined, because of the fictitious values ui,−1 . On the other hand, the values ui,1 are necessary in formula (6.6.11). To eliminate the ghost values, use (6.1.1) for j = 0, 2ui,0 = ui,1 + ui,−1 .
(6.6.12)
Solve with respect to ui,−1 and substitute the result into (6.6.10) to obtain ui,1 = (ui−1,0 + ui+1,0 ) + (1 − 2r)ui,0 .
(6.6.13)
This is what we needed to go on. Note that (6.6.13) is just the starting step of the classical explicit method. An interesting question of the DuFort-Frankel method is the analysis of the consistency. Denote by Li,j the finite-difference operator on the
July 3, 2004
23:17
110
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
left-hand side of (6.6.2), so that this formula is rewritten in compact form as Li,j u = 0.
(6.6.14)
The truncation error is expressed by Ti,j = Li,j U.
(6.6.15)
Using Taylor series gives Ui,j+1 = Ui,j + (Ut )i,j ∆t + (Utt )i,j
(∆t)2 (∆t)3 + (Uttt )i,j + ..., (6.6.16) 2 6
Ui,j−1 = Ui,j − (Ut )i,j ∆t + (Utt )i,j
(∆t)2 (∆t)3 − (Uttt )i,j + ..., (6.6.17) 2 6
Ui+1,j = Ui,j + (Ux )i,j ∆x + (Uxx )i,j
(∆x)2 (∆x)3 + (Uxxx)i,j + ..., (6.6.18) 2 6
Ui−1,j = Ui,j − (Ux )i,j ∆x + (Uxx )i,j
(∆x)2 (∆x)3 − (Uxxx )i,j + .... (6.6.19) 2 6
From (6.6.16)-(6.6.19) it follows Ui,j+1 − Ui,j−1 /(2∆t) = (Ut )i,j + (Uttt )i,j
(∆t)2 + O((∆t)4 ), 6
Ui,j+1 + Ui,j−1 = 2Ui,j + (Utt )i,j (∆t)2 + O((∆t)4 ),
(6.6.20) (6.6.21)
Ui+1,j + Ui−1,j = 2Ui,j + (Uxx )i,j (∆x)2 +(Uxxxx)i,j
(∆x)4 + O((∆x)6 ). 12
(6.6.22)
Substituting (6.6.20)-(6.6.22) into (6.6.15) gives Ti,j = (Uttt )i,j
(∆t)2 (∆x)2 (∆t)2 − (Uxxxx )i,j + (Utt )i,j 6 12 (∆x)2
+O((∆x)4 ) + O((∆t)4 ) + O((∆t)4 /(∆x)2 ),
(6.6.23)
because of (Ut − Uxx )i,j = 0. The analysis of the consistency leads to consider the limit of truncation error (6.6.23), as ∆x, ∆t → 0. Since the ratio O((∆t)2 /(∆x)2 ) is involved,
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Parabolic equations
wsdac04
111
much attention is required. The consistency depends on how ∆x and ∆t tend to zero. Indeed, if ∆t → 0 faster than ∆x, for example, ∆t = c(∆x)2 , c = constant, Ti,j goes to zero and the method DuFort-Frankel is consistent with the approximating partial differential equation (6.1.1). If ∆x and ∆t tend to zero at the same ratio, say ∆t = c∆x, c = constant, the scheme is inconsistent with the heat equation, although it is compatible with the hyperbolic equation Ut − Uxx + c2 Utt = 0. If ∆x → 0 faster than ∆t, Ti,j goes to infinity and the scheme is inconsistent. This result imposes a constraint to the mesh dimensions and a bound to the unconditional freedom allowed by the stability analysis. It is interesting to give matrix form to (6.6.3). Indeed, this allows us to show that a three-time-level method can be formally reduced to a twotime-level method. Define the vectors uj , bj
u1,j u2,j ·
, uj = um−2,j um−1,j
u0,j 0 bj = 2r · , 0 um,j
and the (m − 1) × (m − 1) matrix 0 1 1 0 1 · · · A= . · · · 1 0 1 1 0
(6.6.24)
Using these notations, (6.6.3) can be written as uj+1 = pAuj + quj−1 + bj ,
(6.6.25)
July 3, 2004
23:17
112
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
where p=
2r 1 − 2r , q= . 1 + 2r 1 + 2r
Now, consider the expression uj+1 pA qIm−1 uj bj = + , uj uj−1 0 Im−1 Om−1
(6.6.26)
(6.6.27)
where Im−1 is the unit matrix or order m − 1 and Om−1 is the zero matrix. Note that (6.6.27) is equivalent to (6.6.25). In addition, by defining uj bj pA qIm−1 , vj = , cj = B= , (6.6.28) uj−1 0 Im−1 Om−1 equation (6.6.27) becomes vj+1 = Bvj + cj ,
(6.6.29)
which is typical of two-time-level schemes.
6.7
Matrix stability
Consider an initial-boundary-value problem and assume that the corresponding finite-difference problem can be arranged in matrix form as follows uj = Auj−1 + bj−1 ,
(6.7.1)
where bj−1 is the vector of the known terms, depending on boundary conditions and source term. Examples were provided in Chapter 3 and in Sections 6.1, 6.2, 6.6 of this chapter. Denote by (u1 )i,j , (u2 )i,j two solutions of (6.7.1), which have the same boundary conditions, but different data at a prefixed time, say the initial one. If it is assumed that (u1 )i,j is the exact solution and (u2 )i,j represents the solution perturbed by a rounding error arising at the initial time, the stability analysis leads to consider ui,j = (u1 )i,j − (u2 )i,j .
(6.7.2)
This difference satisfies the homogeneous problem, that is, equation (6.7.1) with homogeneous boundary conditions and vanishing source term. There-
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Parabolic equations
113
uj = Auj−1 .
(6.7.3)
uj = Aj u0 .
(6.7.4)
fore,
Hence,
Next, note that, for every matrix norm ||.||, compatible with vector norm, from (6.7.4) it follows ||uj || = ||Aj u0 ||,
(6.7.5)
||uj || ≤ ||Aj ||||u0 ||.
(6.7.6)
Consequently, a necessary and sufficient condition for the stability of numerical scheme (6.7.4) is ||Aj || ≤ K,
(6.7.7)
where the positive constant K is independent of ∆x, ∆t, ||u0 ||. Indeed, from the stability definition ||uj || ≤ K||u0 ||,
(6.7.8)
||Aj u0 || ≤ K, (||u0 || =
0), ||u0 ||
(6.7.9)
and from (6.7.5) it follows
which implies (6.7.7). Conversely, from condition (6.7.7) and inequality (6.7.6) we immediately find (6.7.8). Note that condition (6.7.7) is clearly satisfied when ||A|| ≤ 1.
(6.7.10)
Also, it is satisfied under the less restrictive condition ||A|| = 1 + O(∆t), ⇔ ||A|| ≤ 1 + C∆t,
(6.7.11)
where C is a constant independent of ∆t, ∆x. Indeed, for j∆t ≤ T we have ||Aj || ≤ ||A||j ≤ (1 + C∆t)j ≤ (1 + CT /j)j ≤ exp(CT ).
(6.7.12)
Now, the application of the matrix method is illustrated by examples.
July 3, 2004
23:17
114
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
Example 6.7.1 In Section 3.3, the Dirichlet problem for the heat equation was arranged in matrix form as (6.7.1). In this case the matrix A is the following (m − 1) × (m − 1) tridiagonal matrix 1 − 2r r r 1 − 2r r · · · A= (6.7.13) . · · · r 1 − 2r r r 1 − 2r It is easy to realize that ||A||1 = ||A||∞ = 2r + |1 − 2r|,
(6.7.14)
showing that, only when r ≤ 1/2,
(6.7.15)
condition (6.7.10) satisfied with ||A||1 = ||A||∞ = 1. We have the same conclusion if ||A||2 is applied. Indeed, the eigenvalues of A are expressed by λi = 1 − 2r + 2r cos(iπ/m) = 1 − 4r sin2 (iπ/2m).
(6.7.16)
Therefore, |λi | ≤ 1 only if (6.7.15) is satisfied. Example 6.7.2 In Section 3.8, the problem, related to the heat equation with boundary conditions of third kind, was discussed by the classical explicit method. Also, the problem was reduced to matrix form (6.7.1), where the (m + 1) × (m + 1) matrix A is given by 1 − 2r(1 + H1 ∆x) 2r r 1 − 2r r · ·· A= . (6.7.17) ·· · r 1 − 2r r 2r 1 − 2r(1 + H2 ∆x) Assume r ≤ min{1/(2 + H1 ∆x), 1/(2 + H2 ∆x)},
(6.7.18)
and note that this is equivalent to |1 − 2r(1 + Hi ∆x)| + 2r ≤ 1, i = 1, 2.
(6.7.19)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Parabolic equations
wsdac04
115
Consequently, it results ||A||∞ = 1, showing that the scheme is stable, under the assumption (6.7.18). This proof is given in [Smith (1985)]. The last example shows that the boundary data can influence the stability condition and the matrix analysis is able to emphasize all this. Example 6.7.3 Consider the implicit method discussed in Section 6.1. The Dirichlet problem is given by (6.1.15), which can be rewritten as uj+1 = C −1 uj + C −1 bj+1 .
(6.7.20)
Here, A = C −1 , where C is defined by (6.1.14). The eigenvalues of A are expressed by λi = 1/[1 + 2r − 2r cos(iπ/m)] = 1/[1 + 4r sin2 (iπ/2m)].
(6.7.21)
Hence, |λi | ≤ 1 for any value of r. Consequently, ||A||2 ≤ 1, implying unconditional stability. Example 6.7.4 In Section 6.2 the Crank-Nicolson method was discussed. The Dirichlet problem is expressed in matrix form by (6.2.6). In this case A = C −1 D, where C and D are the symmetric matrices defined by (6.2.4) and (6.2.5), respectively. Since CD = DC, also the matrix A = C −1 D is symmetric. Therefore, ||A||2 = ρ(A). Moreover, the eigenvalues of A are expressed by λi = [1 − 2r sin2 (iπ/2m)]/[1 + 4r sin2 (iπ/2m)].
(6.7.22)
Hence, |λi | ≤ 1 for any r, proving that the above method is unconditionally stable. Remark 6.7.1 In Appendix B, Section 2, it is proved that the spectral radius ρ(A) of the matrix A is bounded by the matrix norm ρ(A) ≤ ||A||.
(6.7.23)
In addition, if A is a real symmetric matrix, it is shown that ρ(A) = ||A||2 ,
(6.7.24)
where ||A||2 denotes the energy norm of A. From these estimates it follows that the spectral condition ρ(A) ≤ 1,
(6.7.25)
July 3, 2004
23:17
116
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
always provides a sufficient condition for the stability. Furthermore, when A is a real symmetric matrix, spectral stability condition (6.7.25) becomes also sufficient for the finite-difference method to be stable. An example is considered below. Other applications can be found in [DuChateau and Zachmann (1989)]. Example 6.7.5 Consider the DuFort-Frankel method discussed in Section 6.6. In this case the role of A is played by the block matrix B pA qIm−1 B= , (6.7.26) Im−1 Om−1 where p, q are given by (6.6.26), A is defined by (6.6.24), and Im−1 is the unit matrix or order m − 1. Since the four sub-matrices of B have the same eigenvectors, the eigenvalues of B are obtained by considering the matrix pαi q . (6.7.27) 1 O Here, αi denotes the ith eigenvalue of A, expressed by αi = 2 cos(iπ/m), i = 1, ..., m − 1.
(6.7.28)
Therefore, the eigenvalues of B are
λ=
2r cos(iπ/m) ±
1 − 4r2 sin2 (iπ/m) 1 + 2r
,
(6.7.29)
and in Section 6.6 has been shown that |λ| ≤ 1. 6.8
Stability analysis by the energy method
The energy method to analyze the stability was first developed by Richtmayer and Morton in [Richtmyer and Morton (1967)]. It reveals evident analogies with the energy method applied in the qualitative analysis of solutions of partial differential equations and this is the origin of its name. The method uses the properties of a functional along the solutions of finitedifference equations in order to deduce necessary conditions for the stability. It is applicable to equations with variable coefficients and even to nonlinear equations. Most difficulties arise in finding suitable functionals.
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Parabolic equations
wsdac04
117
The method will be illustrated by examples, but some preliminary identities are necessary. At first, note that m−1
vi (zi+1 − zi ) = −
m−1
i=1
zi+1 (vi+1 − vi ) − v0 z1 + vm zm .
(6.8.1)
i=0
Indeed, m−1
vi (zi+1 − zi ) =
m−1
i=1
vi zi+1 − v0 z1 −
i=0
=
m−2
vi+1 zi+1
i=0
m−1
vi zi+1 −
i=0
m−1
vi+1 zi+1 − v0 z1 + vm zm .
i=0
Hence, (6.8.1). Moreover, it is m−1
vi (zi − zi−1 ) = −
i=1
m−1
zi (vi+1 − vi ) − v0 z0 + vm zm−1 .
(6.8.2)
i=0
Indeed, m−1
vi (zi − zi−1 ) =
i=1
m−1
vi zi − v0 z0 −
i=0
=
m−1 i=0
vi zi −
m−2
vi+1 zi
i=0 m−1
vi+1 zi − v0 z0 + vm zm−1 ,
i=0
which implies (6.8.2). Now, denote by (u1 )i,j , (u2 )i,j two solutions of a finite-difference scheme, which have the same boundary conditions, but different initial. If we assume that (u1 )i,j is the exact solution and (u2 )i,j represents the solution perturbed by a rounding error arising at the initial time, the stability analysis leads to consider ui,j = (u1 )i,j − (u2 )i,j .
(6.8.3)
The difference ui,j is solution of the homogeneous equation only in the linear situation. In any case satisfies homogeneous boundary conditions. In the next examples we refer to ui,j defined by (6.8.3).
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
118
Example 6.8.1 In the case of the classic explicit scheme with Dirichlet boundary conditions, ui,j satisfies the equation ui,j+1 − ui,j = r[ui+1,j − ui,j − (ui,j − ui−1,j )], i = 1, ..., m − 1, (6.8.4) and the boundary conditions u0,j = um,j = 0 j = 1, ..., n.
(6.8.5)
Multiply (6.8.4) by ui,j+1 + ui,j and sum over i = 1, ..., m − 1 m−1
(u2i,j+1 − u2i,j )
i=1
=r
m−1
[(ui,j+1 + ui,j )(ui+1,j − ui,j ) − (ui,j+1 + ui,j )(ui,j − ui−1,j )]. (6.8.6)
i=1
Next, use (6.8.1) and (6.8.2) with vi = ui,j+1 + ui,j , zi = ui,j ;
(6.8.7)
in addition, note that v0 = vm = 0, because of (6.8.5). So, we obtain m−1
(u2i,j+1 − u2i,j )
i=1
= −r
m−1
[(ui+1,j − ui,j )2 + (ui+1,j+1 − ui,j+1 )(ui+1,j − ui,j )].
(6.8.8)
i=0
Now, consider the energy functional Ej =
m−1
u2i,j −
i=1
= ||uj ||22 −
m−1 r (ui+1,j − ui,j )2 2 i=0
m−1 r (ui+1,j − ui,j )2 . 2 i=0
(6.8.9)
Using this in (6.8.8) gives Ej+1 = Ej −
m−1 r [(ui+1,j − ui,j ) + (ui+1,j+1 − ui,j+1 )]2 . 2 i=0
(6.8.10)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Parabolic equations
119
Hence, Ej+1 ≤ Ej ... ≤ E0 ≤ ||u0 ||22 .
(6.8.11)
Furthermore, Ej+1 ≥ ||uj+1 ||22 − r
m−1
[u2i+1,j+1 + u2i,j+1 ],
(6.8.12)
Ej+1 ≥ ||uj+1 ||22 − 2r||uj+1 ||22 ≥ (1 − 2r)||uj+1 ||22 .
(6.8.13)
i=0
In conclusion, if r ≤ 1/2,
(6.8.14)
||uj+1 ||22 ≤ ||u0 ||22 /(1 − 2r),
(6.8.15)
from (6.8.11), (6.8.13) it follows
showing the stability of the scheme, under the well-known condition (6.8.14). This result is given in [Mitchell and Griffiths (1995)]. Example 6.8.2 tion 6.1
Consider the backward implicit scheme, discussed in Sec-
ui,j+1 − ui,j = r[ui+1,j+1 − ui,j+1 − (ui,j+1 − ui−1,j+1 )],
(6.8.16)
and assume that (6.8.5) holds. Multiply (6.8.16) by ui,j+1 + ui,j and sum over i = 1, ..., m − 1 m−1
m−1
i=1
i=1
(u2i,j+1 − u2i,j ) = r
[(ui,j+1 + ui,j )(ui+1,j+1 − ui,j+1 )
−(ui,j+1 + ui,j )(ui,j+1 − ui−1,j+1 )].
(6.8.17)
Apply (6.8.1), (6.8.2), as in the earlier example, m−1
m−1
i=1
i=0
(u2i,j+1 − u2i,j ) = −r
[(ui+1,j+1 − ui,j+1 )2
+(ui+1,j+1 − ui,j+1 )(ui+1,j − ui,j )].
(6.8.18)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
120
Next, the energy functional Ej =
m−1
u2i,j
i=1
||uj ||22
=
m−1 r + (ui+1,j − ui,j )2 2 i=0
m−1 r + (ui+1,j − ui,j )2 2 i=0
(6.8.19)
is inserted into (6.8.18) Ej+1 = Ej −
m−1 r [(ui+1,j − ui,j ) + (ui+1,j+1 − ui,j+1 )]2 . 2 i=0
(6.8.20)
From this Ej+1 ≤ Ej ... ≤ E0 .
(6.8.21)
||uj+1 ||22 ≤ Ej+1 , E0 ≤ (1 + 2r)||u0 ||22 .
(6.8.22)
Finally, note that
Example 6.8.3 tion 6.2
Consider the Crank-Nicolson scheme, discussed in Secr [(ui+1,j+1 − ui,j+1 ) − (ui,j+1 − ui−1,j+1 )] 2
ui,j+1 − ui,j =
r + [(ui+1,j − ui,j ) − (ui,j − ui,j )]. 2
(6.8.23)
Use the arguments of the previous examples to derive ||uj+1 ||22 − ||uj ||22 = −
m−1 r [(ui+1,j+1 − ui,j+1 ) + (ui+1,j − ui,j )]2 . (6.8.24) 2 i=0
From (6.8.24) it follows ||uj+1 ||22 ≤ ...||u0 ||22 .
(6.8.25)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Parabolic equations
6.9
wsdac04
121
Variable diffusivity coefficient
Consider the one-dimensional heat equation Ut − α(x, t)Uxx = 0,
(6.9.1)
and assume that the diffusivity coefficient α is a strictly positive function of x and t. The methods introduced in the case of constant coefficient can easily be modified for this situation. Let us show, for example, how the classic explicit method works. It results ui+1,j − 2ui,j + ui−1,j ui,j+1 − ui,j = αi,j . ∆t ∆x2
(6.9.2)
where αi,j = α(xi , tj ) = α(i∆x, j∆t). With the usual definition r = ∆t/∆x2 ,
(6.9.3)
ui,j+1 = (1 − 2rαi,j )ui,j + rαi,j (ui+1,j + ui−1,j ),
(6.9.4)
from (6.9.2) it follows
which allows us to integrate numerically equation (6.9.1), when the initial and the boundary data are prescribed. Scheme (6.9.4) is conditionally stable. Indeed, if the following condition 1 − 2rαi,j ≥ 0, ∀i, j,
(6.9.5)
is satisfied, from (6.9.4) it follows
6.10
|ui,j+1 | ≤ (1 − 2rαi,j )||uj ||∞ + 2rαi,j ||uj ||∞ ,
(6.9.6)
||uj+1 ||∞ ≤ ||u0 ||∞ .
(6.9.7)
Heat equation in two and three space dimensions
The heat equation in two and three space dimensions is involved in several physical questions, not necessarily related to thermal processes. In this section the classic explicit method is generalized to these situations. At first, consider the two-dimensional equation Ut − α(Uxx + Uzz ) = 0.
(6.10.1)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
122
Use the forward approximation for Ut and the central approximations for the second-order derivatives to obtain ui+1,k,j − 2ui,k,j + ui−1,k,j ui,k,j+1 − ui,k,j =α ∆t ∆x2
+α
(6.10.2)
ui,k+1,j − 2ui,k,j + ui,k−1,j . ∆z 2
By defining r1 = α∆t/(∆x)2 , r2 = α∆t/(∆z)2 ,
(6.10.3)
equation (6.10.2) is rewritten as ui,k,j+1 = (1 − 2r1 − 2r2 )ui,k,j + r1 (ui+1,k,j + ui−1,k,j )
(6.10.4)
+r2 (ui,k+1,j + ui,k−1,j ). Note that the role of r is played by r1 + r2 and it can be shown that the stability condition becomes r1 + r2 ≤ 1/2.
(6.10.5)
Indeed, apply the Von Neumann criterion and consider ui,k,j = ξ j eIβi∆x eIγk∆y .
(6.10.6)
Substituting (6.10.6) into (6.10.4) gives ξ = 1 − 2r1 − 2r2 + 2r1 cos(β∆x) + 2r1 cos(γ∆y), ξ = 1 − 4r1 sin2 (β∆x/2) − 4r2 sin2 (γ∆y/2).
(6.10.7)
(6.10.8)
Hence, under the assumption (6.11.5), |ξ| ≤ 1. Similarly, the three-dimensional case can be discussed.
(6.10.9)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Parabolic equations
6.11
wsdac04
123
Diffusion-convection equation
The diffusion-convection equation, governing thermal processes for moving solids, was derived in Chapter 2. In the one-dimensional model, and if there is no source term, this equation is given by Ut + vUx − αUxx = 0.
(6.11.1)
At first, assume that v is constant. Consider the forward approximation for Ut and the central approximations for the space derivatives. It follows Ui+1,j − Ui−1,j Ui,j+1 − Ui,j = −v ∆t 2∆x +α
Ui+1,j − 2Ui,j + Ui−1,j + O(∆t) + O((∆x)2 ). (∆x)2
(6.11.2)
Therefore, a finite-difference method, consistent with partial differential equation (6.11.1), is the following ui,j+1 − ui,j ui+1,j − ui−1,j ui+1,j − 2ui,j + ui−1,j = −v +α . ∆t 2∆x (∆x)2
(6.11.3)
Hence, setting r = ∆t/(∆x)2 ,
s = ∆t/∆x,
(6.11.4)
it follows ui,j+1 = (1−2rα)ui,j −(sv/2)(ui+1,j −ui−1,j )+rα(ui+1,j +ui−1,j ), (6.11.5) or, ui,j+1 = (rα + sv/2)ui−1,j + (1 − 2rα)ui,j + (rα − sv/2)ui+1,j . (6.11.6) This scheme is conditionally stable, as shown by the Von Neumann criterion. The amplification factor is √ ξ = 1 − 2rα[1 − cos(β∆x)] − vs −1 sin(β∆x). (6.11.7) Hence, |ξ|2 = [1 − 4rα sin2 (β∆x/2)]2 + v 2 s2 sin2 (β∆x).
(6.11.8)
Therefore, if v 2 s2 ≤ 2rα, 2rα ≤ 1,
(6.11.9)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
124
then |ξ|2 ≤ [1 − 4rα sin2 (β∆x/2)]2 + 8rα sin2 (β∆x/2)[1 − sin2 (β∆x/2)] ≤ 1 − 8rα(1 − 2rα) sin4 (β∆x/2) ≤ 1.
(6.11.10)
The product s|v| is called Courant number. When the stability conditions (6.11.9) are fulfilled, the following estimate holds s|v| ≤ 1.
(6.11.11)
Remark 6.11.1 If α = 0, equation (6.11.1) reduces to the first-order hyperbolic equation Ut + vUx = 0,
(6.11.12)
which will be considered in Chapter 10. In this case, scheme (6.11.5) becomes ui,j+1 = ui,j − (sv/2)(ui+1,j − ui−1,j ),
(6.11.13)
and condition (6.11.8) reduces to |ξ|2 = 1 + v 2 s2 sin2 (β∆x) > 1.
(6.11.14)
Consequently, the algorithm (6.11.13) is unstable. The diffusivity coefficient is essential to stabilize the scheme. This remark is the starting point of interesting developments.
Exercise 6.11.1 Note that scheme (6.11.6) can be arranged in the following matrix form uj+1 = Auj + bj , where
1 − 2rα rα + sv 2 A=
rα − sv 2 1 − 2rα ·
(6.11.15)
rα − · ·
sv 2
· · rα +
sv 2
· 1 − 2rα rα + sv 2
, sv rα − 2 1 − 2rα
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Parabolic equations
uj =
u1,j · · ·
, bj =
(rα +
sv 2 )u0,j
0 · 0 (rα −
um−1,j
125
.
sv 2 )um,j
Discuss the matrix stability by the norms ||A||∞ , ||A||1 , ||A||2 . Consider equation (6.11.1) and assume that v is a function of x and t Ut + v(x, t)Ux − αUxx = 0.
(6.11.16)
Algorithm (6.11.6) is easily modified to obtain ui,j+1 = (rα+svi,j /2)ui−1,j +(1−2rα)ui,j +(rα−svi,j /2)ui+1,j . (6.11.17) Exercise 6.11.2 tions
Verify that scheme (6.11.17) is stable under the assump1 − 2rα ≥ 0,
Exercise 6.11.3
rα − s|vi,j |/2 ≥ 0.
(6.11.18)
Discuss the equation Ut + v(x, t)Ux − α(x, t)Uxx = 0.
(6.11.19)
If the sign of v(x, t) is known, then using the forward or the backward approximation allows to relax the very restrictive conditions (6.11.9). When v(x, t) is negative, the forward approximation is applied ui+1,j − 2ui,j + ui−1,j ui+1,j − ui,j ui,j+1 − ui,j = −vi,j +α , ∆t ∆x (∆x)2
(6.11.20)
ui,j+1 = rαui−1,j + (1 − 2rα + svi,j )ui,j + (rα − svi,j )ui+1,j .
(6.11.21)
Instead, if v(x, t) > 0, using backward approximation yields ui,j+1 = (rα + svi,j )ui−1,j + (1 − 2rα − svi,j )ui,j + rαui+1,j . Exercise 6.11.4
(6.11.22)
Verify that scheme (6.11.21) is stable if 1 − 2rα + svi,j ≥ 0,
(6.11.23)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
126
and that the stability condition of (6.11.22) is given by 1 − 2rα − svi,j ≥ 0.
(6.11.24)
The method can be generalized to the case of two space dimensions Ut + v1 (x, y, t)Ux + v2 (x, y, t)Uy − α(Uxx + Uyy ) = 0,
(6.11.25)
without difficulties. By defining r1 = ∆t/(∆x)2 , r2 = ∆t/(∆y)2 , s1 = ∆t/∆x, s2 = ∆t/∆y, it follows
(6.11.26)
s1 ui−1,k,j ui,k,j+1 = r1 α + (v1 )i,k,j 2 s2 ui,k−1,j + (1 − 2r1 α − 2r2 α)ui,k,j + r2 α + (v2 )i,k,j 2
s1 s2 ui+1,k,j + r2 α − (v2 )i,k,j ui,k+1,j . + r1 α − (v1 )i,k,j 2 2
(6.11.27)
This is stable under the hypotheses s1 s2 1−2r1 −2r2 ≥ 0, r1 α− |(v1 )i,k,j | ≥ 0, r2 α− |(v2 )i,k,j | ≥ 0. (6.11.28) 2 2 Similarly, the three-dimensional case can be treated. Numerical solutions of convection-diffusion problems are widely discussed in recent monographs: [Bellomo and Preziosi (1995)], [Hundsdorfer and Verner (2003))], [Morton (1996)]. 6.12
Nonlinear equation
Consider the equation Ut = Φ(U, Ux ) + αUxx ,
(6.12.1)
where Φ denotes a linear or nonlinear function of its arguments. For example, if Φ = cU 2 , equation (6.12.1) becomes Ut = cU 2 + αUxx .
(6.12.2)
When Φ = −U Ux , from (6.12.1) it follows Ut = −U Ux + αUxx .
(6.12.3)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Parabolic equations
wsdac04
127
Use the forward approximation for the time derivative and the central approximation for the space derivatives to obtain the following finite-difference scheme ui,j+1 = ui,j + ∆tΦ(ui,j , (ui+1,j − ui−1,j )/2∆x) +rα(ui+1,j − 2ui,j + ui−1,j ),
(6.12.4)
where r is defined by (6.11.4). To analyze the stability of scheme (6.12.4), denote by v and z two solutions related to different initial data and let u be the difference u = v − z.
(6.12.5)
From (6.12.4) it follows ui,j+1 = ui,j + ∆tΦ(vi,j , (vi+1,j − vi−1,j )/2∆x) −∆tΦ(zi,j , (zi+1,j − zi−1,j )/2∆x) + rα(ui+1,j − 2ui,j + ui−1,j ). (6.12.6) Applying the mean value theorem gives ui,j+1 = ui,j + ∆t[Φu ui,j + Φux (ui+1,j − ui−1,j )/2∆x)] +rα(ui+1,j − 2ui,j + ui−1,j ),
(6.12.7)
where the partial derivatives of Φ are evaluated at a point between v and z. Hence, it follows ui,j+1 = (1 + Φu ∆t − 2rα)ui,j + (rα − Φux s/2)ui−1,j +(rα + Φux s/2)ui+1,j ,
(6.12.8)
where s is defined by (6.11.4). Next, note that, setting M = sup |Φu |, M1 = sup |Φux |, (x,t)
(6.12.9)
(x,t)
the following relations hold 1 + Φu ∆t − 2rα ≥ 1 − M ∆t − 2rα, rα ± Φux s/2 ≥ rα − M1 s/2. (6.12.10) Therefore, if 1 − M ∆t − 2rα ≥ 0,
rα − M1 s/2 ≥ 0,
(6.12.11)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
128
from (6.12.8) it follows ||uj+1 ||∞ ≤ (1 + M ∆t)||uj ||∞ , ||uj ||∞ = max |ui,j |, i
||uj ||∞ ≤ (1 + M ∆t)j ||u0 ||∞ .
(6.12.12) (6.12.13)
Furthermore, for j∆t = t ≤ T , ||uj ||∞ ≤ (1 + M T /j)j ||u0 ||∞ ≤ exp(M T )||u0 ||∞ ,
(6.12.14)
showing the conditional stability of scheme (6.12.4). Note that conditions (6.12.11) are certainly satisfied when 0 < r ≤ (1 − M ∆t)/2α, ∆x ≤ 2α/M1 . Exercise 6.12.1
(6.12.15)
Generalize the previous arguments to the equation Ut = Φ(U, Ux , Uxx ),
(6.12.16)
where the function Φ is such that Φuxx ≥ α > 0. 6.13
(6.12.17)
A free boundary problem
Free boundary problems have been introduced in Chapter 2 with reference to phase-change processes. A special case is the one-phase Stefan problem described by the following equations, fig. 6.13.1,
Fig. 6.13.1
One-phase Stefan problem
ut (x, t) = αuxx (x, t), (x, t) ∈ Ω = {0 < x < s(t), 0 < t ≤ T },
(6.13.1)
July 29, 2004
15:48
WSPC/Book Trim Size for 9in x 6in
Parabolic equations
wsdac04
129
u(x, 0) = ϕ(x) ≥ um , 0 ≤ x ≤ s(0),
(6.13.2)
u(0, t) = g(t) ≥ um , 0 ≤ t ≤ T,
(6.13.3)
u(s(t), t) = um , 0 ≤ t ≤ T,
(6.13.4)
˙ 0 ≤ t ≤ T, −kux (s(t), t) = ρLs(t),
(6.13.5)
where α and k are the diffusivity and conductivity coefficients, um denotes the melting temperature, ρ the density and L the latent heat. The unknowns involved in these equations are the temperature u(x, t) and the function s(t), which describes the interface evolution. It can be shown that this function is not decreasing, according to physical experiences. Indeed, from the maximum principle it follows u(x, t) ≥ um , (x, t) ∈ Ω.
(6.13.6)
This implies u(x, t) − u(s(t), t) u(x, t) − um = ≤ 0, (x, t) ∈ Ω. x − s(t) x − s(t)
(6.13.7)
Therefore, from (6.13.5) it follows s(t) ˙ ≤ 0.
(6.13.8)
Let us illustrate a finite-difference method for problem (6.13.1)-(6.13.5), [Crank (1984)]. Preliminarily, the interpolation formulas of Lagrangian type are necessary. The three-point formulas are the following, see e.g. [Quarteroni, Sacco and Saleri (2002)], f (x) =
2
i (x)f (ai ),
(6.13.9)
i=0
where 0 (x) =
(x − a1 )(x − a2 ) , (a0 − a1 )(a0 − a2 ) 2 (x) =
1 (x) =
(x − a0 )(x − a2 ) , (a1 − a0 )(a1 − a2 )
(x − a0 )(x − a1 ) . (a2 − a0 )(a2 − a1 )
(6.13.10)
(6.13.11)
July 29, 2004
16:14
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
130
By assuming a0 = (n − 2)∆x, a1 = (n − 1)∆x, a2 = (n − 1 + p)∆x, from (6.13.9) it follows 1 pf (a0 ) (1 + p)f (a1 ) (1 + 2p)f (a2 ) f (a2 ) = − + , ∆x 1 + p p p(1 + p) f (x) =
f (a0 ) f (a1 ) f (a2 ) 2 − + . (∆x)2 1 + p p p(1 + p)
(6.13.12)
(6.13.13)
(6.13.14)
Now, suppose that the temperature and the free boundary location are known at the time tj uij = u(xi , tj ), i = 0, ..., nj − 1,
(6.13.15)
sj = s(tj ).
(6.13.16)
Denote by nj the node such that (nj − 1)∆x < sj < nj ∆x and let pj ∆x be the distance of the free boundary from nj − 1, fig. 6.13.1. Apply (6.13.13)
Fig. 6.13.2
Free boundary
to the function u(x, tj ) with ai , i = 0, 1, 2, expressed by (6.13.12), (1 + pj )unj −1,j (1 + 2pj )um 1 pj unj −2,j . (6.13.17) − + ux (sj , tj ) = ∆x 1 + pj pj pj (1 + pj ) This relation is used in (6.13.5) to determine the position of the free boundary at the next time tj+1 sj+1 = sj − k∆t ux (sj , tj )/ρL.
(6.13.18)
July 29, 2004
16:22
WSPC/Book Trim Size for 9in x 6in
wsdac04
Parabolic equations
131
For t = tj+1 and for i < nj − 1, the temperature can be evaluated by the classical explicit method uij+1 = uij + r(ui−1j − 2uij + ui+1j ), i = 1, ..., nj − 2,
(6.13.19)
where r = α∆t/(∆x)2 .
(6.13.20)
When i = nj − 1, (6.13.19) cannot be used. However, from (6.13.1) uij+1 = uij + α∆t(uxx )ij ,
(6.13.21)
where the second-order partial derivative can be evaluated by means of (6.13.14) unj −1,j unj −2,j 2 um . (6.13.22) − + (uxx )ij = (∆x)2 1 + pj pj pj (1 + pj ) Finally, from the boundary conditions u0j+1 = g(tj+1 ), u(sj+1 , tj+1 ) = um .
(6.13.23)
Some problem can arise when pj is very small. In this case it is enough to shift towards left the points a0 and a1 , so that, formula (6.13.12) is replaced by a0 = (n − 3)∆x, a1 = (n − 2)∆x, a2 = (n − 1 + p)∆x.
(6.13.24)
Going on as before, we obtain the formulas which replace (6.13.17), (6.13.22), with the role of p played by p + 1. Further Reading: [Ames (1992)], [Bellomo and Preziosi (1995)], [Collatz (1966)], [Crank (1957)], [Crank (1984)], [Douglas and Gallie (1955)], [Douglas and Racheford (1956)], [DuChateau and Zachmann (1989)], [Furzeland (1980)], [Gupta and Kumar (1980)], [Hundsdorfer and Verner (2003))], [Kays and Crawford (1993)], [Knabner and Angermann (2003)], [Lapidus and Pinter (1982)], [Larsson and Thom´ee (2003)], [Mitchell and Griffiths (1995)], [Morton (1980)], [Morton (1996)], [Morton and Mayers (2002)], [Necati Ozisik (1994)], [Quarteroni and Valli (1994)], [Quarteroni, Sacco and Saleri (2002)], [Richtmyer and Morton (1967)], [Rose (1960)], [Smith (1985)], [Thomas (1995)].
July 3, 2004
23:17
132
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Chapter 7
The Heat3 project
The program illustrated in this chapter is concerned with the twodimensional heat equation with boundary conditions of the first and second kind. Developing numerical programs for partial differential equations is a delicate task, where the knowledge of the problem plays a basic role. When finite-difference methods are applied in a program, further questions can arise. These are discussed in details to give the Reader the opportunity to practice.
133
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
134
7.1
Introduction
The program developed in this chapter deals with the two-dimensional heat equation Ut − α(Uxx + Uzz ) = 0, 0 < x < Lx , 0 < z < Lz , 0 < t ≤ T,
(7.1.1)
with the following initial condition U (x, z, 0) = ϕ(x, z), 0 ≤ x ≤ Lx , 0 ≤ z ≤ Lz .
(7.1.2)
In addition, the following boundary conditions will be considered: U (0, z, t) = g1 (z, t), 0 ≤ z ≤ Lz , 0 < t ≤ T, (7.1.3) or −Ux (0, z, t) = g1 (z, t), U (x, 0, t) = g2 (x, t), or −Uz (x, 0, t) = g2 (x, t),
0 ≤ x ≤ Lx , 0 < t ≤ T,
(7.1.4)
U (Lx , z, t) = g3 (z, t), or Ux (Lx , z, t) = g3 (z, t),
0 ≤ z ≤ Lz , 0 < t ≤ T,
(7.1.5)
U (x, Lz , t) = g4 (x, t), or Uz (x, Lz , t) = g4 (x, t),
0 ≤ x ≤ Lx , 0 < t ≤ T.
(7.1.6)
Equation (7.1.1) is approximated by ui,k,j+1 = r1 (ui−1,k,j + ui+1,k,j ) + r2 (ui,k−1,j + ui,k+1,j ) + [1 − 2(r1 + r2 )]ui,k,j , i = 1, ..., nx − 1, k = 1, ..., nz − 1, j = 0, ..., nt − 1,
(7.1.7)
where r1 = α∆t/(∆x)2 , r2 = α∆t/(∆z)2 ,
(7.1.8)
nx = Lx /∆x, nz = Lz /∆z, nt = T /∆t.
(7.1.9)
and
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
The Heat3 Project
135
Scheme (7.1.7) is conditionally stable and the stability condition is given by r1 + r2 ≤ 1/2.
(7.1.10)
Initial condition (7.1.2) are discretized as follows ui,k,0 = ϕi,k , i = 0, ..., nx , k = 0, ..., nz ,
(7.1.11)
where ϕi,k = ϕ(i∆x, k∆z). The discretiztion of the boundary conditions depends on the kind. If they are of the first kind, then u0,k,j = (g1 )k,j , k = 0, ..., nz , j = 1, ..., nt ,
(7.1.12)
ui,0,j = (g2 )i,j , i = 0, ..., nx , j = 1, ..., nt ,
(7.1.13)
unx ,k,j = (g3 )k,j , k = 0, ..., nz , j = 1, ..., nt ,
(7.1.14)
ui,nz ,j = (g4 )i,j , i = 0, ..., nx , j = 1, ..., nt .
(7.1.15)
In the case the case of boundary conditions of the second kind, let us focus our attention on condition (7.1.3)2 . Note that −
u1,k,j − u−1,k,j = (g1 )k,j , 2∆x
u−1,k,j = u1,k,j + 2∆x(g1 )k,j .
(7.1.16)
From (7.1.7), written for i = 0, and from (7.1.16) it follows u0,k,j+1 = (1 − 2r1 − 2r2 )u0,k,j + 2r1 [u1,k,j + ∆x(g1 )k,j ] +r2 (u0,k+1,j + u0,k−1,j ), k = 1, ..., nz − 1, j = 0, ..., nt − 1.
(7.1.17)
Similarly, ui,0,j+1 = (1 − 2r1 − 2r2 )ui,0,j + r1 (ui−1,0,j + ui+1,0,j ) +2r2 [ui,1,j + ∆z(g2 )i,j ], i = 1, ..., nx − 1, j = 0, ..., nt − 1,
(7.1.18)
unx ,k,j+1 = (1 − 2r1 − 2r2 )unx ,k,j + 2r1 [unx −1,k,j + ∆x(g3 )k,j ] +r2 (unx ,k+1,j + unx ,k−1,j ), k = 1, ..., nz − 1, j = 0, ..., nt − 1, (7.1.19)
July 3, 2004
23:17
136
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
ui,nz ,j+1 = (1 − 2r1 − 2r2 )ui,nz ,j + r1 (ui−1,nz ,j + ui+1,nz ,j ) +2r2 [ui,nz −1,j + ∆z(g4 )i,j ], i = 1, ..., nx − 1, j = 0, ..., nt − 1. (7.1.20) Much attention must be paid at the corners: (0, 0), (Lx , 0), (Lx , Lz ), (0, Lz ). Consider, for example, the first and note that four situations can occur, depending on the kind of conditions assigned on the boundaries x = 0 and z = 0: −Ux (0, 0, t) = g1 (0, t), U (0, 0, t) = g2 (0, t),
(7.1.21)
U (0, 0, t) = g1 (0, t), −Uz (0, 0, t) = g2 (0, t),
(7.1.22)
U (0, 0, t) = g1 (0, t), U (0, 0, t) = g2 (0, t),
(7.1.23)
−Ux (0, 0, t) = g1 (0, t), −Uz (0, 0, t) = g2 (0, t).
(7.1.24)
In the first two cases it will be assumed u0,0,j = (g2 )0,j
(7.1.25)
u0,0,j = (g1 )0,j ,
(7.1.26)
and
respectively. In the case (7.1.23), there is no doubt: u0,0,j = [(g1 )0,j + (g2 )0,j ]/2.
(7.1.27)
But, problems arise in the last case. Indeed, if (7.1.18) is written for i = 0, the resulting formula u0,0,j+1 = (1 − 2r1 − 2r2 )u0,0,j + r1 (u−1,0,j + u1,0,j ) +2r2 [u0,1,j + ∆z(g2 )0,j ],
(7.1.28)
depends on the fictitious value u−1,0,j . Eliminating this by means of (7.1.16) yields u0,0,j+1 = (1 − 2r1 − 2r2 )u0,0,j + 2r1 [u1,0,j + ∆x(g1 )0,j ] +2r2 [u0,1,j + ∆z(g2 )0,j ].
(7.1.29)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
The Heat3 Project
137
In similar manner the formulas related to the other three vertices are derived unx ,0,j+1 = (1 − 2r1 − 2r2 )unx ,0,j + 2r1 [unx −1,0,j + ∆x(g3 )0,j ] +2r2 [unx ,1,j + ∆z(g2 )nx ,j ],
(7.1.30)
unx ,nz ,j+1 = (1 − 2r1 − 2r2 )unx ,nz ,j + 2r1 [unx −1,nz ,j + ∆x(g3 )nz ,j ] +2r2 [unx ,nz −1,j + ∆z(g4 )nx ,j ],
(7.1.31)
u0,nz ,j+1 = (1 − 2r1 − 2r2 )u0,nz ,j + 2r1 [u1,nz ,j + ∆x(g1 )nz ,j ] +2r2 [u0,nz −1,j + ∆z(g4 )nx ,j ]. 7.2
(7.1.32)
Main menu
Create a new project Heat3 by following the procedure described in section 4.2. However, Step 4 must be replaced by Step 4 of 6. Uncheck Docking toolbar check box. Uncheck Printing and print preview check box. Uncheck 3D control check box. Click the Advanced button; in the Advanced Options dialog box enter hth as File extension and click Close. Click Next. After creating the new project, modify the PreCreateWindow(CREATESTRUCT& cs) function in the MainFrm.cpp file as in Listing 4.2.1. Furthermore, organize the main menu by modifying the template supplied by the compiler. Here are the steps to follow. 1. Click the ResourceView tab and expand the Menu item. Double-click IDR MAINFRAME to display the menu resource. 2. By Alt+Enter display the Properties box. 3. Note a blank rectangle to the right of the default menu headers. By the mouse drag and drop it between View and Help. In the Properties box enter Data as Caption. 4. Below the Data header a blank rectangle should appear. Click it and, in the Properties box, enter Equation as Caption. The corresponding resource ID should be: ID DATA EQUATION. 5. Repeat the last step to obtain the new items:
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
138
Initial, ID DATA INITIAL, Boundary1, ID DATA BOUNDARY1, Boundary2, ID DATA BOUNDARY2, Boundary3, ID DATA BOUNDARY3, Boundary4, ID DATA BOUNDARY4. 6. Note a blank rectangle to the right of Help. By the mouse drag and drop it between Data and Help. In the Properties box enter Results as Caption. 7. Finally, as in Step 4, add two new items: Graphical, ID RESULTS GRAPHICAL, Numerical, ID RESULTS NUMERICAL. This completes the menu. Compile and test.
7.3
Implementing the document class
This section deals with the implementation of the Document class. Open the Heat3doc.h file and, before the line // Generate message ..., add the following code to declare new member variables and functions. Listing 7.3.1 protected: double m al, m Tt, m Lx, m Lz; int m nx, m nz, m nt, m control; CStringArray m phi, m g1, m g2, m g3, m g4; CUIntArray m bckind, m variables; public: int GetControl(){return m control;}; int GetNx(){return m nx;}; int GetNz(){return m nz;}; int GetNt(){return m nt;}; double GetAl() {return m al;}; double GetTt() {return m Tt;}; double GetLx() {return m Lx;}; double GetLz() {return m Lz;}; CString GetPhi(int i, int k, int n) { if (i*(n+1)+k< m phi.GetSize()) return m phi.GetAt(i*(n+1)+k); else return ””; }; CString GetG1(int k, int j, int n) {
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
The Heat3 Project
wsdac04
139
if (j*(n+1)+k< m g1.GetSize()) return m g1.GetAt(j*(n+1)+k); else return ””; }; CString GetG3(int k, int j, int n) { if (j*(n+1)+k< m g3.GetSize()) return m g3.GetAt(j*(n+1)+k); else return ””; }; CString GetG2(int i, int j, int n) { if (j*(n+1)+i < m g2.GetSize()) return m g2.GetAt(j*(n+1)+i); else return ””; }; CString GetG4(int i, int j, int n) { if (j*(n+1)+i < m g4.GetSize()) return m g4.GetAt(j*(n+1)+i); else return ””; }; int GetBckind(int i) { if (i< m bckind.GetSize()) return m bckind.GetAt(i); else return -1; }; void Stability(); void TryAgain(CString msg);
Then, open the Heat3doc.cpp file and initialize the member variables in the following function. Listing 7.3.2 BOOL CHeat3Doc::OnNewDocument() { if (!CDocument::OnNewDocument()) return FALSE; m al=1.0; m Tt=1.0; m Lx=1000.0; m Lz=400.0; m nx=20; m nz=8; m nt=20; m control=0; m phi.SetSize(1); m phi.SetAt(0,”0”); m g1.SetSize(1); m g1.SetAt(0,”0”); m g2.SetSize(1); m g2.SetAt(0,”0”); m g3.SetSize(1); m g3.SetAt(0,”0”); m g4.SetSize(1); m g4.SetAt(0,”0”); ............................................... m bckind.SetSize(4); for (int i=0; i<4; i++) m bckind.SetAt(i,0); ............................................. m variables.SetSize(5); for (i=0; i<5; i++) m variables.SetAt(i,0); return TRUE; }
[1] [2]
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
140
[1] The information about the kind of boundary conditions will be stored in the m bckind array; the values 1 and 2 are used for the boundary conditions of the first and second kind, respectively. [2] The information about the functional dependence of the initial and the boundary functions will be stored in the m variables array. Now, add the skeleton of the functions which handle the command when the menu items are clicked. 1. Select ClassWizard in the View menu to display the MFC ClassWizard box. Click the Message Maps tab, select CHeat3Doc in the Class name box, select ID DATA EQUATION in the Object IDs box, select COMMAND in the Messages box, click Add Function to obtain the Add Member Function box. Here, click OK to accept the name: OnDataEquation, and add the new function. Then, in the Messages box select UPDATE COMMAND UI, click Add Function and, in the next box, click OK to accept the name for the new member function: OnUpdateDataEquation. 2. Apply the same procedure to: ID DATA INITIAL; ID DATA BOUNDARY1; ID DATA BOUNDARY2; ID DATA BOUNDARY3; ID DATA BOUNDARY4; ID RISULTATS GRAPHICAL; ID RISULTATS NUMERICAl. 3. Click the Edit Code button to edit the skeleton of the new functions which will be completed later. Finally, add the following code necessary to save and to restore the data. Listing 7.3.3 void CHeat1Doc::Serialize(CArchive& ar) { CString str=””; int i=0, bc=0, size=1; if (ar.IsStoring()) { ar<< m al << m Tt << m Lx << m Lz << m control << m nx << m nz << m nt; size=m phi.GetSize(); ar<<size; for (i=0; i<size;i++)
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
The Heat3 Project
wsdac04
141
{ str=m phi.GetAt(i); ar<<str; } size=m g1.GetSize(); ar<<size; for (i=0; i<size;i++) { str=m g1.GetAt(i); ar<<str; } size=m g2.GetSize(); ar<<size; for (i=0; i<size;i++) { str=m g2.GetAt(i); ar<<str; } size=m g3.GetSize(); ar<<size; for (i=0; i<size;i++) { str=m g3.GetAt(i); ar<<str; } size=m g4.GetSize(); ar<<size; for (i=0; i<size;i++) { str=m g4.GetAt(i); ar<<str; } for (i=0; i<4 ;i++) { bc=m bckind.GetAt(i); ar<
} else { ar>>m al >> m Tt >> m Lx >> m Lz >> m control >> m nx >> m nz >> m nt; ar>>size; for (i=0; i<size;i++) {
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
142
ar>>str; m phi.SetAtGrow(i,str);
}
} ar>>size; for (i=0; i<size;i++) { ar>>str; m g1.SetAtGrow(i,str); } ar>>size; for (i=0; i<size;i++) { ar>>str; m g2.SetAtGrow(i,str); } ar>>size; for (i=0; i<size;i++) { ar>>str; m g3.SetAtGrow(i,str); } ar>>size; for (i=0; i<size;i++) { ar>>str; m g4.SetAtGrow(i,str); } for (i=0; i<4 ;i++) { ar>>bc; m bckind.SetAt(i,bc); } for (i=0; i<5 ;i++) { ar>>bc; m variables.SetAt(i,bc); }
}
Compile and test.
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
The Heat3 Project
7.4
wsdac04
143
Dialog resources
This section is devoted to the dialog resources. At first, let us organize the dialog window to enter the equation data: the diffusivity coefficient α, dimensions Lx , Lz , the time interval [0, T ] of the thermal process, the integers nx, nz, nt necessary to fix the mesh. The procedure is the following.
Fig. 7.4.1
Dialog window of the equation data
1. Click Resource in the Insert menu. In the next Insert Resource box double-click Dialog to display the dialog template, fig. 7.4.1. This must be rearranged. 2. By Alt+Enter open the Property box. Replace IDD DIALOG1 by IDD EDATA and enter: Equation data as Caption. 3. Increase suitably the dimensions of the template and by the mouse move the OK and Cancel buttons to lower position, fig. 7.4.1. 4. On the Controls toolbox select the Static Text box. Move the mouse to the upper left corner of the dialog template and click to obtain a static text control. As Caption enter: U t = alpha(U xx + U zz), 0 < x < Lx, 0 < z < Lz, 0 < t < T . 5. Repeat the last step to obtain Alpha=, Lx=, Lz=, T=, Nx=, Nz=, Nt=, fig. 7.4.1. 6. On the Controls toolbox select the Edit box. Move the mouse to the right of “Alpha=” and click to obtain an edit box, fig. 7.4.1. Re-size the blank box and in the Properties box replace IDC EDIT1 by IDC AL, fig. 7.4.1. Apply the same procedure to move other six edit boxes to the right
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
144
of “Lx=”, “Lz=”, “T=”, “Nx=”, “Nz=”, “Nt=”, respectively. Replace the corresponding IDCs by IDC LX, IDC LZ, IDC TT, IDC NX, IDC NZ, IDC NT, respectively, fig. 7.4.1. After completing the resource, fig. 7.4.1, create the related class. Click ClassWizard in the View menu to display the Adding a Class dialog box; accept to create a new class by clicking OK; in the New Class dialog box enter CEdata in the Name box and click OK. In the MFC ClassWizard box select Member Variables tab to declare the variables; double-click IDC AL to obtain the Add Member Variable box; here, in Member variable name box enter m al, and select double in Variable type box; click OK. Apply the same procedure to: IDC LX, Member variable name: m Lx, Variable type: double, IDC LZ, Member variable name: m Lz, Variable type: double, IDC NT, Member variable name: m nt, Variable type: int, IDC NX, Member variable name: m nx, Variable type: int, IDC NZ, Member variable name: m nz, Variable type: int, IDC TT, Member variable name: m Tt, Variable type: double. This completes the class. Lastly, add the code line #include “Edata.h”
in the Heat3Doc.cpp file, after the other including instructions. Now, we can implement the OnDataEquation function, that handles the command when the Equation item is clicked, and also the simple TryAgain function, that is invoked when the first function is executed. Listing 7.4.1 void CHeat3Doc::OnDataEquation() { CEdata edata; .................................................. edata.m al=m al; edata.m Lx=m Lx; edata.m Lz=m Lz; edata.m Tt=m Tt; edata.m nx=m nx; edata.m nz=m nz; edata.m nt=m nt; m control=0; CString str=””; if (edata.DoModal()==IDOK) { ................................................ m al=edata.m al; m Lx=edata.m Lx;
[1]
[2]
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
The Heat3 Project
}
}
145
m Lz=edata.m Lz; m Tt=edata.m Tt; m nx=edata.m nx; m nz=edata.m nz; m nt=edata.m nt; if (edata.m al>0 && edata.m Lx>0 && edata.m Lz>0 && edata.m Tt>0 && ........... [3] edata.m nx>1 && edata.m nz>1 && edata.m nt>1) { // Stability(); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . [4] m control=11; SetModifiedFlag(); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . [5] UpdateAllViews(NULL); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . [5] } else . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . [6] { str.Format(”Alpha, T, Lx, Lz positive; nx, nz, nt integers >1!”); TryAgain(str); }
void CHeat3Doc::TryAgain(CString msg) { AfxMessageBox(msg+” Try again.”); }
................................
[7]
[1] The data of the dialog window are initialized. [2] The entered data are saved. [3] The entered data are verified. [4] If the data are right, the Stability function is invoked, so that the stability condition can be verified. The remark sign must be eliminated after introducing the Stability function. [5] The modification flag is set and the function updating the view is called. [6] In the case of incorrect data, the TryAgain function is called... [7] ... and the user is invited to modify his data. The data m nx, m nz and m nt are involved in the stability condition α(dt/dx2 + dt/dz 2 ) ≤ 1/2,
(7.4.1)
dt = T /nt, dx = L/nx, dz = L/nz.
(7.4.2)
Therefore, they must eventually be adjusted. The program modifies only
August 13, 2004
16:55
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
146
m nt, in order to satisfy condition (7.4.1). The task is handled by the following function. Listing 7.4.2 void CHeat3Doc::Stability() { double dx=m Lx/m nx; double dz=m Lz/m nz; double dt=m Tt/m nt; if (m al*dt/(dx*dx)+m al*dt/(dz*dz) > .5) { do { m nt = m nt+1; dt=m Tt/m nt; }while (m al*dt/(dx*dx)+m al*dt/(dz*dz) > .5); } }
Also, implement the function that enables and disables the Equation item. Listing 7.4.3 void CHeat3Doc::OnUpdateDataEquation(CCmdUI* pCmdUI) { ....................... if (m control< 12) pCmdUI->Enable(TRUE); else pCmdUI->Enable(FALSE); ..................................... }
[1] [2]
[1] If the initial and boundary data have not yet entered, the Equation item is enabled, so that the equation data can be entered. [2] After entering the initial data, the Equation item is disabled. Lastly, before compiling, remove the remark sign in the code line // Stability(); in the OnDataEquation function.
Next, the dialog window to enter the initial data is developed. Its final look is shown in fig. 7.4.2. Here are the steps to follow. 1. Click Resource in the Insert menu to display the Insert Resource box. Here, double-click Dialog to obtain the dialog template, fig. 7.4.1. By Alt+Enter open the Property box. Replace IDD DIALOG1 by IDD IDATA and enter Initial data as Caption. 2. Increase suitably the dimensions of the template and by the mouse move the OK and Cancel buttons to lower position, fig. 7.4.2.
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
The Heat3 Project
Fig. 7.4.2
wsdac04
147
Dialog window of the initial data
3. On the Controls toolbox select the Static Text box. Move the mouse to the upper left corner of the dialog template and click to obtain a static text control, fig. 7.4.2. Enter: Specify if the initial condition is a as Caption. 4. Select the Static Text box. Move the mouse to the next line and click to create a new Static Text control, fig. 7.4.2. Enter: or if it depends on as Caption. 5. Repeat Step 4 to obtain a last Static Text box, fig. 7.4.2. Enter: Data no. as Caption. 6. Select the Edit Box from the Controls toolbox, move the mouse to the right of Data no. and click. In the Property box replace IDC EDIT1 by IDC DATAN; then, click the Styles tab and check Read-only and uncheck Border, fig. 7.4.2. 7. Similarly, other two Edit Box controls are created. Enlarge suitably the blank boxes, fig. 7.4.2. 8. Consider the left control; in the Property box replace IDC EDIT2 by IDC FUNCTION; then, click the Styles tab and check Read-only and uncheck Border. Next, focus our attention to the right control; replace IDC EDIT3 by IDC FVALUE. 9. On the Controls toolbox select the Radio Button box, move the mouse to the right of “Specify if the initial condition is a” and click to obtain a radio button. In the Property box replace IDC RADIO1 by IDC VARIABLES, enter constant function as Caption and select Group to specify that this radio button is the first of a group of four. 10. Other three Radio Button controls are created in the similar way. Enter: x, z, x and z, respectively, as Caption.
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
148
This completes the resource, fig. 7.4.2. Now, create the related class. Select the ClassWizard item from the View menu to display the Adding a Class dialog box; accept to create a new class by clicking OK; in the New Class dialog box enter CIdata in the Name box and click OK. In the MFC ClassWizard box select Member Variables tab to declare the variables; double-click IDC DATAN to obtain the Add Member Variable box; here, in Member variable name box write m datan, and select int in Variable type box; click OK. Apply the same procedure to: IDC FUNCTION, Member variable name: m function, Variable type: CString, IDC FVALUE, Member variable name: m fvalue, Variable type: CString, IDC VARIABLES, Member variable name: m variables, Variable type: int. Lastly, add the code line #include “Idata.h”
in the Heat3Doc.cpp file, after the other including instructions, so that the corresponding file can be seen. Now, implement the OnDataInitial function, that receives the message when the Initial item is clicked. Listing 7.4.4 void CHeat3Doc::OnDataInitial() { CIdata idata; double dx=m Lx/m nx, dz=m Lz/m nz; ............................. idata.m variables=m variables.GetAt(0); idata.m datan=1; idata.m fvalue=m phi.GetAt(0); idata.m function=”x = 0, z = 0, F =”; if (idata.DoModal()==IDOK) { int i=0, k=0; CString str=””; m variables.SetAt(0,idata.m variables); .................................... m phi.SetAt(0,idata.m fvalue); ......................................... switch(idata.m variables) { case 0: for (i=0; i<m nx+1 ;i++) { for (k=0; k<m nz+1 ;k++)
[1]
[2] [3]
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
The Heat3 Project
wsdac04
149
{ if (i==0 && k==0) k=1; .................... if (m phi.GetSize()==i*(m nz+1)+k) { str=m phi.GetAt(i*(m nz+1)+k-1); m phi.SetAtGrow(i*(m nz+1)+k,str); } .............. m phi.SetAt(i*(m nz+1)+k,idata.m fvalue);
[4]
[6]
}
} break; case 1: for (i=0; i<m nx+1 ;i++) { for (k=0; k<m nz+1 ;k++) { if (i==0 && k==0) k=1; .................... if (m phi.GetSize()==i*(m nz+1)+k) { str=m phi.GetAt(i*(m nz+1)+k-1); m phi.SetAtGrow(i*(m nz+1)+k,str); } if (i>0 && k==0) { idata.m variables=1; idata.m datan ++; str.Format(”x=%g, F=”,i*dx); idata.m function=str; idata.m fvalue=m phi.GetAt(i*(m nz+1)+k); idata.DoModal(); ...................................... } .............. m phi.SetAt(i*(m nz+1)+k,idata.m fvalue); } } break; case 2: for (i=0; i<m nx+1 ;i++) { for (k=0; k<m nz+1 ;k++) { if (i==0 && k==0) k=1; .................... if (m phi.GetSize()==i*(m nz+1)+k) { str=m phi.GetAt(i*(m nz+1)+k-1); m phi.SetAtGrow(i*(m nz+1)+k,str); }
[4]
[5] [6]
[4]
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
150
if (i==0) { idata.m variables=2; idata.m datan ++; str.Format(”z=%g, F=”,k*dz); idata.m function=str; idata.m fvalue=m phi.GetAt(i*(m nz+1)+k); idata.DoModal(); ...................................... } else idata.m fvalue=m phi.GetAt((i-1)* (m nz+1)+k); .............. m phi.SetAt(i*(m nz+1)+k,idata.m fvalue);
[5]
[6]
}
} break; case 3: for (i=0; i<m nx+1 ;i++) { for (k=0; k<m nz+1 ;k++) { if (i==0 && k==0) k=1; .................... if (m phi.GetSize()==i*(m nz+1)+k) { str=m phi.GetAt(i*(m nz+1)+k-1); m phi.SetAtGrow(i*(m nz+1)+k,str); } idata.m variables=3; idata.m datan ++; str.Format(”x=%g, z=%g, F=”,i*dx,k*dz); idata.m function=str; idata.m fvalue=m phi.GetAt(i*(m nz+1)+k); idata.DoModal(); ........................................ .............. m phi.SetAt(i*(m nz+1)+k,idata.m fvalue); } } break;
[4]
[5] [6]
} m control=12; } }
[1] The data in the dialog window are initialized. [2] The first entered value is stored. [3] The following cases are considered: constant function, function depending only on x, function depending only on z, function depending on both variables.
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
The Heat3 Project
wsdac04
151
[4] The initial dimension of the array is 1; therefore, the first time the item is activated, the array dimension must grow together with the number of data. On the contrary, the dimension will not increase when the same item is re-activated, for example, to verify or modify the entered values. [5] If the initial condition is not a constant function, the dialog box is called again to enter the other values. [6] The entered value is stored in the array. Also, complete the function that enables/disables the Initial item. Listing 7.4.5 void CHeat3Doc::OnUpdateDataInitial(CCmdUI* pCmdUI) { if (m control==0) pCmdUI->Enable(FALSE); else pCmdUI->Enable(TRUE); }
Compile. The last resource to create is related the boundary data. Its final look is shown in fig. 7.4.3. The procedure to obtain this dialog box is the following.
Fig. 7.4.3
Dialog window of the boundary data
1. Click Resource in the Insert menu to display the Insert Resource box. Here, double-click Dialog to obtain the dialog template, fig. 7.4.1. By Alt+Enter open the Property box. Replace IDD DIALOG1 by IDD BDATA and enter Boundary data as Caption. 2. Increase suitably the dimensions of the template and by the mouse move the OK and Cancel buttons to lower position, fig. 7.4.3.
July 3, 2004
23:17
152
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
3. On the Controls toolbox select the Static Text box. Move the mouse to the upper left corner of the dialog template and click to obtain a static text control, fig. 7.4.3. Enter: Boundary as caption. 4. On the Controls toolbox select the Edit Box; move the mouse to the right of the previous Static Text control and click to display a new Edit Box. In the Property window replace IDC EDIT1 by IDC BOUNDARY; then, click the Styles tab and check Read-only and uncheck Border, fig. 7.4.3. 5. On the Controls toolbox select the Static Text box. Move the mouse to the right of the previous Edit Text rectangle and click to display a new Static Text control. In the Property box enter Kind: as caption, fig. 7.4.3. 6. On the Controls toolbox select the Radio Button box. Move the mouse to the right of the previous Static Text control and click to obtain a new Radio Button control. In the Property box replace IDC RADIO1 by IDC BCKIND, write 1 in the Caption box and select Group to specify that this is the first of a group of two. Similarly, create a second Radio Button control and enter 2 as caption, fig. 7.4.3. 7. On the Controls toolbox select the Static Text box. Move the mouse to the next line and click to obtain a new Static Text control. In the Caption box enter Specify if the boundary condition is a, fig. 7.4.3. Similarly, create a new Static Text control at the beginning of the next line. In the Caption box enter: or if it depends on. 8. On the Controls toolbox select the Radio Button box. Move the mouse to the right of “Specify if the boundary condition is a” and click to obtain a new Radio Button control. In the Property box replace IDC RADIO3 by IDC VARIABLES, enter constant function as caption and select Group to specify that this is the first of a new group of four, fig. 7.4.3. 9. Similarly, create three new Radio Button controls to the right of “or it depends on”. In the Caption box of the first enter t and leave the other two blank, fig. 7.4.3. 10. Create two new Edit Box controls to the right of the last two Radio Button controls. In the Property box replace their IDCs by IDC XORZ and IDC XORZT, respectively. Then, click the Styles tab and check Read-only and uncheck Border, fig. 7.4.3. 11. Create two new Edit Box controls in the next line and re-size suitably the blank boxes, fig. 7.4.3.
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
The Heat3 Project
wsdac04
153
12. Consider the left control; in the Property box replace the default IDC by IDC FUNCTION; then, click the Styles tab and check Read-only and uncheck Border. Then, focus our attention to the right control; replace the corresponding IDC by IDC FVALUE. 13. On the Controls toolbox select the Static Text box. Move the mouse to the next line and click to obtain a new Static Text control. In the Caption box enter: Data no. 14. Select the Edit Box from the Controls toolbox, move the mouse to the right of “Data no.” and click. In the Property box replace IDC EDIT6 by IDC DATAN; then, click the Styles tab and check Read-only and uncheck Border, fig. 7.4.3. This completes the new resource, fig. 7.4.3. Now, create the related class. Select the ClassWizard item from the View menu to display the Adding a Class dialog box; accept to create a new class by clicking OK; in the New Class dialog box enter CBdata in the Name box and click OK. In the MFC ClassWizard box select Member Variables tab to define the variables; double-click IDC BCKIND to display the Add Member Variable box; here, in Member variable name box write m bckind, and select int in Variable type box; click OK. Apply the same procedure to: IDC BOUNDARY, Member variable name: m boundary, Variable type: CString, IDC DATAN, Member variable name: m datan, Variable type: int, IDC FUNCTION, Member variable name: m function, Variable type: CString, IDC FVALUE, Member variable name: m fvalue, Variable type: CString, IDC VARIABLES, Member variable name: m variables, Variable type: int, IDC XORZ, Member variable name: m xorz, Variable type: CString, IDC XORZT, Member variable name: m xorzt, Variable type: CString. Clicking OK completes the class. It remains to add the code #include “Bdata.h” in the Heat3Doc.cpp file, together with the other including instructions. Finally, consider the OnDataBoundary1,..., OnDataBoundary4 functions.
The code of the first function is given in the following listing, without any comment, as it is very similar to the code of the OnDataInitial function. Listing 7.4.6
July 3, 2004
23:17
154
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
void CHeat3Doc::OnDataBoundary1() { int j=0, k=0; CString str=””; CBdata bdata; double dt=m Tt/m nt, dz=m Lz/m nz; bdata.m xorz=”z”; bdata.m xorzt=”z and t”; bdata.m variables=m variables.GetAt(1); bdata.m bckind=m bckind.GetAt(0); bdata m boundary=”x = 0”; bdata.m datan= 1; bdata.m fvalue=m g1.GetAt(0); bdata.m function=”z=0, t=0, F=”; if (bdata.DoModal()==IDOK) { m bckind.SetAt(0,bdata.m bckind); m variables.SetAt(1,bdata.m variables); m g1.SetAt(0,bdata.m fvalue); switch(bdata.m variables) { case 0: for (j=0; j< m nt+1; j++) { for (k=0; k< m nz+1; k++) { if (j == 0 && k == 0) k=1; if (m g1.GetSize()==j*(m nz+1)+k) { str=m g1.GetAt(j*(m nz+1)+k-1); m g1.SetAtGrow(j*(m nz+1)+k,str); } m g1.SetAt(j*(m nz+1)+k,bdata.m fvalue); } } break; case 1: for (j=0; j< m nt+1; j++) { for (k=0; k< m nz+1; k++) { if (j == 0 && k == 0) k=1; if (m g1.GetSize()==j*(m nz+1)+k) { str=m g1.GetAt(j*(m nz+1)+k-1); m g1.SetAtGrow(j*(m nz+1)+k,str);
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
The Heat3 Project
} if (j > 0 && k == 0) { bdata.m variables=1; bdata.m bckind=m bckind.GetAt(0); bdata.m datan ++; str.Format(”t=%g, F=”, j*dt); bdata.m function=str; bdata.m fvalue=m g1.GetAt(j*(m nz+1)+k); bdata.DoModal(); } m g1.SetAt(j*(m nz+1)+k,bdata.m fvalue); } } break; case 2: for (j=0; j< m nt+1; j++) { for (k=0; k< m nz+1; k++) { if (j == 0 && k == 0) k=1; if (m g1.GetSize()==j*(m nz+1)+k) { str=m g1.GetAt(j*(m nz+1)+k-1); m g1.SetAtGrow(j*(m nz+1)+k,str); } if (j == 0) { bdata.m variables=2; bdata.m bckind=m bckind.GetAt(0); bdata.m datan ++; str.Format(”z=%g, F=”, k*dz); bdata.m function=str; bdata.m fvalue=m g1.GetAt(j*(m nz+1)+k); bdata.DoModal(); } else bdata.m fvalue=m g1.GetAt((j-1)*(m nz+1)+k); m g1.SetAt(j*(m nz+1)+k,bdata.m fvalue); } } break; case 3: for (j=0; j< m nt+1; j++) { for (k=0; k< m nz+1; k++) {
wsdac04
155
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
156
if (j == 0 && k == 0) k=1; if (m g1.GetSize()==j*(m nz+1)+k) { str=m g1.GetAt(j*(m nz+1)+k-1); m g1.SetAtGrow(j*(m nz+1)+k,str); } bdata.m variables=3; bdata.m bckind=m bckind.GetAt(0); bdata.m datan ++; str.Format(”z=%g, t=%g, F=”, k*dz,j*dt); bdata.m function=str; bdata.m fvalue=m g1.GetAt(j*(m nz+1)+k); bdata.DoModal(); m g1.SetAt(j*(m nz+1)+k,bdata.m fvalue); } } break; } m control=12; } }
The code of the OnDataBoundary2,..., OnDataBoundary4 functions can be derived easily from the previous one, with obvious modifications. Furthermore, complete the OnUpdateDataBoundary1,..., OnDataBoundary4 functions by copying the code of the OnUpdateDataInitial function, given in Listing 7.4.5. Finally, implement the OnResultsGraphical, OnUpdateResultsGraphical, OnResultsNumerical, OnUpdateResultsNumerical functions. The code for the first two is the following. Listing 7.4.7 void CHeat3Doc::OnResultsGraphical() { m control=21; SetModifiedFlag(); UpdateAllViews(NULL); } void CHeat3Doc::OnUpdateResultsGraphical(CCmdUI* pCmdUI) { if (m phi.GetSize()>1 && m g1.GetSize()>1 && m g2.GetSize()>1 && m g3.GetSize()>1 && m g4.GetSize()>1) pCmdUI->Enable(TRUE); else pCmdUI->Enable(FALSE); }
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
The Heat3 Project
wsdac04
157
The code of the OnResultsNumerical, OnUpdateResultsNumerical functions is obtained by the previous one by replacing m control=21; by m control=22;. Compile and test.
7.5
Implementing the view class
This section deals with the part of the program related the the numerical results. Open the Heat3View.h file and add the following instructions just before the class definition. Listing 7.5.1 #define #define #define #define #define #define #define
V1 1 V2 371 D5 V3 130 V4 381 V5 320 V6 571
Furthermore, declare some new member variables and functions before the code line // Generate message .... Listing 7.5.2 protected: int m xDocSize,m yDocSize, m ii, m jj, m display, m is; CUIntArray m bckind; void GraphResults(CDC* pDC); void NumResults(CDC* pDC); double Phi(int i, int k, int n); double G1(int k, int j, int n); double G2(int i, int j, int n); double G3(int k, int j, int n); double G4(int i, int j, int n); void FiniteDifference(int j, double r1, double r2, double u[], int n1, int n2); int GraphC(double c, double crd, int origin); double Min(double u[], double m, int n1, int n2); double Max(double u[], double m, int n1, int n2);
The new variables are initialized in the class constructor, in the Heat3View.cpp file. Listing 7.5.3 CHeat3View::CHeat3View() { m xDocSize=100, m yDocSize=100;
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
158
m ii=0, m jj=0, m is=0; m display=0; m bckind.SetSize(4); }
In the same file, implement as follows the OnDraw function, whose skeleton was supplied with the compiler. Also, add the body of two new functions. Listing 7.5.4 void CHeat3View::OnDraw(CDC* pDC) { CHeat3Doc* pDoc = GetDocument(); ASSERT VALID(pDoc); pDC->SetMapMode(MM LOENGLISH); CPen pen(PS SOLID, 1, RGB(0,0,0)); CPen* oldPen= pDC->SelectObject(&pen); CFont font; font.CreatePointFont(90,”Times”,pDC); CFont* oldFont=pDC->SelectObject(&font); m bckind.SetAt(0,pDoc-> GetBckind(0)); . . . . . . . . . . . . . . . . . . . . . . . . . . . . m bckind.SetAt(1,pDoc-> GetBckind(1)); m bckind.SetAt(2,pDoc-> GetBckind(2)); m bckind.SetAt(3,pDoc-> GetBckind(3)); if (pDoc-> GetControl() < 22) GraphResults(pDC); else NumResults(pDC); CSize docSize(m xDocSize,m yDocSize); SetScrollSizes(MM LOENGLISH,docSize); pDC->SelectObject(oldPen); pDC->SelectObject(oldFont); }
[1]
void CHeat3View::GraphResults(CDC* pDC) { } void CHeat3View::NumResults(CDC* pDC) { }
[1] Information about the kind of the boundary condition is recovered. Next, we begin to implement the GraphResults function that performs the task of printing the data and the numerical results. We also introduce a simple function that will often be used. Listing 7.5.5 void CHeat3View::GraphResults(CDC* pDC)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
The Heat3 Project
wsdac04
159
{ CHeat3Doc* pDoc = GetDocument(); ASSERT VALID(pDoc); CString str=””; int controlv=pDoc->GetControl(); int nx=pDoc->GetNx(), nz=pDoc->GetNz(), nt=pDoc->GetNt(); double al=pDoc->GetAl(); double Lx=pDoc->GetLx(), Lz=pDoc->GetLz(), Tt=pDoc->GetTt(); double dx=Lx/nx, dz=Lz/nz, dt=Tt/nt; double rx=al*dt/(dx*dx), rz=al*dt/(dz*dz); pDC->Rectangle(V1,-V1,V2,-V2); ................................... pDC->Rectangle(V4,-V3,V6,-V5); ................................... if (controlv >0) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . { str.Format(”Ut = alpha (Uxx+Uzz); alpha = %g”,al); pDC->TextOut(V2+D, -41, str); str.Format(”Lx = %g; Lz = %g; T = %g”,Lx,Lz,Tt); pDC->TextOut(V2+D, -61, str); str.Format(”dx = %g; dz = %g; dt = %g”, dx,dz,dt); pDC->TextOut(V2+D, -81, str); str.Format(”nx = %d; nz = %d; nt = %d;”,nx,nz,nt); pDC->TextOut(V2+D, -101, str); str.Format(”rx = %lf; rz = %lf;r=rx+rz= %lf;”,rx,rz,rx+rz); pDC->TextOut(V1+D, -V2-D, str); double xzrd=(V2-V1-2*D)/Lx; if (Lz > Lx) xzrd=(V2-V1-2*D)/Lz; pDC->MoveTo(V4+D,-V5+D); pDC->LineTo(GraphC(Lx,xzrd/2,V4+D),-V5+D); ................. pDC->MoveTo(V4+D,-V5+D); pDC->LineTo(V4+D,GraphC(Lz,xzrd/2,-V5+D)); ................. pDC->LineTo(GraphC(Lx,xzrd/2,V4+D),GraphC(Lz,xzrd/2,-V5+D)); . pDC->LineTo(GraphC(Lx,xzrd/2,V4+D),-V5+D); ................. // Add new code here }
[1] [2] [3]
[4] [5] [6] [7]
}
[1] This is the rectangle where the solution will be plotted. The first two values are the co-ordinates of the upper left vertex. The other two give the co-ordinates of the lower right vertex. [2] This is the rectangle related to the physical domain. [3] The equation data are printed. [4] This is the base of the physical domain. [5] Left side.
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
160
[6] Upper side. [7] Right side. Listing 7.5.6 int CHeat3View::GraphC(double c, double crd, int origin) { return (int) (origin+c*crd); . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . }
[1]
[1] When this function is invoked, we will pass a physical co-ordinate c, a suitable reduction coefficient of co-ordinates crd and an origin. The function returns a graphical co-ordinate. The GraphResults function will be completed later. Now, we give the simple code of the functions which return the initial and the boundary data. In addition, we implement the important FiniteDifference function, where the solution will be computed. Listing 7.5.7 double CHeat3View:: Phi(int i, int k, int n) { CHeat3Doc* pDoc = GetDocument(); ASSERT VALID(pDoc); return atof(pDoc-> GetPhi(i,k,n)); } double CHeat3View:: G1(int k, int j, int n) { CHeat3Doc* pDoc = GetDocument(); ASSERT VALID(pDoc); return atof(pDoc-> GetG1(k,j,n)); } double CHeat3View:: G2(int i, int j, int n) { CHeat3Doc* pDoc = GetDocument(); ASSERT VALID(pDoc); return atof(pDoc-> GetG2(i,j,n)); } double CHeat3View:: G3(int k, int j, int n) { CHeat3Doc* pDoc = GetDocument(); ASSERT VALID(pDoc); return atof(pDoc-> GetG3(k,j,n)); }
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
The Heat3 Project
wsdac04
161
double CHeat3View:: G4(int i, int j, int n) { CHeat3Doc* pDoc = GetDocument(); ASSERT VALID(pDoc); return atof(pDoc-> GetG4(i,j,n)); }
Listing 7.5.8 void CHeat3View::FiniteDifference(int j, double r1, double r2, double u[], int n1, int n2) { CHeat3Doc* pDoc = GetDocument(); ASSERT VALID(pDoc); int i=0, k=0; double Lz=pDoc-> GetLz(), dz=Lz/n2, Lx=pDoc-> GetLx(), dx=Lx/n1; if (j > 0) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . [1] { double *v; v = new double[(n1+1)*(n2+1)]; if (v != NULL ) { for (i = 0; i < n1+1; i++) { for (k = 0; k < n2+1; k++) v[i*(n2+1)+k]= u[i*(n2+1)+k]; . [2] } for (i = 1; i < n1; i++) { for (k = 1; k < n2; k++) { u[i*(n2+1)+k]=(1-2*r1-2*r2)*v[i*(n2+1)+k]+ r1*(v[(i+1)*(n2+1)+k]+v[(i-1)*(n2+1)+k])+ r2*(v[i*(n2+1)+k+1]+v[i*(n2+1)+k-1]); . . . . . . . . . . . . . . . . . [3] } } if (m bckind.GetAt(0)== 0) { for (k = 1; k < n2; k++) u[0*(n2+1)+k]=G1(k,j,n2); . . . . . . . [4][5] } else { for (k = 1; k < n2; k++) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . [4] { u[0*(n2+1)+k]=(1-2*r1-2*r2)*v[0*(n2+1)+k]+ 2*r1*(v[1*(n2+1)+k]+dx*G1(k,j-1,n2))+ r2*(v[0*(n2+1)+k+1]+v[0*(n2+1)+k-1]); ............... [5]
July 3, 2004
23:17
162
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
} } if (m bckind.GetAt(1)== 0) { for (i = 1; i < n1; i++) u[i*(n2+1)+0]=G2(i,j,n1); . . . . . . . . . . [6][7] } else { for (i = 1; i < n1; i++) ...................................... [6] { u[i*(n2+1)+0]=(1-2*r1-2*r2)*v[i*(n2+1)+0]+ r1*(v[(i+1)*(n2+1)+0]+v[(i-1)*(n2+1)+0])+ 2*r2*(v[i*(n2+1)+1]+dz*G2(i,j-1,n1)); ................... [7] } } if (m bckind.GetAt(2)== 0) { for (k = 1; k < n2; k++) u[n1*(n2+1)+k]=G3(k,j,n2); . . . . . . [8][9] } else { for (k = 1; k < n2; k++) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . [8] { u[n1*(n2+1)+k]=(1-2*r1-2*r2)*v[n1*(n2+1)+k]+ 2*r1*(v[(n1-1)*(n2+1)+k]+dx*G3(k,j-1,n2))+ r2*(v[n1*(n2+1)+k+1]+v[n1*(n2+1)+k-1]); . . . . . . . . . . . . . . [9] } } if (m bckind.GetAt(3)== 0) { for (i = 1; i < n1; i++) u[i*(n2+1)+n2]=G4(i,j,n1); . . . . . . [10][11] } else { for (i = 1; i < n1; i++) ..................................... [10] { u[i*(n2+1)+n2]=(1-2*r1-2*r2)*v[i*(n2+1)+n2]+ r1*(v[(i+1)*(n2+1)+n2]+v[(i-1)*(n2+1)+n2])+ 2*r2*(v[i*(n2+1)+n2-1]+dz*G4(i,j-1,n1)); ............... [11] } } . . . . . . . . . . [12] if (m bckind.GetAt(0)==0 || m bckind.GetAt(1)==0) { if (m bckind.GetAt(0)==0) u[0*(n2+1)+0]=G1(0,j,n2); else u[0*(n2+1)+0]=G2(0,j,n1); if (m bckind.GetAt(0)==0 && m bckind.GetAt(1)==0)
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
The Heat3 Project
u[0*(n2+1)+0]=(G1(0,j,n2)+G2(0,j,n1))/2; } else { u[0*(n2+1)+0]=(1-2*r1-2*r2)*v[0*(n2+1)+0]+ 2*r1*(v[1*(n2+1)+0]+dx*G1(0,j-1,n2))+ 2*r2*(v[0*(n2+1)+1]+dz*G2(0,j-1,n1)); } .......... if (m bckind.GetAt(1)==0 || m bckind.GetAt(2)==0) { if (m bckind.GetAt(1)==0) u[n1*(n2+1)+0]=G2(n1,j,n1); else u[n1*(n2+1)+0]=G3(0,j,n2); if (m bckind.GetAt(1)==0 && m bckind.GetAt(2)==0) u[n1*(n2+1)+0]=(G2(n1,j,n1)+G3(0,j,n2))/2; } else { u[n1*(n2+1)+0]=(1-2*r1-2*r2)*v[n1*(n2+1)+0]+ 2*r1*(v[(n1-1)*(n2+1)+0]+dx*G3(0,j-1,n2))+ 2*r2*(v[n1*(n2+1)+1]+dz*G2(n1,j,n1)); } .......... if (m bckind.GetAt(2)==0 || m bckind.GetAt(3)==0) { if (m bckind.GetAt(2)==0) u[n1*(n2+1)+n2]=G3(n2,j,n2); else u[n1*(n2+1)+n2]=G4(n1,j,n1); if (m bckind.GetAt(2)==0 && m bckind.GetAt(3)==0) u[n1*(n2+1)+n2]=(G3(n2,j,n2)+G4(n1,j,n1))/2; } else { u[n1*(n2+1)+n2]=(1-2*r1-2*r2)*v[n1*(n2+1)+n2]+ 2*r1*(v[(n1-1)*(n2+1)+n2]+dx*G3(n2,j,n2))+ 2*r2*(v[n1*(n2+1)+n2-1]+dz*G4(n1,j,n1)); } .......... if (m bckind.GetAt(3)==0 || m bckind.GetAt(0)==0) { if (m bckind.GetAt(3)==0) u[0*(n2+1)+n2]=G4(0,j,n1); else u[0*(n2+1)+n2]=G1(n2,j,n2); if (m bckind.GetAt(3)==0 && m bckind.GetAt(0)==0) u[0*(n2+1)+n2]=(G4(0,j,n1)+G1(n2,j,n2))/2; } else { u[0*(n2+1)+n2]=(1-2*r1-2*r2)*v[0*(n2+1)+n2]+ 2*r1*(v[1*(n2+1)+n2]+dx*G1(n2,j,n2))+ 2*r2*(v[0*(n2+1)+n2-1]+dz*G4(n1,j,n1));
wsdac04
163
[13]
[14]
[15]
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
164
} } delete []v; } else { for (i = 0; i < n1+1; i++) { for (k = 0; k < n2+1; k++) u[i*(n2+1)+k]= Phi(i, k, n2); } }
...
[16]
}
[1] As emphasized in [16], for j = 0 the u array is initialized by the values given by the initial condition. For j > 0... [2] ... the u array is copied into the v array and... [3] ... this is used in computing the new values by algorithm (7.1.7). [4] We exclude the grid points x = 0, z = 0 and x = 0, z = Lz , corresponding to k = 0 and k = nz , respectively. The values of u related to these points will be computed later. [5] In the case of boundary conditions of the first kind formula (7.1.12) is used. Otherwise, formula (7.1.17) is applied. [6] We exclude the grid points x = 0, z = 0 and x = Lx , z = 0, corresponding to i = 0 and i = nx , respectively. The values of u related to these points will be computed later. [7] In the case of boundary conditions of the first kind formula (7.1.13) is used. Otherwise, formula (7.1.18) is applied. [8] We exclude the grid points x = Lx , z = 0 and x = Lx , z = Lz , corresponding to k = 0 and k = nz , respectively. The values of u related to these points will be computed later. [9] In the case of boundary conditions of the first kind, formula (7.1.14) is used. Otherwise, formula (7.1.19) is applied. [10] We exclude the grid points x = 0, z = Lz and x = Lx , z = Lz , corresponding to i = 0 and i = nx , respectively. The values of u related to these points will be computed later. [11] In the case of boundary conditions of the first kind formula (7.1.15) is used. Otherwise, formula (7.1.20) is applied. [12] The grid point x = 0, z = 0 is considered. If the boundary condition
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
The Heat3 Project
wsdac04
165
on the side x = 0 is of the first kind, then formula (7.1.26) is applied. If the boundary condition on the side z = 0 is of the first kind, then formula (7.1.25) is used. If both conditions are of the first kind, then formula (7.1.27) is applied. In the last case, where both conditions are of the second kind, formula (7.1.20) is used. Similarly, the other three corners are treated, see [13], [14], [15]. [13] Grid point x = Lx , z = 0. [14] Grid point x = Lx , z = Lz . [15] Grid point x = 0, z = Lz . [16] The u array is initialized by the values given by the initial condition. The following functions allow us to find the maximum and the minimum of the function u. Listing 7.5.9 double CHeat3View:: Min(double u[], double m, int n1, int n2) { for (int i = 0; i < n1+1; i++) { for (int k = 0; k < n2+1; k++) { if (u[i*(n2+1)+k]<m) m=u[i*(n2+1)+k]; } } return m; } double CHeat3View:: Max(double u[], double m, int n1, int n2) { for (int i = 0; i < n1+1; i++) { for (int k = 0; k < n2+1; k++) { if (u[i*(n2+1)+k]>m) m=u[i*(n2+1)+k]; } } return m; }
Now, new code is added in the GraphResults function, Listing 7.5.5. This will provide the program the functionality of painting the temperature. The user will be able to fix a section, parallel to the x-axis or to the y-axis. This section will be emphasized in the physical domain. The corresponding temperature will be drawn in the larger rectangle. Suitably varying the sections
July 3, 2004
23:17
166
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
yields a complete description of the thermal process. The code given in the next listing has to be inserted in the GraphResults function, Listing 7.5.5, replacing the line // Add new code here, which should be canceled. Listing 7.5.10 void CHeat3View::GraphResults(CDC* pDC) { ... if (controlv >0) { ... // Add new code here if (controlv == 21) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . { int i=0,k=0,j=0,xzero=V1+D,uzero=-(V1+V2)/2,uunit=30; double urd=xzrd,*u, m[2]; m[0]=0.,m[1]=0.; u = new double[(nx+1)*(nz+1)]; if (u != NULL ) { for (i = 0; i < nx+1; i++) { for (k = 0; k < nz+1; k++) u[i*(nz+1)+k]=0.; } for (j = 0; j < nt+1; j++) { FiniteDifference(j,rx,rz,u,nx,nz); m[0]=Min(u,m[0],nx,nz); m[1]=Max(u,m[1],nx,nz); } if (m[1]-m[0]>0) { if (m[0]>=0) { uzero=-V2+D; urd=(V2-V1-2*D)/m[1]; } else if (m[1]<=0) { uzero=-V1-D; urd=-(V2-V1-2*D)/m[0]; } else { uzero=(int)(((V1+D)*m[0]-(V2-D)*m[1])/(m[1]-m[0]));
[1]
August 1, 2004
14:48
WSPC/Book Trim Size for 9in x 6in
The Heat3 Project
urd=-(V1+D+uzero)/m[1]; }
} str.Format(”U-scale: 1 = %g”, uunit/urd); pDC->TextOut(V2+D, -21, str); str.Format(”Boundary 1: kind %d”, 1+m bckind.GetAt(0)); pDC->TextOut(V1+5, -V2-25, str); str.Format(”Boundary 2: kind %d”, 1+m bckind.GetAt(1)); pDC->TextOut(V1+145, -V2-25, str); str.Format(”Boundary 3: kind %d”, 1+m bckind.GetAt(2)); pDC->TextOut(V1+5, -V2-45, str); str.Format(”Boundary 4: kind %d”, 1+m bckind.GetAt(3)); pDC->TextOut(V1+145, -V2-45, str); pDC->MoveTo(xzero,-V2+D); pDC->LineTo(xzero,-V1-D); pDC->MoveTo(xzero,uzero); if (m display == 0) { pDC->LineTo(GraphC(Lx, xzrd, xzero),uzero); pDC->MoveTo(GraphC(Lx, xzrd, xzero),-V2+D); pDC->LineTo(GraphC(Lx, xzrd, xzero),-V1+D); str.Format(”X-scale: 1 = %g”, dx); pDC->TextOut(V2+5, -1, str); for (i = 1; i < nx; i++) { pDC->MoveTo(GraphC(i*dx,xzrd,xzero), uzero-2); pDC->LineTo(GraphC(i*dx,xzrd,xzero), uzero+2); } pDC->MoveTo(GraphC(m ii*dx, xzrd, xzero),uzero-5); pDC->LineTo(GraphC(m ii*dx, xzrd, xzero),uzero+5); str.Format(”x=%g”, m ii*dx); pDC->TextOut(V2+5, -V2+40, str); pDC->MoveTo(V4+D,GraphC(m is*dz,xzrd/2,-V5+D)); pDC->LineTo(GraphC(Lx,xzrd/2,V4+D), GraphC(m is*dz,xzrd/2,-V5+D)); str.Format(”Section z = %g”, m is*dz); } else { pDC->LineTo(GraphC(Lz, xzrd, xzero),uzero); pDC->MoveTo(GraphC(Lz, xzrd, xzero),-V2+D); pDC->LineTo(GraphC(Lz, xzrd, xzero),-V1+D); str.Format(”Z-scale: 1 = %g”, dz); pDC->TextOut(V2+5, -1, str); for (k = 1; k < nz; k++) {
wsdac04
167
July 3, 2004
23:17
168
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
pDC->MoveTo(GraphC(k*dz,xzrd,xzero), uzero-2); pDC->LineTo(GraphC(k*dz,xzrd,xzero), uzero+2); } pDC->MoveTo(GraphC(m ii*dz, xzrd, xzero),uzero-5); pDC->LineTo(GraphC(m ii*dz, xzrd, xzero),uzero+5); str.Format(”z=%g”, m ii*dz); pDC->TextOut(V2+5, -V2+40, str); pDC->MoveTo(GraphC(m is*dx,xzrd/2,V4+D),D-V5); pDC->LineTo(GraphC(m is*dx,xzrd/2,V4+D), GraphC(Lz,xzrd/2,D-V5)); str.Format(”Section x = %g”, m is*dx); } pDC->TextOut(V6+15, -140, str); for (i = uunit; i < -(uzero+V1+D); i=i+uunit) { pDC->MoveTo(V1+D-1,uzero+i); pDC->LineTo(V1+D+2,uzero+i); } for (i = uunit; i < (uzero+V2-D); i=i+uunit) { pDC->MoveTo(V1+D-1,uzero-i); pDC->LineTo(V1+D+2,uzero-i); } for (i = 0; i < nx+1; i++) { for (k = 0; k < nz+1; k++) u[i*(nz+1)+k]=0.; } for (j = 0; j < m jj+1; j++) FiniteDifference(j,rx,rz,u,nx,nz); if (m display == 0) { pDC->MoveTo(GraphC(0., xzrd, xzero), GraphC(u[0*(nz+1)+m is], urd, uzero)); for (i = 0; i < nx; i++) { pDC->LineTo(GraphC((i+1)*dx, xzrd, xzero), GraphC(u[(i+1)*(nz+1)+m is], urd, uzero)); } str.Format(”u= %7.4f”,u[m ii*(nz+1)+m is]); } else { pDC->MoveTo(GraphC(0., xzrd, xzero), GraphC(u[m is*(nz+1)+0], urd, uzero)); for (k = 0; k < nz; k++) { pDC->LineTo(GraphC((k+1)*dz, xzrd, xzero),
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
The Heat3 Project
wsdac04
169
GraphC(u[m is*(nz+1)+k+1], urd, uzero)); } str.Format(”u= %7.4f”,u[m is*(nz+1)+m ii]); } pDC->TextOut(V2+100, -V2+30, str); str.Format(”t=%lf”, m jj*dt); pDC->TextOut(V2+5, -V2+20); } else pDC->TextOut(V1+D, -10, ”Insufficient memory”); delete []u; }
}
}
[1] If the Graphical item is clicked, the finite-difference algorithm is applied and the solution is painted. Furthermore, since the program requires the use of some keys, the handler functions must be introduced. The procedure is the following. 1. Select the ClassView tab, right-click CHeat3View to display the context menu. 2. Click Add Windows Message Handler to obtain the New Windows Message and Event Handlers box. Here, double-click WM KEYDOWN and, then, WM LBUTTONDOWN. 3. Pressing the Edit Existing button edits the skeleton of the OnKeyDown, OnLButtonDown functions, which must be implemented as in the following listing. Listing 7.5.11 void CHeat3View::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { CHeat3Doc* pDoc = GetDocument(); ASSERT VALID(pDoc); if (pDoc->GetControl() > 20) { if(nChar==VK UP || nChar==VK DOWN || nChar==VK LEFT || nChar==VK RIGHT || nChar==VK ADD || nChar==VK SUBTRACT) { switch (nChar) { . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . [1] case VK SUBTRACT: m ii=0; if (m is > 0) m is −−;
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
170
break; ............................................... case VK ADD: m ii=0; if (m display == 0) { if (m is < pDoc->GetNz()) m is ++; } else { if (m is < pDoc->GetNx()) m is ++; } break; case VK UP: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . if(m jj< pDoc->GetNt()) m jj++; else m jj=0; break; ............................................ case VK DOWN: if ( m jj > 0) m jj- -; else m jj = pDoc->GetNt(); break; .............................................. case VK LEFT: if(m ii> 0) m ii- -; break; ............................................. case VK RIGHT: if (m display == 0) { if ( m ii < pDoc->GetNx()) m ii++; } else { if ( m ii < pDoc->GetNz()) m ii++; } break; } Invalidate(); } } CScrollView::OnKeyDown(nChar, nRepCnt, nFlags); } void CHeat3View::OnLButtonDown(UINT nFlags, CPoint point) { CHeat3Doc* pDoc = GetDocument(); ASSERT VALID(pDoc); if (pDoc->GetControl() > 20) {
[1]
[2]
[3]
[4]
[5]
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
The Heat3 Project
if (m display == 0) m display = 1; else m display = 0; m jj = 0; m ii = 0; m is = 0; Invalidate();
...............................
wsdac04
171
[6]
} CScrollView::OnLButtonDown(nFlags, point); }
[1] When the − and the + keys are pressed (in the numerical keypad), the m is value is decreased and increased, respectively. The temperature of the corresponding section is shown. [2] When the UP key is pressed, if the actual time t is less than T , the mjj variable is increased and the temperature at time t + dt is obtained. Instead, if t = T , the initial values are shown. [3] If the Down key is pressed, the mjj variable is decreased and the temperature at time t − dt is printed. If t = 0, the final values are shown. [4] When the LEFT key is pressed, the m ii variable is decreased and the program will print the temperature value at x-dx, where x is the position of the moving segment. [5] When the RIGHT key is pressed, the m ii variable is increased and the opposite effect is obtained. [6] If the m display variable assumes the zero value, then sections parallel to x-axis are considered; otherwise, sections parallel to z-axis are examined. A last function, NumResults, will be introduced in the next section. Compile and test.
7.6
Using the program
In this section the use of the program is briefly illustrated by a simple example. Example 7.6.1
Consider the following problem
ut = uxx + uzz , 0 < x < 10, 0 < z < 4, 0 < t ≤ 1, u(x, z, 0) = x2 + z 2 , 0 ≤ x ≤ 10, 0 ≤ z ≤ 4,
July 3, 2004
23:17
172
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
u(0, z, t) = z 2 + 4t, u(10, z, t) = 100 + z 2 + 4t, 0 ≤ z ≤ 4, 0 ≤ t ≤ 1, u(x, 0, t) = x2 + 4t, u(x, 4, t) = 16 + x2 + 4t, 0 ≤ x ≤ 10, 0 ≤ t ≤ 1, which admits the solution u(x, t) = x2 + z 2 + 4t. The following data α = 1, Lx = 10, Lz = 4, T = 1, N x = 20, N z = 8, N t = 16, as well as the initial and boundary data have been saved in the Example761.hth file, which is supplied with the CD. Therefore, execute the program and open this file to explore the program. Now, the capabilities of the program are illustrated. When the Graphical item is clicked a picture as in fig. 7.6.1 should appear. More precisely,
Fig. 7.6.1
Graphical results
to obtain exactly the above figure follow the next steps. 1. Press the + key (on the numerical keypad) until the section z = 2 appears.
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
The Heat3 Project
wsdac04
173
2. Press the DOWN key to display the graphics of the temperature for the mentioned section at time t = 1. 3. Press the RIGHT key to move the moving segment to the point of abscissa x = 4. The temperature value (corresponding to x = 4, z = 2, t = 1) should be printed: u = 24. If the mouse is clicked on the picture, the results related to sections parallel to z-axis can be shown. Finally, to show the numerical results, the following function must be implemented. Listing 7.6.1 void CHeat3View::NumResults(CDC* pDC) { CHeat3Doc* pDoc = GetDocument(); ASSERT VALID(pDoc); int nx=pDoc->GetNx(), nz=pDoc->GetNz(), nt=pDoc->GetNt(); int i=0, j=0, k=0, xstep=190, ystep=20; double al=pDoc->GetAl(), Lx=pDoc->GetLx(), Lz=pDoc->GetLz(); double Tt=pDoc->GetTt(), dx=Lx/nx, dz=Lz/nz, dt=Tt/nt; double rx=al*dt/(dx*dx), rz=al*dt/(dz*dz); double *u; CString str=””; u = new double[(nx+1)*(nz+1)]; if (u != NULL ) { pDC->TextOut(V1+5, -20, ”Elaborating...”); for (i = 0; i < nx+1; i++) { for (k = 0; k < nz+1; k++) u[i*(nz+1)+k]=0.; } for (j = 0; j < m jj+1; j++) FiniteDifference(j,rx,rz,u,nx,nz); str.Format(”Numerical values of u(x,z,%g)”,m jj*dt); pDC->TextOut(V1+5, -20,str); pDC->TextOut(V1, -50,”z”); pDC->TextOut(V1+45, -50,”x”); pDC->MoveTo(0,-70); pDC->LineTo(10+xstep*(nx+1),-70); pDC->MoveTo(60,-55); pDC->LineTo(60,-80-ystep*(nz+1)); for (i = 0; i < nx+1; i++) { str.Format(”%g”,i*dx); pDC->TextOut(70+xstep*i,-50,str);
July 3, 2004
23:17
174
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
for (k = 0; k < nz+1; k++) { str.Format(”%g”,k*dz); pDC->TextOut(1,-80-ystep*k,str); str.Format(”%g”,u[i*(nz+1)+k]); pDC->TextOut(70+xstep*i,-80-ystep*k,str); }
} } else pDC->TextOut(V1+5, -V2-10, ”Insufficient memory”); delete []u; m xDocSize=200*(nx+1); m yDocSize=25*(nz+1); }
Lastly, specialize the four icons. Further Reading: [Bates and Tomkins (1998)], [Buzzi Ferraris (2000)], [Chapman (1998)], [Gregory (1997)], [Kernigham and Ritchie (1978)], [Kharab and Guenther (2002)], [Kruglinski, Sheperd and Wingo (1998)].
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Chapter 8
Wave motions
Wave motions are very common phenomena. Propagation of a disturbance is frequently observable in any medium, gas, liquid, solid and even in the vacuum. The study of waves is a fascinating subject which attracted the scientists from the early history of the science. The wave equation is historically related to D’Alembert (1717-1783), the French scientist who derived the equation of a string and solved the initial value problem. This chapter deals with examples of wave motions which occurs in Mechanics. The first model is related to the one-dimensional continuum. The equation governing the motion of a string is derived as special case. After discussing the basic principles of continuous systems, we introduce the equations of elastic solids and the Navier-Stokes equations for fluids. The related wave motions are pointed out. A last section is devoted to a free piston problem arising in Gas Dynamics.
175
wsdac04
July 3, 2004
23:17
176
8.1
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
One-dimensional continuum
The model of one-dimensional continuum is adopted for solid systems where one dimension prevails clearly over the others (thin rods, strings, cables,...). In these cases the system is geometrically modelled by a curved line, denoted by b, and formed, for example, by of the centers of gravity related to solid sections orthogonal to b. The co-ordinates of any point, say P ∈ b, depend uniquely on the curvilinear abscissa s and the time t. Also, the radius vector x depends on the same co-ordinates, fig. 8.1.1, x = x(s, t), ⇔ xi = xi (s, t), i = 1, 2, 3.
Fig. 8.1.1
One-dimensional continuum
The forces acting on solid systems are usually subdivided in internal forces and external forces (including the eventual constraint reactions). The last ones can be concentrated or distributed. The concentrated forces are applied to a finite numbers of points Qi of the solid. When this is modelled by b, it can happen that some Qi ∈ b. The problem is solved by replacing the force by an equivalent force-couple system. As a consequence, a general system of concentrated forces acting on b is given by {(Pi , Fi ), Mi , i = 1, ..., N }, where Mi means couple of moment about point Pi . Similarly, the distributed force system is summarized by the vector functions {(P, F), Ms }, where the subscript s means point characterized by abscissa s. The internal forces arise from the contact of the interior points and we denote by Rσ and Mσ the resultant and the moment, respectively, of these forces in any
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Wave motions
177
section σ = σ(s). More precisely, Rσ , Mσ are related to the internal forces acting on the sub-system with abscissa less than s. Thus, the internal forces acting on the part of system with abscissa greater than s are characterized by −Rσ , −Mσ , fig. 8.1.1. Consider the motion of the part of one-dimensional continuum delimited by any two points, say P , P , and denote by s and s , their respective abscissas. In addition, let µ be the density per unit length and a the acceleration of the generic point. From the laws of Dynamics it follows
µads = s
s
s
n(s ,s )
s
Fi +
i=1
(x − xQ ) × µads =
s s
s
s
Fds + Rσ − Rσ ,
(8.1.1)
[(x − xQ ) × F + Ms ] ds + Mσ − Mσ
n(s ,s )
+
[(xi − xQ ) × Fi + Mi ]+(x −xQ )×Rσ −(x −xQ )×Rσ , (8.1.2)
i=1
where n(s , s ) is the number of points, between P and P , where concentrated force-couples act and x, x , x , xQ , xi represent the radius vectors of the points P , P , P , Q, Pi , respectively. Furthermore, if F0 , M0 , FL , ML denote the resultants and the moments of the external forces acting on end points P0 and PL , the internal forces must satisfy the following boundary conditions Rσ0 = −F0 , Mσ0 = −M0 , RσL = FL , MσL = ML .
(8.1.3)
By considering (8.1.3), let us specialize equations (8.1.1), (8.1.2) to the case P = P0 , P = P , where P is any point of b different from Pi , i = 1, ..., N ,
s
so
s
so
n(s)
(F − µa)d¯ s+
Fi + Rσ + F0 = 0,
(8.1.4)
i=1
[(¯ x − xo ) × (F − µa) + Ms¯] d¯ s + Mσ + Mo + (x − xo ) × Rσ n(s)
+
i=1
[(xi − xo ) × Fi + Mi ] = 0,
(8.1.5)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
178
¯ is the radius vector related to the generic point where n(s) = n(so , s) and x ¯ P of abscissa s¯, so < s¯ < s. Next, differentiate (8.1.4), (8.1.5) with respect to s ∂Rσ + F − µa = 0, ∂s
(8.1.6)
∂Mσ + t × Rσ + Ms = 0, ∂s
(8.1.7)
where t = ∂x/∂s. Formulas (8.1.6), (8.1.7) define the local equations of one-dimensional continuum. Consider the points Pi , excluded by the preceding analysis. Focus attention on one of these points, say Ph with abscissa sh , and choose ∆s > 0 so that s = sh − ∆s > sh−1 and s = sh + ∆s < sh+1 . Denote by P and P the points having abscissas s , s , respectively, and apply equations (8.1.1), (8.1.2) s (F − µa)ds = 0, (8.1.8) Fh + Rσ − Rσ + s
Mh + (x − xh ) × Rσ − (x − xh ) × Rσ + Mσ − Mσ
s
+ s
(x − xh ) × (F − µa)ds +
s
s
Ms ds = 0,
(8.1.9)
where Q = Ph . Setting lim Rσ = Rσ+ , lim Rσ = Rσ− , h
∆s→0
∆s→0
h
and letting ∆s → 0 in (8.1.8), it follows Fh + Rσ+ − Rσ− = 0. h
h
(8.1.10)
This shows that Rσ has a discontinuity of the first kind on Ph and ∆Rσh = −Fh .
(8.1.11)
Similarly, from (8.1.9) it follows ∆Mσh = −Mh .
(8.1.12)
Note that no role has been played by the inertial force −µa. Consequently, the jump relationships (8.1.11) and (8.1.12) hold in Statics as well as in Dynamics.
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Wave motions
8.2
wsdac04
179
Flexible strings
The model of perfectly flexible string applies to one-dimensional continuum with the following characteristics: (1) the string cannot resist to bending moment Mσ = 0;
(8.2.1)
(2) single elements are subjected to no elongation, so that any part of the system keeps constant length and |t| = 1;
(8.2.2)
(3) the string cannot resist to compression Rσ · t ≥ 0;
(8.2.3)
(4) the external forces acting on the string are such that Ms = 0, Mi = 0, ∀i.
(8.2.4)
Considering all this, the second local equation (8.1.7) reduces to Rσ = T t, T ≥ 0. The vector Rσ = T t represents the (vector) tension and it is denoted by T = T t.
(8.2.5)
It is completely characterized by the scalar T , which, for this reason, is called (scalar) tension. Using definition (8.2.5) in local equation (8.1.6) gives the equation governing the motion of a string ∂T + F − µa = 0. ∂s 8.3
(8.2.6)
Wave equation
This section deals with the small transverse motions of a string around its rectilinear position of equilibrium. Consider a reference system Oxyz with x-axis along the string at rest. The components of the unit vector t
July 3, 2004
23:17
180
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
with respect to y and z are very small. Therefore, the hypothesis of small oscillations is summarized by 2 2 ∂z ∂y = = 0. (8.3.1) ∂s ∂s In addition, since these imply
∂x ∂s
2 = 1,
it can be assumed x = s. Next, from (8.2.6) it follows ∂T + Fx = 0, ∂x
(8.3.2)
∂ ∂2y µ 2 = ∂t ∂x
∂y T + Fy , ∂x
(8.3.3)
∂2z ∂ = 2 ∂t ∂x
∂z T + Fz . ∂x
(8.3.4)
µ
Solving equation (8.3.2) yields the tension T , unless a constant depending on the boundary conditions. Integrating the remaining equations gives the unknown functions y(x, t), z(x, t). Furthermore, the vector tension T = T t is expressed by ∂y ∂z ,T . (8.3.5) T = T, T ∂x ∂x Equations (8.3.3) and (8.3.4) are similar and summarized by the following partial differential equation ∂ ∂u ∂2u T + F, (8.3.6) µ 2 = ∂t ∂x ∂x which, substantially, governs the small transverse motions of flexible strings. When T is independent of x, equation (8.3.6) simplifies in 2 ∂2u 2∂ u = c + f, ∂t2 ∂x2
(8.3.7)
where c2 = T /µ,
f = F/µ.
(8.3.8)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Wave motions
wsdac04
181
Equation (8.3.7) is called (one-dimensional) wave equation. Note that the coefficient c, defined by (8.3.8), is expressed in m/s. It represents the propagation velocity of waves along the string. Lastly, when the string motions occur in a plane, say xu, equation (8.3.7) is the only equation that needs, and the vector tension is characterized by (T, T ux ).
(8.3.9)
Integrating equation (8.3.7) gives the unknown function u(x, t), which describes the motion of the string. However, the problem can be successfully solved only when the initial conditions and the boundary conditions are prescribed too. The first ones consist in assigning position and velocity field of the string at a prefixed time, usually the initial status u(x, 0) = ϕ(x),
ut (x, 0) = ψ(x), 0 ≤ x ≤ L.
(8.3.10)
Furthermore, quite general boundary conditions are a1 ux (0, t)+b1 u(0, t) = g1 (t), a2 ux (L, t)+b2 u(L, t) = g2 (t), t > 0. (8.3.11) Special boundary conditions, frequently used in applications, are now stated with reference to the end x = 0.
Fig. 8.3.1
Boundary conditions
• End in motion with prescribed law, or fixed, u(0, t) = g1 (t), or u(0, t) = 0; this last case is shown in fig. 8.3.1 (left). • Vanishing tension, fig. 8.3.1, or prescribed tension; by considering (8.3.9), these conditions are expressed by ux (0, t) = 0, or ux (0, t) = g1 (t).
July 3, 2004
23:17
182
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
• Elastic spring of coefficient k acting on the end, fig. 8.3.1 (right), T ux(0, t) − ku(0, t) = 0. Wave equation is involved in numerous physical processes. Some of these models occurring in Mechanics will be discussed in the next sections.
8.4
Waves in elastic solids
Elastic solids are special continuous media. The equations modelling solid systems follow from general principles, accepted as true on the basis of physical experiences. Consider a moving solid and let V be the control volume of bounding surface ∂V , fig. 8.4.1. The principle of conservation of
Fig. 8.4.1
Control volume
mass states that the time rate of the change of mass must be zero d ρ(x, t) dx = 0, (8.4.1) dt V where ρ denotes the density. An equivalent form of (8.4.1) is obtained by using the transport theorem . If g(x, t) is a continuous differentiable function, this theorem states, e.g. [Guenther and Lee (1988)], d g(x, t) dx = gt dx + g x˙ · n dS, (8.4.2) dt V V ∂V
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Wave motions
wsdac04
183
where x˙ = v is the velocity and n denotes the outward unit normal to ∂Ω at the integration point. Applying the Gauss divergence theorem, (8.4.2) is rewritten as d ˙ dx, g(x, t) dx = [gt + ∇ · (g x)] (8.4.3) dt V V or, d dt
g(x, t) dx =
V
V
˙ dx. [g˙ + g∇ · x]
Now, replace g by ρ and use (8.4.1) to obtain ˙ dx = 0, [ρ˙ + ρ∇ · x]
(8.4.4)
(8.4.5)
V
which holds for any control volume. Hence, ρ˙ + ρ∇ · x˙ = 0.
(8.4.6)
This equation is the local version of (8.4.1) and it is called continuity equation. Another form of the continuity equation is ˙ = 0, ρt + ∇ · (ρx)
(8.4.7)
which follows from (8.4.3). Remark 8.4.1
Replace g by ρg in (8.4.4) and use (8.4.6) to find d ρg dx = ρg˙ dx. (8.4.8) dt V V
The principle of conservation of momentum states that the time rate of the change of momentum is equal to total forces (surface traction + body forces), d ρv dx = Tn dS + ρ f dx. (8.4.9) dt V ∂V V Here, the vector Tn is related to the stress tensor T T = (Tij ), i, j = 1, 2, 3,
(8.4.10)
by the Cauchy relationship Tn = T · n, ⇔ (Tn )i =
3 j=1
Tij nj , i = 1, 2, 3.
(8.4.11)
July 3, 2004
23:17
184
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
By considering this result and the Gauss theorem, from (8.4.9) it follows ρ a dx = div T dx + ρ f dx, (8.4.12) V
V
V
where the vector div T is defined by (div T)i =
3 ∂Tij j=1
∂xj
, i = 1, 2, 3.
(8.4.13)
Since V is arbitrary, from (8.4.12) it follows ρ a = div T + ρ f ,
(8.4.14)
which is the local version of conservation of moment. The principle of conservation of moment of momentum states that the time rate of the change of moment of momentum is equal to the sum of moments of all the forces, d x × vρ dx = x × Tn dS + x × f ρ dx. (8.4.15) dt V ∂V V A consequence of (8.4.15) is the symmetry of the stress tensor, as stated in the next exercise. Exercise 8.4.1 Write equation (8.4.15) in scalar form. Use the Gauss theorem and (8.4.14) to verify that Tij = Tji , i, j = 1, 2, 3 ⇔ T = TT .
(8.4.16)
Equations (8.4.6), (8.4.14), (8.4.16) hold for any type of continuous system. When special media are considered, further equations must be supplied, depending on the specific properties of the material: the constitutive equations. In the case of elastic solid these are given by the generalized Hooke’s law, which functionally relates stress to strain. In linear elasticity the strain tensor ε=(εij ) is defined by 1 ∂ui ∂uj εij = + , i, j = 1, 2, 3, (8.4.17) 2 ∂xj ∂xi where u = (ui ) is the displacement vector. For isotropic elastic media, stress-strain relationship takes the form T = λ∇ · u I + 2µ ε,
(8.4.18)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Wave motions
wsdac04
185
where I is the unit tensor, (I)ij = δij =
1 if i = j 0 if i = j
and λ, µ are the Lam´e parameters, which reduce to constant coefficients for homogeneous elastic bodies. In index notation, (8.4.18) becomes Tij = λ∇ · u δij + 2µ εij , i, j = 1, 2, 3.
(8.4.19)
Substituting expression (8.4.18) into equation (8.4.14) gives ρutt = (λ + µ)∇θ + µ∆u + ρ f ,
(8.4.20)
θ = ∇ · u,
(8.4.21)
where
defines the dilatation. If θ = 0, equation (8.4.20) becomes utt = c2 ∆u + f , where c=
µ/ρ.
(8.4.22)
(8.4.23)
Equation (8.4.22) is the three-dimensional wave equation and c is the propagation velocity of the waves. Since the volume dilatation is zero, these waves are called equivoluminal waves, or distortional waves. Furthermore, straightforward calculations show the vector identity ∆u + ∇ × u = ∇∇ · u,
(8.4.24)
which, in terms of the rotation vector ω, defined by ω = (1/2)∇ × u,
(8.4.25)
∆u + 2∇ × ω = ∇∇ · u.
(8.4.26)
is rewritten as
For irrotational motions, where ω= 0, relation (8.4.24) becomes ∆u = ∇∇ · u.
(8.4.27)
Substituting this result into (8.4.20) gives utt = c21 ∆u + f ,
(8.4.28)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
186
where c1 =
(λ + 2µ)/ρ.
(8.4.29)
Wave equation (8.4.28) emphasizes that the irrotational waves propagate at velocity c1 . These waves are also called dilatational waves. 8.5
Motion of fluids
Fluids, including gases, are modelled as continuous media and their motions are governed by equations (8.4.6), (8.4.14), (8.4.16), which hold for any continuous system. Of course, fluids are characterized by specific constitutive relationships. Following Stokes, it is assumed T = (−p + λ∇ · v)I + 2µD,
(8.5.1)
where p denotes the pressure, I the unit tensor and D = (Dij ) is the tensor defined by 2Dij =
∂vi ∂vj + . ∂xj ∂xi
(8.5.2)
The scalars λ and µ are viscosity coefficients and, according to Thermodynamics, it is µ ≥ 0, 3λ + 2µ ≥ 0.
(8.5.3)
µ ≥ 0, λ = −2µ/3.
(8.5.4)
Usually,
If the expression of tensor T is inserted into equation (8.4.6), which is rewritten for convenience, dv = div T + ρ f , dt
(8.5.5)
2µ −p − ∇ · v I + 2µD + ρ f . 3
(8.5.6)
ρ it follows ρ
∂v + ρ(v · ∇)v = div ∂t
When the viscosity coefficients are constants, the last equation becomes ρ
µ ∂v + ρ(v · ∇)v + ∇p = ∇(∇ · v) + µ∆v + ρf , ∂t 3
(8.5.7)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Wave motions
wsdac04
187
or, in index notation, ρ
∂vi ∂p µ ∂ + ρ(v · ∇)vi + = (∇ · v) + µ∆vi + ρfi , i = 1, 2, 3. (8.5.8) ∂t ∂xi 3 ∂xi
These equations are called Navier-Stokes equations. In the case of ideal fluids, it is µ = 0 and equations (8.5.8) reduce to ∂v + ρ(v · ∇)v + ∇p = ρf , ∂t
(8.5.9)
∂vi ∂p + ρ(v · ∇)vi + = ρfi , i = 1, 2, 3. ∂t ∂xi
(8.5.10)
ρ
ρ
Considering that the continuity equation ρt + ∇ · (ρv) = 0,
(8.5.11)
still holds, four equations are available, involving five unknown functions: pressure, density and velocity components vi . A further equation is required. This follows from the energy conservation. Probably, the simplest case if given by an isentropic gas, where the pressure is functionally related to the density by p = Aργ .
(8.5.12)
Here, A is a positive constant and γ = cp /cv ,
(8.5.13)
where cp and cv are the specific heats at constant pressure and constant volume, respectively. For all gases it is γ > 1 and for most of them γ < 2. Equation (8.5.12) allows us to eliminate the pressure from (8.5.7)-(8.5.10). Indeed, from the definition of sound speed c c2 (ρ) =
∂p = Aγργ−1 , ∂ρ
(8.5.14)
it follows ∂p ∂ρ = c2 , i = 1, 2, 3, ∂xi ∂xi
(8.5.15)
∇p = c2 ∇ρ.
(8.5.16)
equivalent to
July 3, 2004
23:17
188
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
For example, for one-dimensional motions and f = 0, it follows ρ
∂v ∂v 4µ ∂ 2 v ∂ρ + ρv + c2 = , ∂t ∂x ∂x 3 ∂x2
(8.5.17)
∂ρ ∂(ρv) + = 0, ∂t ∂x
(8.5.18)
where x = x1 and v = v1 . Finally, let us discuss the linear case. The condensation σ is defined by σ = (ρ − ρ0 )/ρ0 ⇔ ρ = ρ0 (1 + σ),
(8.5.19)
where ρ0 = constant is a reference value. By using this new function in equations (8.5.17), (8.5.18), it follows (1 + σ)vt + (1 + σ)vvx + c2 σx = νvxx ,
(8.5.20)
σt + σx v + (1 + σ)vx = 0,
(8.5.21)
where ν denotes the kinematic coefficient of viscosity ν = 4µ/3ρ0.
(8.5.22)
In the linear case, higher-order terms are neglected and it results vt + c2 σx = νvxx ,
(8.5.23)
σt + vx = 0,
(8.5.24)
c2 = Aγργ−1 . 0
(8.5.25)
where
From system (8.5.23)-(8.5.24) it follows that both v and σ satisfy the same third-order equation vtt − c2 vxx = νvxxt ,
(8.5.26)
known as perturbed wave equation. Evidently, when there is no viscosity, equation (8.5.26) becomes the wave equation vtt − c2 vxx = 0.
(8.5.27)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Wave motions
8.6
wsdac04
189
Free piston problem
Consider a cylinder filled with gas which can expand between the fixed base of the cylinder and the movable head of the piston, fig. 8.6.1. This
Fig. 8.6.1
Free piston problem
physical process can be modeled by a free-boundary-value problem. In fact, the piston motion depends on the forces acting on the piston, but it is influenced by the gas pressure too. On the other hand, the gas evolution depends on the location of the piston, which delimits the region occupied by the gas. Thus, piston and gas motions are mutually related and both problems must be jointly solved. As example, consider the simple model of one-dimensional motions of ideal gas in the framework of linear theory. The gas evolution is governed by the following equations ), vt + c2 σx = 0, (c2 = Aγργ−1 0
(8.6.1)
σt + vx = 0.
(8.6.2)
The piston path is described by the function x = s(t) and the piston motion is governed by the Newton’s law m¨ s = αp(s, t) + F (s, s, ˙ t),
(8.6.3)
where m denotes the mass of the piston and α the area of its head. Friction forces, depending on s(t), ˙ inevitably arise during the motion. These forces are included in the general forcing term F . In addition, the gas particles at x = s(t) must move with the same velocity as the piston v(s(t), t) = s(t). ˙
(8.6.4)
July 3, 2004
23:17
190
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
The pressure p is functionally related to σ; from relation (8.5.12) it follows p = Aργ0 (1 + σ).
(8.6.5)
Substituting this result into (8.6.3) yields ˙ t). m¨ s = Aαργ0 (1 + σ(s, t)) + F (s, s,
(8.6.6)
The problem is completed by the initial conditions ˙ = s˙ 0 , s(0) = s0 , s(0)
(8.6.7)
v(x, 0) = ϕ(x), σ(x, 0) = ψ(x), 0 ≤ x ≤ s0 ,
(8.6.8)
and the boundary condition on the fixed wall x = 0 v(0, t) = g(t), t > 0.
(8.6.9)
This last condition is physically connected with the mass of gas which enters or leaves the cylinder. Note that two boundary conditions, (8.6.4) and (8.6.6), have been assigned on the free boundary, as, in this case, there is a further unknown to be determined: the function x = s(t). Since, as already remarked, equations (8.6.1), (8.6.2) imply vtt − c2 vxx = 0, σtt − c2 σxx = 0,
(8.6.10)
the problem is an example of free-boundary-value problem for wave equation. Further Reading: [Duffy (1986)], [Graff (1975)], [Guenther and Lee (1988)], [Kevorkian (1990)], [Myint-U and Debnath (1987)].
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Chapter 9
Finite-difference methods for the wave equation
Applications involving the wave equation occur in a variety of different fields, ranging from Continuum Mechanics, Fluid Dynamics, Electromagnetism, General Relativity. Due to its importance, several numerical methods have been developed for this equation. In this chapter we introduce the most used finite-difference schemes for the wave equation. Both explicit and implicit schemes are discussed. Their application is shown by examples and the stability analysis is performed. Furthermore, it must be outlined that, since this second-order equation can be reduced to a system of first-order equations, more general methods can be specialized to this case. Hyperbolic systems will be studied in Chapter 10. Also, we consider the perturbed wave equation, which provides an example of third-order equation. An explicit method for this equation is illustrated.
191
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
192
9.1
wsdac04
Courant-Friederichs-Lewy method
Consider the homogeneous wave equation Utt − c2 Uxx = 0, 0 < x < L, 0 < t ≤ T.
(9.1.1)
Using the central approximations for both derivatives gives ui,j+1 − 2ui,j + ui,j−1 ui+1,j − 2ui,j + ui−1,j − c2 = 0, (∆t)2 (∆x)2
(9.1.2)
where ui,j = u(xi , tj ) = u(i∆x, j∆t).
(9.1.3)
r = c∆t/∆x,
(9.1.4)
Setting
from (9.1.2) we obtain the following explicit scheme for the wave equation ui,j+1 = 2(1 − r2 )ui,j + r2 (ui+1,j + ui−1,j ) − ui,j−1 .
(9.1.5)
Equation (9.1.5) provides an explicit three-time-level method , which is usually called Courant-Friederichs-Lewy (CFL) method, fig. 9.1.1. Let us
Fig. 9.1.1
CFL scheme
show how it is applied with reference to a typical initial and boundary value problem U (x, 0) = ϕ(x), Ut (x, 0) = ψ(x), 0 ≤ x ≤ L,
(9.1.6)
U (0, t) = g(t), U (L, t) = h(t), 0 < t ≤ T.
(9.1.7)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Finite-difference methods for the wave equation
193
In discrete terms, conditions (9.1.6) become ui,0 = ϕi , (ut )i,0 = ψi , i = 0, ..., m, m∆x = L,
(9.1.8)
where the usual notations ϕi = ϕ(xi ) = ϕ(i∆x) and ψi = ψ(xi ) = ψ(i∆x) have been employed. As to (9.1.7), it is u0,j = gj , um,j = hj , j = 1, ..., n, n∆t = T,
(9.1.9)
with gj = g(tj ), hj = h(tj ). If equation (9.1.5) is explicitly written for j = 0, 1, ui,1 = 2(1 − r2 )ϕi + r2 (ϕi+1 + ϕi−1 ) − ui,−1 , ui,2 = 2(1 − r2 )ui,1 + r2 (ui+1,1 + ui−1,1 ) − ϕi, ,
(9.1.10)
the ghost values ui,−1 appear. They can be eliminated with the help of the second initial condition (9.1.8)2 , which has not yet been exploited. Using this condition yields ψi = (ut )i,0 = (ui,1 − ui,−1 )/2∆t.
(9.1.11)
Solving with respect to ui,−1 and the result substituted into (9.1.10) gives ui,1 = (1 − r2 )ϕi + (r2 /2)(ϕi+1 + ϕi−1 ) + ∆tψi, , ui,2 = 2(1 − r2 )ui,1 + r2 (ui+1,1 + ui−1,1 ) − ϕi, .
(9.1.12)
These relations, together with boundary conditions (9.1.9), allow us to find all ui,j ’s related to the first two time levels. Then, the other values can be computed without any difficulty. To understand the approximation order of the CFL scheme, let us evaluate the truncation error Ti,j =
Ui,j+1 − 2Ui,j + Ui,j−1 Ui+1,j − 2Ui,j + Ui−1,j − c2 . 2 (∆t) (∆x)2
(9.1.13)
Applying Taylor’s series expansion to Ui,j+1 , Ui,j−1 , Ui+1,j , Ui−1,j yields Ti,j = (Utt − c2 Uxx )i,j +
+
(∆t)2 c2 (∆x)2 (Utttt )i,j − (Uxxxx)i,j 12 12
(∆t)4 c2 (∆x)4 (Utttttt )i,j − (Uxxxxxx)i,j + .... 360 360
(9.1.14)
Hence, by considering (Utt − c2 Uxx )i,j = 0,
(9.1.15)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
194
it follows Ti,j = O((∆x)2 + (∆t)2 ).
(9.1.16)
This shows the consistency of the CFL scheme. Furthermore, because of (9.1.15), formula (9.1.14) can be rewritten as Ti,j =
+
c2 [(∆t)2 − c2 (∆x)2 ](Uxxxx )i,j 12
c2 [(∆t)4 − c4 (∆x)4 ](Uxxxxxx)i,j + .... 360
(9.1.17)
The last expression emphasizes that Ti,j = 0 when r = 1. In this case, formula (9.1.5) evidently becomes ui,j+1 = ui+1,j + ui−1,j − ui,j−1 ,
(9.1.18)
and it provides an exact finite-difference method of the wave equation. The value r = 1 is also compatible with the stability analysis, as it is shown by the next discussion. Apply the Von Neumann criterion and assume (9.1.19) ui,j = ξ j exp(Iβi∆x), √ where ξ is the amplification factor and I = −1. Substituting (9.1.19) into (9.1.5) gives ξ 2 = 2ξ(1 − r2 ) + r2 ξ[exp(β∆x) + exp(−β∆x)] − 1,
(9.1.20)
ξ 2 − 2ξ + 2ξr2 [1 − cos(β∆x)] + 1 = 0,
(9.1.21)
ξ 2 − 2ξ[1 − 2r2 sin2 (β∆x/2)] + 1 = 0.
(9.1.22)
Hence, ξ± = p ±
p2 − 1,
(9.1.23)
where p = 1 − 2r2 sin2 (β∆x/2) ≤ 1.
(9.1.24)
Therefore, if p < −1, both roots are real and it is ξ− < −1. The Von Neumann criterion is not satisfied. In the other case, it is. Indeed, if p = 1 − 2r2 sin2 (β∆x/2) ≥ −1,
(9.1.25)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Finite-difference methods for the wave equation
wsdac04
195
the roots are complex and |ξ± |2 = p2 + 1 − p2 = 1.
(9.1.26)
Note that (9.1.25) is certainly satisfied if r ≤ 1,
(9.1.27)
which, therefore, represents the stability condition for the CFL scheme. Finally, problem (9.1.5), (9.1.8), (9.1.9), is arranged in matrix form. By using the vectors uj , bj
u1,j u2,j ·
, uj = um−2,j um−1,j
gj 0 2 bj = r · , 0 hj
and the (m − 1) × (m − 1) matrix r2 2(1 − r2 ) 2(1 − r2 ) r2 r2 · · · A= . · · · r2 r2 2(1 − r2 ) 2(1 − r2 ) r2
(9.1.28)
(9.1.29)
the problem is summarized by uj+1 = Auj − uj−1 + bj , j ≥ 1. This is also equivalent to uj+1 A −Im−1 uj bj = + . uj uj−1 0 Im−1 Om−1 Hence, with the notations uj bj A −Im−1 vj = , cj = , , B= uj−1 0 Im−1 Om−1
(9.1.30)
(9.1.31)
(9.1.32)
it follows vj+1 = Bvj + cj ,
(9.1.33)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
196
typical of two-level methods. The result (9.1.22) can be recovered by the spectral condition. Indeed, denote by ξ the eigenvalues of B and note that they coincide with those of the matrix λi −1 , (9.1.34) 1 O where λi are the eigenvalues of A and are expressed by λi = 2[1 − 2r2 sin2 (iπ/2m)], i = 1, ..., m − 1.
(9.1.35)
ξ 2 − 2ξ[1 − 2r2 sin2 (iπ/2m)] + 1 = 0,
(9.1.36)
Therefore,
which is exactly (9.1.22). The discussion is the same and we realize that, under the assumption (9.1.27), the spectral radius of B is estimated by ρ(B) ≤ 1.
(9.1.37)
Further methods for the wave equation will be considered in the following chapter, where numerical methods for hyperbolic systems of first-order equations will be discussed. Indeed, it can be shown that second-order equation (9.1.1) is equivalent to a system of first-order equations. To this end, let us introduce the functions V = Ux , W = Ut .
(9.1.38)
By using these definitions, it is easy to realize that the wave equation reduces to the following system Vt = Wx , Wt = c2 Vx . 9.2
(9.1.39)
Implicit methods
This section deals with implicit methods for wave equation (9.1.1). At first, we discuss the Crank-Nicolson implicit scheme. Use the central approximation for the time derivative and approximate the space derivative by the average of the central finite-difference approximations related to the j − 1 and j + 1 levels. It follows, fig. 9.2.1, ui,j+1 − 2ui,j + ui,j−1 c2 = [ui+1,j+1 − 2ui,j+1 + ui−1,j+1 2 (∆t) 2(∆x)2
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Finite-difference methods for the wave equation
+ui+1,j−1 − 2ui,j−1 + ui−1,j−1 ].
wsdac04
197
(9.2.1)
Hence,
Fig. 9.2.1
Crank-Nicolson scheme
(1 + r2 )ui,j+1 − (r2 /2)(ui+1,j+1 + ui−1,j+1 ) = 2ui,j − (1 + r2 )ui,j−1 + (r2 /2)(ui+1,j−1 + ui−1,j−1 ),
(9.2.2)
with r defined by (9.1.4). This scheme is unconditionally stable. Indeed, applying the Von Neumann criterion to (9.2.2) gives [1 + r2 − r2 cos(β∆x)]ξ 2 = 2ξ − [1 + r2 − r2 cos(β∆x)].
(9.2.3)
Therefore, setting λ = 1 + r2 − r2 cos(β∆x) = 1 + 2r2 sin2 (β∆x/2) ≥ 1,
(9.2.4)
it follows ξ 2 − (2/λ)ξ + 1 = 0, ξ = 1/λ ± I
1 − (1/λ)2 , ⇒ |ξ|2 = 1.
(9.2.5) (9.2.6)
Let us estimate the truncation error. From (9.2.1) it follows Tij =
Ui,j+1 − 2Ui,j + Ui,j−1 c2 − (Ui+1,j+1 − 2Ui,j+1 + Ui−1,j+1 2 (∆t) 2(∆x)2 +Ui+1,j−1 − 2Ui,j−1 + Ui−1,j−1 ).
(9.2.7)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
198
On the other hand, applying Taylor’s series expansion gives Ui,j±1 = Ui,j ±(Ut )i,j ∆t+(Utt )i,j
(∆t)2 (∆t)3 ±(Uttt )i,j +O((∆t)4 ). (9.2.8) 2 3!
This implies Ui,j+1 + Ui,j−1 = 2Ui,j + (Utt )i,j (∆t)2 + O((∆t)4 ).
(9.2.9)
Similarly, Ui+1,j±1 + Ui−1,j±1 = 2Ui,j±1 + (Uxx )i,j±1 (∆x)2 + O((∆x)4 ),
(9.2.10)
(Uxx )i,j+1 + (Uxx )i,j−1 = 2(Uxx )i,j + O((∆t)2 ).
(9.2.11)
Substituting these results into (9.2.7) yields Tij = (Utt )i,j − c2 (Uxx )i,j + O((∆x)2 + (∆t)2 ).
(9.2.12)
Hence, since (Utt − c2 Uxx )i,j = 0, it follows Tij = O((∆x)2 + (∆t)2 ),
(9.2.13)
which proves the consistency. Note that formula (9.2.2) can be rewritten more compactly as Auj+1 = 2uj − Auj−1 + bj , where A is the (m − 1) × (m − 1) matrix 1 + r2 −r2 /2 −r2 /2 1 + r2 −r2 /2 · · · A= · · −r2 /2
(9.2.14)
· 1 + r2 −r2 /2
, −r2 /2 1 + r2
(9.2.15)
and
u1,j u2,j ·
, uj = um−2,j um−1,j
u0,j−1 − u0,j+1 0 r2 . bj = · 2 0 um,j−1 − um,j+1
(9.2.16)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Finite-difference methods for the wave equation
wsdac04
199
The last vector is a known term if boundary conditions (9.2.9) are assigned. From (9.2.14) it follows uj+1 = 2A−1 uj − uj−1 + A−1 bj , which is equivalent to −1 uj+1 2A = uj Im−1
−Im−1 Om−1
−1 uj A bj + , uj−1 O
(9.2.17)
(9.2.18)
where Im−1 denotes the unit matrix of order m − 1. Finally, (9.2.18) can be written as vj+1 = Bvj + cj ,
(9.2.19)
with obvious meaning of notations. The eigenvalues ξ of B are determined by means of the matrix 2/λi −1 , (9.2.20) 1 O where λi denotes the ith eigenvalue of A λi = 1 + 2r2 sin2 (iπ/2m)], i = 1, ..., m − 1.
(9.2.21)
ξ 2 − (2/λi )ξ + 1 = 0.
(9.2.22)
Therefore,
Since this coincides with (9.2.5), we can conclude that ρ(B) = 1, unconditionally. Another implicit algorithm is obtained by approximating the space derivative by a suitable average of the central finite-difference formulas related to the j − 1, j and j + 1 levels, fig. 9.2.2,
Fig. 9.2.2
Implicit algorithm (9.2.23)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
200
ui,j+1 − 2ui,j + ui,j−1 2 ui+1,j+1 − 2ui,j+1 + ui−1,j+1 = c (∆t)2 4(∆x)2 ui+1,j − 2ui,j + ui−1,j ui+1,j−1 − 2ui,j−1 + ui−1,j−1 + + . 2(∆x)2 4(∆x)2 Hence
+
(9.2.23)
r2 r2 r2 1+ ui,j+1 − (ui+1,j+1 + ui−1,j+1 ) = 2 1 − ui,j 2 4 2
r2 r2 r2 (ui+1,j + ui−1,j ) − 1 + ui,j−1 + (ui+1,j−1 + ui−1,j−1 ), (9.2.24) 2 2 4
with r defined by (9.1.4). Exercise 9.2.1 Show that scheme (9.2.24) is unconditionally stable. In addition, arrange (9.2.24) in matrix form. The earlier algorithms are special cases of a most general method c2 ui,j+1 − 2ui,j + ui,j−1 = [p(ui+1,j+1 − 2ui,j+1 + ui−1,j+1 ) (∆t)2 (∆x)2 +(1−2p)(ui+1,j −2ui,j +ui−1,j )+p(ui+1,j−1 −2ui,j−1 +ui−1,j−1 )], (9.2.25) where p is a weighting parameter, 0 ≤ p ≤ 1. From (9.2.25) (1 + 2r2 p)ui,j+1 − r2 p(ui+1,j+1 + ui−1,j+1 ) = 2[1 − (1 − 2p)r2 ]ui,j − (1+ 2pr2 )ui,j−1 +(1−2p)r2 (ui+1,j +ui−1,j )+r2 p(ui+1,j−1 +ui−1,j−1 ). (9.2.26) When p = 1/2, from (9.2.26) we derive Crank-Nicolson scheme (9.2.2) and, if p = 1/4, method (9.2.24) is recovered. In addition, if p = 0, (9.2.26) reduces to the explicit method (9.1.5). Therefore, it is apparent that algorithm (9.2.25) cannot be unconditionally stable, as stated in the next exercise. Exercise 9.2.2 Verify that the amplification factor ξ of method (9.2.26) satisfies the equation ξ 2 − (2λ/µ)ξ + 1 = 0,
(9.2.27)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Finite-difference methods for the wave equation
wsdac04
201
where λ = 1 − 2r2 (1 − 2p) sin2 (β∆x/2), µ = 1 + 4pr2 sin2 (β∆x/2)].
(9.2.28)
Next, show that scheme (9.2.26) is unconditionally stable if p ≥ 1/4, whereas, when p < 1/4, the stability condition is expressed by r2 ≤ 1/(1 − 4p). 9.3
(9.2.29)
Perturbed wave equation
The partial differential equation of third-order Utt − c2 Uxx = εUxxt ,
(9.3.1)
is called perturbed wave equation. Here, c and ε are positive constants. When ε is a small parameter, the right-hand side of (9.3.1) represents a perturbation term to the wave equation. We have already encountered this equation in Chapter 8, in the context of linear motions of viscous fluids. Furthermore, equation (9.3.1) is involved in other physical processes, as shown in Remark 9.3.1 at the end of this section. A finite-difference approximation of (9.3.1) is the following, fig. 9.3.1, ui+1,j − 2ui,j + ui−1,j ui,j+1 − 2ui,j + ui,j−1 = c2 2 (∆t) (∆x)2
+ε
ui+1,j − 2ui,j + ui−1,j − ui+1,j−1 + 2ui,j−1 − ui−1,j−1 = 0. ∆t(∆x)2
With the positions
Fig. 9.3.1
Perturbed wave equation
(9.3.2)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
202
r = c∆t/∆x, s = ε∆t/(∆x)2 ,
(9.3.3)
formula (9.3.2) becomes ui,j+1 = 2(1 − r2 − s)ui,j + (r2 + s)(ui−1,j + ui+1,j ) −s(ui−1,j−1 + ui+1,j−1 ) + (2s − 1)ui,j−1 .
(9.3.4)
If ε = 0, equation (9.3.1) becomes wave equation (9.1.1) and finite-difference approximation (9.3.4) reduces to CFL method, discussed in Section 9.1. Equation (9.3.4) gives an explicit three-time-level method. This aspect will be discussed later on. Let us analyze the stability by the Von Neumann criterion. Substitute (9.1.19) into (9.3.4) to obtain ξ 2 = 2(1 − r2 − s)ξ + 2ξ(r2 + s) cos(β∆x) − 2s cos(β∆x) + 2s − 1, (9.3.5) ξ 2 = 2ξ − 4ξ(r2 + s) sin2 (β∆x/2) + 4s sin2 (β∆x/2) − 1.
(9.3.6)
Hence, ξ 2 − 2p + q = 0,
(9.3.7)
where p = 1 − 2(r2 + s) sin2 (β∆x/2) ≤ 1, q = 1 − 4s sin2 (β∆x/2) ≤ 1. (9.3.8) If the discriminant of (9.3.7) is negative (complex roots) p2 − q < 0, ⇔ q > p2 ≥ 0, then ξ =p±I
√ q − p2 , (I = −1),
(9.3.9)
(9.3.10)
and therefore, because of (9.3.8)2 , |ξ|2 = p2 + q − p2 = q ≤ 1,
(9.3.11)
showing that the Von Neumann condition is satisfied. In the other case, p2 ≥ q (non-negative discriminant), assume r2 + 2s ≤ 1,
(9.3.12)
−1 ≤ p.
(9.3.13)
and note that this implies
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Finite-difference methods for the wave equation
wsdac04
203
The (real) roots of (9.3.7) are given by ξ± = p ± p2 − q,
(9.3.14)
and it results evidently ξ+ = p + p2 − q ≥ p ≥ −1, ξ− = p − p2 − q ≤ p ≤ 1.
(9.3.15)
Furthermore, straightforward calculations show p2 − q − (1 − p)2 = −4r2 sin2 (β∆x/2) ≤ 0,
(9.3.16)
and (p + 1)2 − (p2 − q) = 4[1 − (r2 + 2s) sin2 (β∆x/2)] ≥ 0,
(9.3.17)
where the last inequality follows from (9.3.12). Formulas (9.3.16), (9.3.17) imply (9.3.18) p + p2 − q ≤ 1, p − p2 − q ≥ −1, that is, ξ+ ≤ 1, ξ− =≥ −1.
(9.3.19)
These estimates, together with (9.3.15), show |ξ± | ≤ 1.
(9.3.20)
In conclusion, the Von Neumann analysis proves that method (9.3.4) is stable under the assumption (9.3.12). Note that (9.3.12) reduces to stability condition (9.1.27) when ε = 0. Now, let us discuss the consistency. Consider the truncation error Ti,j =
−ε
Ui+1,j − 2Ui,j + Ui−1,j Ui,j+1 − 2Ui,j + Ui,j−1 − c2 2 (∆t) (∆x)2
(Ui+1,j − 2Ui,j + Ui−1,j ) − (Ui+1,j−1 − 2Ui,j−1 + Ui−1,j−1 ) . (9.3.21) ∆t(∆x)2
From the Taylor’s series expansion it follows Ui,j+1 − 2Ui,j + Ui,j−1 = (Utt )i,j (∆t)2 + Ui+1,j − 2Ui,j + Ui−1,j = (Uxx )i,j (∆x)2 +
(∆t)4 (Utttt )i,j + ..., 12
(9.3.22)
(∆x)4 (Uxxxx)i,j + ..., (9.3.23) 12
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
204
Ui+1,j−1 − 2Ui,j−1 + Ui−1,j−1 = (Uxx )i,j−1 (∆x)2 +
(∆x)4 (Uxxxx )i,j−1 + ..., 12
(Uxx )i,j−1 = (Uxx )i,j − (Uxxt )i,j ∆t +
(∆t)2 (Uxxtt )i,j + ..., 2
(Uxxxx )i,j−1 = (Uxxxx)i,j − (Uxxxxt )i,j ∆t + ....
(9.3.24)
(9.3.25) (9.3.26)
By inserting (9.3.22)-(9.3.26) into (9.3.21) and by considering that (Utt )i,j − c2 (Uxx )i,j − ε(Uxxt )i,j = 0,
(9.3.27)
we obtain Ti,j = (Utttt )i,j
(∆t)2 (∆x)2 ∆t − c2 (Uxxxx )i,j + ε(Uxxtt )i,j 12 12 2 −ε(Uxxxxt)i,j
(∆x)2 + ... 12
(9.3.28)
showing that scheme (9.3.2) is consistent. As already mentioned, formula (9.3.4) gives a three-time-level method and its application requires some comments. In fact, consider the following Dirichlet problem for equation (9.3.4) ui,0 = ϕi , (ut )i,0 = ψi , i = 0, ..., m, m∆x = L, u0,j = gj , um,j = hj , j = 1, ..., n, n∆t = T.
(9.3.29) (9.3.30)
If formula (9.3.4) is explicitly written for j = 0 ui,1 = 2(1 − r2 − s)ϕi + (r2 + s)(ϕi−1 + ϕi+1 ) −s(ui−1,−1 + ui+1,−1 ) + (2s − 1)ui,−1 ,
(9.3.31)
we realize that we cannot evaluate ui,1 , i = 1, ..., m − 1, because of the ghost values. On the other hand, the knowledge of ui,1 , i = 1, ..., m − 1, is requested in the next time step (j = 1) ui,2 = 2(1 − r2 − s)ui,1 + (r2 + s)(ui−1,1 + ui+1,1 ) −s(ϕi−1 + ϕi+1 ) + (2s − 1)ϕi .
(9.3.32)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Finite-difference methods for the wave equation
wsdac04
205
We can proceed as in the case of the wave equation. The initial condition (9.3.29)2 is approximated by the central formula ψi = (ut )i,0 = (ui,1 − ui,−1 )/2∆t,
(9.3.33)
and this is used to eliminate the fictitious values in (9.3.31) 2ui,1 = 2(1 − r2 − s)ϕi + (r2 + s)(ϕi−1 + ϕi+1 ) −s(ui−1,1 + ui+1,1 ) + 2sui,1 + 2s∆t(ψi−1 + ψi+1 ) − 2∆t(2s − 1)ψi . (9.3.34) In addition, noting (ui−1,1 + ui+1,1 )/2 = ui,1 ,
(9.3.35)
we obtain ui,1 = (1 − r2 − s)ϕi + (r2 + s)(ϕi−1 + ϕi+1 )/2 +s∆t(ψi−1 + ψi+1 ) − ∆t(2s − 1)ψi ,
(9.3.36)
which solves the problem. For ε = 0 the last relation reduces to (9.1.12). Another way to obtain the result consists in applying the backward approximation to (9.3.29)2 ψi = (ut )i,0 = (ui,0 − ui,−1 )/∆t = (ϕi − ui,−1 )/∆t.
(9.3.37)
This is solved with respect to ui,−1 and the result substituted into (9.3.31) to replace the ghost values ui,1 = 2(1 − r2 − s)ϕi + (r2 + s)(ϕi−1 + ϕi+1 ) −s[ϕi−1 + ϕi+1 − ∆t(ψi−1 + ψi+1 )] + (2s − 1)(ϕi − ∆tψi ).
(9.3.38)
In this case approximation (9.3.35) has been avoided, but it must be outlined that formula (9.3.37) is less accurate than (9.3.33). Exercise 9.3.1 In the case of Dirichlet problem (9.3.29), (9.3.30), arrange equations (9.3.4) in matrix form as uj+1 = Auj − Buj−1 + bj , j ≥ 1,
(9.3.39)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
206
where
u1,j u2,j ·
, uj = um−2,j um−1,j
(r2 + s)gj − sgj−1 0 , bj = · 0 2 (r + s)hj − sgj−1
and
r2 + s 2(1 − r2 − s) r2 + s 2(1 − r2 − s) r2 + s · · · A= · · · r2 + s r2 + s 2(1 − r2 − s) 2 2 r +s 2(1 − r − s)
1 − 2s s s 1 − 2s s · · · B= . · · · s 1 − 2s s s 1 − 2s Formula (9.3.39) is equivalent to uj+1 A −B uj bj = + , uj uj−1 0 Im−1 Om−1
(9.3.40)
which is rewritten more compactly as
where
vj =
vj+1 = Cvj + dj ,
(9.3.41)
uj bj A −B , dj = . , C= uj−1 0 Im−1 Om−1
(9.3.42)
Verify that all the submatrices of C have the same eigenvectors and the eigenvalues γ of C are expressed by the equation γ 2 − 2γ[1 − 2(r2 + s) sin2 (πi/2m)] + 1 − 4s sin2 (πi/2m) = 0, i = 1, ..., m − 1. Hence, discuss the stability of (9.3.41).
(9.3.43)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Finite-difference methods for the wave equation
Remark 9.3.1 lowing
wsdac04
207
Equation (9.3.1) is the homogeneous version of the folUtt − c2 Uxx − εUxxt = F (x, t, U, Ux , Ut ),
(9.3.44)
which occurs in interesting physical processes. We only mention the wellknown Josephson tunnel effect in Superconductivity, which represents an example of the quantum-mechanical penetration of a barrier. When two superconductors are separated by a thin insulating layer (Josephson junction), electrons penetrate through the barrier and a current appears. This depends on the phase difference ϕ of the wave functions of the two superconductors and it is governed by the following equation βϕxxt + ϕxx − ϕtt − αϕt = sin ϕ − γ, which is a special case of (9.3.44). Here, β, α are constant coefficients and γ is a function of x, t. Further Reading: [Ames (1992)], [D’Acunto and Renno (1999)], [Morton and Mayers (2002)], [Smith (1985)], [Thomas (1995)].
July 3, 2004
23:17
208
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Chapter 10
Hyperbolic equations
This chapter is devoted to finite-difference methods for hyperbolic systems of partial differential equations. A noteworthy example of second-order hyperbolic equation has already been considered in Chapter 9, where the wave equation was studied. In the same chapter it was shown that this equation could be reduced to an equivalent first-order system. This is the topic which we are going to discuss. As a preliminary, the simple first-order equation is introduced. Both explicit and implicit methods are illustrated together with the stability analysis. Also, examples and exercises are given to support the theory. Next, first-order systems are analyzed and the most used finite-difference schemes are presented. Finally, we consider nonlinear system, which give rise to more complicated problems.
209
wsdac04
July 3, 2004
23:17
210
10.1
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
First-order equations. Explicit methods
The first-order PDE equation in the unknown function U = U (x, t) Ut + aUx = 0,
(10.1.1)
is called advection equation. Assume a = constant and use the forward approximation for both derivatives to find Ui,j+1 − Ui,j Ui+1,j − Ui,j = −a + O(∆t) + O(∆x). ∆t ∆x
(10.1.2)
Consequently, the following method ui,j+1 − ui,j ui+1,j − ui,j = −a , ∆t ∆x
(10.1.3)
defines a finite-difference approximation which is consistent with equation (10.1.1). By defining s = ∆t/∆x,
(10.1.4)
ui,j+1 = (1 + sa)ui,j − saui+1,j .
(10.1.5)
formula (10.1.3) becomes
Method (10.1.5) is known as FTFS method (forward in time-forward in space), fig. 10.1.1. Instead, if the backward approximation is used for the space derivative, the FTBS method is obtained, fig. 10.1.1,
Fig. 10.1.1
FTFS (left) and FTBS (right) schemes
ui,j − ui−1,j ui,j+1 − ui,j = −a , ∆t ∆x
(10.1.6)
ui,j+1 = (1 − sa)ui,j + saui−1,j ,
(10.1.7)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Hyperbolic equations
211
with the same order of approximation. Both schemes are conditionally stable. Indeed, apply the Von Neumann method to the FTFS method to find ξ = 1 + sa − sa exp(Iβ∆x) = 1 + sa[1 − cos(β∆x)] − saI sin(β∆x), (10.1.8) √ where I= −1. Hence, |ξ|2 = [1 + 2sa sin2 (β∆x/2)]2 + 4s2 a2 sin2 (β∆x/2) cos2 (β∆x/2), (10.1.9) |ξ|2 = 1 + 4sa(1 + sa) sin2 (β∆x/2).
(10.1.10)
Therefore, under the assumption a < 0, |a|s ≤ 1,
(10.1.11)
|ξ|2 ≤ 1,
(10.1.12)
it follows
showing that algorithm (10.1.5) is conditionally stable. Next, consider the FTBS method and assume a > 0, as ≤ 1.
(10.1.13)
In this hypothesis, equation (10.1.7) implies |ui,j+1 | ≤ ||uj ||∞ , (||uj ||∞ = max |ui,j |). i
(10.1.14)
Hence, ||uj+1 ||∞ ≤ ||uj ||∞ ≤ ... ≤ ||u0 ||∞ .
(10.1.15)
Therefore, the FTBS scheme is stable under condition (10.1.13). Exercise 10.1.1 Use this last method to recover the stability condition (10.1.11) and apply the Von Neumann method to find (10.1.13). Exercise 10.1.2
Arrange the introduced methods in matrix form as uj+1 = Auj + bj ,
and discuss the stability by the norms ||A||∞ , ||A||1 , ||A||2 .
(10.1.16)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
212
Example 10.1.1 tive yields
Using the central approximation for the space derivaui+1,j − ui−1,j ui,j+1 − ui,j = −a , ∆t 2∆x ui,j+1 = ui,j − (sa/2)(ui+1,j − ui−1,j ).
(10.1.17)
This method is unstable as, by the Von Neumann method, it follows |ξ|2 = 1 + a2 s2 sin2 β,
(10.1.18)
showing instability. If, in algorithm (10.1.17), ui,j is replaced by the average ui,j =
ui+1,j − ui−1,j , 2
we obtain the Lax-Friederichs scheme, fig. 10.1.2, ui,j+1 = (1/2)(ui+1,j + ui−1,j ) − (sa/2)(ui+1,j − ui−1,j ).
(10.1.19)
This method is stable under the hypothesis that the Courant number s|a|
Fig. 10.1.2
Lax-Friederichs (left) and Lax-Wendroff (right) schemes
satisfies the condition s|a| ≤ 1.
(10.1.20)
In fact, the amplification factor is given by ξ = cos(β∆x) − asI sin(β∆x).
(10.1.21)
Hence, because of (10.1.20), |ξ|2 = cos2 (β∆x) + s2 a2 sin2 (β∆x) ≤ 1,
(10.1.22)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Hyperbolic equations
213
proving that (10.1.19) is conditionally stable. Exercise 10.1.3 Verify that the truncation error of Lax-Friederichs scheme is expressed by Ti,j = O(∆x + ∆t).
(10.1.23)
In addition, verify that solutions of (10.1.19) satisfy estimate (10.1.15), under hypothesis (10.1.20). Next, show that the algorithm is convergent. A more accurate scheme is the Lax-Wendroff method, which we are going to introduce, fig. 10.1.2. At first, note that a solution (∈ C 2 ) of (10.1.1) satisfies the wave equation too Utt − a2 Uxx = 0 ⇔
Utt = a2 Uxx .
(10.1.24)
Use this result in the Taylor’s series expansion Ui,j+1 = Ui,j + (Ut )i,j ∆t + (Utt )i,j (∆t)2 /2 + O((∆t)3 )
(10.1.25)
to obtain (Ut )i,j = (Ui,j+1 − Ui,j )/∆t − (Uxx )i,j a2 ∆t/2 + O((∆t)2 ).
(10.1.26)
Lastly, replace Uxx by its the central approximation (Ut )i,j =
a2 ∆t Ui,j+1 − Ui,j − (Ui−1,j − 2Ui,j + Ui+1,j ) ∆t 2(∆x)2 +O((∆t)2 + (∆x)2 ).
(10.1.27)
If this expression is used to approximate the time derivative in equation (10.1.1) and the central approximation is applied to Ux , we arrive at the Lax-Wendroff scheme a2 ∆t ui,j+1 − ui,j − (ui−1,j − 2ui,j + ui+1,j ) ∆t 2(∆x)2 +
a (ui+1,j − ui−1,j ) = 0, 2∆x
(10.1.28)
with a truncation error Ti,j = O((∆t)2 + (∆x)2 ). Formula (10.1.28) can be rewritten as sa sa ui,j+1 = (1 − a2 s2 )ui,j + (as − 1)ui+1,j + (as + 1)ui−1,j , (10.1.29) 2 2
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
214
where s is defined by (10.1.4). This algorithm is conditionally stable, as it is immediately realized by Von Neumann method. Indeed, √ (10.1.30) ξ = 1 − a2 s2 [1 − cos(β∆x)] − asI sin(β∆x), (I = −1),
β∆x |ξ| = 1 − 2a s sin 2 2
2 2
2
2 + 4a2 s2 sin2
β∆x β∆x cos2 , 2 2
|ξ|2 = 1 − 4a2 s2 (1 − a2 s2 ) sin4 (β∆x/2).
(10.1.31)
(10.1.32)
Hence, if s|a| ≤ 1,
(10.1.33)
it follows |ξ|2 ≤ 1, implying stability. Exercise 10.1.4 ing matrix form
Arrange Lax-Wendroff method (10.1.29) in the followuj+1 = Auj + bj ,
where
A=
1 − a2 s2 sa(as+1) 2
sa(as−1) 2 2 2
1−a s ·
(10.1.34)
sa(as−1) 2
· ·
· ·
sa(as+1) 2
· 1 − a 2 s2 sa(as+1) 2
sa(as−1) 2 2 2
.
1−a s
Verify that ||A||2 ≤ 1. Next, show the convergence of the scheme. If the central approximations are used for both derivatives in equation (10.1.1), an explicit three-time-level method is obtained (ui,j+1 − ui,j−1 )/(2∆t) = −(ui+1,j − ui−1,j )(a/2∆x), ui,j+1 = ui,j−1 − sa(ui+1,j − ui−1,j ),
(10.1.35) (10.1.36)
with a truncation error Ti,j = O((∆t)2 + (∆x)2 ). The algorithm is stable under the assumption (10.1.33). Indeed, the amplification factor is expressed by ξ = 1/ξ − 2asI sin(β∆x).
(10.1.37)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Hyperbolic equations
wsdac04
215
Hence, |ξ|2 + 2asIξ sin(β∆x) − 1 = 0, ξ = −asI sin(β∆x) +
1 − a2 s2 sin2 (β∆x),
|ξ|2 = 1.
(10.1.38)
(10.1.39) (10.1.40)
By introducing the (m − 1) × (m − 1) matrix 0 −1 1 0 −1 · · · A= . · · · 1 0 −1 1 0 and the column vectors sau0,j u1,j u2,j 0 bj = · , uj = · , um−2,j 0 um−1,j −saum,j
formula (10.1.36) is rewritten more compactly as uj+1 = saAuj + uj−1 + bj .
(10.1.41)
Hence, we obtain the typical matrix form of two-time-level schemes uj+1 saA Im−1 uj bj = + , (10.1.42) uj uj−1 0 Im−1 0m−1 where Im−1 denotes the unit matrix of order (m − 1) and 0m−1 the zero matrix. Exercise 10.1.5
Consider the block matrix saA Im−1 B= Im−1 0m−1
and show that ρ(B) = 1.
(10.1.43)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
216
Exercise 10.1.6 equation
Apply the Lax-Friederichs method to the following Ut + a(x, t)Ux = 0,
(10.1.44)
s|ai,j | ≤ 1.
(10.1.45)
and show that it is stable if
Example 10.1.2
Consider the equation Ut + aUx + cU = 0, a, c = constants.
(10.1.46)
Using the Lax-Friederichs method gives ui,j+1 = (1/2)(ui+1,j +ui−1,j )−(sa/2)(ui+1,j −ui−1,j )−cui,j ∆t. (10.1.47) This method is stable if hypothesis (10.1.20) is fulfilled; in fact, ||uj+1 ||∞ ≤ (1 + |c|∆t)||uj ||∞ ,
(10.1.48)
||uj ||∞ ≤ (1 + |c|∆t)j ||u0 ||∞ .
(10.1.49)
j∆t ≤ T,
(10.1.50)
Since,
inequality (10.1.49) implies ||uj ||∞ ≤ (1 + |c|T /j)j ||u0 ||∞ ≤ exp(|c|T )||u0 ||∞ .
(10.1.51)
Finally, let us illustrate the MacCormack method. It is quite different from all the previous ones, as it involves two steps: the predictor procedure, where the forward approximation is employed for the space derivative u∗i,j+1 = ui,j − sa(ui+1,j − ui,j ),
(10.1.52)
followed by a corrector procedure with the backward approximation to Ux ui,j+1 = (1/2)[ui,j + u∗i,j+1 − sa(u∗i,j+1 − u∗i−1,j+1 )].
(10.1.53)
If (10.1.52) is substituted into (10.1.53), we realize that the Lax-Wendroff method is recovered. Remark 10.1.1 Modelling traffic flow leads to hyperbolic equations of first-order. Suppose we want to describe the traffic evolution on a highway, for example, when people leave the stadium after a football game, or when
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Hyperbolic equations
wsdac04
217
a population leaves the region affected by exceptional events, such as the volcano eruption. Denote by ρ the density of cars, defined by the number of cars per unit length, and note that it depends on the point x on the highway (generally, a curvilinear abscissa) and on time: ρ = ρ(x, t). The total amount of cars between two arbitrary points a, b, a < b, is given by b ρ(x, t) dx. a
This quantity can vary on time, depending on the net flux q of cars entering at a and leaving at b b ∂ ρ(x, t) dx = q(a, t) − q(b, t). (10.1.54) ∂t a From balance law (10.1.54) it follows b ρt dx = − a
b
a
qx dx,
b a
(ρt + qx ) dx = 0.
Since a, b are arbitrary, under the assumption that the integrand function is continuous, it follows ρt + qx = 0.
(10.1.55)
This equation expresses a conservation law, as it states that the total amount of cars is conserved. Note that the average local velocity v of cars is influenced essentially by the surrounding density of cars; this means that v depends on x and t through ρ v = v(ρ). Therefore, if it is assumed q = ρv, then q = q(ρ). Consider this in equation (10.1.55) to obtain ρt + aρx = 0,
(10.1.56)
July 3, 2004
23:17
218
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
where a = a(ρ) =
∂q . ∂ρ
Equation (10.1.56) is, in general, nonlinear and the numerical methods developed in this section cannot be applied. This case will be considered in Section 10.4. 10.2
Implicit methods
Implicit schemes for equation (10.1.1) are presented in this section. The first one is the Crank-Nicolson method. Assume that the equation (10.1.1) is satisfied on (i, j + 1/2). Use the central approximation for the time derivative and replace the space derivative by the average of the central approximations related to j and j + 1. It results, fig. 10.2.1, (ui,j+1 − ui,j )/∆t + (a/2)[(ui+1,j+1 − ui−1,j+1 )/(2∆x) +(ui+1,j − ui−1,j )/(2∆x)] = 0.
(10.2.1)
Hence, ui,j+1 +(sa/4)(ui+1,j+1 −ui−1,j+1 ) = ui,j −(sa/4)(ui+1,j −ui−1,j ), (10.2.2) where the notation (10.1.4) has been employed. The Von Neumann method
Fig. 10.2.1
Crank-Nicolson (left) and Wendroff (right) schemes
shows that this scheme is unconditionally stable. Indeed, the amplification factor is expressed by ξ + (sa/2)ξI sin(β∆x) = 1 − (sa/2)I sin(β∆x),
(10.2.3)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Hyperbolic equations
ξ = [1 − saI sin(β∆x/2)]/[1 + saI sin(β∆x/2)].
wsdac04
219
(10.2.4)
Hence, |ξ|2 = 1.
(10.2.5)
The truncation error related to the Crank-Nicolson method is expressed by Ti,j = Li,j U,
(10.2.6)
where Li,j denotes the operator defined by the left-hand side of (10.2.1). Considering (Ui,j+1 − Ui,j )/∆t = (Ut )i,j+1/2 + O((∆t)2 ),
(10.2.7)
yields a Ti,j = (Ut )i,j+1/2 + O((∆t)2 ) + [(Ux )i,j+1 + (Ux )i,j + O((∆x)2 )]. (10.2.8) 2 Note that (Ux )i,j+1 = (Ux )i,j+1/2 + (Uxt )i,j+1/2 ∆t/2 + O((∆t)2 ),
(10.2.9)
(Ux )i,j = (Ux )i,j+1/2 − (Uxt )i,j+1/2 ∆t/2 + O((∆t)2 ).
(10.2.10)
Hence, (Ux )i,j + (Ux )i,j+1 = 2(Ux )i,j+1/2 + O((∆t)2 ).
(10.2.11)
Substituting this result into formula (10.2.8) and considering that equation (10.1.1) is satisfied on (i, j + 1/2), it follows Ti,j = O((∆x)2 + (∆t)2 ).
(10.2.12)
Another noteworthy implicit scheme is the Wendroff method, which admits the same truncation error (10.2.12). Assume that equation (10.1.1) is satisfied on (i + 1/2, j + 1/2) and use the average of the central approximations for both derivatives. It results, fig. 10.2.1, (a/2∆x)(ui+1,j+1 − ui,j+1 + ui+1,j − ui,j ) +(1/2∆t)(ui+1,j+1 − ui+1,j + ui,j+1 − ui,j ) = 0.
(10.2.13)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
220
Hence, with s defined by (10.1.4), (1 + sa)ui+1,j+1 + (1 − sa)ui,j+1 = (1 − sa)ui+1,j + (1 + sa)ui,j . (10.2.14) The method is unconditionally stable. Indeed, ξ[(1 + sa) exp(Iβ∆x) + 1 − sa] = (1 − sa) exp(Iβ∆x) + 1 + sa, (10.2.15) ξ=
(1 − sa) cos(β∆x) + 1 + sa + I(1 − sa) sin(β∆x) , (1 + sa) cos(β∆x) + 1 − sa + I(1 + sa) sin(β∆x)
(10.2.16)
1 + sap2 + I(1 − sa)p , p = tan(β∆x/2), 1 − sap2 + I(1 + sa)p
(10.2.17)
ξ=
|ξ|2 = 1.
(10.2.18)
Finally, let us introduce the BTCS implicit method. This is obtained by assuming that equation (10.1.1) is satisfied on (i, j + 1) and by considering the backward approximation for Ut and the central approximation for Ux fig. 10.2.2, (a/2∆x)(ui+1,j+1 − ui−1,j+1 ) + (1/∆t)(ui,j+1 − ui,j ) = 0,
(10.2.19)
or, equivalently, ui,j+1 + (sa/2)(ui+1,j+1 − ui−1,j+1 ) = ui,j .
(10.2.20)
As it is easy to verify, the truncation error of this method is given by
Fig. 10.2.2
Implicit BTCS scheme
Ti,j = O((∆x)2 + ∆t).
(10.2.21)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Hyperbolic equations
wsdac04
221
Furthermore, Von Neumann analysis shows that the scheme is stable without any condition. Indeed, straightforward calculations give
10.3
ξsaI sin(β∆x) + ξ = 1,
(10.2.22)
1/ξ = 1 + saI sin(β∆x),
(10.2.23)
1/|ξ|2 = 1 + s2 a2 I sin2 (β∆x) ≥ 1.
(10.2.24)
Systems of first-order equations
Consider the following system of n first-order partial differential equations in n unknown functions Uh (x, t), h = 1, ..., n, n
ahk Ukx + Uht = 0, h = 1, ..., n.
(10.3.1)
k=1
This system can be arranged in matrix form AUx + Ut = 0, where the matrix A and the column vector U are defined by U1 a11 . a1n A = . . . , U = . . an1 . ann Un
(10.3.2)
(10.3.3)
At first, let us introduce the Lax-Friederichs method. Assume that the elements of the matrix A are constants and treat each equation as in the case of one equation in Section 10.1 n
ahk (s/2)[(uk )i+1,j − (uk )i−1,j ]
k=1
+(uh )i,j+1 − (1/2)[(uh )i+1,j + (uh )i−1,j ], h = 1, ..., n,
(10.3.4)
where s = ∆t/∆x.
(10.3.5)
Equations (10.3.4) can be rewritten in matrix form as ui,j+1 = (1/2)(ui+1,j + ui−1,j ) − (sA/2)(ui+1,j − ui−1,j ).
(10.3.6)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
222
The stability of this system can be analyzed by the Von Neumann method. To this end let us consider √ (10.3.7) ui,j = u∗ ξ j exp(βi∆x −1), where u∗ denotes a constant vector. Substitute the last expression into (10.3.6) to find ξu∗ = Gu∗ , where the matrix G is given by √ G = cos(β∆x) In − s −1 sin(β∆x)A, (In = unit matrix).
(10.3.8)
(10.3.9)
This matrix is called amplification matrix for evident reasons. Formula (10.3.8) emphasizes that the amplification factor ξ is an eigenvalue of G |G − ξIn | = 0.
(10.3.10)
Substitute the expression of G into formula (10.3.10) to obtain |A − λIn | = 0,
(10.3.11)
cos(β∆x) − ξ λ= √ . s −1 sin(β∆x)
(10.3.12)
where
Formulas (10.3.11) and (10.3.12) show that the amplification factor ξ is functionally related to the eigenvalues λ of A. Furthermore, from (10.3.12) it follows |ξ|2 = cos2 (β∆x) + s2 λ2 sin2 (β∆x).
(10.3.13)
Therefore, if the spectral radius ρ(A) of A satisfies the condition sρ(A) ≤ 1,
(10.3.14)
|ξ| ≤ 1,
(10.3.15)
it follows
showing the stability of method (10.3.6). Example 10.3.1
Consider the wave equation
Utt − c2 Uxx = 0, c = positive constant.
(10.3.16)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Hyperbolic equations
223
By introducing U1 = Ux , U2 = Ut .
(10.3.17)
as new unknown functions, equation (10.3.16) reduces to the system of first-order equations U1t − U2x = 0, U2t − c2 U1x = 0. This is equivalent to U1t 0 −1 U1x + = AUx + Ut = 0. U2x U2t −c2 0
(10.3.18)
(10.3.19)
In this case ρ(A) = c, and the stability condition (10.3.14) becomes cs ≤ 1,
(10.3.20)
in complete agreement with the stability result already given in Section 9.1 for the wave equation. Example 10.3.2
Consider the following system Ut + AUx + bU = 0, b = constant.
(10.3.21)
Applying the Lax-Friederichs method gives ui,j+1 =
1 sA (u (ui+1,j − ui−1,j ) − bui,j ∆t. + ui−1,j ) − 2 i+1,j 2
(10.3.22)
Substitute (10.3.7) into (10.3.22) to find |G − ξIn | = 0, where the amplification matrix G is expressed by √ G = [cos(β∆x) − b∆t]In − s −1 sin(β∆x)A.
(10.3.23)
(10.3.24)
From (10.3.23) and (10.3.24) it follows |A − λIn | = 0,
(10.3.25)
where λ=
cos(β∆x) − b∆t − ξ √ . s −1 sin(β∆x)
(10.3.26)
Therefore, under the assumption (10.3.14), we derive |ξ| ≤ 1 + |b|∆t,
(10.3.27)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
224
which implies stability. Remark 10.3.1 A system similar to (10.3.21) is involved in the hyperbolic model of heat conduction. In the one-dimensional case this model is described by the following equations (k/α)Ut + Qx = 0, ΓQt + kUx + Q = 0,
(10.3.28)
where k, α and Γ are constant coefficients, denoting the thermal conductivity, the thermal diffusivity coefficient and the relaxation time, respectively. Note that equation (10.3.28)2 implies the Fourier law, as special case (Γ = 0). This equation was introduced by Cattaneo [Cattaneo (1948)] and Vernotte [Vernotte (1958)] essentially to eliminate the paradox of the infinite speed of thermal waves. It describes very well processes of heat conduction when high thermal flows are involved. From (10.3.28) it follows that both U and Q satisfy the same second-order hyperbolic equation Utt − c2 Uxx + Γ−1 Ut = 0,
(10.3.29)
where c=
α/Γ,
(10.3.30)
is the velocity of the thermal wave. Since the original idea dates back to Maxwell, equation (10.3.29) is called Cattaneo-Vernotte-Maxwell heat equation. In matrix form system (10.3.28) is rewritten as 0 α/k 0 Ux 0 Ut + + (1/Γ) = . (10.3.31) Qt Qx k/Γ 0 Q 0 The eigenvalues of matrix A are given by λ = ± α/Γ = ±c,
(10.3.32)
and stability condition (10.3.14) becomes cs ≤ 1. Exercise 10.3.1
Consider the second-order hyperbolic equation Utt − c2 Uxx + bUt .
(10.3.33)
Use definitions (10.3.17) to reduce this equation to system (10.3.21). Derive the stability condition.
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Hyperbolic equations
225
Also the Lax-Wendroff method can be generalized to systems (10.3.2) with constant matrix A. Proceeding as in the case of one equation we obtain ui,j+1 = (In − A2 s2 )ui+1,j + (A2 s2 /2)(ui+1,j + ui−1,j ) +(sA/2)(ui+1,j − ui−1,j ),
(10.3.34)
where s is defined by (10.3.5). The Von Neumann analysis of stability leads to consider |G − ξIn | = 0,
(10.3.35)
where √ G = In − s2 [1 − cos(β∆x)]A2 − s −1 sin(β∆x)A.
(10.3.36)
Formulas (10.3.35) and (10.3.36) emphasize that the amplification factor ξ is functionally related to the eigenvalues λ of A by the relationship √ (10.3.37) ξ = 1 − λ2 s2 [1 − cos(β∆x)] − λs −1 sin(β∆x). This expression of ξ coincides with (10.1.30), if λ is replaced by a. Therefore, if the spectral radius ρ(A) satisfies condition (10.3.14), then |λ| ≤ 1, and from (10.3.17) it follows |ξ| ≤ 1. Exercise 10.3.2
(10.3.38)
Apply the Lax-Wendroff method to the system
Ut + c2 Ux + Vx = 0, Vt + 2c2 Ux − Vx = 0,
(10.3.39)
and discuss the stability. Finally, the generalization of the MacCormack method to system (10.3.2) is given u∗i,j+1 = ui,j − sA(ui+1,j − ui,j ), ui,j+1 = (1/2)[ui,j + u∗i,j+1 − sA(u∗i,j+1 − u∗i−1,j+1 )].
(10.3.40) (10.3.41)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
226
10.4
wsdac04
Nonlinear systems
Consider the nonlinear system A(U)Ux + Ut = 0.
(10.4.1)
This can be arranged in conservative form [F(U)]x + Ut = 0.
(10.4.2)
Indeed, if we introduce the Jacobian matrix of F with respect to U ∂Fh ∂F = , h, k = 1, ..., n, (10.4.3) ∂U ∂Uk we obtain ∂F U + Ut = 0, ∂U x
(10.4.4)
which reduces to (10.4.1) with the position A(U) =
∂F . ∂U
(10.4.5)
At first, let us illustrate the Lax-Wendroff method for systems (10.4.2). From Taylor’s series expansion Ui,j+1 = Ui,j + (Ut )i,j ∆t + (Utt )i,j (∆t)2 /2 + O((∆t)3 ),
(10.4.6)
it follows (Ut )i,j = (Ui,j+1 − Ui,j )/∆t − (Utt )i,j ∆t/2 + O((∆t)2 ).
(10.4.7)
Next, note that from (10.4.2) and (10.4.5) it follows ∂F ∂F Utt = −∂t [F(U)]x = −∂x [F(U)]t = −∂x U = ∂x A . (10.4.8) ∂U t ∂x In addition, ∂x [AFx ] =
=
Ai+ 1 ,j (Fx )i+ 1 ,j − Ai− 1 ,j (Fx )i− 1 ,j 2
2
2
∆x
Ai+ 1 ,j (Fi+1,j − Fi,j ) − Ai− 1 ,j (Fi,j − Fi−1,j ) 2
2
(∆x)2
2
+ O((∆x)2 )
+ O((∆x)2 ),
(10.4.9)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Hyperbolic equations
wsdac04
227
where, for conciseness, the notations Ai,j = A(Ui,j ), Fi,j = F(Ui,j )
(10.4.10)
have been employed. Substitute the expression of Utt , given by (10.4.8) and (10.4.9), into (10.4.7) to obtain the desired approximation to Ut . Finally, if the central approximation is used for the space derivative, we obtain the Lax-Wendroff scheme ui,j+1 = ui,j − (s/2)(Fi+1,j − Fi−1,j ) +(s2 /2)[Ai+ 1 ,j (Fi+1,j − Fi,j ) − Ai− 1 ,j (Fi,j − Fi−1,j )], 2
2
(10.4.11)
with a truncation error Ti,j O((∆t)2 + (∆x)2 ). The terms Ai+ 1 ,j , Ai− 1 ,j 2 2 are usually expressed by the averages Ai+ 1 ,j = (Ai,j + Ai+1,j )/2, Ai− 1 ,j = (Ai,j + Ai−1,j )/2, 2
2
(10.4.12)
or Ai+ 1 ,j = A((ui,j + ui+1,j )/2), Ai− 1 ,j = A((ui,j + ui−1,j )/2). (10.4.13) 2
2
Note that the eigenvalues of the matrix A depend on the unknown function U and this complicates the stability analysis. Exercise 10.4.1
Apply the Lax-Wendroff method to Burger equation. Ut + U Ux = 0.
(10.4.14)
Example 10.4.1 Consider the one-dimensional motions of an isentropic gas. When the gas is not viscous and subjected to no external forces, the physical process is governed by the following equations ρut + ρuux + px = 0, ρt + (ρu)x = 0,
(10.4.15)
where ρ is the density, p the pressure and u denotes the velocity. Pressure and density are functionally depending and, consequently, we also have px = pρ ρx = c2 (ρ)ρx ,
(10.4.16)
where c(ρ) is the sound speed. From (10.4.15) it follows (ρu)t + (ρu2 + p)x = 0, ρt + (ρu)x = 0,
(10.4.17)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
228
which can be arranged as system (10.4.2) 2 ρu ρu + p ∂t = ∂t U + ∂x F = 0. + ∂x ρu ρ The matrix A is given by
2 ∂F uc = A(U) = , 1 u ∂U
(10.4.18)
(10.4.19)
and its eigenvalues are expressed by λ = u ± c.
(10.4.20)
In this case stability condition (10.3.14) is rewritten as (|u| + c)s ≤ 1.
(10.4.21)
Similarly, the Lax-Friederichs method is generalized to systems (10.4.2) ui,j+1 = (ui+1,j + ui−1,j )/2 − (s/2)(Fi+1,j − Fi−1,j ).
(10.4.22)
Finally, we give the MacCormack method for nonlinear systems u∗i,j+1 = ui,j − s(Fi+1,j − Fi,j ), ui,j+1 = (1/2)[ui,j + u∗i,j+1 − s(F∗i,j+1 − F∗i−1,j+1 )],
(10.4.23) (10.4.24)
where F∗i,j = F(u∗i,j ).
(10.4.25)
Exercise 10.4.2 Apply both the MacCormack method and the LaxWendroff method to the Burger equation defined by (10.4.14). Compare the results. Further Reading: [Ames (1992)], [Cattaneo (1948)], [Khaliq and Twizell (1982)], [Lapidus and Pinter (1982)], [Lax (1954)], [Larsson and Thom´ee (2003)], [Mitchell and Griffiths (1995)], [Morton and Mayers (2002)], [Necati Ozisik (1994)], [Parter (1979)], [Richtmyer and Morton (1967)], [Smith (1985)], [Thomas (1995)], [Vernotte (1958)].
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Chapter 11
Elliptic equations
Elliptic partial differential equations are involved in many physical processes. A classic example is provided by the potential generated by gravitational and electrostatic fields. Also, the heat propagation in steady-state systems is analyzed by these type of equations. Another important phenomenon governed by elliptic equations is given by flows through porous media. This model is developed more in details. A basic role in this contest is played by the Darcy’s law (1856). Most applications lead to the Dirichlet, Neumann and Robin problems. Consequently, numerical methods are developed essentially for these boundary value problems. We discuss finite-difference methods for each of them. Furthermore, several examples are provided. A section is devoted to the case of curved boundary.
229
wsdac04
July 3, 2004
23:17
230
11.1
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
Historic model
Remarkable examples of elliptic partial differential equations are given by the Poisson equation ∆U = F, ∆ =
∂2 ∂2 ∂2 + 2 + 2, 2 ∂x ∂y ∂z
(11.1.1)
and by the Laplace equation, which is the homogeneous version of (11.1.1), ∆U = 0.
(11.1.2)
Problems involving elliptic equations are provided by the stationary heat conduction in solids. Indeed, in such a situation heat equation reduces to (11.1.1), or to (11.1.2) when there are no internal thermal sources. The analysis of the elliptic equations is known as potential theory. This points out the historic relationship of the elliptic equations with the potential of gravitational and electrostatic fields. Indeed, consider the simple example of the gravitational field generated by the mass m lying in the origin of the reference system Oxyz. The potential in P (x, y, z) is defined by ∇U = F = −Gmr/r3 ,
(11.1.3)
F , and r its where G is the gravitational constant, r is the radius vector OP modulus r = x2 + y 2 + z 2 . (11.1.4) Straightforward calculations show that the potential U , expressed by U (x, y, z) = Gm/r,
(11.1.5)
satisfies Laplace equation (in all the space, excluded O). Similar results hold for the potential of gravitational fields produced by discrete and continuous systems. 11.2
Porous media
A porous medium can be described as a portion of space occupied by heterogeneous or multiphase matter, for example, solid, fluid and gas; in addition, the solid phase must be distributed throughout the medium and the pores are interconnected, [Bear (1972); Lambe and Whitman (1969)]. An important example is provided by an aquifer, which is a geological stratum
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Elliptic equations
231
containing moving groundwater. Here, the term groundwater denotes water beneath the ground surface. Another remarkable example is given by gas or oil reservoirs. Flows through porous media are analyzed by means of the continuity equation and the Darcy’s law (1856), an experimental law very similar to the Fourier and Fick’s laws. This law follows from physical experiences showing that flows take place from higher piezometric head ϕ to lower one and not from higher pressure regions to lower pressure zones. If q is the flux vector per unit time per unit area, Darcy’s law for isotropic media at rest states that q = −K∇ϕ,
(11.2.1)
where K is the hydraulic conductivity coefficient. This is expressed by K = kρg/µ,
(11.2.2)
where ρ and µ denote the fluid density and viscosity, respectively, k is the permeability of the medium and g is the gravity acceleration. Furthermore, if the z-axis of the reference system is oriented against the gravitation, fig. 11.2.1, ϕ is given by ϕ = z + p/ρg,
(11.2.3)
where p is the fluid pressure. The last formula emphasizes that ϕ is expressed by two terms: elevation head (z) and pressure head (p/ρg).
Fig. 11.2.1
Porous media: vertical section
The generic volume Ω, fig. 11.2.1, is occupied by solid particles, by gas (for example, air) and by fluid (for example, water). The ratio between the
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
232
volume of voids and the whole volume is defined as porosity and denoted by n; it may depend on space and time. It is a dimensionless quantity and is expressed in percentages. The ratio between the volume of voids and the volume of solids is denoted by e and it is functionally related to n by simple relations e = n/(1 − n) ⇔ n = e/(1 + e).
(11.2.4)
When the volume of voids is completely filled by the fluid, this is said to be saturated. In this situation the fluid mass in the control volume Ω is given by ρn dΩ. (11.2.5) Ω
Conservation of mass requires that the time rate of (11.2.5) must equate the mass flowing into Ω through the boundary ∂Ω summed to the internal production d ρn dΩ = − ρq · n dS + ρF dΩ, (11.2.6) dt Ω ∂Ω Ω where n denotes the outward unit normal to ∂Ω at the integration point. Applying the Gauss divergence theorem to (11.2.6) gives (ρn)t dΩ = − ∇ · (ρq) dΩ + ρF dΩ. (11.2.7) Ω
Ω
Ω
Since equality (11.2.7) holds for arbitrary Ω, under the assumption that the integrand functions are continuous, we obtain the continuity equation (ρn)t = −∇ · (ρq) + ρF.
(11.2.8)
Next, consider Darcy’s law (11.2.1) to find (ρn)t = ∇ · [ρK∇ϕ] + ρF.
(11.2.9)
For incompressible fluids (e.g. water) and constant hydraulic conductivity, (11.2.9) becomes nt = K∆ϕ + F.
(11.2.10)
If n is independent of t, as it happens in steady flows, equation (11.2.10) reduces to Poisson equation K∆ϕ + F = 0,
(11.2.11)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Elliptic equations
233
which, by the definition of ϕ, is equivalent to (K/ρg)∆p + F = 0.
(11.2.12)
Equation (11.2.12), or (11.2.11), describes very well pressure regime in several situations (e.g. seepage through earth dams, groundwater motions in drainage basins..., [Bear (1972); Crank (1984); Duffy (1986)]). However, in other cases, the hypothesis nt = 0 is unrealistic. This occurs when the physical process is influenced by phenomena depending on time. In this context, we briefly mention the problem of consolidating media, under the assumption of vertical compressibility. Note that from (11.2.4) it follows et = nt /(1 − n)2 .
(11.2.13)
Furthermore, if the load remains unchanged, as it happens in most groundwater flows, it is [Bear (1972)] et = α∗ pt ,
(11.2.14)
where α∗ is a coefficient expressing soil’s compressibility. Therefore, nt = (1 − n)2 α∗ pt .
(11.2.15)
Insert this into (11.2.10) to obtain (1 − n)2 α∗ pt = (K/ρg)∆p + F,
(11.2.16)
where we recognize the heat equation. 11.3
Dirichlet problem
Consider the Dirichlet problem for the two-dimensional Laplace equation Uxx + Uyy = 0, (x, y) ∈ Ω,
(11.3.1)
where U is prescribed on the boundary ∂Ω U (x, y) = g(x, y), (x, y) ∈ ∂Ω.
(11.3.2)
At first, let us discuss the special situation of a rectangular domain Ω = {0 < x < Lx , 0 < y < Ly }. In this case, boundary condition (11.3.2) becomes U (x, 0) = g(x, 0), U (x, Ly ) = g(x, Ly ), 0 ≤ x ≤ Lx , U (0, y) = g(0, y), U (Lx , y) = g(Lx , y), 0 ≤ y ≤ Ly .
(11.3.3)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
234
Now, using the central approximations for both derivatives of equation (11.3.1) yields ui,k+1 − 2ui,k + ui,k−1 ui+1,k − 2ui,k + ui−1,k + = 0, (∆x)2 (∆y)2
(11.3.4)
where ui,k = u(xi , yk ) = u(i∆x, k∆y).
(11.3.5)
σ = ∆y/∆x,
(11.3.6)
Putting
formula (11.3.4) becomes −2(1 + σ 2 )ui,k + σ 2 (ui+1,k + ui−1,k ) + ui,k+1 + ui,k−1 = 0,
(11.3.7)
with i = 1, ..., nx − 1, nx = Lx /∆x, k = 1, ..., ny − 1, ny = Ly /∆y. (11.3.8) This scheme is called five-point method for evident reasons, fig. 11.3.1. It
Fig. 11.3.1
Five-point method
is completed by the boundary conditions ui,0 = gi,0 , ui,ny = gi,ny , i = 0, ..., nx , u0,k = g0,k , unx,k = gnx,k , k = 0, ..., ny .
(11.3.9)
When ∆x = ∆y, algorithm (11.3.7) simplifies in −4ui,k + ui+1,k + ui−1,k + ui,k+1 + ui,k−1 = 0.
(11.3.10)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Elliptic equations
235
Before examining the general case, apply (11.3.7) to an example. Example 11.3.1
Consider the case illustrated in fig. 11.3.2, where the
Fig. 11.3.2
Example 11.3.1
six unknowns ui,k , i = 1, 2, 3, k = 1, 2, must be found when the boundary conditions ui,0 = gi,0 , ui,3 = gi,3 , i = 0, 1, 2, 3, 4,
(11.3.11)
u0,k = g0,k , u4,k = g4,k , k = 0, 1, 2,
(11.3.12)
are assigned. Writing explicitly (11.3.7) for i = 1, 2, 3, k = 1, 2, gives rise to the linear system −2(1 + σ 2 )u1,1 + σ 2 u2,1 + u1,2 + g1,0 + σ 2 g0,1 = 0, σ 2 u1,1 − 2(1 + σ 2 )u2,1 + σ 2 u3,1 + u2,2 + g2,0 = 0, σ 2 u2,1 − 2(1 + σ 2 )u3,1 + u3,2 + g3,0 + σ 2 g4,1 = 0, u1,1 − 2(1 + σ 2 )u1,2 + σ 2 u2,2 + g1,3 + σ 2 g0,2 = 0, u2,1 + σ 2 u1,2 − 2(1 + σ 2 )u2,2 + σ 2 u3,2 + g2,3 = 0, u3,1 + σ 2 u2,2 − 2(1 + σ 2 )u3,2 + g3,3 + σ 2 g4,2 = 0,
(11.3.13)
which solves completely the problem, as it is easy to verify. In addition, by defining the vectors
g0,1 g0,2 u1,h g1,0 g1,3 b1 = σ 2 0 + g2,0 , b2 = σ 2 0 + g2,3 , uh = u2,h , g3,0 g3,3 u3,h g4,1 g4,2
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
236
h = 1, 2, and the matrix 0 σ2 −2(1 + σ 2 ) , B= −2(1 + σ 2 ) σ2 σ2 2 2 0 −2(1 + σ ) σ system (11.3.13) is arranged as Bu1 + u2 + b1 = 0, u1 + Bu2 + b2 = 0.
(11.3.14)
This is equivalent to
B I I B
b1 u1 + = 0, u2 b2
(11.3.15)
where I denotes the unit matrix. Hence, Au + b = 0, where
(11.3.16)
B I b1 u1 A= , b= . , u= I B u2 b2
The general situation is discussed in the same way. Consider the vectors u1,k , k = 1, ..., ny − 1, (11.3.17) uk = · unx −1,k
g0,1 g0,k 0 2 0 +σ · , bk = σ 2 · , k = 2, ..., ny −2, (11.3.18) b1 = gn −2,0 0 0 x gnx −1,0 gnx ,1 gnx ,k g1,0 g2,0 ·
bny −1
g0,ny −1 0 + σ2 , = · gn −2,n 0 x y gnx −1,ny gnx ,ny −1 g1,ny g2,ny ·
(11.3.19)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Elliptic equations
and the tridiagonal matrix of order −2(1 + σ 2 ) σ2 2 −2(1 + σ 2 ) σ 2 σ · · B = ·
nx − 1
· · · 2 σ2 σ −2(1 + σ 2 ) 2 −2(1 + σ 2 ) σ
237
. (11.3.20)
By using these notations, system (11.3.7) is rewritten as Bu1 + u2 + b1 = 0, u1 + Bu2 + u3 + b2 = 0, u2 + Bu3 + u4 + b3 = 0, ... uny −2 + Buny −1 + bny −1 = 0.
(11.3.21)
Hence,
u1 b1 A · + · = 0, uny −1 bny −1 where A is the block matrix of order ny − 1 B Inx −1 0nx −1 I B Inx −1 nx −1 · · · A= . · · · Inx −1 B Inx −1 0nx −1 Inx −1 B
(11.3.22)
(11.3.23)
Here, Inx −1 denotes the unit matrix of order nx − 1 and 0nx −1 the zero matrix of the same order. Finally, putting uT = [u1 , ..., uny −1 ], bT = [b1 , ..., bny −1 ], from (11.3.22) it follows Au + b = 0.
(11.3.24)
This linear system is formed by (nx −1)(ny −1) equations in (nx −1)(ny −1) unknowns ui,k , related to the interior points of domain Ω. The matrix A is not singular. To realize this, it is enough to verify that all its eigenvalues αik , i = 1, ..., nx − 1, k = 1, ..., ny − 1 are different from zero. Indeed, they
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
238
coincide with the eigenvalues of the (ny βi 1 0 1 β 1 i · · · · · 1 0
− 1) × (ny − 1) matrix
· βi 1
, 1 βi
(11.3.25)
where βi is the ith the eigenvalue of B βi = −2(1 + σ 2 ) + 2σ 2 cos(iπ/nx ), i = 1, ..., nx − 1.
(11.3.26)
Therefore, it results αik = βi + 2 cos(kπ/ny ), i = 1, ..., nx − 1, k = 1, ..., ny − 1, αik = −4[sin2 (kπ/2ny ) + sin2 (iπ/2nx )] < 0.
(11.3.27)
Remark 11.3.1 Formula (11.3.9) implies a maximum principle for the finite-difference solution of the Dirichlet problem. Indeed, assume for sake of simplicity ∆x = ∆y, so that (11.3.9) is rewritten as ui,k =
1 [ui+1,k + ui−1,k + ui,k+1 + ui,k−1 ]. 4
This shows that ui,k cannot attain its maximum or minimum value at an interior point, unless it is a constant, for otherwise it could not be the average of points of its neighbor. The maximum principle can be used to prove that ui,k is unique. In fact, if u1i,k and u2i,k are solutions of the Dirichlet problem with the same boundary conditions, we immediately obtain 0 ≤ u1i,k − u2i,k ≤ 0, proving that u1i,k = u2i,k . This last result indirectly implies that the matrix A is not singular. Let us estimate the truncation error. From (11.3.4) it follows Tij =
Ui+1,k − 2Ui,k + Ui−1,k Ui,k+1 − 2Ui,k + Ui,k−1 + . (∆x)2 (∆y)2
(11.3.28)
Furthermore, applying Taylor’s series expansion gives Ui,k±1 = Ui,k ± (Uy )i,k ∆y + (Uyy )i,k
(∆y)2 (∆y)3 ± (Uyyy )i,k 2 3!
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Elliptic equations
+(Uyyyy )i,k
(∆y)4 (∆y)5 ± (Uyyyyy )i,k + O((∆y)6 ). 4! 5!
wsdac04
239
(11.3.29)
Hence, Ui,k+1 + Ui,k−1 = 2Ui,k + (Uyy )i,k (∆y)2 +(Uyyyy )i,k
(∆y)4 + O((∆y)6 ). 12
(11.3.30)
Similarly, Ui+1,k + Ui−1,k = 2Ui,k + (Uxx )i,k (∆x)2 +(Uxxxx)i,k
(∆x)4 + O((∆x)6 ). 12
(11.3.31)
Now, substituting these last two results into (11.3.28) yields Tij = (Uxx +Uyy )i,k +(Uxxxx )i,k
(∆x)2 (∆y)2 +(Uyyyy )i,k +O((∆x)4 +(∆y)4 ). 12 12
Hence, since (Uxx + Uyy )i,k = 0, it follows Tij = O((∆x)2 + (∆y)2 ). Remark 11.3.2
(11.3.32)
Consider the Dirichlet problem for the Poisson equation
Uxx + Uyy = F (x, y), 0 < x < Lx , 0 < y < Ly .
(11.3.33)
Applying the five-point method gives ui+1,k − 2ui,k + ui−1,k ui,k+1 − 2ui,k + ui,k−1 + = fi,k . (∆x)2 (∆y)2
(11.3.34)
It is easy to realize that this case can be discussed as the previous one. Only the known term of system (11.3.24) has to be modified to include the source terms. 11.4
Curved boundary
This section deals with the Dirichlet problem for the Laplace equation in two-space dimensions Uxx + Uyy = 0, (x, y) ∈ Ω,
(11.4.1)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
240
U (x, y) = g(x, y), (x, y) ∈ ∂Ω,
(11.4.2)
when the domain Ω possesses curved boundaries. Evidently, there exist
Fig. 11.4.1
Dirichlet problem. Curved boundary
points, close the boundary, where equation (11.3.4) cannot be used. For example, in the case illustrated in fig. 11.4.1, formula (11.3.4) can be applied to the points depicted by full disks, but not to those depicted by blank disks. Indeed, focus our attention on P (x, y). The points (x + ∆x, y) and (x, y + ∆y) are outside the domain Ω, whereas the boundary data are prescribed on the points B(x + λ∆x, y) and D(x, y + µ∆y), 0 < λ < 1, 0 < µ < 1. To discuss these situations, consider the Taylor’s series expansions (λ∆x)2 + O((∆x)3 ), 2
(11.4.3)
(∆x)2 + O((∆x)3 ). 2
(11.4.4)
U (B) U (A) U (P ) 2 + − + O(∆x). (∆x)2 λ(1 + λ) 1 + λ λ
(11.4.5)
U (D) U (C) U (P ) 2 + − + O(∆y). Uyy (P ) = (∆y)2 µ(1 + µ) 1 + µ µ
(11.4.6)
U (B) = U (P ) + Ux (P )λ∆x + Uxx (P ) U (A) = U (P ) − Ux (P )∆x + Uxx (P ) Hence, Uxx (P ) = Similarly,
Noting that equation (11.4.1) is satisfied on P , from (11.4.5) and (11.4.6) it follows u(B) u(A) u(P ) u(D) u(C) u(P ) (∆y)2 + − + − + , (11.4.7) (∆x)2 λ(1 + λ) 1 + λ λ µ(1 + µ) 1 + µ µ
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Elliptic equations
241
with a truncation error of order O(∆x + ∆y). Solving with respect to u(P ) yields the equation which replaces (11.3.7) 2 u(B) σ 1 u(A) u(C) u(D) 2 + + + , (11.4.8) u(P ) = σ + λ µ λ(1 + λ) 1 + λ µ(1 + µ) 1 + µ where σ is defined by (11.3.6). Obviously, formula (11.4.8) reduces (11.3.7) if λ = µ = 1. Another simple method to evaluate u(P ) is obtained by linear interpolation. Indeed, u(P ) = [u(B) + λu(A)]/(1 + λ),
(11.4.9)
u(P ) = [u(D) + µu(C)]/(1 + µ).
(11.4.10)
or,
11.5
Three-dimensional applications
Consider the Laplace equation involving three-space dimensions ∆U = Uxx + Uyy + Uzz = 0, (x, y, z) ∈ Ω,
(11.5.1)
where Ω = {0 < x < Lx , 0 < y < Ly , 0 < z < Lz }.
(11.5.2)
The five-point method can be easily generalized to this case to become the seven-point method. In fact, as in two-space dimensions, we obtain, fig. 11.5.1, ui,k+1,l − 2ui,k,l + ui,k−1,l ui+1,k,l − 2ui,k,l + ui−1,k,l + + (∆x)2 (∆y)2 ui,k,l+1 − 2ui,k,l + ui,k,l−1 = 0, (∆z)2
(11.5.3)
i = 1, ..., nx − 1, nx = Lx /∆x, k = 1, ..., ny − 1, ny = Ly /∆y, l = 1, ..., nz − 1, nz = Lz /∆z.
(11.5.4)
where
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
242
Fig. 11.5.1
Seven-point scheme
Hence, ui,k,l =
1 [ui+1,k,l +ui−1,k,l +ui,k+1,l +ui,k−1,l +ui,k,l+1 +ui,k,l−1 ], (11.5.5) 6
where ∆x = ∆y = ∆z for simplicity only. Relations (11.5.5) give rise to a linear system which allows us to find all the unknowns, related to the interior points of Ω, when the Dirichlet boundary conditions are prescribed. Furthermore, since the maximum principle still holds here, the solution is also unique. 11.6
Green’s identities. Consequences
The next sections will be devoted to the Neumann and Robin problems. To better understand the numerical methods for these problems, we briefly mention well-known uniqueness results. The Gauss divergence theorem for a normal bounded domain Ω states ∇ · q dΩ = q · n dS, (11.6.1) Ω
∂Ω
¯ dS is the element of boundary area and n the where q ∈ C (Ω) ∩ C(Ω), exterior unit normal. From (11.6.1) some basic identities can be deduced. ¯ from (11.6.1) it At first, assuming q = ∇u, where u ∈ C 2 (Ω) ∩ C 1 (Ω), follows ∂u ∆u dΩ = dS. (11.6.2) ∂n Ω ∂Ω 1
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Elliptic equations
243
¯ then (11.6.1) implies If q = v∇u, where v ∈ C 2 (Ω) ∩ C 1 (Ω), ∂u dS. (v∆u + ∇v · ∇u) dΩ = v ∂n Ω ∂Ω Similarly, if q = u∇v, (u∆v + ∇u · ∇v) dΩ =
∂Ω
Ω
u
(11.6.3)
∂v dS. ∂n
Lastly, subtract the last two formulas to find ∂v ∂u −u (v∆u − u∆v) dΩ = v dS. ∂n ∂n Ω ∂Ω
(11.6.4)
Integral relations (11.6.2)-(11.6.4) are known as Green’s identities. Remark 11.6.1
Consider the Dirichlet problem ∆U = F (x, y, z), (x, y, z) ∈ Ω,
(11.6.5)
U = g(x, y, z), (x, y, z) ∈ ∂Ω.
(11.6.6)
If U1 and U2 are both solutions of this problem, then the function U = U1 − U2
(11.6.7)
satisfies the Laplace equation with homogeneous boundary conditions ∆U (x, y, z) = 0, (x, y, z) ∈ Ω,
(11.6.8)
U (x, y, z) = 0, (x, y, z) ∈ ∂Ω.
(11.6.9)
Now, apply identity (11.6.3) with u = v = U to find (Ux2 + Uy2 + Uz2 ) dΩ = 0,
(11.6.10)
Ω
Ux2 + Uy2 + Uz2 = 0, on Ω.
(11.6.11)
U = U1 − U2 = c, on Ω,
(11.6.12)
Hence,
where c is a constant, which must be zero because of (11.6.9). Therefore, the solution of (11.6.5), (11.6.6) is unique, if it is smooth enough to verify the hypotheses of the Green’s identities. The numerical conclusions of Section 11.3 are in complete agreement with this result.
July 3, 2004
23:17
244
Remark 11.6.2
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
Consider the Neumann problem for the Poisson equation ∆U = F (x, y, z), (x, y, z) ∈ Ω,
(11.6.13)
∂U = g(x, y, z), (x, y, z) ∈ ∂Ω, ∂n
(11.6.14)
where ∂/∂n denotes the directional derivative, normal to ∂Ω and directed on the outside. If U1 and U2 are two solutions of the Neumann problem, then their difference U is solution of ∆U (x, y, z) = 0, (x, y, z) ∈ Ω,
(11.6.15)
∂U (x, y, z) = 0, (x, y, z) ∈ ∂Ω. ∂n
(11.6.16)
Again use identity (11.6.3) with u = v = U to obtain the result (11.6.12). This proves that any two solutions U1 , U2 of (11.6.13), (11.6.14) differ at most by a constant. Furthermore, if u = U in (11.6.2), it follows F dΩ = g dS. (11.6.17) ∂Ω
Ω
This relation gives a necessary condition for the existence of a solution. If boundary data (11.6.14) are not assigned according to (11.6.17), no solution exists for the Neumann problem. When Laplace equation is considered, then F = 0, and compatibility condition (11.6.17) reduces to g dS = 0. (11.6.18) ∂Ω
Remark 11.6.3 Consider the third boundary value problem, or Robin problem, for the Poisson equation ∆U = F (x, y, z), (x, y, z) ∈ Ω,
(11.6.19)
∂U + αU = g(x, y, z), (x, y, z) ∈ ∂Ω, ∂n
(11.6.20)
where α denotes a strictly positive function α(x, y, z) > 0, (x, y, z) ∈ ∂Ω.
(11.6.21)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Elliptic equations
wsdac04
245
The difference U = U1 −U2 of two solutions of problem (11.6.19), (11.6.20), satisfies the Laplace equation with homogeneous conditions of the third kind. If we proceed as in the previous cases, we arrive at (Ux2 + Uy2 + Uz2 ) dΩ + αU 2 dS = 0. (11.6.22) ∂Ω
Ω
Hence, Ux2 + Uy2 + Uz2 = 0, on Ω,
(11.6.23)
U = 0, on ∂Ω.
(11.6.24)
Evidently, (11.6.23) and (11.6.24) imply U = 0 on Ω, proving uniqueness. 11.7
Neumann problem
Consider the Neumann problem for the Laplace equation in two-space dimensions Uxx + Uyy = 0, on Ω,
(11.7.1)
∂U = g, on ∂Ω, ∂n
(11.7.2)
where g is assigned according to condition (11.6.18) and ∂/∂n denotes the directional derivative normal to ∂Ω. If the domain is given by Ω = {0 < x < Lx , 0 < y < Ly },
(11.7.3)
condition (11.7.2) becomes −Uy (x, 0) = g(x, 0), Uy (x, Ly ) = g(x, Ly ), 0 ≤ x ≤ Lx , −Ux (0, y) = g(0, y), Ux (Lx , y) = g(Lx , y), 0 ≤ y ≤ Ly .
(11.7.4)
Approximating equation (11.7.1) by the five-point method yields −2(1 + σ 2 )ui,k + σ 2 (ui+1,k + ui−1,k ) + ui,k+1 + ui,k−1 = 0, i = 0, ..., nx = Lx /∆x, k = 0, ..., ny = Ly /∆y.
(11.7.5)
Unlike the Dirichlet problem, in this case the values of ui,k on the boundary are unknowns. However, it is clear that, when the indexes i and k assume their extreme values, ghost points, outside the domain Ω, are involved in formula (11.7.1), fig. 11.7.1. For example, when k = 0, it results
July 3, 2004
23:17
246
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
Fig. 11.7.1
Neumann problem
−2(1+σ 2)ui,0 +σ 2 (ui+1,0 +ui−1,0 )+ui,1 +ui,−1 = 0, i = 0, ..., nx . (11.7.6) The fictitious values can be eliminated by a suitable application of the boundary conditions (11.7.4). Indeed, applying the central approximation to the first condition (11.7.4) gives −(ui,1 − ui,−1 )/(2∆y) = gi,0 , i = 0, ..., nx ,
(11.7.7)
gi,k = g(xi , yk ).
(11.7.8)
ui,−1 = ui,1 + 2gi,0 ∆y, i = 0, ..., nx .
(11.7.9)
where
From (11.7.7) it follows
Similarly, ui,ny +1 = ui,ny −1 + 2gi,ny ∆y, i = 0, ..., nx , u−1,k = u1,k + 2g0,k ∆x, k = 0, ..., ny , unx +1,k = unx −1,k + 2gnx ,k ∆x, k = 0, ..., ny ,
(11.7.10) (11.7.11) (11.7.12)
with a truncation error of order O((∆x)2 + (∆y)2 ). Substituting the results (11.7.9)-(11.7.11) into (11.7.5) yields a linear system Au + b = 0,
(11.7.13)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Elliptic equations
247
formed by (nx + 1)(ny + 1) equations involving (nx + 1)(ny + 1) unknowns. This system will be analyzed later, after discussing a special situation. Example 11.7.1 Consider the case illustrated in fig. 11.7.2 and write explicitly equations (11.7.5). By using (11.7.9)-(11.7.11), the first three
Fig. 11.7.2
Example 11.7.1
equations (11.7.5), i = 0, 1, 2 and k = 0, become −2(1 + σ 2 )u0,0 + 2σ 2 u1,0 + 2u0,1 + 2(σ 2 ∆x + ∆y)g0,0 = 0, σ 2 u0,0 − 2(1 + σ 2 )u1,0 + σ 2 u2,0 + 2u1,1 + 2∆yg1,0 = 0, 2σ 2 u1,0 − 2(1 + σ 2 )u2,0 + 2u2,1 + 2(σ 2 ∆x + ∆y)g2,0 = 0.
(11.7.14)
These equations can be rewritten in compact form as Bu0 + 2u1 + b0 = 0,
(11.7.15)
where the matrix B is defined by
−2(1 + σ 2 ) 0 2σ 2 , B= −2(1 + σ 2 ) σ2 σ2 2 2 0 −2(1 + σ ) 2σ and u0,0 u0,1 (1 + σ)g0,0 . u0 = u1,0 , u1 = u1,1 , b0 = 2∆y g1,0 u2,0 u2,1 (1 + σ)g2,0
Similarly, the other six equations can be arranged as u0 + Bu1 + u2 + b1 = 0, 2u1 + Bu2 + b2 = 0,
(11.7.16)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
248
where u0,2 σg0,1 (1 + σ)g0,2 . u2 = u1,2 , b1 = 2∆y 0 , b2 = 2∆y g1,2 u2,2 (1 + σ)g2,2 σg2,1
Lastly, system (11.7.15), (11.7.16) is rewritten as B 2I 0 b0 u0 I B I u1 + b1 = 0. u2 b2 0 2I B Hence, Au + b = 0, where B 2I 0 b0 u0 A = I B I , u = u1 , b = b1 . u2 b2 0 2I B
Verify that matrix A is singular. Consider the general case. Define the column vectors u0,k uk = · , k = 0, ..., ny , unx ,k σg0,s 0 bs = 2∆y · , s = 1, ..., ny − 1, 0 σgnx ,s
(11.7.17)
(1 + σ)g0,0 (1 + σ)g0,ny g1,0 g1,ny , bny = 2∆y , b0 = 2∆y · · gn −1,0 gn −1,n x x y (1 + σ)gnx ,0 (1 + σ)gnx ,ny
(11.7.18)
(11.7.19)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Elliptic equations
wsdac04
249
and the matrix B of order nx + 1 −2(1 + σ 2 ) 2σ 2 −2(1 + σ 2 ) σ 2 σ2 · · · B= . (11.7.20) · · · σ2 σ 2 −2(1 + σ 2 ) −2(1 + σ 2 ) 2σ 2 Substitute the results (11.7.9)-(11.7.12) into equations (11.7.5) and use the notations (11.7.17)-(11.7.20) to obtain Bu0 + 2u1 + b0 = 0, u0 + Bu1 + u2 + b1 = 0, u1 + Bu2 + u3 + b2 = 0, ... 2uny −1 + Buny + bny = 0. Introducing the block matrix of order ny + 1 B 2Inx +1 0nx +1 I nx +1 B Inx +1 · · · A= , · · · Inx +1 B Inx +1 0nx +1 2Inx +1 B
(11.7.21)
(11.7.22)
yields
u0 b0 A · + · = 0. uny bny This assumes the typical form (11.7.13) with the positions uT = [u0 , ..., uny ] and bT = [b0 , ..., bny ]. It is an easy task to verify that the homogeneous system Au = 0, admits the solution
c c = · , c
(11.7.23)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
250
where c is an arbitrary constant. Consequently, if u1 is a solution of (11.7.13), then also u2 = u1 + c is, in complete agreement with the general result of Remark 11.6.2. This also implies that the matrix A is singular. Exercise 11.7.1 the scalars
Consider the matrix B defined by (11.7.20). Verify that
βi = −2(1 + σ 2 ) + 2σ 2 cos(iπ/nx ), i = 0, ..., nx ,
(11.7.24)
and the vectors
cos(iπv0 ) , vi = i/nx, i = 0, ..., nx , Vi = · cos(iπvnx )
(11.7.25)
satisfy the system BVi = βi Vi , i = 0, ..., nx ,
(11.7.26)
that is, βi is the ith eigenvalue of B and Vi the corresponding eigenvector. Exercise 11.7.2 Use the last results to find that the eigenvalues of matrix A, defined by (11.7.22), are expressed by αik = βi + 2 cos(kπ/ny ) = −2(1 + σ 2 ) +2σ 2 cos(iπ/nx ) + 2 cos(kπ/ny ), i = 0, ..., nx , i = 0, ..., ny .
(11.7.27)
Deduce that A is singular. Consider the Neumann problem for the Poisson equation Uxx + Uyy = F (x, y), (x, y) ∈ Ω = {0 < x < Lx , 0 < y < Ly }, (11.7.28) with boundary conditions (11.7.4). The discussion of this problem gives rise to no further difficulty and the five-point method can be applied. Only the known term b, in system (11.7.13), has to be modified to include the terms deriving from F . Finally, let us examine the case of a curved boundary, fig. 11.7.3. The normal derivative in P can be approximated by ∂U (P ) ≈ [u(P ) − u(A)]/AP ∂n
(11.7.29)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Elliptic equations
Fig. 11.7.3
wsdac04
251
Neumann problem. Curved boundary
and the value u(A) is evaluated by linear interpolation u(A) = [u(C)AB + u(B)AC]/BC.
(11.7.30)
Substitute the last result into (11.7.29) to obtain u(P ) = [u(C)AB + u(B)AC]/BC + AP
11.8
∂U (P ). ∂n
(11.7.31)
Third boundary value problem
Consider the Robin problem for the Laplace equation in two-space dimensions Uxx + Uyy = 0,
on Ω,
(11.8.1)
∂U + αU = g, on ∂Ω, (11.8.2) ∂n where the function α is assumed to be strictly positive, according to (11.6.21). There is no special difficulty to discuss this problem by finitedifference methods, as boundary conditions (11.8.2) can be treated as in the Neumann problem. Of course, heavier matrices are obtained. Assume Ω = {0 < x < Lx , 0 < y < Ly },
(11.8.3)
and approximate (11.8.1) by the five-point formula −2(1 + σ 2 )ui,k + σ 2 (ui+1,k + ui−1,k ) + ui,k+1 + ui,k−1 = 0,
(11.8.4)
where i = 0, ..., nx = Lx /∆x, k = 0, ..., ny = Ly /∆y.
(11.8.5)
July 3, 2004
23:17
252
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
In addition, apply the central approximations to boundary data (11.8.2), exactly as in the Neumann problem, ui,−1 = ui,1 + 2∆y(gi,0 − αi,0 ui,0 ), i = 0, ..., nx ,
(11.8.6)
ui,ny +1 = ui,ny −1 + 2∆y(gi,ny − αi,ny ui,ny ), i = 0, ..., nx ,
(11.8.7)
u−1,k = u1,k + 2∆x(g0,k − α0,k u0,k ), k = 0, ..., ny ,
(11.8.8)
unx +1,k = unx −1,k + 2∆x(gnx ,k − αnx ,k unx ,k ), k = 0, ..., ny .
(11.8.9)
Consider equations (11.8.4) for k = 0 and i = 0, ..., nx , −2(1 + σ 2 )u0,0 + σ 2 (u1,0 + u−1,0 ) + u0,1 + u0,−1 = 0, −2(1 + σ 2 )u1,0 + σ 2 (u2,0 + u0,0 ) + u1,1 + u1,−1 = 0, ... −2(1 + σ 2 )unx ,0 + σ 2 (unx +1,0 + unx −1,0 ) + unx ,1 + unx ,−1 = 0, and use (11.8.6)-(11.8.9) to find −2[1 + σ 2 + ∆y(1 + σ)α0,0 ]u0,0 + 2σ 2 u1,0 + 2u0,1 + 2∆y(1 + σ)g0,0 = 0, σ 2 u0,0 − 2[1 + σ 2 + ∆y(1 + σ)α1,0 ]u1,0 + σ 2 u2,0 + 2u1,1 + 2∆yg1,0 = 0, ... 2σ 2 unx −1,0 − 2[1 + σ 2 + ∆y(1 + σ)αnx ,0 ]unx ,0 + 2unx ,1 +2∆y(1 + σ)gnx ,0 = 0. The last equations can be arranged in the following matrix form Bu0 + 2u1 + b0 = 0,
(11.8.10)
where the vectors u0 , u1 , b0 are defined as in (11.7.17)-(11.7.19), and the (nx + 1) × (nx + 1) matrix B is given by b00 2σ 2 σ2 b σ2 11 · · · B= (11.8.11) , · · · σ2 σ 2 bnx −1nx −1 2 2σ bnx nx
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Elliptic equations
wsdac04
253
with bjj = −2[1 + σ 2 + ∆y(1 + σ)αj,0 ], j = 0, nx , bhh = −2[1 + σ 2 + ∆yαh,0 ], h = 1, ..., nx − 1.
(11.8.12)
Next, consider equations (11.8.4) for k = 1 and i = 0, ..., nx . If, as before, boundary conditions (11.8.6)-(11.8.9) are inserted into these equations, it follows u0 + Bu1 + u2 + b1 = 0.
(11.8.13)
u1 + Bu2 + u3 + b2 = 0, ... 2uny −1 + Buny + bny = 0.
(11.8.14)
Similarly,
Equations (11.8.10), (11.8.13), (11.8.14) are summarized by Au + b = 0,
(11.8.15)
where the block matrix A, of order ny + 1, is defined as in (11.7.22) and, in addition, uT = [u0 , ..., uny ], bT = [b0 , ..., bny ]. System (11.8.15) is formed by (nx + 1) × (ny + 1) equations in (nx + 1) × (ny + 1) unknowns and it solves completely the problem. Further Reading: [Ames (1992)], [Bear (1972)], [DuChateau and Zachmann (1989)], [Knabner and Angermann (2003)], [Lambe and Whitman (1969)], [Lapidus and Pinter (1982)], [Larsson and Thom´ee (2003)], [Mitchell and Griffiths (1995)], [Smith (1985)], [Thomas (1995)], [Twizell (1984)].
July 3, 2004
23:17
254
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Appendix A
Classification of PDEs
Partial differential equations can be quite different in character and a classification is necessary to emphasize their distinctive features. This chapter serves as introduction to their classification. Second-order equations are analyzed first. Also, examples, which are often encountered in applications, are presented. Next, systems of first-order partial differential equations are classified. Relationships with second-order equations are pointed out by several examples.
255
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
256
A.1
Second-order partial differential equations
The most general partial differential equation of second order in the unknown function u(x, y) takes the form F (x, y, u, ux , uy , uxx , uxy , uyy ) = 0.
(A.1.1)
Of special importance is the equation a11 uxx + 2a12 uxy + a22 uyy = f,
(A.1.2)
where the coefficients aij and the source term f are real functions of x, y, u, ux , uy aij = aij (x, y, u, ux , uy ), f = f (x, y, u, ux, uy ).
(A.1.3)
Equation (A.1.2) is said quasi-linear, because it is linear in the second derivatives, which are the derivatives of highest order. If the functions aij are independent of u, ux, uy and f depends linearly on u and its derivatives aij = aij (x, y), f = a(x, y)u + b(x, y)ux + c(x, y)uy + d(x, y), the equation becomes linear. To classify equation (A.1.2) consider the symmetric matrix A a11 a12 . A= a12 a22
(A.1.4)
(A.1.5)
The eigenvalues of A are real, as the matrix is symmatric. They are solutions of the characteristic equation |A − λI| = 0, ⇔ λ2 − λ(a11 + a22 ) − (a212 − a11 a22 ) = 0,
(A.1.6)
where I is the unit matrix. Partial differential equation (A.1.2) can be characterized in terms of the signs of these eigenvalues, which evidently depend on ∆ = a212 − a11 a22 .
(A.1.7)
Precisely, • ∆ > 0, the eigenvalues have opposite sign, the equation is hyperbolic in (x, y), • ∆ = 0, one of two eigenvalues vanishes, the equation is parabolic in (x, y), • ∆ < 0, the eigenvalues have same sign, the equation is elliptic in (x, y).
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Classification of PDEs
wsdac04
257
Remark A.1.1 In quasi-linear case (A.1.3), the type of equation may depend on the point (x, y) as well as the solution. In linear situation (A.1.4), the classification depends only on the point and it is independent of this in the special case of constant coefficients. Remark A.1.2
Note that ∆ is the discriminant of the algebraic equation a11 µ2 − 2µa12 + a22 = 0.
(A.1.8)
Therefore, it can be equivalently stated that partial differential equation (A.1.2) is of hyperbolic, parabolic, or elliptic type, if algebraic equation (A.1.8) has two real roots, one real root, or no real root, respectively. Exercise A.1.1
Consider the following equations
utt − c2 uxx = f, (wave, or d’Alembert, equation),
(A.1.9)
ut − αuxx = f, (heat, or Fourier, equation),
(A.1.10)
uxx + uyy = f, (potential, or Poisson-Laplace, equation),
(A.1.11)
uxx − yuyy = f, (transonic-flow, or Tricomi, equation),
(A.1.12)
where c and α are real positive constants. Verify that the wave equation is hyperbolic, the heat equation is parabolic, the potential equation is elliptic, and the Tricomi equation is of hyperbolic or elliptic type, if y > 0 or y < 0, respectively. Finally, let us classify the second-order partial differential equation in the unknown u(x), x = (x0 , ..., xn ) n
aij (x)uxi xj = f (x, u, uxi ), aij = aji ,
(A.1.13)
i,j=0
where the functions aij are assumed to be real. The classification of equation (A.1.13) depends on the eigenvalues λi , i = 0, ..., n of the symmetric matrix A = [aij ]. Precisely, equation (A.1.13) is said to be • hyperbolic in x if the eigenvalues do not vanish, n of them have the same sign and the remaining eigenvalue has opposite sign, • parabolic in x if one of the eigenvalues vanishes and the others have the same sign,
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
258
• elliptic in x if all the eigenvalues do not vanish and have the same sign. Exercise A.1.2
Verify that the equations
utt −c2 (uxx +uxx ) = f, ut −α(uxx +uxx ) = f, uxx +uxx +uzz = f, (A.1.14) are hyperbolic, parabolic and elliptic, respectively.
A.2
Systems of first-order PDEs
The most general partial differential equation of first order in the unknown function u(x, t) is F (x, t, u, ux , ut ) = 0.
(A.2.1)
When F is linear in the first derivatives aux + but = c,
(A.2.2)
and the real functions a, b, c, depend on x, t, u a = a(x, t, u), b = b(x, t, u), c = c(x, t, u),
(A.2.3)
equation (A.2.1) is said to be quasi-linear. If the functions a and b are independent of u a = a(x, t), b = b(x, t), c = c(x, t, u),
(A.2.4)
equation (A.2.2) is called almost linear. If, in addition, the function c depends linearly on u a = a(x, t), b = b(x, t), c = d(x, t)u + f (x, t),
(A.2.5)
equation (A.2.2) is linear. Now, let us consider a system of n partial differential equations of first order in n unknown functions ui (x, t), i = 1, ..., n, n j=1
[aij ujx + bij ujt ] = ci , i = 1, ..., n.
(A.2.6)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Classification of PDEs
wsdac04
259
To give compact form to system (A.2.6), let us define the matrices A, B and the column vectors u, c, b11 . b1n u1 c1 a11 . a1n A = . . . , B = . . . , u = . , c = . . (A.2.7) an1 . ann bn1 . bnn un cn By these notations, system (A.2.6) is rewritten in matrix form as Aux + But = c.
(A.2.8)
Moreover, definitions (A.2.3)-(A.2.5) are generalized to system (A.2.6) in obvious way. This system is called quasi-linear, almost linear, or linear if aij = aij (x, t, u), bij = bij (x, t, u), ci = ci (x, t, u), i, j = 1, ..., n, (A.2.9) aij = aij (x, t), bij = bij (x, t), ci = ci (x, t, u), i, j = 1, ..., n,
(A.2.10)
aij = aij (x, t), bij = bij (x, t), i, j = 1, ..., n,
(A.2.11)
or
ci =
n
dij (x, t)uj + fi (x, t), i = 1, ..., n,
(A.2.12)
i=1
respectively. Example A.2.1
When n = 2, system (A.2.6) simplifies in a11 u1x + a12 u2x + b11 u1t + b12 u2t = c1 , a21 u1x + a22 u2x + b21 u1t + b22 u2t = c2 .
(A.2.13)
Moreover,
a11 a12 b11 b12 u1 c A= ,B = ,u = ,c = 1 . a21 a22 b21 b22 u2 c2
(A.2.14)
The classification of systems (A.2.6) can be carried out if the matrix B, or A, is nonsingular. Assume that the determinant |B| =
0 and consider the algebraic equation |A − λB| = 0.
(A.2.15)
System (A.2.6) is said to be totally hyperbolic in (x, t) if equation (A.2.15) has n real, different roots and elliptic if equation (A.2.15) has no real root. If
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
260
equation (A.2.15) possesses n real, not all distinct roots, system is hyperbolic if there exist n linearly independent eigenvectors; otherwise, it is parabolic. If equation (A.2.15) has both real and complex roots, a general classification cannot be provided. Example A.2.2
Consider the wave equation (A.1.9) and assume f = f (x, t).
(A.2.16)
u1 = ux , u2 = ut ,
(A.2.17)
With the positions
(A.1.9) is transformed into the system 0 −1 10 u1t 0 u1x + = , −c2 0 01 f u2x u2t
(A.2.18)
and |A − λB| = λ2 − c2 .
(A.2.19)
System (A.2.18) is (totally) hyperbolic. Example A.2.3 Consider again the wave equation (A.1.9) and eliminate the assumption (A.2.16), so that f takes its general expression f = f (x, t, u, ux , ut ).
(A.2.20)
u1 = u, u2 = ux , u3 = ut ,
(A.2.21)
Defining
yields the system u1t = u3 , u2t = u3x , u3t − c2 u2x = f (x, t, u1 , u2 , u3 ). Equivalently, in matrix form, 0 0 0 100 u3 u1x u1t 0 0 −1 u2x + 0 1 0 u2t = 0 . u3x u3t 0 −c2 0 f 001
(A.2.22)
(A.2.23)
Moreover, |A − λB| = λ(λ2 − c2 ), showing that (A.2.23) is (totally) hyperbolic.
(A.2.24)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Classification of PDEs
wsdac04
261
Example A.2.4 Consider the heat equation (A.1.10) under the assumption (A.2.16) on f . Apply (A.2.17) to derive the system u2x = u1t , u2 − αu1x = f, or, equivalently, 0 1 −1 0 0 u1x u1t + = . u2x u2t −α 0 0 0 f − u2
(A.2.25)
(A.2.26)
Note that the matrix B is singular and A is not. In this case the role of B should be played by A and vice versa. It is easier to change the roles of the variables x and t. In this way system (A.2.26) becomes 0 1 0 u1t −1 0 u1x + = . (A.2.27) u2x u2t −α 0 f − u2 0 0 Moreover, the equation |A − λB| = αλ2 = 0,
(A.2.28)
has the double root λ = 0. Therefore, it is necessary to analyze the eigenvectors. From (A − λB)v = 0, it follows that there is only one independent eigenvector 0 v= , 1
(A.2.29)
(A.2.30)
showing that the system is parabolic. Exercise A.2.1 Consider heat equation (A.1.10) and assume that f is given by (A.2.20). Using (A.2.21) gives u1x = u2 , u3x = u2t , αu2x = u3 − f (x, t, u1 , u2 , u3 ).
(A.2.31)
Verify that (A.2.31) is a parabolic system. Exercise A.2.2 Consider Laplace equation (A.1.11), where f = 0. Use definitions (A.2.17) to derive an elliptic system. Further Reading: [Courant and Hilbert (1962)], [Duffy (1986)], [Haberman (1983)], [Kevorkian (1990)], [Myint-U and Debnath (1987)], [Renardy and Rogers (1993)], [Taylor (1996)], [Zauderer (1983)].
July 3, 2004
23:17
262
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Appendix B
Elements of linear algebra
Since elements of Linear Algebra occur frequently in dealing with computational methods for partial differential equations, a background in this field is necessary. For example, the concept of matrix norms compatible with vector norms is very important in the stability analysis of finite-difference schemes. Also, the eigenvalues and the eigenvectors of a matrix play a basic role in many problems and applications. To make this volume self-contained, this chapter deals with the essential concepts of Linear Algebra in a very schematic way. Special results of numerical interest are emphasized. Several examples and exercises are provided.
263
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
264
B.1
Eigenvalues and eigenvectors
Let A be an m × m matrix and Im the identity matrix. The roots of the characteristic equation |A − λIm | = 0, are the eigenvalues of matrix A and the vectors u1 u = · , um
(B.1.1)
(B.1.2)
the nontrivial solutions of the linear system Au − λu = 0,
(B.1.3)
are called (right) eigenvectors of the matrix A. Exercise B.1.1
Verify that the eigenvalues of ab0 A = c a b, 0ca
(B.1.4)
are given by λ1 = a +
√ √ 2bc, λ2 = a, λ3 = a − 2bc,
(B.1.5)
and the eigenvectors are expressed by √ √ 2 2 1/2 1/2 (c/b)1/2 2 (c/b) 2 (c/b) , u3 = u1 = √ c/b 0 , u2 = √ −c/b . (B.1.6) 2 2 3/2 3/2 −(c/b)3/2 2 (c/b) 2 (c/b) Formulas (B.1.5) and (B.1.6) can be equivalently written as √ λi = a + 2 bc cos(πi/4), i = 1, 2, 3, (c/b)1/2 sin(πi/4) ui = (c/b) sin(2πi/4) , i = 1, 2, 3, (c/b)3/2 sin(3πi/4)
(B.1.7)
respectively.
(B.1.8)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Elements of linear algebra
wsdac04
265
Matrix (B.1.4) is a special case of tridiagonal matrix, which in general case is defined by a b c a b · · · (B.1.9) T = . · · · c a b c a
Exercise B.1.2
Verify that the scalars √ λi = a + 2 bc cos[πi/(m + 1)], i = 1, ..., m,
(B.1.10)
and the vectors
(c/b)1/2 sin[πi/(m + 1)] · j/2 ui = (c/b) sin[πij/(m + 1)] , i = 1, ..., m, · m/2 sin[πim/(m + 1)] (c/b)
(B.1.11)
satisfy the system T ui = λi ui , i = 1, ..., m. Therefore, they are the eigenvalues and the eigenvectors, respectively, of the matrix T , defined by (B.1.9). Note that formulas (B.1.10), (B.1.11) reduce to (B.1.7), (B.1.8) when m = 3. A matrix A and its transpose AT possess the same eigenvalues. Instead, their eigenvectors, denoted by ui , vi , i = 1, ..., m, respectively, verify the relationship (B.1.12). Exercise B.1.3 Show that
Let λi , i = 1, ..., m, be the eigenvalues of a matrix A. (λi − λj )uTi vj = 0.
Note that (B.1.12) implies uTi vj = 0 for λi = λj .
(B.1.12)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
266
Exercise B.1.4 Let λ be an eigenvalue of the matrix A and u the corresponding eigenvector. Verify that An u = λn u, n ∈ N.
(B.1.13)
A−n u = λ−n u.
(B.1.14)
Note that this implies
Example B.1.5
Consider the block matrix A11 · A1m A = · · · , Am1 · Amm
(B.1.15)
where the n × n matrices Aij possess a common set of independent eigenvectors vk , k = 1, ..., n. Denote by αkij the eigenvalue of Aij corresponding to the eigenvector vk Aij vk = αkij vk , k = 1, ..., n, i = 1, ..., m, j = 1, ..., m.
(B.1.16)
It can be verified that the eigenvalues of A coincide with those of the matrices k α11 · αk1m · · · , k = 1, ..., n. (B.1.17) αkm1 · αkmm Indeed, let α be one of these eigenvalues and a its corresponding eigenvector. From the definition k α11 · αk1m · · · a = αa, (B.1.18) αkm1 · αkmm it follows
k k α11 a1 + ... + α1m am = αa1 ... k αm1 a1 + ... + αkmm am = αam .
(B.1.19)
Now, consider the vector
a1 vk u= · am vk
(B.1.20)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Elements of linear algebra
wsdac04
267
and note that k k α11 a1 vk + ... + αk1m am vk (α11 a1 + ... + αk1m am )vk = . Au = ... ... k k k k αm1 a1 vk + ... + αmm am vk (αm1 a1 + ... + αmm am )vk Therefore, from (B.1.19) it follows αa1 vk = αu, · Au = αam vk
(B.1.21)
proving that α is the eigenvalue of A corresponding to the eigenvector u. The spectral radius ρ(A) of a matrix A is defined by ρ(A) = max |λi |. i=1,...,m
(B.1.22)
In the complex plane, it gives the radius of the smallest disc, with the centre as origin, which contains all the eigenvalues. Useful bounds concerning the spectral radius are provided by the Gerschgorin’s theorem. Theorem B.1 Consider the m × m matrix A. For every eigenvalue λi of A there exists an integer n = n(i) such that m
|λi − Ann | ≤
|Anj |.
(B.1.23)
j=1;j =n
In other words, the eigenvalues of A lie in the union of the m discs, defined by (B.1.23) for n = 1, ..., m. In addition, the spectral radius of a matrix A satisfies the following estimate ρ(A) ≤ max
i=1,...,m
m
|Aij |.
(B.1.24)
j=1
Indeed, consider the definition of eigenvalue Aui = λi ui ,
(B.1.25)
and denote by n = n(i) the index such that |uin | = max |uij |. j=1,...,m
(B.1.26)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
268
Next, select the nth equation m
λi uin =
Anj uij .
(B.1.27)
j=1
Hence, |λi | ≤
m
|Anj ||uij /uin | ≤
j=1
m
|Anj | ≤ max
m
i=1,...,m
j=1
|Aij |,
(B.1.28)
j=1
which implies (B.1.24). To complete the proof, rewrite (B.1.27) as follows λi − Ann =
m
Anj uij /uin .
(B.1.29)
j=1;j =n
Considering the moduli gives (B.1.23). Remark B.1.1 Since A and its transpose AT have the same eigenvalues, formulas (B.1.23) and (B.1.24) can be replaced by m
|λi − Ann | ≤
|Ajn |,
(B.1.30)
|Aij |,
(B.1.31)
j=1;j =n
ρ(A) ≤ max
j=1,...,m
m i=1
respectively. Remark B.1.2
The following results
||A||1 = max
j=1,...,m
m i=1
|Aij |, ||A||∞ = max
i=1,...,m
m
|Aij |,
(B.1.32)
j=1
will be proved in the next section. Considering (B.1.32), the estimates (B.1.24), (B.1.31) on the spectral radius can be summarized by ρ(A) ≤ min{||A||1 , ||A||∞ }.
(B.1.33)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Elements of linear algebra
B.2
wsdac04
269
Vector and matrix norms
The norm of a vector
u1 u= . um
is a real, non-negative functional, which satisfies the following properties ||u|| ≥ 0, ||u|| = 0 ⇔ u = 0, ||cu|| = |c|||u|| = 0, c = real or complex scalar, ||u1 + u2 || ≤ ||u1 || + ||u2 ||.
(B.2.1) (B.2.2) (B.2.3)
The last property is usually referred to as triangle inequality. Indeed, in the case of three-dimensional (geometric) vectors, where the norm of a vector is given by its modulus, (B.2.3) expresses that in a triangle the length of a side is smaller than the sum of the measures of the other two, fig. B.2.1.
Fig. B.2.1
Triangle inequality
Frequently used norms are the following ||u||1 =
m
|ui |, (L1 norm, or 1-norm),
(B.2.4)
i=1
||u||2 =
m
1/2 |ui |
2
!1/2 = uT u , (L2 norm, or 2-norm),
(B.2.5)
i=1
||u||∞ = max |ui |, (L∞ norm, or infinity norm). i=1,...,m
(B.2.6)
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
270
The last norm is also called maximum norm, or sup norm. Norm L2 is often referred to as energy norm. As noted, a vector norm provides a more or less fine measure of the vector size. For the same reasons the norm of a matrix A = [Aij ], i = 1, ..., m, j = 1, ..., m, is introduced. It is a real, non-negative functional, satisfying the following requirements ||A|| ≥ 0, ||A|| = 0 ⇔ A = 0m ,
(B.2.7)
||cA|| = |c|||A||, c = real or complex number,
(B.2.8)
||A1 + A2 || ≤ ||A1 || + ||A2 ||,
(B.2.9)
||A1 A2 || ≤ ||A1 ||||A2 ||.
(B.2.10)
A matrix norm is said to be compatible with a given vector norm if ||Au|| ≤ ||A||||u||, ||u|| =
0.
(B.2.11)
A first noteworthy consequence of this concept is that a compatible norm provides an estimate on the spectral radius. Indeed, from the two definitions it follows |λ|||u|| ≤ ||A||||u||,
(B.2.12)
ρ(A) ≤ ||A||.
(B.2.13)
and, therefore,
A matrix norm is said to be subordinate to a given vector norm if ||Au|| , ||u||
(B.2.14)
||A|| = max ||Au||.
(B.2.15)
||A|| = max
||u|| =0
which is equivalent to ||u||=1
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Elements of linear algebra
wsdac04
271
The importance of such a norm is that it is necessarily compatible with the vector norm which is subordinate to. Indeed, from (B.2.14) it follows immediately ||A|| ≥
||Au|| , ||u|| =
0, ||u||
which is just (B.2.11). Generally, a subordinate matrix norm is denoted as the vector norm. Thus, ||A||1 , ||A||∞ and ||A||2 denote the norms subordinate to L1 , L∞ and L2 vector norms, respectively. Now, the explicit expressions of these norms are provided. Exercise B.2.1 Note that " " " m " m m m "m " " " ≤ A u |A ||u | ≤ |u | max |Aij |, ij j " ij j j " j=1,...,m " i,j=1 i=1 " j=1 j=1 i=1
(B.2.16)
" " " " m "m " max "" Aij uj "" ≤ max |Aij ||uj | i=1,...,m " " i=1,...,m j=1 j=1 ≤ max
i=1,...,m
m
|Aij |||u||∞ ,
(B.2.17)
j=1
and verify that ||A||1 = max
j=1,...,m
m i=1
|Aij |, ||A||∞ = max
i=1,...,m
m
|Aij |.
(B.2.18)
j=1
Moreover, the following result holds ||A||2 = ρ(A¯T A),
(B.2.19)
where A¯ is the transpose of the conjugate complex of A. If A is real ||A||2 = ρ(AT A). (B.2.20) When A is symmetric, this gives ||A||2 = ρ(A2 ) = ρ2 (A) = ρ(A).
(B.2.21)
July 3, 2004
23:17
272
WSPC/Book Trim Size for 9in x 6in
wsdac04
Computational Methods for PDE in Mechanics
This last result is frequently used in numerical applications and it can be proved as follows. Note that statement (B.2.20) is equivalent to ||A||22 = ρ(AT A),
(B.2.22)
where the matrix AT A is symmetric, positive semi-definite, with nonnegative (real) eigenvalues. Therefore, we have to show that the maximum of the function f (u) = (Au)2 = uT AT Au,
(B.2.23)
with the constraint u2 = uT u = 1, is given by ρ(AT A). The method of Lagrange multipliers is used. Consider the auxiliary function g(u) = f (u) + λ(1 − uT u),
(B.2.24)
and impose that its partial derivatives are vanishing guh = 2
m
Ahj
i=1
m
Aij uj − 2λuh = 0.
(B.2.25)
j=1
This is equivalent to ∇g = 2[AT Au − λu] = 0.
(B.2.26)
Hence, we realize that u is an eigenvector of AT A and λ the corresponding eigenvalue. If the function f is evaluated for this value of u, we obtain f (u) = uT λu = λ,
(B.2.27)
which is what we were to prove. Further Reading: [Edwards (1995)], [Edwards and Penney (1988)], [Lipschutz and Lipson (2001)].
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Bibliography
Ames, W. F. (1992). Numerical Methods for Partial Differential Equations, Academic Press, Inc., San Diego. Bates, K. and Tomkins, T. (1998). Using VisualC++6, Que Corp., Indianapolis. Bear, J. (1972). Dynamics of fluids in porous media, American Elsevier, New York. Bellomo, N. and Preziosi, L. (1995). Modelling, Mathematical methods and Scientific Computation, CRC Press, Boca Raton. Buzzi Ferraris, G. (2000). VisualC++ Applicazioni scientifiche, Mondadori, Milano. Cannon, J. R. (1984). The One-Dimensional Heat Equation, Addison-Wesley Publishing Company, London. Carslaw, H. S. and Jager, J. C. (1959). Conduction of Heat in Solids, Clarendon Press, London. Cattaneo, C. (1948). Sulla conduzione del calore, Atti Sem. Fis. Univ. Modena 3, pp. 83–101. Chapman, D. (1998). Teach Yourself VisualC++6 in 21 days, Macmillan Computer Publishing, Indianapolis. Collatz, L. (1966). The Numerical Treatment of Differential Equations, SpringerVerlag, New York. Courant, R. and Hilbert, D. (1962). Methods of Mathematical Physics, J. Wiley & Sons, New York. Crank, J. (1957). Two methods for the numerical solution of moving boundary problems in diffusion and heat flow, J. Mech. Appl. Math. 10, pp. 220–231. Crank, J. (1979). The Mathematics of Diffusion, Clarendon Press, Oxford. Crank, J. (1984). Free and moving boundary problems, Oxford Science Publications, Clarendon Press, Oxford. D’Acunto, B. and Renno, P. (1999). On the operator ε∂xxt +c2 ∂xx −∂tt in General Domains, Rend. Sem. Mat. Fis. Univ. Modena 47, pp. 192–202. Douglas, J. and Gallie, T. M. (1955). On the numerical integration of a Parabolic Differential Equation subject to a moving boundary condiction, Duke Math. J. 22, pp. 557–570. Douglas, J. and Racheford, H. H. (1956). On the numerical solution of heat 273
wsdac04
July 3, 2004
23:17
274
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
conduction problems in two and three space variables, Trans. Amer. Math. Soc., 82, pp. 421–439. DuChateau, P. and Zachmann, D. (1989). Applied Partial Differential Equations, Harper & Row Publishers, New York. Duffy, D. G. (1986). Solutions of Partial Differential Equations, TAB Books Inc, Blue Ridge Summit, PA. Edwards, H. M. (1988). Linear Algebra, Birkh¨ auser, USA. Edwards, C. H. and Penney, D. E. (1988). Elementary Linear Algebra, Prentice Hall International, Englewood Cliffs. Furzeland, R. M. (1980). A comparative study of numerical methods for moving boundary problems, J. Ins. Math. Appl. 26, pp. 411–429. Graff, K. F. (1975). Wave motion in elastic solids, Clarendon Press, Oxford. Gregory, K. (1997). Special Edition Using VisualC++5, Que Corp., Indianapolis. Gupta, R. S. and Kumar, D. (1980) A modified variable time step method for one-dimensional Stefan problem, Comp. Meth. Appl. Mech. Engng., 23, pp. 101–109. Guenther, R. B. and Lee, J. W. (1988). Partial Differential Equations of Mathematical Physics and Integral Equations, Prentice-Hall, Englewood Cliffs. Haberman, R. (1983). Elementary Applied Partial Differential Equations, Prentice-Hall, Englewood Cliffs. Hundsdorfer, W. and Verner, J. G. (2003). Numerical Solutions of TimeDependent Advection-Diffusion-Reaction Equations, Springer, Berlin. Kays, W. M. and Crawford, M. E. (1993). Convective Heat and Mass Transfer, McGraw-Hill, New York. Kernigham, B. W. and Ritchie, D. M. (1978). The C Programming Language, Prentice-Hall, Englewood Cliffs. Kevorkian, J. (1990). Partial Differential Equations. Analitical Solution Techniques, Wadsworth & Brooks/Cole Advanced Book & Software, Pacific Grove. Khaliq, A. Q. and Twizell, E. H. (1982). The extrapolation of stable finite difference schemes for first order hyperbolic equations, Intern. J. Comp. Math. Appl. 11, pp. 155–167. Kharab, A. and Guenther, R. B. (2002). Introduction to Numerical Methods. A Matlab Approach. Chapman & Hall/CRC, Boca Raton. Knabner, P. and Angermann, L. (2003). Numerical Methods for Elliptic and Parabolic Partial Differential Equations, Springer, New York. Kruglinski, D. J., Sheperd, G. and Wingo, S. (1998). Programming VisualC++, Microsoft Press Int, Redmond. Lambe, T. W. and Whitman, R. V. (1969). Soil Mechanics, J. Wiley & Sons Inc., New York. Lapidus, L. and Pinter, G. F. (1982). Numerical Solutions of Partial Differential Equations in Science and Engineering, J. Wiley & Sons, New York. Larsson, S. and Thom´ee, V. (2003). Partial Differential Equations with Numerical Methods, Springer, New York. Lax, P. D. (1954). Weak solutions of nonlinear Hyperbolic Equations and their numerical computations, Comm. Pure Appl. Math. 7, pp. 159–193.
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Bibliography
wsdac04
275
Lipschutz, S. and Lipson, M. (2001). Linear Algebra, McGraw-Hill, New York. Mitchell, A. R. and Griffiths, D. F. (1995). The Finite Difference Method in Partial Differential Equations, J. Wiley & Sons, New York. Myint-U, T. and Debnath, L. (1987). Partial Differential Equation for Scientists and Engineers, North-Holland, New York. Morton, K. W. (1980). Stability of finite-difference approximations to a diffusionconvection equation, Int. J. Num. Meth. Eng. 12, pp. 899–916. Morton, K. W. (1996). Numerical Solution of Convection-Diffusion Problems, Chapman-Hall, London. Morton, K. W. and Mayers, D. F. (2002). Numerical Solution of Partial Differential Equations, Cambridge University Press, Cambridge. Necati Ozisik, M. (1993). Heat Conduction, J. Wiley & Sons New York. Necati Ozisik, M. (1994). Finite Difference Methods in Heat Transfer, CRC Press, London. Parter (Ed.), S. V. (1979). Numerical Methods for Partial Differential Equations, Academic Press, New York. Quarteroni, A. and Valli, A. (1994). Numerical Approximation for PDE, SpringerVerlag, Berlin. Quarteroni, A., Sacco, R. and Saleri, F. (2002). Matematica numerica, SpringerVerlag Italia, Milano. Renardy, M. and Rogers, R. C. (1993). An Introduction to Partial Differential Equations, Springer-Verlag, New York. Richtmyer, R. D. and Morton, K. W. (1967). Difference methods for initial-value problems, J. Wiley & Sons, New York. Rose, M. E. (1960). A Method for calculating solutions of Parabolic Equations with a free boundary, Math. Comput. 14, pp. 249–256. Rubinstein, L. I. (1971). The Stefan Problem, Translation of Mathematical Monographs, American Mathematical Society, Providence. Smith, G. D. (1985). Numerical Solutions of Partial Differential Equations: Finite Difference methods, Oxford University Press, Oxford. Taylor, M. E. (1996). Partial Differential Equations III, Springer-Verlag, New York. Thomas, J. W. (1995). Numerical Partial Differential Equations, Springer-Verlag, New York. Twizell, E. H. (1984). Computational Methods for Partial Differential Equations, J. Wiley & Sons, New York. Vernotte, P. (1958). Le paradoxes de la theorie continue de la chaleur, C. R. Acad. Sci. Paris 246, pp. 3154–3155. Zauderer, E. (1983). Partial Differential Equations of Applied Mathematics, J. Wiley & Sons, New York.
July 3, 2004
23:17
276
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
wsdac04
July 3, 2004
23:17
WSPC/Book Trim Size for 9in x 6in
Index
accurate, 29 advection equation, 210 almost linear equation, 258 almost linear system, 259 amplification factor, 103
Dirichlet conditions, 13 Dirichlet problem, 233, 239 discretization error, 30 distortional waves, 185 DuFort-Frankel method, 108
backward approximation, 3, 6, 7 backward-difference scheme, 94 BTCS implicit method, 220 Burger equation, 228
eigenvalues, 264 eigenvectors, 264 elevation head, 231 elliptic equation, 256 elliptic system, 259 energy method of stability, 116 energy norm, 270 equivoluminal waves, 185
Cattaneo-Vernotte-Maxwell heat equation, 224 central approximation, 4 central approximation, 6, 7 CFL method, 192 classic explicit method, 23 combined scheme, 106 compatible norm, 270 consistency, 28 continuity equation, 183 convection-diffusion equation, 17 convergence, 30 Courant number, 212 Crank-Nicolson method, 196 Crank-Nicolson method, 97, 218
Fick’s law, 18 finite-difference operators, 7 five-point method, 234 forward approximation, 3, 5, 6 Fourier equation, 257 Fourier’s law, 10 FTBS method, 210 FTFS method, 210 heat equation, 12 Hooke’s law, 184 hydraulic conductivity, 231 hyperbolic equation, 256 hyperbolic system, 260
d’Alembert equation, 257 Darcy’s law, 231 diffusion coefficient, 18 diffusion-convection equation, 123 dilational waves, 186
interpolation formulas, 129 irrotational waves, 186 277
wsdac04
July 3, 2004
23:17
278
WSPC/Book Trim Size for 9in x 6in
Computational Methods for PDE in Mechanics
isentropic gas, 187 Josephson tunnel effect, 207 L1 norm, 269 L2 norm, 269 L∞ norm, 269 Lam´e parameters, 185 Laplace equation, 230, 257 Laplace operator, 12 Lax-Friederichs method, 212, 221, 228 Lax-Wendroff method, 213, 225, 226 linear equation, 256 linear system, 259 MacCormack method, 216, 225, 228 matrix method of stability, 113 matrix norm, 270 maximum norm, 270 maximum principle, 238 moment of momentum, conservation, 184 momentum, conservation of, 183 Navier-Stokes equations, 187 Neumann conditions, 13 Newton’s law of cooling, 14 norm of a vector, 269 parabolic equation, 256 parabolic system, 260 perturbed wave equation, 188, 201 piezometric head, 231 Poisson equation, 230, 257 potential, 230 pressure head, 231 quasi-linear equation, 256, 258 quasi-linear system, 259 Richardson method, 107 Robin conditions, 13 Robin problem, 244, 251 specific heat, 11 spectral radius, 267
stability, 25 Stefan problem, 16 Stokes, 186 stress tensor, 183 stress tensor, symmetry, 184 subordinate norm, 270 sup norm, 270 symbol O, 3 tension, 179 thermal conductivity, 10 thermal diffusivity, 12 three-time-level method, 108, 192 totally hyperbolic system, 259 traffic flow, 216 transport theorem, 182 Tricomi equation, 257 tridiagonal matrix, 265 variable-weighted scheme, 106 Von Neumann stability, 103 wave equation, one-dimensional, 181 wave equation, three-dimensional, 185 Wendroff method, 219
wsdac04