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

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_mesh_2d_gen_boundary (d06ba)

## Purpose

nag_mesh_2d_gen_boundary (d06ba) generates a boundary mesh on a closed connected subdomain Ω$\Omega$ of 2${ℝ}^{2}$.

## Syntax

[nvb, coor, nedge, edge, user, ifail] = d06ba(coorch, lined, fbnd, crus, rate, nlcomp, lcomp, nvmax, nedmx, itrace, 'nlines', nlines, 'sdcrus', sdcrus, 'ncomp', ncomp, 'user', user)
[nvb, coor, nedge, edge, user, ifail] = nag_mesh_2d_gen_boundary(coorch, lined, fbnd, crus, rate, nlcomp, lcomp, nvmax, nedmx, itrace, 'nlines', nlines, 'sdcrus', sdcrus, 'ncomp', ncomp, 'user', user)

## Description

Given a closed connected subdomain Ω$\Omega$ of 2${ℝ}^{2}$, whose boundary Ω$\partial \Omega$ is divided by characteristic points into m$m$ distinct line segments, nag_mesh_2d_gen_boundary (d06ba) generates a boundary mesh on Ω$\partial \Omega$. Each line segment may be a straight line, a curve defined by the equation f(x,y) = 0$f\left(x,y\right)=0$, or a polygonal curve defined by a set of given boundary mesh points.
This function is primarily designed for use with either nag_mesh_2d_gen_inc (d06aa) (a simple incremental method) or nag_mesh_2d_gen_delaunay (d06ab) (Delaunay–Voronoi method) or nag_mesh_2d_gen_front (d06ac) (Advancing Front method) to triangulate the interior of the domain Ω$\Omega$. For more details about the boundary and interior mesh generation, consult the D06 Chapter Introduction as well as George and Borouchaki (1998).
This function is derived from material in the MODULEF package from INRIA (Institut National de Recherche en Informatique et Automatique).

## References

George P L and Borouchaki H (1998) Delaunay Triangulation and Meshing: Application to Finite Elements Editions HERMES, Paris

## Parameters

### Compulsory Input Parameters

1:     coorch(2$2$,nlines) – double array
coorch(1,i)${\mathbf{coorch}}\left(1,\mathit{i}\right)$ contains the x$x$ coordinate of the i$\mathit{i}$th characteristic point, for i = 1,2,,nlines$\mathit{i}=1,2,\dots ,{\mathbf{nlines}}$; while coorch(2,i)${\mathbf{coorch}}\left(2,i\right)$ contains the corresponding y$y$ coordinate.
2:     lined(4$4$,nlines) – int64int32nag_int array
The description of the lines that define the boundary domain. The line i$\mathit{i}$, for i = 1,2,,m$\mathit{i}=1,2,\dots ,m$, is defined as follows:
lined(1,i)${\mathbf{lined}}\left(1,i\right)$
The number of points on the line, including two end points.
lined(2,i)${\mathbf{lined}}\left(2,i\right)$
The first end point of the line. If lined(2,i) = j${\mathbf{lined}}\left(2,i\right)=j$, then the coordinates of the first end point are those stored in coorch( : ,j)${\mathbf{coorch}}\left(:,j\right)$.
lined(3,i)${\mathbf{lined}}\left(3,i\right)$
The second end point of the line. If lined(3,i) = k${\mathbf{lined}}\left(3,i\right)=k$, then the coordinates of the second end point are those stored in coorch( : ,k)${\mathbf{coorch}}\left(:,k\right)$.
lined(4,i)${\mathbf{lined}}\left(4,i\right)$
This defines the type of line segment connecting the end points. Additional information is conveyed by the numerical value of lined(4,i)${\mathbf{lined}}\left(4,i\right)$ as follows:
 (i) lined(4,i) > 0${\mathbf{lined}}\left(4,i\right)>0$, the line is described in fbnd with lined(4,i)${\mathbf{lined}}\left(4,i\right)$ as the index. In this case, the line must be described in the trigonometric (anticlockwise) direction; (ii) lined(4,i) = 0${\mathbf{lined}}\left(4,i\right)=0$, the line is a straight line; (iii) if lined(4,i) < 0${\mathbf{lined}}\left(4,i\right)<0$, say ( − p$-p$), then the line is a polygonal arc joining the end points and interior points specified in crus. In this case the line contains the points whose coordinates are stored in coorch( : ,j) ,  crus( : ,p) ,  crus( : ,p + 1) , … , crus( : ,p + r − 3) ,  coorch( : ,k) ${\mathbf{coorch}}\left(:,j\right),\phantom{\rule{0ex}{0ex}}{\mathbf{crus}}\left(:,p\right),\phantom{\rule{0ex}{0ex}}{\mathbf{crus}}\left(:,p+1\right),\dots ,{\mathbf{crus}}\left(:,p+r-3\right),\phantom{\rule{0ex}{0ex}}{\mathbf{coorch}}\left(:,k\right)$ , where z ∈ {1,2}$z\in \left\{1,2\right\}$, r = lined(1,i)$r={\mathbf{lined}}\left(1,i\right)$, j = lined(2,i)$j={\mathbf{lined}}\left(2,i\right)$ and k = lined(3,i)$k={\mathbf{lined}}\left(3,i\right)$.
