0% found this document useful (0 votes)
144 views5 pages

MESH2D - Automatic 2D Mesh Generation

MESH2D is a MATLAB program that generates unstructured triangular meshes in 2D. It allows the user to specify geometric shapes and desired mesh densities. The program relies on Delaunay triangulation to fill the specified region with triangles, allowing for smaller triangles near certain features. MESH2D is distributed with documentation and source code under a permissive license.

Uploaded by

Igor Gjorgjiev
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
144 views5 pages

MESH2D - Automatic 2D Mesh Generation

MESH2D is a MATLAB program that generates unstructured triangular meshes in 2D. It allows the user to specify geometric shapes and desired mesh densities. The program relies on Delaunay triangulation to fill the specified region with triangles, allowing for smaller triangles near certain features. MESH2D is distributed with documentation and source code under a permissive license.

Uploaded by

Igor Gjorgjiev
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

MESH2D - Automatic 2D Mesh Generation

http://people.sc.fsu.edu/~jburkardt/m_src/mesh2d/mesh2d.html[21/04/2014 09:34:24]
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 t sear ch_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:
vertices, required input, a V by 2 list of (X,Y) coordinates of vertices of the boundary. If vertices is the only input argument, then it must be the case
that the vertices are listed consecutively. Otherwise, assuming edge is supplied, the vertices can be given in any order.
MESH2D - Automatic 2D Mesh Generation
http://people.sc.fsu.edu/~jburkardt/m_src/mesh2d/mesh2d.html[21/04/2014 09:34:24]
edge, optional input, a V by 2 list of pairs of indices in the vertices array that constitute the edges of the polygonal boundary. If vertices is actually
already in order, then edge, if specified, would contain the values [1,2; 2,3; 3,4; ... ; V,1].
hdata, optional input, a structure containing element size information (see below).
options, optional input that allows the user to modify the default behavior of the solver (see below).
p, (output), an N by 2 list of node coordinates. The number of nodes generated, N, is determined in part by the size of the edges along the boundary,
and by other user input such as the maximum element size, and the user size function, if supplied.
t, (output), an M by 3 list of node indices, forming counterclockwise triangles. The number of triangles created depends on the number of nodes
created.
hdata, the element size information. This structure, if supplied, can include the following information:
hdata.hmax, the maximum allowable global element size.
hdata.edgeh, an array of element sizes on specified geometry edges, where e1 is an index into the edge array. The edgeh component would have the
form [e1,h1; e2,h2; ...], where the user has specified a certain number of sizes.
hdata.fun, the name of a function preceded by an AT sign, which is the user-defined size function. fun must have the form
h =fun ( x, y, args{} )
where x and y are vectors of point coordinates, and args is an optional addition set of input set in hdata.args. The function returns the user-desired
elementsize at the given points.
hdata.args ={arg1, arg2, ...} contains additional arguments, if any, for hdata.fun.
options allows the user to modify the default behavior of the solver. This structure, if supplied, can include the following information:
options.mlim is the convergence tolerance. The maximum relative change in edge length per iteration must be less than this value, which defaults to
0.02.
options.maxit, the maximum allowable number of iterations, which defaults to 20.
options.dhmax, the maximum allowable (relative) gradient in the size function, which defaults to 0.3.
options.output, a "logical" variable which displays the mesh and the mesh statistics upon completion, and defaults to "TRUE", that is, 1.
Licensing:
Copyr i ght ( c) 2009, Dar r en Engwi r da
Al l r i ght s r eser ved.
Redi st r i but i on and use i n sour ce and bi nar y f or ms, wi t h or wi t hout
modi f i cat i on, ar e per mi t t ed pr ovi ded t hat t he f ol l owi ng condi t i ons ar e
met :
* Redi st r i but i ons of sour ce code must r et ai n t he above copyr i ght
not i ce, t hi s l i st of condi t i ons and t he f ol l owi ng di scl ai mer .
* Redi st r i but i ons i n bi nar y f or m must r epr oduce t he above copyr i ght
not i ce, t hi s l i st of condi t i ons and t he f ol l owi ng di scl ai mer i n
t he document at i on and/ or ot her mat er i al s pr ovi ded wi t h t he di st r i but i on

