import firedrake
import viskex
import viskex.utils.pyvista
import common_01_firedrake as common # isort: skip
Generate meshes of the unit cube by dividing each edge of the cube in 6 segments, using either a tetrahedral or hexahedral mesh.
cube_tetra = firedrake.UnitCubeMesh(
6, 6, 6, hexahedral=False, distribution_parameters={"partitioner_type": "simple"})
cube_hexa = firedrake.UnitCubeMesh(
6, 6, 6, hexahedral=True, distribution_parameters={"partitioner_type": "simple"})
Mark boundaries according to the $(x, y, z)$ position of the vertices of the mesh:
cube_tetra_with_boundaries = common.mark_boundaries(cube_tetra)
cube_hexa_with_boundaries = common.mark_boundaries(cube_hexa)
We plot the resulting boundaries.
viskex.firedrake.plot_mesh_sets(cube_tetra_with_boundaries, 2, "boundaries")
firedrake:WARNING Subdomain (3,) is empty. This is likely an error. Did you choose the right label?
firedrake:WARNING Subdomain (4,) is empty. This is likely an error. Did you choose the right label?
2026-05-25 08:17:01.401 ( 4.144s) [ 7F579D7CA080]vtkXOpenGLRenderWindow.:1460 WARN| bad X server connection. DISPLAY=
viskex.firedrake.plot_mesh_sets(cube_hexa_with_boundaries, 2, "boundaries")
firedrake:WARNING Subdomain (3,) is empty. This is likely an error. Did you choose the right label?
firedrake:WARNING Subdomain (4,) is empty. This is likely an error. Did you choose the right label?
We can also plot all boundaries which belong to the mesh set $4$ (first and second plot), $2$ (third and fourth plot) or both (fifth and sixth plot), which will be displayed with colors. The rest of the mesh facets are still included in the plot, but are colored in gray.
viskex.firedrake.plot_mesh_sets(
cube_tetra_with_boundaries, 2, "boundaries_4", viskex.utils.pyvista.values_in([4]))
viskex.firedrake.plot_mesh_sets(
cube_hexa_with_boundaries, 2, "boundaries_4", viskex.utils.pyvista.values_in([4]))
viskex.firedrake.plot_mesh_sets(
cube_tetra_with_boundaries, 2, "boundaries_2", viskex.utils.pyvista.values_in([2]))
viskex.firedrake.plot_mesh_sets(
cube_hexa_with_boundaries, 2, "boundaries_2", viskex.utils.pyvista.values_in([2]))
viskex.firedrake.plot_mesh_sets(
cube_tetra_with_boundaries, 2, "boundaries_24", viskex.utils.pyvista.values_in([2, 4]))
viskex.firedrake.plot_mesh_sets(
cube_hexa_with_boundaries, 2, "boundaries_24", viskex.utils.pyvista.values_in([2, 4]))
The mesh sets are stored as part of the firedrake mesh object. If the mesh sets get removed, all cells will be displayed in gray in the plot.
cube_tetra.topology_dm.removeLabel(firedrake.cython.dmcommon.FACE_SETS_LABEL)
cube_hexa.topology_dm.removeLabel(firedrake.cython.dmcommon.FACE_SETS_LABEL)
viskex.firedrake.plot_mesh_sets(cube_tetra, 2, "boundaries")
/usr/local/lib/python3.12/dist-packages/pyvista/plotting/mapper.py:963: RuntimeWarning: All-NaN axis encountered clim = [np.nanmin(scalars), np.nanmax(scalars)]
viskex.firedrake.plot_mesh_sets(cube_hexa, 2, "boundaries")