Mat1062: Introductory Numerical Methods for PDE Mary Pugh January 13, 2009 1 Ownership These notes are the joint property of Rob Almgren and Mary Pugh 2 Boundary Conditions We now want to discuss in detail methods for solving the linear diusion equation for u(x, t) u t = D u xx (1) We shall suppose that the domain is X L x X R, and that initial data u 0 (x) is given at t = 0: u(x, 0) = u 0 (x), X L x X R and that suitable boundary conditions are given on x = X L and x = X R for t > 0 We will consider boundary conditions that are Dirichlet, Neumann, or Robin Dirichlet boundary conditions specify the value of u at the endpoints: u(x L, t) = u L (t), u(x R, t) = u R (t) where u L and u R are specied functions of time Neumann conditions specify the derivative u x at the endpoints: u x (X L, t) = u L (t), u x (X R, t) = u R (t) 1
2 Mary Pugh Mat1062 Jan 13, 2009 Robin boundary conditions specify a linear combination of u and u x at the endpoints: a u(x L, t) + b u x (X L, t) = u L (t), c u(x R, t) + d u x (X R, t) = u R (t) where a, b, c, and d are xed constants usually determined by material properties 21 Space Discretization For given X L and X R, we choose a number N Our grid spacing is and we place grid points at locations h = X R X L N x j = X L + j h, j = 0, 1,, N, so that x 0 = X L and x N = X R We represent our solution by a vector U(t) of length N + 1, whose components are U j (t) u ( x j, t), j = 0,, N That is, the jth component of the vector, U j (t) is supposed to approximate the PDE's solution at the x j grid point: u(x j, t) We take the initial data to be an exact sample of the true initial data u 0 (x): U j (0) = u 0 ( xj ) Given Du xx,, a domain [X L, X R ], and boundary conditions, these determine a linear operator on a function space We will approximate this linear operator by a matrix operating on the vector U This allows us to dene U(t) as satisfying a linear ODE U t = LU, which we can solve by standard methods As we will see below, even if the domain is unchanged and the operation Du xx is unchanged, dierent boundary conditions lead to dierent linear operators and hence dierent dynamics This holds in the continuous case (where the operator is acting on a function space) and in the discretized case (where the approximating operator is just a matrix) Boundary conditions matter!
Mat1062 Jan 13, 2009 Mary Pugh 3 22 Dirichlet Boundary Conditions Let us consider the case of Dirichlet boundary conditions: u(x L, t) = u L (t) and u(x R, t) = u R (t) There are N+1 meshpoints and U(t) has a component for each meshpoint However, the the components U 0 (t) and U N (t) are specied by the boundary conditions and so there are only N 1 unknowns: U 1 (t) U N 1 (t) From the January 8 notes, we need to approximate u xx (x j, t) for 1 j N 1 This is done with the nite-dierence approximation In matrix form this is 1 2 1 U 0 u xx (x 1 ) 1 1 2 1 U 1 u xx (x N 1 ) 1 2 1 U N 1 1 2 1 However, these expressions are not quite what we want The vector on the left is of size N 1 and will determine the interior grid values The vector on the right is of size N + 1; it involves both the interior grid values and the boundary values We need to express derivatives at the interior grid points in terms only of interior grid values and the Dirichlet boundary conditions This means that we need to eliminate U 0 and U N from the above Substituting the boundary values u 0 = u L (t), u N = u R (t), we approximate u xx (with Dirichlet boundary conditions on [X L, X R ]) via the inhomogeneous linear operator L 1 L 1 U = M 1 U + R 1, where M 1 is a (N 1) (N 1) tridiagonal matrix and R 1 is an (N 1)-vector containing the boundary data: 2 1 u L (t) M 1 = 1 1 2 1, R 1 (t) = 1 0 (2) 1 2 1 0 1 2 u R (t) R 1 depends on time if the boundary conditions do In practice, it is often more convenient to store the boundary values in their natural locations at U N
4 Mary Pugh Mat1062 Jan 13, 2009 the endpoints of a linear grid, and then the derivatives can be computed by doing the (N 1) (N + 1) multiplication above Of course, the matrix M 1 never actually exists in the computer, nor do we ever actually do a matrix multiply as written above: since most entries are zero, storing the matrix and doing a matrix multiply would be a huge waste of memory and time \Multiplication" really means \apply the linear operator," which we do by taking dierences 23 Neumann Boundary Conditions For Neumann boundary conditions (u x (X L, t) = u L (t), u x (X R, t) = u R (t)) the values at the endponts, U 0 (t) and U N (t), are unknown Again, we approximate the dierentiation operation as U 1 1 2 1 U 0 u xx (x 0 ) 1 1 2 1 U 1 u xx (x N ) 1 2 1 U N 1 1 2 1 U N U N+1 Note that we've done something strange here We refer to U 1 and U N+1 which are the values at X L h and X R + h respectively These grid points are not in our domain They are artices introduced to help implement the nite dierence approximation of u xx at the endpoints Such points are often called \ghost points" The vector on the left is of size N + 1 and will determine the interior grid values and the boundary grid values The vector on the right is of size N + 3; it involves the interior grid values, the boundary grid values, and the values at the two ghost points We need to express the right-hand side in terms of interior grid values and the boundary grid values only This means that we need to use the Neumann boundary conditions to determine the values at the ghost points This is done as follows: u L (t) = u x (X L, t) U 1 U 1 as a result = U 1 = U 1 u L (t) u xx (X L, t) U 1 2U 0 + U 1 = 2U 1 2U 0 2u L(t) h
Mat1062 Jan 13, 2009 Mary Pugh 5 Similarly, at the right-hand endpoint hence 0 = u x (X R, t) U N+1 U N 1 u xx (X R, t) U N+1 2U N + U N 1 = U N+1 = U N 1 + u R (t) = 2U N 1 2U N + 2u R(t) h And so, we approximate u xx (with Neumann boundary conditions on [X L, X R ]) with the inhomogeneous linear operator M 2 U + R 2, where M 2 is a (N+1) (N+1) tridiagonal matrix and R 2 is an N+1-vector containing the boundary data: 2 2 u L (t) M 2 = 1 1 2 1, R 2 (t) = 2 0 h (3) 1 2 1 0 2 2 u R (t) A natural question to ask is why we used centered nite dierences above to approximate u x (X L ) and u x (X R ) rather than using a left-dierence for u x (X L ) and a right-dierence for u x (X R ): 0 = u x (X L ) U 0 U 1 h 0 = u x (X R ) U N+1 U N h We will revisit this question when we discuss the convergence and accuracy of our scheme 24 Robin Boundary Conditions We handle Robin boundary conditions (a u(x L, t) + b u x (X L, t) = u L (t), c u(x R, t) + d u x (X R, t) = u R (t)) in the same manner that we handle Neumann boundary conditions: by introducing ghost grid points the values at which are then determined from the boundary conditions u L (t) = a u(x L, t) + b u x (X L, t) a U 0 + b U 1 U 1 = U 1 = U 1 + 2ah b U 0 u L(t) b
6 Mary Pugh Mat1062 Jan 13, 2009 as a result Similarly, hence u xx (X L, t) U 1 2U 0 + U 1 = 2U 1 (2 2ah/b)U 0 2u L(t) bh u R (t) = c u(x R, t) + d u x (X R, t) c U N + d U N+1 U N 1 = U N+1 = U N 1 2ch d u xx (X R, t) U 1 2U 0 + U 1 U N + u R(t) d = 2U N 1 (2 + 2ch/d)U N + 2u R(t) dh In this way, we can approximate u xx (with Robin boundary conditions on [X L, X R ]) as the inhomogeneous linear operator = M 3 U + R 3 where M 2 is a (N + 1) (N + 1) tridiagonal matrix: 2 + 2ah/b 2 M 3 = 1 1 2 1, R 3 (t) = 2 h 1 2 1 2 2 2ch/d (4) As a reality check, note that if a = c = 0 and if b = d = 1 then this matrix is the same matrix as for the Neumann boundary conditions u L (t)/b 0 0 u R (t)/d 25 Summary The spatial derivative operator Lu = Du xx on [X L, X R ] u(x L, t) = u L (t) u(x R, t) = u R (t)
Mat1062 Jan 13, 2009 Mary Pugh 7 has the discrete approximation LU = MU + R where M = DM 1 and R = DR 1 with M 1 and R 1 given in (2) Similarly, the spatial derivative operator Lu = Du xx on [X L, X R ] u x (X L, t) = u L (t) u x (X R, t) = u R (t) has the discrete approximation LU = MU + R where M = DM 2 and R = DR 2 with M 2 and R 2 given in (3) Finally, the spatial derivative operator Lu = Du xx on [X L, X R ] au(x L, t) + bu x (X L, t) = u L (t) cu(x R, t) + Du x (X R, t) = u R (t) has the discrete approximation LU = MU + R where M = DM 3 and R = DR 3 with M 3 and R 3 given in (4) In all three cases, we have L which is an ane linear operator But the three matrices M 1, M 2, and M 3 are all dierent from one another They will have dierent eigenvalues and eigenvectors All of the eigenvalues of M 1 and M 2 will be either zero or negative The matrix M 3 can have positive eigenvalues They correspond to modes that grow exponentially in time, rather than decaying this shows how powerful boundary eects can be!