Problem in generating a vtk file with UNSTRUCTURED_GRID and reading it in Paraview

I have this .vtk file that I have created for a single quadratic hexahedron element (cube):

vtk DataFile Version 3.0

File generated from DClib
ASCII

DATASET UNSTRUCTURED_GRID
POINTS 20 float
0 0 0
1 0 0
1 1 0
0 1 0
0 0 1
1 0 1
1 1 1
0 1 1
0.5 0 0
1 0.5 0
0.5 1 0
0 0.5 0
0 0 0.5
1 0 0.5
1 1 0.5
0 1 0.5
0.5 0 1
1 0.5 1
0.5 1 1
0 0.5 1
CELLS 1 20
20 0 1 2 3 4 5 6 7 8 9 10 11 16 17 18 19 12 13 14 15
CELL_TYPES 1
25

When I open It in Paraview the clube is missing a side. What I’am missing here?

It seems to be correct when written as follows:

# vtk DataFile Version 5.1
vtk output
ASCII
DATASET UNSTRUCTURED_GRID
POINTS 20 float
0 0 0
1 0 0
1 1 0
0 1 0
0 0 1
1 0 1
1 1 1
0 1 1
0.5 0 0
1 0.5 0
0.5 1 0
0 0.5 0
0.5 0 1
1 0.5 1
0.5 1 1
0 0.5 1
0 0 0.5
1 0 0.5
1 1 0.5
0 1 0.5
CELLS 2 20
OFFSETS vtktypeint64
0 20
CONNECTIVITY vtktypeint64
0 1 2 3 4 5 6 7 8
9 10 11 12 13 14 15 16 17
18 19
CELL_TYPES 1
25

1 Like

Kyoshimi,

indeed it works. But why is necessary create two cells? As far as I know the documentation dont mention it for te hexahedron.

EDIT:

solved here:

Please have a look at https://kitware.github.io/vtk-examples/site/Python/GeometricObjects/LinearCellDemo

You only need 8 points:

# vtk DataFile Version 5.1
vtk output
ASCII
DATASET UNSTRUCTURED_GRID
POINTS 8 float
0 0 0 1 0 0 0 1 0 
1 1 0 0 0 1 1 0 1 
0 1 1 1 1 1 
CELLS 2 8
OFFSETS vtktypeint64
0 8 
CONNECTIVITY vtktypeint64
0 1 2 3 4 5 6 7 
CELL_TYPES 1
11

If you want to write out the unstructured grid, just drop in these lines before the return ug line for each cell type:

    ug_writer = vtk.vtkUnstructuredGridWriter()
    ug_writer.SetInputData(ug)
    ug_writer.SetFileName('x.vtk')
    ug_writer.SetFileTypeToASCII()
    ug_writer.Write()