Main Content

meshQuality

R2026b

Evaluate shape quality of mesh elements

Description

Q = meshQuality(mesh) returns a row vector of numbers from 0 through 1 representing shape quality of all elements of the mesh. Here, 1 corresponds to the optimal shape of the element.

example

Q = meshQuality(mesh,elemIDs) returns the shape quality of the specified elements.

example

Q = meshQuality(___,"aspect-ratio") determines the shape quality by using the ratio of minimal to maximal dimensions of an element. The quality values are numbers from 0 through 1, where 1 corresponds to the optimal shape of the element. Specify "aspect-ratio" after any of the previous syntaxes.

example

Examples

collapse all

Evaluate the shape quality of the elements of a 3-D mesh.

Import and plot the geometry.

g = fegeometry("PlateSquareHoleSolid.stl");
pdegplot(g)

3-D rectangular plate geometry with a small hole at the center

Create and plot a coarse mesh.

g = generateMesh(g,Hmax=35)
g = 
  fegeometry with properties:

        NumCells: 1
        NumFaces: 10
        NumEdges: 24
     NumVertices: 16
        Vertices: [16×3 double]
    FeatureAngle: 44
            Mesh: [1×1 FEMesh]

mesh=g.Mesh;
pdemesh(mesh)

Coarse tetrahedral mesh of the 3-D rectangular plate with a small hole at the center

Evaluate the shape quality of all mesh elements. Display the first five values.

Q = meshQuality(mesh);
Q(1:5)
ans = 1×5

    0.8692    0.7119    0.8047    0.7838    0.8417

Find the elements with the quality values less than 0.2.

elemIDs = find(Q < 0.2);

Highlight these elements in blue on the mesh plot.

pdemesh(mesh,FaceAlpha=0.5)
hold on
pdemesh(mesh.Nodes,mesh.Elements(:,elemIDs), ...
                   FaceColor="blue", ...
                   EdgeColor="blue")

Tetrahedral mesh with elements having quality less than 0.2 highlighted in blue near the hole at the center

Plot the element quality in a histogram.

figure
hist(Q)
xlabel("Element Shape Quality",FontWeight="b")
ylabel("Number of Elements",FontWeight="b")

Histogram of element shape quality with most elements between 0.6 and 0.9, peaking near 0.75

Find the worst quality value.

Qworst = min(Q)
Qworst = 
0.1903

Find the corresponding element IDs.

elemIDs = find(Q==Qworst)
elemIDs = 1×2

     8   244

Evaluate the shape quality of the elements of a 2-D mesh.

Import the following geometry.

g = fegeometry("PlateSquareHolePlanar.stl");
pdegplot(g)

Rectangular plate geometry with a small hole at the center, spanning 0 to 100 in x and 0 to 200 in y

Create and plot a coarse mesh.

g = generateMesh(g,Hmax=20)
g = 
  fegeometry with properties:

        NumCells: 0
        NumFaces: 1
        NumEdges: 8
     NumVertices: 8
        Vertices: [8×3 double]
    FeatureAngle: []
            Mesh: [1×1 FEMesh]

pdemesh(g)

Coarse triangular mesh of the rectangular plate with a small hole at the center

Find the IDs of the elements within a box enclosing the center of the plate.

mesh = g.Mesh;
elemIDs = findElements(mesh,"box",[25,75],[80,120]);

Evaluate the shape quality of these elements. Display the result as a column vector.

Q = meshQuality(mesh,elemIDs);
Q.'
ans = 20×1

    0.8158
    0.4618
    0.9839
    0.5948
    0.3790
    0.3957
    0.3599
    0.6534
    0.9919
    0.6130
    0.7594
    0.7010
    0.7177
    0.6919
    0.9595
      ⋮

Find the elements with the quality values less than 0.4.

elemIDs04 = elemIDs(Q < 0.4)
elemIDs04 = 1×3

    45    51    57

Highlight these elements in green on the mesh plot. Zoom in to see the details.

figure
pdemesh(mesh,ElementLabels="on")
hold on
pdemesh(mesh.Nodes,mesh.Elements(:,elemIDs04),EdgeColor="green")
zoom(10)

Zoomed mesh view with element labels, showing low-quality elements highlighted in green near the hole at the plate center

Determine the shape quality of mesh elements by using the ratios of minimal to maximal dimensions.

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

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

Generate the default mesh for the geometry.

mesh = generateMesh(model);

View the mesh.

pdeplot(model)

Triangular mesh of the L-shaped geometry with elements shown in blue

Evaluate the shape quality of mesh elements by using the minimal to maximal dimensions ratio. Display the first five values.

Q = meshQuality(mesh,"aspect-ratio");
Q(1:5)
ans = 1×5

    0.9964    0.9964    0.5385    0.9605    0.9566

Evaluate the shape quality of mesh elements by using the default setting. Display the first five values.

Q = meshQuality(mesh);
Q(1:5)
ans = 1×5

    1.0000    1.0000    0.8261    0.9992    0.9990

Input Arguments

collapse all

Mesh description, specified as an FEMesh object.

Element IDs, specified as a positive integer or a matrix of positive integers.

Example: [10 68 81 97 113 130 136 164]

Output Arguments

collapse all

Shape quality of mesh elements, returned as a row vector of numbers from 0 through 1. The value 0 corresponds to a deflated element with zero area or volume. The value 1 corresponds to an element of optimal shape.

Example: [0.9150 0.7787 0.9417 0.2744 0.9843 0.9181]

Data Types: double

Algorithms

By default, meshQuality calculates the shape quality of a triangular mesh element as follows:

Q=43Ai=13li2

Here, A is the area of the triangle, and li are the edge lengths of the triangle.

meshQuality calculates the shape quality of a tetrahedral mesh element as follows:

Q=18Vi=16li2k=14Ak2

Here, V is the volume of the tetrahedron, li are the edge lengths, and Ak are the areas of the triangular faces.

When you use the aspect-ratio argument, meshQuality calculates the quality of a triangular mesh element as follows:

QAR=43Almax2

Here, lmax is the maximal edge length of the triangle.

The aspect-ratio quality of a tetrahedral mesh element is:

QAR=362VlmaxAmax

Here, lmax is the maximal edge length of the tetrahedron, and Amax is the area of the largest face of the tetrahedron:

Amax=max(Ak),k=1,,4

References

[1] Knupp, Patrick M. "Matrix Norms & the Condition Number: A General Framework to Improve Mesh Quality via Node-Movement." In Proceedings, 8th International Meshing Roundtable. Lake Tahoe, CA, October 1999: 13-22.

[2] Shewchuk, Jonathan R. "What Is a Good Linear Element? Interpolation, Conditioning, and Quality Measures." In Proceedings, 11th International Meshing Roundtable. Ithaca, NY, September 2002: 115-126.

Version History

Introduced in R2018a