You are on page 1of 22

A SURVEY ON THE MIXED FINITE

ELEMENT METHOD

David Sacco
Oklahoma State University

December 9, 2016
Abstract
In this paper, we investigate a MATLAB implementation of a mixed
finite element method by Carstenson and Bahriawati. We investigate
specifically the method and organization of data structures. Theoretical
estimates on the solution and auxiliary function σ are considered, as well
as a numerical simulation with the MATLAB implementation demonstrat-
ing the error estimates.

Contents
1 Introduction 2
1.1 Relevant Sobolev Spaces . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Problem Formulation . . . . . . . . . . . . . . . . . . . . . . . . . 3

2 Approximation Spaces 4
2.0.1 Discrete Formulation . . . . . . . . . . . . . . . . . . . . . 5
2.1 Prerequisite Results . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2 Error Estimates . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

3 The Matrix Equation 9


3.1 The Linear System . . . . . . . . . . . . . . . . . . . . . . . . . . 9

4 Implementation 10
4.1 nodes2element . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.1.1 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.2 nodes2edge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.3 edge2element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.3.1 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

5 Assembly of Matrix Equation 14


5.1 Local Stiffness Matrix . . . . . . . . . . . . . . . . . . . . . . . . 15
5.2 Global Stiffness Matrix . . . . . . . . . . . . . . . . . . . . . . . . 16
5.3 Right Hand Side Assembly . . . . . . . . . . . . . . . . . . . . . 16
5.3.1 The Forcing Term . . . . . . . . . . . . . . . . . . . . . . 16
5.3.2 Dirichlet Boundary Condition . . . . . . . . . . . . . . . . 17

6 Numerical Example 17

7 Conclusion 18

8 Appendix 20

1 Introduction
In this paper, we examine the structure of a fast MATLAB implementation
of a Mixed Finite Element Method. Rather than just including the code pieces,
we give explanations as to why the code works, and how it interacts with the
convenience of MATLAB’s syntax. This paper should give the reader a better
understanding of this implementation of the algorithm. Theoretical results are
also presented, for error estimates concerning the exact solutions.

2
The implementation we are interested in examining uses the lowest order
Raviart-Thomas approximation space, RT0 . We use this space to approximate
the auxiliary function σ, that is introduced when creation of the weak formula-
tion of the mixed finite element method. In section 1, we introduce the problem
formulation for our problem, in section 2 we introduce the approximation spaces
needed to write the matrix equation, which is discussed in section 3, then in
section 4 and 5 we describe the assembly of the algorithm to solve the problem
numerically in MATLAB.
We also utilize the public project iF EM in order to triangulate the domain.
Using this package, we are also able to flag which elements are boundary ele-
ments. iF EM package can be found at
http : //www.math.uci.edu/ chenlong/programming.html.

1.1 Relevant Sobolev Spaces


