0% found this document useful (0 votes)
14 views

Adaptive Mesh Refinement in 2D - An Efficient Implementation in Matlab

This document discusses the efficient implementation of various adaptive mesh refinement strategies in two dimensions in MATLAB. It presents nine different refinement strategies for triangular and quadrilateral meshes. The paper focuses on an efficient implementation using reasonable data structures and vectorization. It provides insights into marking elements for refinement and closing the mesh to eliminate hanging nodes.

Uploaded by

hung
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Adaptive Mesh Refinement in 2D - An Efficient Implementation in Matlab

This document discusses the efficient implementation of various adaptive mesh refinement strategies in two dimensions in MATLAB. It presents nine different refinement strategies for triangular and quadrilateral meshes. The paper focuses on an efficient implementation using reasonable data structures and vectorization. It provides insights into marking elements for refinement and closing the mesh to eliminate hanging nodes.

Uploaded by

hung
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Comput. Methods Appl. Math.

2019; aop

Research Article

Stefan A. Funken and Anja Schmidt*

Adaptive Mesh Refinement in 2D –


An Efficient Implementation in Matlab
https://doi.org/10.1515/cmam-2018-0220
Received August 21, 2018; revised May 7, 2019; accepted August 1, 2019

Abstract: This paper deals with the efficient implementation of various adaptive mesh refinements in two
dimensions in Matlab. We give insights into different adaptive mesh refinement strategies allowing tri-
angular and quadrilateral grids with and without hanging nodes. Throughout, the focus is on an efficient
implementation by utilization of reasonable data structure, use of Matlab built-in functions and vector-
ization. This paper shows the transition from theory to implementation in a clear way and thus is meant to
serve educational purposes of how to implement a method while keeping the code as short as possible –
an implementation of an efficient adaptive mesh refinement is possible within 71 lines of Matlab. Numeri-
cal experiments underline the efficiency of the code and show the flexible deployment in different contexts
where adaptive mesh refinement is in use. Our implementation is accessible and easy-to-understand and
thus considered to be a valuable tool in research and education.

Keywords: Matlab Program, Adaptive Mesh Refinement, Adaptivity, Finite Element Method

MSC 2010: 65N50, 65N30, 68N15

1 Introduction and Outline


In many applications such as rendering in computer graphics or solving partial differential equations (PDEs)
with the finite element method (FEM), an appropriate generation of meshes is indispensable. There exist lots
of refinement strategies and public code on this topic; an overview and a list of public code is provided by
Schneiders in [22]; in particular, Matlab implementations can be found in [9, 10, 15]. Nonetheless, existing
mesh refinement tools are often inaccessible. Commercial software packages act as a “black box” and open
source codes are mostly too complex to be understood by a wider audience. Furthermore, the mesh refinement
is often just one step in a series of other ones and by the use of an external mesh refinement software, it is
cumbersome to integrate this step with other implementations. In addition, most of these tools only provide
a triangulation of the region into triangles; see, e.g., [9, 10, 15]. However, for some applications like the
evaluation of stress fields or in computational fluid dynamics, it is beneficial to provide the geometric data as
a grid of quadrilaterals [29]. Thus, in this work, we provide an accessible mesh refinement implementation
in Matlab that can be used in a very flexible way and thus extend the functionalities of [9, 15] through more
variety in the refinement step. We want to highlight that our implementation leads to a similar computational
complexity as [9, 15], but we do not restrict our refinement algorithm to one or two strategies. We keep the
data structure simple by only requiring the element connectivity and coordinates of the vertices as input
data. Moreover, we understand a marking as edge-based marking whereas a vertex-based marking is also

*Corresponding author: Anja Schmidt, Institut für Numerische Mathematik, Universität Ulm, Helmholtzstraße 20, 89081 Ulm,
Germany, e-mail: [email protected]
Stefan A. Funken, Institut für Numerische Mathematik, Universität Ulm, Helmholtzstraße 20, 89081 Ulm, Germany,
e-mail: [email protected]

Brought to you by | Columbia University Libraries


Authenticated
Download Date | 10/22/19 2:47 PM
2 | S. A. Funken and A. Schmidt, Adaptive Mesh Refinement in 2D

TrefineR TrefineRG TrefineRGB TrefineNVB

QrefineR QrefineRG QrefineRB QrefineR2 QrefineRG2

mesh-closure

Figure 1: Overview of refinement strategies. An exemplary mesh is refined in the lower left corner by using the patterns
specified below each method. Elements that are non-marked for refinement might also be refined to eliminate hanging nodes
and are illustrated by dotted lines.

conceivable; see, e.g., [23], but not discussed within this work. In contrast to other implementations, we do
not make use of a recursive approach but prefer the implementation in terms of vectorization.
Nine different mesh refinement strategies for triangular and quadrilateral elements are investigated in the
course of this paper. We discuss the following refinement techniques for triangular meshes: the red-green (RG)
refinement proposed by Bank and Sherman in [3], the newest vertex bisection (NVB) first mentioned by Sewell
in [24], and the red-green-blue (RGB) refinement method using reference edges as discussed by Carstensen
in [7]. A further red (R) refinement strategy emerges naturally from the red-green refinement if hanging nodes
are allowed. For quadrilateral meshes, there also exists a red (R) refinement strategy, precisely a refinement
by quadrisection, touched upon from Verfürth in [27]. Furthermore, Bank, Sherman and Weiser proposed
a red-green (RG) algorithm to eliminate hanging nodes arising by quadrisection [4]. A further red-blue (RB)
strategy is investigated which was inspired by a work of Kobbelt [19]. Mao, Zhao, and Shi presented a refine-
ment method based on enneasection (division of a quadrilateral in nine smaller quadrilaterals) [29] which
we call red2-green2 (RG2) refinement strategy in this work. Similarly, for this method the red2 (R2) refine-
ment strategy naturally arises if irregular grids are allowed. An overview of the just mentioned methods is
illustrated in Figure 1.
Our implementation of mesh refinement strategies follows the general procedure MARK – CLOSURE –
CREATE NODES – CREATE ELEMENTS. We understand the first step MARK in the following way: elements
are marked by flagging each edge of the element for bisection or trisection, respectively. Hence, also non-
marked elements can be affected by neighboring elements. In contrast, the bisection algorithm in [9] only
flags the reference edge for bisection. The proceeding step CLOSURE makes sure that either hanging nodes
are removed or the level of two neighboring elements differs at most by one as is needed for irregular mesh
refinement strategies. We provide a detailed explanation of how to implement the first two steps in the course
of this work. The last two steps are self-explanatory and are only marginally addressed here.
The complete Matlab code of ameshref can be downloaded from the web [17], and the technical report
provides a detailed documentation of the underlying ideas [20]. Coarsening is a further important part of
mesh adaption. To this end, it is desirable to coarsen triangulations obtained by the use of the ameshref pack-
age. Coarsening is a straightforward procedure for hierarchical refinement strategies, i.e., the parental infor-

Brought to you by | Columbia University Libraries


Authenticated
Download Date | 10/22/19 2:47 PM
S. A. Funken and A. Schmidt, Adaptive Mesh Refinement in 2D | 3

mation for each element is stored; see, e.g., [21]. As our refinement implementations are non-hierarchical,
an efficient implementation of coarsening is more challenging. Chen and Zhang addressed this aspect for the
newest vertex bisection [11] and showed that no additional data structure is needed. We also provide criteria
for non-hierarchical local coarsening in 2D in [16] that allow to efficiently implement coarsening strategies
without additional data structures and thus extend the work of Chen and Zhang to the refinement strategies
presented in ameshref.
The rest of this paper is organized as follows. First of all, we introduce some notations and basic con-
cepts in Section 2. Subsequently, in Section 3, we briefly introduce the mesh refinement strategies we want
to implement before we go into detail with the implementation itself in Section 4. This work closes with some
numerical experiments discussed in Section 5.

