Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

writing out gmsh file after reading it in #614

Open
SBFRF opened this issue Jan 3, 2020 · 4 comments
Open

writing out gmsh file after reading it in #614

SBFRF opened this issue Jan 3, 2020 · 4 comments

Comments

@SBFRF
Copy link

SBFRF commented Jan 3, 2020

I'm trying to read a mesh in, then write it. I use meshio to read the file in then i go to write it out and get the below error.

In[12]: a = mio.read('Mesh_interp_Mar2018.msh')
WARNING:root:The file contains tag data that couldn't be processed.

In[13]: a.cell_data
Out[13]: 
{'vertex': {'gmsh:physical': array([0, 0, 0, ..., 0, 0, 0]),
  'gmsh:geometrical': array([0, 0, 0, ..., 0, 0, 0])},
 'triangle': {'gmsh:physical': array([0, 0, 0, ..., 0, 0, 0]),
  'gmsh:geometrical': array([     1,      2,      3, ..., 213896, 213897, 213898])}}

In[14]: mio.write('out.msh', a)
WARNING:root:Binary Gmsh needs c_size_t (got int64). Converting.
WARNING:root:Binary Gmsh needs c_size_t (got int64). Converting.
Traceback (most recent call last):
  File "/home/spike/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3326, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-14-8540c4eefe05>", line 1, in <module>
    mio.write('out.msh', a)
  File "/home/spike/anaconda3/lib/python3.7/site-packages/meshio/_helpers.py", line 133, in write
    return writer(filename, mesh, **kwargs)
  File "/home/spike/anaconda3/lib/python3.7/site-packages/meshio/gmsh/main.py", line 109, in <lambda>
    "gmsh": lambda f, m, **kwargs: write(f, m, "4", **kwargs, binary=True),
  File "/home/spike/anaconda3/lib/python3.7/site-packages/meshio/gmsh/main.py", line 101, in write
    writer.write(filename, mesh, binary=binary)
  File "/home/spike/anaconda3/lib/python3.7/site-packages/meshio/gmsh/_gmsh41.py", line 281, in write
    write4_1(filename, mesh, binary=binary)
  File "/home/spike/anaconda3/lib/python3.7/site-packages/meshio/gmsh/_gmsh41.py", line 328, in write4_1
    _write_nodes(fh, mesh.points, mesh.cells, binary)
  File "/home/spike/anaconda3/lib/python3.7/site-packages/meshio/gmsh/_gmsh41.py", line 379, in _write_nodes
    raise WriteError("Can only deal with one cell type for now")
meshio._exceptions.WriteError: Can only deal with one cell type for now

PR #524 has the same error output, and the response suggests that the capability is not supported yet. I'm not too familiar with the different mesh types or conventions associated. Hopefully I'm not duplicating, but I used to be able to write them out so I'm thinking that something else is going on or I'm wondering if something has changed in the package (or maybe there is something else I'm missing). I've attached the mesh in a tarball.

Mesh_interp_Mar2018.msh.tar.gz

I appreciate any help!

@SBFRF
Copy link
Author

SBFRF commented Jan 7, 2020

So i've dug a little deeper, it doesn't seem like the meshio.read actually reads the files appropriately. I've written this to solve my problem, but i'm not sure if it's helpful for the library as a whole (as i don't throughly know the gmsh conventions, but thought i'd leave it here in case it is. (based on one of your old stack posts) https://stackoverflow.com/questions/41641505/read-formatted-data-from-part-of-a-file-fast-gmsh-mesh-format

####################
f = open(fname)
f.readline() # '$MeshFormat\n'
f.readline() # '2.2 0 8\n'
f.readline() # '$EndMeshFormat\n'
f.readline() # '$Nodes\n'
n_nodes = int(f.readline()) # '8\n'
nodes = np.fromfile(f,count=n_nodes*4, sep=" ").reshape((n_nodes,4))
f.readline() # '$EndNodes\n'
f.readline() # '$Elements\n'
n_elems = int(f.readline()) # '2\n'
boundary, internalTriangles = [], []
for ee in range(n_elems):
    data = f.readline().split()
    if len(data) is 6:
        # if boundary will have only
        boundary.append(np.array(data, dtype=int))
    elif len(data) is 9:
        internalTriangles.append(np.array(data, dtype=int))
assert f.readline() is '$EndElements\n', "File didn't read properly"
boundary = np.array(boundary)
internalTriangles = np.array(internalTriangles)

@nschloe
Copy link
Owner

nschloe commented May 9, 2022

So I've looked at the mesh now, trying to find out if this is still an issue. Turns out that not even Gmsh itself can read the file. Error:

Error   : Wrong node index 0
Error   : Error loading '/tmp/Mesh_interp_Mar2018.msh'
Info    : Done reading '/tmp/Mesh_interp_Mar2018.msh'

The tags of the triangles are also weird:

#   idx      type  num_tags   tag1   tag2    tag3  point_indices
    2950       2       3       0      44       0   13666    2532    2533
    2951       2       3       0      45       0   17054    2902    2903
    2952       2       3       0      46       0   31565   71067   71496
    2953       2       3       0      47       0   22182   22181    2906
    2954       2       3       0      48       0   21467   21250   41879
    2955       2       3       0      49       0   17022   34885    4330
    2956       2       3       0      50       0   22181   35162   22179
    2957       2       3       0      51       0    2901   46456    2900

The second tag ("geometrical entity") is different for every single triangle? That seems wrong.

Anyway, can't say if this is/was an actual meshio issue. If OP can shed some light on this, that'd be great. If not, I'll close this at some point.

@SBFRF
Copy link
Author

SBFRF commented May 14, 2022

@thesser1 Do you know anything more about the gmsh file for ww3 that would be helpful here?

1 similar comment
@SBFRF
Copy link
Author

SBFRF commented May 19, 2022

@thesser1 Do you know anything more about the gmsh file for ww3 that would be helpful here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants