Math 610 Computing Assignment 1 1 Exercise 1: Triangulation (25%) Spencer Patty

advertisement
Math 610 Computing Assignment 1
Spencer Patty
February 4, 2016
1
Exercise 1: Triangulation (25%)
Implement a sequence of triangulations for the box with hole shape with opposite outside corners at (−1, −1)
and (1, 1) and opposite inside corners at (−0.5, −0.5) and (0.5, 0.5). You will create the boxwithholes.poly file
describing this shape and then use the Triangle program (http://www.cs.cmu.edu/~quake/triangle.html)
to generate 4 meshes with the maximum area constraint of each mesh defined by our mesh size h as a ≤ 21 h2
for h = 1/2, 1/4, 1/8, 1/16. You will generate the first mesh with the standard flags −pq25ea where is
the decimal value of the area constraint as defined above. For example
> triangle -pq25ea0.1 boxwithhole.poly
This will generate the boxwithhole.1.poly (and .node, .ele, .edge) files. The subsequent meshes will be
generated from the previous ones using the refinement flags −rq25ea . For example to generate the second
mesh with an area constrian of 0.05, I would write
> triangle -rq25ea0.05 boxwithhole.1
and it would generate boxwithhole.2.poly (and .node, .ele, .edge) files. Create all four meshes according to
the h values above.
Import these meshes into matlab using the provided TriangleReader.m file (located on Spencer Patty’s
math 610 lab website) and plot the elements. See the ExampleTriangleReader.m file for help with how to
plot the elements. Turn in a picture of each mesh with the title of each plot describing the mesh size h = .
2
Exercise 2: Lagrange Interpolation (25%)
Plot the linear Lagrange interpolant Ih u(x) of the following functions on each of your four meshes above:
(i) u(x) = |x − y|
(ii) u(x) = sin(π(x + y))
(
1, x ≥ 0
(iii) u(x) =
0, otherwise
on the first and third meshes from above. (6 plots total).
Note that you do not need a global formula for the interpolant, but can plot and do operations on the
interpolant element by element. The best way to construct it is element by element. Loop through the
cells and locally on each cell, describe the three linear (nodal) basis elements on the cell and evaluate the
function at the three (nodal) degrees of freedom on the cell. Recall that there are three linear nodal bases
φi (x) i = 1, . . . , 3 corresponding to the three vertices xi of the triangle. Where φi (x) = ai + bi x + ci y and
φi (xj ) = δij for i, j = 1, . . . , 3. Where δij is the standard kronecker delta function δij = 0 if i 6= j and = 1 if
i = j.
You should loop through each element and locally define the linear interpolants. Then you can plot them
or do some other operation to them as in exercise 3.
1
3
Exercise 3: Error Analysis of Lagrange Interpolation (50%)
Defining Ω to be the box with hole domain, compute the L2 error ku − Ih ukL2 (Ω) on each of the four
triangulations for each of the above functions and each of the triangulations.
The integrals will be evaluated using a second order accurate gauss-quadrature scheme on each cell as
follows. Let T̂ denote the reference triangle with vertices x̂1 = (0, 0), x̂2 = (0, 1) and x̂3 = (1, 0), with x̂ the
coordinate on the reference triangle. Let T denote the current cell we are working with in real space with
vertices x1 , x2 and x3 . Given some function f (x) which we want to integrate on T , we will map it to the
reference element and numerically evaluate the integral on T̂ as
Z
1 1
1
2 1
1
1 2
1
,
+ ĝ
,
+ ĝ
,
ĝ(x̂)dx̂ ≈ ĝ
6
6 6
6
3 6
6
6 3
T̂
Notice, that ĝ is any function defined on T̂ . We map our integral from T to T̂ using
Z
Z
f (x)dx =
fˆ(x̂)| det(B)|dx̂
T
where
x=
x
y
=
x1
y1
T̂
+
x2 − x1
y2 − y1
x3 − x1
y3 − y1
s
t
= x̂1 + B x̂
and
fˆ(x̂) := f (x1 + B x̂).
Notice that the linear basis function are easily defined on the reference element as φ̂1 = 1 − s − t, φ̂2 = s,
and φ̂3 = t.
Compute the L2 norm squared of u − Ih u on each cell and add them all up, then take the square root of
the sum of terms and you have eh = ku − Ih ukL2 (Ω) . The error rate can then be computed as h gets smaller
for each function.
We can prove theorems about how eh behaves as h → 0 for some function u with a certain type of
smoothness and we can then verify that numerically. If we say eh = chα for some c and α, we can compute
the α experimentally. Given eh1 and eh2 with h2 6= h1 , (say h2 = h21 ) then the rate of convergence α between
h1 and h2 can be computed as
α2,1 :=
log (eh1 /eh2 )
log (h1 /h2 )
Compute a table for each function, u(x), above displaying
step
1
2
3
4
h
h1
h2
h3
h4
ku − Ih ukL2 (Ω)
e1
e2
e3
e4
rate
0
α2,1
α3,2
α4,3
where you have computed ei and αi,i−1 as described above. What do your results tell you about the
smoothness of the function u? What do you think would happen if we used quadratic basis elements instead
of just linear ones?
2
Download