d06 Chapter Contents
d06 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_mesh2d_renum (d06ccc)

## 1  Purpose

nag_mesh2d_renum (d06ccc) renumbers the vertices of a given mesh using a Gibbs method, in order the reduce the bandwidth of Finite Element matrices associated with that mesh.

## 2  Specification

 #include #include
 void nag_mesh2d_renum (Integer nv, Integer nelt, Integer nedge, Integer nnzmax, Integer *nnz, double coor[], Integer edge[], Integer conn[], Integer irow[], Integer icol[], Integer itrace, const char *outfile, NagError *fail)

## 3  Description

nag_mesh2d_renum (d06ccc) uses a Gibbs method to renumber the vertices of a given mesh in order to reduce the bandwidth of the associated finite element matrix $A$. This matrix has elements ${a}_{ij}$ such that:
 $aij≠0⇒i​ and ​j​ are vertices belonging to the same triangle.$
This function reduces the bandwidth $m$, which is the smallest integer such that ${a}_{ij}\ne 0$ whenever $\left|i-j\right|>m$ (see Gibbs et al. (1976) for details about that method). nag_mesh2d_renum (d06ccc) also returns the sparsity structure of the matrix associated with the renumbered mesh.
This function is derived from material in the MODULEF package from INRIA (Institut National de Recherche en Informatique et Automatique).

## 4  References

Gibbs N E, Poole W G Jr and Stockmeyer P K (1976) An algorithm for reducing the bandwidth and profile of a sparse matrix SIAM J. Numer. Anal. 13 236–250

## 5  Arguments