Constraints:
• 2lined(1,i)$2\le {\mathbf{lined}}\left(1,i\right)$;
• 1lined(2,i)nlines$1\le {\mathbf{lined}}\left(2,i\right)\le {\mathbf{nlines}}$;
• 1lined(3,i)nlines$1\le {\mathbf{lined}}\left(3,i\right)\le {\mathbf{nlines}}$;
• lined(2,i)lined(3,i)${\mathbf{lined}}\left(2,\mathit{i}\right)\ne {\mathbf{lined}}\left(3,\mathit{i}\right)$, for i = 1,2,,nlines$\mathit{i}=1,2,\dots ,{\mathbf{nlines}}$.
For each line described by fbnd (lines with lined(4,i) > 0 ${\mathbf{lined}}\left(4,\mathit{i}\right)>0$, for i = 1,2,,nlines$\mathit{i}=1,2,\dots ,{\mathbf{nlines}}$) the two end points ( lined(2,i) ${\mathbf{lined}}\left(2,i\right)$ and lined(3,i) ${\mathbf{lined}}\left(3,i\right)$) lie on the curve defined by index lined(4,i)${\mathbf{lined}}\left(4,i\right)$ in fbnd, i.e.,
fbnd (lined(4,i),coorch(1,lined(2,i)),coorch(2,lined(2,i)),user,user) = 0 ${\mathbf{fbnd}}\left({\mathbf{lined}}\left(4,i\right),{\mathbf{coorch}}\left(1,{\mathbf{lined}}\left(2,i\right)\right),{\mathbf{coorch}}\left(2,{\mathbf{lined}}\left(2,i\right)\right),{\mathbf{user}},{\mathbf{user}}\right)=0$;
fbnd (lined(4,i),coorch(1,lined(3,i)),coorch(2,lined(3,i)),user,user) = 0 ${\mathbf{fbnd}}\left({\mathbf{lined}}\left(4,\mathit{i}\right),{\mathbf{coorch}}\left(1,{\mathbf{lined}}\left(3,\mathit{i}\right)\right),{\mathbf{coorch}}\left(2,{\mathbf{lined}}\left(3,\mathit{i}\right)\right),{\mathbf{user}},{\mathbf{user}}\right)=0$, for i = 1,2,,nlines$\mathit{i}=1,2,\dots ,{\mathbf{nlines}}$.
For all lines described as polygonal arcs (lines with lined(4,i) < 0 ${\mathbf{lined}}\left(4,\mathit{i}\right)<0$, for i = 1,2,,nlines$\mathit{i}=1,2,\dots ,{\mathbf{nlines}}$) the sets of intermediate points (i.e., [lined(4,i) : lined(4,i) + lined(1,i) 3 ] $\left[-{\mathbf{lined}}\left(4,i\right):-{\mathbf{lined}}\left(4,i\right)+{\mathbf{lined}}\left(1,i\right)-3\right]$ for all i$i$ such that lined(4,i) < 0${\mathbf{lined}}\left(4,i\right)<0$) are not overlapping. This can be expressed as:
 − lined(4,i) + lined(1,i) − 3 = ∑ { lined(1,i) − 2 } {i,lined(4,i) < 0}
