FEATool  v1.7.1
Finite Element Analysis Toolbox
 All Files Functions Pages
gridgen_gmsh.m File Reference

Description

GRIDGEN_GMSH Generate grid with Gmsh.

[ GRID ] = GRIDGEN_GMSH( SIN, VARARGIN ) Function to generate an unstructured GRID for FEATool geometry objects by calling the external Gmsh mesh generator (http://gmsh.info and http://gmsh.info/doc/texinfo/gmsh.html)

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

SIN is a valid FEATool fea problem, geometry, or geo struct, or alternatively a 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 boundaries
nsm         scalar   {3}               Number of grid smoothing steps
nref        scalar   {0}               Number of uniform grid refinements
algo2       scalar   {2}               2D mesh algorithm (1=MeshAdapt, 2=Automatic,
                                       5=Delaunay, 6=Frontal, 7=BAMG, 8=DelQuad)
algo3       scalar   {1}               3D mesh algorithm (1=Del, 2=New Del, 4=Front
                                       5=Front Del, 6=Front Hex, 7=MMG3D, 9=R-tree)
quad        boolean  {false}           Use quad meshing (for 2D)
mshopt      cell     {}                Cell array of Gmsh options
syscmd      string   {<tt>default</tt>}       Gmsh system call command
                                       (default <tt>gmsh fdir/fname.geo -</tt>)
fname       string   {<tt>fea_gmsh_UID</tt>}  Gmsh imp/exp file name (root)
fdir        string   {tempdir}         Directory to write help files
clean       boolean  {true}            Delete (clean) Gmsh help files
instdir     string   {<tt>lib/gmsh</tt>}      Gmsh binary 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. 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.

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

NREF (default 0) the number of post uniform grid refinement steps.

ALGO2 and ALGO3 the Gmsh 2D and 3D mesh generation algorithms.

QUAD (default 0) toggles Blossom-Quad conversion for 2D geometries.

Additional Gmsh options can be provided with the cell array MSHOPT.

For example MSHOPT could be given as
{{Mesh, CharacteristicLengthMax, 1}, {Mesh, AnisoMax, 10}}
Examples
  1) Unit square with uniform global grid size set to 0.1.

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

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

  grid = gridgen_gmsh( {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_gmsh( 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_gmsh( 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_gmsh( 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_gmsh( geom, <tt>hmax</tt>, w./[5 5 20], <tt>hmaxb</tt>, hmaxb );
  plotgrid( grid )
See also
gridgen, impexp_gmsh, geom2geo