nschloe / meshio

:spider_web: input/output for many mesh formats
MIT License
1.96k stars 402 forks source link

Converting msh to vtk #847

Open Tsunyshka opened 4 years ago

Tsunyshka commented 4 years ago

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 commented 4 years ago

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

nschloe commented 4 years ago

It should work either way. Reopening.

Tsunyshka commented 4 years ago

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

Tsunyshka commented 4 years ago

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
gdmcbain commented 4 years ago

Try

meshio.write(out_file, mesh)
nschloe commented 4 years ago

@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.

keileg commented 4 years ago

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 commented 4 years ago

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

nschloe commented 4 years ago

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.

keileg commented 4 years ago

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

nschloe commented 4 years ago

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.

keileg commented 4 years ago

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

AshfaqueSalmantk commented 1 year ago

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