d06 Chapter Contents
d06 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_mesh2d_inc (d06aac)

## 1  Purpose

nag_mesh2d_inc (d06aac) generates a triangular mesh of a closed polygonal region in ${ℝ}^{2}$, given a mesh of its boundary. It uses a simple incremental method.

## 2  Specification

 #include #include
 void nag_mesh2d_inc (Integer nvb, Integer nvmax, Integer nedge, const Integer edge[], Integer *nv, Integer *nelt, double coor[], Integer conn[], const double bspace[], Nag_Boolean smooth, double coef, double power, Integer itrace, const char *outfile, NagError *fail)

## 3  Description

nag_mesh2d_inc (d06aac) generates the set of interior vertices using a process based on a simple incremental method. A smoothing of the mesh is optionally available. For more details about the triangulation method, consult the d06 Chapter Introduction as well as George and Borouchaki (1998).
This function is derived from material in the MODULEF package from INRIA (Institut National de Recherche en Informatique et Automatique).

## 4  References

George P L and Borouchaki H (1998) Delaunay Triangulation and Meshing: Application to Finite Elements Editions HERMES, Paris

## 5  Arguments

1:     nvbIntegerInput
On entry: the number of vertices in the input boundary mesh.
Constraint: $3\le {\mathbf{nvb}}\le {\mathbf{nvmax}}$.
2:     nvmaxIntegerInput
On entry: the maximum number of vertices in the mesh to be generated.
3:     nedgeIntegerInput
On entry: the number of boundary edges in the input mesh.
Constraint: ${\mathbf{nedge}}\ge 1$.
4:     edge[$3×{\mathbf{nedge}}$]const IntegerInput
On entry: the specification of the boundary edges. ${\mathbf{edge}}\left[\left(j-1\right)×3+0\right]$ and ${\mathbf{edge}}\left[\left(j-1\right)×3+1\right]$ contain the vertex numbers of the two end points of the $j$th boundary edge. ${\mathbf{edge}}\left[\left(j-1\right)×3+2\right]$ is a user-supplied tag for the $j$th boundary edge and is not used by nag_mesh2d_inc (d06aac). Note that the edge vertices are numbered from $1$ to nvb.
Constraint: $1\le {\mathbf{edge}}\left[\left(\mathit{j}-1\right)×3+\mathit{i}-1\right]\le {\mathbf{nvb}}$ and ${\mathbf{edge}}\left[\left(\mathit{j}-1\right)×3+0\right]\ne {\mathbf{edge}}\left[\left(\mathit{j}-1\right)×3+1\right]$, for $\mathit{i}=1,2$ and $\mathit{j}=1,2,\dots ,{\mathbf{nedge}}$.
5:     nvInteger *Output
On exit: the total number of vertices in the output mesh (including both boundary and interior vertices). If ${\mathbf{nvb}}={\mathbf{nvmax}}$, no interior vertices will be generated and ${\mathbf{nv}}={\mathbf{nvb}}$.
6:     neltInteger *Output
On exit: the number of triangular elements in the mesh.
7:     coor[$2×{\mathbf{nvmax}}$]doubleInput/Output
On entry: ${\mathbf{coor}}\left[\left(\mathit{i}-1\right)×2+0\right]$ contains the $x$ coordinate of the $\mathit{i}$th input boundary mesh vertex; while ${\mathbf{coor}}\left[\left(\mathit{i}-1\right)×2+1\right]$ contains the corresponding $y$ coordinate, for $\mathit{i}=1,2,\dots ,{\mathbf{nvb}}$.
On exit: ${\mathbf{coor}}\left[\left(\mathit{i}-1\right)×2+0\right]$ will contain the $x$ coordinate of the $\left(\mathit{i}-{\mathbf{nvb}}\right)$th generated interior mesh vertex; while ${\mathbf{coor}}\left[\left(\mathit{i}-1\right)×2+1\right]$ will contain the corresponding $y$ coordinate, for $\mathit{i}={\mathbf{nvb}}+1,\dots ,{\mathbf{nv}}$. The remaining elements are unchanged.
8:     conn[$3×2×\left({\mathbf{nvmax}}-1\right)$]IntegerOutput
On exit: the connectivity of the mesh between triangles and vertices. For each triangle $\mathit{j}$, ${\mathbf{conn}}\left[\left(\mathit{j}-1\right)×3+\mathit{i}-1\right]$ gives the indices of its three vertices (in anticlockwise order), for $\mathit{i}=1,2,3$ and $\mathit{j}=1,2,\dots ,{\mathbf{nelt}}$. Note that the mesh vertices are numbered from $1$ to nv.
9:     bspace[nvb]const doubleInput
On entry: the desired mesh spacing (triangle diameter, which is the length of the longer edge of the triangle) near the boundary vertices.
Constraint: ${\mathbf{bspace}}\left[\mathit{i}-1\right]>0.0$, for $\mathit{i}=1,2,\dots ,{\mathbf{nvb}}$.
10:   smoothNag_BooleanInput
On entry: indicates whether or not mesh smoothing should be performed.
If ${\mathbf{smooth}}=\mathrm{Nag_TRUE}$, the smoothing is performed; otherwise no smoothing is performed.
11:   coefdoubleInput
On entry: the coefficient in the stopping criteria for the generation of interior vertices. This argument controls the triangle density and the number of triangles generated is in $\mathit{O}\left({{\mathbf{coef}}}^{2}\right)$. The mesh will be finer if coef is greater than $0.7165$ and $0.75$ is a good value.
Suggested value: $0.75$.
12:   powerdoubleInput
On entry: controls the rate of change of the mesh size during the generation of interior vertices. The smaller the value of power, the faster the decrease in element size away from the boundary.
Suggested value: $0.25$.
Constraint: $0.1\le {\mathbf{power}}\le 10.0$.
13:   itraceIntegerInput
On entry: the level of trace information required from nag_mesh2d_inc (d06aac).
${\mathbf{itrace}}\le 0$
No output is generated.
${\mathbf{itrace}}\ge 1$
Output from the meshing solver is printed. This output contains details of the vertices and triangles generated by the process.
You are advised to set ${\mathbf{itrace}}=0$, unless you are experienced with finite element mesh generation.
14:   outfileconst char *Input
On entry: the name of a file to which diagnostic output will be directed. If outfile is NULL the diagnostic output will be directed to standard output.
15:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_INT
On entry, ${\mathbf{nedge}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nedge}}\ge 1$.
NE_INT_2
On entry, ${\mathbf{nvb}}=〈\mathit{\text{value}}〉$ and ${\mathbf{nvmax}}=〈\mathit{\text{value}}〉$.
Constraint: $3\le {\mathbf{nvb}}\le {\mathbf{nvmax}}$.
On entry, the endpoints of the edge $j$ have the same index $i$: $j=〈\mathit{\text{value}}〉$ and $i=〈\mathit{\text{value}}〉$.
NE_INT_4
On entry, ${\mathbf{EDGE}}\left(i,j\right)=〈\mathit{\text{value}}〉$, $i=〈\mathit{\text{value}}〉$, $j=〈\mathit{\text{value}}〉$ and ${\mathbf{nvb}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{EDGE}}\left(i,j\right)\ge 1$ and ${\mathbf{EDGE}}\left(i,j\right)\le {\mathbf{nvb}}$, where ${\mathbf{EDGE}}\left(i,j\right)$ denotes ${\mathbf{edge}}\left[\left(j-1\right)×3+i-1\right]$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
NE_MESH_ERROR
An error has occurred during the generation of the interior mesh. Check the inputs of the boundary.
NE_NOT_CLOSE_FILE
Cannot close file $〈\mathit{\text{value}}〉$.
NE_NOT_WRITE_FILE
Cannot open file $〈\mathit{\text{value}}〉$ for writing.
NE_REAL
On entry, ${\mathbf{power}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{power}}\le 10.0$.
On entry, ${\mathbf{power}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{power}}\ge 0.1$.
NE_REAL_ARRAY_INPUT
On entry, ${\mathbf{bspace}}\left[i-1\right]=〈\mathit{\text{value}}〉$ and $i=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{bspace}}\left[i-1\right]>0.0$.

