# NAG Library Routine Document

## 1Purpose

d06dbf joins together (restitches) two adjacent, or overlapping, meshes.

## 2Specification

Fortran Interface
 Subroutine d06dbf ( eps, nv1, nv2, nv3,
 Integer, Intent (In) :: nv1, nelt1, nedge1, edge1(3,nedge1), conn1(3,nelt1), reft1(nelt1), nv2, nelt2, nedge2, edge2(3,nedge2), conn2(3,nelt2), reft2(nelt2), itrace, liwork Integer, Intent (Inout) :: edge3(3,*), conn3(3,*), reft3(*), ifail Integer, Intent (Out) :: nv3, nelt3, nedge3, iwork(liwork) Real (Kind=nag_wp), Intent (In) :: eps, coor1(2,nv1), coor2(2,nv2) Real (Kind=nag_wp), Intent (Inout) :: coor3(2,*)
#include nagmk26.h
 void d06dbf_ (const double *eps, const Integer *nv1, const Integer *nelt1, const Integer *nedge1, const double coor1[], const Integer edge1[], const Integer conn1[], const Integer reft1[], const Integer *nv2, const Integer *nelt2, const Integer *nedge2, const double coor2[], const Integer edge2[], const Integer conn2[], const Integer reft2[], Integer *nv3, Integer *nelt3, Integer *nedge3, double coor3[], Integer edge3[], Integer conn3[], Integer reft3[], const Integer *itrace, Integer iwork[], const Integer *liwork, Integer *ifail)

## 3Description

d06dbf joins together two adjacent, or overlapping, meshes. If the two meshes are adjacent then vertices belonging to the part of the boundary forming the common interface should coincide. If the two meshes overlap then vertices and triangles in the overlapping zone should coincide too.
This routine is partly derived from material in the MODULEF package from INRIA (Institut National de Recherche en Informatique et Automatique).

None.

## 5Arguments

1:     $\mathbf{eps}$ – Real (Kind=nag_wp)Input
On entry: the relative precision of the restitching of the two input meshes (see Section 9).
Suggested value: $0.001$.
Constraint: ${\mathbf{eps}}>0.0$.
2:     $\mathbf{nv1}$ – IntegerInput
On entry: the total number of vertices in the first input mesh.
Constraint: ${\mathbf{nv1}}\ge 3$.
3:     $\mathbf{nelt1}$ – IntegerInput
On entry: the number of triangular elements in the first input mesh.
Constraint: ${\mathbf{nelt1}}\le 2×{\mathbf{nv1}}-1$.
4:     $\mathbf{nedge1}$ – IntegerInput
On entry: the number of boundary edges in the first input mesh.
Constraint: ${\mathbf{nedge1}}\ge 1$.
5:     $\mathbf{coor1}\left(2,{\mathbf{nv1}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: ${\mathbf{coor1}}\left(1,\mathit{i}\right)$ contains the $x$ coordinate of the $\mathit{i}$th vertex of the first input mesh, for $\mathit{i}=1,2,\dots ,{\mathbf{nv1}}$; while ${\mathbf{coor1}}\left(2,\mathit{i}\right)$ contains the corresponding $y$ coordinate.
6:     $\mathbf{edge1}\left(3,{\mathbf{nedge1}}\right)$ – Integer arrayInput
On entry: the specification of the boundary edges of the first input mesh. ${\mathbf{edge1}}\left(1,j\right)$ and ${\mathbf{edge1}}\left(2,j\right)$ contain the vertex numbers of the two end points of the $j$th boundary edge. ${\mathbf{edge1}}\left(3,j\right)$ is a user-supplied tag for the $j$th boundary edge.
Constraint: $1\le {\mathbf{edge1}}\left(\mathit{i},\mathit{j}\right)\le {\mathbf{nv1}}$ and ${\mathbf{edge1}}\left(1,\mathit{j}\right)\ne {\mathbf{edge1}}\left(2,\mathit{j}\right)$, for $\mathit{i}=1,2$ and $\mathit{j}=1,2,\dots ,{\mathbf{nedge1}}$.
7:     $\mathbf{conn1}\left(3,{\mathbf{nelt1}}\right)$ – Integer arrayInput
On entry: the connectivity between triangles and vertices of the first input mesh. For each triangle $\mathit{j}$, ${\mathbf{conn1}}\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{nelt1}}$.
Constraints:
• $1\le {\mathbf{conn1}}\left(i,j\right)\le {\mathbf{nv1}}$;
• ${\mathbf{conn1}}\left(1,j\right)\ne {\mathbf{conn1}}\left(2,j\right)$;
• ${\mathbf{conn1}}\left(1,\mathit{j}\right)\ne {\mathbf{conn1}}\left(3,\mathit{j}\right)$ and ${\mathbf{conn1}}\left(2,\mathit{j}\right)\ne {\mathbf{conn1}}\left(3,\mathit{j}\right)$, for $\mathit{i}=1,2,3$ and $\mathit{j}=1,2,\dots ,{\mathbf{nelt1}}$.
8:     $\mathbf{reft1}\left({\mathbf{nelt1}}\right)$ – Integer arrayInput
On entry: ${\mathbf{reft1}}\left(\mathit{k}\right)$ contains the user-supplied tag of the $\mathit{k}$th triangle from the first input mesh, for $\mathit{k}=1,2,\dots ,{\mathbf{nelt1}}$.
9:     $\mathbf{nv2}$ – IntegerInput
On entry: the total number of vertices in the second input mesh.
Constraint: ${\mathbf{nv2}}\ge 3$.
10:   $\mathbf{nelt2}$ – IntegerInput
On entry: the number of triangular elements in the second input mesh.
Constraint: ${\mathbf{nelt2}}\le 2×{\mathbf{nv2}}-1$.
11:   $\mathbf{nedge2}$ – IntegerInput
On entry: the number of boundary edges in the second input mesh.
Constraint: ${\mathbf{nedge2}}\ge 1$.
12:   $\mathbf{coor2}\left(2,{\mathbf{nv2}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: ${\mathbf{coor2}}\left(1,\mathit{i}\right)$ contains the $x$ coordinate of the $\mathit{i}$th vertex of the second input mesh, for $\mathit{i}=1,2,\dots ,{\mathbf{nv2}}$; while ${\mathbf{coor2}}\left(2,\mathit{i}\right)$ contains the corresponding $y$ coordinate.
13:   $\mathbf{edge2}\left(3,{\mathbf{nedge2}}\right)$ – Integer arrayInput
On entry: the specification of the boundary edges of the second input mesh. ${\mathbf{edge2}}\left(1,j\right)$ and ${\mathbf{edge2}}\left(2,j\right)$ contain the vertex numbers of the two end points of the $j$th boundary edge. ${\mathbf{edge2}}\left(3,j\right)$ is a user-supplied tag for the $j$th boundary edge.
Constraint: $1\le {\mathbf{edge2}}\left(\mathit{i},\mathit{j}\right)\le {\mathbf{nv2}}$ and ${\mathbf{edge2}}\left(1,\mathit{j}\right)\ne {\mathbf{edge2}}\left(2,\mathit{j}\right)$, for $\mathit{i}=1,2$ and $\mathit{j}=1,2,\dots ,{\mathbf{nedge2}}$.
14:   $\mathbf{conn2}\left(3,{\mathbf{nelt2}}\right)$ – Integer arrayInput
On entry: the connectivity between triangles and vertices of the second input mesh. For each triangle $\mathit{j}$, ${\mathbf{conn2}}\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{nelt2}}$.
Constraints:
• $1\le {\mathbf{conn2}}\left(i,j\right)\le {\mathbf{nv2}}$;
• ${\mathbf{conn2}}\left(1,j\right)\ne {\mathbf{conn2}}\left(2,j\right)$;
• ${\mathbf{conn2}}\left(1,\mathit{j}\right)\ne {\mathbf{conn2}}\left(3,\mathit{j}\right)$ and ${\mathbf{conn2}}\left(2,\mathit{j}\right)\ne {\mathbf{conn2}}\left(3,\mathit{j}\right)$, for $\mathit{i}=1,2,3$ and $\mathit{j}=1,2,\dots ,{\mathbf{nelt2}}$.
15:   $\mathbf{reft2}\left({\mathbf{nelt2}}\right)$ – Integer arrayInput
On entry: ${\mathbf{reft2}}\left(\mathit{k}\right)$ contains the user-supplied tag of the $\mathit{k}$th triangle from the second input mesh, for $\mathit{k}=1,2,\dots ,{\mathbf{nelt2}}$.
16:   $\mathbf{nv3}$ – IntegerOutput
On exit: the total number of vertices in the resulting mesh.
17:   $\mathbf{nelt3}$ – IntegerOutput
On exit: the number of triangular elements in the resulting mesh.
18:   $\mathbf{nedge3}$ – IntegerOutput
On exit: the number of boundary edges in the resulting mesh.
19:   $\mathbf{coor3}\left(2,*\right)$ – Real (Kind=nag_wp) arrayOutput
Note: the second dimension of the array coor3 must be at least ${\mathbf{nv1}}+{\mathbf{nv2}}$.
On exit: ${\mathbf{coor3}}\left(1,\mathit{i}\right)$ will contain the $x$ coordinate of the $\mathit{i}$th vertex of the resulting mesh, for $\mathit{i}=1,2,\dots ,{\mathbf{nv3}}$; while ${\mathbf{coor3}}\left(2,i\right)$ will contain the corresponding $y$ coordinate.
20:   $\mathbf{edge3}\left(3,*\right)$ – Integer arrayOutput
Note: the second dimension of the array edge3 must be at least ${\mathbf{nedge1}}+{\mathbf{nedge2}}$. This may be reduced to ${\mathbf{nedge3}}$ once that value is known.
On exit: the specification of the boundary edges of the resulting mesh. ${\mathbf{edge3}}\left(i,j\right)$ will contain the vertex number of the $i$th end point ($i=1,2$) of the $j$th boundary or interface edge.
If the two meshes overlap, ${\mathbf{edge3}}\left(3,j\right)$ will contain the same tag as the corresponding edge belonging to the first and/or the second input mesh.
If the two meshes are adjacent,
 (i) if the $j$th edge is part of the partition interface, ${\mathbf{edge3}}\left(3,j\right)$ will contain the value $1000×{k}_{1}+{k}_{2}$ where ${k}_{1}$ and ${k}_{2}$ are the tags for the same edge of the first and the second mesh respectively; (ii) otherwise, ${\mathbf{edge3}}\left(3,j\right)$ will contain the same tag as the corresponding edge belonging to the first and/or the second input mesh.
21:   $\mathbf{conn3}\left(3,*\right)$ – Integer arrayOutput
Note: the second dimension of the array conn3 must be at least ${\mathbf{nelt1}}+{\mathbf{nelt2}}$. This may be reduced to ${\mathbf{nelt3}}$ once that value is known.
On exit: the connectivity between triangles and vertices of the resulting mesh. ${\mathbf{conn3}}\left(\mathit{i},\mathit{j}\right)$ will give the indices of its three vertices (in anticlockwise order), for $\mathit{i}=1,2,3$ and $\mathit{j}=1,2,\dots ,{\mathbf{nelt3}}$.
22:   $\mathbf{reft3}\left(*\right)$ – Integer arrayOutput
Note: the dimension of the array reft3 must be at least ${\mathbf{nelt1}}+{\mathbf{nelt2}}$. This may be reduced to ${\mathbf{nelt3}}$ once that value is known.
On exit: if the two meshes form a partition, ${\mathbf{reft3}}\left(\mathit{k}\right)$ will contain the same tag as the corresponding triangle belonging to the first or the second input mesh, for $\mathit{k}=1,2,\dots ,{\mathbf{nelt3}}$. If the two meshes overlap, ${\mathbf{reft3}}\left(\mathit{k}\right)$ will contain the value $1000×{\mathit{k}}_{1}+{\mathit{k}}_{2}$ where ${\mathit{k}}_{1}$ and ${\mathit{k}}_{2}$ are the user-supplied tags for the same triangle of the first and the second mesh respectively, for $\mathit{k}=1,2,\dots ,{\mathbf{nelt3}}$.
23:   $\mathbf{itrace}$ – IntegerInput
On entry: the level of trace information required from d06dbf.
${\mathbf{itrace}}\le 0$
No output is generated.
${\mathbf{itrace}}\ge 1$
Details about the common vertices, edges and triangles to both meshes are printed on the current advisory message unit (see x04abf).
24:   $\mathbf{iwork}\left({\mathbf{liwork}}\right)$ – Integer arrayWorkspace
25:   $\mathbf{liwork}$ – IntegerInput
On entry: the dimension of the array iwork as declared in the (sub)program from which d06dbf is called.
Constraint: ${\mathbf{liwork}}\ge 2×{\mathbf{nv1}}+3×{\mathbf{nv2}}+{\mathbf{nelt1}}+{\mathbf{nelt2}}+{\mathbf{nedge1}}+{\mathbf{nedge2}}+1024$.
26:   $\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{eps}}\le 0.0$, or ${\mathbf{nv1}}<3$, or ${\mathbf{nelt1}}>2×{\mathbf{nv1}}-1$, or ${\mathbf{nedge1}}<1$, or ${\mathbf{edge1}}\left(i,j\right)<1$ or ${\mathbf{edge1}}\left(i,j\right)>{\mathbf{nv1}}$ for some $i=1,2$ and $j=1,2,\dots ,{\mathbf{nedge1}}$, or ${\mathbf{edge1}}\left(1,j\right)={\mathbf{edge1}}\left(2,j\right)$ for some $j=1,2,\dots ,{\mathbf{nedge1}}$, or ${\mathbf{conn1}}\left(i,j\right)<1$ or ${\mathbf{conn1}}\left(i,j\right)>{\mathbf{nv1}}$ for some $i=1,2,3$ and $j=1,2,\dots ,{\mathbf{nelt1}}$, or ${\mathbf{conn1}}\left(1,j\right)={\mathbf{conn1}}\left(2,j\right)$ or ${\mathbf{conn1}}\left(1,j\right)={\mathbf{conn1}}\left(3,j\right)$ or ${\mathbf{conn1}}\left(2,j\right)={\mathbf{conn1}}\left(3,j\right)$ for some $j=1,2,\dots ,{\mathbf{nelt1}}$, or ${\mathbf{nv2}}<3$, or ${\mathbf{nelt2}}>2×{\mathbf{nv2}}-1$, or ${\mathbf{nedge2}}<1$, or ${\mathbf{edge2}}\left(i,j\right)<1$ or ${\mathbf{edge2}}\left(i,j\right)>{\mathbf{nv2}}$ for some $i=1,2$ and $j=1,2,\dots ,{\mathbf{nedge2}}$, or ${\mathbf{edge2}}\left(1,j\right)={\mathbf{edge2}}\left(2,j\right)$ for some $j=1,2,\dots ,{\mathbf{nedge2}}$, or ${\mathbf{conn2}}\left(i,j\right)<1$ or ${\mathbf{conn2}}\left(i,j\right)>{\mathbf{nv2}}$ for some $i=1,2,3$ and $j=1,2,\dots ,{\mathbf{nelt2}}$, or ${\mathbf{conn2}}\left(1,j\right)={\mathbf{conn2}}\left(2,j\right)$ or ${\mathbf{conn2}}\left(1,j\right)={\mathbf{conn2}}\left(3,j\right)$ or ${\mathbf{conn2}}\left(2,j\right)={\mathbf{conn2}}\left(3,j\right)$ for some $j=1,2,\dots ,{\mathbf{nelt2}}$, or ${\mathbf{liwork}}<2×{\mathbf{nv1}}+3×{\mathbf{nv2}}+{\mathbf{nelt1}}+{\mathbf{nelt2}}+{\mathbf{nedge1}}+{\mathbf{nedge2}}+1024$.
${\mathbf{ifail}}=2$
Using the input precision eps, the routine has detected fewer than two coincident vertices between the two input meshes. You are advised to try another value of eps; if this error still occurs the two meshes are probably not stitchable.
${\mathbf{ifail}}=3$
A serious error has occurred in an internal call to the restitching routine. You should check the input of the two meshes, especially the edge/vertex and/or the triangle/vertex connectivities. If the problem persists, contact NAG.
${\mathbf{ifail}}=4$
The routine has detected a different number of coincident triangles from the two input meshes in the overlapping zone. You should check the input of the two meshes, especially the triangle/vertex connectivities.
${\mathbf{ifail}}=5$
The routine has detected a different number of coincident edges from the two meshes on the partition interface. You should check the input of the two meshes, especially the edge/vertex connectivities.
${\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

d06dbf is not threaded in any implementation.

d06dbf finds all the common vertices between the two input meshes using the relative precision of the restitching argument eps. You are advised to vary the value of eps in the neighbourhood of $0.001$ with ${\mathbf{itrace}}\ge 1$ to get the optimal value for the meshes under consideration.

## 10Example

For this routine two examples are presented. There is a single example program for d06dbf, with a main program and the code to solve the two example problems given in Example 1 (EX1) and Example 2 (EX2).
Example 1 (EX1)
This example involves the unit square ${\left[0,1\right]}^{2}$ meshed uniformly, and then translated by a vector $\stackrel{\to }{u}=\left(\begin{array}{c}{u}_{1}\\ {u}_{2}\end{array}\right)$ (using d06daf). This translated mesh is then restitched with the original mesh. Two cases are considered:
 (a) overlapping meshes (${u}_{1}=15.0$, ${u}_{2}=17.0$), (b) partitioned meshes (${u}_{1}=19.0$, ${u}_{2}=0.0$).
The mesh on the unit square has $400$ vertices, $722$ triangles and its boundary has $76$ edges. In the partitioned case the resulting geometry is shown in Figure 1 in Section 10.3 while the restitched mesh is shown in Figure 2 in Section 10.3. In the overlapping case the geometry and mesh are shown in Figure 3 and Figure 4 in Section 10.3.
Example 2 (EX2)
This example restitches three geometries by calling the routine d06dbf twice. The result is a mesh with three partitions. The first geometry is meshed by the Delaunay–Voronoi process (using d06abf), the second one meshed by an Advancing Front algorithm (using d06acf), while the third one is the result of a rotation (by $-\pi /2$) of the second one (using d06daf). The resulting geometry is shown in Figure 5 in Section 10.3 and restitched mesh in Figure 6 in Section 10.3.

### 10.1Program Text

Program Text (d06dbfe.f90)

### 10.2Program Data

Program Data (d06dbfe.d)

### 10.3Program Results

Program Results (d06dbfe.r)

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