hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_pde_2d_triangulate (d03ma)

Purpose

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

Syntax

[npts, places, indx, ifail] = d03ma(h, m, n, nb, sdindx, isin)
[npts, places, indx, ifail] = nag_pde_2d_triangulate(h, m, n, nb, sdindx, isin)

Description

nag_pde_2d_triangulate (d03ma) 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 < sqrt(3)(m1)h,  0 < y < (n1)h.
0<x<3(m-1)h,  0<y<(n-1)h.
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)(x,y) lies in the region. The uniform grid is processed column-wise, with (x1,y1)(x1,y1) preceding (x2,y2)(x2,y2) if x1 < x2x1<x2 or x1 = x2x1=x2, y1 < y2y1<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,yx,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 hh 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 2h2h of another hole or the outer boundary then a triangle may be found with all vertices within (1/2)h12h 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

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

Parameters

Compulsory Input Parameters

1:     h – double scalar
hh, the required length for the sides of the triangles of the uniform mesh.
2:     m – int64int32nag_int scalar
3:     n – int64int32nag_int scalar
Values mm and nn such that all points (x,y)(x,y) inside the region satisfy the inequalities
0xsqrt(3)(m1)h,
0y(n1)h.
0x3(m-1)h, 0y(n-1)h.
Constraint: m = n > 2m=n>2.
4:     nb – int64int32nag_int scalar
The number of times a triangle side is bisected to find a point on the boundary. A value of 1010 is adequate for most purposes (see Section [Accuracy]).
Constraint: nb1nb1.
5:     sdindx – int64int32nag_int scalar
An upper bound on the number of points in the triangulation. The actual value will be returned in npts.
6:     isin – function handle or string containing name of m-file
isin must return the value 11 if the given point (x,y) lies inside the region, and 00 if it lies outside.
[result] = isin(x, y)

Input Parameters

1:     x – double scalar
2:     y – double scalar
The coordinates of the given point.

Output Parameters

1:     result – int64int32nag_int scalar
The result of the function.

Optional Input Parameters

None.

Input Parameters Omitted from the MATLAB Interface

dist sddist

Output Parameters

1:     npts – int64int32nag_int scalar
The number of points in the triangulation.
2:     places(22,sdindx) – double array
The xx and yy coordinates respectively of the iith point of the triangulation.
3:     indx(44,sdindx) – int64int32nag_int array
indx(1,i)indx1i contains ii if point ii is inside the region and i-i if it is on the boundary. For each triangle side between points ii and jj with j > ij>i, indx(k,i)indxki, k > 1k>1, contains jj or j-j according to whether point jj is internal or on the boundary. There can never be more than three such points. If there are less, then some values indx(k,i)indxki, k > 1k>1, are zero.
4:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
  ifail = 1ifail=1
sdindx is too small.
  ifail = 2ifail=2
A point inside the region violates one of the constraints (see parameters m and n).
  ifail = 3ifail=3
sddist is too small.
  ifail = 4ifail=4
m2m2.
  ifail = 5ifail=5
n2n2.
  ifail = 6ifail=6
nb0nb0.

Accuracy

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

Further Comments

The time taken is approximately proportional to m × nm×n.

Example

function nag_pde_2d_triangulate_example
h = 4;
m = int64(3);
n = int64(5);
nb = int64(10);
sdindx = int64(100);
[npts, places, index, ifail] = nag_pde_2d_triangulate(h, m, n, nb, sdindx, @isin);
 npts, ifail

function result = isin(x,y)
      if ((x-7)^2+(y-7)^2 <= 36)
         result = int64(1);
      else
         result = int64(0);
      end
 

npts =

                   14


ifail =

                    0


function d03ma_example
h = 4;
m = int64(3);
n = int64(5);
nb = int64(10);
sdindx = int64(100);
[npts, places, index, ifail] = d03ma(h, m, n, nb, sdindx, @isin);
 npts, ifail

function result = isin(x,y)
      if ((x-7)^2+(y-7)^2 <= 36)
         result = int64(1);
      else
         result = int64(0);
      end
 

npts =

                   14


ifail =

                    0



PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013