Gmsh 4.4.1 in FEniCS? Meshio

Hi Kart,

I don’t identify the error message. But I suggest you to uninstall meshio and h5py again and try the following commands:

> pip3 install meshio --user
#Install h5py using your local version of HDF5 with:
> pip3 install --no-binary=h5py h5py --user

Also, about your request, you can replicate the following example and apply it to your specific case so you may read GMSH meshes correctly:

GMSH 4.4.1 code (2 Dimensional mesh):

Point(6) = {0, 0, 0, 1};
Point(7) = {2, 0, 0, 1};
Point(8) = {0, 2, 0, 1};
Point(9) = {2, 2, 0, 1};
Line(10) = {6, 7};               
Line(20) = {7, 9};           
Line(30) = {9, 8};       
Line(40) = {8, 6};       
Line Loop(1) = {10, 20, 30, 40};
//+
Plane Surface(1) = {1};
Physical Surface(0) = {1};
//+
Physical Curve(1) = {40};
Physical Curve(2) = {20};
Physical Curve(3) = {30};
Physical Curve(4) = {10};

Simple Poisson test problem:

import meshio
from dolfin import Mesh, XDMFFile, File, MeshValueCollection, cpp, Measure,\
                   DirichletBC, FunctionSpace, Constant, TrialFunction, \
                   TestFunction, dot, grad, dx, Function, solve

msh = meshio.read("./Square.msh")
Wri_path = './Dolfin_mesh_functions/'
meshio.write(Wri_path+"mesh.xdmf",
             meshio.Mesh(points=msh.points,
                         cells={"triangle": msh.cells["triangle"]}))

meshio.write(Wri_path+"mf.xdmf",
             meshio.Mesh(points=msh.points,
                         cells={"line": msh.cells["line"]},
                         cell_data={"line": {"name_to_read": msh.cell_data["line"]["gmsh:physical"]}}))

mesh = Mesh()
with XDMFFile(Wri_path+"mesh.xdmf") as infile:
    infile.read(mesh)
File(Wri_path+"Dolfin_circle_mesh.pvd").write(mesh)

mvc = MeshValueCollection("size_t", mesh, 1)
with XDMFFile(Wri_path+"mf.xdmf") as infile:
    infile.read(mvc, "name_to_read")
mf = cpp.mesh.MeshFunctionSizet(mesh, mvc)
File(Wri_path+"Dolfin_circle_facets.pvd").write(mf)

V = FunctionSpace(mesh, 'P', 1)

# Define boundary conditions base on GMSH mesh marks [Physical Curves: 1, 2, 3, 4]
bc1 = DirichletBC(V, Constant(0.0), mf, 1)
bc2 = DirichletBC(V, Constant(10.0), mf, 2)
bc3 = DirichletBC(V, Constant(6.0), mf, 3)
bc4 = DirichletBC(V, Constant(3.0), mf, 4)

bc = [bc1, bc2, bc3, bc4]

# Define variational problem
u = TrialFunction(V)
v = TestFunction(V)
f = Constant(-15.0)
a = dot(grad(u), grad(v))*dx
L = f*v*dx

# Compute solution
u = Function(V)
solve(a == L, u, bc)
File("Solution.pvd").write(u)

I hope you find it useful.
Best regards,

Santiago

4 Likes