generateMesh
Create triangular or tetrahedral mesh
Description
generateMesh(
creates a mesh and stores it in themodel
)model
目的。model
must contain a geometry. For details about creating a geometry and including it in a model, seeGeometry and Mesh以及那里列出的几何功能。
generateMesh(
modifies the mesh creation according to themodel
,Name,Value
)Name,Value
arguments.
还将网格返回到MATLAB®workspace, using any of the previous syntaxes.网
= generateMesh(___)
Examples
Generate 2-D Mesh
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)
生成3-D网格
Create a mesh that is finer than the default.
Create a PDE model and include theBrackettwoholes
geometry.
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(模型)
Refine Mesh on Specified Edges and Vertices
在指定的边缘和顶点周围生成一个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')
使用默认的网格参数为此几何生成网格。
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)
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)
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)
Input Arguments
model
—Model object
PDEModel
object|ThermalModel
object|StructuralModel
object|ElectromagneticModel
object
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
, whereName
is the argument name andValue
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 encloseName
in quotes.
Example:generateMesh(model,'Hmax',0.25);
GeometricOrder
—元素几何顺序
'quadratic'
(default) |'linear'
元素几何顺序, 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
Hgrad
—Mesh growth rate
1.5
(default) |number greater than or equal to 1 and less than or equal to 2
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
Hmax
—Target maximum mesh edge length
positive number
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 exceedHmax
。
generateMesh
估计的默认值Hmax
from overall dimensions of the geometry.
SmallHmax
values 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。注意generateMesh
can take additional time to respond to the interrupt.
Example:generateMesh(model,'Hmax',0.25);
Data Types:double
Hmin
—Target minimum mesh edge length
nonnegative number
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 thanHmin
。
generateMesh
估计的默认值Hmin
from overall dimensions of the geometry.
Example:generateMesh(model,'Hmin',0.05);
Data Types:double
Hface
—Target size on selected faces
cell array
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
Hedge
—Target size around selected edges
cell array
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
Hvertex
—Target size around selected vertices
cell array
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
网
— Mesh description
FEMesh
object
Mesh description, returned as an女性特性目的。网
is the same asmodel.Mesh
。
More About
Element
Anelementis a basic unit in the finite-element method.
For 2-D problems, an element is a triangle in themodel.mesh.element
property. 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
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
当您指定本地元素大小时,请使用以下规则Hface
,Hedge
, orHvertex
。These rules are valid for both the default and custom values ofHmin
和Hmax
。If you specify local sizes for regions near each other,
generateMesh
使用最小尺寸。例如,如果您在边缘上指定尺寸1,其一个顶点上的大小为0.5,则该函数会逐渐降低该顶点的接近度中的元素大小。If you specify local sizes smaller than
Hmin
,generateMesh
ignoresHmin
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
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
你点击一个链接对应MATLABcommand:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:。
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- AméricaLatina(Español)
- Canada(English)
- United States(English)
Europe
- Belgium(English)
- 丹麦(English)
- Deutschland(Deutsch)
- España(Español)
- Finland(English)
- 法国(Français)
- 爱尔兰(English)
- Italia(Italiano)
- Luxembourg(English)
- Netherlands(English)
- 挪威(English)
- Österreich(Deutsch)
- Portugal(English)
- Sweden(English)
- Switzerland
- United Kingdom(English)