From 6d1838d88e3659fcaa45e90308f745d078199c74 Mon Sep 17 00:00:00 2001
From: "TESLA03\\Master" <a.wellmann@tu-bs.de>
Date: Tue, 20 Jul 2021 13:14:01 +0200
Subject: [PATCH] Refactor function getFluidNodesIndices in GridImpl

No need to pass node types anymore
---
 src/gpu/GridGenerator/grid/Grid.h               |  9 +++++----
 .../grid/GridBuilder/MultipleGridBuilder.cpp    |  4 ++--
 .../grid/GridBuilder/MultipleGridBuilder.h      |  1 +
 src/gpu/GridGenerator/grid/GridImp.cu           | 17 +++++++++++++----
 src/gpu/GridGenerator/grid/GridImp.h            |  8 +++++---
 .../Parameter/NodeIndicesMultiGPU.h             |  7 ++++++-
 src/gpu/VirtualFluids_GPU/Parameter/Parameter.h |  1 -
 7 files changed, 32 insertions(+), 15 deletions(-)

diff --git a/src/gpu/GridGenerator/grid/Grid.h b/src/gpu/GridGenerator/grid/Grid.h
index bbb3242c9..91d5c5ccd 100644
--- a/src/gpu/GridGenerator/grid/Grid.h
+++ b/src/gpu/GridGenerator/grid/Grid.h
@@ -28,10 +28,6 @@ public:
     HOSTDEVICE virtual uint getSparseSize() const = 0;
     HOSTDEVICE virtual uint getSize() const = 0;
 
-    CUDA_HOST virtual void findMatrixIDsGEO_FLUID(uint *typeOfGridNode) = 0;
-    HOSTDEVICE virtual uint getGeoFluidSize() const = 0;
-    HOSTDEVICE virtual const std::vector<uint> *getGeoFluidNodes() const = 0;
-
     HOSTDEVICE virtual real getStartX() const = 0;
     HOSTDEVICE virtual real getStartY() const = 0;
     HOSTDEVICE virtual real getStartZ() const = 0;
@@ -145,6 +141,11 @@ public:
 
     virtual void repairCommunicationInices(int direction) = 0;
 
+    // needed for CUDA Streams MultiGPU
+    virtual void findMatrixIDsGEO_FLUID()                     = 0;
+    virtual uint getGeoFluidSize() const                      = 0;
+    virtual const std::vector<uint> *getGeoFluidNodes() const = 0;
+
 };
 
 #endif
diff --git a/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilder.cpp b/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilder.cpp
index ef2048289..3df529d66 100644
--- a/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilder.cpp
+++ b/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilder.cpp
@@ -602,8 +602,8 @@ void MultipleGridBuilder::findCommunicationIndices(int direction, LbmOrGks lbmOr
 
 void MultipleGridBuilder::findGeoFluidNodes()
 {
-    //for (uint i = 0; i < grids.size(); i++)
-    //    grids[i]->findMatrixIDsGEO_FLUID();
+    for (uint i = 0; i < grids.size(); i++)
+        grids[i]->findMatrixIDsGEO_FLUID();
 }
 
 const std::vector<uint> *MultipleGridBuilder::getGeoFluidSizes() const
diff --git a/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilder.h b/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilder.h
index d64a8c2a4..0d5b46387 100644
--- a/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilder.h
+++ b/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilder.h
@@ -85,6 +85,7 @@ public:
 
     GRIDGENERATOR_EXPORT void findCommunicationIndices( int direction, LbmOrGks lbmOrGks );
 
+    // needed for CUDA Streams MultiGPU
     void findGeoFluidNodes();
     GRIDGENERATOR_EXPORT const std::vector<uint> *getGeoFluidSizes() const;
     GRIDGENERATOR_EXPORT const std::vector<const std::vector<uint> *> *getGeoFluidNodeIndices() const;
diff --git a/src/gpu/GridGenerator/grid/GridImp.cu b/src/gpu/GridGenerator/grid/GridImp.cu
index 7e1aae190..76b3bee59 100644
--- a/src/gpu/GridGenerator/grid/GridImp.cu
+++ b/src/gpu/GridGenerator/grid/GridImp.cu
@@ -25,7 +25,6 @@
 
 #include "utilities/communication.h"
 #include "utilities/math/Math.h"
-#include <gpu/VirtualFluids_GPU/LBM/LB.h>
 
 CONSTANT int DIRECTIONS[DIR_END_MAX][DIMENSION];
 
@@ -859,12 +858,22 @@ CUDA_HOST void GridImp::updateSparseIndices()
     sparseSize = size - removedNodes;
 }
 
