Dear Community,
when creating a submesh using dolfinx.mesh.create_submesh and visualizing the spatial coordinates I find that the mesh is somehow destroyed/ the triangles appear to be wrongly associated.
The phenomenon that I see here also appears, when using
x = ufl.SpatialCoordinate(submesh)
I created a MWE for this:
import numpy as np
from mpi4py import MPI
import dolfinx
from dolfinx import fem
from dolfinx.mesh import locate_entities, meshtags
# 1. Create base mesh
domain = dolfinx.mesh.create_unit_square(
MPI.COMM_WORLD, 20, 20)
tdim = domain.topology.dim
# 2. Tag subdomain
def left_half(x):
return x[0]<= 0.5 + 1e-14
cells = locate_entities(domain, tdim, left_half)
ct = meshtags(domain, tdim, cells, np.full(len(cells), 20, dtype=np.int32))
# 3. Create SubMesh
submesh, submesh_to_mesh, vertex_map = dolfinx.mesh.create_submesh(
domain, tdim, ct.find(20))[0:3]
# 4. Function space on SubMesh
Vb = fem.functionspace(submesh, ("Lagrange", 1))
# 5. Plot the grid
import pyvista
topology, cell_types,_ = dolfinx.plot.vtk_mesh(Vb)
grid = pyvista.UnstructuredGrid(topology, cell_types, submesh.geometry.x)
xvals = submesh.geometry.x
grid.point_data["x0"] = xvals[:, 0]
plotter = pyvista.Plotter()
plotter.add_mesh(grid, scalars="x0", show_edges=True)
plotter.show()
See also the following plot:
Interestingly, this does not appear, when changing the definition left_half to
def left_half(x):
return x[1]<= 0.5 + 1e-14
I appreciate any help or insights on what might be the problem or what I am doing wrong here.
Best,
Marvin