Midterm (Due October 27.) Math. 610:600 (Last modified on 2015-10-16 11:15) The midterm involves developing code to implement a two dimensional finite element approximation. You are to do this assignment individually and are not allowed to discuss this with other members of the class or Wenyu. The procedure involves changing variables mapping the local stiffness integrals on the triangles τ to integrals on the reference element τ̂ . These are then subsequently approximated using a fixed quadrature on the reference element. It is only necessary to compute shape functions (local basis functions) on the reference element. Let τ̂ denote the reference triangle with vertexes (0,0), (1,0) and (0,1). We shall use the quadrature Z 1 g(x) da ≈ g(0, 0) + g(1, 0) + g(0, 1) + 9g(1/3, 1/3) 24 τ̂ := 4 X wl g(x̂l ). l=1 All integrals will be transferred to the reference triangle. Here we have denoted the quadrature points on the reference element by {x̂l }, l = 1, 2, 3, 4. Problem 1. Given a list of (hatx, haty) pairs (the quadrature nodes on τ̂ ) write a routine which computes the reference finite elements shape functions and their gradients at each pair in the list, in the case of linears. Your routine should have MATLAB interface: function [hat_phi,hat_phix,hat_phiy]=FEEVAL(hatx,haty,nq) Here x̂i = (x̂(i), ŷ(i)), i = 1, . . . , nq are pairs and hat phi, hat phix, hat phiy are nq × 3 arrays returning the values for each basis function and point in the list (of the basis function, its x derivative and its y derivative). The list of (hatx, haty) pairs come from the quadrature. Problem 2. Write a routine which given v1 , v2 , v3 computes the transformation matrix B appearing in the affine mapping which takes (0,0) to v1 , (1,0) to v2 and (0,1) to v3 1 2 Problem 3. Set up a routine which reads triangulation data generated by “TRIANGLE” (this was discussed in recitation). Triangle gives the list of global nodes (an ordered list of x-y pairs) and a list of elements (triangles). Each element is identified by three global node indices (the global vertex numbers of the triangle). This information provides the local to global node map. You will have to create appropriate data structure to manage this information (this was discussed in recitation). I have included a poly file for running triangle on the L-shaped domain. The command for building the finest mesh is triangle − a.00001 − e − q30 ell.poly. This results in a mesh with 238074 vertexes and 474127 triangles. The “a” parameter above controls the triangle area, thus, for a mesh of twice the mesh size, one would run a.00004. Generate six meshes starting from a.00001 using increases of 4 until the coarsest grid a.01024 (264 vertexes, 726 edges). These are the meshes which you are to use to report computational results. You can look at the coarser meshes using showme. It is also instructive to run with a.2 and carefully examine the resulting output files ell.1.node and ell.1.ele as the general version of these files will have to be read by your code. Problem 4. After reading the mesh files, you need to assemble the global stiffness matrix and global right hand side. The assembly code should have the same structure as that used for the one dimensional problem and needs to create a sparse matrix. This is easy in MATLAB as it supports sparse matrices. An example on initializing the matrix and subsequently incrementing its entries is given in Wenyu’s 610 page. Note that you should initialize the matrix with space for 9N non-zeros with N being the number elements. The local stiffness matrices are to be approximated by changing variable to the reference domain and applying the quadrature (discussed in class on Oct. 15). Problem 5. Write a routine which generates local right hand side contributions and use these to assemble the right hand side vector. As above, this involves only one loop through the elements and a change a variable so that the computation can be approximated using the quadrature rule on the reference element. Problem 6. Approximate the solution of the problem (6.1) −∆u + 2u = (5π 2 + 2) cos(πx) cos(2πy) ∂u = 0 on ∂Ω. ∂n on Ω, 3 The weak formulation results in a bilinear form as in the Oct. 15 notes with a(x) = 1 and q(x) = 2. Here Ω is still the L-shaped domain described earlier. The solution of the above problem is u(x, y) = cos(πx) cos(2πy). Run your program on mesh files (generated by triangle) using the calls triangle triangle triangle triangle triangle triangle -a.01024 -a.00256 -a.00064 -a.00016 -a.00004 -a.00001 -e -e -e -e -e -e -q30 -q30 -q30 -q30 -q30 -q30 ell.poly. ell.poly. ell.poly. ell.poly. ell.poly. ell.poly. For each of the above meshes, generate the coefficient vector for the interpolant of the solution X X vh = u(xi )φi ≡ c i φi i i where xi is the node associated with the finite element basis function φi (vh is the finite element interpolant of theP solution u). Compute the coefficients of the finite element solution uh = i di φi by solving the matrix vector problem involving the stiffness matrix and the right hand side (computed above). Report (for each mesh) kuh − vh k = ((M (c − d)) · (c − d))1/2 . Here k · k denotes the L2 (Ω) norm and M is the mass matrix, i.e., Z φj φi dx. Mij = Ω The mass matrix (in sparse form) can be assembled using your stiffness matrix assembly code and setting a(x) = 0 and q(x) = 1. For one of the meshes, plot the solution and approximate solution (separate graphs) and turn copies of the figures. Here are some hints on debugging your code. You should check your matrix assembly routines on a simple mesh. I have included the node and ele files for a simple triangulation of the unit square. For the first element of this mesh, the local stiffness matrix for the Laplacian is: 1 −1 0 1 −1 2 −1 . 2 0 −1 1 4 Here the second unknown corresponds to the dof at the right angle. The other local stiffness matrices are similar. The local mass matrix is given by 2 1 1 1 1 2 1 . 96 1 1 2 (You should compute the above matrices by hand as an exercise). After building your 2-d elements, verify that your local stiffness matrix is creating the correct results in the above cases.