$-lined4i + lined1i - 3 = ∑ {i,lined4i<0} { lined1i - 2 }$
or
 − lined(4,i) + lined(1,i) − 2 = − lined(4,j) , $-lined4i + lined1i - 2 = -lined4j ,$
for a j$j$ such that j = 1,2,,nlines$j=1,2,\dots ,{\mathbf{nlines}}$, ji$j\ne i$ and lined(4,j) < 0${\mathbf{lined}}\left(4,j\right)<0$.
3:     fbnd – function handle or string containing name of m-file
fbnd must be supplied to calculate the value of the function which describes the curve {(x,y)2; such that ​f(x,y) = 0} $\left\{\left(x,y\right)\in {ℝ}^{2}\text{; such that ​}f\left(x,y\right)=0\right\}$ on segments of the boundary for which lined(4,i) > 0${\mathbf{lined}}\left(4,i\right)>0$. If there are no boundaries for which lined(4,i) > 0${\mathbf{lined}}\left(4,i\right)>0$ fbnd will never be referenced by nag_mesh_2d_gen_boundary (d06ba) and fbnd may be the string 'd06bad'. (nag_mesh_2d_gen_boundary_dummy_fbnd (d06bad) is included in the NAG Toolbox.)
[result, user] = fbnd(ii, x, y, user)

Input Parameters

1:     ii – int64int32nag_int scalar
lined(4,i)${\mathbf{lined}}\left(4,i\right)$, the reference index of the line (portion of the contour) i$i$ described.
2:     x – double scalar
3:     y – double scalar
The values of x$x$ and y$y$ at which f(x,y)$f\left(x,y\right)$ is to be evaluated.
4:     user – Any MATLAB object
fbnd is called from nag_mesh_2d_gen_boundary (d06ba) with the object supplied to nag_mesh_2d_gen_boundary (d06ba).

Output Parameters

