32 #ifndef vtkStructuredGridConnectivity_h 33 #define vtkStructuredGridConnectivity_h 35 #define VTK_NO_OVERLAP 0 36 #define VTK_NODE_OVERLAP 1 37 #define VTK_EDGE_OVERLAP 2 38 #define VTK_PARTIAL_OVERLAP 3 41 #include "vtkFiltersGeometryModule.h" 72 vtkSetVector6Macro(WholeExtent,
int);
73 vtkGetVector6Macro(WholeExtent,
int);
80 vtkGetMacro(DataDimension,
int);
92 virtual void RegisterGrid(
const int gridID,
int extents[6],
102 void GetGridExtent(
const int gridID,
int extent[6] );
108 void SetGhostedGridExtent(
const int gridID,
int ext[6] );
113 void GetGhostedGridExtent(
const int gridID,
int ext[6] );
125 {
return( static_cast<int>(this->Neighbors[ gridID ].
size() )); };
140 vtkIdList* GetNeighbors(
const int gridID,
int *extents );
164 bool InBounds(
const int idx,
const int Lo,
const int Hi )
165 {
return( (idx>=Lo) && (idx<=Hi) ); };
171 {
return( (idx > Lo) && (idx < Hi) ); };
177 {
return( this->InBounds(A[0], B[0], B[1]) &&
178 this->InBounds(A[1], B[0], B[1]) ); };
204 assert(
"ERROR: code should not reach here!" &&
false );
213 void FillNodesGhostArray(
214 const int gridID,
const int dataDescription,
220 void FillCellsGhostArray(
221 const int dataDescription,
const int numNodesPerCell,
230 void SearchNeighbors(
232 const int i,
const int j,
const int k,
239 void MarkNodeProperty(
241 const int i,
const int j,
const int k,
242 int ext[6],
int RealExtent[6],
unsigned char &pfield );
248 void MarkCellProperty(
249 unsigned char &pfield,
250 unsigned char *nodeGhostFields,
const int numNodes );
255 void GetRealExtent(
const int gridID,
int GridExtent[6],
int RealExtent[6] );
262 int GridExtent[6],
int RealExtent[6],
263 const int i,
const int j,
const int k );
269 bool IsNodeOnBoundaryOfExtent(
270 const int i,
const int j,
const int k,
int ext[6] );
277 bool IsNodeOnSharedBoundary(
278 const int gridID,
int RealExtent[6],
279 const int i,
const int j,
const int k );
285 bool IsNodeOnBoundary(
const int i,
const int j,
const int k );
292 const int i,
const int j,
const int k,
300 const int i,
const int j,
const int k,
305 switch( this->DataDescription )
308 if( (GridExtent[0] <= i) && (i <= GridExtent[1]) )
314 if( (GridExtent[2] <= j) && (j <= GridExtent[3] ) )
320 if( (GridExtent[4] <= k) && (k <= GridExtent[5] ) )
326 if( (GridExtent[0] <= i) && (i <= GridExtent[1]) &&
327 (GridExtent[2] <= j) && (j <= GridExtent[3]) )
333 if( (GridExtent[2] <= j) && (j <= GridExtent[3] ) &&
334 (GridExtent[4] <= k) && (k <= GridExtent[5] ) )
340 if( (GridExtent[0] <= i) && (i <= GridExtent[1] ) &&
341 (GridExtent[4] <= k) && (k <= GridExtent[5] ) )
347 if( (GridExtent[0] <= i) && (i <= GridExtent[1]) &&
348 (GridExtent[2] <= j) && (j <= GridExtent[3]) &&
349 (GridExtent[4] <= k) && (k <= GridExtent[5]) )
355 std::cout <<
"Data description is: " << this->DataDescription <<
"\n";
357 assert(
"pre: Undefined data-description!" &&
false );
367 const int i,
const int j,
368 int i2jOrientation[3],
int j2iOrientation[3],
369 int overlapExtent[6] );
379 void DetermineNeighborOrientation(
380 const int idx,
int A[2],
int B[2],
int overlap[2],
int orient[3] );
387 void DetectNeighbors(
388 const int i,
const int j,
int ex1[6],
int ex2[6],
400 int IntervalOverlap(
int A[2],
int B[2],
int overlap[2] );
411 int DoPartialOverlap(
int s[2],
int S[2],
int overlap[2] );
423 int A[2],
const int CofA,
424 int B[2],
const int CofB,
431 void EstablishNeighbors(
const int i,
const int j );
437 void AcquireDataDescription();
453 bool HasBlockConnection(
const int gridID,
const int blockDirection );
469 void RemoveBlockConnection(
const int gridID,
const int blockDirection );
485 void AddBlockConnection(
const int gridID,
const int blockDirection );
491 void ClearBlockConnections(
const int gridID );
500 int GetNumberOfConnectingBlockFaces(
const int gridID );
505 void SetBlockTopology(
const int gridID );
513 void GetIJKBlockOrientation(
514 const int i,
const int j,
const int k,
int ext[6],
int orientation[3] );
520 int Get1DOrientation(
521 const int idx,
const int ExtentLo,
const int ExtentHi,
522 const int OnLo,
const int OnHi,
const int NotOnBoundary );
528 void CreateGhostedExtent(
const int gridID,
const int N );
535 void GetGhostedExtent(
536 int *ghostedExtent,
int GridExtent[6],
537 const int minIdx,
const int maxIdx,
const int N);
543 void CreateGhostedMaskArrays(
const int gridID);
551 void InitializeGhostData(
const int gridID );
571 void TransferRegisteredDataToGhostedData(
const int gridID );
577 void ComputeNeighborSendAndRcvExtent(
const int gridID,
const int N );
584 virtual void TransferGhostDataFromNeighbors(
const int gridID );
589 void TransferLocalNeighborData(
595 void CopyCoordinates(
614 int GetNeighborIndex(
const int gridIdx,
const int NeighborGridIdx );
619 void PrintExtent(
int extent[6] );
628 std::vector< std::vector<vtkStructuredNeighbor> >
Neighbors;
642 const int gridIdx,
const int NeighborGridIdx )
644 assert(
"pre: Grid index is out-of-bounds!" &&
646 (gridIdx < static_cast<int>(this->NumberOfGrids)));
647 assert(
"pre: Neighbor grid index is out-of-bounds!" &&
648 (NeighborGridIdx >= 0) &&
649 (NeighborGridIdx < static_cast<int>(this->NumberOfGrids) ) );
651 std::pair<int,int> gridPair = std::make_pair(gridIdx,NeighborGridIdx);
652 assert(
"pre: Neighboring grid pair does not exist in hash!" &&
653 (this->NeighborPair2NeighborListIndex.find(gridPair) !=
654 this->NeighborPair2NeighborListIndex.end() ) );
656 return(this->NeighborPair2NeighborListIndex[gridPair]);
661 int *ghostedExtent,
int GridExtent[6],
662 const int minIdx,
const int maxIdx,
const int N )
664 assert(
"pre: Number of ghost layers must be N >= 1" && (N >= 1) );
665 assert(
"pre: ghosted extent pointer is nullptr" && ghostedExtent !=
nullptr);
667 ghostedExtent[minIdx] = GridExtent[minIdx]-N;
668 ghostedExtent[maxIdx] = GridExtent[maxIdx]+N;
671 ghostedExtent[minIdx] =
672 (ghostedExtent[minIdx] < this->WholeExtent[minIdx] )?
673 this->WholeExtent[minIdx] : ghostedExtent[minIdx];
674 ghostedExtent[maxIdx] =
675 (ghostedExtent[maxIdx] > this->WholeExtent[maxIdx])?
676 this->WholeExtent[maxIdx] : ghostedExtent[maxIdx];
681 const int gridID,
int ext[6] )
683 assert(
"pre: gridID is out-of-bounds" &&
684 (gridID >= 0) && (gridID < static_cast<int>(this->NumberOfGrids)));
685 assert(
"pre: ghosted-extents vector has not been allocated" &&
686 (this->NumberOfGrids == this->GhostedExtents.size()/6 ) );
688 for(
int i=0; i < 6; ++i )
690 this->GhostedExtents[ gridID*6+i ] = ext[i];
696 const int gridID,
int ext[6])
698 assert(
"pre: gridID out-of-bounds!" &&
699 (gridID >= 0 && gridID < static_cast<int>(this->NumberOfGrids)));
700 for(
int i=0; i < 6; ++i )
702 ext[i] = this->GridExtents[ gridID*6+i ];
708 const int gridID,
int ext[6])
710 assert(
"pre: gridID out-of-bounds!" &&
711 (gridID >= 0 && gridID < static_cast<int>(this->NumberOfGrids)));
713 if( this->GhostedExtents.size() == 0 )
715 ext[0] = ext[2] = ext[4] = -1;
716 ext[1] = ext[3] = ext[5] = 0;
717 vtkErrorMacro(
"No ghosted extents found for registered grid extends!!!" );
721 assert(
"GhostedExtents are not aligned with registered grid extents" &&
722 ( this->GhostedExtents.size() == this->GridExtents.size() ) );
723 for(
int i=0; i < 6; ++i )
725 ext[i] = this->GhostedExtents[ gridID*6+i ];
731 const int i,
const int j,
const int k,
int ext[6] )
733 if( !this->IsNodeWithinExtent( i,j,k, ext) )
739 switch( this->DataDescription )
742 if( i==ext[0] || i==ext[1] )
748 if( j==ext[2] || j==ext[3] )
754 if( k==ext[4] || k==ext[5] )
760 if( (i==ext[0] || i==ext[1]) ||
761 (j==ext[2] || j==ext[3]) )
767 if( (j==ext[2] || j==ext[3]) ||
768 (k==ext[4] || k==ext[5]) )
774 if( (i==ext[0] || i==ext[1]) ||
775 (k==ext[4] || k==ext[5]) )
781 if( (i==ext[0] || i==ext[1]) ||
782 (j==ext[2] || j==ext[3]) ||
783 (k==ext[4] || k==ext[5]) )
789 std::cout <<
"Data description is: " << this->DataDescription <<
"\n";
791 assert(
"pre: Undefined data-description!" &&
false );
799 const int i,
const int j,
const int k,
804 switch( this->DataDescription )
807 if( (GridExtent[0] < i) && (i < GridExtent[1]) )
813 if( (GridExtent[2] < j) && (j < GridExtent[3] ) )
819 if( (GridExtent[4] < k) && (k < GridExtent[5] ) )
825 if( (GridExtent[0] < i) && (i < GridExtent[1]) &&
826 (GridExtent[2] < j) && (j < GridExtent[3]) )
832 if( (GridExtent[2] < j) && (j < GridExtent[3] ) &&
833 (GridExtent[4] < k) && (k < GridExtent[5] ) )
839 if( (GridExtent[0] < i) && (i < GridExtent[1] ) &&
840 (GridExtent[4] < k) && (k < GridExtent[5] ) )
846 if( (GridExtent[0] < i) && (i < GridExtent[1]) &&
847 (GridExtent[2] < j) && (j < GridExtent[3]) &&
848 (GridExtent[4] < k) && (k < GridExtent[5]) )
854 std::cout <<
"Data description is: " << this->DataDescription <<
"\n";
856 assert(
"pre: Undefined data-description!" &&
false );
864 const int idx,
int A[2],
int B[2],
int overlap[2],
int orient[3] )
866 assert(
"pre: idx is out-of-bounds" && (idx >= 0) && (idx < 3) );
869 if( overlap[0] == overlap[1] )
875 else if( A[0] == B[1] )
882 assert(
"ERROR: Code should not reach here!" &&
false );
886 else if( this->IsSubset( A, B) )
888 if( (A[0] == B[0]) && (A[1] == B[1]) )
892 else if( this->StrictlyInsideBounds( A[0], B[0], B[1] ) &&
893 this->StrictlyInsideBounds( A[1], B[0], B[1] ) )
897 else if( A[0] == B[0] )
901 else if( A[1] == B[1] )
908 assert(
"ERROR: Code should not reach here!" &&
false );
912 else if( this->IsSubset( B, A ) )
917 else if( !(this->IsSubset(A,B) || this->IsSubset(A,B)) )
919 if( this->InBounds( A[0], B[0], B[1] ) )
923 else if( this->InBounds( A[1], B[0], B[1] ) )
930 assert(
"ERROR: Code should not reach here!" &&
false );
936 assert(
"ERROR: Code should not reach here!" &&
false );
942 const int idx,
const int ExtentLo,
const int ExtentHi,
943 const int OnLo,
const int OnHi,
const int NotOnBoundary )
945 if( idx == ExtentLo )
949 else if( idx == ExtentHi )
953 return NotOnBoundary;
958 const int gridID,
const int blockDirection )
961 assert(
"pre: gridID is out-of-bounds" &&
962 (gridID >=0) && (gridID < static_cast<int>(this->NumberOfGrids)));
963 assert(
"pre: BlockTopology has not been properly allocated" &&
964 (this->NumberOfGrids == this->BlockTopology.size()));
965 assert(
"pre: blockDirection is out-of-bounds" &&
966 (blockDirection >= 0) && (blockDirection < 6) );
968 if( this->BlockTopology[ gridID ] & (1 << blockDirection) )
977 const int gridID,
const int blockDirection )
980 assert(
"pre: gridID is out-of-bounds" &&
981 (gridID >=0) && (gridID < static_cast<int>(this->NumberOfGrids)));
982 assert(
"pre: BlockTopology has not been properly allocated" &&
983 (this->NumberOfGrids == this->BlockTopology.size()));
984 assert(
"pre: blockDirection is out-of-bounds" &&
985 (blockDirection >= 0) && (blockDirection < 6) );
987 this->BlockTopology[ gridID ] &= ~(1 << blockDirection);
992 const int gridID,
const int blockDirection )
995 assert(
"pre: gridID is out-of-bounds" &&
996 (gridID >=0) && (gridID < static_cast<int>(this->NumberOfGrids)));
997 assert(
"pre: BlockTopology has not been properly allocated" &&
998 (this->NumberOfGrids == this->BlockTopology.size()));
999 assert(
"pre: blockDirection is out-of-bounds" &&
1000 (blockDirection >= 0) && (blockDirection < 6) );
1001 this->BlockTopology[ gridID ] |= (1 << blockDirection);
1009 assert(
"pre: gridID is out-of-bounds" &&
1010 (gridID >=0) && (gridID < static_cast<int>(this->NumberOfGrids)));
1011 assert(
"pre: BlockTopology has not been properly allocated" &&
1012 (this->NumberOfGrids == this->BlockTopology.size()));
1013 for(
int i=0; i < 6; ++i )
1015 this->RemoveBlockConnection( gridID, i );
1024 assert(
"pre: gridID is out-of-bounds" &&
1025 (gridID >=0) && (gridID < static_cast<int>(this->NumberOfGrids)));
1026 assert(
"pre: BlockTopology has not been properly allocated" &&
1027 (this->NumberOfGrids == this->BlockTopology.size()));
1030 for(
int i=0; i < 6; ++i )
1032 if( this->HasBlockConnection( gridID, i ) )
1037 assert(
"post: count must be in [0,5]" && (count >=0 && count <= 6) );
1043 const unsigned int N )
1047 vtkErrorMacro(
"Number of grids cannot be 0.");
1051 this->NumberOfGrids = N;
1054 this->GridExtents.resize( 6*N,-1);
1055 this->Neighbors.resize( N );
1056 this->BlockTopology.resize( N );
int Cardinality(int S[2])
Returns the cardinality of a range S.
int GetNumberOfConnectingBlockFaces(const int gridID)
Returns the number of faces of the block corresponding to the given grid ID that are adjacent to at l...
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
int GetNumberOfNodesPerCell(const int dim)
Returns the number of nodes per cell according to the given dimension.
std::map< std::pair< int, int >, int > NeighborPair2NeighborListIndex
bool HasBlockConnection(const int gridID, const int blockDirection)
Checks if the block corresponding to the given grid ID has a block adjacent to it in the given block ...
boost::graph_traits< vtkGraph * >::vertex_descriptor target(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
represent and manipulate point attribute data
void AddBlockConnection(const int gridID, const int blockDirection)
Adds a block connection along the given direction for the block corresponding to the given gridID...
bool IsSubset(int A[2], int B[2])
Returns true iff A is a subset of B, otherwise false.
void SetGhostedGridExtent(const int gridID, int ext[6])
Sets the ghosted grid extent for the grid corresponding to the given grid ID to the given extent...
void GetGhostedGridExtent(const int gridID, int ext[6])
Returns the ghosted grid extent for the block corresponding the.
virtual void ComputeNeighbors()=0
Computes the grid neighboring topology for the domain.
represent and manipulate cell attribute data
std::vector< unsigned char > BlockTopology
std::vector< std::vector< vtkStructuredNeighbor > > Neighbors
bool InBounds(const int idx, const int Lo, const int Hi)
Returns true iff Lo <= idx <= Hi, otherwise false.
int GetNeighborIndex(const int gridIdx, const int NeighborGridIdx)
Given a global grid ID and the neighbor grid ID, this method returns the neighbor index w...
void GetGhostedExtent(int *ghostedExtent, int GridExtent[6], const int minIdx, const int maxIdx, const int N)
Gets the ghosted extent from the given grid extent along the dimension given by minIdx and maxIdx...
void DetermineNeighborOrientation(const int idx, int A[2], int B[2], int overlap[2], int orient[3])
Given two overlapping extents A,B and the corresponding overlap extent this method computes A's relat...
void SetNumberOfGrids(const unsigned int N) override
Set/Get the total number of domains distributed among processors.
void RemoveBlockConnection(const int gridID, const int blockDirection)
Removes a block connection along the given direction for the block corresponding to the given gridID...
void GetGridExtent(const int gridID, int extent[6])
Returns the grid extent of the grid corresponding to the given grid ID.
vtkStructuredGridConnectivity is a concrete instance of vtkObject that implements functionality for c...
std::vector< int > GhostedExtents
a simple class to control print indentation
list of point or cell ids
A superclass that defines the interface to be implemented by all concrete grid connectivity classes...
virtual void SetNumberOfGrids(const unsigned int N)=0
Sets the total number of grids in the domain.
bool IsNodeInterior(const int i, const int j, const int k, int GridExtent[6])
Checks if the node, corresponding to the given global i,j,k coordinates is within the interior of the...
bool IsNodeWithinExtent(const int i, const int j, const int k, int GridExtent[6])
Checks if the node corresponding to the given global i,j,k coordinates is within the given extent...
dynamic, self-adjusting array of unsigned char
int Get1DOrientation(const int idx, const int ExtentLo, const int ExtentHi, const int OnLo, const int OnHi, const int NotOnBoundary)
A helper method that computes the 1-D i-j-k orientation to facilitate the implementation of GetNodeBl...
An internal, light-weight class used to store neighbor information.
bool StrictlyInsideBounds(const int idx, const int Lo, const int Hi)
Returns true iff Lo < idx < Hi, otherwise false.
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
int GetNumberOfNeighbors(const int gridID)
Returns the number of neighbors for the grid corresponding to the given grid ID.
bool IsNodeOnBoundaryOfExtent(const int i, const int j, const int k, int ext[6])
Checks if the node corresponding to the given global i,j,k coordinates is on the boundary of the give...
void AllocateUserRegisterDataStructures()
Allocate/De-allocate the data-structures where the user-supplied grids will be registered.
virtual void FillGhostArrays(const int gridId, vtkUnsignedCharArray *nodesArray, vtkUnsignedCharArray *cellsArray)=0
Fills the ghost arrays for the given grid.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
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< int > GridExtents
represent and manipulate 3D points
void ClearBlockConnections(const int gridID)
Clears all block connections for the block corresponding to the given grid ID.
represent and manipulate fields of data