# meshQuality

Evaluate shape quality of mesh elements

## Syntax

``Q = meshQuality(mesh)``
``Q = meshQuality(mesh,elemIDs)``
``Q = meshQuality(___,"aspect-ratio")``

## 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.

Create a PDE model.

`model = createpde;`

Include and plot the following geometry.

```importGeometry(model,"PlateSquareHoleSolid.stl"); pdegplot(model)```

Create and plot a coarse mesh.

`mesh = generateMesh(model,"Hmax",35)`
```mesh = FEMesh with properties: Nodes: [3x838 double] Elements: [10x364 double] MaxElementSize: 35 MinElementSize: 17.5000 MeshGradation: 1.5000 GeometricOrder: 'quadratic' ```
`pdemesh(model)`

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")```

Plot the element quality in a histogram.

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

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.

Create a PDE model.

`model = createpde;`

Include and plot the following geometry.

```importGeometry(model,"PlateSquareHolePlanar.stl"); pdegplot(model)```

Create and plot a coarse mesh.

`mesh = generateMesh(model,"Hmax",20)`
```mesh = FEMesh with properties: Nodes: [2x298 double] Elements: [6x132 double] MaxElementSize: 20 MinElementSize: 10 MeshGradation: 1.5000 GeometricOrder: 'quadratic' ```
`pdemesh(model)`

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

`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 ⋮ ```

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.

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

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)`

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 object, specified as the `Mesh` property of a `PDEModel` object or as the output of `generateMesh`.

Example: `model.Mesh`

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=\frac{4\sqrt{3}A}{\sum _{i=1}^{3}{l}_{i}^{2}}$`

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=\frac{18V}{\sqrt{\sum _{i=1}^{6}{l}_{i}^{2}}\sqrt{\sum _{k=1}^{4}{A}_{k}^{2}}}$`

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:

`${Q}_{AR}=\frac{4}{\sqrt{3}}\frac{A}{{l}_{\mathrm{max}}^{2}}$`

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

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

`${Q}_{AR}=\frac{\text{3}\sqrt{6}}{2}\frac{\text{V}}{{\text{l}}_{\text{max}}{A}_{\text{max}}}$`

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

`${A}_{\mathrm{max}}=\mathrm{max}\left({A}_{k}\right),\text{ }k=1,\dots ,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