QuadMesh is a Matlab and Octave cross compatible automatic and unstructured quadrilateral grid generation code, developed to be used with FEATool Multiphysics.

Using quadrilateral grid cells are often advantageous to simplex or triangular cells in that they can provide somewhat more accuracy when aligned with geometry features and also tends to require less overall grid cells. Quadrilaterals unfortunately do not tend to allow for easy automatic grid generation although it is possible to subdivide triangles into quads the resulting grids are often of poor quality.

Originally devised to align quad cell edges with immersed interfaces QuadMesh (and FEATool) uses distance or level set functions to describe implicit geometry objects. The algorithm then uses the zero level set contour from the distance functions to align grid cell edges with external geometry object boundaries. Furthermore, the cells are split in a “somewhat intelligent” way to treat edge cases such as when and interface segment crosses a cell diagonal.


The QuadMesh zip archive contains the required source code:

  • gridgen_quad FEATool compatible grid generation wrapper function, see the FEATool grid documentation for information about the grid output syntax.
  • quadmesh creates the quadrilateral vertex and connectivity information with syntax compatible with P.O. Persson’s DistMesh.
  • gridalign2 utility function for the grid alignment process.

The quadmesh function only depends on gridalign2 and can be used stand alone without FEATool with a similar syntax to DistMesh. QuadMesh was developed to be used with FEATool and can be used by substituting the built-in FEATool gridgen function with the new gridgen_quad. FEATool Professional allows use of the Grid Generation Call… feature from the Grid menu to use gridgen_quad, other FEATool users can either generate a new quadrilateral grid on the Matlab command line and import and substitute the existing grid into the FEATool Gui, or simply use gridgen_quad on in the FEATool command line interface edit field ». This also allows for grid smoothing to improve the grid quality, in contrast to using quadmesh in a stand alone manner.


Use the gridgen_quad and quadmesh help for several examples or run the included examples m-script file.


  • Currently, very sharp corners are not treated properly (when several interface sections intersect a single grid cell), to avoid these issues it is recommended to increase the grid resolution.