FEATool  v1.8
Finite Element Analysis Toolbox
 All Files Functions Pages
gridgen_triangle.m File Reference

Description

GRIDGEN_TRIANGLE Generate unstructured 2D grid with Triangle.

[ GRID, STATS ] = GRIDGEN_TRIANGLE( SIN, VARARGIN ) Function to generate an unstructured 2D triangular GRID for FEATool geometry objects by calling the exernal Triangle grid generator library (https://www.cs.cmu.edu/~quake/triangle.html)

J R Shewchuk, Triangle: Engineering a 2D Quality Mesh Generator and
Delaunay Triangulator, in Applied Computational Geometry: Towards
Geometric Engineering (Ming C. Lin and Dinesh Manocha, editors),
volume 1148 of Lecture Notes in Computer Science, pages 203-222,
Springer-Verlag, Berlin, May 1996. (From the First ACM Workshop on
Applied Computational Geometry.)

If the Triangle binary is not present and found in the INSTDIR the function will attempt to automatically download, (compile if required), and install it in the given directory. If this fails, please manually download and install Triangle from the source reference and link above.

SIN is a valid FEATool fea problem struct or cell array of geometry objects. Accepts the following property/value pairs.

Property    Value/{Default}            Description
-----------------------------------------------------------------------------------
hmax        scal/arr {0.1}             Target grid size for geometry/subdomains
hmaxb       scal/arr {[]}              Target grid size for boundary edges
q           scalar   {28}              Minimum target angle (quality)
syscmd      string   {<tt>default</tt>}       Triangle system call command (default
                                       <tt>triangle -I -q%f -j -e -a -A %s.poly</tt>)
compcmd     string   {<tt>default</tt>}       Triangle unix/linux compilation command
                                       (<tt>cc -O triangle.c -lm -o triangle</tt>)
fname       string   {<tt>fea_tri_UID</tt>}   Triangle imp/exp file name (root)
fdir        string   {tempdir}         Directory to write help files
clean       boolean  {true}            Delete (clean) Triangle help files
instdir     string   {<tt>lib/triangle</tt>}  Triangle installation directory
fid         scalar   {1}               File identifier for output ([]=no output)

HMAX indicates target grid cell diameters, and is either a numeric scalar prescribing the grid size for the entire geometry, or an array with HMAX values corresponding to individual subdomains.

HMAXB is analogous to HMAX but related to boundaries (edges). HMAXB can be a single scalar applicable to all boundaries, a numeric array with entries corresponding to individual boundaries, or a cell array. In the case HMAXB is a cell array each entry and boundary can be prescribed a value for the mean cell edge size or a numeric array of grid point distributions (spanning 0 to 1) along the boundary.

Q (default 28 degrees) specifies a minimum target angle (values less than 33 are generally acceptable, while higher values might prevent Triangle convergence).

Examples
  1) Unit square with uniform global grid size set to 0.1.

  grid = gridgen_triangle( {gobj_rectangle()}, <tt>hmax</tt>, 0.1 );
  plotgrid( grid )

  2) Unit square with prescribed edge node distribution.

  flog  = @(n,m) ((logspace(0,1,n)-1)/9).^m;   % Log distribution function.
  grid = gridgen_triangle( {gobj_rectangle()}, <tt>hmax</tt>, 0.5, ...
                 <tt>hmaxb</tt>, {1-flog(50,2) flog(50,2) 1-flog(15,1.5) flog(15,1.5)} );
  plotgrid( grid )

  3) Domain with a fine grid along curved boundaries (number 5 and 6).

  geom.objects = {gobj_rectangle() gobj_circle([0 0],.6) gobj_circle([1 1],.3,<tt>C2</tt>)};
  geom = geom_apply_formula( geom, <tt>R1-C1-C2</tt> );
  grid = gridgen_triangle( geom, <tt>hmax</tt>, .1, <tt>hmaxb</tt>, [.1 .1 .1 .1 .01 .01] );
  plotgrid( grid )

  4) Two connected subdomains with refined grid along the shared boundary (9).

  geom.objects = { gobj_rectangle(-2e-3,0,-8e-3,8e-3), ...
                   gobj_polygon([0 -6e-3;2e-3 -5e-3;2e-3 4e-3;0 6e-3]) };
  hmax  = 5e-4;
  hmaxb = hmax*ones(1,9);
  hmaxb(9) = hmax/5;
  grid  = gridgen_triangle( geom, <tt>hmax</tt>, hmax, <tt>hmaxb</tt>, hmaxb );
  plotgrid( grid )

  5) Component with fine grid on subdomains 2 and 3, and curved boundaries.

  r1 = gobj_rectangle( 0, 0.11, 0, 0.12,  <tt>R1</tt> );
  c1 = gobj_circle( [ 0.065 0 ],   0.015, <tt>C1</tt> );
  c2 = gobj_circle( [ 0.11 0.12 ], 0.035, <tt>C2</tt> );
  c3 = gobj_circle( [ 0 0.06 ],    0.025, <tt>C3</tt> );
  r2 = gobj_rectangle( 0.065, 0.16, 0.05, 0.07, <tt>R2</tt> );
  c4 = gobj_circle( [ 0.065 0.06 ], 0.01, <tt>C4</tt> );
  geom.objects = { r1 c1 c2 c3 r2 c4 };
  geom = geom_apply_formula( geom, <tt>R1-C1-C2-C3</tt> );
  geom = geom_apply_formula( geom, <tt>R2+C4</tt> );

  hmax  = [0.02 0.0015 0.0015];
  hmaxb = 0.02*ones(1,34);
  hmaxb([8:12]) = 0.0025;
  grid  = gridgen_triangle( geom, <tt>hmax</tt>, hmax, <tt>hmaxb</tt>, hmaxb );
  plotgrid( grid )

  6) Complex geometry with several holes and subdomains.

  w = 10e-4; L = 3*w; H = 5*w;
  p1  = gobj_polygon( [w/10 0;L 0;L H-H/3;L H;0 H;0 H/3], <tt>P1</tt> );
  r1  = gobj_rectangle( (L-w/4)/2, (L+w/4)/2, -sqrt(eps), H, <tt>R1</tt> );
  c1  = gobj_circle( [2*w/3 3*w], w/3, <tt>C1</tt> );
  c2  = gobj_circle( [2*w/3 2*w], w/3, <tt>C2</tt> );
  c3  = gobj_circle( [2*w/3 1*w], w/3, <tt>C3</tt> );
  c4  = gobj_circle( [L-w/2 4.5*w], w/8, <tt>C4</tt> );
  c5  = gobj_circle( [L-w   4.5*w], w/8, <tt>C5</tt> );
  c6  = gobj_circle( [L-w/2 4*w], w/8, <tt>C6</tt> );
  c7  = gobj_circle( [L-w   4*w], w/8, <tt>C7</tt> );
  c8  = gobj_circle( [L-w/2 3.5*w], w/8, <tt>C8</tt> );
  c9  = gobj_circle( [L-w   3.5*w], w/8, <tt>C9</tt> );
  c10 = gobj_circle( [L-w/2 3*w], w/8, <tt>C10</tt> );
  c11 = gobj_circle( [L-w   3*w], w/8, <tt>C11</tt> );
  geom.objects = { p1 r1 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 };
  geom = geom_apply_formula( geom, <tt>P1-C1-C2-C3-C4-C5-C6-C7-C8-C9-C10-C11</tt> );

  hmaxb = w/5*ones(1,59);
  hmaxb([5 9]) = w/50;
  grid  = gridgen_triangle( geom, <tt>hmax</tt>, w./[5 20 5], <tt>hmaxb</tt>, hmaxb );
  plotgrid( grid )
See also
gridgen, impexp_triangle, geom2poly