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

Description

GRIDGEN Grid generation for geometry objects.

[ GRID, STATS ] = GRIDGEN( SIN, VARARGIN ) Function to generate a grid for geometry objects by calling an external grid generation algorithm. SIN is a valid fea problem struct or cell array or geometry objects. Accepts the following property/value pairs.

Property    Value/{Default}           Description
-----------------------------------------------------------------------------------
meshgen string {distmesh} Grid generation algorithm
gmsh, distmesh, or triangle hmax scalar/arr {0.1} Target grid size for subdomains hmaxb scalar/arr {[]} Target grid size for boundaries avhb logical {true} Average hmax to boundaries fixpnt array [n_p,n_sdim] Array of (fixed) points that must be present nsm scalar {3} Number of (post) grid smoothing steps intb logical {false} Keep/reconstruct internal boundaries waitbar scalar {0} Show/hide waitbar fid scalar {1} File identifier for output ([]=no output)

MESHGEN specifies which mesh generation algorithm to use (default distmesh) and calls the corresponding grid generation code.

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. Positive HMAX values uses the minimum mesh size for shared boundaries, while negative applys the mean value.

HMAXB is analogous to HMAX but related to boundaries (edges/faces). HMAXB can be a single scalar applicable to all boundaries, a numeric array with entries corresponding to individual boundaries.

The AVHB logical flag toggles if internal boundaries inheriting HMAX values (when HMAXB is unspecified) should be assigned the smallet HMAX value from neighbouring subdomains, or the mean value (default).

NSM (default 3) the number of GRIDSMOOTH smoothing steps to perform.

INTB toggels internal boundaries (in grid.b) on or off (default).

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

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

  2) Unit square with a finer grid along the top boundary.

  grid = gridgen( {gobj_rectangle()}, <tt>hmax</tt>, 0.5, ...
                       <tt>hmaxb</tt>, [0.5 0.5 0.01 0.5] );
  plotgrid( grid )

  3) Domain with curved boundaries meshed with quadrilaterals.

  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( geom, <tt>hmax</tt>, 0.1, <tt>quad</tt>, true );
  plotgrid( grid )

  4) Two connected subdomains with a shared boundary.

  geom.objects = { gobj_polygon([-2e-3 -8e-3;0 -8e-3;0 -6e-3;0 6e-3;0 8e-3;-2e-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,4);
  hmaxb(3) = hmax/5;
  grid  = gridgen( geom, <tt>hmax</tt>, hmax, <tt>hmaxb</tt>, hmaxb );
  plotgrid( grid )

  5) Composite component with several subdomains.

  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> );

  grid  = gridgen( geom, <tt>hmax</tt>, [0.0025 0.05 0.0025] );
  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-w/4)/2 0;(L-w/4)/2 H;0 H;0 H/3], <tt>P1</tt> );
  p2  = gobj_polygon( [(L+w/4)/2 0;L 0;L H-H/3;L H;(L+w/4)/2 H], <tt>P2</tt> );
  r1  = gobj_rectangle( (L-w/4)/2, (L+w/4)/2, 0, 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 p2 r1 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 };
  geom = geom_apply_formula( geom, <tt>P1-C1-C2-C3</tt> );
  geom = geom_apply_formula( geom, <tt>P2-C4-C5-C6-C7-C8-C9-C10-C11</tt> );

  hmaxb = zeros(1,21);
  hmaxb([5 20]) = w/50;
  grid = gridgen( geom, <tt>hmax</tt>, w./[5 5 20], <tt>hmaxb</tt>, hmaxb );
  plotgrid( grid )
See also
gridgen_distmesh, gridgen_gmsh, gridgen_triangle, gridgen_quad