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_mesh_2d_join (d06db)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_mesh_2d_join (d06db) joins together (restitches) two adjacent, or overlapping, meshes.

Syntax

[nv3, nelt3, nedge3, coor3, edge3, conn3, reft3, ifail] = d06db(coor1, edge1, conn1, reft1, coor2, edge2, conn2, reft2, itrace, 'eps', eps, 'nv1', nv1, 'nelt1', nelt1, 'nedge1', nedge1, 'nv2', nv2, 'nelt2', nelt2, 'nedge2', nedge2)
[nv3, nelt3, nedge3, coor3, edge3, conn3, reft3, ifail] = nag_mesh_2d_join(coor1, edge1, conn1, reft1, coor2, edge2, conn2, reft2, itrace, 'eps', eps, 'nv1', nv1, 'nelt1', nelt1, 'nedge1', nedge1, 'nv2', nv2, 'nelt2', nelt2, 'nedge2', nedge2)

Description

nag_mesh_2d_join (d06db) joins together two adjacent, or overlapping, meshes. If the two meshes are adjacent then vertices belonging to the part of the boundary forming the common interface should coincide. If the two meshes overlap then vertices and triangles in the overlapping zone should coincide too.
This function is partly derived from material in the MODULEF package from INRIA (Institut National de Recherche en Informatique et Automatique).

References

None.

Parameters

Compulsory Input Parameters

1:     coor12nv1 – double array
coor11i contains the x coordinate of the ith vertex of the first input mesh, for i=1,2,,nv1; while coor12i contains the corresponding y coordinate.
2:     edge13nedge1 int64int32nag_int array
The specification of the boundary edges of the first input mesh. edge11j and edge12j contain the vertex numbers of the two end points of the jth boundary edge. edge13j is a user-supplied tag for the jth boundary edge.
Constraint: 1edge1ijnv1 and edge11jedge12j, for i=1,2 and j=1,2,,nedge1.
3:     conn13nelt1 int64int32nag_int array
The connectivity between triangles and vertices of the first input mesh. For each triangle j, conn1ij gives the indices of its three vertices (in anticlockwise order), for i=1,2,3 and j=1,2,,nelt1.
Constraints:
  • 1conn1ijnv1;
  • conn11jconn12j;
  • conn11jconn13j and conn12jconn13j, for i=1,2,3 and j=1,2,,nelt1.
4:     reft1nelt1 int64int32nag_int array
reft1k contains the user-supplied tag of the kth triangle from the first input mesh, for k=1,2,,nelt1.
5:     coor22nv2 – double array
coor21i contains the x coordinate of the ith vertex of the second input mesh, for i=1,2,,nv2; while coor22i contains the corresponding y coordinate.
6:     edge23nedge2 int64int32nag_int array
The specification of the boundary edges of the second input mesh. edge21j and edge22j contain the vertex numbers of the two end points of the jth boundary edge. edge23j is a user-supplied tag for the jth boundary edge.
Constraint: 1edge2ijnv2 and edge21jedge22j, for i=1,2 and j=1,2,,nedge2.
7:     conn23nelt2 int64int32nag_int array
The connectivity between triangles and vertices of the second input mesh. For each triangle j, conn2ij gives the indices of its three vertices (in anticlockwise order), for i=1,2,3 and j=1,2,,nelt2.
Constraints:
  • 1conn2ijnv2;
  • conn21jconn22j;
  • conn21jconn23j and conn22jconn23j, for i=1,2,3 and j=1,2,,nelt2.
8:     reft2nelt2 int64int32nag_int array
reft2k contains the user-supplied tag of the kth triangle from the second input mesh, for k=1,2,,nelt2.
9:     itrace int64int32nag_int scalar
The level of trace information required from nag_mesh_2d_join (d06db).
itrace0
No output is generated.
itrace1
Details about the common vertices, edges and triangles to both meshes are printed on the current advisory message unit (see nag_file_set_unit_advisory (x04ab)).

Optional Input Parameters

