VTK  9.4.20241222
vtkAbstractGridConnectivity.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
30#ifndef vtkAbstractGridConnectivity_h
31#define vtkAbstractGridConnectivity_h
32
33// VTK includes
34#include "vtkCellData.h" // for vtkCellData definition int STL vector
35#include "vtkFiltersGeometryModule.h" // For export macro
36#include "vtkObject.h"
37#include "vtkPointData.h" // for vtkPointData definition in STL vector
38#include "vtkPoints.h" // for vtkPoints definition in STL vector
39#include "vtkUnsignedCharArray.h" // for vtkUnsignedCharArray definition
40
41// Forward declarations
42VTK_ABI_NAMESPACE_BEGIN
43class vtkPointData;
44class vtkCellData;
46class vtkPoints;
47
48// C++ include directives
49VTK_ABI_NAMESPACE_END
50#include <cassert> // For assert
51#include <vector> // For STL vector
52
53VTK_ABI_NAMESPACE_BEGIN
54class VTKFILTERSGEOMETRY_EXPORT vtkAbstractGridConnectivity : public vtkObject
55{
56public:
58 void PrintSelf(ostream& os, vtkIndent indent) override;
59
61
64 vtkSetMacro(NumberOfGhostLayers, unsigned int);
65 vtkGetMacro(NumberOfGhostLayers, unsigned int);
67
75 virtual void SetNumberOfGrids(unsigned int N) = 0;
76
80 unsigned int GetNumberOfGrids() { return this->NumberOfGrids; }
81
85 virtual void ComputeNeighbors() = 0;
86
93 virtual void CreateGhostLayers(int N = 1) = 0;
94
101 vtkUnsignedCharArray* GetGhostedPointGhostArray(int gridID);
102
109 vtkUnsignedCharArray* GetGhostedCellGhostArray(int gridID);
110
117 vtkPointData* GetGhostedGridPointData(int gridID);
118
125 vtkCellData* GetGhostedGridCellData(int gridID);
126
133 vtkPoints* GetGhostedPoints(int gridID);
134
135protected:
138
142 virtual void FillGhostArrays(
143 int gridId, vtkUnsignedCharArray* nodesArray, vtkUnsignedCharArray* cellsArray) = 0;
144
148 void RegisterGridGhostArrays(
149 int gridID, vtkUnsignedCharArray* nodesArray, vtkUnsignedCharArray* cellsArray);
150
154 void RegisterFieldData(int gridID, vtkPointData* PointData, vtkCellData* CellData);
155
159 void RegisterGridNodes(int gridID, vtkPoints* nodes);
160
162
166 void AllocateUserRegisterDataStructures();
167 void DeAllocateUserRegisterDataStructures();
169
171
175 void AllocateInternalDataStructures();
176 void DeAllocateInternalDataStructures();
178
179 // The total number of grids, set initially by the user.
180 unsigned int NumberOfGrids;
182
183 // Arrays registered by the user for each grid
184 std::vector<vtkUnsignedCharArray*> GridPointGhostArrays;
185 std::vector<vtkUnsignedCharArray*> GridCellGhostArrays;
186 std::vector<vtkPointData*> GridPointData;
187 std::vector<vtkCellData*> GridCellData;
188 std::vector<vtkPoints*> GridPoints;
189
190 // Arrays computed internally for each grid
192 std::vector<vtkPointData*> GhostedGridPointData;
193 std::vector<vtkCellData*> GhostedGridCellData;
194 std::vector<vtkUnsignedCharArray*> GhostedPointGhostArray;
195 std::vector<vtkUnsignedCharArray*> GhostedCellGhostArray;
196 std::vector<vtkPoints*> GhostedGridPoints;
197
198private:
200 void operator=(const vtkAbstractGridConnectivity&) = delete;
201};
202
203//------------------------------------------------------------------------------
205{
207 {
208 return nullptr;
209 }
210
211 assert("pre: GridID is out-of-bound GridPointData" && (gridID >= 0) &&
212 (gridID < static_cast<int>(this->NumberOfGrids)));
213 assert("pre: Ghosted point ghost array" &&
214 (this->NumberOfGrids == this->GhostedPointGhostArray.size()));
215
216 return (this->GhostedPointGhostArray[gridID]);
217}
218
219//------------------------------------------------------------------------------
221{
223 {
224 return nullptr;
225 }
226
227 assert("pre: GridID is out-of-bound GridPointData" && (gridID >= 0) &&
228 (gridID < static_cast<int>(this->NumberOfGrids)));
229 assert("pre: Ghosted point ghost array" &&
230 (this->NumberOfGrids == this->GhostedCellGhostArray.size()));
231
232 return (this->GhostedCellGhostArray[gridID]);
233}
234
235//------------------------------------------------------------------------------
237{
239 {
240 return nullptr;
241 }
242
243 assert("pre: GridID is out-of-bound GridPointData" && (gridID >= 0) &&
244 (gridID < static_cast<int>(this->NumberOfGrids)));
245 assert(
246 "pre: Ghosted point ghost array" && (this->NumberOfGrids == this->GhostedGridPointData.size()));
247
248 return (this->GhostedGridPointData[gridID]);
249}
250
251//------------------------------------------------------------------------------
253{
255 {
256 return nullptr;
257 }
258
259 assert("pre: GridID is out-of-bound GridPointData" && (gridID >= 0) &&
260 (gridID < static_cast<int>(this->NumberOfGrids)));
261 assert(
262 "pre: Ghosted point ghost array" && (this->NumberOfGrids == this->GhostedGridCellData.size()));
263
264 return (this->GhostedGridCellData[gridID]);
265}
266
267//------------------------------------------------------------------------------
269{
271 {
272 return nullptr;
273 }
274
275 assert("pre: GridID is out-of-bound GridPointData" && (gridID >= 0) &&
276 (gridID < static_cast<int>(this->NumberOfGrids)));
277 assert(
278 "pre: Ghosted point ghost array" && (this->NumberOfGrids == this->GhostedGridPoints.size()));
279
280 return (this->GhostedGridPoints[gridID]);
281}
282
283//------------------------------------------------------------------------------
285{
286 // Sanity Check
287 assert("pre: Allocating UserRegister for N > 0 grids" && (this->NumberOfGrids > 0));
288
289 this->GridPointGhostArrays.resize(this->NumberOfGrids, nullptr);
290 this->GridCellGhostArrays.resize(this->NumberOfGrids, nullptr);
291 this->GridPointData.resize(this->NumberOfGrids, nullptr);
292 this->GridCellData.resize(this->NumberOfGrids, nullptr);
293 this->GridPoints.resize(this->NumberOfGrids, nullptr);
294}
295
296//------------------------------------------------------------------------------
298{
299 assert("pre: Data-structure has not been properly allocated" &&
300 (this->GridPointGhostArrays.size() == this->NumberOfGrids));
301 assert("pre: Data-structure has not been properly allocated" &&
302 (this->GridCellGhostArrays.size() == this->NumberOfGrids));
303 assert("pre: Data-structure has not been properly allocated" &&
304 (this->GridPointData.size() == this->NumberOfGrids));
305 assert("pre: Data-structure has not been properly allocated" &&
306 (this->GridCellData.size() == this->NumberOfGrids));
307 assert("pre: Data-structure has not been properly allocated" &&
308 (this->GridPoints.size() == this->NumberOfGrids));
309
310 for (unsigned int i = 0; i < this->NumberOfGrids; ++i)
311 {
312 // NOTE: Ghost arrays are not deleted here b/c when they are registered, they
313 // are not shallow-copied.
314 // if( this->GridPointGhostArrays[i] != nullptr )
315 // {
316 // this->GridPointGhostArrays[i]->Delete();
317 // }
318 // if( this->GridCellGhostArrays[i] != nullptr )
319 // {
320 // this->GridCellGhostArrays[i]->Delete();
321 // }
322 if (this->GridPointData[i] != nullptr)
323 {
324 this->GridPointData[i]->Delete();
325 }
326 if (this->GridCellData[i] != nullptr)
327 {
328 this->GridCellData[i]->Delete();
329 }
330 if (this->GridPoints[i] != nullptr)
331 {
332 this->GridPoints[i]->Delete();
333 }
334 } // END for all grids
335
336 this->GridPointGhostArrays.clear();
337 this->GridCellGhostArrays.clear();
338 this->GridPointData.clear();
339 this->GridCellData.clear();
340 this->GridPoints.clear();
341}
342
343//------------------------------------------------------------------------------
345{
346 assert("pre: Allocating Internal data-structured for N > 0 grids" && (this->NumberOfGrids > 0));
347
348 this->GhostedGridPointData.resize(this->NumberOfGrids, nullptr);
349 this->GhostedGridCellData.resize(this->NumberOfGrids, nullptr);
350 this->GhostedPointGhostArray.resize(this->NumberOfGrids, nullptr);
351 this->GhostedCellGhostArray.resize(this->NumberOfGrids, nullptr);
352 this->GhostedGridPoints.resize(this->NumberOfGrids, nullptr);
353 this->AllocatedGhostDataStructures = true;
354}
355
356//------------------------------------------------------------------------------
358{
360 {
361 return;
362 }
363
364 assert("pre: Data-structure has not been properly allocated" &&
365 (this->GhostedGridPointData.size() == this->NumberOfGrids));
366 assert("pre: Data-structure has not been properly allocated" &&
367 (this->GhostedGridCellData.size() == this->NumberOfGrids));
368 assert("pre: Data-structure has not been properly allocated" &&
369 (this->GhostedPointGhostArray.size() == this->NumberOfGrids));
370 assert("pre: Data-structure has not been properly allocated" &&
371 (this->GhostedCellGhostArray.size() == this->NumberOfGrids));
372 assert("pre: Data-structure has not been properly allocated" &&
373 (this->GhostedGridPoints.size() == this->NumberOfGrids));
374
375 for (unsigned int i = 0; i < this->NumberOfGrids; ++i)
376 {
377 if (this->GhostedGridPointData[i] != nullptr)
378 {
379 this->GhostedGridPointData[i]->Delete();
380 }
381 if (this->GhostedGridCellData[i] != nullptr)
382 {
383 this->GhostedGridCellData[i]->Delete();
384 }
385 if (this->GhostedPointGhostArray[i] != nullptr)
386 {
387 this->GhostedPointGhostArray[i]->Delete();
388 }
389 if (this->GhostedCellGhostArray[i] != nullptr)
390 {
391 this->GhostedCellGhostArray[i]->Delete();
392 }
393 if (this->GhostedGridPoints[i] != nullptr)
394 {
395 this->GhostedGridPoints[i]->Delete();
396 }
397 } // END for all grids
398
399 this->GhostedGridPointData.clear();
400 this->GhostedGridCellData.clear();
401 this->GhostedPointGhostArray.clear();
402 this->GhostedCellGhostArray.clear();
403 this->GhostedGridPoints.clear();
404
405 this->AllocatedGhostDataStructures = false;
406}
407
408//------------------------------------------------------------------------------
410 int gridID, vtkUnsignedCharArray* nodesArray, vtkUnsignedCharArray* cellsArray)
411{
412 // Sanity check
413 assert("pre: GridID is out-of-bound GridPointData" && (gridID >= 0) &&
414 (gridID < static_cast<int>(this->NumberOfGrids)));
415 assert("pre: GridPointGhostArrays has not been allocated" &&
416 (this->GridPointGhostArrays.size() == this->NumberOfGrids));
417 assert("pre: GridCellGhostArrays has not been allocated" &&
418 (this->GridCellGhostArrays.size() == this->NumberOfGrids));
419
420 // NOTE: We should really shallow copy the objects here
421 this->GridPointGhostArrays[gridID] = nodesArray;
422 this->GridCellGhostArrays[gridID] = cellsArray;
423}
424
425//------------------------------------------------------------------------------
427 int gridID, vtkPointData* PointData, vtkCellData* CellData)
428{
429 // Sanity check
430 assert("pre: GridID is out-of-bound GridPointData" && (gridID >= 0) &&
431 (gridID < static_cast<int>(this->NumberOfGrids)));
432 assert("pre: GridPointData has not been allocated!" &&
433 (this->GridPointData.size() == this->NumberOfGrids));
434 assert("pre: GridCellData has not been allocated!" &&
435 (this->GridCellData.size() == this->NumberOfGrids));
436
437 // Note: The size of these vectors is allocated in SetNumberOfGrids
438 if (PointData != nullptr)
439 {
440 assert("pre: GridPointData[gridID] must be nullptr" && this->GridPointData[gridID] == nullptr);
441 this->GridPointData[gridID] = vtkPointData::New();
442 this->GridPointData[gridID]->ShallowCopy(PointData);
443 }
444 else
445 {
446 this->GridPointData[gridID] = nullptr;
447 }
448
449 if (CellData != nullptr)
450 {
451 assert("pre: GridCellData[gridID] must be nullptr" && this->GridCellData[gridID] == nullptr);
452 this->GridCellData[gridID] = vtkCellData::New();
453 this->GridCellData[gridID]->ShallowCopy(CellData);
454 }
455 else
456 {
457 this->GridCellData[gridID] = nullptr;
458 }
459}
460
461//------------------------------------------------------------------------------
463{
464 // Sanity check
465 assert("pre: GridID is out-of-bound GridPointData" && (gridID >= 0) &&
466 (gridID < static_cast<int>(this->NumberOfGrids)));
467 assert(
468 "pre: GridPoints has not been allocated!" && (this->GridPoints.size() == this->NumberOfGrids));
469
470 if (nodes != nullptr)
471 {
472 assert("pre:GridPoints[gridID] must be nullptr" && this->GridPoints[gridID] == nullptr);
473 this->GridPoints[gridID] = vtkPoints::New();
474 this->GridPoints[gridID]->SetDataTypeToDouble();
475 this->GridPoints[gridID]->ShallowCopy(nodes);
476 }
477 else
478 {
479 this->GridPoints[gridID] = nullptr;
480 }
481}
482
483VTK_ABI_NAMESPACE_END
484#endif /* vtkAbstractGridConnectivity_h */
A superclass that defines the interface to be implemented by all concrete grid connectivity classes.
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
vtkPoints * GetGhostedPoints(int gridID)
Returns the ghosted grid points for the grid associated with the given grid ID.
std::vector< vtkUnsignedCharArray * > GridCellGhostArrays
virtual void CreateGhostLayers(int N=1)=0
Creates N layers of ghost layers where N is the number of cells that will be added to each grid.
void RegisterGridGhostArrays(int gridID, vtkUnsignedCharArray *nodesArray, vtkUnsignedCharArray *cellsArray)
Registers the ghostarrays for the given grid.
std::vector< vtkCellData * > GridCellData
vtkCellData * GetGhostedGridCellData(int gridID)
Returns the ghosted grid cell data for the grid associated with the given grid ID.
void RegisterFieldData(int gridID, vtkPointData *PointData, vtkCellData *CellData)
Registers the grid's field data, i.e., the node and cell data.
vtkPointData * GetGhostedGridPointData(int gridID)
Returns the ghosted grid point data for the grid associated with the given grid ID.
std::vector< vtkCellData * > GhostedGridCellData
std::vector< vtkPointData * > GridPointData
std::vector< vtkPoints * > GridPoints
vtkUnsignedCharArray * GetGhostedPointGhostArray(int gridID)
Returns the ghosted points ghost array for the grid associated with the given grid ID.
virtual void FillGhostArrays(int gridId, vtkUnsignedCharArray *nodesArray, vtkUnsignedCharArray *cellsArray)=0
Fills the ghost arrays for the given grid.
std::vector< vtkPointData * > GhostedGridPointData
vtkUnsignedCharArray * GetGhostedCellGhostArray(int gridID)
Returns the ghosted cells ghost array for the grid associated with the given grid ID.
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.
~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.
std::vector< vtkUnsignedCharArray * > GridPointGhostArrays
void RegisterGridNodes(int gridID, vtkPoints *nodes)
Registers the grid nodes for the grid associated with the given gridID.
std::vector< vtkUnsignedCharArray * > GhostedCellGhostArray
void DeAllocateInternalDataStructures()
Allocated/De-allocate the data-structures where the ghosted grid data will be stored.
virtual void SetNumberOfGrids(unsigned int N)=0
Sets the total number of grids in the domain.
represent and manipulate cell attribute data
static vtkCellData * New()
a simple class to control print indentation
Definition vtkIndent.h:108
abstract base class for most VTK objects
Definition vtkObject.h:162
represent and manipulate point attribute data
static vtkPointData * New()
represent and manipulate 3D points
Definition vtkPoints.h:139
static vtkPoints * New()
dynamic, self-adjusting array of unsigned char