Skip to content
Open
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ target_sources( T8 PRIVATE
t8_forest/t8_forest_ghost/t8_forest_ghost_definition_helpers.cxx
t8_forest/t8_forest_ghost/t8_forest_ghost_implementations/t8_forest_ghost_definition_face.cxx
t8_forest/t8_forest_ghost/t8_forest_ghost_implementations/t8_forest_ghost_definition_w_search.cxx
t8_forest/t8_forest_mesh_quality/t8_forest_aspect_ratio.cxx
t8_forest/t8_forest_iterate.cxx
t8_forest/t8_forest_balance.cxx
t8_forest/t8_forest_subelement.cxx
Expand Down
88 changes: 88 additions & 0 deletions src/t8_forest/t8_forest_mesh_quality/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# src/t8_forest/t8_forest_mesh_quality

This folder contains functions that measure the quality of the elements of a forest.
The shape of the elements affects how accurate a numerical simulation is and how well the resulting linear systems are conditioned.
It is therefore useful to check a mesh before you use it, for example after it was created by a generator, deformed or adapted.
At the moment, the folder provides the aspect ratio. It works for all element shapes of the default scheme (triangles, quads, tets, hexes, prisms and pyramids),
including hybrid meshes.
The functions are C++ only. The functions that compute global statistics are collective for multiple processes.

## The aspect ratio

The aspect ratio (AR) measure how much an element differs from the ideal, regular element of its shape:

```
AR = L_max * |∂E| / (d * |E|) / c_E
```

Here, `L_max` is the longest edge of the element `E`, `|∂E|` is its perimeter (2D) or surface area (3D), `|E|` is its area (2D) or volume (3D), and `d` is the dimension. For triangles, squares, tetrahedra and cubes, `d * |E| / |∂E|` can also be called the "inradius", so the AR is the longest edge divided by the inradius.
The constant `c_E` is a scalar constant, that differs for each shape. It ensures, that the ideal element has an AR of 1:

| Shape | Ideal element (AR = 1) | `c_E` |
|----------|--------------------------------------------------|------------------|
| triangle | equilateral triangle | 2√3 |
| quad | square | 2 |
| tet | regular tetrahedron | 2√6 |
| hex | cube | 2 |
| prism | equilateral triangle × interval, all edges equal | 2/3 + 4/√3 |
| pyramid | square base, all edges equal | √2 (1 + √3) |

The more an element is stretched, flattened or sheared, the larger is its AR. A degenerate element (zero volume) has AR = infinity.
AR >= 1 holds for all shapes except pyramids: a pyramid slightly taller than the ideal pyramid can reach an AR of about 0.9966.
For triangles, flat quads and tetrahedra, the definition is the same as the "aspect ratio" of the Verdict library, which ParaView's "Mesh Quality" filter uses,
so you can compare the values there.
Some tools (e.g. gmsh) report a quality in [0, 1] instead; here this is 1/AR, which the histogram uses.

A large aspect ratio is not always a mistake. Anisotropic meshes, e.g. boundary layers in flow simulations, contain stretched elements on purpose. If interested, you can look up the paper of Shewchuk below under Literature, as he explains exactly which shapes harm the interpolation error and which harm the conditioning, and how the two differ for anisotropic elements.

The AR is computed from the corner coordinates of an element. Curved geometries are therefore treated as if the element had straight edges. A warped (non-flat) quad face is approximated by the average of its two splits into triangles.

### Literature

- C. J. Stimpson, C. D. Ernst, P. Knupp, P. P. Pébay, D. Thompson:
*The Verdict Geometric Quality Library*, Sandia Report SAND2007-1751, 2007.
[OSTI 901967](https://www.osti.gov/biblio/901967).
Defines the aspect ratio of triangles, quads and tetrahedra that we follow (and many other quality measures).
- P. P. Pébay, T. J. Baker: *Analysis of triangle quality measures*, Mathematics of Computation 72 (2003),
1817–1839. [doi:10.1090/S0025-5718-03-01485-6](https://doi.org/10.1090/S0025-5718-03-01485-6).
Compares common triangle quality measures and proves their extremal and asymptotic properties.
- J. R. Shewchuk: *What Is a Good Linear Finite Element? Interpolation, Conditioning, Anisotropy, and Quality
Measures*, 2002. [Preprint (PDF)](https://people.eecs.berkeley.edu/~jrs/papers/elemj.pdf).
Explains why element shape matters for finite elements and surveys quality measures.

## Files

#### [t8_forest_aspect_ratio.hxx](t8_forest_aspect_ratio.hxx), [t8_forest_aspect_ratio.cxx](t8_forest_aspect_ratio.cxx)

| Function | Purpose |
|----------|---------|
| `t8_forest_element_aspect_ratio` | AR of a single element. |
| `t8_forest_compute_element_aspect_ratios` | AR of every local leaf element as per element data (one entry per element, in forest order). |
| `t8_forest_compute_aspect_ratio_stats` | Global minimum, maximum, average and a histogram of 1/AR in 10 bins (collective). Optionally from already computed per element data. |
| `t8_forest_average_aspect_ratio`, `t8_forest_max_aspect_ratio` | Shortcuts for the average AR and the AR of the worst element (collective). |
| `t8_forest_print_aspect_ratio` | Prints best, worst and average AR and a gmsh-style histogram on rank 0. |
| `t8_forest_write_vtk_aspect_ratio` | Writes the forest to vtu files with the cell data `aspect_ratio` and `aspect_ratio_quality` (= 1/AR), e.g. for ParaView (collective). |

The forest does not store the aspect ratios. If you need them several times, compute them once with `t8_forest_compute_element_aspect_ratios` and pass the vector to the statistics and output functions:

```cpp
#include <t8_forest/t8_forest_mesh_quality/t8_forest_aspect_ratio.hxx>

/* Quick overview. */
t8_forest_print_aspect_ratio (forest);

/* Compute the aspect ratios once and reuse them. */
const std::vector<double> aspect_ratios = t8_forest_compute_element_aspect_ratios (forest);
const t8_forest_aspect_ratio_stats stats = t8_forest_compute_aspect_ratio_stats (forest, aspect_ratios);
t8_forest_print_aspect_ratio (stats);
t8_forest_write_vtk_aspect_ratio (forest, "my_forest", aspect_ratios);
```

## See also

- [example/forest/t8_example_aspect_ratio.cxx](../../../example/forest/t8_example_aspect_ratio.cxx): creates meshes with
particularly good and bad elements and writes them to vtu files, to compare with ParaView.
- [test/t8_forest/t8_gtest_aspect_ratio.cxx](../../../test/t8_forest/t8_gtest_aspect_ratio.cxx): tests with
analytically known aspect ratios.
- [mesh_handle/competences/aspect_ratio_competences.hxx](../../../mesh_handle/competences/aspect_ratio_competences.hxx):
the same functionality for the mesh handle.
Loading
Loading