TMA4220 Numerical Solution of Partial Differential Equations Using Element Methods Høst 2014

Similar documents
Lehrstuhl Informatik V. Lehrstuhl Informatik V. 1. solve weak form of PDE to reduce regularity properties. Lehrstuhl Informatik V

Scientific Computing I

Chapter 1: The Finite Element Method

A brief introduction to finite element methods

Simple Examples on Rectangular Domains

1. Let a(x) > 0, and assume that u and u h are the solutions of the Dirichlet problem:

TMA4220: Programming project - part 1

[2] (a) Develop and describe the piecewise linear Galerkin finite element approximation of,

WRT in 2D: Poisson Example

The Finite Element Method for the Wave Equation

(f P Ω hf) vdx = 0 for all v V h, if and only if Ω (f P hf) φ i dx = 0, for i = 0, 1,..., n, where {φ i } V h is set of hat functions.

Finite Element Method for Ordinary Differential Equations

1. Differential Equations (ODE and PDE)

Chapter Two: Numerical Methods for Elliptic PDEs. 1 Finite Difference Methods for Elliptic PDEs

Lecture 1. Finite difference and finite element methods. Partial differential equations (PDEs) Solving the heat equation numerically

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

1 Discretizing BVP with Finite Element Methods.

Time-dependent variational forms

One-dimensional and nonlinear problems

Numerical Simulation of Potential Flow using the Finite Element Method

Numerical Solutions to Partial Differential Equations

Discretization Methods Exercise # 5

LECTURE # 0 BASIC NOTATIONS AND CONCEPTS IN THE THEORY OF PARTIAL DIFFERENTIAL EQUATIONS (PDES)

Scientific Computing WS 2018/2019. Lecture 15. Jürgen Fuhrmann Lecture 15 Slide 1

Finite Difference Methods for Boundary Value Problems

AMS 529: Finite Element Methods: Fundamentals, Applications, and New Trends

Numerical Solutions to Partial Differential Equations

Implementation of the dg method

Finite Element Methods

LibMesh Experience and Usage

Finite Elements for Nonlinear Problems

A Finite Element Primer

A Fast Fourier transform based direct solver for the Helmholtz problem. AANMPDE 2017 Palaiochora, Crete, Oct 2, 2017

A very short introduction to the Finite Element Method

Scientific Computing: Numerical Integration

A simple FEM solver and its data parallelism

LibMesh Experience and Usage

Higher-Order Compact Finite Element Method

PIECEWISE LINEAR FINITE ELEMENT METHODS ARE NOT LOCALIZED

are continuous). Then we also know that the above function g is continuously differentiable on [a, b]. For that purpose, we will first show that

HIGHER-ORDER THEORIES

Domain Decomposition Preconditioners for Spectral Nédélec Elements in Two and Three Dimensions

you expect to encounter difficulties when trying to solve A x = b? 4. A composite quadrature rule has error associated with it in the following form

Iterative Methods for Linear Systems

Numerical methods for PDEs FEM convergence, error estimates, piecewise polynomials

Class notes: Approximation

Chapter 7: Bounded Operators in Hilbert Spaces

Scientific Computing WS 2017/2018. Lecture 18. Jürgen Fuhrmann Lecture 18 Slide 1

There are five problems. Solve four of the five problems. Each problem is worth 25 points. A sheet of convenient formulae is provided.

An Introduction to Algebraic Multigrid (AMG) Algorithms Derrick Cerwinsky and Craig C. Douglas 1/84

PREPRINT 2010:23. A nonconforming rotated Q 1 approximation on tetrahedra PETER HANSBO

TD 1: Hilbert Spaces and Applications

Chapter 1 Piecewise Polynomial Approximation in 1D

Numerical Methods for Partial Differential Equations

Contents. Prologue Introduction. Classical Approximation... 19

MAE 107 Homework 7 Solutions

ACM/CMS 107 Linear Analysis & Applications Fall 2017 Assignment 2: PDEs and Finite Element Methods Due: 7th November 2017

Nonlinear, Transient Conduction Heat Transfer Using A Discontinuous Galerkin Hierarchical Finite Element Method

Applied Math Qualifying Exam 11 October Instructions: Work 2 out of 3 problems in each of the 3 parts for a total of 6 problems.

Boundary Value Problems and Iterative Methods for Linear Systems

Some Notes on Elliptic Regularity

WELL POSEDNESS OF PROBLEMS I

Optimal multilevel preconditioning of strongly anisotropic problems.part II: non-conforming FEM. p. 1/36

