Hi All,
I am trying to use Gmsh .msh file in FEniCS. The environment is FEniCS container with meshio 4.3.12 installed. Gmsh is 4.8.0. and not in the container.
I generated a simple model (a unit box with a cylinder hole in y direction), and defined two surface physical groups 1/2, (top/bottom surface of the box). I export the mesh to box.msh in version 2 format. I used the python codes discussed previously, in which meshio reads the msh file and generates two xdmf files. The first one, mesh.xdmf is tetra cells, which is OK. The second mf.xdmf file is triangle cells, supposedly referring to the two physical surfaces 1/2. However, in paraview mf.xdmf is all surfaces of the box and cylinder hole. mesh_from_file.get_cell_data("gmsh:physical", "triangle")
gives an array of all 0 elements. It seems the meshio failed to recognize physical groups.
If the mesh is exported as version 4 msh format, the meshio.read(box.msh) throws an error âValueError: Incompatible cell data. 33 cell blocks, but âgmsh:physicalâ has 2 blocks.â
Could anyone help? I followed this thread closely (Gmsh 4.4.1 in FEniCS? Meshio) , and also this one Meshio Changelog - pyup.io (meshio ver 4.0 change mesh.cells from dict to list tuples).
Thank you!
The geo code
// Gmsh project created on Fri Apr 09 22:46:46 2021
SetFactory("OpenCASCADE");
//+
Box(1) = {0, 0, 0, 1, 1, 1};
//+
Cylinder(2) = {0.3, 0, 0.5, 0, 1, 0, 0.1, 2*Pi};
//+
BooleanDifference{ Volume{1}; Delete; }{ Volume{2}; Delete; };
//+
Physical Surface("1", 28) = {10};
//+
Physical Surface("2", 29) = {12};
python code
import meshio
import numpy
mesh_from_file = meshio.read("box.msh")
meshio.write("mesh.xdmf", meshio.Mesh(points=mesh_from_file.points,
cells={"tetra": mesh_from_file.get_cells_type("tetra")}))
meshio.write("mf.xdmf", meshio.Mesh(points=mesh_from_file.points, cells={"triangle": mesh_from_file.get_cells_type("triangle")},
cell_data={"name_to_read": [mesh_from_file.get_cell_data("gmsh:physical", "triangle")]}))
My python code and geo codes are attached