1:     eps – double scalar
Default: 0.001.
The relative precision of the restitching of the two input meshes (see Further Comments).
Constraint: eps>0.0.
2:     nv1 int64int32nag_int scalar
Default: the dimension of the array coor1.
The total number of vertices in the first input mesh.
Constraint: nv13.
3:     nelt1 int64int32nag_int scalar
Default: the dimension of the arrays conn1, reft1. (An error is raised if these dimensions are not equal.)
The number of triangular elements in the first input mesh.
Constraint: nelt12×nv1-1.
4:     nedge1 int64int32nag_int scalar
Default: the dimension of the array edge1.
The number of boundary edges in the first input mesh.
Constraint: nedge11.
5:     nv2 int64int32nag_int scalar
Default: the dimension of the array coor2.
The total number of vertices in the second input mesh.
Constraint: nv23.
6:     nelt2 int64int32nag_int scalar
Default: the dimension of the arrays conn2, reft2. (An error is raised if these dimensions are not equal.)
The number of triangular elements in the second input mesh.
Constraint: nelt22×nv2-1.
7:     nedge2 int64int32nag_int scalar
Default: the dimension of the array edge2.
The number of boundary edges in the second input mesh.
Constraint: nedge21.

Output Parameters

1:     nv3 int64int32nag_int scalar
The total number of vertices in the resulting mesh.
2:     nelt3 int64int32nag_int scalar
The number of triangular elements in the resulting mesh.
3:     nedge3 int64int32nag_int scalar
The number of boundary edges in the resulting mesh.
4:     coor32: – double array
The second dimension of the array coor3 will be nv1+nv2.
coor31i will contain the x coordinate of the ith vertex of the resulting mesh, for i=1,2,,nv3; while coor32i will contain the corresponding y coordinate.
5:     edge33: int64int32nag_int array
The second dimension of the array edge3 will be nedge1+nedge2. This may be reduced to nedge3 once that value is known.
The specification of the boundary edges of the resulting mesh. edge3ij will contain the vertex number of the ith end point (i=1,2) of the jth boundary or interface edge.
If the two meshes overlap, edge33j will contain the same tag as the corresponding edge belonging to the first and/or the second input mesh.
If the two meshes are adjacent,
(i) if the jth edge is part of the partition interface, then edge33j will contain the value 1000×k1+k2 where k1 and k2 are the tags for the same edge of the first and the second mesh respectively;
(ii) otherwise, edge33j will contain the same tag as the corresponding edge belonging to the first and/or the second input mesh.
6:     conn33: int64int32nag_int array
The second dimension of the array conn3 will be nelt1+nelt2. This may be reduced to nelt3 once that value is known.
The connectivity between triangles and vertices of the resulting mesh. conn3ij will give the indices of its three vertices (in anticlockwise order), for i=1,2,3 and j=1,2,,nelt3.
7:     reft3: int64int32nag_int array
The dimension of the array reft3 will be nelt1+nelt2. This may be reduced to nelt3 once that value is known
If the two meshes form a partition, reft3k will contain the same tag as the corresponding triangle belonging to the first or the second input mesh, for k=1,2,,nelt3. If the two meshes overlap, then reft3k will contain the value 1000×k1+k2 where k1 and k2 are the user-supplied tags for the same triangle of the first and the second mesh respectively, for k=1,2,,nelt3.
8:     ifail int64int32nag_int scalar
ifail=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
On entry,eps0.0,
ornv1<3,
ornelt1>2×nv1-1,
ornedge1<1,
oredge1ij<1 or edge1ij>nv1 for some i=1,2 and j=1,2,,nedge1,
oredge11j=edge12j for some j=1,2,,nedge1,
orconn1ij<1 or conn1ij>nv1 for some i=1,2,3 and j=1,2,,nelt1,
orconn11j=conn12j or conn11j=conn13j or
conn12j=conn13j for some j=1,2,,nelt1,
ornv2<3,
ornelt2>2×nv2-1,
ornedge2<1,
oredge2ij<1 or edge2ij>nv2 for some i=1,2 and j=1,2,,nedge2,
oredge21j=edge22j for some j=1,2,,nedge2,
orconn2ij<1 or conn2ij>nv2 for some i=1,2,3 and j=1,2,,nelt2,
orconn21j=conn22j or conn21j=conn23j or
conn22j=conn23j for some j=1,2,,nelt2,
orliwork<2×nv1+3×nv2+nelt1+nelt2+nedge1+nedge2+1024.
   ifail=2