2 Preliminaries
In this work, we consider a polygonal Lipschitz domain Ω in ℝ2 . Let therefore T be a triangulation of Ω, i.e.,
∙ T is a finite set of compact elements T with positive area |T| > 0,
∙ the union of all elements in T covers the closure Ω,
∙ for two elements T1 , T2 ∈ T with T1 ≠ T2 holds T̊1 ∩ T̊2 = 0, where T̊ denotes the interior of T.
Here, we restrict the elements T to be of triangular or quadrilateral shape. If additionally the boundary
Γ := ∂Ω is divided into a segment Γ1 and Γ2 = Γ \ Γ1 as may be the case for an underlying domain of partial
differential equations with mixed boundary conditions, we require that
∙ for all T ∈ T it holds that T ∩ Γ1 is empty or an edge.
In addition, we call T a regular triangulation of Ω if
∙ for all T1 , T2 ∈ T with T1 ≠ T2 it holds that T1 ∩ T2 is empty, a common node or a common edge.
This definition prevents a triangulation from having hanging nodes. If z ∈ T1 ∩ T2 is a vertex of T1 but not of
T2 , we call z a hanging node. In the following, we call T k-irregular if the triangulation is not regular and has
at most k hanging nodes per edge.
Throughout this work, we denote the set of all vertices of a triangulation T with N. In all of the presented
mesh refinement strategies, we want to assure the shape regularity of a family of triangulations {Th } with
h = maxT∈T h T > 0, namely that,
∙ for triangles, there exists a constant c ≥ 1 such that
hT
≤c for all T ∈ Th and all h > 0,
ϱT
where h T denotes the diameter of T ∈ Th and ϱ T is the diameter of the largest ball inscribed in T. This
definition is known as the inscribed ball condition proposed by Ciarlet in [12].
∙ For quadrilaterals, there exists a constant c1 ≥ 1 and c2 > 0 such that

hT
≤ c1 for all T ∈ Th and all h > 0,
hT

where h T and h T are the longest and shortest edge of T respectively and

|cos(θ)| ≤ c2 < 1 for all inner angles θ of T.

Note that the additional angle condition proposed by Ciarlet and Raviart in [13] prevents a quadrilateral
from degenerating into a triangle.
The shape regularity of a triangulation is of importance within different contexts. For example, the numerical
computation of the surface area of a cylinder fails for degenerated triangles [28]. Furthermore, in the frame-
work of (adaptive) finite element methods shape regularity of a triangulation lays the foundations for deriving
optimal interpolation order, proving convergence of the finite element method as well as finding appropriate
a posteriori error estimates [6].

Brought to you by | Columbia University Libraries


Authenticated
Download Date | 10/22/19 2:47 PM
4 | S. A. Funken and A. Schmidt, Adaptive Mesh Refinement in 2D

A further aspect to examine is the nesting of a sequence of triangulations. Let {Ti }i=1,...,n be a sequence
of triangulations where Ti+1 is formed by refining the triangulation Ti with a mesh refinement strategy. We
call this sequence a nested triangulation if T1 ⊂ T2 ⊂ ⋅ ⋅ ⋅ ⊂ Tn holds for all n ∈ ℕ. Nesting of triangulations
are closely related to nested spaces in the framework of adaptive finite element methods. To this end, this
property ensures an error reduction and thus is an important key property in proving optimal convergence
rates; cf. [25] for the first and [8] for the axiomatic contributions with a historical overview.

2.1 Adaptivity

Uniformly refining a mesh is not difficult because the setting is very clear. Each element T of a triangula-
tion T is split into four new elements, the resulting mesh is regular, the shape regularity is preserved and
obviously the sequence of triangulations {Ti } obtained is nested. Note that the shape regularity for quadrilat-
eral elements is not obvious but can be shown by small adaptions of the proof in [29]. Additionally, in each
refinement step, the number of elements quadruples and hence a triangulation Tn formed after n uniform
refinement steps of T0 has 4n ⋅ #T0 elements. However, a uniform mesh refinement does not meet the needs
of some applications. This is the case for problems where high resolution is needed while keeping the compu-
tational cost low. Therefore, we try to keep the number of elements as small as possible, whereas we also want
to achieve a certain accuracy of the computed solution. To this end, refinement indicators are computed for
each element that specify the local error; see, e.g., [27] for details. Criterions such as, e.g., the Dörfler marking
[14] or maximum criterion [2] can then be used to flag elements for further refinement using this refinement
indicator.
Throughout this work, we investigate different adaptive mesh refinement strategies. For this purpose,
we assume that a set of marked elements M is given and elements are flagged by marking each edge for
refinement. Obviously, elements T̃ ∉ M can also be affected indirectly by sharing an edge with a neighboring
element T ∈ M.

3 Mesh Refinement Strategies


Before investigating the above stated adaptive refinement methods, we first state some general rules we like
to follow.
Firstly, we have the convention that all elements in the initial triangulation T0 are painted in red. This
is favorable because, for other colored elements, a refinement might have to be removed to ensure the shape
regularity of the sequence of triangulations Ti . As a consequence, the nesting {T i } cannot further be pre-
served. Secondly, we wish to maintain the regularity of the grid for all strategies. However, due to the allowed
refinement patterns, there are cases in which this is not possible. In this event, we follow the k-Irregular
Rule proposed in [4] which says: refine any unrefined element that has more than k hanging nodes on an edge.
We consider k = 1 for red refinements and k = 2 for red2 refinements and thus ensure that the refinement
level between two elements differs at most by one. Furthermore, we also use the proposed d-Neighbor Rule
from [4]: refine any element with d neighbors that have been red/red2 refined. Generally, we set d = 2 for trian-
gles and d = 3 for quadrilaterals. However, we only use the 2-Neighbor Rule for triangles in one refinement
strategy, namely TrefineRG. In contrast, the 3-Neighbor Rule for quadrilaterals is used in all of our quadri-
lateral refinement strategies. With these preliminaries, we can state the refinement methods by sorting them
into different categories, namely regular and nested refinements, regular and non-nested refinements, and
irregular refinements.

Brought to you by | Columbia University Libraries


Authenticated
Download Date | 10/22/19 2:47 PM
S. A. Funken and A. Schmidt, Adaptive Mesh Refinement in 2D | 5

none red none red none red2

Figure 2: Refinement patterns in TrefineR. Figure 3: Refinement patterns Figure 4: Refinement patterns
in QrefineR. in QrefineR2.

3.1 Irregular Mesh Refinements

The following refinement methods only use one refinement pattern, namely a red/red2 refinement. This
results into hanging nodes that cannot be eliminated without refining the mesh uniformly, and hence the
refined mesh is irregular. To restrict the number of hanging nodes per edge, we deploy the k-Irregular Rule
with k = 1 for red refinements and k = 2 for red2 refinements.
TrefineR is a refinement strategy for triangular meshes. It provides one refinement pattern that is formed
by connecting the midpoints of each edge with each other; see Figure 2. Obviously, the four new triangles
are geometrically similar to their ancestor, and thus the shape regularity is preserved with this method. The
sequence of triangulations {T i } obtained by TrefineR is nested.
QrefineR refines quadrilateral meshes by quadrisection, i.e., midpoints of opposite lying edges are joined
together; see Figure 3. Here, the sons are not similar to their ancestors in general; however, the shape regu-
larity for all Ti , i = 1, . . . , n, can be shown by a small adaption of the proof in [29]. A nesting of the sequence
of triangulations is obtained.
QrefineR2 splits a quadrilateral into nine son quadrilaterals by trisecting each edge and connecting oppo-
site lying nodes with each other; see Figure 4. Since, in each step, two new nodes per edge are introduced,
we call this refinement step red2. The preservation of the shape regularity of the grid is proven [29]. Again,
the sequence of triangulations obtained by QrefineR2 is nested.
Hereinafter, we introduce further refinement patterns to eliminate hanging nodes without refining the
mesh uniformly.

