Main Content

generateMesh

Create triangular or tetrahedral mesh

Description

example

generateMesh(model)creates a mesh and stores it in themodel目的。modelmust contain a geometry. For details about creating a geometry and including it in a model, seeGeometry and Mesh以及那里列出的几何功能。

example

generateMesh(model,Name,Value)modifies the mesh creation according to theName,Valuearguments.

= generateMesh(___)还将网格返回到MATLAB®workspace, using any of the previous syntaxes.

Examples

collapse all

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

Create a PDE model and include the L-shaped geometry.

model = createpde(1); geometryFromEdges(model,@lshapeg);

生成几何形状的默认网格。

generateMesh(model);

View the mesh.

pdeplot(model)

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

Create a mesh that is finer than the default.

Create a PDE model and include theBrackettwoholesgeometry.

model = createpde(1); importGeometry(model,'Brackettwoholes.stl');

Generate a default mesh for comparison.

generateMesh(model)
ans = FEMesh with properties: Nodes: [3x10003 double] Elements: [10x5774 double] MaxElementSize: 9.7980 MinElementSize: 4.8990 MeshGradation: 1.5000 GeometricOrder: 'quadratic'

View the mesh.

PDEPLOT3D(模型)

Create a mesh with target maximum element size 5 instead of the default 7.3485.

generateMesh(model,'Hmax',5)
ans = FEMesh with properties: Nodes: [3x66982 double] Elements: [10x44093 double] MaxElementSize: 5 MinElementSize: 2.5000 MeshGradation: 1.5000 GeometricOrder: 'quadratic'

View the mesh.

PDEPLOT3D(模型)

在指定的边缘和顶点周围生成一个2D网格。

Create a model.

model = createpde;

Create and plot a 2-D geometry representing a circle with a diamond-shaped hole in its center.

g = geometryFromEdges(模型、@scatterg);pdegplot (g,'顶板标签','on','edgelabels','on')

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

使用默认的网格参数为此几何生成网格。

m1 = generateMesh(model)
M1 =具有属性的Femesh:节点:[2x1159 double]元素:[6x547 double] maxeLementize:0.0509 MineLementize:0.0254网格加密:1.5000 geetricricordorder:'quadratic''

Plot the resulting mesh.

pdeplot(m1)

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.

m2 = generatemesh(模型,'Hedge',{1,0.001})
m2 = FEMesh with properties: Nodes: [2x2631 double] Elements: [6x1241 double] MaxElementSize: 0.0509 MinElementSize: 0.0254 MeshGradation: 1.5000 GeometricOrder: 'quadratic'

Plot the resulting mesh.

PDEPLOT(M2)

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.

m3 = generateMesh(model,'Hedge',{1,0.001},'Hvertex',{[6 7],0.002})
m3 = FEMesh with properties: Nodes: [2x2903 double] Elements: [6x1365 double] MaxElementSize: 0.0509 MinElementSize: 0.0254 MeshGradation: 1.5000 GeometricOrder: 'quadratic'

Plot the resulting mesh.

PDEPLOT(M3)

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

Input Arguments

collapse all

Model object, specified as aPDEModel目的,ThermalModel目的,StructuralModel目的,或者ElectromagneticModel目的。

Example:model = createpde(3)

Example:ThermalModel = CreatePde(“热”,“ Steadystate”)

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

Example:emagmodel = createpde(“电磁”,“静电”)

Name-Value Arguments

将可选的参数对Name1=Value1,...,NameN=ValueN, whereNameis the argument name andValueis 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 encloseNamein quotes.

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

元素几何顺序, specified as'linear'或者'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:generateMesh(model,'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:generateMesh(model,'Hgrad',1.3);

Data Types:double

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

Hmaxis an approximate upper bound on the mesh edge lengths. Occasionally,generateMeshcan create a mesh with some elements that exceedHmax

generateMesh估计的默认值Hmaxfrom overall dimensions of the geometry.

SmallHmaxvalues let you create finer meshes, but mesh generation can take a very long time in this case. You can interrupt mesh generation by usingCtrl+C。注意generateMeshcan take additional time to respond to the interrupt.

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

Data Types:double

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

Hminis an approximate lower bound on the mesh edge lengths. Occasionally,generateMeshcan create a mesh with some elements that are smaller thanHmin

generateMesh估计的默认值Hminfrom overall dimensions of the geometry.

Example:generateMesh(model,'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:generateMesh(model,'Hmax',0.25,'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:generatemesh(型号,'hmax',0.25,'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:generateMesh(model,'Hmax',0.25,'Hvertex',{1,0.02})

Data Types:double

Output Arguments

collapse all

Mesh description, returned as an女性特性目的。is the same asmodel.Mesh

More About

collapse all

Element

Anelementis a basic unit in the finite-element method.

For 2-D problems, an element is a triangle in themodel.mesh.elementproperty. If the triangle represents a linear element, it has nodes only at the triangle corners. If the triangle represents a quadratic element, then it has nodes at the triangle corners and edge centers.

For 3-D problems, an element is a tetrahedron with either four or ten points. A four-point (linear) tetrahedron has nodes only at its corners. A ten-point (quadratic) tetrahedron has nodes at its corners and at the center point of each edge.

For details, seeMesh Data

Tips

  • generateMeshcan 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当您指定本地元素大小时,请使用以下规则Hface,Hedge, orHvertex。These rules are valid for both the default and custom values ofHminHmax

    • If you specify local sizes for regions near each other,generateMesh使用最小尺寸。例如,如果您在边缘上指定尺寸1,其一个顶点上的大小为0.5,则该函数会逐渐降低该顶点的接近度中的元素大小。

    • If you specify local sizes smaller thanHmin,generateMeshignoresHminin those localities.

    • If you specify local sizes larger thanHmax,generateMeshignores the specified local sizes.Hmaxis not exceeded anywhere in the mesh.

Version History

在R2015a中引入