1:     result – double scalar
The result of the function.
2:     user – Any MATLAB object
4:     crus(2$2$,sdcrus) – double array
The coordinates of the intermediate points for polygonal arc lines. For a line i$i$ defined as a polygonal arc (i.e., lined(4,i) < 0${\mathbf{lined}}\left(4,i\right)<0$), if p = lined(4,i)$p=-{\mathbf{lined}}\left(4,i\right)$, then crus(1,k)${\mathbf{crus}}\left(1,\mathit{k}\right)$, for k = p,,p + lined(1,i)3$\mathit{k}=p,\dots ,p+{\mathbf{lined}}\left(1,i\right)-3$, must contain the x$x$ coordinate of the consecutive intermediate points for this line. Similarly crus(2,k)${\mathbf{crus}}\left(2,\mathit{k}\right)$, for k = p,,p + lined(1,i)3$\mathit{k}=p,\dots ,p+{\mathbf{lined}}\left(1,i\right)-3$, must contain the corresponding y$y$ coordinate.
5:     rate(nlines) – double array
nlines, the dimension of the array, must satisfy the constraint nlines1${\mathbf{nlines}}\ge 1$.
rate(i)${\mathbf{rate}}\left(\mathit{i}\right)$ is the geometric progression ratio between the points to be generated on the line i$\mathit{i}$, for i = 1,2,,m$\mathit{i}=1,2,\dots ,m$ and lined(4,i)0${\mathbf{lined}}\left(4,i\right)\ge 0$.
If lined(4,i) < 0${\mathbf{lined}}\left(4,i\right)<0$, rate(i)${\mathbf{rate}}\left(i\right)$ is not referenced.
Constraint: if lined(4,i)0${\mathbf{lined}}\left(4,i\right)\ge 0$, rate(i) > 0.0${\mathbf{rate}}\left(\mathit{i}\right)>0.0$, for i = 1,2,,nlines$\mathit{i}=1,2,\dots ,{\mathbf{nlines}}$.
6:     nlcomp(ncomp) – int64int32nag_int array
ncomp, the dimension of the array, must satisfy the constraint ncomp1${\mathbf{ncomp}}\ge 1$.
|nlcomp(k)|$|{\mathbf{nlcomp}}\left(k\right)|$ is the number of line segments in component k$k$ of the contour. The line i$i$ of component k$k$ runs in the direction lined(2,i)${\mathbf{lined}}\left(2,i\right)$ to lined(3,i)${\mathbf{lined}}\left(3,i\right)$ if nlcomp(k) > 0${\mathbf{nlcomp}}\left(k\right)>0$, and in the opposite direction otherwise; for k = 1,2,,n$k=1,2,\dots ,n$.
Constraints:
• 1|nlcomp(k)|nlines$1\le |{\mathbf{nlcomp}}\left(\mathit{k}\right)|\le {\mathbf{nlines}}$, for k = 1,2,,ncomp$\mathit{k}=1,2,\dots ,{\mathbf{ncomp}}$;
• k = 1 n |nlcomp(k)| = nlines $\sum _{k=1}^{n}|{\mathbf{nlcomp}}\left(k\right)|={\mathbf{nlines}}$.
7:     lcomp(nlines) – int64int32nag_int array
nlines, the dimension of the array, must satisfy the constraint nlines1${\mathbf{nlines}}\ge 1$.
lcomp(l1 : l2)${\mathbf{lcomp}}\left(l1:l2\right)$, where l2 = i = 1k |nlcomp(i)| $l2=\sum _{i=1}^{k}|{\mathbf{nlcomp}}\left(i\right)|$ and l1 = l2 + 1|nlcomp(k)|$l1=l2+1-|{\mathbf{nlcomp}}\left(\mathit{k}\right)|$ is the list of line numbers for the k$\mathit{k}$th components of the boundary, for k = 1,2,,ncomp$\mathit{k}=1,2,\dots ,{\mathbf{ncomp}}$.
Constraint: lcomp${\mathbf{lcomp}}$ must hold a valid permutation of the integers [1,nlines]$\left[1,{\mathbf{nlines}}\right]$.
8:     nvmax – int64int32nag_int scalar
The maximum number of the boundary mesh vertices to be generated.
Constraint: ${\mathbf{nvmax}}\ge {\mathbf{nlines}}$.
9:     nedmx – int64int32nag_int scalar
The maximum number of boundary edges in the boundary mesh to be generated.
Constraint: nedmx1${\mathbf{nedmx}}\ge 1$.
10:   itrace – int64int32nag_int scalar
The level of trace information required from nag_mesh_2d_gen_boundary (d06ba).
itrace = 0${\mathbf{itrace}}=0$ or itrace < 1${\mathbf{itrace}}<-1$
No output is generated.
itrace = 1${\mathbf{itrace}}=1$
Output from the boundary mesh generator is printed on the current advisory message unit (see nag_file_set_unit_advisory (x04ab)). This output contains the input information of each line and each connected component of the boundary.
itrace = 1${\mathbf{itrace}}=-1$
An analysis of the output boundary mesh is printed on the current advisory message unit. This analysis includes the orientation (clockwise or anticlockwise) of each connected component of the boundary. This information could be of interest to you, especially if an interior meshing is carried out using the output of this function, calling either nag_mesh_2d_gen_inc (d06aa), nag_mesh_2d_gen_delaunay (d06ab) or nag_mesh_2d_gen_front (d06ac).
itrace > 1${\mathbf{itrace}}>1$
The output is similar to that produced when itrace = 1${\mathbf{itrace}}=1$, but the coordinates of the generated vertices on the boundary are also output.
You are advised to set itrace = 0${\mathbf{itrace}}=0$, unless you are experienced with finite element mesh generation.

### Optional Input Parameters

