vtkStringArray is not properly added when vtkUnstructuredGrid is outputted as PVTU file

I am trying to add a vtkStringArray to a vtkUnstructuredGrid using the AddArray method. The string array shows up in the spreadsheet view for serial vtu files, but does not appear when loading a pvtu file in ParaView.

I add a string array by building on the Polyhedron example from https://lorensen.github.io/VTKExamples/site/Cxx/GeometricObjects/Polyhedron/

The source code for adding a string array to a polyhedron and writing out to a serial vtu file is shown below:

#include <vtkCellArray.h>
#include <vtkCellData.h>
#include <vtkDataArray.h>
#include <vtkDataSetMapper.h>
#include <vtkIdList.h>
#include <vtkNamedColors.h>
#include <vtkPointData.h>
#include <vtkPoints.h>
#include <vtkPolyhedron.h>
#include <vtkSmartPointer.h>
#include <vtkStringArray.h>
#include <vtkUnstructuredGrid.h>
#include <vtkXMLUnstructuredGridWriter.h>

int main(int, char *[])
{
  // Create a Polyhedron (cube)
  vtkIdType pointIds[8] = {0, 1, 2, 3, 4, 5, 6, 7};

  vtkSmartPointer<vtkPoints> points =
    vtkSmartPointer<vtkPoints>::New();
  points->InsertNextPoint(-1.0,-1.0,-1.0);
  points->InsertNextPoint( 1.0,-1.0,-1.0);
  points->InsertNextPoint( 1.0, 1.0,-1.0);
  points->InsertNextPoint(-1.0, 1.0,-1.0);
  points->InsertNextPoint(-1.0,-1.0, 1.0);
  points->InsertNextPoint( 1.0,-1.0, 1.0);
  points->InsertNextPoint( 1.0, 1.0, 1.0);
  points->InsertNextPoint(-1.0, 1.0, 1.0);

  // Define faces according to point IDs
  vtkSmartPointer<vtkCellArray> faces =
    vtkSmartPointer<vtkCellArray>::New();
  vtkIdType face0[4] = {0, 3, 2, 1};
  vtkIdType face1[4] = {0, 4, 7, 3};
  vtkIdType face2[4] = {4, 5, 6, 7};
  vtkIdType face3[4] = {5, 1, 2, 6};
  vtkIdType face4[4] = {0, 1, 5, 4};
  vtkIdType face5[4] = {2, 3, 7, 6};

  faces->InsertNextCell(4, face0);
  faces->InsertNextCell(4, face1);
  faces->InsertNextCell(4, face2);
  faces->InsertNextCell(4, face3);
  faces->InsertNextCell(4, face4);
  faces->InsertNextCell(4, face5);

  vtkSmartPointer<vtkUnstructuredGrid> ugrid =
    vtkSmartPointer<vtkUnstructuredGrid>::New();
  ugrid->SetPoints(points);
  ugrid->InsertNextCell(VTK_POLYHEDRON, 8, pointIds,
                        6, faces->GetPointer());

  // Create string scalar
  vtkSmartPointer<vtkStringArray> string_data = 
    vtkSmartPointer<vtkStringArray>::New();

  string_data->SetName("A_String_Array");
  string_data->InsertNextValue("Hello");

  // Add string array to unstructured grid
  ugrid->GetCellData()->AddArray(string_data);

  // Here write out serial vtu
  vtkSmartPointer<vtkXMLUnstructuredGridWriter> writer =
    vtkSmartPointer<vtkXMLUnstructuredGridWriter>::New();
  writer->SetInputData(ugrid);
  writer->SetFileName("polyhedron.vtu");
  writer->SetDataModeToAscii();
  writer->Update();
  writer->Write();

For the pvtu file, I simply replace the writer in the above code with:

  vtkSmartPointer<vtkXMLPUnstructuredGridWriter> writer =
    vtkSmartPointer<vtkXMLPUnstructuredGridWriter>::New();
  writer->SetInputData(ugrid);
  writer->SetFileName("parallel_polyhedron.pvtu");
  writer->SetNumberOfPieces(1);
  writer->SetStartPiece(0);
  writer->SetEndPiece(0);
  writer->SetDataModeToAscii();
  writer->Update();
  writer->Write();

and replace the #include <vtkXMLUnstructuredGridWriter.h> to #include <vtkXMLPUnstructuredGridWriter.h> .

When loading the vtu files for both cases (“polyhedron.vtu” and “parallel_polyhedron_0.vtu”), the string value "Hello" show up in the spreadsheet view under "test_name" . However, when the pvtu file (“parallel_polyhedron.pvtu”) is loaded, the string value is blank under "test_name" in the spreadsheet view.

How can I add a string array such that its string value shows up properly in the spreadsheet view when loading the pvtu file?

Thank you,
Victor

please share your dataset.

Hi Mathieu,
The datasets are attached. Note that the string value "Hello" shows up under "A_String_Array" for the “polyhedron.vtu” and “parallel_polyhedron_0.vtu” files in the spreadsheet view (make sure to choose the cell attribute). When loading the “parallel_polyhedron.pvtu” file, the string value is blank under "A_String_Array".
Thank you,
Victorpolyhedron.vtu (1.8 KB) parallel_polyhedron_0.vtu (2.0 KB) parallel_polyhedron.pvtu (401 Bytes)

Looks like a small bug with the parallel reader. I’ve opened an issue here:
https://gitlab.kitware.com/paraview/paraview/issues/19501

Hi Matthieu,
No one seems to be interested in fixing this bug. Could you give me some guidance on how to fix this issue? Once fixed, I can submit a pull request.
Thank you,
Victor

One would need to investigate it by debugging the parallel reader. I may try to do it if I find the time.