Lecture 9 Approximations of Laplace s Equation, Finite Element Method. Mathématiques appliquées (MATH0504-1) B. Dewals, C.

Schwarz Preconditioner for the Stochastic Finite Element Method

Spline Element Method for Partial Differential Equations

The Spectral-Element Method: Introduction

Algorithms for Scientific Computing

Lecture 10 Polynomial interpolation

2 Elliptic Differential Equations

Wavelets in Scattering Calculations

Solving the steady state diffusion equation with uncertainty Final Presentation

Strauss PDEs 2e: Section Exercise 2 Page 1 of 6. Solve the completely inhomogeneous diffusion problem on the half-line

Mathematical methods for engineering. The finite element method

Parallel Discontinuous Galerkin Method

Xingye Yue. Soochow University, Suzhou, China.

Small zeros of hermitian forms over quaternion algebras. Lenny Fukshansky Claremont McKenna College & IHES (joint work with W. K.

44 CHAPTER 3. CAVITY SCATTERING

Partial Differential Equations

Chapter 12. Partial di erential equations Di erential operators in R n. The gradient and Jacobian. Divergence and rotation

SINC PACK, and Separation of Variables

Solution to Set 7, Math 2568

Finite Element Analysis Prof. Dr. B. N. Rao Department of Civil Engineering Indian Institute of Technology, Madras. Module - 01 Lecture - 11

Continuous and Discontinuous Finite Element Methods for a Peridynamics Model of Mechanics DRAFT

Variational Formulation of Plane Beam Element

arxiv: v1 [math.na] 1 May 2013

Computational Methods for Engineering Applications II. Homework Problem Sheet 4

Introduction to PDEs: Assignment 9: Finite elements in 1D

MATH 333: Partial Differential Equations

Finite Difference and Finite Element Methods

Chapter 5 A priori error estimates for nonconforming finite element approximations 5.1 Strang s first lemma

Ritz Method. Introductory Course on Multiphysics Modelling

Recovery Techniques in Finite Element Methods

Outline. 1 Boundary Value Problems. 2 Numerical Methods for BVPs. Boundary Value Problems Numerical Methods for BVPs

An additive average Schwarz method for the plate bending problem

Numerical Solutions to Partial Differential Equations

Introduction to Spectral Element Methods

System of Linear Equations

Lecture Notes: African Institute of Mathematics Senegal, January Topic Title: A short introduction to numerical methods for elliptic PDEs

Qualifying Examination

Transcription:

Norwegian University of Science and Technology Department of Mathematical Sciences TMA422 Numerical Solution of Partial Differential Equations Using Element Methods Høst 214 Exercise set 2 1 Consider the equation u xx = f(x), < x < 1, u() =, u(1) =, which is solved with the finite element method with equidistant grid (x i = ih, h = 1/N), and the basis functions x x i 1 h, for x i 1 x x i, x ϕ i (x) = i+1 x h for x i x x i+1, otherwise. for i = 1,2,...,N 1. Denote the numerical solution u N. In Exercise 1.3, you solved this equation with f(x) = x 4. You may have noticed that the numerical and exact solution coincide on the gridpoints, that is u(x i ) = u N (x i ), for i =,1,2,...,N. In this problem, we are to show that this is true for all f(x). For i = and i = N, there is nothing to prove (Why?), what remains is i = 1,2,...,N 1. a) Prove that a(u u h,ϕ i ) = for i = 1,2,...,N 1. Solution: Let V h = span{ϕ 1,ϕ 2,...,ϕ N 1 } V = H 1 ([,1]). Then the numerical solution satisfies a(u h,v h ) = f(v h ) v V h, while the exact solution satisfies ϕ i V h V, so a(u,v) = f(v) v V. a(u u h,ϕ i ) = a(u,ϕ i ) a(u h,ϕ i ) a bilinear. = f(ϕ i ) f(ϕ i ) u and u h solves the wea problems. =. b) Prove that for all v H 1 ([,1]) C ([,1]) and i = 1,2...,N 1, a(v,ϕ i ) = 1 h (2v(x i) v(x i 1 ) v(x i+1 )). September 1, 214 Page 1 of 7