1:     nvIntegerInput
On entry: the total number of vertices in the input mesh.
Constraint: ${\mathbf{nv}}\ge 3$.
2:     neltIntegerInput
On entry: the number of triangles in the input mesh.
Constraint: ${\mathbf{nelt}}\le 2×{\mathbf{nv}}-1$.
3:     nedgeIntegerInput
On entry: the number of the boundary edges in the input mesh.
Constraint: ${\mathbf{nedge}}\ge 1$.
4:     nnzmaxIntegerInput
On entry: the maximum number of nonzero entries in the matrix based on the input mesh. It is the dimension of the arrays irow and icol as declared in the function from which nag_mesh2d_renum (d06ccc) is called.
Constraint: $4×{\mathbf{nelt}}+{\mathbf{nv}}\le {\mathbf{nnzmax}}\le {{\mathbf{nv}}}^{2}$.
5:     nnzInteger *Output
On exit: the number of nonzero entries in the matrix based on the input mesh.
6:     coor[$2×{\mathbf{nv}}$]doubleInput/Output
On entry: ${\mathbf{coor}}\left[\left(\mathit{i}-1\right)×2+0\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+0\right]$ will contain the $x$ coordinate of the $\mathit{i}$th renumbered 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.
7:     edge[$3×{\mathbf{nedge}}$]IntegerInput/Output
On entry: the specification of the boundary or interface edges. ${\mathbf{edge}}\left[\left(j-1\right)×3+0\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+0\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}}$.
On exit: the renumbered specification of the boundary or interface edges.
8:     conn[$3×{\mathbf{nelt}}$]IntegerInput/Output
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+0\right]\ne {\mathbf{conn}}\left[\left(\mathit{j}-1\right)×3+1\right]$ and ${\mathbf{conn}}\left[\left(\mathit{j}-1\right)×3+0\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}}$.
On exit: the renumbered connectivity of the mesh between triangles and vertices.
9:     irow[nnzmax]IntegerOutput
10:   icol[nnzmax]IntegerOutput
On exit: the first nnz elements contain the row and column indices of the nonzero elements supplied in the finite element matrix $A$.
11:   itraceIntegerInput
On entry: the level of trace information required from nag_mesh2d_renum (d06ccc).
${\mathbf{itrace}}\le 0$
No output is generated.
${\mathbf{itrace}}=1$
Information about the effect of the renumbering on the finite element matrix are output. This information includes the half bandwidth and the sparsity structure of this matrix before and after renumbering.
${\mathbf{itrace}}>1$
The output is similar to that produced when ${\mathbf{itrace}}=1$ but the sparsities (for each row of the matrix, indices of nonzero entries) of the matrix before and after renumbering are also output.
12:   outfileconst 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.
13:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_FAIL_SPARSITY
An error has occurred during the computation of the compact sparsity of the finite element matrix. Check the Triangle/Vertices connectivity.
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, the endpoints of the edge $j$ have the same index $i$: $j=〈\mathit{\text{value}}〉$ and $i=〈\mathit{\text{value}}〉$.
On entry, vertices $1$ and $2$ of the triangle $k$ have the same index $i$: $k=〈\mathit{\text{value}}〉$ and $i=〈\mathit{\text{value}}〉$.
On entry, vertices $1$ and $3$ of the triangle $k$ have the same index $i$: $k=〈\mathit{\text{value}}〉$ and $i=〈\mathit{\text{value}}〉$.
On entry, vertices $2$ and $3$ of the triangle $k$ have the same index $i$: $k=〈\mathit{\text{value}}〉$ and $i=〈\mathit{\text{value}}〉$.
NE_INT_3
On entry, ${\mathbf{nnzmax}}=〈\mathit{\text{value}}〉$, ${\mathbf{nelt}}=〈\mathit{\text{value}}〉$ and ${\mathbf{nv}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nnzmax}}\ge \left(4×{\mathbf{nelt}}+{\mathbf{nv}}\right)$ and ${\mathbf{nnzmax}}\le {{\mathbf{nv}}}^{2}$.
NE_INT_4
On entry, ${\mathbf{CONN}}\left(i,j\right)=〈\mathit{\text{value}}〉$, $i=〈\mathit{\text{value}}〉$, $j=〈\mathit{\text{value}}〉$ and ${\mathbf{nv}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{CONN}}\left(i,j\right)\ge 1$ and ${\mathbf{CONN}}\left(i,j\right)\le {\mathbf{nv}}$, where ${\mathbf{CONN}}\left(i,j\right)$ denotes ${\mathbf{conn}}\left[\left(j-1\right)×3+i-1\right]$.
On entry, ${\mathbf{EDGE}}\left(i,j\right)=〈\mathit{\text{value}}〉$, $i=〈\mathit{\text{value}}〉$, $j=〈\mathit{\text{value}}〉$ and ${\mathbf{nv}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{EDGE}}\left(i,j\right)\ge 1$ and ${\mathbf{EDGE}}\left(i,j\right)\le {\mathbf{nv}}$, where ${\mathbf{EDGE}}\left(i,j\right)$ denotes ${\mathbf{edge}}\left[\left(j-1\right)×3+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.
A serious error has occurred in an internal call to the renumbering function. Check the input mesh especially the connectivity. Seek expert help.
NE_NOT_CLOSE_FILE
Cannot close file $〈\mathit{\text{value}}〉$.
NE_NOT_WRITE_FILE
Cannot open file $〈\mathit{\text{value}}〉$ for writing.

Not applicable.

Not applicable.

## 9  Example

In this example, a geometry with two holes (two interior circles inside an exterior one) is considered. The geometry has been meshed using the simple incremental method (nag_mesh2d_inc (d06aac)) and it has $250$ vertices and $402$ triangles (see Figure 1). The function nag_mesh2d_bound (d06bac) is used to renumber the vertices, and one can see the benefit in terms of the sparsity of the finite element matrix based on the renumbered mesh (see Figure 2).

### 9.1  Program Text

Program Text (d06ccce.c)

### 9.2  Program Data

Program Data (d06ccce.d)

### 9.3  Program Results

Program Results (d06ccce.r)

Figure 1: Mesh of the geometry
Figure 2: Sparsity of the matrix before (top) and after (bottom) the renumbering