D06 Chapter Contents
D06 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentD06CAF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

D06CAF uses a barycentering technique to smooth a given mesh.

## 2  Specification

 SUBROUTINE D06CAF ( NV, NELT, NEDGE, COOR, EDGE, CONN, NVFIX, NUMFIX, ITRACE, NQINT, IWORK, LIWORK, RWORK, LRWORK, IFAIL)
 INTEGER NV, NELT, NEDGE, EDGE(3,NEDGE), CONN(3,NELT), NVFIX, NUMFIX(*), ITRACE, NQINT, IWORK(LIWORK), LIWORK, LRWORK, IFAIL REAL (KIND=nag_wp) COOR(2,NV), RWORK(LRWORK)

## 3  Description

D06CAF 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.
D06CAF 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 routine 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  Parameters

1:     NV – INTEGERInput
On entry: the total number of vertices in the input mesh.
Constraint: ${\mathbf{NV}}\ge 3$.
2:     NELT – INTEGERInput
On entry: the number of triangles in the input mesh.
Constraint: ${\mathbf{NELT}}\le 2×{\mathbf{NV}}-1$.
3:     NEDGE – INTEGERInput
On entry: the number of the boundary and interface edges in the input mesh.
Constraint: ${\mathbf{NEDGE}}\ge 1$.
4:     COOR($2$,NV) – REAL (KIND=nag_wp) arrayInput/Output
On entry: ${\mathbf{COOR}}\left(1,\mathit{i}\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(2,\mathit{i}\right)$ contains the corresponding $y$ coordinate.
On exit: ${\mathbf{COOR}}\left(1,\mathit{i}\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(2,\mathit{i}\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:     EDGE($3$,NEDGE) – INTEGER arrayInput
On entry: the specification of the boundary or interface 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 or interface edge: ${\mathbf{EDGE}}\left(3,j\right)=0$ for an interior edge and has a nonzero tag otherwise.
Constraint: $1\le {\mathbf{EDGE}}\left(\mathit{i},\mathit{j}\right)\le {\mathbf{NV}}$ 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}}$.
6:     CONN($3$,NELT) – INTEGER arrayInput
On entry: 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}}$.
Constraint: $1\le {\mathbf{CONN}}\left(\mathit{i},\mathit{j}\right)\le {\mathbf{NV}}$ and ${\mathbf{CONN}}\left(1,\mathit{j}\right)\ne {\mathbf{CONN}}\left(2,\mathit{j}\right)$ and ${\mathbf{CONN}}\left(1,\mathit{j}\right)\ne {\mathbf{CONN}}\left(3,\mathit{j}\right)$ and ${\mathbf{CONN}}\left(2,\mathit{j}\right)\ne {\mathbf{CONN}}\left(3,\mathit{j}\right)$, for $\mathit{i}=1,2,3$ and $\mathit{j}=1,2,\dots ,{\mathbf{NELT}}$.
7:     NVFIX – INTEGERInput
On entry: the number of fixed vertices in the input mesh.
Constraint: $0\le {\mathbf{NVFIX}}\le {\mathbf{NV}}$.
8:     NUMFIX($*$) – INTEGER arrayInput
Note: the dimension 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}\right)\le {\mathbf{NV}}$, for $\mathit{i}=1,2,\dots ,{\mathbf{NVFIX}}$.
9:     ITRACE – INTEGERInput
On entry: the level of trace information required from D06CAF.
${\mathbf{ITRACE}}\le 0$
No output is generated.
${\mathbf{ITRACE}}=1$
A histogram of the triangular element qualities is printed on the current advisory message unit (see X04ABF) 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:   NQINT – INTEGERInput
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.
11:   IWORK(LIWORK) – INTEGER arrayWorkspace
12:   LIWORK – INTEGERInput
On entry: the dimension of the array IWORK as declared in the (sub)program from which D06CAF is called.
Constraint: ${\mathbf{LIWORK}}\ge 8×{\mathbf{NELT}}+2×{\mathbf{NV}}$.
13:   RWORK(LRWORK) – REAL (KIND=nag_wp) arrayWorkspace
14:   LRWORK – INTEGERInput
On entry: the dimension of the array RWORK as declared in the (sub)program from which D06CAF is called.
Constraint: ${\mathbf{LRWORK}}\ge 2×{\mathbf{NV}}+{\mathbf{NELT}}$.
15:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
 On entry, ${\mathbf{NV}}<3$, or ${\mathbf{NELT}}>2×{\mathbf{NV}}-1$, or ${\mathbf{NEDGE}}<1$, or ${\mathbf{EDGE}}\left(i,j\right)<1$ or ${\mathbf{EDGE}}\left(i,j\right)>{\mathbf{NV}}$ 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{CONN}}\left(i,j\right)<1$ or ${\mathbf{CONN}}\left(i,j\right)>{\mathbf{NV}}$ for some $i=1,2,3$ and $j=1,2,\dots ,{\mathbf{NELT}}$, or ${\mathbf{CONN}}\left(1,j\right)={\mathbf{CONN}}\left(2,j\right)$ or ${\mathbf{CONN}}\left(1,j\right)={\mathbf{CONN}}\left(3,j\right)$ or ${\mathbf{CONN}}\left(2,j\right)={\mathbf{CONN}}\left(3,j\right)$ for some $j=1,2,\dots ,{\mathbf{NELT}}$, or ${\mathbf{NVFIX}}<0$ or ${\mathbf{NVFIX}}>{\mathbf{NV}}$, or ${\mathbf{NUMFIX}}\left(i\right)<1$ or ${\mathbf{NUMFIX}}\left(i\right)>{\mathbf{NV}}$ for some $i=1,2,\dots ,{\mathbf{NVFIX}}$ if ${\mathbf{NVFIX}}>0$, or ${\mathbf{LIWORK}}<8×{\mathbf{NELT}}+2×{\mathbf{NV}}$, or ${\mathbf{LRWORK}}<2×{\mathbf{NV}}+{\mathbf{NELT}}$.
${\mathbf{IFAIL}}=2$
A serious error has occurred in an internal call to an auxiliary routine. Check the input mesh, especially the connectivity between triangles and vertices (the parameter CONN). Setting ${\mathbf{ITRACE}}>1$ may provide more information. If the problem persists, contact NAG.

Not applicable.

None.

## 9  Example

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

### 9.1  Program Text

Program Text (d06cafe.f90)

### 9.2  Program Data

Program Data (d06cafe.d)

### 9.3  Program Results

Program Results (d06cafe.r)