VTK  9.1.0
vtkAbstractGridConnectivity.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkAbstractGridConnectivity.h
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 =========================================================================*/
42#ifndef vtkAbstractGridConnectivity_h
43#define vtkAbstractGridConnectivity_h
44
45// VTK includes
46#include "vtkCellData.h" // for vtkCellData definition int STL vector
47#include "vtkFiltersGeometryModule.h" // For export macro
48#include "vtkObject.h"
49#include "vtkPointData.h" // for vtkPointData definition in STL vector
50#include "vtkPoints.h" // for vtkPoints definition in STL vector
51#include "vtkUnsignedCharArray.h" // for vtkUnsignedCharArray definition
52
53// Forward declarations
54class vtkPointData;
55class vtkCellData;
57class vtkPoints;
58
59// C++ include directives
60#include <cassert> // For assert
61#include <vector> // For STL vector
62
63class VTKFILTERSGEOMETRY_EXPORT vtkAbstractGridConnectivity : public vtkObject
64{
65public:
67 void PrintSelf(ostream& os, vtkIndent indent) override;
68
70
73 vtkSetMacro(NumberOfGhostLayers, unsigned int);
74 vtkGetMacro(NumberOfGhostLayers, unsigned int);
76
84 virtual void SetNumberOfGrids(const unsigned int N) = 0;
85
89 unsigned int GetNumberOfGrids() { return this->NumberOfGrids; }
90
94 virtual void ComputeNeighbors() = 0;
95
102 virtual void CreateGhostLayers(const int N = 1) = 0;
103
110 vtkUnsignedCharArray* GetGhostedPointGhostArray(const int gridID);
111
118 vtkUnsignedCharArray* GetGhostedCellGhostArray(const int gridID);
119
126 vtkPointData* GetGhostedGridPointData(const int gridID);
127
134 vtkCellData* GetGhostedGridCellData(const int gridID);
135
142 vtkPoints* GetGhostedPoints(const int gridID);
143
144protected:
147
151 virtual void FillGhostArrays(
152 const int gridId, vtkUnsignedCharArray* nodesArray, vtkUnsignedCharArray* cellsArray) = 0;
153
157 void RegisterGridGhostArrays(
158 const int gridID, vtkUnsignedCharArray* nodesArray, vtkUnsignedCharArray* cellsArray);
159
163 void RegisterFieldData(const int gridID, vtkPointData* PointData, vtkCellData* CellData);
164
168 void RegisterGridNodes(const int gridID, vtkPoints* nodes);
169
171
175 void AllocateUserRegisterDataStructures();
176 void DeAllocateUserRegisterDataStructures();
178
180
184 void AllocateInternalDataStructures();
185 void DeAllocateInternalDataStructures();
187
188 // The total number of grids, set initially by the user.
189 unsigned int NumberOfGrids;
191
192 // Arrays registered by the user for each grid
193 std::vector<vtkUnsignedCharArray*> GridPointGhostArrays;
194 std::vector<vtkUnsignedCharArray*> GridCellGhostArrays;
195 std::vector<vtkPointData*> GridPointData;
196 std::vector<vtkCellData*> GridCellData;
197 std::vector<vtkPoints*> GridPoints;
198
199 // Arrays computed internally for each grid
201 std::vector<vtkPointData*> GhostedGridPointData;
202 std::vector<vtkCellData*> GhostedGridCellData;
203 std::vector<vtkUnsignedCharArray*> GhostedPointGhostArray;
204 std::vector<vtkUnsignedCharArray*> GhostedCellGhostArray;
205 std::vector<vtkPoints*> GhostedGridPoints;
206
207private:
209 void operator=(const vtkAbstractGridConnectivity&) = delete;
210};
211
212//------------------------------------------------------------------------------
214 const int gridID)
215{
217 {
218 return nullptr;
219 }
220
221 assert("pre: GridID is out-of-bound GridPointData" && (gridID >= 0) &&
222 (gridID < static_cast<int>(this->NumberOfGrids)));
223 assert("pre: Ghosted point ghost array" &&
224 (this->NumberOfGrids == this->GhostedPointGhostArray.size()));
225
226 return (this->GhostedPointGhostArray[gridID]);
227}
228
229//------------------------------------------------------------------------------
231{
233 {
234 return nullptr;
235 }
236
237 assert("pre: GridID is out-of-bound GridPointData" && (gridID >= 0) &&
238 (gridID < static_cast<int>(this->NumberOfGrids)));
239 assert("pre: Ghosted point ghost array" &&
240 (this->NumberOfGrids == this->GhostedCellGhostArray.size()));
241
242 return (this->GhostedCellGhostArray[gridID]);
243}
244
245//------------------------------------------------------------------------------
247{
249 {
250 return nullptr;
251 }
252
253 assert("pre: GridID is out-of-bound GridPointData" && (gridID >= 0) &&
254 (gridID < static_cast<int>(this->NumberOfGrids)));
255 assert(
256 "pre: Ghosted point ghost array" && (this->NumberOfGrids == this->GhostedGridPointData.size()));
257
258 return (this->GhostedGridPointData[gridID]);
259}
260
261//------------------------------------------------------------------------------
263{
265 {
266 return nullptr;
267 }
268
269 assert("pre: GridID is out-of-bound GridPointData" && (gridID >= 0) &&
270 (gridID < static_cast<int>(this->NumberOfGrids)));
271 assert(
272 "pre: Ghosted point ghost array" && (this->NumberOfGrids == this->GhostedGridCellData.size()));
273
274 return (this->GhostedGridCellData[gridID]);
275}
276
277//------------------------------------------------------------------------------
279{
281 {
282 return nullptr;
283 }
284
285 assert("pre: GridID is out-of-bound GridPointData" && (gridID >= 0) &&
286 (gridID < static_cast<int>(this->NumberOfGrids)));
287 assert(
288 "pre: Ghosted point ghost array" && (this->NumberOfGrids == this->GhostedGridPoints.size()));
289
290 return (this->GhostedGridPoints[gridID]);
291}
292
293//------------------------------------------------------------------------------
295{
296 // Sanity Check
297 assert("pre: Allocating UserRegister for N > 0 grids" && (this->NumberOfGrids > 0));
298
299 this->GridPointGhostArrays.resize(this->NumberOfGrids, nullptr);
300 this->GridCellGhostArrays.resize(this->NumberOfGrids, nullptr);
301 this->GridPointData.resize(this->NumberOfGrids, nullptr);
302 this->GridCellData.resize(this->NumberOfGrids, nullptr);
303 this->GridPoints.resize(this->NumberOfGrids, nullptr);
304}
305
306//------------------------------------------------------------------------------
308{
309 assert("pre: Data-structure has not been properly allocated" &&
310 (this->GridPointGhostArrays.size() == this->NumberOfGrids));
311 assert("pre: Data-structure has not been properly allocated" &&
312 (this->GridCellGhostArrays.size() == this->NumberOfGrids));
313 assert("pre: Data-structure has not been properly allocated" &&
314 (this->GridPointData.size() == this->NumberOfGrids));
315 assert("pre: Data-structure has not been properly allocated" &&
316 (this->GridCellData.size() == this->NumberOfGrids));
317 assert("pre: Data-structure has not been properly allocated" &&
318 (this->GridPoints.size() == this->NumberOfGrids));
319
320 for (unsigned int i = 0; i < this->NumberOfGrids; ++i)
321 {
322 // NOTE: Ghost arrays are not deleted here b/c when they are registered, they
323 // are not shallow-copied.
324 // if( this->GridPointGhostArrays[i] != nullptr )
325 // {
326 // this->GridPointGhostArrays[i]->Delete();
327 // }
328 // if( this->GridCellGhostArrays[i] != nullptr )
329 // {
330 // this->GridCellGhostArrays[i]->Delete();
331 // }
332 if (this->GridPointData[i] != nullptr)
333 {
334 this->GridPointData[i]->Delete();
335 }
336 if (this->GridCellData[i] != nullptr)
337 {
338 this->GridCellData[i]->Delete();
339 }
340 if (this->GridPoints[i] != nullptr)
341 {
342 this->GridPoints[i]->Delete();
343 }
344 } // END for all grids
345
346 this->GridPointGhostArrays.clear();
347 this->GridCellGhostArrays.clear();
348 this->GridPointData.clear();
349 this->GridCellData.clear();
350 this->GridPoints.clear();
351}
352
353//------------------------------------------------------------------------------
355{
356 assert("pre: Allocating Internal data-structured for N > 0 grids" && (this->NumberOfGrids > 0));
357
358 this->GhostedGridPointData.resize(this->NumberOfGrids, nullptr);
359 this->GhostedGridCellData.resize(this->NumberOfGrids, nullptr);
360 this->GhostedPointGhostArray.resize(this->NumberOfGrids, nullptr);
361 this->GhostedCellGhostArray.resize(this->NumberOfGrids, nullptr);
362 this->GhostedGridPoints.resize(this->NumberOfGrids, nullptr);
363 this->AllocatedGhostDataStructures = true;
364}
365
366//------------------------------------------------------------------------------
368{
370 {
371 return;
372 }
373
374 assert("pre: Data-structure has not been properly allocated" &&
375 (this->GhostedGridPointData.size() == this->NumberOfGrids));
376 assert("pre: Data-structure has not been properly allocated" &&
377 (this->GhostedGridCellData.size() == this->NumberOfGrids));
378 assert("pre: Data-structure has not been properly allocated" &&
379 (this->GhostedPointGhostArray.size() == this->NumberOfGrids));
380 assert("pre: Data-structure has not been properly allocated" &&
381 (this->GhostedCellGhostArray.size() == this->NumberOfGrids));
382 assert("pre: Data-structure has not been properly allocated" &&
383 (this->GhostedGridPoints.size() == this->NumberOfGrids));
384
385 for (unsigned int i = 0; i < this->NumberOfGrids; ++i)
386 {
387 if (this->GhostedGridPointData[i] != nullptr)
388 {
389 this->GhostedGridPointData[i]->Delete();
390 }
391 if (this->GhostedGridCellData[i] != nullptr)
392 {
393 this->GhostedGridCellData[i]->Delete();
394 }
395 if (this->GhostedPointGhostArray[i] != nullptr)
396 {
397 this->GhostedPointGhostArray[i]->Delete();
398 }
399 if (this->GhostedCellGhostArray[i] != nullptr)
400 {
401 this->GhostedCellGhostArray[i]->Delete();
402 }
403 if (this->GhostedGridPoints[i] != nullptr)
404 {
405 this->GhostedGridPoints[i]->Delete();
406 }
407 } // END for all grids
408
409 this->GhostedGridPointData.clear();
410 this->GhostedGridCellData.clear();
411 this->GhostedPointGhostArray.clear();
412 this->GhostedCellGhostArray.clear();
413 this->GhostedGridPoints.clear();
414
415 this->AllocatedGhostDataStructures = false;
416}
417
418//------------------------------------------------------------------------------
420 const int gridID, vtkUnsignedCharArray* nodesArray, vtkUnsignedCharArray* cellsArray)
421{
422 // Sanity check
423 assert("pre: GridID is out-of-bound GridPointData" && (gridID >= 0) &&
424 (gridID < static_cast<int>(this->NumberOfGrids)));
425 assert("pre: GridPointGhostArrays has not been allocated" &&
426 (this->GridPointGhostArrays.size() == this->NumberOfGrids));
427 assert("pre: GridCellGhostArrays has not been allocated" &&
428 (this->GridCellGhostArrays.size() == this->NumberOfGrids));
429
430 // NOTE: We should really shallow copy the objects here
431 this->GridPointGhostArrays[gridID] = nodesArray;
432 this->GridCellGhostArrays[gridID] = cellsArray;
433}
434
435//------------------------------------------------------------------------------
437 const int gridID, vtkPointData* PointData, vtkCellData* CellData)
438{
439 // Sanity check
440 assert("pre: GridID is out-of-bound GridPointData" && (gridID >= 0) &&
441 (gridID < static_cast<int>(this->NumberOfGrids)));
442 assert("pre: GridPointData has not been allocated!" &&
443 (this->GridPointData.size() == this->NumberOfGrids));
444 assert("pre: GridCellData has not been allocated!" &&
445 (this->GridCellData.size() == this->NumberOfGrids));
446
447 // Note: The size of these vectors is allocated in SetNumberOfGrids
448 if (PointData != nullptr)
449 {
450 assert("pre: GridPointData[gridID] must be nullptr" && this->GridPointData[gridID] == nullptr);
451 this->GridPointData[gridID] = vtkPointData::New();
452 this->GridPointData[gridID]->ShallowCopy(PointData);
453 }
454 else
455 {
456 this->GridPointData[gridID] = nullptr;
457 }
458
459 if (CellData != nullptr)
460 {
461 assert("pre: GridCellData[gridID] must be nullptr" && this->GridCellData[gridID] == nullptr);
462 this->GridCellData[gridID] = vtkCellData::New();
463 this->GridCellData[gridID]->ShallowCopy(CellData);
464 }
465 else
466 {
467 this->GridCellData[gridID] = nullptr;
468 }
469}
470
471//------------------------------------------------------------------------------
473{
474 // Sanity check
475 assert("pre: GridID is out-of-bound GridPointData" && (gridID >= 0) &&
476 (gridID < static_cast<int>(this->NumberOfGrids)));
477 assert(
478 "pre: GridPoints has not been allocated!" && (this->GridPoints.size() == this->NumberOfGrids));
479
480 if (nodes != nullptr)
481 {
482 assert("pre:GridPoints[gridID] must be nullptr" && this->GridPoints[gridID] == nullptr);
483 this->GridPoints[gridID] = vtkPoints::New();
484 this->GridPoints[gridID]->SetDataTypeToDouble();
485 this->GridPoints[gridID]->ShallowCopy(nodes);
486 }
487 else
488 {
489 this->GridPoints[gridID] = nullptr;
490 }
491}
492
493#endif /* vtkAbstractGridConnectivity_h */
A superclass that defines the interface to be implemented by all concrete grid connectivity classes.
vtkUnsignedCharArray * GetGhostedPointGhostArray(const int gridID)
Returns the ghosted points ghost array for the grid associated with the given grid ID.
void DeAllocateUserRegisterDataStructures()
Allocate/De-allocate the data-structures where the user-supplied grids will be registered.
void AllocateUserRegisterDataStructures()
Allocate/De-allocate the data-structures where the user-supplied grids will be registered.
virtual void ComputeNeighbors()=0
Computes the grid neighboring topology for the domain.
std::vector< vtkUnsignedCharArray * > GhostedPointGhostArray
std::vector< vtkUnsignedCharArray * > GridCellGhostArrays
void RegisterGridNodes(const int gridID, vtkPoints *nodes)
Registers the grid nodes for the grid associated with the given gridID.
vtkPointData * GetGhostedGridPointData(const int gridID)
Returns the ghosted grid point data for the grid associated with the given grid ID.
std::vector< vtkCellData * > GridCellData
std::vector< vtkCellData * > GhostedGridCellData
std::vector< vtkPointData * > GridPointData
void RegisterFieldData(const int gridID, vtkPointData *PointData, vtkCellData *CellData)
Registers the grid's field data, i.e., the node and cell data.
virtual void SetNumberOfGrids(const unsigned int N)=0
Sets the total number of grids in the domain.
vtkCellData * GetGhostedGridCellData(const int gridID)
Returns the ghosted grid cell data for the grid associated with the given grid ID.
std::vector< vtkPoints * > GridPoints
std::vector< vtkPointData * > GhostedGridPointData
unsigned int GetNumberOfGrids()
Returns the total number of grids.
void AllocateInternalDataStructures()
Allocated/De-allocate the data-structures where the ghosted grid data will be stored.
void RegisterGridGhostArrays(const int gridID, vtkUnsignedCharArray *nodesArray, vtkUnsignedCharArray *cellsArray)
Registers the ghostarrays for the given grid.
~vtkAbstractGridConnectivity() override
std::vector< vtkPoints * > GhostedGridPoints
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkUnsignedCharArray * GetGhostedCellGhostArray(const int gridID)
Returns the ghosted cells ghost array for the grid associated with the given grid ID.
virtual void CreateGhostLayers(const int N=1)=0
Creates N layers of ghost layers where N is the number of cells that will be added to each grid.
std::vector< vtkUnsignedCharArray * > GridPointGhostArrays
vtkPoints * GetGhostedPoints(const int gridID)
Returns the ghosted grid points for the grid associated with the given grid ID.
virtual void FillGhostArrays(const int gridId, vtkUnsignedCharArray *nodesArray, vtkUnsignedCharArray *cellsArray)=0
Fills the ghost arrays for the given grid.
std::vector< vtkUnsignedCharArray * > GhostedCellGhostArray
void DeAllocateInternalDataStructures()
Allocated/De-allocate the data-structures where the ghosted grid data will be stored.
represent and manipulate cell attribute data
Definition: vtkCellData.h:142
static vtkCellData * New()
a simple class to control print indentation
Definition: vtkIndent.h:113
abstract base class for most VTK objects
Definition: vtkObject.h:73
represent and manipulate point attribute data
Definition: vtkPointData.h:142
static vtkPointData * New()
represent and manipulate 3D points
Definition: vtkPoints.h:143
static vtkPoints * New()
dynamic, self-adjusting array of unsigned char