1:     nlines – int64int32nag_int scalar
Default: The dimension of the arrays coorch, lined, rate, lcomp. (An error is raised if these dimensions are not equal.)
m$m$, the number of lines that define the boundary of the closed connected subdomain (this equals the number of characteristic points which separate the entire boundary Ω$\partial \Omega$ into lines).
Constraint: nlines1${\mathbf{nlines}}\ge 1$.
2:     sdcrus – int64int32nag_int scalar
Default: The second dimension of the array crus.
The second dimension of the array crus as declared in the (sub)program from which nag_mesh_2d_gen_boundary (d06ba) is called.
Constraint: sdcrus{i,lined(4,i) < 0} {lined(1,i)2}${\mathbf{sdcrus}}\ge \sum _{\left\{i,{\mathbf{lined}}\left(4,i\right)<0\right\}}\phantom{\rule{0.25em}{0ex}}\left\{{\mathbf{lined}}\left(1,i\right)-2\right\}$.
3:     ncomp – int64int32nag_int scalar
Default: The dimension of the array nlcomp.
n$n$, the number of separately connected components of the boundary.
Constraint: ncomp1${\mathbf{ncomp}}\ge 1$.
4:     user – Any MATLAB object
user is not used by nag_mesh_2d_gen_boundary (d06ba), but is passed to fbnd. Note that for large objects it may be more efficient to use a global variable which is accessible from the m-files than to use user.

### Input Parameters Omitted from the MATLAB Interface

ruser iuser rwork lrwork iwork liwork

### Output Parameters

1:     nvb – int64int32nag_int scalar
The total number of boundary mesh vertices generated.
2:     coor(2$2$,nvmax) – double array
coor(1,i)${\mathbf{coor}}\left(1,\mathit{i}\right)$ will contain the x$x$ coordinate of the i$\mathit{i}$th boundary mesh vertex generated, for i = 1,2,,nvb$\mathit{i}=1,2,\dots ,{\mathbf{nvb}}$; while coor(2,i)${\mathbf{coor}}\left(2,i\right)$ will contain the corresponding y$y$ coordinate.
3:     nedge – int64int32nag_int scalar
The total number of boundary edges in the boundary mesh.
4:     edge(3$3$,nedmx) – int64int32nag_int array
The specification of the boundary edges. edge(1,j)${\mathbf{edge}}\left(1,j\right)$ and edge(2,j)${\mathbf{edge}}\left(2,j\right)$ will contain the vertex numbers of the two end points of the j$j$th boundary edge. edge(3,j)${\mathbf{edge}}\left(3,j\right)$ is a reference number for the j$j$th boundary edge and
• edge(3,j) = lined(4,i)${\mathbf{edge}}\left(3,j\right)={\mathbf{lined}}\left(4,i\right)$, where i$i$ and j$j$ are such that the j$j$th edges is part of the i$i$th line of the boundary and lined(4,i)0${\mathbf{lined}}\left(4,i\right)\ge 0$;
• edge(3,j) = 100 + |lined(4,i)|${\mathbf{edge}}\left(3,j\right)=100+|{\mathbf{lined}}\left(4,i\right)|$, where i$i$ and j$j$ are such that the j$j$th edges is part of the i$i$th line of the boundary and lined(4,i) < 0${\mathbf{lined}}\left(4,i\right)<0$.
5:     user – Any MATLAB object
6:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

