import firedrake
import viskex
import common_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)
cube_hexa = firedrake.UnitCubeMesh(6, 6, 6, hexahedral=True)
Mark subdomains according to the $(x, y, z)$ position of the vertices of the mesh:
cube_tetra_with_subdomains = common.mark_subdomains(cube_tetra)
cube_hexa_with_subdomains = common.mark_subdomains(cube_hexa)
We plot the resulting subdomains.
viskex.firedrake.plot_mesh_sets(cube_tetra_with_subdomains, 3, "subdomains")
error: XDG_RUNTIME_DIR is invalid or not set in the environment. MESA: error: ZINK: failed to choose pdev glx: failed to create drisw screen
viskex.firedrake.plot_mesh_sets(cube_hexa_with_subdomains, 3, "subdomains")
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
MESA: error: ZINK: failed to choose pdev glx: failed to create drisw screen
We can also plot all subdomains that belong to the mesh set $2$, which will be displayed with colors. The rest of the mesh cells are still included in the plot, but are colored in gray.
viskex.firedrake.plot_mesh_sets(
cube_tetra_with_subdomains, 3, "subdomains_2", viskex.utils.values_in([2]))
error: XDG_RUNTIME_DIR is invalid or not set in the environment. MESA: error: ZINK: failed to choose pdev glx: failed to create drisw screen
viskex.firedrake.plot_mesh_sets(
cube_hexa_with_subdomains, 3, "subdomains_2", viskex.utils.values_in([2]))
error: XDG_RUNTIME_DIR is invalid or not set in the environment. MESA: error: ZINK: failed to choose pdev glx: failed to create drisw screen
Alternatively, we can clip the plot so that it only shows the subset of the mesh with subdomain set equal to $2$.
viskex.firedrake.plot_mesh_sets(
cube_tetra_with_subdomains, 3, "subdomains_2",
lambda grid: grid.threshold(2)) # type: ignore[no-untyped-call]
error: XDG_RUNTIME_DIR is invalid or not set in the environment. MESA: error: ZINK: failed to choose pdev glx: failed to create drisw screen
viskex.firedrake.plot_mesh_sets(
cube_hexa_with_subdomains, 3, "subdomains_2",
lambda grid: grid.threshold(2)) # type: ignore[no-untyped-call]
error: XDG_RUNTIME_DIR is invalid or not set in the environment. MESA: error: ZINK: failed to choose pdev glx: failed to create drisw screen
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.CELL_SETS_LABEL)
cube_hexa.topology_dm.removeLabel(firedrake.cython.dmcommon.CELL_SETS_LABEL)
viskex.firedrake.plot_mesh_sets(cube_tetra, 3, "subdomains")
/home/firedrake/firedrake/lib/python3.12/site-packages/pyvista/plotting/mapper.py:669: RuntimeWarning: All-NaN axis encountered clim = [np.nanmin(scalars), np.nanmax(scalars)] error: XDG_RUNTIME_DIR is invalid or not set in the environment. MESA: error: ZINK: failed to choose pdev glx: failed to create drisw screen
viskex.firedrake.plot_mesh_sets(cube_hexa, 3, "subdomains")
/home/firedrake/firedrake/lib/python3.12/site-packages/pyvista/plotting/mapper.py:669: RuntimeWarning: All-NaN axis encountered clim = [np.nanmin(scalars), np.nanmax(scalars)] error: XDG_RUNTIME_DIR is invalid or not set in the environment. MESA: error: ZINK: failed to choose pdev glx: failed to create drisw screen