meshio
meshio copied to clipboard
Wrong 2D ansys mesh from 2D vtk mesh
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.
- When I try to open it using Ansys Fluent (with the option
2d
checked), I get the following error:
Error: rect2d.msh file has wrong dimensions(3)
- Using the
3d
option in Ansys Fluent, I get the following error:
Can't read quadrilateral cells into this solver
Reading cells: failed while reading section 12.
Clearing partially read grid.
Error: Read aborted due to critical error.
The output file (.msh
file) attached here:
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.
@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
@MuellerSeb is the master of RECTILINEAR_GRID
s.
Sorry, I have totally missed this Issue. Quite busy ATM. Maybe I can have a look at this later.
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.
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
@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")
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