Errors or warnings detected by the function:
ifail = 1${\mathbf{ifail}}=1$
 On entry, nlines < 1${\mathbf{nlines}}<1$; or ${\mathbf{nvmax}}<{\mathbf{nlines}}$; or nedmx < 1${\mathbf{nedmx}}<1$; or ncomp < 1${\mathbf{ncomp}}<1$; or lrwork < 2 × (nlines + sdcrus) + 2 × maxi = 1,2, … ,m{lined(1,i)} × nlines$\mathit{lrwork}<2×\left({\mathbf{nlines}}+{\mathbf{sdcrus}}\right)+2×{\mathrm{max}}_{i=1,2,\dots ,m}\left\{{\mathbf{lined}}\left(1,i\right)\right\}×{\mathbf{nlines}}$; or liwork < ∑ {i, lined(4,i) < 0 }  {lined(1,i) − 2} + 8 × nlines + nvmax + 3 ×   nedmx + 2 × sdcrus $\mathit{liwork}<\sum _{\left\{i,{\mathbf{lined}}\left(4,i\right)<0\right\}}\phantom{\rule{0.25em}{0ex}}\left\{{\mathbf{lined}}\left(1,i\right)-2\right\}+8×{\mathbf{nlines}}+{\mathbf{nvmax}}+3×\phantom{\rule{0ex}{0ex}}{\mathbf{nedmx}}+2×{\mathbf{sdcrus}}$; or sdcrus < ∑ {i, lined(4,i) < 0 }  {lined(1,i) − 2} ${\mathbf{sdcrus}}<\sum _{\left\{i,{\mathbf{lined}}\left(4,i\right)<0\right\}}\phantom{\rule{0.25em}{0ex}}\left\{{\mathbf{lined}}\left(1,i\right)-2\right\}$; or rate(i) < 0.0${\mathbf{rate}}\left(i\right)<0.0$ for some i = 1,2, … ,nlines$i=1,2,\dots ,{\mathbf{nlines}}$ with lined(4,i) ≥ 0${\mathbf{lined}}\left(4,i\right)\ge 0$; or lined(1,i) < 2${\mathbf{lined}}\left(1,i\right)<2$ for some i = 1,2, … ,nlines$i=1,2,\dots ,{\mathbf{nlines}}$; or lined(2,i) < 1${\mathbf{lined}}\left(2,i\right)<1$ or lined(2,i) > nlines${\mathbf{lined}}\left(2,i\right)>{\mathbf{nlines}}$ for some i = 1,2, … ,nlines$i=1,2,\dots ,{\mathbf{nlines}}$; or lined(3,i) < 1${\mathbf{lined}}\left(3,i\right)<1$ or lined(3,i) > nlines${\mathbf{lined}}\left(3,i\right)>{\mathbf{nlines}}$ for some i = 1,2, … ,nlines$i=1,2,\dots ,{\mathbf{nlines}}$; or lined(2,i) = lined(3,i)${\mathbf{lined}}\left(2,i\right)={\mathbf{lined}}\left(3,i\right)$ for some i = 1,2, … ,nlines$i=1,2,\dots ,{\mathbf{nlines}}$; or nlcomp(k) = 0${\mathbf{nlcomp}}\left(k\right)=0$, or |nlcomp(k)| > nlines$|{\mathbf{nlcomp}}\left(k\right)|>{\mathbf{nlines}}$ for a k = 1,2, … ,ncomp$k=1,2,\dots ,{\mathbf{ncomp}}$; or ∑ k = 1 n |nlcomp(k)| ≠ nlines $\sum _{k=1}^{n}|{\mathbf{nlcomp}}\left(k\right)|\ne {\mathbf{nlines}}$; or lcomp does not represent a valid permutation of the integers in [1,nlines]$\left[1,{\mathbf{nlines}}\right]$; or one of the end points for a line i$\mathit{i}$ described by the user-supplied function (lines with lined(4,i) > 0${\mathbf{lined}}\left(4,\mathit{i}\right)>0$, for i = 1,2, … ,nlines$\mathit{i}=1,2,\dots ,{\mathbf{nlines}}$) does not belong to the corresponding curve in fbnd; or the intermediate points for the lines described as polygonal arcs (lines with lined(i) < 0${\mathbf{lined}}\left(\mathit{i}\right)<0$, for i = 1,2, … ,nlines$\mathit{i}=1,2,\dots ,{\mathbf{nlines}}$) are overlapping.
