I have a complicated mesh that comes with cell tags to mark the regions.
How can I write out a partial mesh for the separate regions for expection in, say, paraview? Preferably using the capabilities of dolfinx.io
Here is a screenshot of the mesh (already clipped to see some of the inner parts)
And here is the code that I use to convert the mesh from .nas
to .xdmf
and then to read it into dolfinx
.
import meshio
import dolfinx
from mpi4py import MPI
def create_mesh(mesh, cell_type, prune_z=False):
cells = mesh.get_cells_type(cell_type)
cell_data = mesh.get_cell_data("nastran:ref", cell_type)
out_mesh = meshio.Mesh(points=mesh.points, cells={cell_type: cells},
cell_data={"Region": [cell_data]})
return out_mesh
msh = meshio.read("FuMO_mesh.nas")
tetra_mesh = create_mesh(msh, "tetra", True)
meshio.write("tetra_mesh.xdmf", tetra_mesh)
print('saved tetra mesh')
filename = 'tetra_mesh.xdmf'
with dolfinx.io.XDMFFile(MPI.COMM_WORLD, filename, "r") as xdmf:
mesh = xdmf.read_mesh(name="Grid")
cell_tags = xdmf.read_meshtags(mesh, name="Grid")