Mesh Metrics

The nanomesh.metrics module helps with calculating different types of cell metrics.

There are a few higher level functions available. While one could use calculate_all_metrics() to calculate all available metrics, each function is also available by itself.

histogram() and plot2d() are helpers to visualize the metrics.

See also

For more info, see the example on Calculate mesh quality metrics.

Functions

These metrics are currently available:

area

Calculate the area of a triangle.

aspect_frobenius

Calculate the Frobenius condition number of the transformation matrix from an equilateral triangle to a triangle.

aspect_ratio

Calculate the aspect ratio of a triangle.

condition

Calculate the condition number of a triangle.

distortion

Calculate the distortion of a triangle.

max_angle

Calculate the maximal (non-oriented) angle of a triangle.

max_min_edge_ratio(mesh)

Calculate the ratio between the longest and shortest edge lengths of a triangle.

min_angle

Calculate the minimal (non-oriented) angle of a triangle.

radius_ratio

R/2r, where R and r respectively denote the circumradius and the inradius of t.

relative_size_squared

Calculate the square of the relative size of a triangle.

scaled_jacobian

Calculate the scaled Jacobian of a triangle.

shape

Calculate the shape of a triangle.

shape_and_size

Calculate the product of shape and relative size of a triangle.

Utility functions:

calculate_all_metrics(mesh[,Β inplace])

Calculate all available metrics.

histogram(mesh,Β *,Β metric[,Β ax])

Create a mesh plot with the cells are colored by the cell quality.

plot2d(mesh,Β *,Β metric[,Β ax])

Create a mesh plot with the cells are colored by the cell quality.

Reference

nanomesh.metrics.calculate_all_metrics(mesh: Mesh, inplace: bool = False) dict[source]

Calculate all available metrics.

Parameters
  • mesh (Mesh) – Input mesh

  • inplace (bool, optional) – Updates the Mesh.cell_data attribute on the mesh with the metrics.

Returns

metrics – Return a dict with all the metrics

Return type

dict

nanomesh.metrics.histogram(mesh: Mesh, *, metric: str, ax: Optional[Axes] = None, **kwargs) Axes[source]

Create a mesh plot with the cells are colored by the cell quality.

Parameters
  • mesh (Mesh) – Input mesh

  • metric (str) – Metric to calculate.

  • ax (matplotlib.axes.Axes) – If specified, ax will be used to create the subplot.

  • vmin (int, float) – Set the lower/upper boundary for the color value.

  • vmax (int, float) – Set the lower/upper boundary for the color value.

  • cmap (str) – Set the color map.

  • **kwargs – Keyword arguments passed on to matplotlib.pyplot.hist().

Returns

ax

Return type

matplotlib.axes.Axes

nanomesh.metrics.plot2d(mesh: Mesh, *, metric: str, ax: Optional[Axes] = None, **kwargs) Axes[source]

Create a mesh plot with the cells are colored by the cell quality.

Parameters
  • mesh (Mesh) – Input mesh

  • metric (str) – Metric to calculate.

  • ax (matplotlib.axes.Axes) – If specified, ax will be used to create the subplot.

  • vmin (int, float) – Set the lower/upper boundary for the color value. Defaults to the 1st and 99th percentile, respectively.

  • vmax (int, float) – Set the lower/upper boundary for the color value. Defaults to the 1st and 99th percentile, respectively.

  • cmap (str) – Set the color map.

  • **kwargs – Keyword arguments passed on to matplotlib.pyplot.tripcolor().

Returns

ax

Return type

matplotlib.axes.Axes

nanomesh.metrics.area(mesh: Mesh) ndarray

Calculate the area of a triangle.

Parameters

mesh (Mesh) – Input mesh

Returns

quality – Array with cell qualities.

Return type

numpy.ndarray

nanomesh.metrics.aspect_frobenius(mesh: Mesh) ndarray

Calculate the Frobenius condition number of the transformation matrix from an equilateral triangle to a triangle.

Parameters

mesh (Mesh) – Input mesh

Returns

quality – Array with cell qualities.

Return type

numpy.ndarray

nanomesh.metrics.aspect_ratio(mesh: Mesh) ndarray

Calculate the aspect ratio of a triangle.

Parameters

mesh (Mesh) – Input mesh

Returns

quality – Array with cell qualities.

Return type

numpy.ndarray

nanomesh.metrics.condition(mesh: Mesh) ndarray

Calculate the condition number of a triangle.

Parameters

mesh (Mesh) – Input mesh

Returns

quality – Array with cell qualities.

Return type

numpy.ndarray

nanomesh.metrics.distortion(mesh: Mesh) ndarray

Calculate the distortion of a triangle.

Parameters

mesh (Mesh) – Input mesh

Returns

quality – Array with cell qualities.

Return type

numpy.ndarray

nanomesh.metrics.max_angle(mesh: Mesh) ndarray

Calculate the maximal (non-oriented) angle of a triangle.

Parameters

mesh (Mesh) – Input mesh

Returns

quality – Array with cell qualities.

Return type

numpy.ndarray

nanomesh.metrics.max_min_edge_ratio(mesh: Mesh) ndarray[source]

Calculate the ratio between the longest and shortest edge lengths of a triangle.

Parameters

mesh (Mesh) – Input mesh

Returns

quality – Array with cell qualities.

Return type

numpy.ndarray

nanomesh.metrics.min_angle(mesh: Mesh) ndarray

Calculate the minimal (non-oriented) angle of a triangle.

Parameters

mesh (Mesh) – Input mesh

Returns

quality – Array with cell qualities.

Return type

numpy.ndarray

nanomesh.metrics.radius_ratio(mesh: Mesh) ndarray

Calculate the radius ratio of a triangle. The radius ratio of a triangle t is: R/2r, where R and r respectively denote the circumradius and the inradius of t.

Parameters

mesh (Mesh) – Input mesh

Returns

quality – Array with cell qualities.

Return type

numpy.ndarray

nanomesh.metrics.relative_size_squared(mesh: Mesh) ndarray

Calculate the square of the relative size of a triangle.

Parameters

mesh (Mesh) – Input mesh

Returns

quality – Array with cell qualities.

Return type

numpy.ndarray

nanomesh.metrics.scaled_jacobian(mesh: Mesh) ndarray

Calculate the scaled Jacobian of a triangle.

Parameters

mesh (Mesh) – Input mesh

Returns

quality – Array with cell qualities.

Return type

numpy.ndarray

nanomesh.metrics.shape(mesh: Mesh) ndarray

Calculate the shape of a triangle.

Parameters

mesh (Mesh) – Input mesh

Returns

quality – Array with cell qualities.

Return type

numpy.ndarray

nanomesh.metrics.shape_and_size(mesh: Mesh) ndarray

Calculate the product of shape and relative size of a triangle.

Parameters

mesh (Mesh) – Input mesh

Returns

quality – Array with cell qualities.

Return type

numpy.ndarray