[vtkusers] is whole extent required for multiblock dataset?
Ufuk Turuncoglu
ufuk.turuncoglu at itu.edu.tr
Fri Jun 2 08:13:46 EDT 2017
Hi Again,
I create following test code to write dummy data (checkerboard with 0
and 1) using vtkStructuredGrid in multiblock format. Without extent in
left and top of the tiles the data looks correct but there is a gap
between pieces (see attached screenshot). To fix the issue, i add a
extra piece of code to overlap one row and columns (using hasLeft and
hasTop control). The problem is that when i run the code with this
modification, i am getting totally wrong grid representation (screen2).
I just wonder that do i need to set whole extent in somewhere. I tried
to add following to set whole extent to multiblock dataset,
int extent[6] = {0, N-1, 0, N-1, 0, 0};
mb->GetInformationObject(0)->Set(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(),
extent, 6);
but it won't work as i expected. Any suggestion? Thanks.
Regards,
--ufuk
#include <iostream>
#include "mpi.h"
#include "vtkStructuredGrid.h"
#include "vtkSmartPointer.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkMultiPieceDataSet.h"
#include "vtkNew.h"
#include "vtkXMLPMultiBlockDataWriter.h"
#include "vtkMPIController.h"
#include "vtkDoubleArray.h"
#include "vtkDataSet.h"
#include "vtkPointData.h"
#include "vtkInformation.h"
#include "vtkStreamingDemandDrivenPipeline.h"
using namespace std;
// global variables
int const N = 10;
int const tileX = 2;
int const tileY = 2;
int main(int argc, char** argv) {
// initialize MPI
MPI_Init(NULL, NULL);
// setup global controller, true means initialized externally
vtkNew<vtkMPIController> controller;
controller->Initialize(&argc, &argv, true);
vtkMultiProcessController::SetGlobalController(controller.Get());
// get number of processor and rank
int nproc, myid;
MPI_Comm_size(MPI_COMM_WORLD, &nproc);
MPI_Comm_rank(MPI_COMM_WORLD, &myid);
// create 2d decomposition parameters
bool hasLeft = false, hasTop = false;
if (myid%tileX == 0) hasLeft = true;
if (myid/tileY == 0) hasTop = true;
int istr = myid%tileX*N/tileX;
int iend = istr+N/tileX-1;
if (hasLeft) iend = iend+1;
int jstr = myid/tileX*N/tileY;
int jend = jstr+N/tileY-1;
if (hasTop) jend = jend+1;
int size = (iend-istr+1)*(jend-jstr+1);
//cout << myid << " of " << nproc << " " << boolalpha << hasLeft << "
" << hasTop << endl;
//cout << myid << " " << istr << " " << iend << " " << jstr << " " <<
jend << endl;
// create structured grid
vtkSmartPointer<vtkStructuredGrid> grid =
vtkSmartPointer<vtkStructuredGrid>::New();
// define grid coordinates
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
points->SetNumberOfPoints(size);
int id = 0;
for (int i = istr; i <= iend; i++) {
for (int j = jstr; j <= jend; j++) {
points->SetPoint(id, i, j, 0);
id = id+1;
}
}
grid->SetPoints(points);
grid->SetExtent(istr, iend, jstr, jend, 0, 0);
points->Delete();
// add field, checkerboard type data with full of 0/1
vtkSmartPointer<vtkDoubleArray> field =
vtkSmartPointer<vtkDoubleArray>::New();
field->SetName("dummy");
field->SetNumberOfComponents(1);
field->SetNumberOfValues(size);
id = 0;
for (int i = istr; i <= iend; i++) {
for (int j = jstr; j <= jend; j++) {
int val = (i+j)%2 ? 0 : 1;
field->SetValue(id, val);
id = id+1;
}
}
// create multi block grid
vtkMultiBlockDataSet* mb = vtkMultiBlockDataSet::New();
vtkNew<vtkMultiPieceDataSet> mpds;
mpds->SetNumberOfPieces(nproc);
mpds->SetPiece(myid, grid.GetPointer());
mb->SetNumberOfBlocks(1);
mb->SetBlock(0, mpds.GetPointer());
// add field
vtkDataSet *ds = vtkDataSet::SafeDownCast(mpds->GetPiece(myid));
ds->GetPointData()->AddArray(field);
// create a writer
vtkSmartPointer<vtkXMLPMultiBlockDataWriter> mbw =
vtkSmartPointer<vtkXMLPMultiBlockDataWriter>::New();
mbw->SetFileName("test.vtm");
mbw->SetDataModeToAscii();
mbw->SetInputData(mb);
mbw->Write();
// finalize the MPI environment.
MPI_Finalize();
return 0;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: screen.png
Type: image/png
Size: 294963 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170602/a0a03cb6/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: screen2.png
Type: image/png
Size: 321266 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170602/a0a03cb6/attachment-0003.png>
More information about the vtkusers
mailing list