The routine may be called by the names d03maf or nagf_pde_dim2_triangulate.
3Description
d03maf begins with a uniform triangular grid as shown in Figure 1 and assumes that the region to be triangulated lies within the rectangle given by the inequalities
This rectangle is drawn in bold in Figure 1. The region is specified by the isin which must determine whether any given point $(x,y)$ lies in the region. The uniform grid is processed column-wise, with $({x}_{1},{y}_{1})$ preceding $({x}_{2},{y}_{2})$ if ${x}_{1}<{x}_{2}$ or ${x}_{1}={x}_{2}$, ${y}_{1}<{y}_{2}$. Points near the boundary are moved onto it and points well outside the boundary are omitted. The direction of movement is chosen to avoid pathologically thin triangles. The points accepted are numbered in exactly the same order as the corresponding points of the uniform grid were scanned. The output consists of the $x,y$ coordinates of all grid points and integers indicating whether they are internal and to which other points they are joined by triangle sides.
The mesh size $h$ must be chosen small enough for the essential features of the region to be apparent from testing all points of the original uniform grid for being inside the region. For instance if any hole is within $2h$ of another hole or the outer boundary then a triangle may be found with all vertices within $\frac{1}{2}h$ of a boundary. Such a triangle is taken to be external to the region so the effect will be to join the hole to another hole or to the external region.
Further details of the algorithm are given in the references.
Figure 1
4References
Reid J K (1970) Fortran subroutines for the solutions of Laplace's equation over a general routine in two dimensions Harwell Report TP422
Reid J K (1972) On the construction and convergence of a finite-element solution of Laplace's equation J. Instr. Math. Appl.9 1–13
5Arguments
1: $\mathbf{h}$ – Real (Kind=nag_wp)Input
On entry: $h$, the required length for the sides of the triangles of the uniform mesh.
2: $\mathbf{m}$ – IntegerInput
3: $\mathbf{n}$ – IntegerInput
On entry: values $m$ and $n$ such that all points $(x,y)$ inside the region satisfy the inequalities
On entry: the number of times a triangle side is bisected to find a point on the boundary. A value of $10$ is adequate for most purposes (see Section 7).
Constraint:
${\mathbf{nb}}\ge 1$.
5: $\mathbf{npts}$ – IntegerOutput
On exit: the number of points in the triangulation.
6: $\mathbf{places}(2,{\mathbf{sdindx}})$ – Real (Kind=nag_wp) arrayOutput
On exit: the $x$ and $y$ coordinates respectively of the $i$th point of the triangulation.
On exit: ${\mathbf{indx}}(1,i)$ contains $i$ if point $i$ is inside the region and $-i$ if it is on the boundary. For each triangle side between points $i$ and $j$ with $j>i$, ${\mathbf{indx}}(k,i)$, $k>1$, contains $j$ or $-j$ according to whether point $j$ is internal or on the boundary. There can never be more than three such points. If there are less, some values ${\mathbf{indx}}(k,i)$, $k>1$, are zero.
8: $\mathbf{sdindx}$ – IntegerInput
On entry: the second dimension of the arrays places and indx as declared in the (sub)program from which d03maf is called.
isin must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which d03maf is called. Arguments denoted as Input must not be changed by this procedure.
10: $\mathbf{dist}(4,{\mathbf{sddist}})$ – Real (Kind=nag_wp) arrayWorkspace
11: $\mathbf{sddist}$ – IntegerInput
On entry: the second dimension of the array dist as declared in the (sub)program from which d03maf is called.
Constraint:
${\mathbf{sddist}}\ge 4{\mathbf{n}}$.
12: $\mathbf{ifail}$ – IntegerInput/Output
On entry: ifail must be set to $0$, $\mathrm{-1}$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $\mathrm{-1}$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $\mathrm{-1}$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ 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 $\mathrm{-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$
sdindx is too small: ${\mathbf{sdindx}}=\u27e8\mathit{\text{value}}\u27e9$.
${\mathbf{ifail}}=2$
A point inside the region violates one of the constraints.
${\mathbf{ifail}}=3$
On entry, ${\mathbf{sddist}}=\u27e8\mathit{\text{value}}\u27e9$ and ${\mathbf{n}}=\u27e8\mathit{\text{value}}\u27e9$.
Constraint: ${\mathbf{sddist}}\ge 4\times {\mathbf{n}}$.
${\mathbf{ifail}}=4$
On entry, ${\mathbf{m}}=\u27e8\mathit{\text{value}}\u27e9$.
Constraint: ${\mathbf{m}}>2$.
${\mathbf{ifail}}=5$
On entry, ${\mathbf{n}}=\u27e8\mathit{\text{value}}\u27e9$.
Constraint: ${\mathbf{n}}>2$.
${\mathbf{ifail}}=6$
On entry, ${\mathbf{nb}}=\u27e8\mathit{\text{value}}\u27e9$.
Constraint: ${\mathbf{nb}}>0$.
${\mathbf{ifail}}=-99$
An unexpected error has been triggered by this routine. Please
contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.
7Accuracy
Points are moved onto the boundary by bisecting a triangle side nb times. The accuracy is, therefore, $h\times {2}^{-{\mathbf{nb}}}$.
8Parallelism and Performance
Background information to multithreading can be found in the Multithreading documentation.
d03maf is not threaded in any implementation.
9Further Comments
The time taken is approximately proportional to $m\times n$.
10Example
The following program triangulates the circle with centre $(7.0,7.0)$ and radius $6.0$ using a basic grid size $h=4.0$.