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 and minimum mesh edge lengths, which are approximate upper and lower bounds on the mesh edge lengths. Note that occasionally, some elements can have edges longer than the target maximum length or shorter than the target minimum length.
Target size on selected faces, edges, and vertices. These parameters support local mesh refinement, enabling you to create meshes with finer spots around specifies faces, edges, and vertices.
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.
Maximum and Minimum Mesh Edge Length
Import a geometry of a plate with a square hole in its center.
g = fegeometry("PlateSquareHolePlanar.stl");
Plot the geometry.
figure pdegplot(g)
Generate a default mesh. For this geometry, the default target maximum and minimum mesh edge lengths are 8.9443 and 4.4721, respectively.
g = generateMesh(g); g.Mesh
ans = FEMesh with properties: Nodes: [2×1210 double] Elements: [6×570 double] MaxElementSize: 8.9443 MinElementSize: 4.4721 MeshGradation: 1.5000 GeometricOrder: 'quadratic'
View the mesh.
figure pdemesh(g)
For comparison, create a mesh with the target maximum element edge length of 20.
g = generateMesh(g,Hmax=20); g.Mesh
ans = FEMesh with properties: Nodes: [2×298 double] Elements: [6×132 double] MaxElementSize: 20 MinElementSize: 10 MeshGradation: 1.5000 GeometricOrder: 'quadratic'
figure pdemesh(g)
Now create a mesh with the target minimum element edge length of 0.1.
g = generateMesh(g,Hmin=0.1); g.Mesh
ans = FEMesh with properties: Nodes: [2×1394 double] Elements: [6×662 double] MaxElementSize: 8.9443 MinElementSize: 0.1000 MeshGradation: 1.5000 GeometricOrder: 'quadratic'
figure pdemesh(g)
Create a mesh, specifying both the maximum and minimum element edge lengths instead of using the default values.
g = generateMesh(g,Hmax=20,Hmin=0.1); g.Mesh
ans = FEMesh with properties: Nodes: [2×454 double] Elements: [6×210 double] MaxElementSize: 20 MinElementSize: 0.1000 MeshGradation: 1.5000 GeometricOrder: 'quadratic'
View the mesh.
figure pdemesh(g)
Mesh Growth Rate
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.
g = generateMesh(g,Hmax=20, ... Hmin=0.1, ... Hgrad=1.9); g.Mesh
ans = FEMesh with properties: Nodes: [2×374 double] Elements: [6×170 double] MaxElementSize: 20 MinElementSize: 0.1000 MeshGradation: 1.9000 GeometricOrder: 'quadratic'
figure pdemesh(g)
Local Mesh Refinement
Generate a mesh with finer spots around the center hole and the corners of the plate. To do this, find the IDs of the edges around the hole and the IDs of the vertices in the corners of the plate.
Plot the center hole with the edge labels.
figure
pdegplot(g,EdgeLabels="on");
xlim([48 52])
ylim([98 102])
Plot the entire plate geometry with the vertex labels.
figure
pdegplot(g,VertexLabels="on");
xlim([-10 110])
ylim([-10 210])
Generate a mesh with the target size 0.1 near the corners of the plate and around the center hole.
g = generateMesh(g,Hedge={[1 4 5 8],0.1}, ...
Hvertex={[3:5 8],0.1});
Plot the resulting mesh.
figure pdemesh(g)
Linear and Quadratic Meshes
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.
g = generateMesh(g,Hmax=40); figure pdemesh(g,NodeLabels="on") hold on plot(g.Mesh.Nodes(1,:), ... g.Mesh.Nodes(2,:), ... "ok",MarkerFaceColor="g")
To save memory, override the default quadratic geometric order.
g = generateMesh(g,Hmax=40,GeometricOrder="linear"); figure pdemesh(g,NodeLabels="on") hold on plot(g.Mesh.Nodes(1,:), ... g.Mesh.Nodes(2,:), ... "ok",MarkerFaceColor="g")