cashocs.geometry.quality#

Mesh quality computation.

Functions

compute_mesh_quality(mesh[, quality_type, ...])

This computes the mesh quality of a given mesh.

Classes

ConditionNumberCalculator()

Implements the condition number quality measure.

MaximumAngleCalculator()

Implements the maximum angle quality measure.

MeshQuality()

A class used to compute the quality of a mesh.

MeshQualityCalculator()

Interface for calculating mesh quality.

RadiusRatiosCalculator()

Implements the radius ratios quality measure.

SkewnessCalculator()

Implements the skewness quality measure.

class cashocs.geometry.quality.ConditionNumberCalculator[source]#

Bases: MeshQualityCalculator

Implements the condition number quality measure.

compute(mesh)[source]#

Computes the condition number quality for each cell.

This quality criterion uses the condition number (in the Frobenius norm) of the (linear) mapping from the elements of the mesh to the reference element.

Parameters:

mesh (fenics.Mesh) – The mesh, whose quality shall be computed.

Returns:

The condition numbers of the elements on process 0.

Return type:

ndarray

class cashocs.geometry.quality.MaximumAngleCalculator[source]#

Bases: MeshQualityCalculator

Implements the maximum angle quality measure.

compute(mesh)[source]#

Computes the largest angle of each element.

This measures the relative distance of a triangle’s angles or a tetrahedron’s dihedral angles to the corresponding optimal angle. The optimal angle is defined as the angle an equilateral (and thus equiangular) element has. This is defined as

\[1 - \max\left( \frac{\alpha - \alpha^*}{\pi - \alpha^*} , 0 \right),\]

where \(\alpha\) is the corresponding (dihedral) angle of the element and \(\alpha^*\) is the corresponding (dihedral) angle of the reference element.

Parameters:

mesh (fenics.Mesh) – The mesh, whose quality shall be computed.

Returns:

The maximum angle quality measure for each element on process 0.

Return type:

ndarray

class cashocs.geometry.quality.MeshQuality[source]#

Bases: object

A class used to compute the quality of a mesh.

All quality measures have values in \([0,1]\), where 1 corresponds to the reference (optimal) element, and 0 corresponds to degenerate elements.

classmethod avg(calculator, mesh)[source]#

Computes the average mesh quality.

Parameters:
  • calculator (MeshQualityCalculator) – The calculator used to compute the mesh quality.

  • mesh (fenics.Mesh) – The mesh under investigation.

Returns:

The average mesh quality according to the measure used.

Return type:

float

classmethod min(calculator, mesh)[source]#

Computes the minimum mesh quality.

Parameters:
  • calculator (MeshQualityCalculator) – The calculator used to compute the mesh quality.

  • mesh (fenics.Mesh) – The mesh under investigation.

Returns:

The minimum mesh quality according to the measure used.

Return type:

float

class cashocs.geometry.quality.MeshQualityCalculator[source]#

Bases: object

Interface for calculating mesh quality.

abstract compute(mesh)[source]#

Compute the mesh quality based on the implemented quality measure.

Parameters:

mesh (fenics.Mesh) – The mesh under investigation.

Returns:

The array of cell qualities, gathered on process 0.

Return type:

ndarray

class cashocs.geometry.quality.RadiusRatiosCalculator[source]#

Bases: MeshQualityCalculator

Implements the radius ratios quality measure.

compute(mesh)[source]#

Computes the radius ratios of the mesh elements.

This measures the ratio of the element’s inradius to its circumradius, normalized by the geometric dimension. This is computed via

\[d \frac{r}{R},\]

where \(d\) is the spatial dimension, \(r\) is the inradius, and \(R\) is the circumradius.

Parameters:

mesh (fenics.Mesh) – The mesh, whose quality shall be computed.

Returns:

The radius ratios of the mesh elements on process 0.

Return type:

ndarray

class cashocs.geometry.quality.SkewnessCalculator[source]#

Bases: MeshQualityCalculator

Implements the skewness quality measure.

compute(mesh)[source]#

Computes the skewness of the mesh.

This measure the relative distance of a triangle’s angles or a tetrahedron’s dihedral angles to the corresponding optimal angle. The optimal angle is defined as the angle an equilateral, and thus equiangular, element has. The skewness lies in \([0,1]\), where 1 corresponds to the case of an optimal (equilateral) element, and 0 corresponds to a degenerate element. The skewness corresponding to some (dihedral) angle \(\alpha\) is defined as

\[1 - \max \left( \frac{\alpha - \alpha^*}{\pi - \alpha*} , \ \frac{\alpha^* - \alpha}{\alpha^* - 0} \right),\]

where \(\alpha^*\) is the corresponding angle of the reference element.

Parameters:

mesh (fenics.Mesh) – The mesh whose quality shall be computed.

Returns:

The element wise skewness of the mesh on process 0.

Return type:

ndarray

cashocs.geometry.quality.compute_mesh_quality(mesh, quality_type='min', quality_measure='skewness')[source]#

This computes the mesh quality of a given mesh.

Parameters:
  • mesh (fenics.Mesh) – The mesh whose quality shall be computed.

  • quality_type (str) – The type of measurement for the mesh quality, either minimum quality or average quality over all mesh cells, default is ‘min’.

  • quality_measure (str) – The type of quality measure which is used to compute the quality measure, default is ‘skewness’

Returns:

The quality of the mesh, in the interval \([0,1]\), where 0 is the worst, and 1 the best possible quality.

Return type:

float