ifail = 2${\mathbf{ifail}}=2$
An error has occurred during the generation of the boundary mesh. It appears that nedmx is not large enough, so you are advised to increase the value of nedmx.
ifail = 3${\mathbf{ifail}}=3$
An error has occurred during the generation of the boundary mesh. It appears that nvmax is not large enough, so you are advised to increase the value of nvmax.
ifail = 4${\mathbf{ifail}}=4$
An error has occurred during the generation of the boundary mesh. Check the definition of each line (the parameter lined) and each connected component of the boundary (the arguments nlcomp, and lcomp, as well as the coordinates of the characteristic points. Setting itrace > 0${\mathbf{itrace}}>0$ may provide more details.

## Accuracy

Not applicable.

The boundary mesh generation technique in this function has a ‘tree’ structure. The boundary should be partitioned into geometrically simple segments (straight lines or curves) delimited by characteristic points. Then, the lines should be assembled into connected components of the boundary domain.
Using this strategy, the inputs to that function can be built up, following the requirements stated in Section [Parameters]:
The example below details the use of this strategy.

## Example

```function nag_mesh_2d_gen_boundary_example
coorch = [9.5,33,9.5,-14,-4,-2,2,4,2,-2,-4,-2,2,4,7,9,13,16,9,12,7,10,...
18,21,17,20,16,20,15.5,16,18,21,16,18,18.5811,21,17,20,20.5,23;
-1,7.5,16,7.5,3,3,3,3,7,8,12,12,12,12,3,3,3,3,5,5,12,12,2,2,3,3,...
5,5,6,6,6,6,6.5,6.5,10.0811,10.0811,10.7361,10.7361,12,12];
lined = [int64(15),15,15,15,4,10,10,4,15,4,10,10,4,15,4,7,4,7,4,13,5,13,4,...
10,4,4,10,4,4,4,4,4,10,4,4,4,4,10,4,4;
1,2,3,4,6,10,7,8,14,13,9,12,11,5,16,19,20,17,18,22,21,15,24,24,31,...
34,34,36,40,39,38,37,37,30,29,27,28,26,25,23;
2,3,4,1,5,6,10,7,8,14,13,9,12,11,15,16,19,20,17,18,22,21,23,32,32,...
31,35,35,36,40,39,38,33,33,30,29,27,28,26,25;
1,1,1,1,-1,0,0,-3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,...
0,3,0,0,0,0,0,4,0,0,0,0,5,0,0];
coorus = zeros(2, 100);
coorus(1,(1:4))=[-2.6667,-3.3333,3.3333,2.6667];
coorus(2,(1:4))=[3,3,3,3];
rate = [0.95;1.05;0.95;1.05;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;
1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1];
nlcomp = [int64(4);10;8;18];
lcomp = [int64(1);2;3;4;14;13;12;11;10;9;8;7;6;5;22;21;20;19;18;
17;16;15;30;29;28;27;26;25;24;23;40;39;38;37;36;35;34;33;32;31];
nvmax = int64(1000);
nedmx = int64(300);
itrace = int64(-1);
user = [23.5; 8.5; 9.5; 7.5];
[nvb, coor, nedge, edge, user, ifail] = ...
nag_mesh_2d_gen_boundary(coorch, lined, @fbnd, coorus, rate, nlcomp, lcomp, nvmax, ...
nedmx, itrace, 'user', user);
nvb, nedge, ifail

function [result, user] = fbnd(i, x, y, user)
xa = user(1);
xb = user(2);
x0 = user(3);
y0 = user(4);

result = 0.d0;
if (i == 1)
% line 1,2,3, and 4: ellipse centred in (x0,y0) with
% xa and xb as coefficients
result = ((x-x0)/xa)^2 + ((y-y0)/xb)^2 - 1.d0;
elseif (i == 2)
% line 24, 27, 33 and 38 are a circle centred in (x0,y0)
x0 = 20.5d0;
y0 = 4.d0;
result = (x-x0)^2 + (y-y0)^2 - radius2;
elseif (i == 3)
x0 = 17.d0;
y0 = 8.5d0;
result = (x-x0)^2 + (y-y0)^2 - radius2;
elseif (i == 4)
x0 = 17.d0;
y0 = 8.5d0;
result = (x-x0)^2 + (y-y0)^2 - radius2;
elseif (i == 5)
x0 = 19.5d0;
y0 = 4.d0;
result = (x-x0)^2 + (y-y0)^2 - radius2;
end
```
```
ANALYSIS OF THE BOUNDARY CREATED:
THE BOUNDARY MESH CONTAINS    259 VERTEX AND    259 EDGES
THERE ARE      4 COMPONENTS CONNECTED THE BOUNDARY
THE  1-st COMPONENT CONTAINS      4 LINES IN ANTICLOCKWISE ORIENTATION
THE  2-nd COMPONENT CONTAINS     10 LINES IN CLOCKWISE ORIENTATION
THE  3-rd COMPONENT CONTAINS      8 LINES IN CLOCKWISE ORIENTATION
THE  4-th COMPONENT CONTAINS     18 LINES IN CLOCKWISE ORIENTATION

nvb =

259

nedge =

259

ifail =

0

```
```function d06ba_example
coorch = [9.5,33,9.5,-14,-4,-2,2,4,2,-2,-4,-2,2,4,7,9,13,16,9,12,7,10,...
18,21,17,20,16,20,15.5,16,18,21,16,18,18.5811,21,17,20,20.5,23;
-1,7.5,16,7.5,3,3,3,3,7,8,12,12,12,12,3,3,3,3,5,5,12,12,2,2,3,3,...
5,5,6,6,6,6,6.5,6.5,10.0811,10.0811,10.7361,10.7361,12,12];
lined = [int64(15),15,15,15,4,10,10,4,15,4,10,10,4,15,4,7,4,7,4,13,5,13,4,...
10,4,4,10,4,4,4,4,4,10,4,4,4,4,10,4,4;
1,2,3,4,6,10,7,8,14,13,9,12,11,5,16,19,20,17,18,22,21,15,24,24,31,...
34,34,36,40,39,38,37,37,30,29,27,28,26,25,23;
2,3,4,1,5,6,10,7,8,14,13,9,12,11,15,16,19,20,17,18,22,21,23,32,32,...
31,35,35,36,40,39,38,33,33,30,29,27,28,26,25;
1,1,1,1,-1,0,0,-3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,...
0,3,0,0,0,0,0,4,0,0,0,0,5,0,0];
coorus = zeros(2, 100);
coorus(1,(1:4))=[-2.6667,-3.3333,3.3333,2.6667];
coorus(2,(1:4))=[3,3,3,3];
rate = [0.95;1.05;0.95;1.05;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;
1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1];
nlcomp = [int64(4);10;8;18];
lcomp = [int64(1);2;3;4;14;13;12;11;10;9;8;7;6;5;22;21;20;19;18;
17;16;15;30;29;28;27;26;25;24;23;40;39;38;37;36;35;34;33;32;31];
nvmax = int64(1000);
nedmx = int64(300);
itrace = int64(-1);
user = [23.5; 8.5; 9.5; 7.5];
[nvb, coor, nedge, edge, user, ifail] = ...
d06ba(coorch, lined, @fbnd, coorus, rate, nlcomp, lcomp, nvmax, ...
nedmx, itrace, 'user', user);
nvb, nedge, ifail

function [result, user] = fbnd(i, x, y, user)
xa = user(1);
xb = user(2);
x0 = user(3);
y0 = user(4);

result = 0.d0;
if (i == 1)
% line 1,2,3, and 4: ellipse centred in (x0,y0) with
% xa and xb as coefficients
result = ((x-x0)/xa)^2 + ((y-y0)/xb)^2 - 1.d0;
elseif (i == 2)
% line 24, 27, 33 and 38 are a circle centred in (x0,y0)
x0 = 20.5d0;
y0 = 4.d0;
result = (x-x0)^2 + (y-y0)^2 - radius2;
elseif (i == 3)
x0 = 17.d0;
y0 = 8.5d0;
result = (x-x0)^2 + (y-y0)^2 - radius2;
elseif (i == 4)
x0 = 17.d0;
y0 = 8.5d0;
result = (x-x0)^2 + (y-y0)^2 - radius2;
elseif (i == 5)
x0 = 19.5d0;
y0 = 4.d0;
result = (x-x0)^2 + (y-y0)^2 - radius2;
end
```
```
ANALYSIS OF THE BOUNDARY CREATED:
THE BOUNDARY MESH CONTAINS    259 VERTEX AND    259 EDGES
THERE ARE      4 COMPONENTS CONNECTED THE BOUNDARY
THE  1-st COMPONENT CONTAINS      4 LINES IN ANTICLOCKWISE ORIENTATION
THE  2-nd COMPONENT CONTAINS     10 LINES IN CLOCKWISE ORIENTATION
THE  3-rd COMPONENT CONTAINS      8 LINES IN CLOCKWISE ORIENTATION
THE  4-th COMPONENT CONTAINS     18 LINES IN CLOCKWISE ORIENTATION

nvb =

259

nedge =

259

ifail =

0

```