MATH 212 Advanced Calculus 2 for Electrical Engineering Advanced Calculus 2 for Nanotechnology Engineering NE 217 Finite-Element Methods in One Dimension Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada Copyright © 2011 by Douglas Wilhelm Harder. All rights reserved. Finite-element Methods in One Dimension Outline This topic discusses an introduction to finite-element methods – Background – Justification – Uniform test functions • On equally spaced points • On unequally spaced points 2 Finite-element Methods in One Dimension Outcomes Based Learning Objectives By the end of this laboratory, you will: – The concept of a test function – How we can approximate Laplace’s equation on unequally spaced points 3 Finite-element Methods in One Dimension Background The most significant problem with finite differences: – Seldom does nature line up on a grid In 1d, finite differences form equally spaced points on a line: We need to be able to move the points around so that: – The points will match the geometry of the actual shape, and – We can add more points in areas of interest 4 Finite-element Methods in One Dimension Justification In higher dimensions, examples from mechanical engineering quickly spring to mind: – The crumple zones of a car User:MrMambo 5 Finite-element Methods in One Dimension Justification However, we may need this flexibility even in one dimension – Consider heat diffusion along a rod containing three regions • Copper • A transition from copper to aluminium • Aluminium The points do not even line up with the transitions in the materials 6 Finite-element Methods in One Dimension Justification We could add more points: Now we are solving a system of 41 equations and unknowns… 7 Finite-element Methods in One Dimension Justification What we really want: – More points close to and in the transition Such a system is much simpler than the previous idea… 8 Finite-element Methods in One Dimension Test Functions We will look at a solution that produces the same result as finite differences; however, we will be able to generalize it – The generalization can be extended to higher dimensions, too 9 Finite-element Methods in One Dimension Test Functions Starting with the equally spaced intervals, define a point a piecewise constant test function for each interval: 1 x1 x x3 0 otherwise 2 x 10 Finite-element Methods in One Dimension Test Functions Starting with the equally spaced intervals, define a point a piecewise constant test function for each interval: 1 x2 x x4 0 otherwise 3 x 11 Finite-element Methods in One Dimension The Unknown Solution We know the solution passes through unknown points with the constraints: u(a) = ua = u1 u(b) = ub = u2 12 Finite-element Methods in One Dimension Piecewise Linear Approximations We will approximation the solution through piecewise linear functions: u1 x u1 x x2 x x1 u2 x1 x2 x2 x1 13 Finite-element Methods in One Dimension Piecewise Linear Approximations We will approximation the solution through piecewise linear functions: u1 x u1 x x2 x x1 u2 x1 x2 x2 x1 1 At x1: u1 x1 u1 0 x1 x2 x x u2 1 1 u1 x1 x2 x2 x1 14 Finite-element Methods in One Dimension Piecewise Linear Approximations We will approximation the solution through piecewise linear functions: u1 x u1 x x2 x x1 u2 x1 x2 x2 x1 0 At x2: u1 x2 u1 1 x2 x2 x x u2 2 1 u2 x1 x2 x2 x1 15 Finite-element Methods in One Dimension Piecewise Linear Approximations We can write a similar piecewise-linear on each interval u2 x u 2 x x3 x x2 u3 x2 x3 x3 x2 16 Finite-element Methods in One Dimension The Target Equation Next, we have Laplace’s equation in one dimension: d2 u x 0 2 dx Define: def d2 V x 2 u x dx we have the equation V x 0 17 Finite-element Methods in One Dimension The Integral If V x 0 , it follows that x V x 0 for any test function (x) and therefore b x V x dx 0 a d2 In this case, however, we defined V x u x and thus 2 dx def d2 a x dx2 u x dx 0 b 18 Finite-element Methods in One Dimension The Integral Consider the first test function 1(x) : 3 d2 d2 a 1 x dx 2 u x dx x dx 2 u x dx 0 1 b x 19 Finite-element Methods in One Dimension The Integral If, however, we approximate u(x) on that interval by the piecewise constant function x x3 x x2 x x1 x x2 u1 x u1 u2 u2 x u 2 u3 x1 x2 x2 x1 x2 x3 x3 x2 d2 d2 u x 2 u2 x 0 we already have that 2 1 dx dx We get no additional information! 20 Finite-element Methods in One Dimension The System of Linear Equations Thus, we approximate the function u(x) by x x1 x x2 u u 2 1 x x x2 x1 1 2 x x2 x x3 u3 u2 x3 x2 u x u x x2 x3 x xn x xn 1 u u n n 1 x x xn xn 1 n 1 n def where we define uk x uk x1 x x2 x2 x x3 xn 1 x xn x xk 1 x xk uk 1 on xk x xk 1 xk xk 1 xk 1 xk 21 Finite-element Methods in One Dimension Integration by Parts However, take d2 x u x a dx2 dx 0 and performing integration by parts, we have b b d d d x u x x u x dx 0 dx a a dx dx b d d d d b u x a u x x u x dx 0 dx dx dx dx a x b x a b 22 Finite-element Methods in One Dimension Integration by Parts First, substituting in the first test function: b d2 x u x a 2 d 2 x dx 0 x x1 x x3 which yields x3 1 1 d d d d x u x x u x x u x dx 0 2 2 3 2 1 dx dx dx dx x1 x x3 x x1 23 Finite-element Methods in One Dimension Integration by Parts Now, given x 3 d d d u x u x x x x x u x 1 3 dx 0 dx dx dx x1 x x3 x x1 substitute our approximation: x3 d d d u x u x x x x x u x 1 3 dx 0 dx dx dx x1 x x3 x x1 Remember that on the interval of interest, x x2 u1 u2 u1 x x1 x x2 x1 x2 u x u x x x x 2 2 3 u x x3 u 3 2 x2 x3 x x1 x2 x1 x1 x x2 x x2 x3 x2 x2 x x3 24 Finite-element Methods in One Dimension Integration by Parts Differentiating and substituting in the two approximations yields u3 u2 u2 u1 2 2 0 x3 x2 x2 x1 but as the denominators are equal (equal width intervals), this simplifies to u3 2u2 u1 0 This is the exact same linear equation we got from Laplace’s equation using finite differences 25 Finite-element Methods in One Dimension The System of Linear Equations If we were to repeat this at each interval, we would have: 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 u2 ua u 0 3 u4 0 u 0 5 u6 0 1 u7 0 2 u8 ub 9k k 1 This has the regular solution uk ua ub 8 8 which is a straight line… 26 Finite-element Methods in One Dimension Unequally Spaced Points What this tells us, however, is that we have a method that can allow us to use arbitrary sized intervals: 27 Finite-element Methods in One Dimension The Test Functions The most obvious generalization is to use similar test functions: 2 x 3 x 4 x 5 x 28 Finite-element Methods in One Dimension The Equations The most obvious generalization is to use similar test functions: u3 u2 u2 u1 0 x3 x2 x2 x1 u4 u3 u3 u2 0 x4 x3 x3 x2 u5 u4 u4 u3 0 x5 x4 x4 x3 u6 u5 u5 u4 0 x6 x5 x5 x4 29 Finite-element Methods in One Dimension The Equations Assuming the width of the intervals are either h or 2h, we get: u3 u2 u2 u1 0 x3 x2 x2 x1 u4 u3 u3 u2 0 x4 x3 x3 x2 u5 u4 u4 u3 0 x5 x4 x4 x3 u6 u5 u5 u4 0 x6 x5 x5 x4 u3 u2 h u4 u3 h u5 u4 2h u6 u5 2h u2 u1 2h u u 3 2 h u u 4 3 h u u 5 4 2h 0 0 0 0 30 Finite-element Methods in One Dimension The Equations Multiply by h: u3 u2 h u4 u3 h u5 u4 2h u6 u5 2h u2 u1 2h u u 3 2 h u u 4 3 h u u 5 4 2h 0 u3 u2 12 u2 12 u1 0 0 0 u4 u3 u3 u2 0 1 2 1 2 u5 12 u4 u4 u3 0 u6 12 u5 12 u5 12 u4 0 0 31 Finite-element Methods in One Dimension The Equations This gives us the system of linear equations 1.5 1 u2 0.5u1 u 0 1 2 1 3 1 1.5 0.5 u4 0 u 0.5 u 0.5 1 5 6 32 Finite-element Methods in One Dimension The Equations Solving this yields points on a straight line 3u1 u6 4 u2 5u 3u 1 6 8 u3 u4 u1 u6 2 u5 u 3u 6 1 4 1 4 3 8 1 2 3 4 33 Finite-element Methods in One Dimension Summary We have looked an alternate approach to approximating solutions to partial differential equations – – – – Used test functions Used integration by parts The result gave us a system of linear equations The solution was an approximation • In this case, with Laplace’s equation in one dimension, it was exact 34 Finite-element Methods in One Dimension What’s Next? We will next consider – Replacing Laplace’s equation with Poisson’s equation – Use non-uniform test functions • Tent functions 35 Finite-element Methods in One Dimension References [1] Glyn James, Advanced Modern Engineering Mathematics, 4th Ed., Prentice Hall, 2011, §§9.2-3. 36 Finite-element Methods in One Dimension Usage Notes • • These slides are made publicly available on the web for anyone to use If you choose to use them, or a part thereof, for a course at another institution, I ask only three things: – that you inform me that you are using the slides, – that you acknowledge my work, and – that you alert me of any mistakes which I made or changes which you make, and allow me the option of incorporating such changes (with an acknowledgment) in my set of slides Sincerely, Douglas Wilhelm Harder, MMath dwharder@alumni.uwaterloo.ca 37