Hi all,
I’m having problem visualizing meshtags in Paraview (version 5.13.1). In the following MWE I build a simple mesh and define meshtags (0 and 1) as a MeshTags
object (named mesh_tags) and as a ("DG", 0)
function (named tagfun). Then I export them as an xdmf file with the commands write_meshtags
and write_function
.
from mpi4py import MPI from dolfinx import mesh, fem from dolfinx.fem import Function, functionspace from dolfinx.io import XDMFFile from dolfinx.mesh import locate_entities, meshtags, MeshTags, create_unit_square, CellType import numpy as np def Omega_0(x): return x[1] <= 0.5 def Omega_1(x): return x[1] >= 0.5 mesh = create_unit_square(MPI.COMM_WORLD, 10, 10, CellType.triangle) cells_0 = locate_entities(mesh, mesh.topology.dim, Omega_0) cells_1 = locate_entities(mesh, mesh.topology.dim, Omega_1) sorted_cells = np.sort(np.concatenate((cells_0, cells_1))) tags = np.zeros_like(sorted_cells) tags[np.isin(sorted_cells, cells_0)] = 0 tags[np.isin(sorted_cells, cells_1)] = 1 cell_tags = meshtags(mesh, mesh.topology.dim, sorted_cells, tags) Q = functionspace(mesh, ("DG", 0)) tagfun = Function(Q, name="tagfun") tagfun.x.array[:] = cell_tags.values file_results = XDMFFile(MPI.COMM_WORLD, "tagtest/tagstest.xdmf", "w") file_results.write_mesh(mesh) file_results.write_meshtags(cell_tags, mesh.geometry) file_results.write_function(tagfun) file_results.close()
Although the mesh_tags array shows up in the properties of the file, I can’t find a way to visualize it. Look at the screenshots:
Instead, if I replace the last few lines of the MWE with
file_results = XDMFFile(MPI.COMM_WORLD, "tagtest/tagstest.xdmf", "w") file_results.write_mesh(mesh) file_results.write_meshtags(cell_tags, mesh.geometry) file_results.close()
i.e., when the MeshTags
object is the only data exported in the xdmf file aside from the mesh, then I’m able to access the mesh_tags array, as you can see from the screenshots:
Exporting mesh tags as functions is not ideal as it forces me to write them at every time of the simulation, making the xdmf file unnecessarily large.
How trivial is this issue?