import firedrake
/home/firedrake/firedrake/lib/python3.10/site-packages/pytools/__init__.py:2489: UserWarning: unable to find git revision warn("unable to find git revision")
import viskex
import common_firedrake as common # isort: skip
Generate a mesh of the unit interval, divided into six cells.
interval = firedrake.UnitIntervalMesh(6)
Mark subdomains according to the $x$ position of the vertices of the mesh:
interval_with_subdomains = common.mark_subdomains(interval)
We plot the resulting subdomains.
viskex.firedrake.plot_mesh_sets(interval_with_subdomains, 1, "subdomains")
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(
interval_with_subdomains, 1, "subdomains_2", viskex.utils.values_in([2]))
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(
interval_with_subdomains, 1, "subdomains_2",
lambda grid: grid.threshold(2)) # type: ignore[no-untyped-call]
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.
interval.topology_dm.removeLabel(firedrake.cython.dmcommon.CELL_SETS_LABEL)
viskex.firedrake.plot_mesh_sets(interval, 1, "subdomains")
/home/firedrake/firedrake/lib/python3.10/site-packages/pyvista/plotting/mapper.py:670: RuntimeWarning: All-NaN axis encountered clim = [np.nanmin(scalars), np.nanmax(scalars)]