GMSH import - Cell Block issue

Hey there.

I created a mesh with GMSH, .geo. I wanted to import this mesh to Fenics by using msh2xdmf file (msh2xdmf/msh2xdmf.py at master · floiseau/msh2xdmf · GitHub).

When the program runs this line:

msh2xdmf('malla_modo3.msh',2)

I get the error

  File "/mnt/c/fenics/msh2xdmf.py", line 28, in msh2xdmf
    export_domain(msh, dim, directory, prefix)
  File "/mnt/c/fenics/msh2xdmf.py", line 45, in export_domain
    data_array = [arr for (t, arr) in msh.cells if t == cell_type]
  File "/mnt/c/fenics/msh2xdmf.py", line 45, in <listcomp>
    data_array = [arr for (t, arr) in msh.cells if t == cell_type]
TypeError: cannot unpack non-iterable CellBlock object

This program msh2xmdf should be fine, as it works in a lot of other simulations. I’m guessing the problem is my mesh, but I checked the meshing on GMSH and it looked fine. Here is the original .geo from which I obtained .msh.

lc=0.1;
Point(1) = {0, 0, 0, lc};
Point(2) = {0.5, 0, 0, lc};
Point(3) = {0.5, 1, 0, lc};
Point(4) = {-0.5, 1, 0, lc};
Point(5) = {-0.5, 0.01, 0, lc};
Line(1) = {1, 2};
Line(2) = {2, 3};
Line(3) = {4, 4};
Line(4) = {3, 4};
Line(5) = {4, 5};
Line(6) = {5, 1};
Curve Loop(1) = {4, 5, 6, 1, 2};
Plane Surface(1) = {1};

Thanks in advance.

This seems like it is related to: test_conversion: meshio TypeError: cannot unpack non-iterable CellBlock · Issue #14 · floiseau/msh2xdmf · GitHub
Could you confirm if the suggested changes there work for you (if you modify msh2xdmf)

I believe this problem has been solved, but I can’t confirm because a new problem arose:

I’m using the following lines:

import msh2xdmf_changes
msh2xdmf_changes('malla_modo3.msh',2)

Where, simulating I obtain

TypeError: 'module' object is not callable

But, the object should be callable, it’s exactly the .msh generated by .geo, commonly used. I suspect the original problem has been solved and this might be a new one.

Thanks again, dokken.

Shouldnt this be

import msh2xdmf_changes
msh2xdmf_changes.msh2xdmf('malla_modo3.msh',2)

?

That’s for sure my mistake, but even after editing the original code with the changes, the code (msh2xdmf_changes) has several issues I don’t know how to solve. I believe I did the right changes with the information you gave me in your previous answer, but now it geets worse:

Traceback (most recent call last):
  File "/mnt/c/fenics/msh2xdmf_changes.py", line 62, in export_domain
    [
  File "/mnt/c/fenics/msh2xdmf_changes.py", line 63, in <listcomp>
    msh.cell_data["gmsh:physical"][i]
KeyError: 'gmsh:physical'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "Robin_Neumann_Edu.py", line 16, in <module>
    msh2xdmf_cambios.msh2xdmf('malla_modo3.msh',2)
  File "/mnt/c/fenics/msh2xdmf_cambios.py", line 28, in msh2xdmf
    export_domain(msh, dim, directory, prefix)
  File "/mnt/c/fenics/msh2xdmf_cambios.py", line 71, in export_domain
    raise ValueError(
ValueError:
            No physical group found for the domain.
            Define the domain physical group.
                - if dim=2, the domain is a surface
                - if dim=3, the domain is a volume

I don’t know what to do. Thanks again.

This error is quite straightforward.
You do not use Physical Volume, Physical Surface or Physical Curve in your GMSH file.
Thus you cannot use msh2xdmf, as it seems to rely on you using physical markers (which also gmsh and meshio relies on to some extent).

So the problem is on my original .geo and .msh code? Is that what I should edit?

Add

Physical Surface(1) = {1};

as shown in for instance

or
https://doc.nektar.info/userguide/5.0.0/user-guidese14.html

Yes, the problem seems to have been solved, so I believe the changes you provided with the first answer are the proper ones. I’ll mark that as a solution. Thanks.

I still face the next problem:

$Element section not found.
Error: Couldn't read file malla_modo3.msh as either of ansys, gmsh

I know this is slightly out of topic. I’d appreciate any further information on this issue. Thanks.

You need to provide the complete geo file, and the commands you used to convert it to msh, what version of Gmsh you are using etc.