Using the input precision eps, the function has detected fewer than two coincident vertices between the two input meshes. You are advised to try another value of eps; if this error still occurs the two meshes are probably not stitchable.
   ifail=3
A serious error has occurred in an internal call to the restitching function. You should check the input of the two meshes, especially the edge/vertex and/or the triangle/vertex connectivities. If the problem persists, contact NAG.
   ifail=4
The function has detected a different number of coincident triangles from the two input meshes in the overlapping zone. You should check the input of the two meshes, especially the triangle/vertex connectivities.
   ifail=5
The function has detected a different number of coincident edges from the two meshes on the partition interface. You should check the input of the two meshes, especially the edge/vertex connectivities.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

Accuracy

Not applicable.

Further Comments

nag_mesh_2d_join (d06db) finds all the common vertices between the two input meshes using the relative precision of the restitching argument eps. You are advised to vary the value of eps in the neighbourhood of 0.001 with itrace1 to get the optimal value for the meshes under consideration.

Example

For this function two examples are presented. There is a single example program for nag_mesh_2d_join (d06db), with a main program and the code to solve the two example problems given in Example 1 (EX1) and Example 2 (EX2).
Example 1 (EX1)
This example involves the unit square 0,12 meshed uniformly, and then translated by a vector u= u1 u2  (using nag_mesh_2d_transform_affine (d06da)). This translated mesh is then restitched with the original mesh. Two cases are considered:
(a) overlapping meshes (u1=15.0, u2=17.0),
(b) partitioned meshes (u1=19.0, u2=0.0).
Example 2 (EX2)
This example restitches three geometries by calling the function nag_mesh_2d_join (d06db) twice. The result is a mesh with three partitions. The first geometry is meshed by the Delaunay–Voronoi process (using nag_mesh_2d_gen_delaunay (d06ab)), the second one meshed by an Advancing Front algorithm (using nag_mesh_2d_gen_front (d06ac)), while the third one is the result of a rotation (by -π/2) of the second one (using nag_mesh_2d_transform_affine (d06da)).
function d06db_example


fprintf('d06db example results\n\n');

d06db_ex1;
d06db_ex2;



function d06db_ex1

  fprintf('Example 1\n\n');
  n = 20;
  coor1 = zeros(2,n^2);
  dx = [0:1/(n-1):1];
  for j = 1:n
    coor1(1,(j-1)*n+1:j*n) = dx;
    coor1(2,(j-1)*n+1:j*n) = dx(j);
  end
  edge1 = ones(3, 4*n-4, 'int64');
  ind = int64(1:n-1);
  edge1(1, 1:(4*n-4)) = [ind,n*ind,n^2+1-ind,n^2+1-n*ind];
  edge1(2, 1:(4*n-5)) = edge1(1, 2:(4*n-4));
  edge1(2, 4*n-4)     = edge1(1, 1);
  conn1 = zeros(3, 2*(n-1)^2, 'int64');

  k = 0;
  l = int64(0);
  for i=1:n-1
    for j=1:n-1
       l = l + 1;
       k = k + 1;
       conn1(1, k) = l;
       conn1(2, k) = l + 1;
       conn1(3, k) = l + n + 1;
       k = k + 1;
       conn1(1, k) = l;
       conn1(2, k) = l + n + 1;
       conn1(3, k) = l + n;
    end
    l = l + 1;
  end
  reft1 = ones(2*(n-1)^2, 1, 'int64');
  reft2 = reft1;
  reft2(:) = int64(2);
  itype = [int64(1)];
  itrace = int64(1);

  for ktrans = 1:2
    if ktrans==2
      % Transform the first domain to obtain an overlapping second domain
      a = (n-5)/(n-1);
      b = (n-3)/(n-1);
      trans = [a; b; 0; 0; 0; 0];
      % plot boundary for partitioned geometry 
      fig3 = figure;
      plot([0 1  1 0 0], [0 0 1 1 0], 'black', ...
           [a a+1 a+1 a a],[b b b+1 b+1 b],'black')
      axis off
      axis equal
      title('Figure 3: Boundary of overlapping squares');
      fig4 = figure;
    else
      % Domains partition
      trans = [1; 0; 0; 0; 0; 0];
      % plot boundary for partitioned geometry 
      fig1 = figure;
      plot([0 2  2 0 0],[0 0 1 1 0],'black',[1 1],[0, 1],'black')
      axis off
      axis equal
      title('Figure 1: Boundary of partitioned squares');
      fig2 = figure;
    end
    [coor1, edge1, conn1, coor2, edge2, conn2, ifail] = ...
    d06da( ...
           itype, trans, coor1, edge1, conn1, itrace);

    % Restitch the meshes
    [nv3, nelt3, nedge3, coor3, edge3, conn3, reft3, ifail] = ...
    d06db( ...
           coor1, edge1, conn1, reft1, coor2, edge2, conn2, reft2, itrace);

    % Plot the result
    triplot(transpose(double(conn3(:,1:nelt3))), coor3(1,:), coor3(2,:));
    axis equal;
    axis off;
    if ktrans==2
      title ('Figure 4: mesh for two overlapping squares');
    else
      title ('Figure 2: mesh for two partitioned squares');
    end

  end
