D06 Chapter Contents
D06 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentD06DBF

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

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

## 2  Specification

 SUBROUTINE D06DBF ( EPS, NV1, NELT1, NEDGE1, COOR1, EDGE1, CONN1, REFT1, NV2, NELT2, NEDGE2, COOR2, EDGE2, CONN2, REFT2, NV3, NELT3, NEDGE3, COOR3, EDGE3, CONN3, REFT3, ITRACE, IWORK, LIWORK, IFAIL)
 INTEGER NV1, NELT1, NEDGE1, EDGE1(3,NEDGE1), CONN1(3,NELT1), REFT1(NELT1), NV2, NELT2, NEDGE2, EDGE2(3,NEDGE2), CONN2(3,NELT2), REFT2(NELT2), NV3, NELT3, NEDGE3, EDGE3(3,*), CONN3(3,*), REFT3(*), ITRACE, IWORK(LIWORK), LIWORK, IFAIL REAL (KIND=nag_wp) EPS, COOR1(2,NV1), COOR2(2,NV2), COOR3(2,*)

## 3  Description

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.

## 5  Parameters

1:     EPS – REAL (KIND=nag_wp)Input
On entry: the relative precision of the restitching of the two input meshes (see Section 8).
Suggested value: $0.001$.
Constraint: ${\mathbf{EPS}}>0.0$.
2:     NV1 – INTEGERInput
On entry: the total number of vertices in the first input mesh.
Constraint: ${\mathbf{NV1}}\ge 3$.
3:     NELT1 – INTEGERInput
On entry: the number of triangular elements in the first input mesh.
Constraint: ${\mathbf{NELT1}}\le 2×{\mathbf{NV1}}-1$.
4:     NEDGE1 – INTEGERInput
On entry: the number of boundary edges in the first input mesh.
Constraint: ${\mathbf{NEDGE1}}\ge 1$.
5:     COOR1($2$,NV1) – 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:     EDGE1($3$,NEDGE1) – 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:     CONN1($3$,NELT1) – 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:     REFT1(NELT1) – 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:     NV2 – INTEGERInput
On entry: the total number of vertices in the second input mesh.
Constraint: ${\mathbf{NV2}}\ge 3$.
10:   NELT2 – INTEGERInput
On entry: the number of triangular elements in the second input mesh.
Constraint: ${\mathbf{NELT2}}\le 2×{\mathbf{NV2}}-1$.
11:   NEDGE2 – INTEGERInput
On entry: the number of boundary edges in the second input mesh.
Constraint: ${\mathbf{NEDGE2}}\ge 1$.
12:   COOR2($2$,NV2) – 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:   EDGE2($3$,NEDGE2) – 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:   CONN2($3$,NELT2) – 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:   REFT2(NELT2) – 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:   NV3 – INTEGEROutput
On exit: the total number of vertices in the resulting mesh.
17:   NELT3 – INTEGEROutput
On exit: the number of triangular elements in the resulting mesh.
18:   NEDGE3 – INTEGEROutput
On exit: the number of boundary edges in the resulting mesh.
19:   COOR3($2$,$*$) – 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:   EDGE3($3$,$*$) – 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, then ${\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:   CONN3($3$,$*$) – 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:   REFT3($*$) – 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, then ${\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:   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:   IWORK(LIWORK) – INTEGER arrayWorkspace
25:   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:   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{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.

## 7  Accuracy

Not applicable.

D06DBF finds all the common vertices between the two input meshes using the relative precision of the restitching parameter 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.

## 9  Example

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 overlapping case the resulting geometry is shown in Figure 1 and Figure 2. The resulting geometry for the partitioned meshes is shown in Figure 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 4 and Figure 5.

### 9.1  Program Text

Program Text (d06dbfe.f90)

### 9.2  Program Data

Program Data (d06dbfe.d)

### 9.3  Program Results

Program Results (d06dbfe.r)

Figure 1: The boundary and the interior interfaces of the two partitioned squares geometry

Figure 2: The interior mesh of the two partitioned squares geometry

Figure 3: The boundary and the interior interfaces (left); the interior mesh (right)
of the two overlapping squares geometry

Figure 4: The boundary and the interior interfaces of the double restitched geometry

Figure 5: The interior mesh of the double restitched geometry