# NAG CL Interfaced06cac (dim2_​smooth_​bary)

## 1Purpose

d06cac uses a barycentering technique to smooth a given mesh.

## 2Specification

 #include
 void d06cac (Integer nv, Integer nelt, Integer nedge, double coor[], const Integer edge[], const Integer conn[], Integer nvfix, const Integer numfix[], Integer itrace, const char *outfile, Integer nqint, NagError *fail)
The function may be called by the names: d06cac, nag_mesh_dim2_smooth_bary or nag_mesh2d_smooth.

## 3Description

d06cac uses a barycentering approach to improve the smoothness of a given mesh. The measure of quality used for a triangle $K$ is
 $QK=αhKρK;$
where ${h}_{K}$ is the diameter (length of the longest edge) of $K$, ${\rho }_{K}$ is the radius of its inscribed circle and $\alpha =\frac{\sqrt{3}}{6}$ is a normalization factor chosen to give ${Q}_{K}=1$ for an equilateral triangle. ${Q}_{K}$ ranges from $1$, for an equilateral triangle, to $\infty$, for a totally flat triangle.
d06cac makes small perturbation to vertices (using a barycenter formula) in order to give a reasonably good value of ${Q}_{K}$ for all neighbouring triangles. Some vertices may optionally be excluded from this process.
For more details about the smoothing method, especially with regard to differing quality, 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).

## 4References

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

## 5Arguments

