Xmlunstructuredgridwriter issue with time.

I have used the multi-time step feature successfully before in a python script, now I am trying to do something similar with c++.

I tried it several ways, but something weird is happening that’s causes paraview to choke on the file when I try to change the step. When I write each grid to a separate file it worked fine.

The approach I used in python was to use the vtkappendfilter to add a grid from a reader write the next time step, and then remove the appended grid, (except for the last step or else you get an error about 0 connections but 1 required.

I tried doing this similar approach as well as setting the grid via shallowcopy and deepcopy.

It writes the grids fine and loads but breaks when changing the time step in paraview.

Is there a better example out there or approach?

I will post some code when I am back at a desk computer.

here is how I am doing things,

  std::map<double, std::string> filemap; // populated with time and filepaths

  vtkSmartPointer<vtkXMLUnstructuredGridWriter>
    writer = vtkSmartPointer<vtkXMLUnstructuredGridWriter>::New();
  vtkSmartPointer<vtkUnstructuredGrid>
    grid_adapter = vtkSmartPointer<vtkUnstructuredGrid>::New();

  int nfiles = 31;
 
  writer->SetFileName("test.vtu");
  writer->SetNumberOfTimeSteps(filemap.size());
  writer->SetInputData(grid_adapter);
  writer->Start();
  int count = 0;
  for(auto file :: filemap) {
    //                  time idx               input file path string
    std::cout << file.first << " " << file.second << "\n";
    char *szBuffer = new char[file.second.size()+1];
    ReadFileTest(szBuffer, TRUE, FALSE, grid_adapter);
    strcpy(szBuffer, file.second.c_str());
    writer->WriteNextTime(count);
    delete[] szBuffer;
    count += 1;
  }

the main part of ReadFileTest()

       vtkSmartPointer<vtkUnstructuredGrid>
          grid = vtkSmartPointer<vtkUnstructuredGrid>::New();
        grid->SetPoints(points);
        grid->SetCells(celltypes, cells);
        for (int k = 0; k < pt_data_arrays.size(); ++k)
        {
          grid->GetPointData()->AddArray(pt_data_arrays.at(k));
        }
        grid->GetCellData()->AddArray(zone_label);
        // grid->BuildLinks(); // this doesn't change anything.
        grid_adapter->ShallowCopy(grid); // does the same for either DeepCopy or ShallowCopy

trying to do more than load the initial file in Paraview causes a segfault, here is the truncated error log

(  24.769s) [paraview        ]vtkUnstructuredGridGeom:1200   ERR| vtkUnstructuredGridGeometryFilter (0xabe69b0): Cell type UnknownClass(49) is not a 3D cell.
...
(  24.771s) [paraview        ]vtkHigherOrderWedge.cxx:1240   ERR| vtkBezierWedge (0xbe7b1b0): The degrees are not correctly set in the input file.
...
(  24.772s) [paraview        ]vtkUnstructuredGridGeom:1200   ERR| vtkUnstructuredGridGeometryFilter (0xabe69b0): Cell type UnknownClass(164) is not a 3D cell.
...
(  24.777s) [paraview        ]vtkUnstructuredGridGeom:1200   ERR| vtkUnstructuredGridGeometryFilter (0xabe69b0): Cell type vtkHigherOrderWedge(65) is not a 3D cell.
(  24.777s) [paraview        ]vtkHigherOrderWedge.cxx:1240   ERR| vtkBezierWedge (0xbe7b1b0): The degrees are not correctly set in the input file.
(  24.777s) [paraview        ]vtkHigherOrderWedge.cxx:1262   ERR| vtkBezierWedge (0xbe7b1b0): The degrees might be direction dependents, and should be set before GetOrder is called. numPts is 8 and Order[3] 6
...
(  24.835s) [paraview        ]vtkUnstructuredGridGeom:1200   ERR| vtkUnstructuredGridGeometryFilter (0xabe69b0): Cell type UnknownClass(120) is not a 3D cell.

Loguru caught a signal: SIGSEGV
Stack trace:
71            0x407a7d /home/krs/tools/ParaView-5.8.0-MPI-Linux-Python3.7-64bit/bin/paraview() [0x407a7d]
70      0x7fcfc8388b97 __libc_start_main + 231
69            0x40774d /home/krs/tools/ParaView-5.8.0-MPI-Linux-Python3.7-64bit/bin/paraview() [0x40774d]
68      0x7fcfc5eed0b4 QCoreApplication::exec() + 132
67      0x7fcfc5ee44aa QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) + 234
66      0x7fcf96559e96 /media/store/krs/tools/ParaView-5.8.0-MPI-Linux-Python3.7-64bit/plugins/platforms/../../lib/libQt5XcbQpa.so.5(+0xb1e96) [0x7fcf96559e96]
65      0x7fcfc631862b QWindowSystemInterface::sendWindowSystemEvents(QFlags<QEventLoop::ProcessEventsFlag>) + 187
64      0x7fcfc633cc15 QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent*) + 261
63      0x7fcfc633b1a3 QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent*) + 1779
62      0x7fcfc5ee5c08 QCoreApplication::notifyInternal2(QObject*, QEvent*) + 264
61      0x7fcfc79dff01 QApplication::notify(QObject*, QEvent*) + 577
60      0x7fcfc79d8c8c QApplicationPrivate::notify_helper(QObject*, QEvent*) + 156
59      0x7fcfc7a31cd3 /media/store/krs/tools/ParaView-5.8.0-MPI-Linux-Python3.7-64bit/bin/../lib/libQt5Widgets.so.5(+0x1b8cd3) [0x7fcfc7a31cd3]
58      0x7fcfc7a2f42d /media/store/krs/tools/ParaView-5.8.0-MPI-Linux-Python3.7-64bit/bin/../lib/libQt5Widgets.so.5(+0x1b642d) [0x7fcfc7a2f42d]
57      0x7fcfc79df4ed QApplicationPrivate::sendMouseEvent(QWidget*, QMouseEvent*, QWidget*, QWidget*, QWidget**, QPointer<QWidget>&, bool) + 461
56      0x7fcfc5ee5c08 QCoreApplication::notifyInternal2(QObject*, QEvent*) + 264
55      0x7fcfc79e0c78 QApplication::notify(QObject*, QEvent*) + 4024
54      0x7fcfc79d8c8c QApplicationPrivate::notify_helper(QObject*, QEvent*) + 156
53      0x7fcfc7a159d8 QWidget::event(QEvent*) + 488
52      0x7fcfc7acc4c5 QAbstractButton::mouseReleaseEvent(QMouseEvent*) + 213
51      0x7fcfc7acc312 /media/store/krs/tools/ParaView-5.8.0-MPI-Linux-Python3.7-64bit/bin/../lib/libQt5Widgets.so.5(+0x253312) [0x7fcfc7acc312]
50      0x7fcfc7acb014 /media/store/krs/tools/ParaView-5.8.0-MPI-Linux-Python3.7-64bit/bin/../lib/libQt5Widgets.so.5(+0x252014) [0x7fcfc7acb014]
49      0x7fcfc7acae02 QAbstractButton::clicked(bool) + 50
48      0x7fcfc5f11c47 QMetaObject::activate(QObject*, int, int, void**) + 1511
47      0x7fcfc7286c93 pqPropertiesPanel::apply() + 627
46      0x7fcfc5f11c47 QMetaObject::activate(QObject*, int, int, void**) + 1511
45      0x7fcfc7f7bc1c pqApplyBehavior::applied(pqPropertiesPanel*) + 892
44      0x7fcfbaee082f vtkSMViewProxy::Update() + 287
43      0x7fcfc51d7b35 vtkPVSessionBase::ExecuteStream(unsigned int, vtkClientServerStream const&, bool) + 53
42      0x7fcfc51d8a7b vtkPVSessionCore::ExecuteStream(unsigned int, vtkClientServerStream const&, bool) + 59
41      0x7fcfc51d8c45 vtkPVSessionCore::ExecuteStreamInternal(vtkClientServerStream const&, bool) + 245
40      0x7fcfc4757dcd vtkClientServerInterpreter::ProcessStream(vtkClientServerStream const&) + 29
39      0x7fcfc4757a9e vtkClientServerInterpreter::ProcessOneMessage(vtkClientServerStream const&, int) + 1198
38      0x7fcfc4756fda vtkClientServerInterpreter::ProcessCommandInvoke(vtkClientServerStream const&, int) + 330
37      0x7fcfc4756ce5 vtkClientServerInterpreter::CallCommandFunction(char const*, vtkObjectBase*, char const*, vtkClientServerStream const&, vtkClientServerStream&) + 325
36      0x7fcfbc2fbec6 vtkPVRenderViewCommand(vtkClientServerInterpreter*, vtkObjectBase*, char const*, vtkClientServerStream const&, vtkClientServerStream&, void*) + 17558
35      0x7fcfbae5898c vtkPVRenderView::Update() + 140
34      0x7fcfbae6cc2b vtkPVView::Update() + 251
33      0x7fcfbae6b092 vtkPVView::CallProcessViewRequest(vtkInformationRequestKey*, vtkInformation*, vtkInformationVector*) + 242
32      0x7fcfbadd4698 vtkGeometryRepresentationWithFaces::ProcessViewRequest(vtkInformationRequestKey*, vtkInformation*, vtkInformation*) + 24
31      0x7fcfbadd2629 vtkGeometryRepresentation::ProcessViewRequest(vtkInformationRequestKey*, vtkInformation*, vtkInformation*) + 25
30      0x7fcfbae1e1a1 vtkPVDataRepresentation::ProcessViewRequest(vtkInformationRequestKey*, vtkInformation*, vtkInformation*) + 225
29      0x7fcfc0880f0f vtkStreamingDemandDrivenPipeline::Update(int, vtkInformationVector*) + 255
28      0x7fcfc0841f8a vtkDemandDrivenPipeline::UpdateData(int) + 138
27      0x7fcfc087f9b1 vtkStreamingDemandDrivenPipeline::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 801
26      0x7fcfc0843457 vtkDemandDrivenPipeline::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 1447
25      0x7fcfc083dab1 vtkCompositeDataPipeline::ExecuteData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 257
24      0x7fcfc08408b7 vtkDemandDrivenPipeline::ExecuteData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 55
23      0x7fcfc0846320 vtkExecutive::CallAlgorithm(vtkInformation*, int, vtkInformationVector**, vtkInformationVector*) + 64
22      0x7fcfbadd2c1e vtkGeometryRepresentation::RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 110
21      0x7fcfc0880f0f vtkStreamingDemandDrivenPipeline::Update(int, vtkInformationVector*) + 255
20      0x7fcfc0841f8a vtkDemandDrivenPipeline::UpdateData(int) + 138
19      0x7fcfc087f9b1 vtkStreamingDemandDrivenPipeline::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 801
18      0x7fcfc0842fb6 vtkDemandDrivenPipeline::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 262
17      0x7fcfc083c82a vtkCompositeDataPipeline::ForwardUpstream(vtkInformation*) + 330
16      0x7fcfc087f9b1 vtkStreamingDemandDrivenPipeline::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 801
15      0x7fcfc0843457 vtkDemandDrivenPipeline::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 1447
14      0x7fcfc083dab1 vtkCompositeDataPipeline::ExecuteData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 257
13      0x7fcfc08408b7 vtkDemandDrivenPipeline::ExecuteData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 55
12      0x7fcfc0846320 vtkExecutive::CallAlgorithm(vtkInformation*, int, vtkInformationVector**, vtkInformationVector*) + 64
11      0x7fcfbaa2b408 vtkPVGeometryFilter::RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 296
10      0x7fcfbaa2a4df vtkPVGeometryFilter::UnstructuredGridExecute(vtkUnstructuredGridBase*, vtkPolyData*, int) + 655
9       0x7fcfc0880f0f vtkStreamingDemandDrivenPipeline::Update(int, vtkInformationVector*) + 255
8       0x7fcfc0841f8a vtkDemandDrivenPipeline::UpdateData(int) + 138
7       0x7fcfc087f9b1 vtkStreamingDemandDrivenPipeline::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 801
6       0x7fcfc0843457 vtkDemandDrivenPipeline::ProcessRequest(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 1447
5       0x7fcfc083dab1 vtkCompositeDataPipeline::ExecuteData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 257
4       0x7fcfc08408b7 vtkDemandDrivenPipeline::ExecuteData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 55
3       0x7fcfc0846320 vtkExecutive::CallAlgorithm(vtkInformation*, int, vtkInformationVector**, vtkInformationVector*) + 64
2       0x7fcfb3be4ea2 vtkUnstructuredGridGeometryFilter::RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) + 11026
1       0x7fcfc0508367 vtkUnstructuredGridCellIterator::FetchFaces() + 71
0       0x7fcfc83a5fd0 /lib/x86_64-linux-gnu/libc.so.6(+0x3efd0) [0x7fcfc83a5fd0]
(  24.836s) [paraview        ]                       :0     FATL| Signal: SIGSEGV
Segmentation fault (core dumped)

There is a difference between the options
writer->SetDataModeToBinary();
this gives an error when being read with paraview

ERROR: In /home/buildslave/dashboards/buildbot/paraview-pvbinsdash-linux-shared-release_superbuild/build/superbuild/paraview/src/VTK/IO/XMLParser/vtkXMLParser.cxx, line 379
vtkXMLDataParser (0x722a7e0): Error parsing XML in stream at line 1669, column 0, byte index 500120070: no element found

ERROR: In /home/buildslave/dashboards/buildbot/paraview-pvbinsdash-linux-shared-release_superbuild/build/superbuild/paraview/src/VTK/IO/XML/vtkXMLReader.cxx, line 510
vtkXMLUnstructuredGridReader (0x6221d50): Error parsing input file.  ReadXMLInformation aborting

writer->SetDataModeToAppended(); gives the error above