Finite difference methods for the diffusion equation D150, Tillämpade numeriska metoder II Olof Runborg May 0, 003 These notes summarize a part of the material in Chapter 13 of Iserles. They are based on the lectures (F5 and F6. 1 Diffusion equation We consider here the model parabolic equation with Dirichlet boundary conditions, u t = u xx, t > 0, x (0, 1, u(0,x = g(x, (1 u(t, 0 = u(t, 1 = 0. The simplest way of deriving and understanding numerical methods for this equation is through semi-discrete approximations. 1.1 Semi-discretizations (SD Semi-discretization means that we only discretize in space, x, and let time, t, remain continuous. Introduce the space grid, x j = j x, x = 1, j =0,...,N +1, N +1 and let u j (t u(t, x j. Approximate the second derivative xx by, for instance, central differences u xx (t, x j u j 1(t u j (t+u j+1 (t ( x, j =1,...,N. This gives the semi-discrete form of (1, du j dt = u j 1 u j + u j+1 ( x, j =1,...,N, u j (0 = g(x j, u 0 (t = u N+1 (t =0. Setting ū(t =(u 1 (t,...,u N (t T we can write this in matrix form as g(x 1 dū = Aū, ū(0 = dt.. ( g(x N 1
where 1 A = 1 ( x 1 1......... 1 1 1 R N N, is a discrete approximation of xx. We have thus transformed a PDE into a large system of ODEs, which is often a useful way of looking at evolutionary PDEs in general. We would get a similar form if xx was approximated with other methods than central differences, for instance FEM. The problem ( can now be solved with standard ODE methods such as forward Euler, ū n+1 =ū n + taū n. The whole approach is often called method of lines, since the PDE problem is eventually solved along a number of lines x = const and t>0. A necessary condition for the approach to work is that the ODE solver is linearly stable, i.e. that tλ n D, n =1,...,N, (3 where {λ n } are the eigenvalues of A and D is the linear stability domain of the ODE method. This implies a restriction on t. A typical example for explicit methods is given by the central difference approximation together with forward Euler. In this case we can write down the eigenvalues in closed form, λ n = 4 ( x sin ( nπ x. (4 It follows that 4/( x <λ n < 0 and since the linear stability restriction of forward Euler and real eigenvalues is tλ n 0, we get 4 t/( x, and then µ := t ( x 1. (5 Note that this is a severe restriction. The timestep must be very much smaller than the spacestep. We will see below that this necessary condition is in fact also sufficient for the Euler scheme to converge when x 0andµ =const. Some remarks: The number µ is often called the Courant number. For explicit methods like Euler, the condition (5 is a very typical restriction on the possible choices of space- and timesteps. In other situations, the natural relationship to consider between t and x is t/ x (without the square, and, beware, sometimes this is also called the Courant number. CFL number is another name often used instead of Courant number. The linear stability depends both on t and x. One should keep in mind that we consider in fact a whole family of ODE-systems indexed by x: When x decreases, the size of A increases and we get a different ODE system, with different eigenvalues, and therefore with different stability properties.
Semi-discretizations of the diffusion equation lead to stiff ODE systems. In the example above, the stiffness ratio is max n λ n min n λ n 1 ( x 1, when x 1. This is the typical situation for all parabolic equations and reflects the fact that many vastly different timescales are present in the solution; low spatial frequencies decay slowly, while high spatial frequencies decay very rapidly. Therefore, implicit methods are preferred for parabolic problems. Hence, the forward Euler method, although good for illustrating the properties of semi-discretizations, is not very practical for actually solving (1. Crank Nicolson (see below is a better choice. 1. Convergence The pure semi-discrete approach is not quite sufficient for analyzing the convergence of numerical schemes for the diffusion equation. Even if we know that the ODE method that we apply to ( is convergent, we cannot conclude that the full method converges. The reasons is that ODE theory only considers convergence as t 0 with a fixed x >0. The method is then only shown to converge to the solution of the semi-discrete approximation. We need to check convergence when t 0 and x 0 at the same time. Usually one maintains a fixed relation between the time- and space step, e.g. t = µ( x or t = λ x, and let x 0. The numbers µ or λ are chosen such that the method remains stable and that the errors incurred by the time- and space discretizations are balanced. In order to analyze this convergence we must start from a full discretization (FD of (1 in time and space. We therefore introduce the space-time grid x j = j x, t n = n t, x = 1, j =0,...,N +1, n =0, 1,..., N +1 and approximate u n j u(t n,x j. Example 1: Forward Euler + central differences = the Euler method, j = u n j + t ( x (un j+1 u n j + u n j 1. Example : Trapezoidal rule + central differences = the Crank Nicolson method, j 1 t ( x (un+1 j+1 un+1 j + j 1 =un j + 1 t ( x (un j+1 u n j + u n j 1. Note that this is an implicit method. We will analyze the following general one-step discretization, b k (µ j+k = k= α c k (µu n j+k. (6 The coefficients b k and c k depend on µ. Close to the boundaries the scheme will have to be modified to accomodate the boundary conditions, but we disregard this complication here. Our goal is loosely speaking to show that u n j u(t n,x j when t, x 0. Let us first introduce some notation and then state this in a more precise way. Set ũ n j = u(t n,x j 3
(the exact solution. Define the vectors ū n =(u n 1,...,u n N T,ũ n =(ũ n 1,...,ũ n N T and the discrete L norm, N g x := x gj, g =(g 1,...,g N T. j=1 Then we say that the method in (6 is convergent if ( lim max ū n ũ n x x 0 0 n N t when t = λ( x r for some positive constants λ, r and with N t t = T fixed. Convergence is given by the important Theorem 13.3 in Iserles (the Lax equivalence theorem which applies not only to the diffusion equation, but to general (well-posed, linear evolutionary PDEs (e.g. also the advection and wave equation in Chapter 14. This theorem says that the method is convergent if it is consistent and stable. We now turn to defining those concepts and to showing how they can be checked for (6. For both of them the method s characteristic function, a(z,µ := =0, β k= α c k(µz k δ b k(µz k, (7 is a helpful tool. It is sometimes also called the amplification factor. 1..1 Consistency We begin to define the local truncation error of the method in (6. It is given as the residual, divided by t, when the exact solution ũ n j is entered into the scheme: b k (µũ n+1 j+k k= α c k (µũ n j+k =: tτ n+1 j. (8 If τj n = O(( xp +( t q the method is of order p in space and q in time. The method is consistent if p 1andq 1. If we use a constant µ, or more generally if t/( x = O(1, then τj n = O(( x p +( x q =O(( x r where r = min(p, q and we simply say that the method is of order r. Consistency and order can either be checked by direct Taylor expansion of the exact solution in (8, or by the following theorem, which characterizes the order via a(z,µ, Theorem 1 If ( a e i x t, ( x = e t + O( t[( x p +( t q ], then the method is of order p and q in space and time respectively. If µ =constand then the method is of order r. (C.f. Theorem 13.6 in Iserles. a ( e i x,µ = e µ( x + O(( x r+, 4
Example: The Euler method is of order in space and 1 in time, i.e. of order if µ is constant. Crank Nicolson is of order both in time and space. This should come as no surprise recalling the order of the corresponding ODE methods (forward Euler and the trapezoidal rule and that central differencing gives a second order approximation of the second derivative. 1.. Stability The method is said to be stable if ū n x C(T ū 0 x, n =0,...,N t, (9 when t = λ( x r for some positive constants λ, r and N t t = T is fixed. Note that the constant C depends on T but not on t and x. For methods derived via semi-discretization, one can show that the stability (9 follows if the ODE-method is linearly stable for each pair of t and x that is used. One can thus follow the methodology in Section 1.1 to check stability. It is, however, not always so straightforward to write down the eigenvalues corresponding to the matrix A, as in (4, and in practice it is often easier to use another method, based on Fourier analysis. The method is called von Neumann anlaysis. For simplicity we assume that the diffusion equation is solved over the entire real axis, and not just in the interval [0, 1]. The spatial index then ranges over all integers, j Z, and we can interpret the sequence u n j as the Fourier series of a function in L [0, π], û n ( := j= u n j e ij. (10 (Here we tacitly assume that {u n j } l (Z for fixed n. See Iserles. After multiplication by e ij and summing the left and right hand side of (6 over all j, we obtain b k (µ b k (µ j= j= j+k e ij = j e i(j k = c k (µ u n j+ke ij, k= α j= c k (µ u n j e i(j k. k= α j= Using the definition (10 we get û n+1 ( b k (µe ik =û n ( k= α c k (µe ik, and finally, after dividing with the b k sum and recalling the definition (7 of a(z,µ, we have û n+1 ( =a(e i,µû n (. The characteristic function a(e i,µ thus shows how frequency is amplified in each timestep. According to a version of Parseval s theorem, ū n x = x π π 5 0 û n ( d,
and therefore, with a := sup 0 π a(e i,µ, ū n+1 x = x π π 0 a(e i,µ û n ( d a x π Consequently, ū n x a n ū 0 x, and the method is stable if a 1. We thus get π Theorem The method in (6 applied to the whole real axis,is stable if 0 û n ( d = a ū n x. a(e i,µ 1, [0, π]. (C.f. Theorem 13.11 in Iserles. This restriction then translates into a restriction on µ. Example 1: The Euler method. Here a(e i,µ=1 4µ sin (, and the method is stable if a 1 for all [0, π], i.e. if µ 1/ (as we already knew. Example : The Crank-Nicolson method. Here a(e i,µ= 1 µ ( sin 1+µ sin (, and 1 µ sin ( a = 1+µ sin ( 1+µ ( sin 1+µ sin ( =1, for all µ>0. We can thus choose any timestep to get stability, which is expected since it is an implicit method. We also have to think about accuracy, however. The local truncation error is O(( x +( t and in order to balance the errors from the time stepping and the space discretization, one often picks t x. 6