Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_mesh_2d_gen_inc (d06aa)

## Purpose

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

## Syntax

[nv, nelt, coor, conn, ifail] = d06aa(edge, coor, bspace, smooth, itrace, 'nvb', nvb, 'nvmax', nvmax, 'nedge', nedge, 'coef', coef, 'power', power)
[nv, nelt, coor, conn, ifail] = nag_mesh_2d_gen_inc(edge, coor, bspace, smooth, itrace, 'nvb', nvb, 'nvmax', nvmax, 'nedge', nedge, 'coef', coef, 'power', power)

## Description

nag_mesh_2d_gen_inc (d06aa) 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).

## References

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

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{edge}\left(3,{\mathbf{nedge}}\right)$int64int32nag_int array
The specification of the boundary edges. ${\mathbf{edge}}\left(1,j\right)$ and ${\mathbf{edge}}\left(2,j\right)$ contain the vertex numbers of the two end points of the $j$th boundary edge. ${\mathbf{edge}}\left(3,j\right)$ is a user-supplied tag for the $j$th boundary edge and is not used by nag_mesh_2d_gen_inc (d06aa).
Constraint: $1\le {\mathbf{edge}}\left(\mathit{i},\mathit{j}\right)\le {\mathbf{nvb}}$ and ${\mathbf{edge}}\left(1,\mathit{j}\right)\ne {\mathbf{edge}}\left(2,\mathit{j}\right)$, for $\mathit{i}=1,2$ and $\mathit{j}=1,2,\dots ,{\mathbf{nedge}}$.
2:     $\mathrm{coor}\left(2,{\mathbf{nvmax}}\right)$ – double array
${\mathbf{coor}}\left(1,\mathit{i}\right)$ contains the $x$ coordinate of the $\mathit{i}$th input boundary mesh vertex; while ${\mathbf{coor}}\left(2,\mathit{i}\right)$ contains the corresponding $y$ coordinate, for $\mathit{i}=1,2,\dots ,{\mathbf{nvb}}$.
3:     $\mathrm{bspace}\left({\mathbf{nvb}}\right)$ – double array
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}\right)>0.0$, for $\mathit{i}=1,2,\dots ,{\mathbf{nvb}}$.
4:     $\mathrm{smooth}$ – logical scalar
Indicates whether or not mesh smoothing should be performed.
If ${\mathbf{smooth}}=\mathit{true}$, the smoothing is performed; otherwise no smoothing is performed.
5:     $\mathrm{itrace}$int64int32nag_int scalar
The level of trace information required from nag_mesh_2d_gen_inc (d06aa).
${\mathbf{itrace}}\le 0$
No output is generated.
${\mathbf{itrace}}\ge 1$
Output from the meshing solver is printed on the current advisory message unit (see nag_file_set_unit_advisory (x04ab)). 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.

### Optional Input Parameters

1:     $\mathrm{nvb}$int64int32nag_int scalar
Default: the dimension of the array bspace.
The number of vertices in the input boundary mesh.
Constraint: $3\le {\mathbf{nvb}}\le {\mathbf{nvmax}}$.
2:     $\mathrm{nvmax}$int64int32nag_int scalar
Default: the dimension of the array coor.
The maximum number of vertices in the mesh to be generated.
3:     $\mathrm{nedge}$int64int32nag_int scalar
Default: the dimension of the array edge.
The number of boundary edges in the input mesh.
Constraint: ${\mathbf{nedge}}\ge 1$.
4:     $\mathrm{coef}$ – double scalar
Default: $0.75$.
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.
5:     $\mathrm{power}$ – double scalar
Default: $0.25$.
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.
Constraint: $0.1\le {\mathbf{power}}\le 10.0$.

### Output Parameters