3.2 Regular and Nested Refinements

As a first method, we want to mention the well-known newest vertex bisection, called TrefineNVB in this paper.
Here, a reference edge is chosen for each element in the initial triangulation T0 , e.g., the longest edge. The
idea is to split a triangle subsequently at the newest vertex introduced until all marked edges are bisected.
Each new triangle then obtains a new reference edge, considered to be the edge opposite to the newest vertex.
To this end, the refinement process is uniquely determined by the refinement patterns shown in Figure 5. The
colors do not have a specific role in this context; each new triangle is treated as a red element. This is because
all triangles formed through this refinement strategy fall into at most 4 ⋅ #T0 similarity classes [24], and thus
the shape regularity of the grid is preserved. We will see the analogies of the coloring later on. Obviously, the
sequence of meshes is nested and regular.

none green blueℓ bluer redNVB

Figure 5: Refinement patterns in TrefineNVB. Left to right: A red element and its refinement patterns. Reference edges are
highlighted by hatched lines.

Brought to you by | Columbia University Libraries


Authenticated
Download Date | 10/22/19 2:47 PM
6 | S. A. Funken and A. Schmidt, Adaptive Mesh Refinement in 2D

red

Figure 6: Replacement of redNVB .

An evident variation of TrefineNVB leads to the refinement strategy TrefineRGB where the abbreviation
stands for red-green-blue refinement. To this end, the last refinement pattern redNVB is replaced by the already
known red refinement; see Figure 6. The concept of reference edges is carried over from the previous refine-
ment method. Again, the resulting mesh is shape regular since a red refinement divides a triangle into four
similar triangles and thus no further similarity classes arise. The nesting and regularity of the grid is apparent.
For both methods, the choice of reference edges in the initial mesh has some impacts on the locality of
the mesh. Removing hanging nodes during the refinement process can inflate the number of refined elements
depending on the choice of reference edges. A very intuitive choice is the longest edge because for this the
largest angle is subdivided. However, an unfavorable mesh can lead to a chain of further refinements. Other
algorithms on how to choose the reference edge in the initial mesh to keep the refinement local are, e.g.,
mentioned in [7, 26]. An important result however is that the overall number of triangles created throughout
the completion process stays proportional to the number of elements marked in the refinement process. This
was first proven in [5] under certain assumptions on the initial mesh T0 . However, dropping the assumptions
on T0 does not affect the statement as is shown in [18].
Henceforth, only non-nested refinement strategies are presented.

3.3 Regular and Non-nested Refinements

In the course of removing hanging nodes while assuring shape regularity for all triangulations Tℓ , ℓ ∈ ℕ, one
loses the nesting of the sequence of triangulations when not utilizing the concept of reference edges. To this
end, from now on, the color of the elements plays a special role.
TrefineRG is a refinement strategy that basically offers two refinement patterns: a red and a green refine-
ment. Both terms have already been introduced; however, since there are no reference edges, a green refine-
ment can split a triangle by halving one of the three edges; see the top row of Figure 7 for an illustration.
Additionally, we follow the 2-Neighbor Rule.
To prevent the angles of an element from becoming too small, a green element is not further refined, i.e.,
the green refinement is first removed before the element is refined again; see the bottom row of Figure 7 for
a green element and its refinement patterns.

none red green1 green2 green3

g2green g2red g2red1 g2red2 g2red12

Figure 7: Refinement patterns in TrefineRG. Top left to right: a red element and its refinement patterns. Bottom left to right:
a green element and its refinement patterns.

Brought to you by | Columbia University Libraries


Authenticated
Download Date | 10/22/19 2:47 PM
S. A. Funken and A. Schmidt, Adaptive Mesh Refinement in 2D | 7

none red green – type 1 green – type 2 green – type 3 red blue

Figure 8: Refinement patterns for red elements in QrefineRG. From left to right: a red Figure 9: Red and blue pattern.
element and its refinement patterns. Rotation for green elements is allowed.

Figure 10: Non-uniqueness of QrefineRB without any further assumptions. Top left to bottom right: red refinement and possible
eliminations of hanging nodes by using blue patterns.

QrefineRG is the counterpart for quadrilaterals. Instead of allowing one green refinement in all orienta-
tions, we allow three different types of green refinements (see Figure 8), each in all possible orientations. To
assure the shape regularity, green elements are removed in the same manner as in TrefineRG before refin-
ing further. Here, we comply with the 3-Neighbor Rule. Since this refinement method leads to a mixture of
quadrilaterals and triangles, it is desirable to create a strategy with quadrilateral elements only.
To this end, we consider QrefineRB with a red and blue refinement pattern shown in Figure 9, where the
blue pattern resembles a Y-formation. We seek a blue pattern that regularizes a mesh by eliminating hanging
nodes.
However, due to the blue pattern, by repairing one hanging node, another hanging node is introduced,
i.e., hanging nodes are shifted to an adjacent edge. Only connecting two hanging nodes leads to a regular
mesh. To resolve this issue, we utilize this pattern to surround a node until another is reached, and thus
hanging nodes will be eliminated [19]. There still remains the question about the implementation of this
method, i.e., how to uniquely place the blue pattern.
Without any further assumptions on how to place the blue pattern, this refinement strategy does not
lead to a unique refinement. For an illustration of the non-uniqueness, the nodes of an exemplary mesh are
painted alternately in black and white. Originating from a red refinement shown in the top left of Figure 10,
the subsequent meshes are some possible closures, namely placing the Y-formation around black nodes,
around white nodes or a mixture of both. To guarantee uniqueness, we stick to the convention of placing the
Y-formation around black nodes, i.e., we only allow the patterns in relation to black and white nodes depicted
in Figure 11.
To implement this method, painting the nodes alternately in black and white and subsequently matching
the patterns would be an obvious approach. However, in practice, coloring the nodes alternately can be of
great effort, and supplementarily there exist meshes for which an alternating coloring cannot be achieved; see
Figure 12. Thus, we follow Kobbelt’s proposal to first refine the mesh uniformly [19], i.e., by red-refining each

Brought to you by | Columbia University Libraries


Authenticated
Download Date | 10/22/19 2:47 PM
8 | S. A. Funken and A. Schmidt, Adaptive Mesh Refinement in 2D

none red bluer

Figure 11: Convention of placing the patterns Figure 12: Counterexample for coloring the nodes alternately.
in relation to black and white nodes. Nodes cannot be painted alternately in two different colors due to
the odd number of nodes forming a ring.

none red bluer blueℓ

b2blue b2red b2south b2east b2southeast

Figure 13: Refinement patterns in QrefineRB. Top left to right: a red element and its refinement patterns. Bottom left to right:
a blue element and its refinement patterns.

none red2 green2 – type 1 green2 – type 2 green2 – type 3

Figure 14: Refinement patterns in QrefineRG2. Left to right: a red element and its refinement patterns.

