I was trying to import a hexahedral 20 mesh(.msh-.xDMF-read) from GMSH using the tutorial Meshio. The following error occurred while using xdmf.read_mesh(name=“Grid”) : Cannot recognise cell type. Unknown value: hexahedron_2
The code is as follows:
def create_mesh(mesh, cell_type, prune_z=False):
cells = mesh.get_cells_type(cell_type)
cell_data = mesh.get_cell_data(“gmsh:geometrical”, 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
proc = MPI.COMM_WORLD.rank
if proc == 0:
# Read in mesh
msh = meshio.read(“test/model.msh”)
# Create and save one file for the mesh, and one file for the facets
triangle_mesh = create_mesh(msh, "quad8", prune_z = False)
tetra_mesh = create_mesh(msh, "hexahedron20", prune_z = False)
meshio.write("mesh.xdmf", tetra_mesh)
meshio.write("mt.xdmf", triangle_mesh)
with dolfinx.io.XDMFFile(MPI.COMM_WORLD, ‘mesh.xdmf’, ‘r’) as xdmf:
mesh = xdmf.read_mesh(name=“Grid”)
subdomains = xdmf.read_meshtags(mesh, name=“Grid”)
mesh.topology.create_connectivity(mesh.topology.dim, mesh.topology.dim-1)
with dolfinx.io.XDMFFile(MPI.COMM_WORLD, ‘mt.xdmf’, ‘r’) as xdmf:
boundaries = xdmf.read_meshtags(mesh, name=“Grid”)
I have another question, what is the difference between the higher order of Mesh in Dolfinx and the higher order of CG-2 in Fem. FunctionSpace(mesh, (“CG”, 2)). I understand that both have the same effect of adding nodes to a grid of order one.
If I import a grid of second-order cells (27 node hexahedrons), do I need to declare the “2” in (" CG “, 2) here when FunctionSpace is created? Because it’s already level 2 or is it the same as if I created FunctionSpace (” CG ", 2) with a grid of first order cells (8 node hexahedrons)?
The function space and mesh is decoupled.
This means that if you want to use a second order space, you would need to define a P2 function space.
You can also load a first order mesh and define a second order function space on the mesh.
The difference between a first and second order mesh is that a second order mesh allows for curved facets/edges, while a linear mesh as straight (bi-linear) facets/edges.
The function space is where you define the unknown quantity. It can be an arbitrary order space (Lagrange/Nedelec/Raviart-Thomas etc). It is defined on the reference element, and can be pushed forward to you mesh using the appropriate mapping: DefElement (Section mapping finite elements)
This mapping depends on the order of your grid, as the Jacobian is defined by the derivative of the basis functions defining your mesh.
Thank you. I now understand the difference between a grid and a cell. Now the question is, what is the relationship between the 27 nodes in the second-order hexahedroncell that I created through FunctionSpace and the 27 nodes on the grid that I imported into the mesh file (Meshio-Celltype: Hexahedron27)?
As they both are second order Lagrange spaces, their dofs will align for each cell.
Note that DOLFINx does not use the VTK ordering for vertices on higher order elements or quads/hexes, and thus the input is permuted.
The ordering is described here: dolfinx/cells.h at main · FEniCS/dolfinx · GitHub