Math 610 Computing Assignment 2 Spencer Patty February 16, 2016 1 Exercise 1: Mass Matrix and L2 Projection on Square Domain (34%) Let Ω = [0, 1]2 and u(x) = xy sin(πx) cos(πy). Your task is to construct a function that does the L2 (Ω)projection of u(x) into your finite element space P1 (Th ) function U = L2_projection(u, T, fe_degree, quad_degree) that takes a function, u(x), a triangulation, T , a finite element degree and a quadrature degree (use the same quadrature as in Lab 01 which for your convenience is defined below in problem 3 again) and returns the coefficient vector of the L2 projection of u(x). In this function, you must construct the linear system MU = F where (1) Z Mij = Θj (x)Θi (x)dx Ω is the mass matrix and Z Fj = Θj (x)u(x)dx Ω the right hand side. We recall that U is the vector of coefficients for the global linear basis functions Θi . Note that you will construct the mass matrix and right hand side as you loop through the elements and add the local contributions into the global matrix and right hand side. Use a sparse data format in matlab (see spalloc or sparse functions in Matlab) to store the matrix and consider preallocating space for speed. The local linear basis functions on T are φi for i = 1, . . . , 3 and so the local contributions can be computed on the reference element as Z Z cell matrixij = φj (x)φi (x)dx = φ̂j (x̂)φ̂i (x̂)| det J|dx̂ (2) T T̂ where 1 ≤ i, j ≤ 3 and Z cell rhsj = Z φj (x)f (x)dx = T φ̂j (x̂)fˆ(x̂)| det J|dx̂. (3) T̂ Of course you will do the computations using a quadrature rule as in Lab 01. Notice that on element k, we can extract the global dofs and distribute the local contributions to the global matrix and rhs using the following Matlab commands: dof_indices = T.elements{k,:}; M(dof_indices, dof_indices) = M(dof_indices, dof_indices) + cell_matrix; F(dof_indices,1) = F(dof_indices,1) + cell_rhs; Once M and F are assembled, we can solve the linear system using the Matlab backslash operator 1 U = M\F; which is exactly what your matlab function should return. Construct a sequence of triangulations of Ω, defined above, using Triangle with area constraints corresponding to h = 1/8, 1/16, 1/32, 1/64. Construct your L2 projections uh = Πh u. Plot your solution uh and calculate the L2 (Ω) error analysis as in Lab 1. Construct the table of convergence rates. Note that the theory says that for u ∈ H r (Ω), ku − Πh ukL2 (Ω) ≤ chr+1 |u|H r (Ω) where Πh projects onto Pr (Th ). In our case, r = 1 and so for u ∈ H 2 (Ω), we should see a convergence rate of O(h2 ). 2 Exercise 2: Mass Matrix and L2 Projection on L-shaped Domain (33%) Repeat Exercise 1 with the L-Shaped domain Ω = [−1, 1]2 \(−1, 0)2 and u(x) = ex 3 2 +y 2 cos(2πx) cos(2πy). Exercise 3: Mass Matrix and L2 Projection with a Poor Quadrature Rule (33%) Repeat Exercise 1 with the one point quadrature rule exact for linear functions (defined on reference element). The first order rule is given by wq = 1 and xq = (1/3, 1/3), the barycenter of the reference element. In other words, Z 1 1 1 , . ĝ(x̂)dx̂ ≈ |T̂ |wq ĝ (xq ) = ĝ 2 3 3 T̂ You only need to provide the convergence tables, not the plots. What convergence rate do we see in this case? Compare to the results of problem 1. Recall that your quadrature rule from problem 1 (introduced in Lab 1) is a three point rule which is exact for quadratic functions: Z 3 X ĝ(x̂)dx̂ = |T̂ | wq ĝ(xq , yq ) T̂ q=1 where q 1 2 3 wq 0.333333333333333 0.333333333333333 0.333333333333333 xq 0.166666666666667 0.166666666666667 0.666666666666666 2 yq 0.166666666666667 0.666666666666666 0.166666666666667 (4) 4 Optional Exercise 4: Mass Matrix and L2 Projection with an Unnecessarily Good Quadrature Rule (For your own betterment) Repeat Excersize 1 with the 7-point quadrature rule which is exact for polynomials of degree 5, defined by Z ĝ(x̂)dx̂ = |T̂ | T̂ 7 X wq ĝ(xq , yq ) q=1 where q 1 2 3 4 5 6 7 wq 0.225000000000000 0.125939180544827 0.125939180544827 0.125939180544827 0.132394152788506 0.132394152788506 0.132394152788506 xq 0.333333333333333 0.797426985353087 0.101286507323456 0.101286507323456 0.059715871789770 0.470142064105115 0.470142064105115 yq 0.333333333333333 0.101286507323456 0.797426985353087 0.101286507323456 0.470142064105115 0.059715871789770 0.470142064105115 (5) Does it improve the convergence rates to use a quadrature rule that is of 5th order? Now compare the actual values of error, does it help at all? It turns out we only need a quadrature rule that is as good as the order our theory predicts we should get out, any less and our system might be underdetermined and any more and we are overkill. We will study this later once we have introduced you to the Bramble-Hilbert Lemma and Strang’s Lemmas. 3