MESH2D
Automatic 2D Mesh Generation


MESH2D is a MATLAB program which generates unstructured meshes in 2D, by Darren Engwirda.

The code is relatively simple, flexible and powerful. The user is able to define a variety of geometric shapes, and desired mesh densities.

MESH2D is most useful because it allows a user to specify a shape or region, which the program will then fill with a triangular mesh. The density of the triangular mesh can be uniform, or the user can request that smaller triangles be used near certain features of the region. The program relies heavily on the features of the Delaunay triangulation, which chooses, among all possible triangulations of a set of points, that triangulation which best avoids small angles.

Interested users should refer to the copy of MESH2D that is made available through the MATLAB Central File Exchange. This copy is essentially my personal working copy, to which I may have added comments, small coding changes, and extra tests and examples.

Note that the MESH2D function "mytsearch()" was originally written to call MATLAB's "tsearch()" function. The tsearch() function has since been removed from MATLAB. One alternative is a file called tsearch_mex.c, which searches a triangulation to determine which triangle contains each point. It does not require that the triangulation be Delaunay. To use this function with MATLAB, you need to apply MATLAB's MEX compiler...if you have never used the MEX compiler before, you may have some difficulty, since you need to determine that you have the MEX compiler, that you have a C or C++ compiler on your system, that MEX knows where these compilers are, and that you know how to invoke MEX to compile the function. That should be something like

        mex tsearch_mex.c
      
(The second time you do something like this is, of course, a hundred times easier and only half as mysterious!)

A second alternative is to replace the call to tsearch() by a call to MATLAB's replacement function DelaunayTri; however, a simple substitution of one call for the other does not quite work. There is, apparently, some feature of tsearch() that is not available in DelaunayTri(). In particular, it may be that tsearch() did not require the triangulation to be Delaunay...

A third alternative is to replace the call to tsearch(x,y,t,px,py) by a call to tsearchn([x y], t, [px py] ), which seems to work.

Usage:

[ p, t ] = mesh2d ( vertices, edge, hdata, options );
where:

hdata, the element size information. This structure, if supplied, can include the following information:

options allows the user to modify the default behavior of the solver. This structure, if supplied, can include the following information:

Licensing:

Copyright (c) 2009, Darren Engwirda
All rights reserved.

Redistribution and use in source and binary forms, with or without 
modification, are permitted provided that the following conditions are 
met:

    * Redistributions of source code must retain the above copyright 
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright 
      notice, this list of conditions and the following disclaimer in 
      the documentation and/or other materials provided with the distribution
      
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
POSSIBILITY OF SUCH DAMAGE.
    

Languages:

MESH2D is available in a MATLAB version.

Related Data and Programs:

DISTMESH, a MATLAB library which carries out triangular or tetrahedral mesh generation, by Per-Olof Persson and Gilbert Strang.

MESH2D_HAND, a MATLAB program which reads in a set of 59 points which outline a human hand, and calls MESH2D, which is able to create a fine triangular mesh of the region outlined by the points.

MESH2D_WRITE, a MATLAB program which demonstrates how node and element data from MESH2D can be written to files.

TEST_TRIANGULATION, a MATLAB library which defines some test regions for triangulation.

TRIANGLE, a C program which computes a triangulation of a geometric region, by Jonathan Shewchuk.

TRIANGULATION, a MATLAB library which performs various operations on order 3 ("linear") or order 6 ("quadratic") triangulations.

TSEARCH, a MATLAB library which compares several replacements for MATLAB's obsolete tsearch() function, which searched a Delaunay triangulation to find the triangle that encloses a given point.

Author:

Darren Engwirda

Source Code:

Examples and Tests:

AIRFOIL_DEMO draws a mesh around the outside of an airfoil. The mesh uses 621 nodes and 1015 elements.

BAFFLE_DEMO considers a rectangular region containing 13 hexagonal baffles or obstacles. The mesh uses 512 nodes and 874 elements.

CIRCLE_DEMO considers a circular region with an off-center hole, with the interior and exterior boundaries each defined by 16 vertices.

ELL_DEMO demonstrates features of MESH2D for the L-shaped region.

ICAM_DEMO demonstrates features of MESH2D for the first floor of the Wright House.

OBSTACLE_DEMO demonstrates features of MESH2D for a channel with a square obstacle.

REFINE_DEMO demonstrates how the refinement feature of MESH2D can be controlled with a mask, which specifies that only certain triangles should be refined, rather than all of them. The masked triangles are split into 4 subtriangles. Triangles immediately neighboring such triangles will be split in half. Remaining triangles will be untouched.

You can go up one level to the MATLAB source codes.


Last revised on 17 October 2013.