import dolfinx.mesh
import mpi4py.MPI
import viskex
import common_dolfinx 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 = dolfinx.mesh.create_unit_cube(mpi4py.MPI.COMM_WORLD, 6, 6, 6, dolfinx.mesh.CellType.tetrahedron)
cube_hexa = dolfinx.mesh.create_unit_cube(mpi4py.MPI.COMM_WORLD, 6, 6, 6, dolfinx.mesh.CellType.hexahedron)
Mark subdomains according to the $(x, y, z)$ position of the vertices of the mesh:
cube_tetra_subdomains = common.mark_subdomains(cube_tetra)
cube_hexa_subdomains = common.mark_subdomains(cube_hexa)
We plot the resulting subdomains.
viskex.dolfinx.plot_mesh_tags(cube_tetra, cube_tetra_subdomains, "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.dolfinx.plot_mesh_tags(cube_hexa, cube_hexa_subdomains, "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 with tag equal to $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.dolfinx.plot_mesh_tags(
cube_tetra, cube_tetra_subdomains, "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.dolfinx.plot_mesh_tags(
cube_hexa, cube_hexa_subdomains, "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 tag equal to $2$.
viskex.dolfinx.plot_mesh_tags(
cube_tetra, cube_tetra_subdomains, "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.dolfinx.plot_mesh_tags(
cube_hexa, cube_hexa_subdomains, "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