VTK
vtkStructuredAMRGridConnectivity.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkStructuredAMRGridConnectivity.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  =========================================================================*/
33 #ifndef VTKSTRUCTUREDAMRGRIDCONNECTIVITY_H_
34 #define VTKSTRUCTUREDAMRGRIDCONNECTIVITY_H_
35 
36 #include "vtkFiltersGeometryModule.h" // For export macro
38 
39 #include "vtkStructuredAMRNeighbor.h" // For vtkStructuredAMRNeighbor def.
40 
41 
42 // C++ includes
43 #include <map> // For STL map
44 #include <ostream> // For STL stream
45 #include <set> // For STL set
46 #include <vector> // For STL vector
47 
50 {
51 public:
54  void PrintSelf(ostream& os, vtkIndent indent );
55 
57 
62  void Initialize(
63  const unsigned int NumberOfLevels,
64  const unsigned int N, const int RefinementRatio=-1);
66 
68  virtual void ComputeNeighbors();
69 
71  virtual void CreateGhostLayers(const int N=1);
72 
74 
77  virtual void RegisterGrid(
78  const int gridIdx, const int level, const int refinementRatio,
79  int extents[6],
80  vtkUnsignedCharArray* nodesGhostArray,
81  vtkUnsignedCharArray* cellGhostArray,
82  vtkPointData* pointData,
83  vtkCellData* cellData,
84  vtkPoints* gridNodes);
86 
88 
91  virtual void RegisterGrid(
92  const int gridIdx, const int level, int extents[6],
93  vtkUnsignedCharArray* nodesGhostArray,
94  vtkUnsignedCharArray* cellGhostArray,
95  vtkPointData* pointData,
96  vtkCellData* cellData,
97  vtkPoints* gridNodes);
99 
101 
105  vtkSetMacro(BalancedRefinement,bool);
106  vtkGetMacro(BalancedRefinement,bool);
108 
110 
113  vtkSetMacro(NodeCentered,bool);
114  vtkGetMacro(NodeCentered,bool);
116 
118 
120  vtkSetMacro(CellCentered,bool);
121  vtkGetMacro(CellCentered,bool);
123 
126  int GetNumberOfNeighbors(const int gridID);
127 
130  void GetGhostedExtent(const int gridID, int ext[6]);
131 
134  vtkStructuredAMRNeighbor GetNeighbor(const int gridID, const int nei);
135 
136 protected:
139 
141  virtual void SetNumberOfGrids( const unsigned int N );
142 
144  void CreateGhostedMaskArrays(const int gridID);
145 
147  void CreateGhostedExtent(const int gridID, const int N);
148 
151  void SetGhostedExtent(const int gridID, int ext[6]);
152 
154 
155  void GetCoarsenedExtent(
156  const int gridIdx, int fromLevel, int toLevel, int ext[6]);
158 
160 
161  void GetRefinedExtent(
162  const int gridIdx, int fromLevel, int toLevel, int ext[6]);
164 
166 
167  void RefineExtent(
168  int orient[3], int ndim, int fromLevel, int toLevel, int ext[6]);
170 
172 
174  void GetCellRefinedExtent(
175  int orient[3], int ndim,
176  const int i, const int j, const int k,
177  const int fromLevel, const int toLevel,
178  int ext[6]);
180 
182 
183  void CoarsenExtent(
184  int orient[3], int ndim, int fromLevel, int toLevel, int ext[6]);
186 
188  void GetGridExtent( const int gridIdx, int ext[6] );
189 
191  int GetGridLevel( const int gridIdx );
192 
194  bool LevelExists( const int level );
195 
197 
198  bool IsNodeInterior(
199  const int i, const int j, const int k, int ext[6]);
201 
203 
204  bool IsNodeWithinExtent(
205  const int i, const int j, const int k, int ext[6]);
207 
209 
210  bool IsNodeOnSharedBoundary(
211  const int i, const int j, const int k,
212  const int gridId,int gridExt[6]);
214 
216 
217  bool IsNodeOnBoundaryOfExtent(
218  const int i, const int j, const int k, int ext[6] );
220 
223  void InsertGridAtLevel( const int level, const int gridID);
224 
227  void ComputeNeighborSendAndRcvExtent(const int gridID, const int N);
228 
231  void ComputeWholeExtent();
232 
235  void GetWholeExtentAtLevel(const int level, int ext[6]);
236 
239  void EstablishNeighbors(const int i, const int j);
240 
242 
243  void GetNodeOrientation(
244  const int i, const int j, const int k,
245  int gridExt[6], int nodeOrientation[3]);
247 
249 
255  void GetOrientationVector(
256  const int dataDescription, int orient[3], int &ndim);
258 
260  bool HasConstantRefinementRatio( );
261 
263  void SetRefinementRatioAtLevel( const int level, const int r);
264 
266  int GetRefinementRatioAtLevel(const int level);
267 
269  bool AreExtentsEqual(int ext1[6], int ext2[6] );
270 
272  void SetBlockTopology(const int gridID);
273 
279  int GetNumberOfConnectingBlockFaces( const int gridID );
280 
282 
289  bool HasBlockConnection(const int gridID, const int blockDirection)
290  {
291  // Sanity check
292  assert("pre: gridID is out-of-bounds" &&
293  (gridID >=0) && (gridID < static_cast<int>(this->NumberOfGrids)));
294  assert("pre: BlockTopology has not been properly allocated" &&
295  (this->NumberOfGrids == this->BlockTopology.size()));
296  assert("pre: blockDirection is out-of-bounds" &&
297  (blockDirection >= 0) && (blockDirection < 6) );
298  bool status = false;
299  if( this->BlockTopology[ gridID ] & (1 << blockDirection) )
300  {
301  status = true;
302  }
303  return( status );
304  }
306 
314  void RemoveBlockConnection(const int gridID, const int blockDirection);
315 
323  void AddBlockConnection(const int gridID, const int blockDirection);
324 
327  void ClearBlockConnections( const int gridID );
328 
330 
331  virtual void MarkNodeProperty(
332  const int gridId, const int i, const int j, const int k,
333  int gridExt[6], int wholeExt[6],
334  unsigned char &p);
336 
338 
339  virtual void FillNodesGhostArray(
340  const int gridId, vtkUnsignedCharArray* nodesArray);
342 
344 
345  virtual void FillCellsGhostArray(
346  const int gridId, vtkUnsignedCharArray* cellArray);
348 
350 
351  virtual void FillGhostArrays(
352  const int gridId,
353  vtkUnsignedCharArray* nodesArray,
354  vtkUnsignedCharArray* cellsArray );
356 
358 
364  vtkStructuredAMRNeighbor GetAMRNeighbor(
365  const int i, const int iLevel, int next1[6],
366  const int j, const int jLevel, int next2[6],
367  const int normalizedLevel,
368  const int levelDiff,
369  vtkStructuredNeighbor &nei);
371 
373 
377  void ComputeAMRNeighborOverlapExtents(
378  const int iLevel, const int jLevel, const int normalizedLevel,
379  const vtkStructuredNeighbor &nei,
380  int orient[3], int ndim,
381  int gridOverlapExtent[6],
382  int neiOverlapExtent[6]);
384 
386 
387  int Get1DOrientation(
388  const int idx, const int ExtentLo, const int ExtentHi,
389  const int OnLo, const int OnHi, const int NotOnBoundary);
391 
393  void PrintExtent(std::ostream& os, int ext[6]);
394 
396  void InitializeGhostData( const int gridID );
397 
400  void TransferRegisteredDataToGhostedData( const int gridID );
401 
403 
404  void TransferLocalNodeCenteredNeighborData(
405  const int gridID, vtkStructuredAMRNeighbor &nei);
407 
409 
411  void GetLocalCellCentersFromCoarserLevel(
412  const int gridID, vtkStructuredAMRNeighbor &nei);
414 
416 
417  void GetLocalCellCentersFromFinerLevel(
418  const int gridID, vtkStructuredAMRNeighbor &nei);
420 
422 
424  void GetLocalCellCentersAtSameLevel(
425  const int gridID, vtkStructuredAMRNeighbor &nei);
427 
429 
430  void TransferLocalCellCenteredNeighborData(
431  const int gridID, vtkStructuredAMRNeighbor &nei);
433 
435 
436  void TransferLocalNeighborData(
437  const int gridID, vtkStructuredAMRNeighbor &nei);
439 
441  virtual void TransferGhostDataFromNeighbors(const int gridID);
442 
444 
446  void AverageFieldData(
447  vtkFieldData *source, vtkIdType *sourceIds, const int N,
448  vtkFieldData *target, vtkIdType targetIdx);
450 
452 
457  void CopyFieldData(
458  vtkFieldData *source, vtkIdType sourceIdx,
459  vtkFieldData *target, vtkIdType targetIdx);
461 
462 
463  unsigned int NumberOfLevels; // The total number of levels;
464  int DataDimension; // The dimension of the data, i.e. 2 or 3
465  int DataDescription; // The data description, i.e., VTK_XY_PLANE, etc.
466  int WholeExtent[6]; // The whole extent w.r.t. to the root level, level 0.
467  int MaxLevel; // The max level of the AMR hierarchy
468  int RefinementRatio; // The refinement ratio, set in the initialization,iff,
469  // a constant refinement ratio is used. A value of -1
470  // indicates that the refinement ratio is not constant
471  // and the RefinementRatios vector is used instead.
472 
473  bool NodeCentered; // Indicates if the data is node-centered
474  bool CellCentered; // Indicates if the data is cell-centered
475 
476  bool BalancedRefinement; // If Balanced refinement is true, then adjacent
477  // grids in the hierarchy can only differ by one
478  // level.
479 
480  // BTX
481  // AMRHierarchy stores the the set of grid Ids in [0,N] for each level
482  std::map< int, std::set<int> > AMRHierarchy;
483 
484  // For each grid, [0,N] store the grid extents,level, and list of neighbors
485  std::vector< int > GridExtents; // size of this vector is 6*N
486  std::vector< int > GhostedExtents; // size of this vector is 6*N
487  std::vector< unsigned char > BlockTopology; // size of this vector is N
488  std::vector< int > GridLevels; // size of ths vector is N
489  std::vector< std::vector<vtkStructuredAMRNeighbor> > Neighbors;
490 
491  // For each grid, [0,N], store the donor level,grid and cell information, a
492  // DonorLevel of -1 indicates that the cell is not receiving any information
493  // from a donor.
494  std::vector< std::vector<int> > CellCenteredDonorLevel;
495 
496 
497  // RefinementRatios stores the refinement ratio at each level, this vector
498  // is used only when the refinement ratio varies across levels
499  std::vector< int > RefinementRatios;
500  // ETX
501 
502 private:
504  void operator=(const vtkStructuredAMRGridConnectivity&); // Not implemented
505 };
506 
507 //=============================================================================
508 // INLINE METHODS
509 //=============================================================================
510 
511 //------------------------------------------------------------------------------
512 inline int
514  const int gridID)
515 {
516  assert("pre: grid ID is out-of-bounds" &&
517  (gridID >= 0) && (gridID < static_cast<int>(this->NumberOfGrids)));
518  assert("pre: neighbors vector has not been properly allocated" &&
519  (this->Neighbors.size()==this->NumberOfGrids));
520  return( static_cast<int>(this->Neighbors[gridID].size()) );
521 }
522 
523 //------------------------------------------------------------------------------
526  const int gridID, const int nei)
527 {
528  assert("pre: grid ID is out-of-bounds" &&
529  (gridID >= 0) && (gridID < static_cast<int>(this->NumberOfGrids)));
530  assert("pre: neighbors vector has not been properly allocated" &&
531  (this->Neighbors.size()==this->NumberOfGrids));
532  assert("pre: nei index is out-of-bounds" &&
533  (nei >= 0) &&
534  (nei < static_cast<int>(this->Neighbors[gridID].size())));
535  return( this->Neighbors[gridID][nei] );
536 }
537 
538 //------------------------------------------------------------------------------
539 inline int
541  const int idx, const int ExtentLo, const int ExtentHi,
542  const int OnLo, const int OnHi, const int NotOnBoundary)
543 {
544  if( idx == ExtentLo )
545  {
546  return OnLo;
547  }
548  else if( idx == ExtentHi )
549  {
550  return OnHi;
551  }
552  return NotOnBoundary;
553 }
554 
555 //------------------------------------------------------------------------------
556 inline
558  const int gridID )
559 {
560  // Sanity check
561  assert("pre: gridID is out-of-bounds" &&
562  (gridID >=0) && (gridID < static_cast<int>(this->NumberOfGrids)));
563  assert("pre: BlockTopology has not been properly allocated" &&
564  (this->NumberOfGrids == this->BlockTopology.size()));
565 
566  int count = 0;
567  for( int i=0; i < 6; ++i )
568  {
569  if( this->HasBlockConnection( gridID, i ) )
570  {
571  ++count;
572  }
573  }
574  assert( "post: count must be in [0,5]" && (count >=0 && count <= 6) );
575  return( count );
576 }
577 
578 //------------------------------------------------------------------------------
580  const int gridID, const int blockDirection )
581 {
582  // Sanity check
583  assert("pre: gridID is out-of-bounds" &&
584  (gridID >=0) && (gridID < static_cast<int>(this->NumberOfGrids)));
585  assert("pre: BlockTopology has not been properly allocated" &&
586  (this->NumberOfGrids == this->BlockTopology.size()));
587  assert("pre: blockDirection is out-of-bounds" &&
588  (blockDirection >= 0) && (blockDirection < 6) );
589 
590  this->BlockTopology[ gridID ] &= ~(1 << blockDirection);
591 }
592 
593 //------------------------------------------------------------------------------
595  const int gridID, const int blockDirection )
596 {
597  // Sanity check
598  assert("pre: gridID is out-of-bounds" &&
599  (gridID >=0) && (gridID < static_cast<int>(this->NumberOfGrids)));
600  assert("pre: BlockTopology has not been properly allocated" &&
601  (this->NumberOfGrids == this->BlockTopology.size()));
602  assert("pre: blockDirection is out-of-bounds" &&
603  (blockDirection >= 0) && (blockDirection < 6) );
604  this->BlockTopology[ gridID ] |= (1 << blockDirection);
605 }
606 
607 //------------------------------------------------------------------------------
609  const int gridID )
610 {
611  // Sanity check
612  assert("pre: gridID is out-of-bounds" &&
613  (gridID >=0) && (gridID < static_cast<int>(this->NumberOfGrids)));
614  assert("pre: BlockTopology has not been properly allocated" &&
615  (this->NumberOfGrids == this->BlockTopology.size()));
616  for( int i=0; i < 6; ++i )
617  {
618  this->RemoveBlockConnection( gridID, i );
619  } // END for all block directions
620 }
621 
622 //------------------------------------------------------------------------------
623 inline
625  int ext1[6], int ext2[6])
626 {
627  for( int i=0; i < 6; ++i )
628  {
629  if( ext1[i] != ext2[i] )
630  {
631  return false;
632  }
633  } // END for
634  return true;
635 }
636 
637 //------------------------------------------------------------------------------
638 inline
640  std::ostream& os, int ext[6])
641 {
642  for( int i=0; i < 6; i+=2 )
643  {
644  os << "[";
645  os << ext[i] << " ";
646  os << ext[i+1] << "] ";
647  } // END for
648 }
649 
650 //------------------------------------------------------------------------------
651 inline
653 {
654  assert("pre: grid Index is out-of-bounds!" &&
655  (gridIdx < static_cast<int>(this->NumberOfGrids)));
656  assert("pre: grid levels vector has not been allocated" &&
657  (this->GridLevels.size()==this->NumberOfGrids) );
658  return( this->GridLevels[gridIdx] );
659 }
660 
661 //------------------------------------------------------------------------------
662 inline
664  const int level, const int r)
665 {
666  assert("pre: RefinementRatios vector is not propertly allocated" &&
667  this->RefinementRatios.size()==this->NumberOfLevels);
668  assert("pre: leve is out-of-bounds!" &&
669  (level >= 0) &&
670  (level < static_cast<int>(this->RefinementRatios.size())) );
671  assert("pre: invalid refinement ratio" && (r >= 2) );
672 
673  this->RefinementRatios[ level ] = r;
674 }
675 
676 //------------------------------------------------------------------------------
677 inline
679  const int level)
680 {
681  assert( "pre: RefinementRatios vector is not propertly allocated" &&
682  this->RefinementRatios.size()==this->NumberOfLevels);
683  assert( "pre: leve is out-of-bounds!" &&
684  (level >= 0) &&
685  (level < static_cast<int>(this->RefinementRatios.size())));
686  assert( "pre: refinement ratio for level has not been set" &&
687  (this->RefinementRatios[ level ] >= 2) );
688 
689  return(this->RefinementRatios[level]);
690 }
691 
692 //------------------------------------------------------------------------------
693 inline
695 {
696  if( this->RefinementRatio < 2 )
697  {
698  return false;
699  }
700  return true;
701 }
702 
703 //------------------------------------------------------------------------------
705  const int gridIdx, int ext[6])
706 {
707  assert("pre: grid index is out-of-bounds" &&
708  ( (gridIdx >= 0) &&
709  (gridIdx < static_cast<int>(this->GridExtents.size()) ) ) );
710 
711  for( int i=0; i < 6; ++i )
712  {
713  ext[ i ] = this->GridExtents[ gridIdx*6+i ];
714  }
715 }
716 
717 //------------------------------------------------------------------------------
719  const int level )
720 {
721  if( this->AMRHierarchy.find(level) != this->AMRHierarchy.end() )
722  {
723  return true;
724  }
725  return false;
726 }
727 
728 //------------------------------------------------------------------------------
730  const int level, const int gridID )
731 {
732  if( this->LevelExists( level ) )
733  {
734  this->AMRHierarchy[ level ].insert( gridID );
735  }
736  else
737  {
738  std::set<int> grids;
739  grids.insert( gridID );
740  this->AMRHierarchy[ level ] = grids;
741  }
742 }
743 
744 #endif /* VTKSTRUCTUREDAMRGRIDCONNECTIVITY_H_ */
void RemoveBlockConnection(const int gridID, const int blockDirection)
boost::graph_traits< vtkGraph * >::vertex_descriptor target(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
bool HasBlockConnection(const int gridID, const int blockDirection)
represent and manipulate point attribute data
Definition: vtkPointData.h:36
void SetRefinementRatioAtLevel(const int level, const int r)
virtual void ComputeNeighbors()=0
std::vector< std::vector< vtkStructuredAMRNeighbor > > Neighbors
represent and manipulate cell attribute data
Definition: vtkCellData.h:37
int vtkIdType
Definition: vtkType.h:275
int Get1DOrientation(const int idx, const int ExtentLo, const int ExtentHi, const int OnLo, const int OnHi, const int NotOnBoundary)
std::vector< std::vector< int > > CellCenteredDonorLevel
a simple class to control print indentation
Definition: vtkIndent.h:38
void GetGridExtent(const int gridIdx, int ext[6])
virtual void SetNumberOfGrids(const unsigned int N)=0
void PrintSelf(ostream &os, vtkIndent indent)
dynamic, self-adjusting array of unsigned char
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
void PrintExtent(std::ostream &os, int ext[6])
std::map< int, std::set< int > > AMRHierarchy
vtkStructuredAMRNeighbor GetNeighbor(const int gridID, const int nei)
virtual void FillGhostArrays(const int gridId, vtkUnsignedCharArray *nodesArray, vtkUnsignedCharArray *cellsArray)=0
static vtkObject * New()
#define VTKFILTERSGEOMETRY_EXPORT
bool AreExtentsEqual(int ext1[6], int ext2[6])
virtual void CreateGhostLayers(const int N=1)=0
void AddBlockConnection(const int gridID, const int blockDirection)
represent and manipulate 3D points
Definition: vtkPoints.h:38
represent and manipulate fields of data
Definition: vtkFieldData.h:55
void InsertGridAtLevel(const int level, const int gridID)