Generate Mesh
The generateMesh
function creates a triangular mesh for a 2-D geometry and a tetrahedral mesh for a 3-D geometry. By default, the mesh generator uses internal algorithms to choose suitable sizing parameters for a particular geometry. You also can use additional arguments to specify the following parameters explicitly:
Target maximum mesh edge length, which is an approximate upper bound on the mesh edge lengths. Note that occasionally, some elements can have edges longer than this parameter.
Target minimum mesh edge length, which is an approximate lower bound on the mesh edge lengths. Note that occasionally, some elements can have edges shorter than this parameter.
Mesh growth rate, which is the rate at which the mesh size increases away from the small parts of the geometry. The value must be between 1 and 2. This ratio corresponds to the edge length of two successive elements. The default value is 1.5, that is, the mesh size increases by 50%.
Quadratic or linear geometric order. A quadratic element has nodes at its corners and edge centers, while a linear element has nodes only at its corners.
Create a model and include the geometry of a plate with a square hole in its center.
model = femodel(Geometry="PlateSquareHolePlanar.stl");
Plot the geometry.
pdegplot(model)
Generate a default mesh. For this geometry, the default target maximum and minimum mesh edge lengths are 8.9443 and 4.4721, respectively.
model = generateMesh(model); model.Geometry.Mesh
ans = FEMesh with properties: Nodes: [2x1210 double] Elements: [6x570 double] MaxElementSize: 8.9443 MinElementSize: 4.4721 MeshGradation: 1.5000 GeometricOrder: 'quadratic'
View the mesh.
figure pdemesh(model)
For comparison, create a mesh with the target maximum element edge length of 20.
model = generateMesh(model,Hmax=20); model.Geometry.Mesh
ans = FEMesh with properties: Nodes: [2x298 double] Elements: [6x132 double] MaxElementSize: 20 MinElementSize: 10 MeshGradation: 1.5000 GeometricOrder: 'quadratic'
figure pdemesh(model)
Now create a mesh with the target minimum element edge length of 0.1.
model = generateMesh(model,Hmin=0.1); model.Geometry.Mesh
ans = FEMesh with properties: Nodes: [2x1394 double] Elements: [6x662 double] MaxElementSize: 8.9443 MinElementSize: 0.1000 MeshGradation: 1.5000 GeometricOrder: 'quadratic'
figure pdemesh(model)
Create a mesh, specifying both the maximum and minimum element edge lengths instead of using the default values.
model = generateMesh(model,Hmax=20,Hmin=0.1); model.Geometry.Mesh
ans = FEMesh with properties: Nodes: [2x454 double] Elements: [6x210 double] MaxElementSize: 20 MinElementSize: 0.1000 MeshGradation: 1.5000 GeometricOrder: 'quadratic'
View the mesh.
figure pdemesh(model)
Create a mesh with the same maximum and minimum element edge lengths, but with the growth rate of 1.9 instead of the default value of 1.5.
model = generateMesh(model,Hmax=20, ... Hmin=0.1, ... Hgrad=1.9); model.Geometry.Mesh
ans = FEMesh with properties: Nodes: [2x374 double] Elements: [6x170 double] MaxElementSize: 20 MinElementSize: 0.1000 MeshGradation: 1.9000 GeometricOrder: 'quadratic'
figure pdemesh(model)
You also can choose the geometric order of the mesh. The toolbox can generate meshes made up of quadratic or linear elements. By default, it uses quadratic meshes, which have nodes at both the edge centers and corner nodes.
model = generateMesh(model,Hmax=50); figure pdemesh(model,NodeLabels="on") hold on plot(model.Geometry.Mesh.Nodes(1,:), ... model.Geometry.Mesh.Nodes(2,:), ... "ok","MarkerFaceColor","g")
To save memory, override the default quadratic geometric order.
model = generateMesh(model,Hmax=50, ... GeometricOrder="linear"); figure pdemesh(model,NodeLabels="on") hold on plot(model.Geometry.Mesh.Nodes(1,:), ... model.Geometry.Mesh.Nodes(2,:), ... "ok","MarkerFaceColor","g")