D03MAF (PDF version)
D03 Chapter Contents
D03 Chapter Introduction
NAG Library Manual

NAG Library Routine Document


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.

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

D03MAF places a triangular mesh over a given two-dimensional region. The region may have any shape, including one with holes.

2  Specification


3  Description

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
0<x<3m-1h,  0<y<n-1h.
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 x1,y1 preceding x2,y2 if x1<x2 or x1=x2, y1<y2. 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 12h 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
Figure 1

4  References

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

5  Parameters

1:     H – REAL (KIND=nag_wp)Input
On entry: h, the required length for the sides of the triangles of the uniform mesh.
2:     M – INTEGERInput
3:     N – INTEGERInput
On entry: values m and n such that all points x,y inside the region satisfy the inequalities
0x3m-1h, 0yn-1h.
Constraint: M=N>2.
4:     NB – INTEGERInput
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: NB1.
5:     NPTS – INTEGEROutput
On exit: the number of points in the triangulation.
6:     PLACES(2,SDINDX) – REAL (KIND=nag_wp) arrayOutput
On exit: the x and y coordinates respectively of the ith point of the triangulation.
7:     INDX(4,SDINDX) – INTEGER arrayOutput
On exit: INDX1i 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, INDXki, 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, then some values INDXki, k>1, are zero.
8:     SDINDX – INTEGERInput
On entry: the second dimension of the arrays PLACES and INDX as declared in the (sub)program from which D03MAF is called.
Constraint: SDINDXNPTS.
9:     ISIN – INTEGER FUNCTION, supplied by the user.External Procedure
ISIN must return the value 1 if the given point (X,Y) lies inside the region, and 0 if it lies outside.
The specification of ISIN is:
REAL (KIND=nag_wp)  X, Y
1:     X – REAL (KIND=nag_wp)Input
2:     Y – REAL (KIND=nag_wp)Input
On entry: the coordinates of the given point.
ISIN must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which D03MAF is called. Parameters denoted as Input must not be changed by this procedure.
10:   DIST(4,SDDIST) – REAL (KIND=nag_wp) arrayWorkspace
On entry: the second dimension of the array DIST as declared in the (sub)program from which D03MAF is called.
Constraint: SDDIST4N.
12:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ 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​ 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 -1​ or ​1 is used it is essential to test the value of IFAIL on exit.
On exit: IFAIL=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6  Error Indicators and Warnings

If on entry 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:
SDINDX is too small.
A point inside the region violates one of the constraints (see parameters M and N).
SDDIST is too small.

7  Accuracy

Points are moved onto the boundary by bisecting a triangle side NB times. The accuracy is therefore h×2-NB.

8  Further Comments

The time taken is approximately proportional to m×n.

9  Example

The following program triangulates the circle with centre 7.0,7.0 and radius 6.0 using a basic grid size h=4.0.

9.1  Program Text

Program Text (d03mafe.f90)

9.2  Program Data

Program Data (d03mafe.d)

9.3  Program Results

Program Results (d03mafe.r)

Produced by GNUPLOT 4.4 patchlevel 0 0 2 4 6 8 10 12 14 0 2 4 6 8 10 12 14 y x Example Program Triangulation of a Circle with centre (7,7) and radius 6 using grid size=4

D03MAF (PDF version)
D03 Chapter Contents
D03 Chapter Introduction
NAG Library Manual

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