Professional Documents
Culture Documents
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)
xi-1
xi
xi+1
Lecture26
ui+1
xi-1
xi
xi+1
i+1
xi-1
xi
xi+1
Element i
hi
Lecture26
The Discrete problem: find (x) such that the residual r(x) is orthogonal to the basis functions
ij
Lecture26
xi-1
xi
xi+1
-1
xi
xi+1 1
Lecture26
-1
xi
xi+1 1
N'2(t)
N'1(t)
Lecture26
-1
Lecture26
xi-1
xi
xi+1
Lecture26
Galerkin Finite Elements: Matlab
function [A,f] = assembleGlobalProblem(xCoords,func,alpha,beta) % assembleGlobalProblem - loops over elements and assembles global matrix % and right-hand side and sets Dirichlet Boundary conditions % % [A,f] = assembleGlobalProblem(func,xCoords,alpha,beta) % % xCoords:- coordinates of all elements % func:-function handle to RHS f(x) % alpha: - dirichlet condition at xCoords(1); % beta:- dirichlet condition at xCoords(end); % % A: Global stiffness+Mass matrix K+M % f: Global force vector % N = length(xCoords); % numbier of points nels = N - 1; % number of elements A = spalloc(N,N,3*N); f = zeros(N,1); for k = 1:nels % loop over elements and assemble global matrix kEl = k:k+1; % index of element k [Ke,Me] = getElementMatrix(xCoords(kEl)); fe = getElementForceVector(func,xCoords(kEl)); A(kEl,kEl) = A(kEl,kEl) + Ke+Me; f(kEl) = f(kEl)+fe; end %x dirichlet boundary conditions A(1,1:2)=[ 1 0 ]; A(end,end-1:end)=[ 0 1 ]; f([ 1 end ]) = [ alpha ; beta ]';
Lecture26