Dear all,
Newbie here, I’m trying to use VTK to write results of a simulation on a structured grid. The calculations are done in parallel in distributed memory so I’m trying to write them using the vtkXMLPStructuredGridWriter.
First I had some troubles getting the pvts to contain the overall size of the grid. As shown in a couple of examples, I had to add use a programmable filter to solve the problem. I don’t fully understand why I have to use the programmable filter but it seems to be working now.
Could someone explain me why I have to put this?
Next, the real problem is that I saw that the pieces of the output are being written twice. I mean each piece is written and then the each piece is overwritten once again. I don’t know What I am doing wrong. I extracted the parts of the code where I use VTK just for the sake of showing what I am doing. You can find it at the end of this message.
Does anyone know what I am doing wrong.
pf = vtkProgrammableFilter::New();
meshGrid = vtkStructuredGrid::New();
meshPoints = vtkPoints::New();
// points are set using meshPoints->InsertNextPoint(x, y, z);
args.pf = pf;
args.local_extent[0] = brick_origin_id->at(0);
args.local_extent[1] = brick_origin_id->at(0)+nx;
args.local_extent[2] = brick_origin_id->at(1);
args.local_extent[3] = brick_origin_id->at(1)+ny;
args.local_extent[4] = brick_origin_id->at(2);
args.local_extent[5] = brick_origin_id->at(2)+nz;
pf->SetExecuteMethod(vtkParallelRegularGridDumper::executeFilter, &args);
meshGrid->SetDimensions(nx+1, ny+1, nz+1);
meshGrid->SetExtent(0, global_cells->at(0), 0, global_cells->at(1), 0, global_cells->at(2));
pf->SetInputData(meshGrid);
meshGrid->SetPoints(meshPoints);
meshPoints->Delete();
writer = vtkXMLPStructuredGridWriter::New();
vtkDoubleArray * f_temp = vtkDoubleArray::New();
f_temp->SetNumberOfComponents(9);
f_temp->SetNumberOfTuples(n_tuples);
f_temp->SetName(c_f_name);
meshGrid->GetCellData()->AddArray(f_temp);
writer->SetInputConnection(pf->GetOutputPort());
writer->SetController(contr);
writer->SetFileName((name+"_"+std::to_string(sequence++)+".pvts").c_str());
writer->UpdateWholeExtent();
writer->SetNumberOfPieces(grid->getPartWorld());
writer->SetStartPiece(grid->getPartRank());
writer->SetEndPiece(grid->getPartRank());
writer->WriteSummaryFileOn();
writer->Update();
writer->Write();
void vtkParallelRegularGridDumper::executeFilter(void* arg) {
Args* args = reinterpret_cast<Args*>(arg);
auto info = args->pf->GetOutputInformation(0);
auto output_tmp = args->pf->GetOutput();
auto input_tmp = args->pf->GetInput();
vtkStructuredGrid* output = dynamic_cast<vtkStructuredGrid*>(output_tmp);
vtkStructuredGrid* input = dynamic_cast<vtkStructuredGrid*>(input_tmp);
output->ShallowCopy(input);
output->SetExtent(args->local_extent);
}
Thanks in advance,
Daniel