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
39#include "vtkFiltersGeometryModule.h"
68 vtkSetVector6Macro(WholeExtent,
int);
69 vtkGetVector6Macro(WholeExtent,
int);
76 vtkGetMacro(DataDimension,
int);
95 void GetGridExtent(
const int gridID,
int extent[6]);
101 void SetGhostedGridExtent(
const int gridID,
int ext[6]);
106 void GetGhostedGridExtent(
const int gridID,
int ext[6]);
119 return (
static_cast<int>(this->Neighbors[gridID].
size()));
157 bool InBounds(
const int idx,
const int Lo,
const int Hi) {
return ((idx >= Lo) && (idx <= Hi)); }
164 return ((idx > Lo) && (idx < Hi));
172 return (this->InBounds(A[0], B[0], B[1]) && this->InBounds(A[1], B[0], B[1]));
199 assert(
"ERROR: code should not reach here!" &&
false);
229 int RealExtent[6],
unsigned char& pfield);
235 void MarkCellProperty(
unsigned char& pfield,
unsigned char* nodeGhostFields,
const int numNodes);
246 bool IsGhostNode(
int GridExtent[6],
int RealExtent[6],
const int i,
const int j,
const int k);
252 bool IsNodeOnBoundaryOfExtent(
const int i,
const int j,
const int k,
int ext[6]);
260 const int gridID,
int RealExtent[6],
const int i,
const int j,
const int k);
272 bool IsNodeInterior(
const int i,
const int j,
const int k,
int GridExtent[6]);
282 switch (this->DataDescription)
285 if ((GridExtent[0] <= i) && (i <= GridExtent[1]))
291 if ((GridExtent[2] <= j) && (j <= GridExtent[3]))
297 if ((GridExtent[4] <= k) && (k <= GridExtent[5]))
303 if ((GridExtent[0] <= i) && (i <= GridExtent[1]) && (GridExtent[2] <= j) &&
304 (j <= GridExtent[3]))
310 if ((GridExtent[2] <= j) && (j <= GridExtent[3]) && (GridExtent[4] <= k) &&
311 (k <= GridExtent[5]))
317 if ((GridExtent[0] <= i) && (i <= GridExtent[1]) && (GridExtent[4] <= k) &&
318 (k <= GridExtent[5]))
324 if ((GridExtent[0] <= i) && (i <= GridExtent[1]) && (GridExtent[2] <= j) &&
325 (j <= GridExtent[3]) && (GridExtent[4] <= k) && (k <= GridExtent[5]))
331 std::cout <<
"Data description is: " << this->DataDescription <<
"\n";
333 assert(
"pre: Undefined data-description!" &&
false);
343 const int i,
const int j,
int i2jOrientation[3],
int j2iOrientation[3],
int overlapExtent[6]);
353 void DetermineNeighborOrientation(
354 const int idx,
int A[2],
int B[2],
int overlap[2],
int orient[3]);
362 const int i,
const int j,
int ex1[6],
int ex2[6],
int orientation[3],
int ndim);
396 int A[2],
const int CardinalityOfA,
int B[2],
const int CardinalityOfB,
int overlap[2]);
424 bool HasBlockConnection(
const int gridID,
const int blockDirection);
440 void RemoveBlockConnection(
const int gridID,
const int blockDirection);
456 void AddBlockConnection(
const int gridID,
const int blockDirection);
462 void ClearBlockConnections(
const int gridID);
471 int GetNumberOfConnectingBlockFaces(
const int gridID);
485 const int i,
const int j,
const int k,
int ext[6],
int orientation[3]);
491 int Get1DOrientation(
const int idx,
const int ExtentLo,
const int ExtentHi,
const int OnLo,
492 const int OnHi,
const int NotOnBoundary);
505 void GetGhostedExtent(
506 int* ghostedExtent,
int GridExtent[6],
const int minIdx,
const int maxIdx,
const int N);
580 int GetNeighborIndex(
const int gridIdx,
const int NeighborGridIdx);
594 std::vector<std::vector<vtkStructuredNeighbor>>
Neighbors;
608 const int gridIdx,
const int NeighborGridIdx)
610 assert(
"pre: Grid index is out-of-bounds!" && (gridIdx >= 0) &&
612 assert(
"pre: Neighbor grid index is out-of-bounds!" && (NeighborGridIdx >= 0) &&
615 std::pair<int, int> gridPair = std::make_pair(gridIdx, NeighborGridIdx);
616 assert(
"pre: Neighboring grid pair does not exist in hash!" &&
618 this->NeighborPair2NeighborListIndex.end()));
625 int* ghostedExtent,
int GridExtent[6],
const int minIdx,
const int maxIdx,
const int N)
627 assert(
"pre: Number of ghost layers must be N >= 1" && (N >= 1));
628 assert(
"pre: ghosted extent pointer is nullptr" && ghostedExtent !=
nullptr);
630 ghostedExtent[minIdx] = GridExtent[minIdx] - N;
631 ghostedExtent[maxIdx] = GridExtent[maxIdx] + N;
634 ghostedExtent[minIdx] = (ghostedExtent[minIdx] < this->
WholeExtent[minIdx])
636 : ghostedExtent[minIdx];
637 ghostedExtent[maxIdx] = (ghostedExtent[maxIdx] > this->
WholeExtent[maxIdx])
639 : ghostedExtent[maxIdx];
645 assert(
"pre: gridID is out-of-bounds" && (gridID >= 0) &&
647 assert(
"pre: ghosted-extents vector has not been allocated" &&
650 for (
int i = 0; i < 6; ++i)
659 assert(
"pre: gridID out-of-bounds!" &&
660 (gridID >= 0 && gridID <
static_cast<int>(this->
NumberOfGrids)));
661 for (
int i = 0; i < 6; ++i)
670 assert(
"pre: gridID out-of-bounds!" &&
671 (gridID >= 0 && gridID <
static_cast<int>(this->
NumberOfGrids)));
675 ext[0] = ext[2] = ext[4] = -1;
676 ext[1] = ext[3] = ext[5] = 0;
677 vtkErrorMacro(
"No ghosted extents found for registered grid extends!!!");
681 assert(
"GhostedExtents are not aligned with registered grid extents" &&
683 for (
int i = 0; i < 6; ++i)
691 const int i,
const int j,
const int k,
int ext[6])
702 if (i == ext[0] || i == ext[1])
708 if (j == ext[2] || j == ext[3])
714 if (k == ext[4] || k == ext[5])
720 if ((i == ext[0] || i == ext[1]) || (j == ext[2] || j == ext[3]))
726 if ((j == ext[2] || j == ext[3]) || (k == ext[4] || k == ext[5]))
732 if ((i == ext[0] || i == ext[1]) || (k == ext[4] || k == ext[5]))
738 if ((i == ext[0] || i == ext[1]) || (j == ext[2] || j == ext[3]) ||
739 (k == ext[4] || k == ext[5]))
747 assert(
"pre: Undefined data-description!" &&
false);
755 const int i,
const int j,
const int k,
int GridExtent[6])
762 if ((GridExtent[0] < i) && (i < GridExtent[1]))
768 if ((GridExtent[2] < j) && (j < GridExtent[3]))
774 if ((GridExtent[4] < k) && (k < GridExtent[5]))
780 if ((GridExtent[0] < i) && (i < GridExtent[1]) && (GridExtent[2] < j) && (j < GridExtent[3]))
786 if ((GridExtent[2] < j) && (j < GridExtent[3]) && (GridExtent[4] < k) && (k < GridExtent[5]))
792 if ((GridExtent[0] < i) && (i < GridExtent[1]) && (GridExtent[4] < k) && (k < GridExtent[5]))
798 if ((GridExtent[0] < i) && (i < GridExtent[1]) && (GridExtent[2] < j) &&
799 (j < GridExtent[3]) && (GridExtent[4] < k) && (k < GridExtent[5]))
807 assert(
"pre: Undefined data-description!" &&
false);
815 const int idx,
int A[2],
int B[2],
int overlap[2],
int orient[3])
817 assert(
"pre: idx is out-of-bounds" && (idx >= 0) && (idx < 3));
820 if (overlap[0] == overlap[1])
826 else if (A[0] == B[1])
833 assert(
"ERROR: Code should not reach here!" &&
false);
839 if ((A[0] == B[0]) && (A[1] == B[1]))
848 else if (A[0] == B[0])
852 else if (A[1] == B[1])
859 assert(
"ERROR: Code should not reach here!" &&
false);
870 if (this->
InBounds(A[0], B[0], B[1]))
874 else if (this->
InBounds(A[1], B[0], B[1]))
881 assert(
"ERROR: Code should not reach here!" &&
false);
887 assert(
"ERROR: Code should not reach here!" &&
false);
893 const int ExtentHi,
const int OnLo,
const int OnHi,
const int NotOnBoundary)
899 else if (idx == ExtentHi)
903 return NotOnBoundary;
908 const int gridID,
const int blockDirection)
911 assert(
"pre: gridID is out-of-bounds" && (gridID >= 0) &&
913 assert(
"pre: BlockTopology has not been properly allocated" &&
915 assert(
"pre: blockDirection is out-of-bounds" && (blockDirection >= 0) && (blockDirection < 6));
926 const int gridID,
const int blockDirection)
929 assert(
"pre: gridID is out-of-bounds" && (gridID >= 0) &&
931 assert(
"pre: BlockTopology has not been properly allocated" &&
933 assert(
"pre: blockDirection is out-of-bounds" && (blockDirection >= 0) && (blockDirection < 6));
940 const int gridID,
const int blockDirection)
943 assert(
"pre: gridID is out-of-bounds" && (gridID >= 0) &&
945 assert(
"pre: BlockTopology has not been properly allocated" &&
947 assert(
"pre: blockDirection is out-of-bounds" && (blockDirection >= 0) && (blockDirection < 6));
955 assert(
"pre: gridID is out-of-bounds" && (gridID >= 0) &&
957 assert(
"pre: BlockTopology has not been properly allocated" &&
959 for (
int i = 0; i < 6; ++i)
969 assert(
"pre: gridID is out-of-bounds" && (gridID >= 0) &&
971 assert(
"pre: BlockTopology has not been properly allocated" &&
975 for (
int i = 0; i < 6; ++i)
982 assert(
"post: count must be in [0,5]" && (count >= 0 && count <= 6));
991 vtkErrorMacro(
"Number of grids cannot be 0.");
A superclass that defines the interface to be implemented by all concrete grid connectivity classes.
void AllocateUserRegisterDataStructures()
Allocate/De-allocate the data-structures where the user-supplied grids will be registered.
virtual void SetNumberOfGrids(const unsigned int N)=0
Sets the total number of grids in the domain.
unsigned int NumberOfGrids
represent and manipulate cell attribute data
represent and manipulate fields of data
list of point or cell ids
a simple class to control print indentation
represent and manipulate point attribute data
represent and manipulate 3D points
vtkStructuredGridConnectivity is a concrete instance of vtkObject that implements functionality for c...
void ComputeNeighborSendAndRcvExtent(const int gridID, const int N)
This method computes, the send and rcv extents for each neighbor of each grid.
bool IsSubset(int A[2], int B[2])
Returns true iff A is a subset of B, otherwise false.
vtkStructuredNeighbor GetGridNeighbor(const int gridID, const int nei)
Returns the neighbor corresponding to the index nei for the grid with the given (global) grid ID.
~vtkStructuredGridConnectivity() override
void SetBlockTopology(const int gridID)
Sets the block topology connections for the grid corresponding to gridID.
void AllocateCellData(vtkCellData *RCD, const int N, vtkCellData *CD)
Adds/creates all the arrays in the reference grid cell data, RCD, to the user-supplied cell data inst...
void GetIJKBlockOrientation(const int i, const int j, const int k, int ext[6], int orientation[3])
Given i-j-k coordinates and the grid defined by tis extent, ext, this method determines IJK orientati...
void CopyFieldData(vtkFieldData *source, vtkIdType sourceIdx, vtkFieldData *target, vtkIdType targetIdx)
Loops through all arrays in the source and for each array, it copies the tuples from sourceIdx to the...
void CreateGhostedMaskArrays(const int gridID)
This method creates the ghosted mask arrays, i.e., the NodeGhostArrays and the CellGhostArrays for th...
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...
void FillNodesGhostArray(const int gridID, const int dataDescription, int GridExtent[6], int RealExtent[6], vtkUnsignedCharArray *nodesArray)
Fills the ghost array for the nodes.
void CreateGhostedExtent(const int gridID, const int N)
Creates the ghosted extent of the grid corresponding to the given gridID.
void CreateGhostLayers(const int N=1) override
Creates ghost layers.
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 EstablishNeighbors(const int i, const int j)
Establishes the neighboring information between the two grids corresponding to grid ids "i" and "j" w...
void PrintExtent(int extent[6])
Prints the extent, used for debugging.
void SetNeighbors(const int i, const int j, int i2jOrientation[3], int j2iOrientation[3], int overlapExtent[6])
Creates a neighbor from i-to-j and from j-to-i.
void TransferRegisteredDataToGhostedData(const int gridID)
This method transfers the registered grid data to the corresponding ghosted grid data.
void TransferLocalNeighborData(const int gridID, const vtkStructuredNeighbor &Neighbor)
This method transfers the fields.
void GetRealExtent(const int gridID, int GridExtent[6], int RealExtent[6])
Given a grid extent, this method computes the RealExtent.
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.
virtual void RegisterGrid(const int gridID, int extents[6], vtkUnsignedCharArray *nodesGhostArray, vtkUnsignedCharArray *cellGhostArray, vtkPointData *pointData, vtkCellData *cellData, vtkPoints *gridNodes)
Registers the current grid corresponding to the grid ID by its global extent w.r.t.
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 ...
int Cardinality(int S[2])
Returns the cardinality of a range S.
void ComputeNeighbors() override
Computes neighboring information.
void SearchNeighbors(const int gridID, const int i, const int j, const int k, vtkIdList *neiList)
Given a point (i,j,k) belonging to the grid corresponding to the given gridID, this method searches f...
bool IsGhostNode(int GridExtent[6], int RealExtent[6], const int i, const int j, const int k)
Checks if the node corresponding to the given global i,j,k coordinates is a ghost node or not.
void MarkNodeProperty(const int gridID, const int i, const int j, const int k, int ext[6], int RealExtent[6], unsigned char &pfield)
Marks the node properties with the node with the given global i,j,k grid coordinates w....
void ClearBlockConnections(const int gridID)
Clears all block connections for the block corresponding to the given grid ID.
void MarkCellProperty(unsigned char &pfield, unsigned char *nodeGhostFields, const int numNodes)
Marks the cell property for the cell composed by the nodes with the given ghost fields.
bool IsNodeOnBoundary(const int i, const int j, const int k)
Checks if the node corresponding to the given global i,j,k coordinates touches the real boundaries of...
void AllocatePointData(vtkPointData *RPD, const int N, vtkPointData *PD)
Adds/creates all the arrays in the reference grid point data, RPD, to the user-supplied point data in...
bool IsNodeOnSharedBoundary(const int gridID, int RealExtent[6], const int i, const int j, const int k)
Checks if the node corresponding to the given global i,j,k coordinates is on the shared boundary,...
virtual void TransferGhostDataFromNeighbors(const int gridID)
This method transfers the fields (point data and cell data) to the ghost extents from the neighboring...
std::vector< unsigned char > BlockTopology
void FillGhostArrays(const int gridID, vtkUnsignedCharArray *nodesArray, vtkUnsignedCharArray *cellsArray) override
Fills the mesh property arrays, nodes and cells, for the grid corresponding to the given grid ID.
std::vector< int > GhostedExtents
void AddBlockConnection(const int gridID, const int blockDirection)
Adds a block connection along the given direction for the block corresponding to the given gridID.
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 DetectNeighbors(const int i, const int j, int ex1[6], int ex2[6], int orientation[3], int ndim)
Detects if the two extents, ex1 and ex2, corresponding to the grids with grid IDs i,...
void CopyCoordinates(vtkPoints *source, vtkIdType sourceIdx, vtkPoints *target, vtkIdType targetIdx)
Copies the coordinates from the source points to the target points.
void RemoveBlockConnection(const int gridID, const int blockDirection)
Removes a block connection along the given direction for the block corresponding to the given gridID.
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 GetGridExtent(const int gridID, int extent[6])
Returns the grid extent of the grid corresponding to the given grid ID.
bool InBounds(const int idx, const int Lo, const int Hi)
Returns true iff Lo <= idx <= Hi, otherwise false.
std::map< std::pair< int, int >, int > NeighborPair2NeighborListIndex
void GetGhostedGridExtent(const int gridID, int ext[6])
Returns the ghosted grid extent for the block corresponding the.
void InitializeGhostData(const int gridID)
This method initializes the ghost data according to the computed ghosted grid extent for the grid wit...
int PartialOverlap(int A[2], const int CardinalityOfA, int B[2], const int CardinalityOfB, int overlap[2])
Checks if the intervals A,B partially overlap.
bool StrictlyInsideBounds(const int idx, const int Lo, const int Hi)
Returns true iff Lo < idx < Hi, otherwise false.
vtkIdList * GetNeighbors(const int gridID, int *extents)
Returns the list of neighboring blocks for the given grid and the corresponding overlapping extents a...
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 FillCellsGhostArray(const int dataDescription, const int numNodesPerCell, int dims[3], int CellExtent[6], vtkUnsignedCharArray *nodesArray, vtkUnsignedCharArray *cellsArray)
Fills the ghost array for the grid cells.
int DoPartialOverlap(int s[2], int S[2], int overlap[2])
Checks if the internals s,S partially overlap where |s| < |S|.
std::vector< int > GridExtents
vtkStructuredGridConnectivity()
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,...
int GetNumberOfNodesPerCell(const int dim)
Returns the number of nodes per cell according to the given dimension.
std::vector< std::vector< vtkStructuredNeighbor > > Neighbors
static vtkStructuredGridConnectivity * New()
int IntervalOverlap(int A[2], int B[2], int overlap[2])
Checks if the intervals A,B overlap.
int GetNumberOfNeighbors(const int gridID)
Returns the number of neighbors for the grid corresponding to the given grid ID.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
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...
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...
void AcquireDataDescription()
Based on the user-supplied WholeExtent, this method determines the topology of the structured domain,...
void SetNumberOfGrids(const unsigned int N) override
Set/Get the total number of domains distributed among processors.
An internal, light-weight class used to store neighbor information.
dynamic, self-adjusting array of unsigned char
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
boost::graph_traits< vtkGraph * >::vertex_descriptor target(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)