29 #ifndef vtkStructuredGridConnectivity_h
30 #define vtkStructuredGridConnectivity_h
32 #define VTK_NO_OVERLAP 0
33 #define VTK_NODE_OVERLAP 1
34 #define VTK_EDGE_OVERLAP 2
35 #define VTK_PARTIAL_OVERLAP 3
38 #include "vtkFiltersGeometryModule.h"
69 vtkSetVector6Macro(WholeExtent,
int);
70 vtkGetVector6Macro(WholeExtent,
int);
77 vtkGetMacro(DataDimension,
int);
89 virtual void RegisterGrid(
const int gridID,
int extents[6],
99 void GetGridExtent(
const int gridID,
int extent[6] );
105 void SetGhostedGridExtent(
const int gridID,
int ext[6] );
110 void GetGhostedGridExtent(
const int gridID,
int ext[6] );
122 {
return( static_cast<int>(this->Neighbors[ gridID ].
size() )); };
137 vtkIdList* GetNeighbors(
const int gridID,
int *extents );
161 bool InBounds(
const int idx,
const int Lo,
const int Hi )
162 {
return( (idx>=Lo) && (idx<=Hi) ); };
168 {
return( (idx > Lo) && (idx < Hi) ); };
174 {
return( this->InBounds(A[0], B[0], B[1]) &&
175 this->InBounds(A[1], B[0], B[1]) ); };
201 assert(
"ERROR: code should not reach here!" &&
false );
210 void FillNodesGhostArray(
211 const int gridID,
const int dataDescription,
217 void FillCellsGhostArray(
218 const int dataDescription,
const int numNodesPerCell,
227 void SearchNeighbors(
229 const int i,
const int j,
const int k,
236 void MarkNodeProperty(
238 const int i,
const int j,
const int k,
239 int ext[6],
int RealExtent[6],
unsigned char &pfield );
245 void MarkCellProperty(
246 unsigned char &pfield,
247 unsigned char *nodeGhostFields,
const int numNodes );
252 void GetRealExtent(
const int gridID,
int GridExtent[6],
int RealExtent[6] );
259 int GridExtent[6],
int RealExtent[6],
260 const int i,
const int j,
const int k );
266 bool IsNodeOnBoundaryOfExtent(
267 const int i,
const int j,
const int k,
int ext[6] );
274 bool IsNodeOnSharedBoundary(
275 const int gridID,
int RealExtent[6],
276 const int i,
const int j,
const int k );
282 bool IsNodeOnBoundary(
const int i,
const int j,
const int k );
289 const int i,
const int j,
const int k,
297 const int i,
const int j,
const int k,
302 switch( this->DataDescription )
305 if( (GridExtent[0] <= i) && (i <= GridExtent[1]) )
311 if( (GridExtent[2] <= j) && (j <= GridExtent[3] ) )
317 if( (GridExtent[4] <= k) && (k <= GridExtent[5] ) )
323 if( (GridExtent[0] <= i) && (i <= GridExtent[1]) &&
324 (GridExtent[2] <= j) && (j <= GridExtent[3]) )
330 if( (GridExtent[2] <= j) && (j <= GridExtent[3] ) &&
331 (GridExtent[4] <= k) && (k <= GridExtent[5] ) )
337 if( (GridExtent[0] <= i) && (i <= GridExtent[1] ) &&
338 (GridExtent[4] <= k) && (k <= GridExtent[5] ) )
344 if( (GridExtent[0] <= i) && (i <= GridExtent[1]) &&
345 (GridExtent[2] <= j) && (j <= GridExtent[3]) &&
346 (GridExtent[4] <= k) && (k <= GridExtent[5]) )
352 std::cout <<
"Data description is: " << this->DataDescription <<
"\n";
354 assert(
"pre: Undefined data-description!" &&
false );
364 const int i,
const int j,
365 int i2jOrientation[3],
int j2iOrientation[3],
366 int overlapExtent[6] );
376 void DetermineNeighborOrientation(
377 const int idx,
int A[2],
int B[2],
int overlap[2],
int orient[3] );
384 void DetectNeighbors(
385 const int i,
const int j,
int ex1[6],
int ex2[6],
397 int IntervalOverlap(
int A[2],
int B[2],
int overlap[2] );
408 int DoPartialOverlap(
int s[2],
int S[2],
int overlap[2] );
420 int A[2],
const int CofA,
421 int B[2],
const int CofB,
428 void EstablishNeighbors(
const int i,
const int j );
434 void AcquireDataDescription();
450 bool HasBlockConnection(
const int gridID,
const int blockDirection );
466 void RemoveBlockConnection(
const int gridID,
const int blockDirection );
482 void AddBlockConnection(
const int gridID,
const int blockDirection );
488 void ClearBlockConnections(
const int gridID );
497 int GetNumberOfConnectingBlockFaces(
const int gridID );
502 void SetBlockTopology(
const int gridID );
510 void GetIJKBlockOrientation(
511 const int i,
const int j,
const int k,
int ext[6],
int orientation[3] );
517 int Get1DOrientation(
518 const int idx,
const int ExtentLo,
const int ExtentHi,
519 const int OnLo,
const int OnHi,
const int NotOnBoundary );
525 void CreateGhostedExtent(
const int gridID,
const int N );
532 void GetGhostedExtent(
533 int *ghostedExtent,
int GridExtent[6],
534 const int minIdx,
const int maxIdx,
const int N);
540 void CreateGhostedMaskArrays(
const int gridID);
548 void InitializeGhostData(
const int gridID );
568 void TransferRegisteredDataToGhostedData(
const int gridID );
574 void ComputeNeighborSendAndRcvExtent(
const int gridID,
const int N );
581 virtual void TransferGhostDataFromNeighbors(
const int gridID );
586 void TransferLocalNeighborData(
592 void CopyCoordinates(
611 int GetNeighborIndex(
const int gridIdx,
const int NeighborGridIdx );
616 void PrintExtent(
int extent[6] );
625 std::vector< std::vector<vtkStructuredNeighbor> >
Neighbors;
639 const int gridIdx,
const int NeighborGridIdx )
641 assert(
"pre: Grid index is out-of-bounds!" &&
644 assert(
"pre: Neighbor grid index is out-of-bounds!" &&
645 (NeighborGridIdx >= 0) &&
646 (NeighborGridIdx < static_cast<int>(this->
NumberOfGrids) ) );
648 std::pair<int,int> gridPair = std::make_pair(gridIdx,NeighborGridIdx);
649 assert(
"pre: Neighboring grid pair does not exist in hash!" &&
658 int *ghostedExtent,
int GridExtent[6],
659 const int minIdx,
const int maxIdx,
const int N )
661 assert(
"pre: Number of ghost layers must be N >= 1" && (N >= 1) );
662 assert(
"pre: ghosted extent pointer is nullptr" && ghostedExtent !=
nullptr);
664 ghostedExtent[minIdx] = GridExtent[minIdx]-N;
665 ghostedExtent[maxIdx] = GridExtent[maxIdx]+N;
668 ghostedExtent[minIdx] =
669 (ghostedExtent[minIdx] < this->
WholeExtent[minIdx] )?
671 ghostedExtent[maxIdx] =
672 (ghostedExtent[maxIdx] > this->
WholeExtent[maxIdx])?
678 const int gridID,
int ext[6] )
680 assert(
"pre: gridID is out-of-bounds" &&
681 (gridID >= 0) && (gridID < static_cast<int>(this->
NumberOfGrids)));
682 assert(
"pre: ghosted-extents vector has not been allocated" &&
685 for(
int i=0; i < 6; ++i )
693 const int gridID,
int ext[6])
695 assert(
"pre: gridID out-of-bounds!" &&
696 (gridID >= 0 && gridID < static_cast<int>(this->
NumberOfGrids)));
697 for(
int i=0; i < 6; ++i )
705 const int gridID,
int ext[6])
707 assert(
"pre: gridID out-of-bounds!" &&
708 (gridID >= 0 && gridID < static_cast<int>(this->
NumberOfGrids)));
712 ext[0] = ext[2] = ext[4] = -1;
713 ext[1] = ext[3] = ext[5] = 0;
714 vtkErrorMacro(
"No ghosted extents found for registered grid extends!!!" );
718 assert(
"GhostedExtents are not aligned with registered grid extents" &&
720 for(
int i=0; i < 6; ++i )
728 const int i,
const int j,
const int k,
int ext[6] )
739 if( i==ext[0] || i==ext[1] )
745 if( j==ext[2] || j==ext[3] )
751 if( k==ext[4] || k==ext[5] )
757 if( (i==ext[0] || i==ext[1]) ||
758 (j==ext[2] || j==ext[3]) )
764 if( (j==ext[2] || j==ext[3]) ||
765 (k==ext[4] || k==ext[5]) )
771 if( (i==ext[0] || i==ext[1]) ||
772 (k==ext[4] || k==ext[5]) )
778 if( (i==ext[0] || i==ext[1]) ||
779 (j==ext[2] || j==ext[3]) ||
780 (k==ext[4] || k==ext[5]) )
788 assert(
"pre: Undefined data-description!" &&
false );
796 const int i,
const int j,
const int k,
804 if( (GridExtent[0] < i) && (i < GridExtent[1]) )
810 if( (GridExtent[2] < j) && (j < GridExtent[3] ) )
816 if( (GridExtent[4] < k) && (k < GridExtent[5] ) )
822 if( (GridExtent[0] < i) && (i < GridExtent[1]) &&
823 (GridExtent[2] < j) && (j < GridExtent[3]) )
829 if( (GridExtent[2] < j) && (j < GridExtent[3] ) &&
830 (GridExtent[4] < k) && (k < GridExtent[5] ) )
836 if( (GridExtent[0] < i) && (i < GridExtent[1] ) &&
837 (GridExtent[4] < k) && (k < GridExtent[5] ) )
843 if( (GridExtent[0] < i) && (i < GridExtent[1]) &&
844 (GridExtent[2] < j) && (j < GridExtent[3]) &&
845 (GridExtent[4] < k) && (k < GridExtent[5]) )
853 assert(
"pre: Undefined data-description!" &&
false );
861 const int idx,
int A[2],
int B[2],
int overlap[2],
int orient[3] )
863 assert(
"pre: idx is out-of-bounds" && (idx >= 0) && (idx < 3) );
866 if( overlap[0] == overlap[1] )
872 else if( A[0] == B[1] )
879 assert(
"ERROR: Code should not reach here!" &&
false );
885 if( (A[0] == B[0]) && (A[1] == B[1]) )
894 else if( A[0] == B[0] )
898 else if( A[1] == B[1] )
905 assert(
"ERROR: Code should not reach here!" &&
false );
916 if( this->
InBounds( A[0], B[0], B[1] ) )
920 else if( this->
InBounds( A[1], B[0], B[1] ) )
927 assert(
"ERROR: Code should not reach here!" &&
false );
933 assert(
"ERROR: Code should not reach here!" &&
false );
939 const int idx,
const int ExtentLo,
const int ExtentHi,
940 const int OnLo,
const int OnHi,
const int NotOnBoundary )
942 if( idx == ExtentLo )
946 else if( idx == ExtentHi )
950 return NotOnBoundary;
955 const int gridID,
const int blockDirection )
958 assert(
"pre: gridID is out-of-bounds" &&
959 (gridID >=0) && (gridID < static_cast<int>(this->
NumberOfGrids)));
960 assert(
"pre: BlockTopology has not been properly allocated" &&
962 assert(
"pre: blockDirection is out-of-bounds" &&
963 (blockDirection >= 0) && (blockDirection < 6) );
974 const int gridID,
const int blockDirection )
977 assert(
"pre: gridID is out-of-bounds" &&
978 (gridID >=0) && (gridID < static_cast<int>(this->
NumberOfGrids)));
979 assert(
"pre: BlockTopology has not been properly allocated" &&
981 assert(
"pre: blockDirection is out-of-bounds" &&
982 (blockDirection >= 0) && (blockDirection < 6) );
989 const int gridID,
const int blockDirection )
992 assert(
"pre: gridID is out-of-bounds" &&
993 (gridID >=0) && (gridID < static_cast<int>(this->
NumberOfGrids)));
994 assert(
"pre: BlockTopology has not been properly allocated" &&
996 assert(
"pre: blockDirection is out-of-bounds" &&
997 (blockDirection >= 0) && (blockDirection < 6) );
1006 assert(
"pre: gridID is out-of-bounds" &&
1007 (gridID >=0) && (gridID < static_cast<int>(this->
NumberOfGrids)));
1008 assert(
"pre: BlockTopology has not been properly allocated" &&
1010 for(
int i=0; i < 6; ++i )
1021 assert(
"pre: gridID is out-of-bounds" &&
1022 (gridID >=0) && (gridID < static_cast<int>(this->
NumberOfGrids)));
1023 assert(
"pre: BlockTopology has not been properly allocated" &&
1027 for(
int i=0; i < 6; ++i )
1034 assert(
"post: count must be in [0,5]" && (count >=0 && count <= 6) );
1040 const unsigned int N )
1044 vtkErrorMacro(
"Number of grids cannot be 0.");