FEATool Multiphysics supports calling external programs for grid generation, solvers, and postprocessing directly from the GUI. This post illustrates how this can be done by showing an example with Triangle, a very fast 2D unstructured grid generation code written by Jonathan R. Shewchuk.

  1. The first step is to download and compile Triangle from www.cs.cmu.edu/~quake/triangle.html. Alternatively, precompiled mex files can found in the mutils package, and a Windows executable is also available through Sourceforge.

  2. To use Triangle with FEATool put the executable binary in the featool/lib/triangle directory (create the directory if it doesn’t exist).

  3. Also download the gridgen_triangle.m function wrapper from the link at the bottom of this post and put it in the featool directory (where also the gridgen function resides).

  4. To use an alternative grid generation routine in the FEATool GUI, simply choose the Grid Generation Call… from the Grid menu.

  5. This will open a dialog box where you can specify the grid generation call. In this case simply replace gridgen with the wrapper gridgen_triangle. Click on Generate Grid to call the specified grid generation routine.

Although Distmesh, the built-in automatic grid generation routine, is very robust and produces high quality grids. As can be seen from the table below Triangle can be a magnitude or more faster.

n_cellst (Distmesh)n_cellst (Triangle)

It also possible to call the Triangle grid generation function directly on the command line and directly import the created grid struct in to the GUI. The example script below generates a grid for a square domain with a circle subtracted from the upper right corner and compares it with Distmesh

hmax = 0.02;

xmin  = 0;
xmax  = 1;
ymin  = 0;
ymax  = 1;
gobj1 = gobj_rectangle( xmin, xmax, ymin, ymax, 'R1' );

xc    = 0.8;
yc    = 0.8;
r     = 0.4;
gobj2 = gobj_circle( [xc yc], r, 'C1' );

fea.geom.objects = { gobj1 gobj2 };
fea = geom_apply_formula( fea, 'R1-C1' );

grid1 = gridgen( fea, 'hmax', hmax );
t_distmesh = toc;

grid2 = gridgen_triangle( fea, 'hmax', hmax );
t_triangle = toc;

plotgrid( grid1 )
plotgrid( grid2 )


The Triangle function wrapper also supports specifying the minimum acceptable angle and target grid sizes for each edge, see help gridgen_triangle for more information. The function wrapper can be downloaded from the link below

FEATool Triangle Grid Generation M-Script File