meshio icon indicating copy to clipboard operation
meshio copied to clipboard

Converting msh to vtk

Open Tsunyshka opened this issue 5 years ago • 13 comments

Hi! I am trying to convert .msh (gmsh ascii) to .vtk file format with the simple comand:

meshio-convert input.msh output.vtk

But i getting strange result in my output file... What should i do to fix this?

Attach input and output files mesh.zip

Tsunyshka avatar Jun 18 '20 13:06 Tsunyshka

fixed it with --output-format vtk --ascii

Tsunyshka avatar Jun 18 '20 16:06 Tsunyshka

It should work either way. Reopening.

nschloe avatar Jun 18 '20 19:06 nschloe

Hi! Is it possible to use meshio-convert in a .py script?

Tsunyshka avatar Jun 21 '20 20:06 Tsunyshka

Hi! Is it possible to use meshio-convert in a .py script?

I’m trying to use smth like this, but it actually doesn’t work...

import meshio 

in_file = "/path/to/test_mesh.msh"
out_file = "/path/to/test_mesh.ply"
mesh = meshio.read(in_file, file_format="msh")  # works
mesh.write(out_file, file_format="ply")  # error

Tsunyshka avatar Jun 21 '20 20:06 Tsunyshka

Try

meshio.write(out_file, mesh)

gdmcbain avatar Jun 21 '20 20:06 gdmcbain

@keileg Do you have an idea how to fix this? I'm getting

AssertionError: Incompatible cell data. 157 cell blocks, but 'gmsh:physical' has 16 blocks.

trying to read OP's input msh.

nschloe avatar Oct 09 '20 08:10 nschloe

I think you need to store data on which CellBlock 'gmsh:physical' belongs to; right now I think there is a (tacit) assumption that length of 'gmsh:physical' equals the number of CellBlocks. I actually thought that gmsh only generates cells for objects decleared physical, but that may be a wrong or outdated assumption on my part.

keileg avatar Oct 09 '20 08:10 keileg

I don't know if the best is to move 'gmsh:physical' to Mesh.cell_sets?

keileg avatar Oct 09 '20 09:10 keileg

I actually thought that gmsh only generates cells for objects decleared physical, but that may be a wrong or outdated assumption on my part.

@keileg I thought so too, but working with the Gmsh API it seems that this isn't the case. The data isn't really set data either. (This would be a list of indices into the points or cells array.) I would expect cell_data["gmsh:physical"] to list None for whenever a cell block has no associated data, such that len(cells) == len(datum) for all cell_data.

nschloe avatar Oct 09 '20 13:10 nschloe

I agree, but would it not break the idea that cell_data are numpy arrays with one item per cell?

keileg avatar Oct 09 '20 14:10 keileg

Well, if there is no data for a particular cell type, we have to do something. Setting it to None makes pretty clear what's going on I think.

nschloe avatar Oct 26 '20 11:10 nschloe

As long as it does not violate the assumptions in read/write functions, I think None is a good option.

keileg avatar Nov 02 '20 20:11 keileg

If .msh has two different regions, whether converting to the vtu format keeps or does not keep the tag name of the regions?

AshfaqueSalmantk avatar Feb 24 '23 15:02 AshfaqueSalmantk