MATH 212 Advanced Calculus 2 for Electrical Engineering Advanced Calculus 2 for Nanotechnology Engineering NE 217 1-D Finite-Element Methods with Poisson’s Equation Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada Copyright © 2011 by Douglas Wilhelm Harder. All rights reserved. 1-D Finite-element Methods with Poisson’s Equation Outline This topic discusses an introduction to finite-element methods – Review of Poisson’s equation – Defining a new kernel V(x) – Approximate solutions using uniform test functions 2 1-D Finite-element Methods with Poisson’s Equation Outcomes Based Learning Objectives By the end of this laboratory, you will: – Understand how to approximate the heat-conduction/diffusion and wave equations in two and three dimensions – You will understand the differences between insulated and Dirichlet boundary conditions 3 1-D Finite-element Methods with Poisson’s Equation The Target Equation Recall the first of Maxwell’s equations (Gauss’s equation): E 0 If we are attempting to solve for the underlying potential function, under the assumption that it is a conservative field, we have 2u 0 This is in the form of Poisson’s equation 4 1-D Finite-element Methods with Poisson’s Equation The Target Equation In one dimension, this simplifies to: x d2 u x 2 dx 0 Define: x d2 V x 2 u x dx 0 def and thus we are solving for V x 0 5 1-D Finite-element Methods with Poisson’s Equation The Integral If V x 0 , it follows that f x V x 0 for any test function f(x) and therefore b f x V x dx 0 a Substituting the alterative definition of V(x) into this equation, we get x d2 f x u x a dx2 0 dx 0 b 6 1-D Finite-element Methods with Poisson’s Equation The Integral Consider the first test function f1(x) : x3 b x d2 d2 a f 1 x dx 2 u x dx x dx 2 u x 0 dx 0 1 7 1-D Finite-element Methods with Poisson’s Equation Integration by Parts Again, take x d2 f x u x a dx2 0 dx 0 but before we apply integration by parts, expand the integral: b b x d2 f x u x dx f x a dx2 a 0 dx 0 b Everything in the second integral is known: bring it to the right: b x d2 a f x dx2 u x dx a f x 0 dx b 8 1-D Finite-element Methods with Poisson’s Equation Integration by Parts The left-hand integral is no different from before, b b x d2 f x u x dx f x a dx2 a 0 dx and performing integration by parts, we have x d d d f x u x f x u x dx f x dx 0 dx a a dx dx a b b b x d d d d f b u x f a u x f x u x dx f x dx dx dx dx dx 0 a a x b x a b b 9 1-D Finite-element Methods with Poisson’s Equation Integration by Parts First, substituting in the first test function: b b x d2 f x u x dx f x a 2 d 2 x a 2 0 dx x x1 x x3 which yields x3 x3 1 1 1 x dx d d d d f x u x f x u x f x u x dx f x 2 2 2 3 2 1 dx dx dx dx 0 x1 x1 x x3 x x1 10 1-D Finite-element Methods with Poisson’s Equation The System of Linear Equations Again, recall that we approximated the solution by unknown piecewise linear functions: x x1 x x2 u u 2 1 x x x2 x1 1 2 x x2 x x3 u3 u2 x3 x2 u x x2 x3 x xn x xn 1 u u n n 1 x x xn xn 1 n 1 n x1 x x2 x2 x x3 xn 1 x xn x xk 1 x xk uk 1 where we define uk x uk on xk x xk 1 xk xk 1 xk 1 xk def 11 1-D Finite-element Methods with Poisson’s Equation Unequally Spaced Points Recall that we approximated the left-hand integral by substituting the piecewise linear functions to get: b x d2 a fk x d 2 x u x dx a fk x 0 dx b k 1 x d2 dx x u x d 2 x x 0 dx k 1 k 1 xk 1 x uk uk 1 k 1 x uk 1 uk dx 2 2 xk xk 1 xk 1 0 xk 1 xk x 1 1 1 2 u 2 k 1 x x k 1 xk xk 1 xk 1 xk k 1 2 u k 1 xk 1 xk k 1 x dx uk 1 0 xk 1 x 12 1-D Finite-element Methods with Poisson’s Equation Integration by Parts That is, our linear equations are: 1 1 1 1 u u k 1 k 1 x x x x x x k 1 k 1 k 1 k k k xk 1 xk 1 k 1 x dx uk 1 2 xk 1 0 x This time, let’s take an actual example 13 1-D Finite-element Methods with Poisson’s Equation Integration by Parts Consider the equation d2 u x 2 u x sin 4 x dx with the boundary conditions 2 u(0) = 0 u(1) = 0 14 1-D Finite-element Methods with Poisson’s Equation Integration by Parts The solution to the boundary value problem d2 u x 2 u x sin 4 x dx 2 u(0) = 0 u(1) = 0 is the exact function u x 1 1 2 4 3 x x 1 4 5cos x cos x 16 2 15 1-D Finite-element Methods with Poisson’s Equation Integration by Parts We know in one dimension if the right-hand side is close to zero, the solution is a straight line d2 2 u x 2 u x sin 4 x dx Thus, choose 9 interior points with a focus on the centre: >> x_uneq = [0 0.16 0.25 0.33 0.41 0.5 0.59 0.67 0.75 0.84 1]; 16 1-D Finite-element Methods with Poisson’s Equation Integration by Parts We will compare this approximation with the approximation found using 9 equally spaced interior points – The finite difference approximation >> x_eq = 0:0.1:1; 17 1-D Finite-element Methods with Poisson’s Equation The Test Functions The function to find the approximations is straight-forward: function [ v ] = uniform1d( x, uab, rho ) n = length( x ) - 2; idx = 1./diff(x); M = diag( -(idx( 1:end - 1 ) + idx( 2: end )) ) + ... diag( idx( 2:end - 1 ), -1 ) + ... diag( idx( 2:end - 1 ), +1 ); b b = zeros ( n, 1 ); int( rho, a, b ) approximates x dx for k = 1:n b(k) = 0.5*int( rho, x(k), x(k + 2) ); end a b(1) = b(1) - idx(1)*uab(1); b(end) = b(end) - idx(end)*uab(end); v = [uab(1); M \ b; uab(2)]; end 18 1-D Finite-element Methods with Poisson’s Equation The Test Functions The right-hand function of 2 d 2u x 2 u x sin 4 x dx is also straight-forward: function [ u ] = rho( x ) u = sin( pi*x ).^4; end 19 1-D Finite-element Methods with Poisson’s Equation The Equations Thus, we can find our two approximations: >> >> >> >> >> x_eq = (0:0.1:1)'; plot( x_eq, uniform1d( x_eq, [0, 0], @rho ), 'b+' ); hold on x_uneq = [0 0.16 0.25 0.33 0.41 0.5 0.59 0.67 0.75 0.84 1]'; plot( x_uneq, uniform1d( x_uneq, [0, 0], @rho ), 'rx' ); 20 1-D Finite-element Methods with Poisson’s Equation The Equations It is difficult to see which is the better function, therefore create a function storing the actual solution (as found in Maple): function u = u(x) u = -1/16*( (cos(pi*x).^4 - 5*cos(pi*x).^2 + 4)/pi^2 + 3*x.*(x - 1) ); end ... ... ... 21 1-D Finite-element Methods with Poisson’s Equation The Equations Instead, plotting the errors: >> >> >> >> >> x_eq = 0:0.1:1; plot( x_eq, uniform1d( x_eq, [0, 0], @rho ) - u(x_eq), 'b+' ); hold on xnu = [0 0.16 0.25 0.33 0.41 0.5 0.59 0.67 0.75 0.84 1]; plot( x_uneq, uniform1d( x_uneq, [0, 0], @rho ) - u(x_uneq), 'rx' ); 22 1-D Finite-element Methods with Poisson’s Equation Integration by Parts Understanding that the right-hand side has a greater influence in the centre, d2 2 u x 2 u x sin 4 x dx appropriately changing the sample points yielded a significantly better approximation 23 1-D Finite-element Methods with Poisson’s Equation Summary In this topic, we have generalized Laplace’s equation to Poisson’s equation – Used the same uniform test functions – We looked at a problem for which there is an exact solution • Changing the points allowed us to get better approximations 24 1-D Finite-element Methods with Poisson’s Equation What’s Next? The impulse function (the derivative of a step function) is difficult to deal with… We will next consider test functions that avoid this… – The test functions will be tents – This generalizes to higher dimensions 25 1-D Finite-element Methods with Poisson’s Equation References [1] Glyn James, Advanced Modern Engineering Mathematics, 4th Ed., Prentice Hall, 2011, §§9.2-3. 26 1-D Finite-element Methods with Poisson’s Equation 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 27