Main Content

generateMesh

Create triangular or tetrahedral mesh

Description

fegeometry = generateMesh(fegeometry) creates a mesh for the geometry stored in the fegeometry object. The toolbox stores the mesh in the Geometry.Mesh property.

example

femodel = generateMesh(femodel) creates a mesh for the geometry stored in the femodel object. The toolbox stores the mesh in the Geometry.Mesh property. Assigning the result to the model updates the mesh stored in the Geometry property of the model.

example

mesh = generateMesh(model) creates a mesh for the geometry stored in the model object. The toolbox stores the mesh in the Mesh property of the structural, thermal, electromagnetic model, or PDEModel.

model must contain a geometry. For details about creating a geometry and including it in a model, see Geometry and Mesh and the geometry functions listed there.

___ = generateMesh(___,Name,Value) modifies the mesh generation according to the Name,Value arguments. This syntax works with the model and femodel arguments.

example

Examples

collapse all

Generate the default 2-D mesh for the L-shaped geometry.

Create a fegeometry object representing the L-shaped geometry.

gm = fegeometry(@lshapeg);

Generate the default mesh for the geometry.

gm = generateMesh(gm);

View the mesh.

pdemesh(gm)

Figure contains an axes object. The axes object contains 2 objects of type line.

Create a mesh that is finer than the default.

Create an femodel object and include the BracketTwoHoles geometry.

model = femodel(Geometry="BracketTwoHoles.stl");

Generate a default mesh for comparison.

model = generateMesh(model);

View the mesh.

pdemesh(model)

Figure contains an axes object. The hidden axes object contains 5 objects of type quiver, text, patch.

Create a mesh with target maximum element size 5.

model = generateMesh(model,Hmax=5);

View the mesh.

pdemesh(model)

Figure contains an axes object. The hidden axes object contains 5 objects of type quiver, text, patch.

Generate a 2-D mesh with finer spots around the specified edges and vertices.

Create an femodel object and include a geometry representing a circle with a diamond-shaped hole in its center.

model = femodel(Geometry=@scatterg);

Plot the geometry.

pdegplot(model.Geometry,VertexLabels="on", ...
                        EdgeLabels="on")

Figure contains an axes object. The axes object contains 17 objects of type line, text.

Generate a mesh for this geometry using the default mesh parameters.

model = generateMesh(model);

Plot the resulting mesh.

pdemesh(model)

Figure contains an axes object. The axes object contains 2 objects of type line.

Generate a mesh with the target size on edge 1, which is smaller than the target minimum element size, MinElementSize, of the default mesh.

model = generateMesh(model,Hedge={1,0.001});

Plot the resulting mesh.

pdemesh(model)

Figure contains an axes object. The axes object contains 2 objects of type line.

Generate a mesh specifying the target sizes for edge 1 and vertices 6 and 7.

model = generateMesh(model,Hedge={1,0.001}, ...
                           Hvertex={[6 7],0.002});

Plot the resulting mesh.

pdemesh(model)

Figure contains an axes object. The axes object contains 2 objects of type line.

Input Arguments

collapse all

Geometry object for finite element analysis, specified as an fegeometry object.

Example: fegeometry = fegeometry(@squareg)

Finite element model container, specified as an femodel object.

Example: model = femodel(AnalysisType = "structuralStatic")

Model container, specified as a PDEModel object, ThermalModel object, StructuralModel object, or ElectromagneticModel object.

Example: model = createpde(3)

Example: thermalmodel = createpde(thermal="steadystate")

Example: structuralmodel = createpde(structural="static-solid")

Example: emagmodel = createpde(electromagnetic="electrostatic")

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: generateMesh(model,"Hmax",0.25);

Element geometric order, specified as "linear" or "quadratic".

A triangle or tetrahedron representing a linear element has nodes at the corners. A triangle or tetrahedron representing a quadratic element has nodes at its corners and edge centers. The center nodes in quadratic meshes are always added at half-distance between corners. For geometries with curved surfaces and edges, center nodes might not appear on the edge or surface itself.

In general, "quadratic" elements produce more accurate solutions. Override the default "quadratic" only to solve a 3-D magnetostatic problem, to save memory, or to solve a 2-D problem using a legacy solver. Legacy PDE solvers use linear triangular mesh for 2-D geometries.

Example: gm = generateMesh(gm,GeometricOrder="linear");

Data Types: char | string

Mesh growth rate, specified as a number greater than or equal to 1 and less than or equal to 2.

Example: gm = generateMesh(gm,Hgrad=1.3);

Data Types: double

Target maximum mesh edge length, specified as a positive number.

Hmax is an approximate upper bound on the mesh edge lengths. Occasionally, generateMesh can create a mesh with some elements that exceed Hmax.

generateMesh estimates the default value of Hmax from overall dimensions of the geometry.

Small Hmax values let you create finer meshes, but mesh generation can take a very long time in this case. You can interrupt mesh generation by using Ctrl+C. Note that generateMesh can take additional time to respond to the interrupt.

Example: gm = generateMesh(gm,Hmax=0.25);

Data Types: double

Target minimum mesh edge length, specified as a nonnegative number.

Hmin is an approximate lower bound on the mesh edge lengths. Occasionally, generateMesh can create a mesh with some elements that are smaller than Hmin.

generateMesh estimates the default value of Hmin from overall dimensions of the geometry.

Example: gm = generateMesh(gm,Hmin=0.05);

Data Types: double

Target size on selected faces, specified as a cell array containing an even number of elements. Odd-indexed elements are positive integers or vectors of positive integers specifying face IDs. Even-indexed elements are positive numbers specifying the target size for the corresponding faces.

Example: gm = generateMesh(gm,Hface={[1 2],0.1,[3 4 5],0.05})

Data Types: double

Target size around selected edges, specified as a cell array containing an even number of elements. Odd-indexed elements are positive integers or vectors of positive integers specifying edge IDs. Even-indexed elements are positive numbers specifying the target sizes for the corresponding edges.

Example: gm = generateMesh(gm,Hedge={[1 2],0.01,3,0.05})

Data Types: double

Target size around selected vertices, specified as a cell array containing an even number of elements. Odd-indexed elements are positive integers or vectors of positive integers specifying vertex IDs. Even-indexed elements are positive numbers specifying the target sizes for the corresponding vertices.

Example: gm = generateMesh(gm,Hvertex={1,0.02})

Data Types: double

Output Arguments

collapse all

Mesh description, returned as an FEMesh object.

Tips

  • generateMesh can return slightly different meshes in different releases. For example, the number of elements in the mesh can change. Avoid writing code that relies on explicitly specified node and element IDs or node and element counts.

  • generateMesh uses the following set of rules when you specify local element sizes with Hface, Hedge, or Hvertex. These rules are valid for both the default and custom values of Hmin and Hmax.

    • If you specify local sizes for regions near each other, generateMesh uses the minimum size. For example, if you specify size 1 on an edge and size 0.5 on one of its vertices, the function gradually reduces the element sizes in the proximity of that vertex.

    • If you specify local sizes smaller than Hmin, generateMesh ignores Hmin in those localities.

    • If you specify local sizes larger than Hmax, generateMesh ignores the specified local sizes. Hmax is not exceeded anywhere in the mesh.

Version History

Introduced in R2015a

expand all