Error and Segfault reading vtk meshes

Submitted by tdl on Mon, 04/22/2013 - 11:43

Dear All,
I still have some problems when I ask LIGGGHTS to read meshes in VTK format.
My situation is the following:

1) I am using the latest LIGGGHTS, v. 2.3.2

2) I create the mesh in STL format (using OpenSCAD)

3) the meshes are converted in VTK, legacy ascii "unstructured grid" format
using gmsh, as suggested by another helpful forum user, with the command:
"gmsh -2 file.stl -o file.vtk".
I am attaching here the two mesh files for reference. (the VTK meshes are
"correct", in the sense that I can open the files with paraview and they appear
as expected)

4) I try to load the meshes using:
fix rotor all mesh/surface/stress file asymm_rect_cw.vtk type 1 verbose yes

At this point I had this sequence of errors:

A) at first, LIGGGHTS exited with these two lines:

"Note: Skipping empty line in VTK mesh file
ERROR: Expecting ASCII VTK mesh file, cannot continue (input_mesh_tri.cpp:171)"

I found out that this error is generated for this reason:
most vtk files have the first line starting with "#".
But such line is interpreted as an empty line, and skipped.
For this reason, line n.3 does not match with the expected
text: "ASCII", and LIGGGHTS exits.

This was solved by removing the "#" character from the input vtk file,
although I think this should be handled by LIGGGHTS.

B) After this modification, I got the second error:

"ERROR: Expecting ASCII VTK unstructured grid mesh file, cannot continue (input_mesh_tri.cpp:178)"

This turns out to be caused by this line in the cpp file:

if(strcmp(arg[0],"DATASET UNSTRUCTURED_GRID"))

In fact, arg[0] is read only as "DATASET", since there is a space before
"UNSTRUCTURED_GRID".
For this reason, whatever file is considered incorrect, and skipped with an error.

I tried to modify the cpp in this way:

if(strcmp(arg[0],"DATASET")&&strcmp(arg[1]," UNSTRUCTURED_GRID"))

And this time the error disappears.

C) However, now LIGGGHTS gives a segmentation fault, while reading
the file. The point is probably when it gets to read the "CELLS" section.

These are my findings, can anybody comment on this?
Am I doing something wrong (especially with the vtk format) ?
Thank you,
Alessandro

AttachmentSize
Binary Data Example meshes in stl and vtk format1.64 KB

AGl | Mon, 04/22/2013 - 16:06

Why do you want to import VTK-file, if STL-files are supported as well [1]?
You have definitely some problems with the mesh. I was trying to load your stl-file:

Mesh cad: element id 19 (line 135) has 6 neighs, but only 5 expected
ERROR: Mesh cad: elements 0 and 2 (lines 2 and 16) are duplicate
ERROR on proc 0: Fix mesh: Bad mesh, cannot continue. You can try re-running with 'heal auto_remove_duplicates' (/home/liggghts/LIGGGHTS-PUBLIC/src/surface_mesh_I.h:457)

[1] https://github.com/CFDEMproject/LIGGGHTS-PUBLIC/blob/master/examples/LIG...

tdl | Mon, 04/22/2013 - 16:30

Hi, and thanks for your input.

1) I would like to use vtk files because you can output more informations
(see dump vtk vs dump stl).
Also, it would simplify workflow afterwards (paraview likes less stl files).

2) All stl files have duplicate vertices due to the way faces are written
in the file. However you can "heal" this mesh within liggghts.

Futhermore, the vtk file I was using is obtained with this specific mesh,
and it should work, so I included the original stl file needed to reproduce
the vtk.
You can find another old post where I have an "healed" stl file that works
directly with liggghts.
Apparently the original quality of the stl mesh is ininfluent: the vtk files
are correctly displayed by paraview, have the correct structure if you
personally check them, but cannot be loaded with liggghts.

Thanks,
Alessandro

AGl | Tue, 04/23/2013 - 10:32

Sorry, I do not get your point. You are asking about Input or Output? I'm also using vtk for __output__ files, but as input-files you can use STL, if it works for you.

tdl | Tue, 04/23/2013 - 13:49

