diff --git a/src/gpu/GridGenerator/grid/GridBuilder/GridBuilder.h b/src/gpu/GridGenerator/grid/GridBuilder/GridBuilder.h index e1fb6e5cd1075572d68c6ba4735d11762fd8d9f1..f4367f74bda79a434e3be357d40441e5beeec5d7 100644 --- a/src/gpu/GridGenerator/grid/GridBuilder/GridBuilder.h +++ b/src/gpu/GridGenerator/grid/GridBuilder/GridBuilder.h @@ -91,8 +91,8 @@ public: uint sizeOfICellCFC, uint *neighborX, uint *neighborY, uint *neighborZ, int direction, int level) = 0; virtual void getAndReorderReceiveIndices(int *recvIndices, uint &numberOfRecvNeighborsAfterFtoC, - uint *iCellFCCBorder, uint sizeOfICellFCCBorder, int direction, int level, - bool receiveIndicesNeedToBeReordered) = 0; + std::vector<uint> &sendIndicesForCommAfterFtoCPositions, int direction, + int level) = 0; virtual uint getNumberOfFluidNodes(unsigned int level) const = 0; diff --git a/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.cpp b/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.cpp index 79669bcef5383a8fcbfb6512df3ddeb8f9aaee4d..b51dc9dee67f90e7cc0a535069419983c1696839 100644 --- a/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.cpp +++ b/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.cpp @@ -280,16 +280,14 @@ LevelGridBuilder::getAndReorderSendIndices(int *sendIndices, uint &numberOfSendN return sendIndicesForCommAfterFtoCPositions; } -GRIDGENERATOR_EXPORT void LevelGridBuilder::getAndReorderReceiveIndices(int *recvIndices, - uint &numberOfRecvNeighborsAfterFtoC, - uint *iCellFCCBorder, uint sizeOfICellFCCBorder, - int direction, int level, - bool receiveIndicesNeedToBeReordered) +GRIDGENERATOR_EXPORT void +LevelGridBuilder::getAndReorderReceiveIndices(int *recvIndices, uint &numberOfRecvNeighborsAfterFtoC, + std::vector<uint> &sendIndicesForCommAfterFtoCPositions, int direction, + int level) { getReceiveIndices(recvIndices, direction, level); - if (receiveIndicesNeedToBeReordered) - reorderRecvIndexForCommAfterFtoC(recvIndices, numberOfRecvNeighborsAfterFtoC, iCellFCCBorder, - sizeOfICellFCCBorder, direction, level); + reorderRecvIndicesForCommAfterFtoC(recvIndices, numberOfRecvNeighborsAfterFtoC, sendIndicesForCommAfterFtoCPositions, + direction, level); } GRIDGENERATOR_EXPORT void LevelGridBuilder::reorderSendIndicesForCommAfterFtoC( @@ -305,17 +303,13 @@ GRIDGENERATOR_EXPORT void LevelGridBuilder::reorderSendIndicesForCommAfterFtoC( << "reorderSendIndicesForCommAfterFtoC(): iCellFCC needs to be inititalized before calling " "this function " << "\n"; - uint numberOfSendIndices = getNumberOfSendIndices(direction, level); - if (numberOfSendIndices == 0) { - numberOfSendNeighborsAfterFtoC = 0; - return; - } int sparseIndexSend; bool isInICells; std::vector<int> sendIndicesAfterFtoC; std::vector<int> sendIndicesOther; int neighborToAddX, neighborToAddY, neighborToAddZ; + uint numberOfSendIndices = getNumberOfSendIndices(direction, level); for (uint posInSendIndices = 0; posInSendIndices < numberOfSendIndices; posInSendIndices++) { neighborToAddX = neighborToAddY = neighborToAddZ = -1; @@ -418,55 +412,38 @@ void LevelGridBuilder::findIfSparseIndexIsInSendIndicesAndAddToVectors( } } - -GRIDGENERATOR_EXPORT void LevelGridBuilder::reorderRecvIndexForCommAfterFtoC(int *recvIndices, uint &numberOfRecvNeighborsAfterFtoC, - uint *iCellFCCBorder, uint sizeOfICellFCCBorder, +GRIDGENERATOR_EXPORT void LevelGridBuilder::reorderRecvIndicesForCommAfterFtoC(int *recvIndices, uint &numberOfRecvNeighborsAfterFtoC, + std::vector<uint> &sendIndicesForCommAfterFtoCPositions, int direction, int level) { *logging::out << logging::Logger::INFO_INTERMEDIATE << "reorder receive indices for communication after fine to coarse: level: " << level << " direction: " << direction; - if (sizeOfICellFCCBorder == 0) + if (sendIndicesForCommAfterFtoCPositions.size() == 0) *logging::out << logging::Logger::LOGGER_ERROR - << "reorderRecvIndexForCommAfterFtoC(): iCellFCC needs to be inititalized before calling " - "this function " + << "reorderRecvIndicesForCommAfterFtoC(): sendIndicesForCommAfterFtoCPositions is empty." << "\n"; - uint numberOfSendIndices = getNumberOfReceiveIndices(direction, level); - if (numberOfSendIndices == 0) { - numberOfRecvNeighborsAfterFtoC = 0; - return; - } - - int sparseIndexRecv; - bool isInICellFCCBorder; + uint numberOfRecvIndices = getNumberOfReceiveIndices(direction, level); std::vector<int> recvIndicesAfterFtoC; std::vector<int> recvIndicesOther; + int sparseIndexRecv; - for (uint i = 0; i < numberOfSendIndices; i++) { - sparseIndexRecv = recvIndices[i]; - - // check if sparse index is in ICellFCC border - isInICellFCCBorder = false; - for (uint j = 0; j < sizeOfICellFCCBorder; j++) { - if (sparseIndexRecv < 0) - continue; - if (iCellFCCBorder[j] == (uint) sparseIndexRecv) { - isInICellFCCBorder = true; - break; - } - } - - // add index to corresponding vector - if (isInICellFCCBorder) - recvIndicesAfterFtoC.push_back(sparseIndexRecv); - else + // find recvIndices for Communication after fine to coarse + for (uint vectorPos : sendIndicesForCommAfterFtoCPositions) + recvIndicesAfterFtoC.push_back(recvIndices[vectorPos]); + + // add sparseIndices not in recvIndicesAfterFtoC to recvIndicesOther + for (uint posInRecvIndices = 0; posInRecvIndices < numberOfRecvIndices; posInRecvIndices++) { + sparseIndexRecv = recvIndices[posInRecvIndices]; + if (std::find(recvIndicesAfterFtoC.begin(), recvIndicesAfterFtoC.end(), sparseIndexRecv) == + recvIndicesAfterFtoC.end()) recvIndicesOther.push_back(sparseIndexRecv); } - numberOfRecvNeighborsAfterFtoC = (uint) recvIndicesAfterFtoC.size(); - - // copy new vectors back to receiveIndices array + numberOfRecvNeighborsAfterFtoC = (uint)recvIndicesAfterFtoC.size(); + + // copy new vectors back to sendIndices array for (uint i = 0; i < numberOfRecvNeighborsAfterFtoC; i++) recvIndices[i] = recvIndicesAfterFtoC[i]; for (uint i = 0; i < recvIndicesOther.size(); i++) @@ -475,8 +452,15 @@ GRIDGENERATOR_EXPORT void LevelGridBuilder::reorderRecvIndexForCommAfterFtoC(int *logging::out << logging::Logger::INFO_INTERMEDIATE << "... numberOfRecvNeighborsAfterFtoC: " << numberOfRecvNeighborsAfterFtoC << "\n"; - bool numberOfNodesIsCorrect = numberOfRecvNeighborsAfterFtoC + recvIndicesOther.size() == numberOfSendIndices; - std::cout << "correct number of nodes?: " << numberOfNodesIsCorrect << std::endl; + if (numberOfRecvNeighborsAfterFtoC + recvIndicesOther.size() != numberOfRecvIndices) { + *logging::out << logging::Logger::LOGGER_ERROR + << "reorderRecvIndicesForCommAfterFtoC(): incorrect number of nodes" + << "\n"; + std::cout << "numberOfRecvNeighborsAfterFtoC = " << numberOfRecvNeighborsAfterFtoC + << ", recvIndicesOther.size() = " << recvIndicesOther.size() + << ", numberOfRecvIndices = " << numberOfRecvIndices << std::endl; + } + } uint LevelGridBuilder::getNumberOfNodes(unsigned int level) const diff --git a/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.h b/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.h index dbfc5ad7021ba759fe3d3c0a50005228982573ba..2059438f112fba3acbff505cc29dd50582beac87 100644 --- a/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.h +++ b/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.h @@ -154,9 +154,8 @@ public: uint *iCellCFC, uint sizeOfICellCFC, uint *neighborX, uint *neighborY, uint *neighborZ, int direction, int level) override; GRIDGENERATOR_EXPORT void getAndReorderReceiveIndices(int *recvIndices, uint &numberOfRecvNeighborsAfterFtoC, - uint *iCellFCCBorder, uint sizeOfICellFCCBorder, - int direction, int level, - bool receiveIndicesNeedToBeReordered) override; + std::vector<uint> &sendIndicesForCommAfterFtoCPositions, + int direction, int level) override; GRIDGENERATOR_EXPORT void reorderSendIndicesForCommAfterFtoC(int *sendIndices, uint &numberOfSendNeighborsAfterFtoC, uint *iCellFCC, uint sizeOfICellFCC, uint *iCellCFC, uint sizeOfICellCFC, uint *neighborX, uint *neighborY, @@ -165,8 +164,8 @@ public: void findIfSparseIndexIsInSendIndicesAndAddToVectors(int sparseIndex, int *sendIndices, uint numberOfSendIndices, std::vector<int> &sendIndicesAfterFtoC, std::vector<uint> &sendIndicesForCommAfterFtoCPositions) const; - GRIDGENERATOR_EXPORT void reorderRecvIndexForCommAfterFtoC(int *recvIndices, uint &numberOfRecvNeighborsAfterFtoC, - uint *iCellFCCBorder, uint sizeOfICellFCCBorder, + GRIDGENERATOR_EXPORT void reorderRecvIndicesForCommAfterFtoC(int *recvIndices, uint &numberOfRecvNeighborsAfterFtoC, + std::vector<uint> &sendIndicesForCommAfterFtoCPositions, int direction, int level); }; diff --git a/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/GridGenerator.cpp b/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/GridGenerator.cpp index ed7ec278ef52cc6b35be1c6dc9840936afa03a46..a6feb721e9e040540e5d56a2b3e77b0e3397c9f6 100644 --- a/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/GridGenerator.cpp +++ b/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/GridGenerator.cpp @@ -338,8 +338,7 @@ void GridGenerator::allocArrays_BoundaryValues() builder->getAndReorderReceiveIndices( para->getParH(level)->recvProcessNeighborX[j].index, para->getParH(level)->numberOfRecvProcessNeighborsAfterFtoCX[j], - para->getParH(level)->intFC.ICellFCC, para->getParH(level)->intFC.kFC, direction, level, - level != builder->getNumberOfGridLevels() - 1); + sendIndicesForCommAfterFtoCPositions, direction, level); para->getParD(level)->numberOfSendProcessNeighborsAfterFtoCX[j] = para->getParH(level)->numberOfSendProcessNeighborsAfterFtoCX[j]; para->getParD(level)->numberOfRecvProcessNeighborsAfterFtoCX[j] = @@ -421,8 +420,7 @@ void GridGenerator::allocArrays_BoundaryValues() builder->getAndReorderReceiveIndices( para->getParH(level)->recvProcessNeighborY[j].index, para->getParH(level)->numberOfRecvProcessNeighborsAfterFtoCY[j], - para->getParH(level)->intFC.ICellFCC, para->getParH(level)->K_CF, direction, level, - level != builder->getNumberOfGridLevels() - 1); + sendIndicesForCommAfterFtoCPositions, direction, level); para->getParD(level)->numberOfSendProcessNeighborsAfterFtoCY[j] = para->getParH(level)->numberOfSendProcessNeighborsAfterFtoCY[j]; para->getParD(level)->numberOfRecvProcessNeighborsAfterFtoCY[j] = @@ -504,8 +502,7 @@ void GridGenerator::allocArrays_BoundaryValues() builder->getAndReorderReceiveIndices( para->getParH(level)->recvProcessNeighborZ[j].index, para->getParH(level)->numberOfRecvProcessNeighborsAfterFtoCZ[j], - para->getParH(level)->intFC.ICellFCC, para->getParH(level)->intFC.kFC, direction, level, - level != builder->getNumberOfGridLevels() - 1); + sendIndicesForCommAfterFtoCPositions, direction, level); para->getParD(level)->numberOfSendProcessNeighborsAfterFtoCZ[j] = para->getParH(level)->numberOfSendProcessNeighborsAfterFtoCZ[j]; para->getParD(level)->numberOfRecvProcessNeighborsAfterFtoCZ[j] =