diff --git a/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/GridGenerator.cpp b/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/GridGenerator.cpp index 99f3de8a80d05865496ed534b0d3ee93deb2b8ad..c96bd40131c5594be3e07e0c551a37f8a3d69bca 100644 --- a/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/GridGenerator.cpp +++ b/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/GridGenerator.cpp @@ -6,6 +6,7 @@ #include <sstream> #include <iostream> +#include <algorithm> #include "utilities/math/Math.h" #include "LBM/LB.h" #include "Output/QDebugWriter.hpp" @@ -801,13 +802,10 @@ void GridGenerator::reorderSendIndicesForCommAfterFtoC(int *sendIndices, int &nu int direction, int level, int j, std::vector<uint> &sendIndicesForCommAfterFtoCPositions) { - uint sizeOfICellFCC = para->getParH(level)->K_CF; - uint sizeOfICellCFC = para->getParH(level)->K_FC; - *logging::out << logging::Logger::INFO_INTERMEDIATE << "reorder send indices for communication after fine to coarse: level: " << level << " direction: " << direction; - if (sizeOfICellFCC == 0 || sizeOfICellCFC == 0) + if (para->getParH(level)->K_CF == 0 || para->getParH(level)->K_FC == 0) *logging::out << logging::Logger::LOGGER_ERROR << "reorderSendIndicesForCommAfterFtoC(): iCellFCC needs to be inititalized before calling " "this function " @@ -821,22 +819,22 @@ void GridGenerator::reorderSendIndicesForCommAfterFtoC(int *sendIndices, int &nu std::array<int, 7> neighbors; uint numberOfSendIndices = builder->getNumberOfSendIndices(direction, level); + //iCellFCC for (uint posInSendIndices = 0; posInSendIndices < numberOfSendIndices; posInSendIndices++) { neighbors.fill(-1); - sparseIndexSend = sendIndices[posInSendIndices]; - - isInICellFCC = isSparseIndexInICellFCC(sizeOfICellFCC, sparseIndexSend, level); - isInICellCFC = findIndexInICellCFCandNeighbors(sizeOfICellCFC, sparseIndexSend, level, neighbors); - - if (isInICellFCC || isInICellCFC) + sparseIndexSend = sendIndices[posInSendIndices]; + if (isSparseIndexInICellFCC(para->getParH(level)->K_CF, sparseIndexSend, level)) addUniqueIndexToCommunicationVectors(sendIndicesAfterFtoC, sparseIndexSend, sendIndicesForCommAfterFtoCPositions, posInSendIndices); - for (int neighbor : neighbors) { - findIfSparseIndexIsInSendIndicesAndAddToCommVectors( - neighbor, sendIndices, numberOfSendIndices, sendIndicesAfterFtoC, sendIndicesForCommAfterFtoCPositions); - } } + // iCellCFC + std::vector<uint> nodesCFC; + aggregateNodesInICellCFC(level, nodesCFC); + for (auto sparseIndex : nodesCFC) + findIfSparseIndexIsInSendIndicesAndAddToCommVectors(sparseIndex, sendIndices, numberOfSendIndices, + sendIndicesAfterFtoC, sendIndicesForCommAfterFtoCPositions); + numberOfSendNeighborsAfterFtoC = (int)sendIndicesAfterFtoC.size(); findIndicesNotInCommAfterFtoC(numberOfSendIndices, sendIndices, sendIndicesAfterFtoC, sendIndicesOther); @@ -872,28 +870,27 @@ bool GridGenerator::isSparseIndexInICellFCC(uint sizeOfICellFCC, int sparseIndex return false; } -bool GridGenerator::findIndexInICellCFCandNeighbors(uint sizeOfICellCFC, int sparseIndex, int level, - std::array<int, 7> &neighbors) +void GridGenerator::aggregateNodesInICellCFC(int level, std::vector<uint> &nodesCFC) { - // check if sparse index is in ICellCFC. If true also return all 7 neighbors + uint sparseIndex; uint *neighborX = para->getParH(level)->neighborX_SP; uint *neighborY = para->getParH(level)->neighborY_SP; uint *neighborZ = para->getParH(level)->neighborZ_SP; - for (uint j = 0; j < sizeOfICellCFC; j++) { - if (sparseIndex < 0) - return false; - if (para->getParH(level)->intCF.ICellCFC[j] == (uint)sparseIndex) { - neighbors[0] = neighborX[sparseIndex]; - neighbors[1] = neighborY[sparseIndex]; - neighbors[2] = neighborZ[sparseIndex]; - neighbors[3] = neighborY[neighborX[sparseIndex]]; - neighbors[4] = neighborZ[neighborX[sparseIndex]]; - neighbors[5] = neighborZ[neighborY[sparseIndex]]; - neighbors[6] = neighborZ[neighborY[neighborX[sparseIndex]]]; - return true; - } + + for (int x = 0; x < para->getParH(level)->K_FC; x++) { + sparseIndex = para->getParH(level)->intCF.ICellCFC[x]; + nodesCFC.push_back(sparseIndex); + nodesCFC.push_back(neighborX[sparseIndex]); + nodesCFC.push_back(neighborY[sparseIndex]); + nodesCFC.push_back(neighborZ[sparseIndex]); + nodesCFC.push_back(neighborY[neighborX[sparseIndex]]); + nodesCFC.push_back(neighborZ[neighborX[sparseIndex]]); + nodesCFC.push_back(neighborZ[neighborY[sparseIndex]]); + nodesCFC.push_back(neighborZ[neighborY[neighborX[sparseIndex]]]); } - return false; + std::sort(nodesCFC.begin(), nodesCFC.end()); + auto iterator = std::unique(nodesCFC.begin(), nodesCFC.end()); + nodesCFC.erase(iterator, nodesCFC.end()); } void GridGenerator::addUniqueIndexToCommunicationVectors( diff --git a/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/GridGenerator.h b/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/GridGenerator.h index cf8d6ae371a09a15b35d7cc02ced9a45a844a5c6..a58a573cd65f8b1514fe8c652f367a4f0b120840 100644 --- a/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/GridGenerator.h +++ b/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/GridGenerator.h @@ -49,7 +49,7 @@ public: void reorderSendIndicesForCommAfterFtoC(int *sendIndices, int &numberOfSendNeighborsAfterFtoC, int direction, int level, int j, std::vector<uint> &sendIndicesForCommAfterFtoCPositions); bool isSparseIndexInICellFCC(uint sizeOfICellFCC, int sparseIndexSend, int level); - bool findIndexInICellCFCandNeighbors(uint sizeOfICellCFC, int sparseIndexSend, int level, std::array<int, 7> &neighbors); + void aggregateNodesInICellCFC(int level, std::vector<uint> &nodesCFC); void addUniqueIndexToCommunicationVectors(std::vector<int> &sendIndicesAfterFtoC, int &sparseIndexSend, std::vector<unsigned int> &sendIndicesForCommAfterFtoCPositions, uint &posInSendIndices) const;