# NAG Library Routine Document

## 1Purpose

d06caf uses a barycentering technique to smooth a given mesh.

## 2Specification

Fortran Interface
 Subroutine d06caf ( nv, nelt, coor, edge, conn,
 Integer, Intent (In) :: nv, nelt, nedge, edge(3,nedge), conn(3,nelt), nvfix, numfix(*), itrace, nqint, liwork, lrwork Integer, Intent (Inout) :: ifail Integer, Intent (Out) :: iwork(liwork) Real (Kind=nag_wp), Intent (Inout) :: coor(2,nv) Real (Kind=nag_wp), Intent (Out) :: rwork(lrwork)
#include nagmk26.h
 void d06caf_ (const Integer *nv, const Integer *nelt, const Integer *nedge, double coor[], const Integer edge[], const Integer conn[], const Integer *nvfix, const Integer numfix[], const Integer *itrace, const Integer *nqint, Integer iwork[], const Integer *liwork, double rwork[], const Integer *lrwork, Integer *ifail)

## 3Description

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

## 4References

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

## 5Arguments

1:     $\mathbf{nv}$ – IntegerInput
On entry: the total number of vertices in the input mesh.
Constraint: ${\mathbf{nv}}\ge 3$.
2:     $\mathbf{nelt}$ – IntegerInput
On entry: the number of triangles in the input mesh.
Constraint: ${\mathbf{nelt}}\le 2×{\mathbf{nv}}-1$.
3:     $\mathbf{nedge}$ – IntegerInput
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)$ – 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:     $\mathbf{edge}\left(3,{\mathbf{nedge}}\right)$ – 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:     $\mathbf{conn}\left(3,{\mathbf{nelt}}\right)$ – 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:     $\mathbf{nvfix}$ – IntegerInput
On entry: the number of fixed vertices in the input mesh.
Constraint: $0\le {\mathbf{nvfix}}\le {\mathbf{nv}}$.
8:     $\mathbf{numfix}\left(*\right)$ – 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:     $\mathbf{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:   $\mathbf{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:   $\mathbf{iwork}\left({\mathbf{liwork}}\right)$ – Integer arrayWorkspace
12:   $\mathbf{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:   $\mathbf{rwork}\left({\mathbf{lrwork}}\right)$ – Real (Kind=nag_wp) arrayWorkspace
14:   $\mathbf{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:   $\mathbf{ifail}$ – IntegerInput/Output
On entry: ifail must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation 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 argument, 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).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-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 argument conn). Setting ${\mathbf{itrace}}>1$ may provide more information. If the problem persists, contact NAG.
${\mathbf{ifail}}=-99$
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

Not applicable.

## 8Parallelism and Performance

d06caf 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 routine. 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 routines from Chapter G05. d06caf is then used to smooth the distorted mesh and recover a uniform mesh.

### 10.1Program Text

Program Text (d06cafe.f90)

### 10.2Program Data

Program Data (d06cafe.d)

### 10.3Program Results

Program Results (d06cafe.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017