I wrote some codes to create a model with gmsh for FEniCSx to read, and it works fine for tetrahedron mesh, but once the mesh is wedge, FEnICSx doesn’t read it.
Below is the simplified code. If you set recombine=False, it reads fine.
import gmsh
from dolfinx.io import gmshio
gmsh.initialize()
gmsh.clear()
gmsh.model.add("SquareExtrusion")
gmsh.model.occ.addRectangle(0,0,0,1,1,tag=1)
gmsh.model.occ.extrude([(2,1)],0,0,1,[1,1],recombine=True)
gmsh.model.occ.synchronize()
gmsh.model.addPhysicalGroup(3,[1],1,'Box') # ID No1 in 3D(Volume)
gmsh.model.mesh.generate(3)
gmsh.write('./SquareExtrusion.msh')
# gmsh.fltk.run()
gmsh.finalize()
msh, cell, facet_tags=gmshio.read_from_msh('./SquareExtrusion.msh',MPI.COMM_WORLD,0)
Also, the error is as shown below.
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
Cell In[3], line 19
16 # gmsh.fltk.run()
17 gmsh.finalize()
---> 19 msh, cell, facet_tags=gmshio.read_from_msh('./SquareExtrusion.msh',MPI.COMM_WORLD,0)
File /opt/homebrew/Caskroom/miniconda/base/envs/try10/lib/python3.12/site-packages/dolfinx/io/gmshio.py:373, in read_from_msh(filename, comm, rank, gdim, partitioner)
371 gmsh.model.add("Mesh from file")
372 gmsh.merge(filename)
--> 373 msh = model_to_mesh(gmsh.model, comm, rank, gdim=gdim, partitioner=partitioner)
374 gmsh.finalize()
375 return msh
File /opt/homebrew/Caskroom/miniconda/base/envs/try10/lib/python3.12/site-packages/dolfinx/io/gmshio.py:290, in model_to_mesh(model, comm, rank, gdim, partitioner, dtype)
287 facet_values = np.empty((0,), dtype=np.int32)
289 # Create distributed mesh
--> 290 ufl_domain = ufl_mesh(cell_id, gdim, dtype=dtype)
291 gmsh_cell_perm = cell_perm_array(_cpp.mesh.to_type(str(ufl_domain.ufl_cell())), num_nodes)
292 cells = cells[:, gmsh_cell_perm].copy()
File /opt/homebrew/Caskroom/miniconda/base/envs/try10/lib/python3.12/site-packages/dolfinx/io/gmshio.py:74, in ufl_mesh(gmsh_cell, gdim, dtype)
72 except KeyError as e:
73 print(f"Unknown cell type {gmsh_cell}.")
---> 74 raise e
75 cell = ufl.Cell(shape)
76 element = basix.ufl.element(
77 basix.ElementFamily.P,
78 cell.cellname(),
(...)
82 dtype=dtype, # type: ignore[arg-type]
83 )
File /opt/homebrew/Caskroom/miniconda/base/envs/try10/lib/python3.12/site-packages/dolfinx/io/gmshio.py:71, in ufl_mesh(gmsh_cell, gdim, dtype)
57 """Create a UFL mesh from a Gmsh cell identifier and geometric dimension.
58
59 See https://gmsh.info//doc/texinfo/gmsh.html#MSH-file-format.
(...)
68
69 """
70 try:
---> 71 shape, degree = _gmsh_to_cells[gmsh_cell]
72 except KeyError as e:
73 print(f"Unknown cell type {gmsh_cell}.")
KeyError: np.int32(6)
I am still using FEnICSx=0.8.0 for this compatibility reason, and I hope someone in the community would guide me to create and read wedge mesh. Thank you in advance.