nschloe / meshio

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

Wrong 2D ansys mesh from 2D vtk mesh #529

Open s1291 opened 4 years ago

s1291 commented 4 years ago

I am trying to convert this basic 2D vtk mesh to ansys using meshio 3.2.14. the file rect2d.vtk:

# vtk DataFile Version 3.0
vtk output
ASCII
DATASET RECTILINEAR_GRID
DIMENSIONS 3 4 1
X_COORDINATES 3 float
0 2 4
Y_COORDINATES 4 float
1 2 3 4
Z_COORDINATES 1 float
0
CELL_DATA 6
FIELD FieldData 1
cellscalar 1 6 float
1.1 7.5 1.2 1.5 2.6 8.1
POINT_DATA 12

Because if the vtk mesh is 2D, meshio pads a zero third component to the mesh. To convert it to ansys format:

meshio-convert --input-format vtk-ascii --output-format ansys-ascii rect2d.vtk rect2d.msh

the result is a 3d mesh.

The output file (.msh file) attached here:

gdmcbain commented 4 years ago

Does the --prune-z-0 flag help?

https://github.com/nschloe/meshio/blob/058346fe2124e1ded1c99b55587be8f67d192b83/meshio/_cli.py#L89-L94

The output file looks better, though I haven't attempted to open it in Ansys.

s1291 commented 4 years ago

@gdmcbain Thank you for the suggestion I forgot about it. Unfortunately that didn't work too. I got the following error from Ansys Fluent:

Cell ID 0 out of declared range (1<=id<=4).
Cell ID 5 out of declared range (1<=id<=4).
Reading Cells: failed while reading section 12.

       Clearing partially read grid.

Error: Read_Grid_Section: Aborted due to critical error.
Error Object: #f
nschloe commented 4 years ago

@MuellerSeb is the master of RECTILINEAR_GRIDs.

MuellerSeb commented 4 years ago

Sorry, I have totally missed this Issue. Quite busy ATM. Maybe I can have a look at this later.

MuellerSeb commented 4 years ago

Having a second look at this, I don't think, this is a problem at the VTK side, since in VTK all grids are described by 3D points. The problem is on the ansys side, where there needs to be a check if the mesh is a flat 2D one, so it could be converted to a real 2D mesh. But even that is hard, since it is not determined by the cell types (which could be easily checked), since a mesh could contain only 2D cell-types but is representing a curved surface in space.

MuellerSeb commented 4 years ago

Oh I see, that apparently meshio stores 2D meshes explicitly with only 2D points. So I could truncate the points list in 2D and it should work.

https://github.com/nschloe/meshio/blob/d9c05ae688858b5166630874f3ec875a43b8fd37/meshio/vtk/_vtk.py#L585

Then the next question is: what about 1D meshes? This wouldn't be catched by the line above. Are they also handled separately by some routines? @nschloe

MuellerSeb commented 4 years ago

@s1291 as a workaround, you could truncate the points-dimension by hand:

import meshio
mesh = meshio.read("rect2d.vtk")
mesh.points = mesh.points[:, :2]
meshio.write("rect2d.msh", mesh, file_format="ansys-ascii")
Huangzizhou commented 3 years ago

I got a very similar error as @s1291 when using the following script to export a msh22 file to ansys.

import meshio
mesh = meshio.read("corner_2.msh")
mesh.points = mesh.points[:, :2]
meshio.write("corner_2_fluent.msh", mesh, file_format="ansys", binary=False)

The error I got from ansys fluent is

Buffering for file scan...

    3801 nodes.
Cell ID 0 out of declared range (1<=id<=2).
Cell ID 3599 out of declared range (1<=id<=2).

The msh22 mesh is attached here: corner_2.zip