element. Instead of coloring the nodes alternately, we make use of the property that, after one refinement, the
nodes of an element can be assigned to two generations. We store the oldest node of each element as reference
node and consider this reference node as one of the white nodes, and therefore we allow the refinement
patterns in relation to the reference node shown in the top row of Figure 13. Since we only deal with one
reference node, we have to take into account a bluer and blueℓ refinement pattern. However, a distinction is
only needed to cover all cases for the refinement of a red element. Afterwards, a blue element is refined as
shown in the bottom row of Figure 13 – no distinction into bluer and blueℓ is needed.
Also, a blue element is coarsened before further refined; see the bottom row of Figure 13 for a blue ele-
ment and its refinement patterns. The shape regularity of meshes Tℓ obtained by applying QrefineRB can be
proven by a small adaption of the proof in [29].
QrefineRG2 is a one-to-one translation of QrefineRG from quadrisection to enneasection and results in
a mesh of quadrilaterals since the refinement patterns depicted in Figure 14 only consist of quadrilateral
elements. The shape regularity of QrefineRG2 is proven in [29].
As we have now briefly introduced the mesh refinement strategies, we want to highlight the following
property.

Remark 1. All mesh refinement strategies presented above hold the shape regularity of the grid.

Brought to you by | Columbia University Libraries


Authenticated
Download Date | 10/22/19 2:47 PM
S. A. Funken and A. Schmidt, Adaptive Mesh Refinement in 2D | 9

4 Matlab Implementation of Adaptive Mesh Refinement


This section is outlined as follows: We first explain the data structure of a triangulation T. Subsequently, we
explain the steps MARK and CLOSURE in more detail. For the latter, we make use of three different imple-
mentation approaches, namely a hash map concept, implementation by means of virtual elements and lastly
a three-step procedure. The approaches are explained via an extract of a representative refinement strategy.
The implementation of the other refinement methods are just small adaptions of the exemplary code. How-
ever, for the interested reader, an extensive presentation is provided in [20]. The rest of this section briefly
addresses the steps CREATE NODES and CREATE ELEMENTS and provides a small example on how to embed
the code into a framework. We close this section by listing the functions given in the package ameshref.

4.1 Data Structure of a Triangulation

To represent the data, we need to specify the triangulation T = {T1 , . . . , T M }, the corresponding set of nodes
N = {z1 , . . . , z n } and potentially boundary data. We follow [1, 15] and define coordinates as an N × 2 array
with the ℓ-th row
coordinates(ℓ, :) = [xℓ yℓ ]
representing the x- and y-coordinates of the ℓ-th node zℓ = (xℓ , yℓ ) ∈ ℝ2 . Furthermore, the triangulation T is
stored in an M × 3 array elements3 for triangles, i.e., the ℓ-th element Tℓ = conv{z i , z j , z k } is represented by

elements3(ℓ, :) = [i j k].

Analogously, an M × 4 array elements4 for quadrilaterals stores the ℓ-th element Tℓ = conv{z i , z j , z k , z l } as

elements4(ℓ, :) = [i j k l].

If boundary edges are given, the ℓ-th edge Eℓ = conv{z i , z j } corresponds to

dirichlet(ℓ, :) = [i j] or neumann(ℓ, :) = [i j],

depending on the boundary conditions. See an exemplary illustration of the introduced terms in Figure 15.
It is ensured that the order of the nodes in a triangulation is given in a mathematical positive sense.
Using this data structure, we may visualize a grid by Matlab’s built-in function

patch ( ' Faces ' , elements4 , ' Vertices ', coordinates , ' Facecolor ' , ' none ')

This works analogously for triangular meshes by replacing elements4 by elements3.

coordinates elements4 dirichlet neumann


z6 z7 z8
−1.0 −1.0 1 2 4 3 1 2 2 4
0.0 −1.0 8 7 4 5 4 5 5 8
−1.0 0.0 6 3 4 7 8 7 6 3
0.0 0.0 7 6 3 1
1.0 0.0
z3 z4 z5 −1.0 1.0
0.0 1.0
1.0 1.0

z1 z2

Figure 15: A triangulation T of the L-shaped domain Ω = (−1, 1)2 \ ([0, 1] × [−1, 0]) into 3 quadrilaterals characterized by the
arrays coordinates and elements4. The boundary edges of the L-shape are partitioned into Dirichlet (in black) and Neumann
boundary (in red). This illustration is based on the data representation in [1, 15].

Brought to you by | Columbia University Libraries


Authenticated
Download Date | 10/22/19 2:47 PM
10 | S. A. Funken and A. Schmidt, Adaptive Mesh Refinement in 2D

4.2 MARK

As already stated, we understand a marked element as an element where each edge is marked for refinement.
To this end, it is favorable to generate a numbering of the edges instead of searching data structure costly.
This is accomplished by the function provideGeometricData given in Listing 1 which is an enhanced version
of the one provided in [15]. This function returns the corresponding nodes in edge2nodes(ℓ, :) = [i j] for the
ℓ-th edge Eℓ = conv{z i , z j } and the edges of the triangulation T in element3edges and element4edges respec-
tively. element3edges(i, ℓ) provides the number of the edge between the nodes elements3(i, ℓ mod 3 + 1) and
elements3(i, (ℓ + 1) mod 3 + 1), analogously for elements4edges by replacing ℓ mod 3 by ℓ mod 4. Addition-
ally, optional information about boundary edges can be queried. This is implemented as follows:
∙ Line 1: The function is usually called by

[ edge2nodes , element3edges , element4edges , dirichlet2edges , neumann2edges ] ...


= provideGeometricData ( elements3 , elements4 , dirichlet , neumann )

where the boundary conditions dirichlet and neumann are hidden in the optional arguments varargin
and varargout. If the mesh only consists of triangular elements, we hand over elements4 = zeros(0,4);
similarly, if the mesh only consists of quadrilateral elements, we hand over elements3 = zeros(0,3).
∙ Lines 5–12: A collection of all edges is stored in edges. The ptr counts the number of all existing edges
for triangles, quadrilaterals and boundary edges. Here, duplications due to neighboring elements are
included.
∙ Line 14: These duplications are removed by sorting the edges such that the smallest entry per column is
listed first.
∙ Lines 15–20: The variables element3edges, element4edges and boundary data (varargout) are assem-
bled as described above.

Listing 1: provideGeometricData.m

1 function [ edge2nodes , element3edges , element4edges , varargout ] ...


2 = provideGeometricData ( elements3 , elements4 , varargin )
3 % *** Obtain geometric information on edges
4 % *** Collect all edges
5 edges = [ reshape ( elements3 (: ,[1:3 ,2:3 ,1]) ,[] ,2); ...
6 reshape ( elements4 (: ,[1:4 ,2:4 ,1]) ,[] ,2)] ;
7 ptr = [3* size ( elements3 ,1) ,4* size ( elements4 ,1) , zeros (1 , nargin -2)];
8 for j = 1: nargin -2
9 ptr ( j +2) = size ( varargin { j } ,1);
10 edges = [ edges ; varargin { j }];
11 end
12 ptr = cumsum ( ptr );
13 % *** Create numbering of edges
14 [ edge2nodes ,~ , ie ] = unique ( sort ( edges ,2) , ' rows ' );
15 element3edges = reshape ( ie ( 1: ptr (1)) ,[] ,3);
16 element4edges = reshape ( ie ( ptr (1)+1: ptr (2)) ,[] ,4);
17 % *** Provide boundary2edges
18 for j = 1: nargin -2
19 varargout { j } = ie ( ptr ( j +1)+1: ptr ( j +2));
20 end

Brought to you by | Columbia University Libraries


Authenticated
Download Date | 10/22/19 2:47 PM
S. A. Funken and A. Schmidt, Adaptive Mesh Refinement in 2D | 11

Utilizing the just mentioned function, we can then implement the marking process as illustrated exem-
plarily in Listing 2 for the function QrefineRB. Remember, that for this refinement strategy a distinction
into red and blue elements is necessary. In Listing 2, the first part of the function QrefineRB is shown that
implements the step MARK for this strategy.
∙ Lines 1–5: The function is usually called by