Solution: a(v,ϕ i ) = v x ϕ i. 1 ϕ h, for x i 1 < x < x i, i = 1 h, for x i < x < x i+1,, otherwise. a(v,ϕ i ) = xi x i 1 v x h xi+1 x i v x h c) The M M matrix = 1 h (v(x i) v(x i 1 ) (v(x i+1 ) v(x i ))) = 1 h (2v(x i) v(x i 1 ) v(x i+1 )). 2 1. A = 1 2........ 1 1 2 is invertible for all M. Use this fact and the results of a) and b) to prove that u(x i ) u N (x i ) = for i = 1,2...,N 1. Solution: Combining the results of a) and b), we see that v i = u(x i ) u N (x i ) satisfies v i 1 +2v i v i+1 = for i = 1,2,...,N 1. Removing v and v N, (which are equal to zero) this is equivalent to Av = where A is as above and v = [v 1 v 2...v N 1 ]. Since A is invertible, Av = v =. 2 Given the Helmholtz problem u xx +σu = f on (,1), u() = u(1) =. where σ > is a constant. Set up the wea form for this problem. Show that, when this problem is solved by a Galerin method, using V h = span {φ i } N i=1, the discrete problem can be written as (A+σM)u = f. Set up the matrix M for V h = Xh 1 on a uniform grid. Solution: Multiply by the equation by a test function v, integrate over the domain September 1, 214 Page 2 of 7

(,1), use partial integration and get rid of the boundary terms by require v() = v(1) =. The the wea formualtion becomes: Find u H 1 (Ω) such that v x u x +σ uv = fv, v H 1 (,1). Choose V h = span{ϕ 1,ϕ 2,...,ϕ N }, let our unnown approximation be written as u h (x) = where the coefficients u j is found from u j ϕ j (x), ( dϕj ) dϕ i +σ (ϕ j ϕ i ) = (f ϕ i ), i = 1,2,,N. This is a linear system of equations Au+σMu = f where (A i,j = ( dϕj ) dϕ i, M i,j = (ϕ j ϕ i ) and f i = (fϕ i ). Let V h = X 1 h on a uniform grid, so that h = 1/N and x i = ih, i =,1,...,N. ϕ i 1 ϕ i ϕ i+1 h h h h x i 2 x i 1 x i x i+1 x i+2 The non-zeros elements of the stiffness matrix A and the mass matrix M is xi+1 ( ) dϕi A i,i = = 2 xi+1 h, A dϕ i i,i+1 = = 1 h = A i+1,i M i,i = x i 1 xi+1 x i 1 ϕ 2 i = 2 3 h, M i,i+1 = dϕ i+1 x i xi+1 x i ϕ i+1 ϕ i = 1 6 h = M i+1,i. All the other elements are. So 4 1 M = h 1 4 1. 6 1 4........ 1 1 4 R (N 1) (N 1). September 1, 214 Page 3 of 7

3 Write a MATLAB program for solving the Helmholtz problem u xx +σu = f(x), < x < 1, u() = u(1) =. or, using the wea formulation find u H 1 (,1) s.t. u x v x +σ uv = fv, for all v H 1 (,1) (1) by the finite element method on Xh 2, using the algorithm outlined in the supplementary note. To test your code, let σ = 1, f = sin(πx) in which case u(x) = sin(πx)/(1+π 2 ). Use for example [,.1,.25,.3,.4,.45,.5,.55,.6,.7,.8,.9,1] for the partition of the elements. As already pointed out in exercise 2, the discrete problem can be written as (A+σM)u = b. (2) So the tas is to set up the matrices A and M and the load vector b, and solve the system. What you have to do is described in the following: a) Preliminaries: Set up the element matrices A K h and MK h, corresponding to contribution from element K to the first and second integrals of (1) resp. Solution: Starting from the very beginning: The quadratic shape functions defined on the reference element ˆK = (,1), corresponding to the nodes x 1 =, x 2 = 1/2 and x 3 = 1 is given by ψ 1 (ξ) = 2(ξ 1 2 )(ξ 1), ψ 2(x) = 4ξ(ξ 1), ψ 3 (x) = 2ξ(ξ 1 2 ). The mapping from the ˆK to K = (,+1 ) is given by x(ξ) = + h ξ and the inverse mapping is ξ(x) = (x )/h, where h = +1. A K h = 1 7 8 1 8 16 8, Mh K 3h = h 4 2 1 2 16 2 3 1 8 7 1 2 4 So the contribution from element K to the element matrices Mh K and AK h becomes: (M K h ) α,β = (A K h ) α,β = x+1 x+1 ϕ K α (x)ϕ K β (x) = h dϕ K α ψ α (ξ)ψ β (ξ)dξ dϕ K β = 1 ψ α dψ β h dξ dξ dξ se the slides on the webpage for details. Altogether, we ends up with: A K h = 1 7 8 1 8 16 8, Mh K 3h = h 4 2 1 2 16 2 3 1 8 7 1 2 4 September 1, 214 Page 4 of 7

