galerkin finite element methods
TRANSCRIPT
7/29/2019 Galerkin Finite Element Methods
http://slidepdf.com/reader/full/galerkin-finite-element-methods 1/9
Lecture26 April 28, 20
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
x
xi
xi+1
xi-1
ui-1
ui+1u
i
7/29/2019 Galerkin Finite Element Methods
http://slidepdf.com/reader/full/galerkin-finite-element-methods 2/9
Lecture26 April 28, 20
Galerkin Finite Elements
Basis Function view: linear combination of "hat functions"
x
xi
xi+1
xi-1
ui-1
ui+1u
i
1
0
Galerkin Finite Elements
Element view: union of piecewise linear elements (with local element basis functions)
xi
xi+1
xi-1
ui-1
ui+1u
i
1
0
hi
Element i
7/29/2019 Galerkin Finite Element Methods
http://slidepdf.com/reader/full/galerkin-finite-element-methods 3/9
Lecture26 April 28, 20
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) isorthogonal 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 Mij
3) Components of the force vector f i
7/29/2019 Galerkin Finite Element Methods
http://slidepdf.com/reader/full/galerkin-finite-element-methods 4/9
Lecture26 April 28, 20
Galerkin Finite Elements
Putting it together, basis function view vs "element view": the Mass matrix
0
1
xi-1 x
i+1xi
for basis function ϕiwant:
Galerkin Finite Elements
Putting it together, basis function view vs "element view": the local elementMass matrix M
e: consider the contributions from one element i
xi
xi+1
N1(t)
N2
(t)
-1 1t
Element basis functions: N1(t), N
2(t)
Need _____ integrals for element mass matrix
7/29/2019 Galerkin Finite Element Methods
http://slidepdf.com/reader/full/galerkin-finite-element-methods 5/9
Lecture26 April 28, 20
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
xi
xi+1
N1
(t)
N2(t)
-1 1t
Element Mass Matrix:
Galerkin Finite Elements
Putting it together, basis function view vs "element view":
N1
(t)
N2
(t)
Element Stiffness Matrix:
N'2(t)
N'1(t)
7/29/2019 Galerkin Finite Element Methods
http://slidepdf.com/reader/full/galerkin-finite-element-methods 6/9
Lecture26 April 28, 20
Galerkin Finite Elements
Putting it together, basis function view vs "element view":
N1
(t)
N2
(t)
Element Force vector:
-1 1t
Galerkin Finite Elements: Matlab
function [Ke,Me] = getElementMatrix(xCoords)
% GETELEMENTMATRIX - returns element matrices for an individual element
%% [Ke,Me] = getElementMatrix(xCoords)
%
% xCoords:- coordinates of 1D element [ xMin xMax ]
% Ke: - element stiffness matrix (assuming linear elements)
% Me: - element mass matrix (assuming linear hat elements)
%
N1 = @(t) (1-t)/2; % linear hat function
N2 = @(t) (1+t)/2;
N1p = @(t) -.5*ones(size(t)); % derivative dN1/dt (not really a function)
N2p = @(t) .5*ones(size(t));
% quadrature points and weights (2-point Gauss-legendre)
tQ = [ -1 1 ]'/sqrt(3);
wQ = [ 1 1 ];
h = xCoords(2)-xCoords(1); %element width
Ke = zeros(2);
Me = Ke;
%stiffness matrix
Ke(1,1) = wQ*(N1p(tQ).*N1p(tQ));
Ke(1,2) = wQ*(N1p(tQ).*N2p(tQ));
Ke(2,1) = Ke(1,2);
Ke(2,2) = wQ*(N2p(tQ).*N2p(tQ));
Ke = Ke*2/h;
%Mass matrix
Me(1,1) = wQ*(N1(tQ).*N1(tQ));
Me(1,2) = wQ*(N1(tQ).*N2(tQ));
Me(2,1) = Me(1,2);
Me(2,2) = wQ*(N2(tQ).*N2(tQ));
Me = Me*h/2;
7/29/2019 Galerkin Finite Element Methods
http://slidepdf.com/reader/full/galerkin-finite-element-methods 7/9
Lecture26 April 28, 20
Galerkin Finite Elements: Matlab
function [fe] = getElementForceVector(func,xCoords)
% getElementForceVector - returns element force vector for an individual element
%
% [fe] = getElementForceVector(func,xCoords)
%% func:-function handle to RHS f(x)
% xCoords:- coordinates of 1D element [ xMin xMax ]
%
% fe: - element force vector
%
h = xCoords(2)-xCoords(1); %element width
N1 = @(t) (1-t)/2; % linear hat function
N2 = @(t) (1+t)/2;x = @(t) xCoords(1) + h*(t + 1)/2; % affine transformation
% quadrature points and weights (2-point Gauss-legendre)
tQ = [ -1 1 ]'/sqrt(3);
wQ = [ 1 1 ];
h = xCoords(2)-xCoords(1); %element width
%Force vector matrixfe(1) = wQ*(func(x(tQ)).*N1(tQ));
fe(2) = wQ*(func(x(tQ)).*N2(tQ));
fe = fe'*h/2;
Galerkin Finite Elements: Global Matrix assembly
0
1
xi-1 x
i+1xi
7/29/2019 Galerkin Finite Element Methods
http://slidepdf.com/reader/full/galerkin-finite-element-methods 8/9
Lecture26 April 28, 20
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
%fix dirichlet boundary conditions
A(1,1:2)=[ 1 0 ];
A(end,end-1:end)=[ 0 1 ];
f([ 1 end ]) = [ alpha ; beta ]';
Galerkin Finite Elements: The future
Linear hats on a line is the simplest problem...but Finite Elements is a very rich subject...
Possible extensions:
1) higher order elements (quadratic, cubic, "spectral", mixed)
2) Higher spatial dimensions: meshing in 2 (and 3-D)
Finite element calculation of viscous fluid flow around a "dolfin"
7/29/2019 Galerkin Finite Element Methods
http://slidepdf.com/reader/full/galerkin-finite-element-methods 9/9
Lecture26 April 28, 20
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, computational science and modeling can be a veryrewarding mix of Mathematics, Computer Science and domain specific
science and engineering.
We've just scratched the surface in this course...but understandingthese building blocks is where you start...the fun is just beginning...