Cannot read facetag when converting .bdf file genarted from hypermesh to xdmf

Please note that you are simply not reading in your facet tags correctly:

import meshio
import dolfinx
from mpi4py import MPI
from pathlib import Path

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

if MPI.COMM_WORLD.rank == 0:
    filename = 'linear_elasticity_test.bdf'

    msh = meshio.read(filename)
    hex_mesh = create_mesh(msh, "hexahedron", False)
    meshio.write("hex.xdmf", hex_mesh)

    quad_mesh = create_mesh(msh, "quad", False)

    meshio.write("quad.xdmf", quad_mesh)
MPI.COMM_WORLD.barrier()

filename_facets = 'quad.xdmf'  # quad meshes to apply fixed boundary condition.

with dolfinx.io.XDMFFile(MPI.COMM_WORLD, "hex.xdmf", "r") as xdmf:
    mesh = xdmf.read_mesh(name="Grid")
    mesh.topology.create_connectivity(mesh.topology.dim - 1, mesh.topology.dim)

with dolfinx.io.XDMFFile(mesh.comm, filename_facets, "r") as xdmf:
    facet_tags = xdmf.read_meshtags(mesh, name="Grid")
print(facet_tags.indices, facet_tags.values)

Reads facet_tags in for your hexahedral mesh.
The reason that you cannot read in the facet_tags on a grid based of facets, is that the “quad.xdmf” grid contains nodes that are not in the actual mesh, causing a right mess inside DOLFINx.

2 Likes