b) Write a function computing integrals by the following quadrature formula: g(x) 1 2 (g(c 1)+g(c 2 )), c 1,2 = 1 2 ± 3 6. This will be used for to approximate the contribution from an element to the load vector. Solution: On an element, the approximation becomes x+1 g(x) g( +c 1 h )+g( +c 2 h ) 2 But the contributions to the load vector is +1 b K i = x+1 The corresponding function can be ϕ i (x)f(x) φ i (x)f(x), so that 2 ψ i (c j )f( +c j ). function b = b(f,x) % Calculate a numerical approximation to the elemental load vector % of the function f on an element [x(1),x(2)]. % using quadratic elements. h = x(2)-x(1); c1 = 1/2-sqrt(3)/6; c2 = 1/2+sqrt(3)/6; b = h*[(c1-.5)*(c1-1)*f(x(1)+h*c1) + (c2-.5)*(c2-1)*f(x(1)+h*c2);... 2*c1*(1-c1)*f(x(1)+h*c1) + 2*c2*(1-c2)*f(x(1)+h*c2); c1*(c1-.5)*f(x(1)+h*c1)+c2*(c2-.5)*f(x(1)+h*c2)]; c) Assemble the prototype matrices Ãh and M h as well as the load vector b.. Solution: For points b)-e), see Figure 1. d) Remove the rows and columns corresponding to the boundary conditions. e) Solve (2), and plot the solution. f) Change the boundary conditions to u() = 1 and u x (1) = 2. Which changes has to be done in the code? Solution: The wea formulation of the Helmholtz problem is now find u V s.t. u x v x +σ uv = fv R g,x v x +2v(1), for all v V where v = {v H 1 (,1) : v() = } and R g H 1 (,1) is some function satisfying R g () = 1. For the numerical solution, we choose R g = ϕ (x). The correpsonding discrete formulation is u j ϕ j,x ϕ i,x +σ u j ϕ j ϕ i = j= fϕ i ϕ i,x ϕ,x + 2φ i (1) for i = 1,2,,N. In practice, this means that the column corresponding to the left hand side Dirichlet condition is moved to the right hand side. In addition, we add one term in the last equation, to include the contribution from the Neumann boundary conditions. Line 31-41 in Figure 1 has to be changed to September 1, 214 Page 5 of 7

f = @(x) sin(pi*x); sigma = 1; % The partition of [,1]. x = [,.1,.25,.3,.4,.45,.5,.55,.6,.7,.8,.9,1]; A = [7/3, -8/3, 1/3; % Element stiffness matrix -8/3, 16/3, -8/3; 1/3, -8/3, 7/3]; M = [2/15, 1/15, -1/3; % Element mass matrix 1/15, 8/15, 1/15; -1/3, 1/15, 2/15]; N = length(x)-1; % Number of elements. N = 2*N+1; % Number of nodes (including the boundaries) theta = @(,alpha) 2*(-1)+alpha; % local-to-global mapping. Ah = sparse(n,n); Mh = sparse(n,n); bh = zeros(n,1); % Stiffness matrix % Mass matrix resp. % Load vector % Assemble process: for = 1:N h = x(+1)-x(); % Size of the element gi = theta(,1):theta(,1)+2; Ah(gi,gi) = Ah(gi,gi) + A/h; Mh(gi,gi) = Mh(gi,gi) + M*h; bh(gi) = bh(gi) + b(f,[x(),x(+1)]); end % For the case u()=u(1)= % Remove contributions concerning the Dirichlet boundaries. A = Ah(2:end-1,2:end-1); M = Mh(2:end-1,2:end-1); b = bh(2:end-1); % Solve the system u = (A+sigma*M)\b; % Include the boundaries. u = [;u;]; % For the plot: Create a x-vector with all the nodes % including the midpoints of each element. xi = x(1); for =1:N xi = [xi;x()+(x(+1)-x())/2; x(+1)]; end % Plot the numerical and the exact solution in the nodes. u_exact = sin(pi*xi)/(1+pi^2); plot(xi,u_exact, r,xi,u, b ) legend( u_exact, u_h ); Figure 1: Code for solving the Helmholtz equation in 1D by a quadratic FEM September 1, 214 Page 6 of 7

% For the case u()=1, u_x(1)=2. bh = bh - Ah(:,1)*1; bh(end) = bh(end)+2; A = Ah(2:end,2:end); M = Mh(2:end,2:end); b = bh(2:end); % Solve the system u = (A+sigma*M)\b; % Include the Dirichlet boundary. u = [1;u;]; September 1, 214 Page 7 of 7