1: $\mathbf{nv}$Integer Input
On entry: the total number of vertices in the input mesh.
Constraint: ${\mathbf{nv}}\ge 3$.
2: $\mathbf{nelt}$Integer Input
On entry: the number of triangles in the input mesh.
Constraint: ${\mathbf{nelt}}\le 2×{\mathbf{nv}}-1$.
3: $\mathbf{nedge}$Integer Input
On entry: the number of the boundary and interface edges in the input mesh.
Constraint: ${\mathbf{nedge}}\ge 1$.
4: $\mathbf{coor}\left[2×{\mathbf{nv}}\right]$double Input/Output
Note: the $\left(i,j\right)$th element of the matrix is stored in ${\mathbf{coor}}\left[\left(j-1\right)×2+i-1\right]$.
On entry: ${\mathbf{coor}}\left[\left(\mathit{i}-1\right)×2\right]$ contains the $x$ coordinate of the $\mathit{i}$th input mesh vertex, for $\mathit{i}=1,2,\dots ,{\mathbf{nv}}$; while ${\mathbf{coor}}\left[\left(\mathit{i}-1\right)×2+1\right]$ contains the corresponding $y$ coordinate.
On exit: ${\mathbf{coor}}\left[\left(\mathit{i}-1\right)×2\right]$ will contain the $x$ coordinate of the $\mathit{i}$th smoothed mesh vertex, for $\mathit{i}=1,2,\dots ,{\mathbf{nv}}$; while ${\mathbf{coor}}\left[\left(\mathit{i}-1\right)×2+1\right]$ will contain the corresponding $y$ coordinate. Note that the coordinates of boundary and interface edge vertices, as well as those specified by you (see the description of numfix), are unchanged by the process.
5: $\mathbf{edge}\left[3×{\mathbf{nedge}}\right]$const Integer Input
Note: the $\left(i,j\right)$th element of the matrix is stored in ${\mathbf{edge}}\left[\left(j-1\right)×3+i-1\right]$.
On entry: the specification of the boundary or interface edges. ${\mathbf{edge}}\left[\left(j-1\right)×3\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 or interface edge: ${\mathbf{edge}}\left[\left(j-1\right)×3+2\right]=0$ for an interior edge and has a nonzero tag otherwise. Note that the edge vertices are numbered from $1$ to nv.
Constraint: $1\le {\mathbf{edge}}\left[\left(\mathit{j}-1\right)×3+\mathit{i}-1\right]\le {\mathbf{nv}}$ and ${\mathbf{edge}}\left[\left(\mathit{j}-1\right)×3\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}}$.
6: $\mathbf{conn}\left[3×{\mathbf{nelt}}\right]$const Integer Input
Note: the $\left(i,j\right)$th element of the matrix is stored in ${\mathbf{conn}}\left[\left(j-1\right)×3+i-1\right]$.
On entry: 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.
Constraint: $1\le {\mathbf{conn}}\left[\left(\mathit{j}-1\right)×3+\mathit{i}-1\right]\le {\mathbf{nv}}$ and ${\mathbf{conn}}\left[\left(\mathit{j}-1\right)×3\right]\ne {\mathbf{conn}}\left[\left(\mathit{j}-1\right)×3+1\right]$ and ${\mathbf{conn}}\left[\left(\mathit{j}-1\right)×3\right]\ne {\mathbf{conn}}\left[\left(\mathit{j}-1\right)×3+2\right]$ and ${\mathbf{conn}}\left[\left(\mathit{j}-1\right)×3+1\right]\ne {\mathbf{conn}}\left[\left(\mathit{j}-1\right)×3+2\right]$, for $\mathit{i}=1,2,3$ and $\mathit{j}=1,2,\dots ,{\mathbf{nelt}}$.
7: $\mathbf{nvfix}$Integer Input
On entry: the number of fixed vertices in the input mesh.
Constraint: $0\le {\mathbf{nvfix}}\le {\mathbf{nv}}$.
8: $\mathbf{numfix}\left[\mathit{dim}\right]$const Integer Input
Note: the dimension, dim, of the array numfix must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{nvfix}}\right)$.
On entry: the indices in coor of fixed interior vertices of the input mesh.
Constraint: if ${\mathbf{nvfix}}>0$, $1\le {\mathbf{numfix}}\left[\mathit{i}-1\right]\le {\mathbf{nv}}$, for $\mathit{i}=1,2,\dots ,{\mathbf{nvfix}}$.
9: $\mathbf{itrace}$Integer Input
On entry: the level of trace information required from d06cac.
${\mathbf{itrace}}\le 0$
No output is generated.
${\mathbf{itrace}}=1$
A histogram of the triangular element qualities is printed before and after smoothing. This histogram gives the lowest and the highest triangle quality as well as the number of elements lying in each of the nqint equal intervals between the extremes.
${\mathbf{itrace}}>1$
The output is similar to that produced when ${\mathbf{itrace}}=1$ but the connectivity between vertices and triangles (for each vertex, the list of triangles in which it appears) is given.
You are advised to set ${\mathbf{itrace}}=0$, unless you are experienced with finite element meshes.
10: $\mathbf{outfile}$const 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.
11: $\mathbf{nqint}$Integer Input
On entry: the number of intervals between the extreme quality values for the input and the smoothed mesh.
If ${\mathbf{itrace}}=0$, nqint is not referenced.
12: $\mathbf{fail}$NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_INT
On entry, ${\mathbf{nedge}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nedge}}\ge 1$.
On entry, ${\mathbf{nv}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nv}}\ge 3$.
NE_INT_2
On entry, ${\mathbf{nelt}}=〈\mathit{\text{value}}〉$ and ${\mathbf{nv}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nelt}}\le 2×{\mathbf{nv}}-1$.
On entry, ${\mathbf{nv}}=〈\mathit{\text{value}}〉$ and ${\mathbf{nvfix}}=〈\mathit{\text{value}}〉$.
Constraint: $0\le {\mathbf{nvfix}}\le {\mathbf{nv}}$.
On entry, the end points of the edge $\mathit{J}$ have the same index $\mathit{I}$: $\mathit{J}=〈\mathit{\text{value}}〉$ and $\mathit{I}=〈\mathit{\text{value}}〉$.
On entry, vertices $1$ and $2$ of the triangle $\mathit{K}$ have the same index $\mathit{I}$: $\mathit{K}=〈\mathit{\text{value}}〉$ and $\mathit{I}=〈\mathit{\text{value}}〉$.
On entry, vertices $1$ and $3$ of the triangle $\mathit{K}$ have the same index $\mathit{I}$: $\mathit{K}=〈\mathit{\text{value}}〉$ and $\mathit{I}=〈\mathit{\text{value}}〉$.
On entry, vertices $2$ and $3$ of the triangle $\mathit{K}$ have the same index $\mathit{I}$: $\mathit{K}=〈\mathit{\text{value}}〉$ and $\mathit{I}=〈\mathit{\text{value}}〉$.
NE_INT_3
On entry, ${\mathbf{numfix}}\left[\mathit{I}-1\right]=〈\mathit{\text{value}}〉$, $\mathit{I}=〈\mathit{\text{value}}〉$ and ${\mathbf{nv}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{numfix}}\left[\mathit{I}-1\right]\ge 1$ and ${\mathbf{numfix}}\left[\mathit{I}-1\right]\le {\mathbf{nv}}$.
NE_INT_4
On entry, ${\mathbf{conn}}\left(\mathit{I},\mathit{J}\right)=〈\mathit{\text{value}}〉$, $\mathit{I}=〈\mathit{\text{value}}〉$, $\mathit{J}=〈\mathit{\text{value}}〉$ and ${\mathbf{nv}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{conn}}\left(\mathit{I},\mathit{J}\right)\ge 1$ and ${\mathbf{conn}}\left(\mathit{I},\mathit{J}\right)\le {\mathbf{nv}}$, where ${\mathbf{conn}}\left(\mathit{I},\mathit{J}\right)$ denotes ${\mathbf{conn}}\left[\left(\mathit{J}-1\right)×3+\mathit{I}-1\right]$.
On entry, ${\mathbf{edge}}\left(\mathit{I},\mathit{J}\right)=〈\mathit{\text{value}}〉$, $\mathit{I}=〈\mathit{\text{value}}〉$, $\mathit{J}=〈\mathit{\text{value}}〉$ and ${\mathbf{nv}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{edge}}\left(\mathit{I},\mathit{J}\right)\ge 1$ and ${\mathbf{edge}}\left(\mathit{I},\mathit{J}\right)\le {\mathbf{nv}}$, where ${\mathbf{edge}}\left(\mathit{I},\mathit{J}\right)$ denotes ${\mathbf{edge}}\left[\left(\mathit{J}-1\right)×3+\mathit{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.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
A serious error has occurred in an internal call to an auxiliary function. Check the input mesh, especially the connectivity between triangles and vertices (the argument conn). Setting ${\mathbf{itrace}}>1$ may provide more information. If the problem persists, contact NAG.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
NE_NOT_CLOSE_FILE
Cannot close file $〈\mathit{\text{value}}〉$.
NE_NOT_WRITE_FILE
Cannot open file $〈\mathit{\text{value}}〉$ for writing.

Not applicable.

## 8Parallelism and Performance

d06cac makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

None.

## 10Example

In this example, a uniform mesh on the unit square is randomly distorted using functions from Chapter G05. d06cac is then used to smooth the distorted mesh and recover a uniform mesh.

### 10.1Program Text

Program Text (d06cace.c)

### 10.2Program Data

Program Data (d06cace.d)

### 10.3Program Results

Program Results (d06cace.r)