260 likes | 490 Views
1-D Finite-Element Methods with Tent Test Functions. Outline. This topic discusses an introduction to finite-element methods Background Define tent-shaped test functions Perform integration-by-parts to get the linear equation Approximate the solution by a linear solution
E N D
Outline This topic discusses an introduction to finite-element methods • Background • Define tent-shaped test functions • Perform integration-by-parts to get the linear equation • Approximate the solution by a linear solution • Find the system of equations
Outcomes Based Learning Objectives By the end of this laboratory, you will: • Understand the use of test functions in one dimension • Understand how to create a system of linear equations using these test functions in one dimenion
The Target Equation At this point, we have generalized the finite-difference method to allow arbitrarily spaced points in one dimension The ultimate goal is to do this in 2 and 3 dimensions • In order to achieve this, we need one further idea
Test Functions Up to this point, we have used uniform test functions:
Test Functions Two problems: • The impulse function appears in the integrals, and • This will not generalize to two and three dimensions!
Test Functions Solution: • Use a tent function
Test Functions Defining such functions is straight-forward: If x = x2, both , if x = x1, , and if x = x3,
Integration by Parts Now, substitute this test function into the integral: which yields
Integration by Parts The tent function disappears at x1 at x3: thus, this simplifies to: 0
Integration by Parts The tent function disappears at x1 at x3: thus, this simplifies to: 0 A similar property will be used in 2 and 3 dimensions – remember this fact!
Integration by Parts Recall that both the test function f2(x) and are defined on :
Integration by Parts On the intervals, the derivatives are defined:
Integration by Parts Thus:
Integration by Parts In general:
Integration by Parts Substituting this back into our equation, we get: or, expanding the left-hand side:
Integration by Parts In the special case that is a constant, this simplifies further:
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 = zeros ( n, 1 ); for k = 1:n b(k) = int( rho, x(k), x(k + 1), x(k + 2) ); end b(1) = b(1) - idx(1)*uab(1); b(end) = b(end) - idx(end)*uab(end); v = [uab(1); M \ b; uab(2)]; end int( rho, a, b ) approximates
The Test Functions In Matlab, recall that we may evaluate functions at a vector of points: • Let a, b, c be the points x = linspace( a, c, n ); rhox = rho( x ).*((x < b).*(x – a)/(b – a) + (x >= b).*(x – c)/(b – c));
The Test Functions For example, we get the following graph with this Matlab code: >> a = 1; b = 2; c = 5; >> x = linspace( a, c, 100 ); >> tentx = (x < b).*(x - a)/(b - a) + (x >= b).*(x - c)/(b – c); >> cosx = cos(x).*tentx; >> hold on >> plot( x, cosx, 'b' ); >> plot( x, cos(x), 'r' ); >> plot( x, tentx, 'm' );
The Test Functions Using the exact same example fromthe last uniform case: >> x_uneq = [0 0.16 0.25 0.33 0.41 0.5 0.59 0.67 0.75 0.84 1]'; >> u_uniform = uniform1d( x_uneq, [0, 0], @rho ); >> u_tent = tent1d( x_uneq, [0, 0], @rho ); >> plot( x_uneq, u_uniform, 'b+' ); >> hold on >> plot( x_uneq, u_tent, 'rx' );
The Test Functions To demonstrate that this is better than the previous approximation: >> plot( x_uneq, u_uniform - u(x_uneq), 'b+' ); >> plot( x_uneq, u_tent - u(x_uneq), 'rx' ); >> norm( u_uniform - u(x_uneq) ) ans = 0.0012 >> norm( u_tent - u(x_uneq) ) ans = 4.7368e-011 Recall that the function u(x) is the exact solution 8 × 10–4 –1.8 × 10–11
Summary In this topic, we have used tent-shaped test functions as opposed to uniform test functions • The integration-by-parts was simpler • We avoided the end points as they were zero • No impulse functions… • More work is required for the code • Better solution for our example
What’s Next? We will next look at how we can extend this to two dimensions • Use triangles to divide up the region instead of intervals • Tessellations • Approximate the solution using interpolating polynomials Intervals Tessellation
References [1] Glyn James, Advanced Modern Engineering Mathematics, 4th Ed., Prentice Hall, 2011, §§9.2-3.
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