Hi,
I was not sure that I could import a mesh from an STL file, and
then output the same mesh as vtk.
I had assumed that you had to output the data in the same format
you had for input.
Thanks :-)
Alessandro

ckloss's picture

ckloss | Thu, 05/02/2013 - 14:43

Hi tdl,

>> vtk DataFile Version 2.0
you're using vtk 2.0, not legacy. 2.0 is not (yet) supported by LIGGGHTS as outlined in the doc

Cheers
Christoph

tdl | Thu, 05/02/2013 - 15:00

Thanks, Christoph,
in fact I figured it out shortly afterwards.
What I am doing now is import STL files, and export
the geometry as VTK, without any problem.

However, you should check out for the whole
" if(strcmp(arg[0],"DATASET UNSTRUCTURED_GRID")) "
stuff. If I am not mistaken, this applies to legacy vtk
files too.
Otherwise, forget my comments.

Thanks,
AS

ckloss's picture

ckloss | Fri, 05/03/2013 - 10:21

>>However, you should check out for the whole
>>" if(strcmp(arg[0],"DATASET UNSTRUCTURED_GRID")) "
Why?LIGGGHTS is supporting legacy vtk only.

Christoph

mingqiu | Thu, 03/10/2016 - 17:17

It seems that I read in the vtk (unstructure_grid) in liggghts but not work, same error as above.......(vtk data set are as following)

# vtk DataFile Version 3.0
vtk output
ASCII
DATASET UNSTRUCTURED_GRID
POINTS 302844 float
-41.163631 29.584673 -82.046661
-41.164371 29.672607 -82.260803
-41.164982 29.760965 -82.475983

mingqiu wu

Arnon | Mon, 10/22/2018 - 11:59

Hi Christoph

I know this is an old thread and probably should write a new one, however my two questions are related with this one.

So far I have used STL files as surfaces and it works perfectly fine. Lately, I have been trying to use VTK files using the same: fix mesh/surface/stress.
In the LIGGGHTS documentation it is said:

"This fix allows the import of triangular surface mesh wall geometry for granular simulations from ASCII STL files or legacy ASCII VTK files"

My first question is:
Can I have solid elements or only shells are computed? If I can't use solid elements then I will keep using stl files.

Otherwise. The structure of my legacy VTK file is as explained in:

https://www.vtk.org/wp-content/uploads/2015/04/file-formats.pdf

So basically:
# vtk DataFile Version 2.0
Header
ASCII
DATASET UNSTRUCTURED_GRID
POINTS (...)

The error:

ERROR: Expecting ASCII VTK mesh file, cannot continue

However my file, in the third line, contains the keyword ASCII as required by fix mesh/surface/stress:
if(iLine == 3)
{
if(strcmp(arg[0],"ASCII"))
error->all(FLERR,"Expecting ASCII VTK mesh file, cannot continue");
continue;
}

When I removed '#' from the first line "# vtk DataFile Version 2.0", I obtain this other error:

Expecting ASCII VTK unstructured grid mesh file, cannot continue (../input_mesh_tri.cpp:216)

But again, the DATASET is UNSTRUCTURED_GRID as the fix requires:
if(iLine == 4)
{
if(strcmp(arg[0],"DATASET UNSTRUCTURED_GRID"))
error->all(FLERR,"Expecting ASCII VTK unstructured grid mesh file, cannot continue");
continue;
}

My second question is:
Does anyone have an idea of where the problem might be coming from?

Regards,
Arnón

Daniel Queteschiner | Tue, 10/30/2018 - 16:07

1) Surface meshes can only use triangles based meshes. Regions could use VTK files containing tetrahedral elements - unless I am mistaken.

2) It's been some time since I fixed this in our version of LIGGGHTS but if I remember correctly, there is an off-by-one error in the vtk reader implementation in input_mesh_tri.cpp (basically all lines involving iLine in the meshtrifile_vtk method).
Also line 215
if(strcmp(arg[0],"DATASET UNSTRUCTURED_GRID"))
needs to be changed to
if(strcmp(arg[0],"DATASET") || strcmp(arg[1],"UNSTRUCTURED_GRID"))

Arnon | Wed, 10/31/2018 - 10:14

Hi Daniel,

Thanks for the answer I will try to fix the problem with the information you have provided.

Regards,
Arnón