We will use the following spaces:
( 
H(div; Ω) = p ∈ L2 (Ω) : ∇ · p ∈ L2 (Ω)

H01 (Ω) = u ∈ H 1 (Ω) : u|∂Ω = 0
1
With norms kpkH(div) = (kpk20 + k∇ · pk20 ) 2 , and
1
kuk1 = (kuk20 + +k∇uk20 ) 2 . Here, we denote k · k0 to be the norm of L2 (Ω).

1.2 Problem Formulation


Let Ω be a bounded Lipschitz domain with outer unit normal ν on the polygo-
nal boundary ∂Ω. Suppose that f ∈ L2 (Ω) is given. We consider the following
model problem

(
−∆u = f in Ω
(1)
u = 0 on ∂Ω
The solution u to (1) satisfies the estimate

kuk2 ≤ Ckf k0 (2)

By introducing a new variable, σ ∈ L2 (Ω)2 , we transform the above second-


order equation into an equation of first order.

∇ · σ = f in Ω

σ = −∇u in Ω (3)

u = 0 on ∂Ω

Now, after multiplying equation (3) by test function q ∈ H(div; Ω) and


v ∈ L2 (Ω) respectively, then integrating and applying Integration by Parts, we
obtain the following variational formulation for the mixed finite element method:

3
For given f ∈ L2 (Ω), find σ ∈ H(div; Ω) and u ∈ L2 (Ω) such that
Z Z
σ · q dx + u∇ · q dx = 0 ∀q ∈ H(div; Ω)

ZΩ Z
v∇ · σ dx = vf dx ∀v ∈ L2 (Ω)
Ω Ω

A unique solution exists to this formulation and has been established, and can
be found in Brenner and Scott [2].

2 Approximation Spaces
Let Ω be a polygonal domain and Th be a quasi-uniform triangulation of Ω. For
each T ∈ T , we let hT = diam(T ), so that h = max { diam(T ) : T ∈ Th }. Th is
said to be quasi uniform if there exists ρ > 0 such that
min{diam(BT ) : T ∈ Th } ≥ ρhdiam(Ω), where BT is the largest ball contained
2
in
R T . Define the inner product by the standard L inner product, (f, g) =
s

f g dx, and kf ks for nonnegative s to be the norm in H (Ω), lastly, | · |s
denotes the s-seminorm on H s .
We need subspaces of H(div; Ω) and L2 (Ω) in order to approximate functions
in their respective spaces. For the approximation space for L2 (Ω), we use

Qh = { q ∈ L2 (Ω) : q|T ∈ P0 (T ), for each T ∈ Th }


where P0 (T ) is the set of constant polynomials. We let Ph : L2 (Ω) → Qh define
the local L2 projection. Ph onto Qh satisfies the estimate

kv − Ph vk0,T ≤ Ch|v|1,T (4)

for all v ∈ H 1 (T ). Also,


(v − Ph v, qh ) =0 (5)
for all qh ∈ Qh (T ).
The above, using Cauchy Schwarz implies that

kPh vk0 ≤ kvk0 (6)

In order to approximate H(div; Ω), we use the lowest order Raviart-Thomas


subspace,

RT0 (T ) = {p ∈ L2 (T )| for all T, x ∈ T there is a ∈ R2 and b ∈ R, p(x) = a + bx,


and for all E ∈ EΩ , [p]E · νE = 0}

Here, EΩ is the set of all interior edges, and [p]E = p|T+ − p|T− is the jump of p
across the edge E = T+ ∩ T− , which is shared by the two neighboring triangles
T+ and T− in T (as seen in section 3.2). We will see an explicit form of the basis
in 3.1, but note that the basis elements ψE (x) have the following properties.
First, we define νE to be the outward pointing normal of an edge of T at the
midpoint of E. We have

( (
1 along E ± |T|E|
±|
on T±
ψE · νE = , ∇ · ψE =
0 elsewhere 0 elsewhere

4
We consider ψ to be a basis that is vector based, so that when one dot
products it with the outward normal vector of E, it holds the value of either 0
or 1, whereas in a polynomial basis, basis values are 0 or 1 at only points along
the edges. For this reason, we sometimes call these basis functions edge based.
Further, let Πh : H(div; Ω) → RT0 define the Raviart-Thomas projection
operator [3]. Then Πh satisfies the following commuting diagram property,

∇ · Πh q = Ph ∇ · q (7)

for all q ∈ H(div; Ω). Also, it satisfies

kq − Πh qk0,T ≤ Ch|q|1,T (8)

2.0.1 Discrete Formulation


The discrete problem is: Find uh ∈ Qh (T ), and σh ∈ RT0 such that

Z Z
σh · qh dx + uh ∇ · qh dx = 0 ∀qh ∈ RT0

ZΩ Z
vh ∇ · σh dx = vh f dx ∀vh ∈ Qh (T )
Ω Ω

Next, in order to rewrite this into a linear system, we will utilize the fact that
we have a basis for each of the approximation spaces being used.

2.1 Prerequisite Results


We introduce some other results that will be used to prove the error estimates.
Solutions that have the superscript denoted with an G are the approximate
solution from the Galerkin Method, where solutions with the superscript m are
the approximate solution from the mixed method.
From the mixed formulation, the pair (u−um m
h , σ −σh ) satisfies the following
error equations

(σ − σhm , qh ) − (∇qh , u − um

h ) =0 (9)
(∇ · (σ − σhm ), vh ) = 0
for all (vh , qh ) ∈ Qh (T ) × RT0 (T ).
From the Galerkin Method the variational formulation is: Find u ∈ H01 (Ω)
such that
(∇u, ∇v) = (f, v), ∀v ∈ H01 (Ω)
To approximate the solution of the above equation, let Vh be the space of piece-
wise continuous linear functions on Th . We define the approximation uG h of u
by
(∇uGh , ∇vh ) = (f, vh ), ∀vh ∈ Vh

Then,
(∇(u − uG
h , ∇vh ) = 0, ∀vh ∈ Vh

with the error estimates

ku − uG G 2
h k1 ≤ Chkuk2 and ku − uh k0 ≤ Ch kuk2 (10)

5
2.2 Error Estimates
We now are ready to prove the following main theorems, which leads us to the
solution estimates for u and σ. [4]
Theorem 1 Let Ω be a polygonal domain, and Ph be the local L2 projection.
Then,

kPh (uG m m m G

h − uh )k0 ≤ C hk(σ − σh )k0 + hk∇ · (σ − σh )k0 + ku − uh k0

Proof.
We use (5) along with the Cauchy-Schwarz inequality. We then have

kPh (uG m 2 G m G m
h − uh )k0 = (Ph (uh − uh ), Ph (uh − uh ))

= (Ph (uG G m m G m
h − u), Ph (uh − uh )) + (Ph (u − uh ), Ph (uh − uh ))

= (uG G m m G m
h − u, Ph (uh − uh )) + (u − uh , Ph (uh − uh ))

≤ kuG G m m G m
h − uk0 kPh (uh − uh )k0 + (u − uh , Ph (uh − uh )) (11)

Now, let us focus our attention to the second term in the above. We obtain
an upper bound of this term by a duality argument. Consider the following
problem.

G m
∇ · ψ = Ph (uh − uh ) in Ω

ψ = −∇a in Ω (12)

a = 0 on ∂Ω

Note then that

Ph ∇ · ψ = Ph (Ph (uG m G m
h − uh )) = Ph (uh − uh )

by properties of the L2 projection. Now, using (7) and the above, we have that

∇ · Πh ψ = Ph ∇ · ψ = Ph (uG m
h − uh ) (13)
Now, by (2) , we have

kψk1 ≤ Ckak2 ≤ CkPh (uG m


h − uh )k0 (14)
So, using (13),(9), definition of ψ, integration by parts, and (9) again, we
have

(u − um G m m
h , Ph (uh − uh )) = (u − uh , ∇ · Πh ψ)
= (σ − σhm , Πh ψ)
= (σ − σhm , Πh ψ − ψ) + (σ − σhm , ψ)
= (σ − σhm , Πh ψ − ψ) − (σ − σhm , ∇a)
= (σ − σhm , Πh ψ − ψ) + (∇ · (σ − σhm ), a)
= (σ − σhm , Πh ψ − ψ) + (∇ · (σ − σhm ), a − Ph a)
(15)

6
We now estimate each term in (15) individually. For the first term, we will
apply Cauchy-Schwarz, (8), and Hölder’s Inequality. We’ve

X
(σ − σhm , Πh ψ − ψ) ≤ kσ − σhm k0,K kΠh ψ − ψk0,K
K∈T
X
≤ Ch ||σ − σhm ||0,K ||ψ||1,K
K∈T
! 21 ! 21
X X
≤ Ch ||(σ − σhm )||20,K ||ψ||21,K
K∈T K∈T
≤ Ch||(σ − σhm )||0 ||ψ||1

For the second term, we use the Cauchy-Schwarz inequality and (4),

X
(∇ · (σ − σhm ), a − Ph a) ≤ ||σ − σhm )||0,K ||a − Ph a||0,K
K∈T
X
≤C ||h∇ · (σ − σhm )||0,K |a|1,K
K∈T
≤ Ch||∇ · (σ − σhm )||0 ||a||1

Now, after plugging these approximations into (15), then using (14) we have
that

(u − um G m m m
h , Ph (uh − uh )) ≤ Chk(σ − σh )k0 kψks + Chk∇ · (σ − σh )k0 kak1
≤ Ch(k(σ − σhm )||0 + k∇ · (σ − σhm )k0 )(kψks + kak1 )
 
≤ Ch k(σ − σhm )||0 + k∇ · (σ − σhm )k0 kPh (uG m
h − uh )k0

Finally, plugging this estimate into (11), dividing appropriately by


||Ph (uG m
h − uh )||0 , we are done.

We will use the following lemma in the next theorem.
Lemma A Let Ω be a convex polygonal domain, and Πh the Raviart-Thomas
Operator. Then ∇ · (Πh σ − σhm ) = 0.
Proof.
We first note that ∇ · (Πh σ − σhm ) ∈ P0 , so using (6) and (9), we have

(∇ · (Πh σ − σhm ), ∇ · (Πh σ − σhm )) = (Ph ∇ · σ − ∇ · σhm , ∇ · (Πh σ − σhm ))


= (∇ · σ − ∇ · σhm , ∇ · (Πh σ − σhm ))
=0

Hence we have shown that k∇ · (Πh σ − σhm )k20 = 0, so,


∇ · (Πh σ − σhm ) = 0. This completes the proof.


7
Lemma B Let Ω be a convex polygonal domain. Then
k∇ · (σ − σhm )k0 ≤ Chkf k1

Proof.
We have by Lemma A and (8) that
k∇ · (σ − σhm )k0 ≤ k∇ · (σ − Πh σ)k0 + k∇ · (Πh σ − σhm )k0
= k∇ · (σ − Πh σ)k ≤ Chk∇ · σk1 ≤ Chkf k1
We now prove our error estimate for kσ − σhm k.
Theorem 2 Let Ω be a polygonal domain. For the axillary function σ corre-
sponding to model problem, we have that
||σ − σhm ||0 ≤ Ch||σ||1 ≤ Ch||u||2
Where u is the solution to the model problem.
Proof.
Using what we’ve shown, we have that
kσ − σhm k0 ≤ kσ − Πh σk0 + kΠh σ − σhm k0
≤ 2kΠh σ − σk0
We have from (9), Lemma A, and Cauchy-Schwarz that
||Πh σ − σhm ||20 = (Πh σ − σhm , Πh σ − σhm )
= (Πh σ − σ, Πh σ − σhm ) + (σ − σhm , Πh σ − σhm )
= (Πh σ − σ, Πh σ − σhm ) + (∇ · (σ − σhm ), u − um
h )
≤ ||Πh σ − σ||0 ||Πh σ − σhm ||0
so that
||Πh σ − σhm ||0 ≤ ||Πh σ − σ||0
By (8), we get
||Πh σ − σ||0 ≤ Ch||σ||1

This completes the proof of the estimate. 


Now, we prove our final result.
Theorem 3 Let Ω be a polygonal domain. For the solution u to the model
problem, with f the forcing term, and um h the mixed finite element solution,
then
ku − um 2
h k0 ≤ Chkuk1 + Ch (kuk2 + kf k1 )
.
Proof.
Using the Triangle Inequality, (6), and the fact that Ph um m
h = uh ∈ P0 , we have

kum m G G
h − Ph uk0 ≤ kuh − Ph uh k0 + kPh (uh − u)k0

≤ kum G G
h − Ph uh k0 + kuh − uk0

= kPh (um G G
h − Ph uh )k0 + kuh − uk0

8
Now, using Theorem 1, (10), Lemma B and Theorem 2, we have

kum 2
h − Ph uk0 ≤ Ch (kuk2 + kf k1 )

Now,

ku − um m
h k0 ≤ ku − Ph uk0 + kPh u − uh k0
≤ ku − Ph uk0 + Ch2 (kuk2 + kf k1 )

To estimate the first term, we note


X
ku − Ph uk0 = ku − Ph uk0,T
T ∈T
X
≤ Chkuk1,T
T ∈T
= Chkuk1

Using this inequality in place for the original estimate, this completes the proof.


3 The Matrix Equation


We now consider a MATLAB implementation of the mixed finite element method.

3.1 The Linear System


We are now ready to describe the linear system to approximate the solution of
the original problem (1) possible. First, we need to describe the Raviart-Thomas
basis functions in detail.
Given and edge E ∈ E, there are either two elements T+ and T− in T with a
joint edge E = ∂T+ ∩ T− or there is exactly one element T+ in T with E ⊂ ∂T+ .
If T± = conv{E ∪ {P± }} for the vertex P± opposite to E of T± , the local basis
elements are (
|E|
± 2|T ±|
(x − P± ) for x ∈ T±
ψE (x) =
0 elsewhere

We note here that we choose an orientation for νE so that it always points


from T+ to T− . The ± in the basis function definition comes from this global
orientation, and is only negative when νE points inwards.
Suppose now that there are M interior edges, the size or EΩ . Our basis
is described as above, and is enumerated as { ψj | j = 1, 2, ..., M } such that

9
PM
xψ = (x1 , x2 , ..., xM ) coming from σh = k=1 xk ψk . Further, we also have
xu = (xM +1 , xM +2 , ..., xM +L ) of uh |Tl = xM +l for l = 1, 2, ..., L. Here, T =
(T1 , T2 , ..., TL ).
We can then rewrite the discrete formulation in the previous section with
unknown variables (x1 , ..., xM , xM +1 , ..., xM +L ) as

M
X Z L
X Z
xk ψj · ψk dx + xM +l ∇ · ψj dx =0
k=1 Ω l=1 Tl

and

M
X Z Z
xk ∇ · ψk dx = f dx
k=1 Tl Tl

All together, we have M + L equations and M + L unknowns, there are M


interior edges and L triangle elements. This leads to the matrix equation of the
form     
B C xψ 0
=
CT 0 xu bf
The formation of B and C are discussed later, but it is worth noting that
xψ is the solution to the values of the auxiliary equation σ, and xu is the value
of the solution on each triangle. The 0 and bf come from Dirichlet conditions
and approximation of f by a one point quadrature rule. 

4 Implementation
In this section, we discuss the MATLAB implementation by Bahriawati
and Carstensen [1]. In particular, we provide some key MATLAB functions to
implement the mixed finite element method. The way that data is stored in this
mixed finite element method is important because they allow easy access to data
when needed. In order to reduce memory usage, we use sparse matrices sparse
matrices, MATLAB’s usage of these matrices makes it easy to manipulate many
such matrices.
Once again, it should be noted that storage of coordinates of vertices, enu-
merations of elements, and enumeration of Dirichlet edges are provided by
iFEM. In Carstensen’s paper, a specific scheme to ordering edges and elements
is used, but it should be noted that the algorithm itself is independent of which
ordering scheme is used.
We discretize the domain using squaremesh.m from iF EM and store the
information in it’s own matrix. Let L be the number of triangular elements in
T , M the number of edges, and N the number of nodes. One may store this
information in several .dat files, namely coordinate.dat, element.dat,
and Dirichlet.dat. coordinate.dat consists of a N × 2 matrix that
stores the vertex positions of all triangles, where the row number denotes a
labeling for the vertex, element.dat consists of a L × 3 matrix that stores,
per row, each triangular element via the vertex labels. For example (1 2 3)

10
might denote a triangle who’s vertices have been labeled as 1, 2, 3. Finally,
Dirichlet.dat consists of the edges of elements that are considered to host a
boundary condition. Now, in order to form the matrix equation in the previous
section, we need fast ways to store ways to go between nodes, elements, and
edges.
We use the following example mesh for remaining sections.

We now give explanations of how these matrices will be formed. For reference,
we have examples of the matrices for the above mesh example, given below.
 
0 0 0 1 5 0 0 0 0
5 0 0 0 2 6 0 0 0
 
0 6 0 0 0 0 0 0 0
 
0 0 0 0 1 0 3 7 0
 
1 5 0 7 0 2 0 4 8
N o2El =  
0 2 6 0 8 0 0 0 0
 
0 0 0 0 0 0 0 3 0
 
0 0 0 3 7 0 0 0 4
0 0 0 0 4 8 0 0 0

11
 
2 1 5 0

 3 2 6 0 


 1 4 1 0 

   5 1 1 5 
0 1 0 3 4 0 0 0 0  
1
 2 5 2 5 
0 2 0 5 7 0 0 0  

0
  4 5 1 7 
2 0 0 0 8 0 0 0  

3
  6 2 2 6 
0 0 0 6 0 10 11 0  
   6 3 6 0 
4
N o2Ed =  5 0 6 0 9 0 12 14 , Ed2El =  
0
  5 6 2 8 
7 8 0 9 0 0 0 15  

0
  4 7 3 0 
0 0 10 0 0 0 13 0  

0
  8 4 3 7 
0 0 11 12 0 13 0 16  
 5 8 4 7 
0 0 0 0 14 15 0 16 0  

 7 8 3 0 


 9 5 4 8 

 9 6 8 0 
8 9 4 0

4.1 nodes2element
This first matrix allows us to store information assigning nodes (the rows coming
from coordinate.dat), to elements (rows from element.dat). This is
stored in a sparse matrix of size N × N . We define it as follows:


j if (k, l) are nodes of the element number j
nodes2element(k, l) =
0 otherwise

One thing to note is that, considering the figure in section 1.3, if two elements
share an edge (A, B), then we force nodes2element(A, B) to be the label
assigned to T− , while nodes2element(B, A) is the label assigned to T+ . The
MATLAB code for forming this matrix is then
n o d e s 2 e l e m e n t=s p a r s e ( s i z e ( c o o r d i n a t e , 1 ) , s i z e ( c o o r d i n a t e , 1 ) ) ;
f o r j =1: s i z e ( element , 1 )
nodes2element ( element ( j , : ) , element ( j , [ 2 3 1 ] ) ) = . . .
nodes2element ( element ( j , : ) , element ( j , [ 2 3 1]))+ j ∗ eye ( 3 , 3 ) ;
end

4.1.1 Example
MATLAB allows you to single out specific rows and columns by inserting an
array into the argument. For example, if we have element(1, :) = [1, 2, 5], then
the first step in the above procedure has right hand side
nodes2element([1, 2, 5], [2, 5, 1])), which is a 3 × 3 sub-matrix consisting of
the 4th, 5th, and 1st rows along with the 5th, 1st, and 4th columns of the larger
matrix that is nodes2element.
A small snapshot of this matrix assignment might look like the following
2 5 1  
1 0 0 0
! 1 0 0
nodes2element := 2 0 0 0 + 1 0 1 0
5 0 0 0 0 0 1

12
This forces nodes2element(1, 2) = 1, nodes2element(2, 5) = 1, and
nodes2element(5, 1) = 1, which is exactly what we want. Notice, then, that
using this method we can cut down on the number of operations to make this
matrix by taking advantage of MATLAB’s built-in functions. Another way
that one might think of what the [2 3 1] permutation of rows is doing in the
procedure, is that it is rotating the triangular element’s nodes one position to
the right. What we get then, pairing this new element with the old one, is a list
of three pairs of nodes(edges), that correspond to that element.

4.2 nodes2edge
This matrix is also a sparse matrix of size N × N , and gives us a way to assign
nodes to an edge. The function is defined as


j if edge Ej is connected by nodes (k, l)
nodes2edge(k, l) =
0 otherwise

Here, we don’t do anything to symmetrized values – so that


nodes2edge(1, 2) = nodes2edge(2, 1). Here is how the code goes
B=n o d e s 2 e l e m e n t+n o d e s 2 e l e m e n t ’ ;
[ I , J]= f i n d ( t r i u (B ) ) ;
n o d e s 2 e d g e=s p a r s e ( I , J , 1 : s i z e ( I , 1 ) , . . .
s i z e ( coordinate , 1 ) , s i z e ( coordinate , 1 ) ) ;
n o d e s 2 e d g e=n o d e s 2 e d g e+nodes2edge ’ ;
n o e d g e s=s i z e ( I , 1 ) ;

Note that B is a symmetric matrix and now every pair of nodes correspond-
ing to a row and column are assigned to just one element. We only really
need the upper triangular portion of this matrix, and since it too is sparse,
[I,J]=find(triu(B)); allows us to find the indices of nonzero values and
store them in I and J. We will use these matrices to form nodes2edge.
Next, we simply initialize nodes2edge via the sparse() MATLAB func-
tion. It specifies that we set the values of nodes2edge(I(k), J(k)) = k, where
1 ≤ k ≤ size(I, 1), and that nodes2edge will be of size N × N . From here,
we can easily see that we can assign the number of edges to be the same as the
number of rows in I, so that noedges = size(I,1).

4.3 edge2element
This matrix is a M × 4 sparse matrix consisting of assignments of edges to
elements. Each row consists of a pair of nodes – that is, an edge – (k, l) and
another pair (m, n) consisting of the labeled elements (T+ , T− ). This allows us
to see in the case of a shared edge which element is T+ , which tells which edges
are assigned a negative sign due to the inward pointing of νE . The definition is
then

[m, n] if edge j belongs to elements [m, n]
edge2element(j, [3, 4]) =
[m, 0] if edge j belongs to only m

The code for the formation of this matrix is a nested for loop, given as

13
e d g e 2 e l e m e n t=z e r o s ( s i z e ( i , 1 ) , 4 ) ;
f o r m = 1 : s i z e ( element , 1 )
for k = 1:3
i n i t i a l e d g e = e l e m e n t (m, k ) ;
e n d e d g e = e l e m e n t (m, rem ( k , 3 ) + 1 ) ;
p = nodes2edge ( i n i t i a l e d g e , end edge ) ;
i f e d g e 2 e l e m e n t ( p,1)==0
edge2element (p , : ) = [ i n i t i a l e d g e , end edge , . . .
nodes2element ( i n i t i a l e d g e , end edge ) . . .
nodes2element ( end edge , i n i t i a l e d g e ) ] ;
end
end
end

We note in the above that rem is th remainder function in MATLAB. This


structure is very useful in the fact that we can compute from it all interior
and exterior edges very easily. find(edge2element(:,4)) lists all inte-
rior edges since we are looking for nonzero entries in the 4th column, and
find(edge2element(:,4) == 0) does the opposite.

4.3.1 Example
The way this matrix is assembled is by going through every element, deter-
mining edges from that element. Say m = 1, k = 1, and from our example,
element(1, :) = [1, 2, 5]. Then initial edge = 1, and end end edge = 2
since rem(1, 3) = 1. All this does is initialize the node that forms the targeted
edge. Now, setting p = nodes2edge(initial edge,end edge) returns
the node and labeled edge for our targeted edge.
Now, once we have p, we test to see if edge2element(p,1)==0 to see
if the edge belongs to another element. if not, then it only belongs to p(1,1).
If it is 0, then we manually enter the entire row for edge2element. Note that
nodes2element(initial edge,end edge) and
nodes2element(end edge,initial edge) just assign the edge that is tar-
geted to T− and T+ .

5 Assembly of Matrix Equation


In this section we will describe how to form the matrix equation as described in
section 1.2. For a referenced triangle, we consider the triangle formed from the
three points {P1 , P2 , P3 }, labeled counter clockwise, with edged {E1 , E2 , E3 }
between P2 and P3 , P3 and P1 , and P1 and P2 .

14
5.1 Local Stiffness Matrix
Since the Global Stiffness Matrix is made up of two matrices individually, B
and C, we will have two local matrices to describe both of these. Let BL and
CL be the local matrices for B and C. BL and CL are both 3 × 3 real valued
matrices defined by
Z
(BL )jk = ψj · ψk dx for j, k = 1, 2, 3
T
and Z Z Z 
(CL )jk = diag ∇ · ψ1 dx, ∇ · ψ2 dx, ∇ · ψ3 dx
T T T

Here, ψi is the local basis for RT0 . One can compute these without having
to consult a quadrature rule – we compute them directly. Define

 
2 0 1 0 1 0
0 2 0 1 0 1  

1
 0 P1 − P2 P1 − P3
0 2 0 1 0
P2 − P1
M := 
0 and N := 0 P2 − P3 
1 0 2 0 1

1
 P3 − P1 P3 − P2 0
0 1 0 2 0
0 1 0 1 0 2

Then we may write [1]


1
BL = C T N T M N CL
48|T | L

We write BL in terms of CL , as we need to compute them both individually


to create the global matrix. However, CL is computed rather easily, since
( |E|
± |T± | on T±
∇ · ψE =
0 elsewhere

The above can be obtained from direct computation of the Raviart-Thomas


local basis[1]. Hence each integral amounts to just computing ±|E|, the length
of the edge E. The MATLAB code, then, to compute BL is as follows.
f u n c t i o n B=stimaB ( c o o r d ) ;
N=c o o r d ( : ) ∗ o n e s (1 ,3) − repmat ( coord , 3 , 1 ) ;
C=d i a g ( [ norm (N ( [ 5 , 6 ] , 2 ) ) , norm (N ( [ 1 , 2 ] , 3 ) ) , norm (N ( [ 1 , 2 ] , 2 ) ) ] ) ;
M=s p d i a g s ( [ o n e s ( 6 , 1 ) , o n e s ( 6 , 1 ) , 2 ∗ o n e s ( 6 , 1 ) , o n e s ( 6 , 1 ) , o n e s ( 6 , 1 ) ] , . . .
[ −4 , −2 ,0 ,2 ,4] ,6 ,6);
B=C∗N’ ∗M∗N∗C/ ( 2 4 ∗ d e t ( [ 1 , 1 , 1 ; c o o r d ] ) ) ;

Going throughthings,
  the formation
 of N is just
P1 P 1 P1 P1 P 2 P3
P2 P2 P2  − P1 P2 P3  and it should be noted that
P P 3 P3 P1 P2 P 3
 3 
1 1 1
det = 2|T |
P1 P2 P3

15
5.2 Global Stiffness Matrix
Now, once we are able to compute the local stiffness matrices for B and C, we
can compute the global matrices by assembling via each element. We note that
B is a k × k real valued matrix, and C is a k × l real valued matrix, where k is
the number of edges, and l is the number of triangles.
X X
B= B(T ) and C = C(T )
T ∈T T ∈T
Here, we note that each B(T ) and C(T ) depend on the currently computed
edge numbers from T , (m1 , m2 , m3 ), and that σEmk = ±1 is negative only when
the normal vector is pointing inwards. Each B(T ) is computed by
B(T ) = diag(σEm1 , σEm2 , σEm3 )BL diag(σEm1 , σEm2 , σEm3 )
and
C(T ) = diag(σEm1 , σEm2 , σEm3 )(|P3 − P2 |, |P1 − P3 |, |P2 − P1 |)T
The MATLAB code for formation of the Global Stiffness Matrix B and C
is then
B=s p a r s e ( noedges , n o e d g e s ) ;
C=s p a r s e ( noedges , s i z e ( element , 1 ) ) ;
f o r j =1: s i z e ( element , 1 )
c o o r d=c o o r d i n a t e ( e l e m e n t ( j , : ) , : ) ’ ;
I=d i a g ( n o d e s 2 e d g e ( e l e m e n t ( j , [ 2 3 1 ] ) , e l e m e n t ( j , [ 3 1 2 ] ) ) ) ;
signum=o n e s ( 1 , 3 ) ;
signum ( f i n d ( j==e d g e 2 e l e m e n t ( I , 4 ) ) ) = − 1 ;
n=c o o r d ( : , [ 3 1 2]) − c o o r d ( : , [ 2 3 1 ] ) ;
B( I , I )=B( I , I )+ d i a g ( signum ) ∗ stimaB ( c o o r d ) ∗ d i a g ( signum ) ;
C( I , j )= d i a g ( signum ) ∗ [ norm ( n ( : , 1 ) ) norm ( n ( : , 2 ) ) norm ( n ( : , 3 ) ) ] ’ ;
end

Thus, to form the Global Stiffness Matrix, A, the MATLAB code is


A=s p a r s e ( n o e d g e s+s i z e ( element , 1 ) , n o e d g e s+s i z e ( element , 1 ) ) ;
A=[B, C ; C’ , s p a r s e ( s i z e (C, 2 ) , s i z e (C , 2 ) ) ] ;

5.3 Right Hand Side Assembly


We now discuss very briefly how we construct the right hand side of the matrix
equation, which is composed of computing bf and bD . bf comes from the terms
associated with the ’forcing‘ term, while bD comes from the boundary conditions.
We only consider when we have a dirichlet boundary condition, where the value
of the given function on this boundary is 0.

5.3.1 The Forcing Term


In order to approximate the forcing term f ∈ L2 (Ω), we use a one point quadra-
ture rule on each triangle. f itself is specified by the user, and is given in the
f.m file. The one point quadrature rule is quite easy to write down, it is just
Z
f (x) dx = |T |f (z)
T

where z is located in the centroid of each triangle, which can be computed by


simply finding the average of {P1 , P2 , P3 }. In MATLAB code, this is just

16
−d e t ( [ 1 1 1 ; c o o r d i n a t e ( e l e m e n t ( l , : ) , : ) ’ ] ) ∗ . . .
f ( sum ( c o o r d i n a t e ( e l e m e n t ( l , : ) , : ) ) / 3 ) / 2

Where we once again note that the first line is equivalent to 2|T |, so that we
must divide by 2 eventually(the second line).

5.3.2 Dirichlet Boundary Condition


While we only consider in our model problem, that u = 0 on ∂Ω, in general for
non-zero values we can approximate the value via a one point quadrature rule.
The MATLAB code given below accounts for this possibility, but we only use
it in a special case, uD = 0.
for k = 1: size ( dirichlet ,1)
b( nodes2edge ( d i r i c h l e t ( k , 1 ) , d i r i c h l e t (k , 2 ) ) ) = . . .
norm ( c o o r d i n a t e ( d i r i c h l e t ( k , 1 ) , : ) − . . .
c o o r d i n a t e ( d i r i c h l e t ( k , 2 ) , : ) ) ∗ u D ( sum ( c o o r d i n a t e ( d i r i c h l e t ( k , : ) , : ) ) / 2 ) ;
end

6 Numerical Example
In this section we present some numerical examples demonstrating the error
estimates that were proven. For code to run this example, see the Appendix.
Let Ω = [0, 1] × [0, 1], and consider the following problem:
(
−∆u = (2(x2 − x) + 2(y 2 − y)) in Ω
u = 0 on ∂Ω
An exact solution may be computed for the above Dirichlet problem, note that

u(x, y) = (x2 − x)(y 2 − y)

with
σ(x, y) = −((2x − 1)(y 2 − y), (x2 − x)(2y − 1))

The mesh generated for our problem, with h = 1 .


16

Below is a plot of the solution um


h , along with the flux σ, in the x and y
variables. Here, we label them px and py respectively. We used, from the iFEM
package, the program squaremesh.m in order to generate a triangulation of the
domain Ω.

17
The plot of the approximate displacement, u.

The plot of the x and y direction of σ, denoted px and py .

m
kσ−σh k0 ku−um
h k0
h ku − um
h k0 kσ − σhm k0 m k
kσ−σh/2 0 ku−um k
h/2 0

.5 0.015539 0.061658 1.737737 1.81479


.25 0.008562 0.035482 1.928159 1.96097
125 0.004366 0.018402 1.981351 1.99115
.0625 0.002192 0.009287 1.995273 1.99795
.03125 0.001097 0.004654 1.998797 1.99942
.015625 0.000548 0.002328 1.999656 1.99985
0.0078125 0.000274 0.001164 − −
Now, when comparing this method with the exact in the L2 error, we see that
it reflects the results found in the previous section.

7 Conclusion
In conclusion, we are able to see the efficiency in this implementation of the
mixed finite element method through MATLAB. Sparse matrices are heavily
used to save memory, and are one of the good ways to store data when dealing
with large matrices who’s elements are just 0. We investigated the design of the
data storage for many things that need to be kept track of when implement-
ing MFEM, such as the relationship between edges, nodes, and elements. In

18
this way, MATLAB makes it very convenient to access specific elements when
needed. Even when under awkward domains and boundary conditions, the im-
plementation proves to be flexible and fast. We also presented error estimates
and demonstrated the estimates via a numerical simulation.

19
8 Appendix
In this appendix, I leave the code that is able ot run the numerical example. It
should be easy to modify this code to run as a loop, to store information about
errors at different step sizes. We use edge as a helper function to compile the
above matrices, then EBmf em to use all of the information to form the solution
to the problem, as described throughout the paper. EBmf em, f luxEB, and
ShowF lux are taken from the Carstensen implementation, which can be found
at
www.mathematik.hu − berlin.de/ cc/cc homepage/sof tware/sof tware.shtml
The functions getL2error is imported from the iFEM framework, and
L2sigmaE is built to compute the L2 error for σ. All relevant information such
as exact solutions and values on the boundary are stored in a struct in the file
P DEInf o. L2sigmaE is given by
f u n c t i o n e r r = L2sigmaE ( element , c o o r d i n a t e , sigmah , nodes2edge , . . .
edge2element )

lambda = [ 2 / 3 , 1 / 6 , 1 / 6 ; . . .
1/6 , 2/3 , 1/6; . . .
1/6 , 1/6 , 2 / 3 ] ;
weight = [ 1 / 3 , 1/3 , 1 / 3 ] ;
PDE = PDEInfo ;
sigma = PDE. Du ;
e r r =0;

NuT=s i z e ( element , 1 ) ;

f o r j =1:NuT
c o o r d=c o o r d i n a t e ( e l e m e n t ( j , : ) , : ) ’ ;
I=d i a g ( n o d e s 2 e d g e ( e l e m e n t ( j , [ 2 3 1 ] ) , e l e m e n t ( j , [ 3 1 2 ] ) ) ) ;
signum=o n e s ( 1 , 3 ) ;
signum ( f i n d ( j==e d g e 2 e l e m e n t ( I , 4 ) ) ) = − 1 ;
n=c o o r d ( : , [ 3 1 2]) − c o o r d ( : , [ 2 3 1 ] ) ;

P=c o o r d ∗ lambda ’ ;

localerror = 0;
f o r k =1:3
M=repmat (P ( : , k ) , 1 , 3 ) − [ c o o r d ( : , 1 ) ’ ; c o o r d ( : , 2 ) ’ ; c o o r d ( : , 3 ) ’ ] ’ ;
sh =(M∗ d i a g ( signum ) ∗ d i a g ( [ norm ( n ( : , 1 ) ) norm ( n ( : , 2 ) ) norm ( n ( : , 3 ) ) ] ) ∗ . . .
‘ sigmah ( I ) ) / ( d e t ( [ 1 1 1 ; c o o r d ] ) ) ;
l o c a l e r r o r=l o c a l e r r o r+w e i g h t ( k ) ∗ norm ( sigma (P ( : , k ) ’ ) − sh ’ ) ˆ 2 ;
end

e r r=e r r+l o c a l e r r o r ∗ d e t ( [ 1 1 1 ; c o o r d ] ) / 2 ;

end

e r r=s q r t ( e r r ) ;

Then, finally, the following script may be ran to output the solution, plot of
the solution, and retrieve the solution error of σ and u.
close all
pde = PDEInfo ;
h =1/2; %s t e p s i z e

%Mesh G e n e r a t i o n
[ c o o r d i n a t e , e l e m e n t ] = squaremesh ( [ 0 , 1 , 0 , 1 ] , h ) ;

20
%S e t Boundary C o n d i t i o n
bdFlag = s e t b o u n d a r y ( c o o r d i n a t e , element , ’ D i r i c h l e t ’ ) ;
allEdge = [ element ( : , [ 2 , 3 ] ) ; element ( : , [ 3 , 1 ] ) ; element ( : , [ 1 , 2 ] ) ] ;
d i r i c h l e t = a l l E d g e ( ( bdFlag ( : ) == 1 ) , : ) ;
neumann = [ ] ;

%Compute s o l u t i o n
[ n o d e s 2 e l e m e n t , nodes2edge , noedges , e d g e 2 e l e m e n t , i n t e r i o r e d g e ] = . . .
edge ( element , c o o r d i n a t e ) ;
u=EBmfem( element , c o o r d i n a t e , d i r i c h l e t , neumann , n o d e s 2 e l e m e n t , . . .
nodes2edge , noedges , e d g e 2 e l e m e n t ) ;
u = f u l l (u ) ;

%P l o t S o l u t i o n
figure (2)
ShowDisplacement ( element , c o o r d i n a t e , u ) ;
p=fluxEB ( element , c o o r d i n a t e , u , noedges , nodes2edge , e d g e 2 e l e m e n t ) ;
figure (3)
ShowFlux ( element , c o o r d i n a t e , p ) ;

%E r r o r e s t i m a t i o n
uh = u ( ( end − s i z e ( element , 1 ) ) + 1 : end ) ;
sigmah = u ( 1 : end − s i z e ( element , 1 ) ) ;
e x a c t u = pde . e x a c t u ;
u L 2 e r r = g e t L 2 e r r o r ( c o o r d i n a t e , element , pde . exactu , uh ) ;
s L 2 e r r = L2sigmaE ( element , c o o r d i n a t e , sigmah , nodes2edge , e d g e 2 e l e m e n t ) ;

21
References
[1] C. Bahriawati and C. Carstensen. Three MATLAB implementations of the
lowest-order Raviart-Thomas MFEM with a posteriori error control. Com-
put. Methods Appl. Math., 5(4):333–361 (electronic), 2005.

[2] Susanne C. Brenner and L. Ridgway Scott. The mathematical theory of finite
element methods, volume 15 of Texts in Applied Mathematics. Springer, New
York, third edition, 2008.
[3] Vivette Girault and Pierre-Arnaud Raviart. Finite element methods for
Navier-Stokes equations, volume 5 of Springer Series in Computational
Mathematics. Springer-Verlag, Berlin, 1986. Theory and algorithms.
[4] JaEun Ku. Supercloseness of the mixed finite element method for the pri-
mary function on unstructured meshes and its applications. BIT, 54(4):1087–
1097, 2014.

22

You might also like