[ coordinates , elements4 , dirichlet , neumann ] ...


= QrefineRB ( coordinates , elements4 , dirichlet , neumann , marked4 )

The variable elements4 consists of red and blue elements, and they are stored block by block, starting
with red elements. The last entry of varargin is considered to be the marked elements. A persistent
variable nB is defined which gives the number of blue elements and is updated in every function call.
A persistent variable is local to the function in which it is declared. Between function calls, the value of
the variable nB is kept in memory.
∙ Lines 6–13: Further geometric data is generated by calling provideGeometricData. The number of red
elements nR can easily be determined from the number of blue elements nB and the overall number of
elements nE.
∙ Lines 14–19: Red elements are marked by marking all edges for refinement (lines 15–17). For blue
elements, only non-marked edges of the father element are marked. Thus, they are determined with
element2edges(nR+[3*marked-2,3*marked+3*nE-1]) and correspond to edge 1 and 2 of the outer edges
of a blue element as shown in Figure 16.

Listing 2: The step MARK in QrefineRB.m

1 function [ coordinates , newElements , varargout ] ...


2 = QrefineRB ( coordinates , elements , varargin )
3 persistent nB ;
4 nE = size ( elements ,1);
5 markedElements = varargin { end };
6 % *** Obtain geometric information on edges
7 [ edge2nodes ,~ , element2edges , boundary2edges {1: nargin -3}] ...
8 = provideGeometricData ( zeros (0 ,3) , elements , varargin {1: end -1});
9 % *** Count number of blue sibling elements ;
10 if isempty ( nB )
11 nB =0;
12 end
13 nR = nE - nB ;
14 % *** Mark edges for refinement
15 edge2newNode = zeros (1 , size ( edge2nodes ,1));
16 marked = markedElements ( markedElements <= nR );
17 edge2newNode ( element2edges ( marked ,:)) = 1;
18 marked = ceil (( markedElements ( markedElements > nR ) - nR )/3);
19 edge2newNode ( element2edges ( nR +[3* marked -2 ,3* marked +3* nE -1])) = 1;

4.3 CLOSURE

Once the edges of marked elements are flagged, further edges might need to be marked as well to properly
map the marking to an admissible grid. Note that further edges can always be marked whereas removing
a marking is not considered. This procedure is called CLOSURE, and we present different approaches on how
to implement this step for different refinement strategies.

Brought to you by | Columbia University Libraries


Authenticated
Download Date | 10/22/19 2:47 PM
12 | S. A. Funken and A. Schmidt, Adaptive Mesh Refinement in 2D

mark

bin 000 100 010 110 001 101 011 111


dec 0 1 2 3 4 5 6 7
↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓

hash

bin 000 100 110 110 101 101 111 111


val 0 1 2 2 3 3 4 4
type none green bluer bluer blueℓ blueℓ redNVB redNVB

Table 1: Mapping of eight possible markings to the five patterns allowed in TrefineNVB. For each hash, a binary number is given
and a type name plus value is assigned.

4.3.1 Implementation with Hash Maps

Our first approach is based on hash maps. For this procedure we understand each edge as a binary, i.e.,
a flagged edge has value one and a non-flagged edge has value zero. We illustrate the proceeding in Table 1 for
the easiest example, namely for TrefineNVB. For this refinement strategy, the knowledge about the location
of the reference edges is essential. Instead of building further data, we incorporate this information in the
already existing data structures, i.e., the nodes of the reference edges are given by elements3(:,1:2), and
thus the reference edges correspond to the first entry per row in elements3edges. For a triangle, there exist
23 = 8 possibilities to mark edges that are shown in Table 1 with an assignment of a binary and decimal
number. Note that the corresponding binary number is given in a reverse order. For each marking, it is clear
by definition of the refinement strategy which pattern encoded in hash is the one to choose. This mapping is
done automatically by the auxiliary function hash2map with input parameters dec, i.e., we specify the decimal
number corresponding to the marking and the possible refinement patterns given by the refinement strategy
in hash.
An efficient implementation of TrefinenNVB and TrefineRGB is given in [15]. We maintain the notation
and parts of the structure; however, we make use of hash maps instead. We implement four refinement strate-
gies by utilization of hash maps: TrefineNVB, TrefineRGB, TrefineRG and QrefineRB. In this paper, we focus
on the implementation of the latter. Small adaptions to this code yield the other strategies. For an extensive
discussion, we refer to [20]. The implementation of the step CLOSURE in QrefineRB is shown in Listing 3 and
explained in the following. Remember that the assignment of a reference node is needed for this strategy. We
have the convention to store the reference node of the ℓ-th element in elements4(ℓ, 1).
∙ Lines 20–23: Refinement patterns for red and blue elements are translated into a binary number and
saved in hashR and hashB. Hence, for red elements, red (1111), bluer (1100), and blueℓ (0011) come into
question. With the numbering of edges depicted in Figure 16, 110000 is b2red, 111001 corresponds to
b2south, 110110 is b2east, and 111111 leads to b2southeast; compare Figure 13. With six outer edges,
there are 26 = 64 possibilities of different markings. For all potential markings, the correct refinement
pattern is determined and stored in mapR and mapB.
∙ Lines 24–33: To ensure the regularity of the grid, further markings may be needed to match appropri-
ate patterns and eliminate all hanging nodes. Thus, this is done in an iterative process until no further
changes are made.
∙ Lines 34–50: The same is done for blue elements. However, for this, only the outer edges are concerned.
Those are specified in bit and ordered in the same way as shown in Figure 16. A particularity is that,
for a marked third or fourth outer edge, an additional node needs to be created. Lines 49–50 ensure that
the edge conv{v3 v4 } of element T1 is marked for refinement if the third outer edge is marked, and the
edge conv{w2 w3 } of element T2 is marked for refinement if the fourth outer edge is marked; compare
Figure 16.

Brought to you by | Columbia University Libraries


Authenticated
Download Date | 10/22/19 2:47 PM
S. A. Funken and A. Schmidt, Adaptive Mesh Refinement in 2D | 13

w4 v2 1 v1

T1 3

v3 v4
2 w3
z4 z3

T2 T3 6

w1 4 w2 z1 5 z2

Figure 16: Numbering of outer edges for blue elements.

Listing 3: The step CLOSURE in QrefineRB.m

20 hashR = [1 ,1 ,1 ,1;1 ,1 ,0 ,0;0 ,0 ,1 ,1];