-CUDA_HOST void GridImp::findMatrixIDsGEO_FLUID(uint *typeOfGridNode) // typeOfGridNode = para->getParD(level)->geoSP[index]
+CUDA_HOST void GridImp::findMatrixIDsGEO_FLUID() // typeOfGridNode = para->getParD(level)->geoSP[index]
 {
+    // auf Basis von getNodeValues und updateSparseIndices
     int removedNodes = 0;
     for (uint index = 0; index < size; index++) {
-        if (typeOfGridNode[index] == GEO_FLUID)            
-            geoFluidNodes.push_back(index);           
+        if (this->sparseIndices[index] == -1) {
+            removedNodes++;
+            continue;
+        }
+
+        if (this->field.isFluid(index))
+            // + 1 for numbering shift between GridGenerator and VF_GPU
+            geoFluidNodes.push_back(index+1); //+1 notwendig?
+
+        /*if (typeOfGridNode[index] == GEO_FLUID)            
+            geoFluidNodes.push_back(index);  */         
         else
             removedNodes++;        
     }
diff --git a/src/gpu/GridGenerator/grid/GridImp.h b/src/gpu/GridGenerator/grid/GridImp.h
index 169c77fde..80eb37be3 100644
--- a/src/gpu/GridGenerator/grid/GridImp.h
+++ b/src/gpu/GridGenerator/grid/GridImp.h
@@ -195,8 +195,6 @@ public:
     HOSTDEVICE real getDelta() const override;
     HOSTDEVICE uint getSize() const override;
     HOSTDEVICE uint getSparseSize() const override;
-    HOSTDEVICE uint getGeoFluidSize() const override;
-    HOSTDEVICE const std::vector<uint> *getGeoFluidNodes() const override;
     HOSTDEVICE int getSparseIndex(uint matrixIndex) const override;
     CUDA_HOST real* getDistribution() const override;
     CUDA_HOST int* getDirection() const override;
@@ -246,7 +244,6 @@ public:
     CUDA_HOST virtual void findSparseIndices(SPtr<Grid> fineGrid) override;
 
     CUDA_HOST void updateSparseIndices();
-    CUDA_HOST void findMatrixIDsGEO_FLUID(uint *typeOfGridNode) override;
     HOSTDEVICE void setNeighborIndices(uint index);
     HOSTDEVICE real getFirstFluidNode(real coords[3], int direction, real startCoord) const override;
     HOSTDEVICE real getLastFluidNode(real coords[3], int direction, real startCoord) const override;
@@ -319,6 +316,11 @@ public:
 
     void repairCommunicationInices(int direction) override;
 
+    // needed for CUDA Streams MultiGPU
+    void findMatrixIDsGEO_FLUID() override;
+    uint getGeoFluidSize() const override;
+    const std::vector<uint> *getGeoFluidNodes() const override;
+
 public:
 
     struct CommunicationIndices
diff --git a/src/gpu/VirtualFluids_GPU/Parameter/NodeIndicesMultiGPU.h b/src/gpu/VirtualFluids_GPU/Parameter/NodeIndicesMultiGPU.h
index 4544864a3..ed4aad52c 100644
--- a/src/gpu/VirtualFluids_GPU/Parameter/NodeIndicesMultiGPU.h
+++ b/src/gpu/VirtualFluids_GPU/Parameter/NodeIndicesMultiGPU.h
@@ -1,3 +1,6 @@
+#ifndef INDICES_MULTIGPU_H
+#define INDICES_MULTIGPU_H
+
 #include <vector>
 #include <memory>
 #include "basics/Core/DataTypes.h"
@@ -12,4 +15,6 @@ public:
 
     uint getGeoFluidSize(uint gridNumber);
     const std::vector<uint>* getGeoFluidNodeIndices(uint gridNumber);
-};
\ No newline at end of file
+};
+
+#endif
\ No newline at end of file
diff --git a/src/gpu/VirtualFluids_GPU/Parameter/Parameter.h b/src/gpu/VirtualFluids_GPU/Parameter/Parameter.h
index 9ea35d9ff..d0d49fd23 100644
--- a/src/gpu/VirtualFluids_GPU/Parameter/Parameter.h
+++ b/src/gpu/VirtualFluids_GPU/Parameter/Parameter.h
@@ -840,7 +840,6 @@ private:
     
     // CUDA Streams Multi GPU
     std::shared_ptr<NodeIndicesMultiGPU> nodeIndicesMultiGPU;
-
 public:
     void setNodeIndicesMultiGPU(std::shared_ptr<NodeIndicesMultiGPU> nodeIndicesMultiGPU);
     std::shared_ptr<NodeIndicesMultiGPU> getNodeIndicesMultiGPU();
-- 
GitLab