THI S SOFTWARE I S PROVI DED BY THE COPYRI GHT HOLDERS AND CONTRI BUTORS " AS I S"
MESH2D - Automatic 2D Mesh Generation
http://people.sc.fsu.edu/~jburkardt/m_src/mesh2d/mesh2d.html[21/04/2014 09:34:24]
AND ANY EXPRESS OR I MPLI ED WARRANTI ES, I NCLUDI NG, BUT NOT LI MI TED TO, THE
I MPLI ED WARRANTI ES OF MERCHANTABI LI TY AND FI TNESS FOR A PARTI CULAR PURPOSE
ARE DI SCLAI MED. I N NO EVENT SHALL THE COPYRI GHT OWNER OR CONTRI BUTORS BE
LI ABLE FOR ANY DI RECT, I NDI RECT, I NCI DENTAL, SPECI AL, EXEMPLARY, OR
CONSEQUENTI AL DAMAGES ( I NCLUDI NG, BUT NOT LI MI TED TO, PROCUREMENT OF
SUBSTI TUTE GOODS OR SERVI CES; LOSS OF USE, DATA, OR PROFI TS; OR BUSI NESS
I NTERRUPTI ON) HOWEVER CAUSED AND ON ANY THEORY OF LI ABI LI TY, WHETHER I N
CONTRACT, STRI CT LI ABI LI TY, OR TORT ( I NCLUDI NG NEGLI GENCE OR OTHERWI SE)
ARI SI NG I N ANY WAY OUT OF THE USE OF THI S SOFTWARE, EVEN I F ADVI SED OF THE
POSSI BI LI TY 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 J onathan 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:
centroid_mesh.m returns the centroids of the triangles that make up a mesh.
checkgeometry.m checks a geometry input for MESH2D.
circumcircle.m computes the center and radius of the circumcircle of a triangle.
connectivity.m assembles connectivity data for a triangular mesh, including the unique mesh edges, the triangle neighbors, and the boundary edges.
MESH2D - Automatic 2D Mesh Generation
http://people.sc.fsu.edu/~jburkardt/m_src/mesh2d/mesh2d.html[21/04/2014 09:34:24]
dist2poly.m finds the distance between a point and a polygon.
findedge.m locates the edges that contain a sequence of points.
fixmesh.m checks a triangular mesh for consistency.
inpoly.m determines whether a point is inside a polygon.
mesh2d.m generates a triangular mesh for a polygon, which can include cavities.
meshfaces.m generates a triangular mesh for a polygonal region which can include cavities.
meshpoly.m used by MESH2D or MESHFACES to mesh a region.
mydelaunayn.m computes the Delaunay triangulation of a set of points.
mytsearch.m finds a triangle which encloses a set of points in the plane.
quadtree.m decomposes a polygonal region using a quadtree.
quality.m determines the "quality" of a triangle.
refine.m refines a triangular mesh.
smoothmesh.m uses Laplacian smoothing on a triangular mesh.
tinterp.m carries out linear interpolation at points within a triangle, given function values at the vertices.
triarea.m computes the area of one or more triangles, assuming their vertices are given in counterclockwise order.
tsearch_mex.c, which carries out a search of the triangulation; Matlab's "tsearch()" function already does this, but is a) officially obsolete, resulting in
lots of warnings; b) requires that the triangulation be Delaunay. In "mytsearch()", replace the call to "tsearch()" by a call to "tsearch_mex()". To use
this file, it must be compiled within MATLAB (once) using a command like
mex t sear ch_mex. c

Examples and Tests:
facedemo.m demonstrates two example polygonal geometries for input to MESHFACES.
mesh_collection.m contains a collection of meshing examples.
meshdemo.m demonstrates the use of MESH2D.
AIRFOIL_DEMO draws a mesh around the outside of an airfoil. The mesh uses 621 nodes and 1015 elements.
airfoil_demo.m the source code.
airfoil.txt the coordinates of 102 points that trace out the shape of the airfoil, in clockwise direction.
airfoil_elements.png an image of the elements.
airfoil_nodes.png an image of the nodes.
airfoil_vertices.png an image of the vertices.
BAFFLE_DEMO considers a rectangular region containing 13 hexagonal baffles or obstacles. The mesh uses 512 nodes and 874 elements.
baffle_demo.m the source code.
baffle_elements.png the elements created when we set a maximum element size of 0.5.
baffle_nodes.png the nodes created when we set a maximum element size of 0.5.
baffle_vertices.png the vertices that define the region and the obstacles.
MESH2D - Automatic 2D Mesh Generation
http://people.sc.fsu.edu/~jburkardt/m_src/mesh2d/mesh2d.html[21/04/2014 09:34:24]
CIRCLE_DEMO considers a circular region with an off-center hole, with the interior and exterior boundaries each defined by 16 vertices.
circle_demo.m the source code.
circle_elements.png the elements created when we set a maximum element size of 0.25.
circle_nodes.png the nodes created when we set a maximum element size of 0.25.
circle_vertices.png the vertices that define the region and the obstacles.
ELL_DEMO demonstrates features of MESH2D for the L-shaped region.
ell_demo.m the source code.
ell_mesh1.png the mesh created with the simplest input.
ell_mesh2.png the mesh created when we specify two small segments on the boundary.
ell_mesh3.png the mesh created when we specify a maximum element size.
ell_mesh4.png the mesh created when we specify a size function that requests small elements near the reentrant corner.
ell_mesh5.png the mesh created we call refine() on the first mesh;
ell_mesh6.png the mesh created when we call smoothmesh() on the second mesh.
ICAM_DEMO demonstrates features of MESH2D for the first floor of the Wright House.
icam_demo.m the source code.
icam_nodes.png the nodes created by MESH2D.
icam_elements.png the elements created by MESH2D.
OBSTACLE_DEMO demonstrates features of MESH2D for a channel with a square obstacle.
obstacle_demo.m the source code.
obstacle_mesh.png a mesh created for the region.
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.
refine_demo.m the source code.
refine_demo1.png the initial mesh;
refine_demo2.png the mesh after refining all the triangles whose centroid has a Y coordinate greater than 1/2.
refine_demo3.png the mesh after a second refinement, on all the triangles whose centroid has an X coordinate less than 1/2.
You can go up one level to the MATLAB source codes.
Last revised on 17 October 2013.

You might also like