import firedrake
/home/firedrake/firedrake/lib/python3.12/site-packages/pytools/persistent_dict.py:52: RecommendedHashNotFoundWarning: Unable to import recommended hash 'siphash24.siphash13', falling back to 'hashlib.sha256'. Run 'python3 -m pip install siphash24' to install the recommended hash. warn("Unable to import recommended hash 'siphash24.siphash13', "
import viskex
import common_firedrake as common # isort: skip
Generate meshes of the unit square by dividing each edge of the square in 6 segments, using either a triangular or quadrangular mesh.
square_tria = firedrake.UnitSquareMesh(6, 6, quadrilateral=False, diagonal="right")
square_quad = firedrake.UnitSquareMesh(6, 6, quadrilateral=True, diagonal="right")
Mark subdomains according to the $(x, y)$ position of the vertices of the mesh:
square_tria_with_subdomains = common.mark_subdomains(square_tria)
square_quad_with_subdomains = common.mark_subdomains(square_quad)
/home/firedrake/firedrake/src/loopy/loopy/schedule/__init__.py:2255: LoopyWarning: in kernel expression_kernel: Falling back to a slow scheduler implementation due to: cannot schedule kernels with priority dependencies between sibling loop nests (add 'v1_scheduler_fallback' to silenced_warnings kernel attribute to disable) warn_with_kernel(
/home/firedrake/firedrake/src/loopy/loopy/schedule/__init__.py:2255: LoopyWarning: in kernel expression_kernel: Falling back to a slow scheduler implementation due to: cannot schedule kernels with priority dependencies between sibling loop nests (add 'v1_scheduler_fallback' to silenced_warnings kernel attribute to disable) warn_with_kernel(
/home/firedrake/firedrake/src/loopy/loopy/schedule/__init__.py:2255: LoopyWarning: in kernel expression_kernel: Falling back to a slow scheduler implementation due to: cannot schedule kernels with priority dependencies between sibling loop nests (add 'v1_scheduler_fallback' to silenced_warnings kernel attribute to disable) warn_with_kernel(
/home/firedrake/firedrake/src/loopy/loopy/schedule/__init__.py:2255: LoopyWarning: in kernel expression_kernel: Falling back to a slow scheduler implementation due to: cannot schedule kernels with priority dependencies between sibling loop nests (add 'v1_scheduler_fallback' to silenced_warnings kernel attribute to disable) warn_with_kernel(
We plot the resulting subdomains.
viskex.firedrake.plot_mesh_sets(square_tria_with_subdomains, 2, "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(square_quad_with_subdomains, 2, "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(
square_tria_with_subdomains, 2, "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(
square_quad_with_subdomains, 2, "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(
square_tria_with_subdomains, 2, "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(
square_quad_with_subdomains, 2, "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.
square_tria.topology_dm.removeLabel(firedrake.cython.dmcommon.CELL_SETS_LABEL)
square_quad.topology_dm.removeLabel(firedrake.cython.dmcommon.CELL_SETS_LABEL)
viskex.firedrake.plot_mesh_sets(square_tria, 2, "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(square_quad, 2, "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