21 [ mapR , valueR ] = hash2map ((0:15) ' , hashR );
22 hashB = logical ([1 ,1 ,0 ,0 ,0 ,0;1 ,1 ,1 ,0 ,0 ,1;1 ,1 ,0 ,1 ,1 ,0;1 ,1 ,1 ,1 ,1 ,1]);
23 [ mapB , valueB ] = hash2map ((0:63) ' , hashB );
24 swap = 1;
25 while ~ isempty ( swap ) || any ( flags (:))
26 markedEdge = edge2newNode ( element2edges );
27 % *** Change flags for red elements
28 bit = markedEdge (1: nR ,:);
29 dec = sum ( bit .*( ones ( nR ,1)*2.^(0:3)) ,2);
30 valR = valueR ( dec +1);
31 [ idx , jdx ] = find (~ bit & mapR ( dec +1 ,:));
32 swap = idx +( jdx -1)* nE ;
33 edge2newNode ( element2edges ( swap )) = 1;
34 % *** Change flags for blue elements
35 bit = [ markedEdge ( nR +1:3: end ,1) , markedEdge ( nR +2:3: end ,4) , ...
36 markedEdge ( nR +1:3: end ,4) , markedEdge ( nR +2:3: end ,1) , ...
37 markedEdge ( nR +3:3: end ,1:2)];
38 dec = sum ( bit .*( ones ( nB /3 ,1)*2.^(0:5)) ,2);
39 valB = valueB ( dec +1);
40 bdx = find ( valB ) ';
41 flags = ~ bit ( bdx ,:) & mapB ( dec ( dec >0)+1 ,:);
42 edge2newNode ( element2edges ( nR +3* bdx ( flags (: ,1)) -2 ,1))=1;
43 edge2newNode ( element2edges ( nR +3* bdx ( flags (: ,2)) -1 ,4))=1;
44 edge2newNode ( element2edges ( nR +3* bdx ( flags (: ,3)) -2 ,4))=1;
45 edge2newNode ( element2edges ( nR +3* bdx ( flags (: ,4)) -1 ,1))=1;
46 edge2newNode ( element2edges ( nR +3* bdx ( flags (: ,5)) ,1))=1;
47 edge2newNode ( element2edges ( nR +3* bdx ( flags (: ,6)) ,2))=1;
48 end
49 edge2newNode ( element2edges ( nR +3* bdx ( hashB ( valB ( bdx ) ,3)) -2 ,3))=1;
50 edge2newNode ( element2edges ( nR +3* bdx ( hashB ( valB ( bdx ) ,4)) -1 ,2))=1;

Brought to you by | Columbia University Libraries


Authenticated
Download Date | 10/22/19 2:47 PM
14 | S. A. Funken and A. Schmidt, Adaptive Mesh Refinement in 2D

Figure 17: Irregularity data as virtual elements. An irregular edge with a hanging node (top left) can be interpreted as a virtual
triangle (top right). For two hanging nodes per edge the virtual element is a quadrilateral (bottom).

4.3.2 Implementation with Virtual Elements

Unlike for regular refinement strategies, in the irregular case, hanging nodes are not removed.
However, to follow the k-Irregular Rule for irregular mesh refinement methods such as TrefineR,
QrefineR and QrefineR2, a distinction into regular and irregular edges is indispensable. To this end, we
make use of virtual elements irregular as depicted in Figure 17. Then irregular(ℓ, 3) gives the hanging
node of the ℓ-th irregular edge. This convention is handy because if one of the two halves of the irregular
edge is marked, the unrefined neighbor element can be flagged for refinement, too. The implementation of
the steps MARK and CLOSURE for TrefineR is given in Listing 4.
∙ Lines 1–4: The function is usually called by

[ coordinates , elements3 , irregular , dirichlet , neumann ] ...


= TrefineR ( coordinates , elements3 , irregular , dirichlet , neumann , marked3 )

where we output all information about the refined mesh. Optional arguments are dirichlet,neumann
and marked3. The last entry in varargin is anticipated to be the marked elements.
∙ Lines 5–10: To receive edge-based information on the mesh, triangular elements and irregular virtual
elements are handed over to the function provideGeometricData.
∙ Lines 11–14: The variable edge2newNodes is created, which is set to one for all edges of marked elements.
Furthermore, edges with hanging nodes are considered in this marking process, too (line 14).
∙ Lines 15–27: To ensure the 1-irregularity of the grid, it is always checked whether further markings
entail an introduction of more hanging nodes on one edge. In this case, the 1-Irregular Rule needs to
be deployed, i.e., neighboring elements need to be refined. To get this information, in lines 22–26, the
index in markedEdge is set to −1 for the first edge of the virtual element if the second or third edge is
marked. Note that the first edge of the virtual element always corresponds to the longest edge. Thus, in
the completion process, elements with a markedEdge entry of −1 are also red refined even though not all
edges are marked for refinement (lines 18–21).

Listing 4: The steps MARK and CLOSURE in TrefineR.m

1 function [ coordinates , newElements , newIrregular , varargout ] ...


2 = TrefineR ( coordinates , elements , irregular , varargin )
3 nE = size ( elements ,1);
4 markedElements = varargin { end };
5 % *** Obtain geometric information on edges
6 [ edge2nodes , element2edges ,~ , boundary2edges {1: nargin -4}] ...
7 = provideGeometricData ([ elements ; irregular ] , zeros (0 ,4) ,...
8 varargin {1: end -1});

Brought to you by | Columbia University Libraries


Authenticated
Download Date | 10/22/19 2:47 PM
S. A. Funken and A. Schmidt, Adaptive Mesh Refinement in 2D | 15

9 irregular2edges = element2edges ( nE +1: end ,:);


10 element2edges = element2edges (1: nE ,:);
11 % *** Mark edges for refinement and existing hanging nodes
12 edge2newNode = zeros (1 , size ( edge2nodes ,1));
13 edge2newNode ( element2edges ( markedElements ,:)) = 1;
14 edge2newNode ( irregular2edges (: ,1)) = 1;
15 kdx = 1;
16 while ~ isempty ( kdx ) || ~ isempty ( swap )
17 markedEdge = edge2newNode ( element2edges );
18 % *** Change flags for elements
19 kdx = find ( sum ( abs ( markedEdge ) ,2) <3 & min ( markedEdge ,[] ,2) <0);
20 [ idx , jdx ] = find (~ markedEdge ( kdx ,:));
21 edge2newNode ( element2edges ( kdx ( idx )+( jdx -1)* nE )) = 1;
22 % *** Change flags for irregular marker elements
23 markedEdge = edge2newNode ( irregular2edges );
24 flag = irregular2edges ( any ( markedEdge (: ,2: end ) ,2) ,1);
25 swap = find ( edge2newNode ( flag ) ~= -1);
26 edge2newNode ( flag ( swap )) = -1;
27 end

4.3.3 Implementation in Three Steps

QrefineRG and QrefineRG2 are not covered by the implementation with hash maps or virtual elements.
An implementation of QrefineRG and QrefineRG2 via hash maps is generally possible but leads to an
excessive code. Let us illustrate briefly why this is the case for QrefineRG. For red elements, there exist 24 = 16
different ways to mark an element. Furthermore, for green elements of type 1 additional 25 = 32 possibilities
plus for green elements of type 2 and type 3 a number of 26 = 64 options each have to be considered. For
QrefineRG2 the overall number of possible markings is even larger. To this end, we rather follow a three
step process recoarse regularity edges – refine irregular grid – regularize edges to implement these methods;
cf. Figure 18. The second step is nothing else than the implementation via virtual elements. The other two
steps are done by additional functions recoarseedges and regularizeedges.
A detailed investigation of the implementation can be found in [20]. A quick reference guide of how to
run these strategies is given in Section 4.6.

Figure 18: Depiction of the three step process. Hanging nodes of the irregular grid (in black) are removed in the regularize step
(in red). The red edges have to be eliminated in the next refinement step to receive an irregular mesh (recoarse).

Brought to you by | Columbia University Libraries


Authenticated
Download Date | 10/22/19 2:47 PM
16 | S. A. Funken and A. Schmidt, Adaptive Mesh Refinement in 2D

8 w4 v2 v1 z2 z1 w2 w1
4 3
18
15 T1 T3 T2
13 v3 v4 z3 z4
9 5 7 w3 w3
z4 z3 v4 v3
17
16 14 12 T2 T3 T1

1 2 w4
10 6 11 w1 w2 z1 z2 v1 v2
bluer blueℓ

Figure 19: Numbering of the nodes Figure 20: Bluer and blueℓ elements: after storing, the blue elements are
in variable tmp in QrefineRB. not distinguishable any more.

4.4 CREATE NODES and CREATE ELEMENTS

As soon as all edges are marked for refinement, the coordinates of new nodes can be generated. To this end,
coordinates is expanded and filled with the midpoints of the marked edges; compare lines 51–55 in List-
ing 5. For quadrilaterals, the step CREATE NODES also comprises of the generation of interior nodes. This is
done in the same matter and is omitted here.

Listing 5: The step CREATE NODES on edges in QrefineRB.m

51 % *** Generate new nodes on edges


52 edge2newNode ( edge2newNode ~= 0) ...
53 = size ( coordinates ,1) + (1: nnz ( edge2newNode ));
54 idx = find ( edge2newNode );
55 coordinates ( edge2newNode ( idx ) ,:) = ( coordinates ( edge2nodes ( idx ,1) ,:)...
56 + coordinates ( edge2nodes ( idx ,2) ,:))/2;

To fit the correct refinement patterns, further data is generated pointing to the elements to refine such as,
e.g., bluer and bluel. All nodes are stored in a temporary array tmp and numbered as shown in Figure 19.
A numbering of elements is set up in rdx for red and in bdx for blue elements. The step CREATE ELEMENTS
is illustrated exemplary for the blueℓ and bluer refinement:

newElements ([ bdx ( bluer ) ,1+ bdx ( bluer ) ,2+ bdx ( bluer )] ,:) ...
= [ tmp ( bluer ,[3 ,4 ,5 ,7]); tmp ( bluer ,[1 ,6 ,5 ,4]); tmp ( bluer ,[6 ,2 ,7 ,5])];
newElements ([ bdx ( bluel ) ,1+ bdx ( bluel ) ,2+ bdx ( bluel )] ,:) ...
= [ tmp ( bluel ,[1 ,2 ,5 ,9]); tmp ( bluel ,[3 ,8 ,5 ,2]); tmp ( bluel ,[8 ,4 ,9 ,5])];

Note that there is one particularity for this method. Even though we first distinguish blueℓ from bluer , after
storing a blue element, they are not distinguishable anymore; compare Figure 20. This simplifies the code
since this information is not needed in the further course of the implementation.
For irregular mesh refinements these steps are basically the same. The step CREATE ELEMENTS addition-
ally includes the generation of virtual elements.

4.5 A Minimal Example

Listing 6 provides an exemplary code of how to embed the refinement strategy into a framework. The function
markCircle marks elements with diameter greater than min_d which intersect the circle with center C and
radius r and is provided in example1/.

Brought to you by | Columbia University Libraries


Authenticated
Download Date | 10/22/19 2:47 PM
S. A. Funken and A. Schmidt, Adaptive Mesh Refinement in 2D | 17

To mark triangular elements, we call


mark3 = markCircle ( coordinates , elements3 ,[] , C ,r , min_d )
instead. Refinement strategies can be interchanged within the scope of their input and output parameters as
specified in Section 4.6.

Listing 6: Minimal example: circular refinement

1 C = [0.8 ,0.7]; % center of circle


2 r = 0.5; % radius of circle
3 min_d = 5e -6; % minimal diameter of an element allowed
4
5 %% exemplary use of a quadrilateral mesh refinement strategy
6 coordinates = [0 ,0;1 ,0;1 ,1;0 ,1;2 ,0;2 ,1];
7 elements4 = [1 ,2 ,3 ,4;2 ,5 ,6 ,3];
8 while 1
9 mark4 = markCircle ( coordinates ,[] , elements4 ,C ,r , min_d );
10 mark4 = find ( mark4 );
11 [ coordinates , elements4 ] = QrefineRB ( coordinates , elements4 , mark4 );
12 if isempty ( mark4 )
13 break
14 end
15 end

4.6 Overview of Functions Provided by ameshref-Package


Our software package ameshref provides several modules. We use the following abbreviations for the input
parameters C (coordinates), E3 (elements3), E4 (elements4), I (irregular), D (dirichlet), and N (neumann)
and state the function call for each function below. The last two items are optional arguments.

4.6.1 Local Mesh Refinement

The functions for adaptive mesh refinement are called by


[C ,E3 ,I ,D ,N] = TrefineR (C , E3 ,I ,D ,N , marked )
[C ,E4 ,I ,D ,N] = QrefineR (C , E4 ,I ,D ,N , marked )
[C ,E4 ,I ,D ,N] = QrefineR2 (C , E4 ,I ,D ,N , marked )
[C ,E3 ,D ,N] = TrefineNVB (C , E3 ,D ,N , marked )
[C ,E3 ,D ,N] = TrefineRGB (C , E3 ,D ,N , marked )
[C ,E3 ,D ,N] = TrefineRG (C , E3 ,D ,N , marked )
[C ,E4 ,D ,N] = QrefineRB (C , E4 ,D ,N , marked )
QrefineRG is called in the three-step process
[C ,E4 , marked ,I ] = recoarseedges_tri (C , E3 , E4 , marked3 , marked4 )
[C ,E4 ,I ,D ,N] = QrefineR (C , E4 ,I ,D ,N , marked )
[C ,E4 , E3 ] = regularizeedges_tri (C , E4 , I )
and analogously, QrefineRG2 by
[C ,E4 , marked ,I ] = recoarseedges (C , E4 , marked4 )
[C ,E4 ,I ,D ,N] = QrefineR (C , E4 ,I ,D ,N , marked )
[C , E4 ] = regularizeedges (C , E4 , I )

Brought to you by | Columbia University Libraries


Authenticated
Download Date | 10/22/19 2:47 PM
18 | S. A. Funken and A. Schmidt, Adaptive Mesh Refinement in 2D

4.6.2 Auxiliary Functions

For the numbering of edges and the mapping to an admissible mesh, the auxiliary functions
[ edge2nodes , element3edges , element4edges , dirichlet2edges , neumann2edges ]
= provideGeometricData ( E3 , E4 ,D , N )
and
[ map , val ] = hash2map ( dec , hash )
are provided.

4.6.3 Examples and Demo Files

Numerical experiments are given in subdirectories


∙ example1/: refinement along a circle,
∙ example2/: triangulation of a picture,
∙ example3/: adaptive finite element implementation following [15], and
∙ example4/: refinement of elements indicated by a set of discrete points.

5 Numerical Experiments
To demonstrate the efficiency of the developed Matlab code, we provide some numerical experiments per-
formed on an Apple MacBook Air with a 1.6 GHz Intel Core i5, a RAM of 8 GB 1600 MHz DDR3 on Mac OS
High Sierra, version 10.13.2. Throughout, Matlab version 9.2.0 (R2017a) is used.
For the first experiment, we consider the test example described in Section 4.5, provided in example1/.
We measure 15 times the computational time by use of Matlab’s built-in function cputime and take the mean
of the measured times. The mean values for each refinement strategy are plotted in Figure 21 and show an

102
QrefineR TrefineR
QrefineRB TrefineRG
101 QrefineRG TrefineRGB
QrefineR2 TrefineNVB
QrefineRG2
Computational time [s]

100
−1

10−1
1

10−2

10−3
101 102 103 104 105 106 107
Number of elements

Figure 21: Computational times of the adaptive mesh refinements for example1/ over the number of elements. A nearly linear
behavior between the number of elements and computational time evens out for all of our implementations. The non-linear
behavior for few elements is due to Matlab’s precompiling process.

Brought to you by | Columbia University Libraries


Authenticated
Download Date | 10/22/19 2:47 PM
S. A. Funken and A. Schmidt, Adaptive Mesh Refinement in 2D | 19

Figure 22: Refinement along a circle. Elements are marked for refinement if they intersect with a given circle. From top left to
bottom right, the following refinements are used: TrefineR, TrefineRG, TrefineNVB, TrefineRGB, QrefineR, QrefineRG, QrefineRB,
QrefineR2, QrefineRG2.

QrefineR

QrefineRB

QrefineR2

TrefineR

TrefineRG

TrefineRGB

TrefineNVB

0 2 4 6 8 10 12 14 16 18 20
Number of iterations

Figure 23: Boxplot of the number of iterations in the closure process for implementations via hash maps and via virtual
elements. Considered are the first 12 runs of the refinement functions for three test examples, i.e., the number of data points
considered in the plot is 36. The number of elements during the refinement process ranges from 2 to 5 ⋅ 105 .

almost linear behavior between the number of elements and computational time. The non-linear behavior at
the beginning of the refinement process is an overlay of Matlab’s precompiling process. The refined meshes
of this example are depicted in Figure 22.
From Figure 21, we also observe that a refined mesh with 107 elements is generated within 20–30 sec-
onds. The step CLOSURE is implemented by means of a while-loop. A priori, it is not clear how often this
while-part iterates. In the worst-case scenario, the iteration would run #Tℓ − #M times if, in each closure
step, only one further element is influenced.
To get a better feeling about this uncertainty, we stored the number of iterations in the closure step
for three applications: refinement along a circle as given in example1/ and two AFEM examples given in
example3/. example2/ is not considered for this investigation as the gradient based refinement of a picture
is not the main application of this toolbox and distorts the statement due to the non-concentrated refine-

Brought to you by | Columbia University Libraries


Authenticated
Download Date | 10/22/19 2:47 PM
20 | S. A. Funken and A. Schmidt, Adaptive Mesh Refinement in 2D

ment. For this purpose, we only measured the first twelve adaptive refinements where the number of elements
ranged between 2 and 5 ⋅ 105 . Figure 23 shows the number of iterations in the closure step in dependence of
the refinement strategy. The boxplot characterizes the median of the data with a red line, the bottom and top
edges of the blue boxes indicate the 25th and 75th percentiles, respectively. Furthermore, outliers are plotted
using a red “+”-symbol, whereas the whiskers include further data points that are not considered outliers.
It is noticeable that the number of iterations is mainly concentrated between one and ten runs. There are
some outliers, but, as they are not within the whiskers, this situation only occurs rarely.
We only considered the first twelve refinements up to a number of elements of 5 ⋅ 105 . As we raise this
quantity, the outliers can also fall into a larger interval. However, even in the rare cases, the closure process
takes longer; in comparison to the implementation of the complete data structure of the refined mesh, this is
imperceptible in computation time.

References
[1] J. Alberty, C. Carstensen and S. A. Funken, Remarks around 50 lines of Matlab: Short finite element implementation,
Numer. Algorithms 20 (1999), no. 2–3, 117–137.
[2] I. Babuška and M. Vogelius, Feedback and adaptive finite element solution of one-dimensional boundary value problems,
Numer. Math. 44 (1984), no. 1, 75–102.
[3] R. E. Bank and A. H. Sherman, An adaptive, multilevel method for elliptic boundary value problems, Computing 26 (1981),
no. 2, 91–105.
[4] R. E. Bank, A. H. Sherman and A. Weiser, Refinement algorithms and data structures for regular local mesh refinement, in:
Scientific Computing (Montreal 1982), IMACS, New Brunswick (1983), 3–17.
[5] P. Binev, W. Dahmen and R. DeVore, Adaptive finite element methods with convergence rates, Numer. Math. 97 (2004),
no. 2, 219–268.
[6] D. Braess, Finite Elements: Theory, Fast Solvers, and Applications in Solid Mechanics, 3rd ed., Cambridge University Press,
Cambridge, 2007.
[7] C. Carstensen, An adaptive mesh-refining algorithm allowing for an H1 stable L2 projection onto Courant finite element
spaces, Constr. Approx. 20 (2004), no. 4, 549–564.
[8] C. Carstensen, M. Feischl, M. Page and D. Praetorius, Axioms of adaptivity, Comput. Math. Appl. 67 (2014), no. 6,
1195–1253.
[9] L. Chen, iFEM: An innovative finite element methods package in MATLAB, preprint (2008), University of Maryland.
[10] L. Chen, Short implementation of bisection in MATLAB, in: Recent Advances in Computational Sciences, World Scientific,
Hackensack (2008), 318–332.
[11] L. Chen and C. Zhang, A coarsening algorithm on adaptive grids by newest vertex bisection and its applications, J. Comput.
Math. 28 (2010), no. 6, 767–789.
[12] P. G. Ciarlet, The Finite Element Method for Elliptic Problems, Class. Appl. Math. 40, Society for Industrial and Applied
Mathematics (SIAM), Philadelphia, 2002.
[13] P. G. Ciarlet and P.-A. Raviart, Interpolation theory over curved elements, with applications to finite element methods,
Comput. Methods Appl. Mech. Engrg. 1 (1972), 217–249.
[14] W. Dörfler, A convergent adaptive algorithm for Poisson’s equation, SIAM J. Numer. Anal. 33 (1996), no. 3, 1106–1124.
[15] S. Funken, D. Praetorius and P. Wissgott, Efficient implementation of adaptive P1-FEM in Matlab, Comput. Methods Appl.
Math. 11 (2011), no. 4, 460–490.
[16] S. A. Funken and A. Schmidt, Criteria for Non-Recursive Local Coarsening in 2D, work in progress (2019).
[17] S. A. Funken and A. Schmidt, ameshref – Efficient implementation of adaptive mesh refinement in 2D, Software download
at https://github.com/aschmidtuulm/ameshref.
[18] M. Karkulik, D. Pavlicek and D. Praetorius, On 2D newest vertex bisection: Optimality of mesh-closure and H1 -stability of
L2 -projection, Constr. Approx. 38 (2013), no. 2, 213–234.
[19] L. Kobbelt, Interpolatory subdivision on open quadrilateral nets with arbitrary topology, Comput. Graph. Forum 15 (1996),
no. 3, 409–420.
[20] A. Schmidt, Adaptive mesh refinement in 2D – an efficient implementation in matlab for triangular and quadrilateral
meshes, Master’s thesis, Universität Ulm, 2018.
[21] A. Schmidt and K. G. Siebert, Design of Adaptive Finite Element Software, Lect. Notes Comput. Sci. Eng. 42, Springer,
Berlin, 2005.
[22] R. Schneiders, Mesh generation and grid generation on the web.
[23] R. Schneiders, Algorithms for quadrilateral and hexahedral mesh generation, Proc. VKI-LS Comput. Fluid Dyn. (2000).

Brought to you by | Columbia University Libraries


Authenticated
Download Date | 10/22/19 2:47 PM
S. A. Funken and A. Schmidt, Adaptive Mesh Refinement in 2D | 21

[24] E. G. Sewell, A Utomatic Generation of Triangulations for Piecewise Polynomial Approximation, ProQuest LLC, Ann Arbor,
1972; Thesis (Ph.D.)–Purdue University.
[25] R. Stevenson, Optimality of a standard adaptive finite element method, Found. Comput. Math. 7 (2007), no. 2, 245–269.
[26] R. Stevenson, The completion of locally refined simplicial partitions created by bisection, Math. Comp. 77 (2008), no. 261,
227–241.
[27] R. Verfürth, A Review of a Posteriori Error Estimation and Adaptive Mesh-refinement Techniques, John Wiley & Sons, New
York, 1996.
[28] F. Zames, Surface area and the cylinder area paradox, College Math. J. 8 (1977), no. 4, 207–211.
[29] X. Zhao, S. Mao and Z. Shi, Adaptive finite element methods on quadrilateral meshes without hanging nodes, SIAM J. Sci.
Comput. 32 (2010), no. 4, 2099–2120.

Brought to you by | Columbia University Libraries


Authenticated
Download Date | 10/22/19 2:47 PM

You might also like