# NAG Library Routine Document

## 1Purpose

d06cbf generates the sparsity pattern of a finite element matrix associated with a given mesh.

## 2Specification

Fortran Interface
 Subroutine d06cbf ( nv, nelt, conn, nnz, irow, icol,
 Integer, Intent (In) :: nv, nelt, nnzmax, conn(3,nelt) Integer, Intent (Inout) :: ifail Integer, Intent (Out) :: nnz, irow(nnzmax), icol(nnzmax)
#include nagmk26.h
 void d06cbf_ (const Integer *nv, const Integer *nelt, const Integer *nnzmax, const Integer conn[], Integer *nnz, Integer irow[], Integer icol[], Integer *ifail)

## 3Description

d06cbf generates the sparsity pattern of a finite element matrix associated with a given mesh. The sparsity pattern is returned in a coordinate storage format consistent with the sparse linear algebra routines in Chapter F11. More precisely d06cbf returns the number of nonzero elements in the associated sparse matrix, and their row and column indices. This is designed to assist you in applying finite element discretization to meshes from the D06 Chapter Introduction and in solving the resulting sparse linear system using routines from Chapter F11.
The output sparsity pattern is based on the fact that finite element matrix $A$ has elements ${a}_{ij}$ satisfying:
 $aij≠0 ⇒i​ and ​j ​ are vertices belonging to the same triangle.$

None.

## 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{nnzmax}$ – IntegerInput
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 subroutine from which d06cbf is called.
Constraint: $4×{\mathbf{nelt}}+{\mathbf{nv}}\le {\mathbf{nnzmax}}\le {{\mathbf{nv}}}^{2}$.
4:     $\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}}$.
5:     $\mathbf{nnz}$ – IntegerOutput
On exit: the number of nonzero entries in the matrix associated with the input mesh.
6:     $\mathbf{irow}\left({\mathbf{nnzmax}}\right)$ – Integer arrayOutput
7:     $\mathbf{icol}\left({\mathbf{nnzmax}}\right)$ – Integer arrayOutput
On exit: the first nnz elements contain the row and column indices of the nonzero elements supplied in the finite element matrix $A$.
8:     $\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{nnzmax}}<4×{\mathbf{nelt}}+{\mathbf{nv}}$ or ${\mathbf{nnzmax}}>{{\mathbf{nv}}}^{2}$ or ${\mathbf{conn}}\left(i,j\right)<1$ or ${\mathbf{conn}}\left(i,j\right)>{\mathbf{nv}}$ for some $i=1,3$ and $j$, $1\le j\le {\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}}$.
${\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). Array dimensions should be checked as well. 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

d06cbf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
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

See Section 10 in d06ccf.
© The Numerical Algorithms Group Ltd, Oxford, UK. 2017