Even if I use meshio
I get the same error for this MWE;
import numpy as np
from mpi4py import MPI
from dolfinx.io import gmshio
import gmsh
gmsh.initialize()
gdim = 1
mesh_comm = MPI.COMM_WORLD
model_rank = 0
if model_rank == 0:
gmsh.clear()
gmsh.option.setNumber("General.Terminal", 1)
r_inner = 0.2
r_outer = 0.25
gap = 1E-5
p1 = gmsh.model.occ.addPoint(0, 0, 0)
p2 = gmsh.model.occ.addPoint(r_inner-gap, 0, 0)
l1 = gmsh.model.occ.addLine(p1,p2,1)
p3 = gmsh.model.occ.addPoint(r_inner+gap, 0, 0)
p4 = gmsh.model.occ.addPoint(r_outer, 0, 0)
l2 = gmsh.model.occ.addLine(p3,p4,2)
gmsh.model.occ.synchronize()
# Boundary Tags
gmsh.model.addPhysicalGroup(0, [p1], 1) # Innest boundary
gmsh.model.addPhysicalGroup(0, [p4], 2) # Outest boundary
gmsh.model.addPhysicalGroup(0, [p2,p3], 0) # Outest boundary
# Line Tags
gmsh.model.addPhysicalGroup(1, [l1], tag=1) # Inner
gmsh.model.addPhysicalGroup(1, [l2], tag=2) # Outer
lc = 0.005 # 0.01
gmsh.model.occ.synchronize()
gmsh.option.setNumber("Mesh.MeshSizeMax", lc)
gmsh.model.mesh.generate(1)
# gmsh.fltk.run()
gmsh.write("mesh.msh")
# mesh, subdomains, facet_tags = gmshio.model_to_mesh(gmsh.model, mesh_comm, model_rank, gdim=gdim)
gmsh.clear()
gmsh.finalize()
MPI.COMM_WORLD.barrier()
import meshio
def create_mesh(mesh, cell_type, prune_z=False):
cells = mesh.get_cells_type(cell_type)
cell_data = mesh.get_cell_data("gmsh:physical", cell_type)
points = mesh.points[:,:2] if prune_z else mesh.points
out_mesh = meshio.Mesh(points=points, cells={cell_type: cells}, cell_data={"name_to_read":[cell_data]})
return out_mesh
if MPI.COMM_WORLD.rank == 0:
# Read in mesh
msh = meshio.read("mesh.msh")
# Create and save one file for the mesh, and one file for the facets
line_mesh = create_mesh(msh, "line", prune_z=True)
vertex_mesh = create_mesh(msh, "vertex", prune_z=True)
meshio.write("mesh.xdmf", line_mesh)
meshio.write("mt.xdmf", vertex_mesh)
from dolfinx.io import XDMFFile
with XDMFFile(MPI.COMM_WORLD, "mesh.xdmf", "r") as xdmf:
mesh = xdmf.read_mesh(name="Grid")
ct = xdmf.read_meshtags(mesh, name="Grid")
mesh.topology.create_connectivity(mesh.topology.dim, mesh.topology.dim-1)
with XDMFFile(MPI.COMM_WORLD, "mt.xdmf", "r") as xdmf:
ft = xdmf.read_meshtags(mesh, name="Grid")
outputs;
File "MWE_mesh.py", line 70, in <module>
ft = xdmf.read_meshtags(mesh, name="Grid")
File "/home/ee331/Dev/Venvs/v060/lib/python3.8/dist-packages/dolfinx/io/utils.py", line 177, in read_meshtags
return super().read_meshtags(mesh, name, xpath)
RuntimeError: Unrecognised cell type.
It looks like I need to implement vertex tags and line tags using;
import numpy as np
def on_boundary(x):
return np.isclose(x[0]), 0.2)
boundary_dofs = fem.locate_dofs_geometrical(V, on_boundary)
or something like that.