function d06db_ex2

  fprintf('\n\nExample 2\n\n');

  % First Geometry
  % -----------------------------------------------------------
  nlines = 9;
  % Characteristic points of the boundary mesh
  coorch = [ 2   2   1  -1  -2.2361   0.0000   0   0   0.0000;
            -1   1   0   0   0.0000  -2.2361  -1   1   2.2361];
  % Lines of the boundary mesh
  n10 = int64(10);
  line = [n10 10 10 10 10 10 10 10 10;
            1  2  9  5  6  3  8  4  7;
            2  9  5  6  1  8  4  7  3;
            0  2  2  2  2  1  1  1  1];
  rate = ones(nlines,1);
  % number of connected components
  ncomp = 2;
  nlcomp = int64([5; -4]);
  lcomp = ones(nlines,1,'int64');
  lcomp(1:nlcomp(1))        = [1   2   3   4   5];
  lcomp(nlcomp(1)+1:nlines) = [9   8   7   6];

  % Generate boundary mesh
  nvmax = int64(700);
  nedmx = int64(200);
  itrace = int64(0);
  crus = [0; 0];
  [nvb1, coor1, nedge1, edge1, user, ifail] = ...
  d06ba( ...
         coorch, line, @fbnd, crus, rate, nlcomp, lcomp, nvmax, ...
         nedmx, itrace);

  % Generate mesh using Delaunay-Voronoi method
  weight = [];
  npropa = int64(1);
  [nv1, nelt1, coor1, conn1, ifail] = ...
  d06ab( ...
         nvb1, edge1, coor1, weight, npropa, itrace, 'nedge', nedge1);

  % Smooth
  numfix = int64([0]);
  nqint = int64(0);
  [coor1, ifail] = d06ca( ...
                          coor1, edge1, conn1, numfix, itrace, nqint, ...
                          'nv', nv1, 'nelt', nelt1, 'nedge', nedge1, ...
                          'nvfix', int64(0));
  
  % Second Geometry
  % -----------------------------------------------------------
  nlines = 4;
  % Characteristic points of the boundary mesh
  coorch = [ 2   6   6   2;
            -1  -1   1   1];
  % Lines of the boundary mesh
  n19 = int64(19);
  line = [n19 10 19 10;
            1  2  3  4;
            2  3  4  1;
            0  0  0  0];
  rate = ones(nlines,1);
  % number of connected components
  ncomp = 1;
  nlcomp = [int64(4)];
  lcomp = int64([1   2   3   4]);

  % Generate boundary mesh
  [nvb2, coor2, nedge2, edge2, user, ifail] = ...
  d06ba( ...
         coorch, line, @fbnd, crus, rate, nlcomp, lcomp, nvmax, ...
         nedmx, itrace);
  % Generate mesh using Advancing Front method
  [nv2, nelt2, coor2, conn2, ifail] = ...
  d06ac( ...
         nvb2, edge2, coor2, weight, itrace, 'nedge', nedge2);

  % Third Geometry (rotation and translation of second)
  % -----------------------------------------------------------
  itype = [int64(3)];
  trans = [6; -1; -90; 0; 0; 0];
  [coor3, edge3, conn3, coor3, edge3, conn3, ifail] = ...
  d06da( ...
         itype, trans, coor2, edge2, conn2, itrace, 'nv', nv2, ...
         'nelt', nelt2, 'nedge', nedge2);
  
  % -----------------------------------------------------------
  % Combine 3 meshes
  % -----------------------------------------------------------
  % Restitch 1 and 2 to form mesh 4
  reft1(1:nelt1) = int64(1);
  reft2(1:nelt2) = int64(2);
  [nv4, nelt4, nedge4, coor4, edge4, conn4, reft4, ifail] = ...
  d06db( ...
         coor1, edge1, conn1, reft1, coor2, edge2, conn2, reft2, itrace, ...
         'nv1', nv1, 'nelt1', nelt1, 'nedge1', nedge1, ...
         'nv2', nv2, 'nelt2', nelt2, 'nedge2', nedge2);

  % Restitch 3 and 4 to form mesh 5
  reft3(1:nelt2) = int64(3);
  [nv5, nelt5, nedge5, coor5, edge5, conn5, reft5, ifail] = ...
  d06db( ...
         coor4, edge4, conn4, reft4, coor3, edge3, conn3, reft3, itrace, ...
         'nv1', nv4, 'nelt1', nelt4, 'nedge1', nedge4, ...
         'nv2', nv2, 'nelt2', nelt2, 'nedge2', nedge2);

  fprintf(' The restitched mesh characteristics\n');
  fprintf(' nv    = %5d\n', nv5);
  fprintf(' nelt  = %5d\n', nelt5);
  fprintf(' nedge = %5d\n', nedge5);

  % Plot boundary
  fig5 = figure;
  a = asin(1/sqrt(5));
  t1 = linspace(a, 2*pi-a, 100);
  t2 = linspace(0, 2*pi, 100);
  hold on
  r = sqrt(5);
  plot(r*cos(t1),r*sin(t1),'black');
  r = 1;
  plot(r*cos(t2),r*sin(t2),'black');
  plot([2 6 6 2 2],[-1 -1 1 1 -1],'black');
  plot([6 8 8 6 6],[-1 -1 3 3 -1],'black');
  axis off
  axis equal
  title('Figure 5: Boundary and Interior Interfaces for Key Shape'); 

  % Plot mesh
  fig6 = figure;
  triplot(transpose(double(conn5(:,1:nelt5))), coor5(1,:), coor5(2,:));
  axis equal;
  axis off;
  title ('Figure 6: mesh of keyshape');
function [result, user] = fbnd(i, x, y, user)
  result = 0;
  if (i == 1)
    % inner circle
    result = x^2 + y^2 - 1;
  elseif (i == 2)
    % outer circle
    result = x^2 + y^2 - 5;
  end
d06db example results

Example 1


 Transformation   1: translation
  translation vector:   1.000       0.000

 Final transformation matrix y = A*x + b:
    1.000       0.000          1.000
    0.000       1.000          0.000

 Transformation   1: translation
  translation vector:  0.7895      0.8947

 Final transformation matrix y = A*x + b:
    1.000       0.000         0.7895
    0.000       1.000         0.8947


Example 2

 The restitched mesh characteristics
 nv    =   643
 nelt  =  1133
 nedge =   171
d06db_fig1.png
d06db_fig2.png
d06db_fig3.png
d06db_fig4.png
d06db_fig5.png
d06db_fig6.png

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–2015