1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkStructuredGridGhostDataGenerator.cxx
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14 =========================================================================*/
15 #include "vtkStructuredGridGhostDataGenerator.h"
16 #include "vtkObjectFactory.h"
17 #include "vtkMultiBlockDataSet.h"
18 #include "vtkStructuredGridConnectivity.h"
19 #include "vtkStructuredGrid.h"
20 #include "vtkInformation.h"
21 #include "vtkInformationVector.h"
22
23 #include "vtkStreamingDemandDrivenPipeline.h"
24
25 vtkStandardNewMacro(vtkStructuredGridGhostDataGenerator);
26
27 //------------------------------------------------------------------------------
vtkStructuredGridGhostDataGenerator()28 vtkStructuredGridGhostDataGenerator::vtkStructuredGridGhostDataGenerator()
29 {
30 this->GridConnectivity = vtkStructuredGridConnectivity::New();
31 }
32
33 //------------------------------------------------------------------------------
~vtkStructuredGridGhostDataGenerator()34 vtkStructuredGridGhostDataGenerator::~vtkStructuredGridGhostDataGenerator()
35 {
36 this->GridConnectivity->Delete();
37 }
38
39 //------------------------------------------------------------------------------
PrintSelf(ostream & os,vtkIndent indent)40 void vtkStructuredGridGhostDataGenerator::PrintSelf(
41 ostream &os, vtkIndent indent)
42 {
43 this->Superclass::PrintSelf( os, indent );
44 }
45
46 //------------------------------------------------------------------------------
RegisterGrids(vtkMultiBlockDataSet * in)47 void vtkStructuredGridGhostDataGenerator::RegisterGrids(
48 vtkMultiBlockDataSet *in)
49 {
50 assert("pre: Input multi-block is nullptr" && (in != nullptr) );
51 assert("pre: Grid connectivity should not be nullptr" &&
52 (this->GridConnectivity != nullptr) );
53
54 this->GridConnectivity->SetNumberOfGrids( in->GetNumberOfBlocks() );
55 this->GridConnectivity->SetNumberOfGhostLayers( 0 );
56 this->GridConnectivity->SetWholeExtent(
57 in->GetInformation()->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT()));
58
59 for( unsigned int i=0; i < in->GetNumberOfBlocks(); ++i )
60 {
61 vtkStructuredGrid *grid = vtkStructuredGrid::SafeDownCast( in->GetBlock(i));
62 assert("pre: grid block is nullptr" && (grid != nullptr) );
63
64 vtkInformation *info = in->GetMetaData( i );
65 assert("pre: nullptr meta-data" && (info != nullptr) );
66 assert("pre: No piece meta-data" &&
67 info->Has(vtkDataObject::PIECE_EXTENT()));
68
69 this->GridConnectivity->RegisterGrid(
70 static_cast<int>(i),info->Get(vtkDataObject::PIECE_EXTENT()),
71 grid->GetPointGhostArray(),
72 grid->GetCellGhostArray(),
73 grid->GetPointData(),
74 grid->GetCellData(),
75 grid->GetPoints() );
76 } // END for all blocks
77 }
78
79 //------------------------------------------------------------------------------
CreateGhostedDataSet(vtkMultiBlockDataSet * in,vtkMultiBlockDataSet * out)80 void vtkStructuredGridGhostDataGenerator::CreateGhostedDataSet(
81 vtkMultiBlockDataSet *in, vtkMultiBlockDataSet *out)
82 {
83 assert("pre: Input multi-block is nullptr" && (in != nullptr) );
84 assert("pre: Output multi-block is nullptr" && (out != nullptr) );
85 assert("pre: Grid connectivity should not be nullptr" &&
86 (this->GridConnectivity != nullptr) );
87
88 out->SetNumberOfBlocks( in->GetNumberOfBlocks() );
89 int wholeExt[6];
90 in->GetInformation()->Get(
91 vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), wholeExt );
92 vtkInformation *outInfo = out->GetInformation();
93 outInfo->Set(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(),wholeExt,6);
94
95 int ghostedExtent[6];
96 for( unsigned int i=0; i < out->GetNumberOfBlocks(); ++i )
97 {
98 // STEP 0: Get the computed ghosted grid extent
99 this->GridConnectivity->GetGhostedGridExtent( i, ghostedExtent );
100
101 // STEP 1: Construct the ghosted structured grid instance
102 vtkStructuredGrid *ghostedGrid = vtkStructuredGrid::New();
103 assert("pre: Cannot create ghosted grid instance" && (ghostedGrid != nullptr));
104 ghostedGrid->SetExtent( ghostedExtent );
105
106 vtkPoints *ghostedGridPoints = vtkPoints::New();
107 ghostedGridPoints->DeepCopy(this->GridConnectivity->GetGhostedPoints(i));
108 ghostedGrid->SetPoints(ghostedGridPoints);
109 ghostedGridPoints->Delete();
110
111 // STEP 2: Copy the node/cell data
112 ghostedGrid->GetPointData()->DeepCopy(
113 this->GridConnectivity->GetGhostedGridPointData(i) );
114 ghostedGrid->GetCellData()->DeepCopy(
115 this->GridConnectivity->GetGhostedGridCellData(i) );
116
117 out->SetBlock(i,ghostedGrid);
118 ghostedGrid->Delete();
119 } // END for all blocks
120 }
121
122 //------------------------------------------------------------------------------
GenerateGhostLayers(vtkMultiBlockDataSet * in,vtkMultiBlockDataSet * out)123 void vtkStructuredGridGhostDataGenerator::GenerateGhostLayers(
124 vtkMultiBlockDataSet *in, vtkMultiBlockDataSet *out )
125 {
126 assert("pre: Input multi-block is nullptr" && (in != nullptr) );
127 assert("pre: Output multi-block is nullptr" && (out != nullptr) );
128 assert("pre: Grid connectivity should not be nullptr" &&
129 (this->GridConnectivity != nullptr) );
130
131 // STEP 0: Register the input grids
132 this->RegisterGrids( in );
133
134 // STEP 1: Computes the neighbors
135 this->GridConnectivity->ComputeNeighbors();
136
137 // STEP 2: Generate the ghost layers
138 this->GridConnectivity->CreateGhostLayers( this->NumberOfGhostLayers );
139
140 // STEP 3: Get the output dataset
141 this->CreateGhostedDataSet( in ,out );
142 }
143