# mixed elements (including polyhedron) in vtu file

**URL:** https://discourse.paraview.org/t/mixed-elements-including-polyhedron-in-vtu-file/4542
**Category:** ParaView Support
**Created:** [June 8, 2020, 9:04pm UTC](https://discourse.paraview.org/t/mixed-elements-including-polyhedron-in-vtu-file/4542 "2020-06-08T21:04:18Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![tomrobin.teschner](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/t/b487fb/32.png) [@tomrobin.teschner](https://discourse.paraview.org/u/tomrobin.teschner)
#### Post date: [June 8, 2020, 9:04pm UTC](https://discourse.paraview.org/t/mixed-elements-including-polyhedron-in-vtu-file/4542/1 "2020-06-08T21:04:18Z")

</div>

I am currently trying to bridge my CFD solver with paraview and I am about to implement support for polyhedral meshes and want to explore how to write the corresponding output file.

I have used the legacy vtk file format before and it seems (?!) that polyhedral cells cannot be written in that file format (or put differently, I am not able to find any documentation on that). I was able to find some documentation on polyhedral cells using the vtu xml-based file format and got it eventually working for a single polyhedron, however, now when I want to write out a mesh (and ultimately a solution on it) consisting of vtk inbuild types (like tetrahedron, hexahedron etc.) + polhedral cells I am getting an error message that my faceoffset array is not long enough. While the error message is fairly verbose, I am not sure which should be the correct offset I should use. Here is an example output file consisiting of only a hexahedron and a polyhedron:

```
<VTKFile type="UnstructuredGrid" version="1.0" byte_order="LittleEndian" header_type="UInt64">
  <UnstructuredGrid>
    <Piece NumberOfPoints="14" NumberOfCells="2">
      <Points>
        <DataArray type="Float32" Name="Points" NumberOfComponents="3" format="ascii" RangeMin="0" RangeMax="2">
          0 0 0
          1 0 0
          1 1 0
          0 1 0
          0 0 1
          1 0 1
          1 1 1
          0 1 1
          1.5 0 0
          2 0 0.5
          2 0 1
          2 1 1
          1.5 1 0
          2 1 0.5
        </DataArray>
      </Points>
      <Cells>
        <DataArray type="Int64" Name="connectivity" format="ascii" RangeMin="0" RangeMax="13">
          0 1 2 3 4 5 6 7
          1 8 9 13 12 2 5 10 11 6
        </DataArray>
        <DataArray type="Int64" Name="offsets" format="ascii" RangeMin="8" RangeMax="18">
          8
          18
        </DataArray>
        <DataArray type="UInt8" Name="types" format="ascii" RangeMin="12" RangeMax="42">
          12
          42
        </DataArray>
        <DataArray type="Int64" Name="faces" format="ascii" RangeMin="1" RangeMax="13">
          7
          5 1 8 9 10 5
          5 2 12 13 11 6
          4 1 2 6 5
          4 9 10 11 13
          4 8 9 13 12
          4 1 8 12 2
          4 5 10 11 6
        </DataArray>
        <DataArray type="Int64" Name="faceoffsets" format="ascii" RangeMin="38" RangeMax="38">
          38
        </DataArray>
      </Cells>
    </Piece>
  </UnstructuredGrid>
</VTKFile>

```

Any help would be appreciated!

Edit: This is the exact error message I am getting in Paraview: “ERROR: In C:\bbd\ecd3383f\build\superbuild\paraview\src\VTK\IO\XML\vtkXMLUnstructuredDataReader.cxx, line 831  
vtkXMLUnstructuredGridReader (0000018446A52840): Cannot read face offsets from Cells in piece 0 because the “faceoffsets” array is not long enough.”

---

<div class="post-metadata">

### Author: ![Kenneth\_Moreland](https://discourse.paraview.org/user_avatar/discourse.paraview.org/kenneth_moreland/32/15033_2.png) [@Kenneth\_Moreland](https://discourse.paraview.org/u/Kenneth_Moreland)
#### Post date: [June 8, 2020, 9:38pm UTC](https://discourse.paraview.org/t/mixed-elements-including-polyhedron-in-vtu-file/4542/2 "2020-06-08T21:38:39Z")

</div>

The problem is that the `faceoffsets` array has to be the same size as the number of cells. That is, you have to have an entry for every cell, even those that are not polyhedron-type. For those cells that do not use faces, put a `-1` in that place in the array. So, your `faceoffsets` array should look like this:

```xml
        <DataArray type="Int64" Name="faceoffsets" format="ascii" RangeMin="-1" RangeMax="38">
          -1 38
        </DataArray>

```

---

<div class="post-metadata">

### Author: ![tomrobin.teschner](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/t/b487fb/32.png) [@tomrobin.teschner](https://discourse.paraview.org/u/tomrobin.teschner)
#### Post date: [June 11, 2020, 5:10am UTC](https://discourse.paraview.org/t/mixed-elements-including-polyhedron-in-vtu-file/4542/3 "2020-06-11T05:10:48Z")

</div>

Thanks Kenneth, that did the trick for me!
