Lecture26

April 28, 2008

Lecture 26: Putting it all together #5... Galerkin Finite Element Methods for ODE BVPs
Outline

1) Galerkin Finite Elements: Review 2) A specific Example: Piecewise linear elements 3) Computational Issues and Algorithms A) Calculation of integrals: Basis functions vs Element View B) Element Matrices C) Global Assembly 4) Matlab Demo 5) The End (of the beginning)

Galerkin Finite Elements
Example problem: Find best fit piecewise linear function ũ(x), that satisfies -u''+u = f(x) (u(0)=α, u(L)=β) in a least-squares sense
ui-1
u i
u i+1

xi-1

xi

xi+1

x

2008 Galerkin Finite Elements Basis Function view: linear combination of "hat functions" ui-1 ui 1 ui+1 0 xi-1 xi xi+1 x Galerkin Finite Elements Element view: union of piecewise linear elements (with local element basis functions) ui-1 u 1 i u i+1 0 xi-1 xi xi+1 Element i hi .Lecture26 April 28.

Lecture26 April 28. 2008 Galerkin Finite Elements Galerkin FEM as a least squares problem: The Continuous problem: find u(x) that satisfies The Discrete problem: find ũ(x) such that the residual r(x) is orthogonal to the basis functions Galerkin Finite Elements Evaluating the integrals: 3 critical integrals to evaluate 1) Components of the stiffness matrix Kij 2) Components of the Mass matrix M ij 3) Components of the force vector f i .

Lecture26 April 28. basis function view vs "element view": the Mass matrix 1 0 xi-1 xi xi+1 for basis function ϕ want: i Galerkin Finite Elements Putting it together. basis function view vs "element view": the local element Mass matrix Me: consider the contributions from one element i N1(t) N2(t) Element basis functions: N1(t). N2(t) -1 xi t xi+1 1 Need _____ integrals for element mass matrix . 2008 Galerkin Finite Elements Putting it together.

basis function view vs "element view": Element Stiffness Matrix: N1(t) N2(t) N'2(t) N'1(t) .Lecture26 April 28. 2008 Galerkin Finite Elements Putting it together. basis function view vs "element view": the local element Mass matrix Me: consider the contributions from one element i N1(t) N2(t) Element Mass Matrix: -1 xi t xi+1 1 Galerkin Finite Elements Putting it together.

Ke(2.2) = wQ*(N2p(tQ).1) = Me(1. Ke(2. Me(2.5*ones(size(t)).*N2(tQ)).1) = Ke(1. basis function view vs "element view": Element Force vector: N1(t) N2(t) -1 t 1 Galerkin Finite Elements: Matlab function [Ke.2) = wQ*(N2(tQ).2). % quadrature points and weights (2-point Gauss-legendre) tQ = [ -1 1 ]'/sqrt(3).1) = wQ*(N1(tQ).*N1p(tQ)).Me] = getElementMatrix(xCoords) % % xCoords:. N1p = @(t) -. Ke = Ke*2/h.returns element matrices for an individual element % % [Ke.Me] = getElementMatrix(xCoords) % GETELEMENTMATRIX .5*ones(size(t)).*N2p(tQ)).*N1(tQ)).coordinates of 1D element [ xMin xMax ] % Ke: .*N2(tQ)). Me(1.1) = wQ*(N1p(tQ). Ke(1. .2) = wQ*(N1(tQ). Me = Me*h/2.element mass matrix (assuming linear hat elements) % N1 = @(t) (1-t)/2. % derivative dN1/dt (not really a function) N2p = @(t) . Me(2.2). %element width Ke = zeros(2). wQ = [ 1 1 ]. %stiffness matrix Ke(1.Lecture26 April 28.element stiffness matrix (assuming linear elements) % Me: . 2008 Galerkin Finite Elements Putting it together. %Mass matrix Me(1. h = xCoords(2)-xCoords(1). Me = Ke.*N2p(tQ)). % linear hat function N2 = @(t) (1+t)/2.2) = wQ*(N1p(tQ).

fe = fe'*h/2. % affine transformation % quadrature points and weights (2-point Gauss-legendre) tQ = [ -1 1 ]'/sqrt(3). %element width N1 = @(t) (1-t)/2. wQ = [ 1 1 ]. Galerkin Finite Elements: Global Matrix assembly 1 0 xi-1 xi xi+1 .returns element force vector for an individual element % % [fe] = getElementForceVector(func.coordinates of 1D element [ xMin xMax ] % % fe: .xCoords) % getElementForceVector . % linear hat function N2 = @(t) (1+t)/2.Lecture26 April 28.*N1(tQ)). fe(2) = wQ*(func(x(tQ)). %element width %Force vector matrix fe(1) = wQ*(func(x(tQ)). x = @(t) xCoords(1) + h*(t + 1)/2.xCoords) % % func:-function handle to RHS f(x) % xCoords:. 2008 Galerkin Finite Elements: Matlab function [fe] = getElementForceVector(func.element force vector % h = xCoords(2)-xCoords(1).*N2(tQ)). h = xCoords(2)-xCoords(1).

.xCoords(kEl)). % beta:.alpha.loops over elements and assembles global matrix % and right-hand side and sets Dirichlet Boundary conditions % % [A. for k = 1:nels % loop over elements and assemble global matrix kEl = k:k+1. end %fix dirichlet boundary conditions A(1. % number of elements A = spalloc(N. but Finite Elements is a very rich subject.kEl) = A(kEl.dirichlet condition at xCoords(end). beta ]'. cubic.beta) % assembleGlobalProblem . "spectral".dirichlet condition at xCoords(1).Me] = getElementMatrix(xCoords(kEl)).coordinates of all elements % func:-function handle to RHS f(x) % alpha: .3*N).N. f = zeros(N. % index of element k [Ke.end-1:end)=[ 0 1 ]. April 28.1. % % A: Global stiffness+Mass matrix K+M % f: Global force vector % N = length(xCoords). % numbier of points nels = N .f] = assembleGlobalProblem(xCoords. mixed) 2) Higher spatial dimensions: meshing in 2 (and 3-D) Finite element calculation of viscous fluid flow around a "dolfin" ..Lecture26 Galerkin Finite Elements: Matlab function [A. f([ 1 end ]) = [ alpha . A(end.xCoords.. f(kEl) = f(kEl)+fe..f] = assembleGlobalProblem(func.1:2)=[ 1 0 ]. 2008 Galerkin Finite Elements: The future Linear hats on a line is the simplest problem. A(kEl.beta) % % xCoords:. Possible extensions: 1) higher order elements (quadratic. fe = getElementForceVector(func.func.1).alpha.kEl) + Ke+Me.

the fun is just beginning. Computer Science and domain specific science and engineering...but understanding these building blocks is where you start.Lecture26 April 28... computational science and modeling can be a very rewarding mix of Mathematics. .. We've just scratched the surface in this course. 2008 Galerkin Finite Elements: The future Extensions: 3) Space-time PDE's 4) Multi-physics/Multi-Scale models 5) Peta-scale high-performance computation 6) Advanced software design Point: If you're interested..

Sign up to vote on this title
UsefulNot useful

Master Your Semester with Scribd & The New York Times

Special offer: Get 4 months of Scribd and The New York Times for just $1.87 per week!

Master Your Semester with a Special Offer from Scribd & The New York Times