From aad08178b4a17da46d926e264a24762b239aed2a Mon Sep 17 00:00:00 2001
From: Anna Wellmann <a.wellmann@tu-braunschweig.de>
Date: Tue, 14 Sep 2021 12:52:23 +0200
Subject: [PATCH] Add comments to findFluidNodeIndices in GridImp

---
 src/gpu/GridGenerator/grid/GridImp.cu | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/gpu/GridGenerator/grid/GridImp.cu b/src/gpu/GridGenerator/grid/GridImp.cu
index 895d77b42..9a6c88e58 100644
--- a/src/gpu/GridGenerator/grid/GridImp.cu
+++ b/src/gpu/GridGenerator/grid/GridImp.cu
@@ -861,7 +861,7 @@ CUDA_HOST void GridImp::updateSparseIndices()
 
 CUDA_HOST void GridImp::findFluidNodeIndices(bool splitDomain) 
 {
-    findFluidNodeIndicesBorder();
+    // find sparse index of all fluid nodes
     this->fluidNodeIndices.clear();
     for (uint index = 0; index < this->size; index++) {
         int sparseIndex = this->getSparseIndex(index);
@@ -871,24 +871,27 @@ CUDA_HOST void GridImp::findFluidNodeIndices(bool splitDomain)
             this->fluidNodeIndices.push_back((uint)sparseIndex+1);
     }
 
-    // If splitDomain: remove all indices in fluidNodeIndicesBorder from fluidNodeIndices
+    // If splitDomain: find fluidNodeIndicesBorder and remove all indices in fluidNodeIndicesBorder from fluidNodeIndices
     if (splitDomain) {
+        findFluidNodeIndicesBorder();
         std::sort(this->fluidNodeIndices.begin(), this->fluidNodeIndices.end());
-        auto it = std::set_difference(this->fluidNodeIndices.begin(), this->fluidNodeIndices.end(),
+        auto iterator = std::set_difference(this->fluidNodeIndices.begin(), this->fluidNodeIndices.end(),
                             this->fluidNodeIndicesBorder.begin(), this->fluidNodeIndicesBorder.end(),
                             this->fluidNodeIndices.begin());
-        this->fluidNodeIndices.resize(it - this->fluidNodeIndices.begin());
+        this->fluidNodeIndices.resize(iterator - this->fluidNodeIndices.begin());
     }
 }
 
 void GridImp::findFluidNodeIndicesBorder() {
     this->fluidNodeIndicesBorder.clear();
 
+    // resize fluidNodeIndicesBorder (for better performance in copy operation)
     size_t newSize = 0;
     for (CommunicationIndices& ci : this->communicationIndices)
         newSize += ci.sendIndices.size();    
     this->fluidNodeIndicesBorder.reserve(newSize);
 
+    // copy all send indices to fluidNodeIndicesBorder
     for (CommunicationIndices& ci : this->communicationIndices)
         std::copy(ci.sendIndices.begin(), ci.sendIndices.end(), std::back_inserter(this->fluidNodeIndicesBorder));
 
-- 
GitLab