Reading msh error

Hello everybody,

i have the following problem.
I want to load a msh-file for my mesh in FeniCS.

msh = meshio.read("meshMSH3.msh")
meshio.write("meshX.xml",msh)
mesh = Mesh("meshX.xml")

The error which occurs at meshio.write(“meshX.xml”,msh) is

raise ReadError()
meshio._exceptions.ReadError

Unfortunately i don’t know how to handle this problem.

Greetings

According to example given here, for writing to the file you should use following:

 mesh.write("foo.vtk",  # str, os.PathLike, or buffer/open file
  # file_format="vtk",  # optional if first argument is a path; inferred from extension)

or in your particular case

msh.write("meshX.xml")

Hello bmf,

thank you for your reply.
Now i have the following error

"DOLFIN XML only supports triangles and tetrahedra. "
meshio._exceptions.WriteError: DOLFIN XML only supports triangles and tetrahedra. 
Consider using XDMF instead.

I overlooked this part about reading, sorry. Is this the whole error message?
What kind of mesh is it, and which version of gmsh and meshio do you use?
Maybe you could check this discussion, it could be useful.

Hello,

the version of Gmsh ist 4.8.4.
The mesh looks like the following:

Point(1) = {2.25, 1.75, 0, 0.25};
Point(2) = {1.0, 3.0, 0, 0.25};
Point(3) = {-1.0, 1.0, 0, 0.25};
Point(4) = {4.0, -4.0, 0, 0.25};
Point(5) = {5.0, -3.0, 0, 0.25};
Point(6) = {2.0, 0.0, 0, 0.25};
Point(7) = {0.5, 0.0, 0, 0.25};
Line(1) = {2, 3};
Line(2) = {3, 4};
Line(3) = {4, 5};
Line(4) = {5, 6};
Line(5) = {6, 7};
Line(6) = {7, 1};
Line(7) = {1, 2};
Line Loop(8) = {1, 2, 3, 4, 5, 6, 7};
Plane Surface(9) = {8};
Physical Line("bottom") = {3};
Point(8) = {2.25, 1.75, 0, 0.25};
Line(10) = {2, 8};
Line(11) = {8, 7};
Line Loop(12) = {1, 2, 3, 4, 5, -11, -10};
Plane Surface(13) = {12};
Physical Line("bottom", 1) += {3};
Physical Line("top", 14) = {1};
Physical Line("left", 15) = {2};
Physical Line("left", 15) += {2};
Physical Line("right", 16) = {4, 6, 5, 11, 10};
Line Loop(17) = {6};
Plane Surface(18) = {17};
Physical Line("inside", 19) = {6};
Physical Line(20) = {6};
Plane Surface(21) = {12};
Show "*";
Hide {
Line{7};
Surface{9,13,18,21};
}

Plane Surface(22) = {12};

I am sorry. Don´t know if i opened the file correctly for only seeing the values.

I suggest taking the error message literally. From the message it might be that your mesh contains quadrilaterial elements, which is not really supported in DOLFIN (use the new DOLFIN-X instead).

In any case, the xml format is deprecated. As the error message suggests, use xdmf instead.

Hello dparsons,

thank you for your reply.
Ok I tried to use xdmf by following this

        msh = meshio.read("meshMSH3.msh")
        pdb.set_trace()

        meshio.write("mesh.xdmf", meshio.Mesh(points=msh.points, cells={"tetra": msh.cells["tetra"]}))
        pdb.set_trace()
        meshio.write("mf.xdmf", meshio.Mesh(points=msh.points, cells={"triangle": msh.cells["triangle"]},
                                            cell_data={"triangle": {"name_to_read": msh.cell_data["triangle"]["gmsh:physical"]}}))
        pdb.set_trace()
        meshio.write("cf.xdmf", meshio.Mesh(
           points=msh.points, cells={"tetra": msh.cells["tetra"]},
           cell_data={"tetra": {"name_to_read":
                                   msh.cell_data["tetra"]["gmsh:physical"]}}))

I get the following error:

  File "MA_latest6.py", line 222, in solver
    meshio.write("mesh.xdmf", meshio.Mesh(points=msh.points, cells={"tetra": msh.cells["tetra"]}))
TypeError: list indices must be integers or slices, not str

Also

meshio-convert meshXMLX.xml meshXDMF.xdmf

fails. I have installed meshio, but meshio-convert is not known.

[edit: meshio.write("mesh.xdmf") is failing. Dokken’s link may help with that]

If you’re using a Debian or Ubuntu system, then meshio-convert is provided by the meshio-tools package. In future releases it will be Recommended by the python3-meshio package so might get installed automatically depending on the system’s configuration for recommended packages. But at the moment it needs to be installed independently.

But I’d expect meshio-convert would give the same error. It’s just a thin wrapper script for the meshio python module.

@newbyJulia Have you had a look at: Accessing and marking imported boundaries - #8 by dokken