1:     $\mathrm{nv}$int64int32nag_int scalar
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}}$.
2:     $\mathrm{nelt}$int64int32nag_int scalar
The number of triangular elements in the mesh.
3:     $\mathrm{coor}\left(2,{\mathbf{nvmax}}\right)$ – double array
${\mathbf{coor}}\left(1,\mathit{i}\right)$ will contain the $x$ coordinate of the $\left(\mathit{i}-{\mathbf{nvb}}\right)$th generated interior mesh vertex; while ${\mathbf{coor}}\left(2,\mathit{i}\right)$ will contain the corresponding $y$ coordinate, for $\mathit{i}={\mathbf{nvb}}+1,\dots ,{\mathbf{nv}}$. The remaining elements are unchanged.
4:     $\mathrm{conn}\left(3,2×\left({\mathbf{nvmax}}-1\right)\right)$int64int32nag_int array
The connectivity of the mesh between triangles and vertices. For each triangle $\mathit{j}$, ${\mathbf{conn}}\left(\mathit{i},\mathit{j}\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}}$.
5:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Errors or warnings detected by the function:
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{nvb}}<3$ or ${\mathbf{nvb}}>{\mathbf{nvmax}}$, or ${\mathbf{nedge}}<1$, or ${\mathbf{edge}}\left(i,j\right)<1$ or ${\mathbf{edge}}\left(i,j\right)>{\mathbf{nvb}}$, for some $i=1,2$ and $j=1,2,\dots ,{\mathbf{nedge}}$, or ${\mathbf{edge}}\left(1,j\right)={\mathbf{edge}}\left(2,j\right)$, for some $j=1,2,\dots ,{\mathbf{nedge}}$, or ${\mathbf{bspace}}\left(i\right)\le 0.0$, for some $i=1,2,\dots ,{\mathbf{nvb}}$, or ${\mathbf{power}}<0.1$ or ${\mathbf{power}}>10.0$, or $\mathit{liwork}<16×{\mathbf{nvmax}}+2×{\mathbf{nedge}}+\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(4×{\mathbf{nvmax}}+2,{\mathbf{nedge}}\right)-14$, or $\mathit{lrwork}<{\mathbf{nvmax}}$.
${\mathbf{ifail}}=2$
An error has occurred during the generation of the interior mesh. Check the definition of the boundary (arguments coor and edge) as well as the orientation of the boundary (especially in the case of a multiple connected component boundary). Setting ${\mathbf{itrace}}>0$ may provide more details.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## 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.

## 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. Note that the particular mesh generated could be sensitive to the machine precision and therefore may differ from one implementation to another.
```function d06aa_example

fprintf('d06aa example results\n\n');

edge = zeros(3, 100, 'int64');
coor = zeros(2, 250);

% Define boundaries
ncirc     = 3; % 3 circles
nvertices = [40, 30, 30];
centres   = [ 0,   0;
-0.5, 0;
-0.5, 0.65];

% First circle is outer circle
csign = 1;
i1 = 0;
nvb = 0;
for icirc = 1:ncirc
for i = 0:nvertices(icirc)-1
i1 = i1+1;
theta = 2*pi*i/nvertices(icirc);
coor(1,i1) = radii(icirc)*cos(theta) + centres(icirc, 1);
coor(2,i1) = csign*radii(icirc)*sin(theta) +  centres(icirc, 2);
edge(1,i1) = i1;
edge(2,i1) = i1 + 1;
edge(3,i1) = 1;
end
edge(2,i1) = nvb + 1;
nvb = nvb + nvertices(icirc);
% Subsequent circles are inner circles
csign = -1;
end
nedge = nvb;

% Initialise mesh control parameters
bspace = zeros(1, 100);
bspace(1:nvb) = 0.05;
smooth = true;
itrace = int64(0);

[nv, nelt, coor, conn, ifail] = d06aa( ...
edge, coor, bspace, smooth, itrace);
fprintf('\nnv   = %d\n', nv);
fprintf('nelt = %d\n', nelt);
% Plot mesh
fig1 = figure;
triplot(transpose(double(conn(:,1:nelt))), coor(1,:), coor(2,:));
axis equal;

```
```d06aa example results

nv   = 250
nelt = 402
```