## 7  Accuracy

Not applicable.

The position of the internal vertices is a function of the positions of the vertices on the given boundary. A fine mesh on the boundary results in a fine mesh in the interior. The algorithm allows you to obtain a denser interior mesh by varying nvmax, bspace, coef and power. But you are advised to manipulate the last two arguments with care.
You are advised to take care to set the boundary inputs properly, especially for a boundary with multiply connected components. The orientation of the interior boundaries should be in clockwise order and opposite to that of the exterior boundary. If the boundary has only one connected component, its orientation should be anticlockwise.

## 9  Example

In this example, a geometry with two holes (two interior circles inside an exterior one) is meshed using the simple incremental method (see the d06 Chapter Introduction). The exterior circle is centred at the origin with a radius $1.0$, the first interior circle is centred at the point $\left(-0.5,0.0\right)$ with a radius $0.49$, and the second one is centred at the point $\left(-0.5,0.65\right)$ with a radius $0.15$. Note that the points $\left(-1.0,0.0\right)$ and $\left(-0.5,0.5\right)$) are points of ‘near tangency’ between the exterior circle and the first and second circles.
The boundary mesh has $100$ vertices and $100$ edges (see Figure 1). Note that the particular mesh generated could be sensitive to the machine precision and therefore may differ from one implementation to another. Figure 2 contains the output mesh.

### 9.1  Program Text

Program Text (d06aace.c)

### 9.2  Program Data

Program Data (d06aace.d)

### 9.3  Program Results

Program Results (d06aace.r)

Figure 1: The boundary mesh of the geometry with two holes
Figure 2: Interior mesh of the geometry with two holes