Integer type:** int32**** int64**** nag_int** show int32 show int32 show int64 show int64 show nag_int show nag_int

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.

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

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 (x_{1},y_{1})$({x}_{1},{y}_{1})$ preceding (x_{2},y_{2})$({x}_{2},{y}_{2})$ if x_{1} < x_{2}${x}_{1}<{x}_{2}$ or x_{1} = x_{2}${x}_{1}={x}_{2}$, y_{1} < y_{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$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.

0 < x < sqrt(3)(m − 1)h, 0 < y < (n − 1)h.
$$0<x<\sqrt{3}(m-1)h\text{, \hspace{1em}}0<y<(n-1)h\text{.}$$ |

The mesh size h$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$2h$ of another hole or the outer boundary then a triangle may be found with all vertices within (1/2)h$\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.

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

- 1: h – double scalar
- h$h$, the required length for the sides of the triangles of the uniform mesh.
- 2: m – int64int32nag_int scalar
- 3: n – int64int32nag_int scalar
- Values m$m$ and n$n$ such that all points (x,y)$(x,y)$ inside the region satisfy the inequalities
0 ≤ x ≤ sqrt(3)(m − 1)h, 0 ≤ y ≤ (n − 1)h. $$\begin{array}{l}0\le x\le \sqrt{3}(m-1)h\text{,}\\ 0\le y\le (n-1)h\text{.}\end{array}$$ - 4: nb – int64int32nag_int scalar
- The number of times a triangle side is bisected to find a point on the boundary. A value of 10$10$ is adequate for most purposes (see Section [Accuracy]).
- 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

None.

- dist sddist

- 1: npts – int64int32nag_int scalar
- The number of points in the triangulation.
- 2: places(2$2$,sdindx) – double array
- The x$x$ and y$y$ coordinates respectively of the i$i$th point of the triangulation.
- 3: indx(4$4$,sdindx) – int64int32nag_int array
- indx(1,i)${\mathbf{indx}}\left(1,i\right)$ contains i$i$ if point i$i$ is inside the region and − i$-i$ if it is on the boundary. For each triangle side between points i$i$ and j$j$ with j > i$j>i$, indx(k,i)${\mathbf{indx}}\left(k,i\right)$, k > 1$k>1$, contains j$j$ or − j$-j$ according to whether point j$j$ 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)${\mathbf{indx}}\left(k,i\right)$, k > 1$k>1$, are zero.
- 4: ifail – int64int32nag_int scalar
- ifail = 0${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

Errors or warnings detected by the function:

- sdindx is too small.

- sddist is too small.

- m ≤ 2${\mathbf{m}}\le 2$.

- n ≤ 2${\mathbf{n}}\le 2$.

- nb ≤ 0${\mathbf{nb}}\le 0$.

Points are moved onto the boundary by bisecting a triangle side nb times. The accuracy is therefore h × 2^{ − nb}$h\times {2}^{-{\mathbf{nb}}}$.

The time taken is approximately proportional to m × n$m\times n$.

Open in the MATLAB editor: nag_pde_2d_triangulate_example

function nag_pde_2d_triangulate_exampleh = 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, ifailfunction result = isin(x,y)if ((x-7)^2+(y-7)^2 <= 36) result = int64(1); else result = int64(0); end

npts = 14 ifail = 0

Open in the MATLAB editor: d03ma_example

function d03ma_exampleh = 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, ifailfunction result = isin(x,y)if ((x-7)^2+(y-7)^2 <= 36) result = int64(1); else result = int64(0); end

npts = 14 ifail = 0

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