Please Note that the gridgen_triangle function has been fully integrated with the both the FEATool GUI and CLI, and embedded in the gridgen function. See the FEATool-Triangle Mesh Generator Integration post for more details.
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.
The first step is to download and compile Triangle from www.cs.cmu.edu/~quake/triangle.html. Alternatively, Windows, Linux, and MacOS executables are also available from GitHub.
To use Triangle with FEATool put the executable binary in the featool/lib/triangle directory (create the directory if it doesn’t exist).
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).
To use an alternative grid generation routine in the FEATool GUI, simply choose the Grid Generation Call… from the Grid menu.
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_cells | t (DistMesh) | n_cells | t (Triangle) |
---|---|---|---|
211 | 0.40 | 168 | 0.08 |
899 | 0.35 | 694 | 0.06 |
3642 | 1.10 | 2724 | 0.08 |
14632 | 2.88 | 10864 | 0.20 |
58698 | 13.29 | 43898 | 0.48 |
235793 | 60.38 | 170996 | 1.74 |
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' );
tic
grid1 = gridgen( fea, 'hmax', hmax );
t_distmesh = toc;
tic
grid2 = gridgen_triangle( fea, 'hmax', hmax );
t_triangle = toc;
subplot(1,2,1)
plotgrid( grid1 )
title('DistMesh')
subplot(1,2,2)
plotgrid( grid2 )
title('Triangle')
t_distmesh
t_triangle
The Triangle function wrapper also supports specifying the minimum
acceptable angle and target grid sizes for each edge, for more
information type help gridgen_triangle
to see the help
documentation. The function wrapper can be downloaded from the link
below