Mesh quality

Check a mesh before running it: Mesh.check() finds the problems that stop a simulation (inverted cells, faces without a patch or connection, patches without a condition) and summarises the cell quality that affects accuracy and solver convergence. Mesh.get_domain() runs the same checks and refuses a mesh with errors.

import phipict.meshing as pm

walls = pm.Patch("walls", pm.Wall())
mesh = pm.Mesh([pm.make_quad([(0, 0), (2, 0), (0.5, 1), (2.5, 1)], cells=(16, 8),
                        patches=pm.FacePatches(y_minus=walls, y_plus=walls))])
report = mesh.check()
print(report)
# 1 blocks, 128 cells
# min volume 0.01562, min scaled Jacobian 0.894
# max aspect ratio 1.12, max non-orthogonality 26.6 deg
# ERROR: faces without patch or connection: quad:X_MINUS, quad:X_PLUS

mesh.make_periodic(translation=(2.0, 0.0))
assert mesh.check().ok

The report

MeshReport has the size of the mesh, four quality measures, a list of errors and a list of warnings. report.ok is true without errors, and report.raise_if_invalid() raises a ValueError listing them.

Measure

Meaning

min_volume

smallest cell volume (area in 2D); negative for inverted cells

min_scaled_jacobian

smallest normalised corner Jacobian, 1 for rectangular cells; at or below 0 a cell is degenerate or inverted

max_aspect_ratio

longest over shortest cell edge; large values are normal in boundary layers

max_non_orthogonality

largest angle between a face normal and the line between the two cell centres, in degrees; the pressure solves converge more slowly as it grows, above about 70 degrees a warning is issued

A block whose cells are all inverted is left-handed: its axes are ordered the wrong way round. Flip one axis (MeshBlock.flip()).

Per-cell values

The measures are also available per cell, e.g. to find where a mesh is poor or to plot them (phipict.io.export.write_vtk() writes volume and scaled Jacobian of a mesh as cell data):

from phipict.meshing.quality import non_orthogonality, scaled_jacobian

block = mesh.blocks[0]
angles = non_orthogonality(block.coords)    # [ny, nx], degrees
print(float(angles.max()))

API

class phipict.meshing.MeshReport(n_blocks: int, n_cells: int, min_volume: float, min_scaled_jacobian: float, max_aspect_ratio: float, max_non_orthogonality: float, errors: list[str] = <factory>, warnings: list[str] = <factory>)[source]

Quality summary of a mesh, from Mesh.check.

n_blocks, n_cells

Size of the mesh.

Type:

int

min_volume

Smallest cell volume (area in 2D).

Type:

float

min_scaled_jacobian

Smallest normalised corner Jacobian, 1 for rectangular cells.

Type:

float

max_aspect_ratio

Largest cell aspect ratio.

Type:

float

max_non_orthogonality

Largest non-orthogonality within the blocks, in degrees.

Type:

float

errors

Problems that make the mesh unusable for a domain.

Type:

list of str

warnings

Problems that may hurt the solution.

Type:

list of str

property ok: bool

Whether there are no errors.

raise_if_invalid() → None[source]

Raise a ValueError listing the errors, if any.

Cell quality measures of structured blocks.

All functions take block vertices [dims, (nz + 1,) ny + 1, nx + 1] and return one value per cell, [(nz,) ny, nx].

phipict.meshing.quality.aspect_ratio(coords: Tensor) → Tensor[source]

Longest over shortest mean edge length of each cell.

phipict.meshing.quality.cell_volumes(coords: Tensor) → Tensor[source]

Signed cell volumes (areas in 2D), from the Jacobian at the cell centre.

Negative values mark inverted (left-handed) cells.

phipict.meshing.quality.non_orthogonality(coords: Tensor) → Tensor[source]

Largest non-orthogonality angle of a cell’s inner faces, in degrees.

The angle between the face normal and the line joining the two cell centres, for the faces between cells of the block (block interfaces are not included). Cells without an inner face get 0.

phipict.meshing.quality.scaled_jacobian(coords: Tensor) → Tensor[source]

Smallest normalised corner Jacobian of each cell, in [-1, 1].

1 is a rectangular cell; values at or below 0 mark degenerate or inverted cells.