From 8652459a2f1cb37c4fd25cce85390efb7acfc3a3 Mon Sep 17 00:00:00 2001
From: Soeren Peters <peters@irmb.tu-bs.de>
Date: Mon, 29 Jan 2018 15:38:10 +0100
Subject: [PATCH] - change order of creation of grids -> order in vector is the
 same

---
 src/GridGenerator/grid/Grid.cu                |  8 +--
 .../grid/GridBuilder/LevelGridBuilder.cpp     | 25 +++++-----
 .../grid/GridBuilder/LevelGridBuilder.h       |  2 +-
 src/GridGenerator/grid/GridInterface.cu       |  9 +++-
 src/GridGenerator/grid/GridInterface.cuh      |  4 +-
 .../GridCpuStrategy/GridCpuStrategy.cpp       |  4 +-
 .../GridCpuStrategy/GridCpuStrategy.h         |  2 +-
 src/VirtualFluids_GPU/LBM/Simulation.cpp      | 50 +++++++++----------
 targets/apps/HULC/main.cpp                    | 11 ++--
 9 files changed, 64 insertions(+), 51 deletions(-)

diff --git a/src/GridGenerator/grid/Grid.cu b/src/GridGenerator/grid/Grid.cu
index e19944e03..489b87ef7 100644
--- a/src/GridGenerator/grid/Grid.cu
+++ b/src/GridGenerator/grid/Grid.cu
@@ -57,8 +57,8 @@ HOST SPtr<Grid> Grid::makeShared(real startX, real startY, real startZ, real end
 
     time_t end = clock();
     real time = (real)(real(end - begin) / CLOCKS_PER_SEC);
-    *logging::out << logging::Logger::INTERMEDIATE << "Time initial field: " + SSTR(time / 1000) + "sec\n";
-    *logging::out << logging::Logger::INTERMEDIATE << "-------------------------------------------\n";
+    *logging::out << logging::Logger::LOW << "Time initial field: " + SSTR(time / 1000) + "sec\n";
+    *logging::out << logging::Logger::LOW << "-------------------------------------------\n";
 
     return grid;
 }
@@ -533,8 +533,10 @@ void Grid::setGridInterface(uint* gridInterfaceList, const uint* oldGridInterfac
 
 HOSTDEVICE void Grid::print() const
 {
-    printf("min: (%2.2f, %2.2f, %2.2f), max: (%2.2f, %2.2f, %2.2f), size: %d, delta: %2.2f\n", startX, startY, startZ,
+    printf("min: (%2.4f, %2.4f, %2.4f), max: (%2.4f, %2.4f, %2.4f), size: %d, delta: %2.4f\n", startX, startY, startZ,
            endX, endY, endZ, size, delta);
+    if(this->gridInterface)
+        this->gridInterface->print();
 }
 
 std::string Grid::toString() const
diff --git a/src/GridGenerator/grid/GridBuilder/LevelGridBuilder.cpp b/src/GridGenerator/grid/GridBuilder/LevelGridBuilder.cpp
index af665b7ca..75c2a8d6a 100644
--- a/src/GridGenerator/grid/GridBuilder/LevelGridBuilder.cpp
+++ b/src/GridGenerator/grid/GridBuilder/LevelGridBuilder.cpp
@@ -61,17 +61,13 @@ void LevelGridBuilder::verifyGridNeighbors()
     //    std::cout << grid->verifyNeighborIndices();
 }
 
-void LevelGridBuilder::addGrid(real minX, real minY, real minZ, real maxX, real maxY, real maxZ, real delta, const std::string& device, const std::string& distribution)
+VF_PUBLIC void LevelGridBuilder::addGrid(real minX, real minY, real minZ, real maxX, real maxY, real maxZ, real delta, const std::string& device, const std::string& distribution, bool periodictyX, bool periodictyY, bool periodictyZ)
 {
     const auto grid = GridFactory::makeGrid(minX, minY, minZ, maxX, maxY, maxZ, delta, device, distribution);
-    grids.push_back(grid);
+    grids.insert(grids.begin(), grid);
 
-    if(this->getNumberOfGridLevels() == 1)
-        grid->setPeriodicity(true, true, true);
-    else
-        grid->setPeriodicity(false, false, false);
+    grid->setPeriodicity(periodictyX, periodictyY, periodictyZ);
 
-    grid->print();
 
     this->removeOverlapNodes();
 }
@@ -96,7 +92,12 @@ void LevelGridBuilder::removeOverlapNodes()
 {
     const uint numberOfLevels = getNumberOfGridLevels();
     if(numberOfLevels > 1)
-        grids[numberOfLevels - 2]->removeOverlapNodes(grids[numberOfLevels - 1]);
+    {
+        grids[0]->removeOverlapNodes(grids[1]);
+        grids[0]->print();
+
+    }
+       
 }
 
 
@@ -261,10 +262,10 @@ void LevelGridBuilder::getNodeValues(real *xCoords, real *yCoords, real *zCoords
         xCoords[nodeNumber + 1] = x;
         yCoords[nodeNumber + 1] = y;
         zCoords[nodeNumber + 1] = z;
-        neighborX[nodeNumber + 1] = (unsigned int)(grid.neighborIndexX[i] + 1);
-        neighborY[nodeNumber + 1] = (unsigned int)(grid.neighborIndexY[i] + 1);
-        neighborZ[nodeNumber + 1] = (unsigned int)(grid.neighborIndexZ[i] + 1);
-        geo[nodeNumber + 1] = (unsigned int)grid.isSolid(i) ? GEOSOLID : GEOFLUID;
+        neighborX[nodeNumber + 1] = uint(grid.neighborIndexX[i] + 1);
+        neighborY[nodeNumber + 1] = uint(grid.neighborIndexY[i] + 1);
+        neighborZ[nodeNumber + 1] = uint(grid.neighborIndexZ[i] + 1);
+        geo[nodeNumber + 1] = uint(grid.isSolid(i) ? GEOSOLID : GEOFLUID);
         nodeNumber++;
     }
 }
diff --git a/src/GridGenerator/grid/GridBuilder/LevelGridBuilder.h b/src/GridGenerator/grid/GridBuilder/LevelGridBuilder.h
index 376e7c35b..25e38a588 100644
--- a/src/GridGenerator/grid/GridBuilder/LevelGridBuilder.h
+++ b/src/GridGenerator/grid/GridBuilder/LevelGridBuilder.h
@@ -32,7 +32,7 @@ public:
     VF_PUBLIC void verifyGridNeighbors();
 
     VF_PUBLIC virtual void addGrid(real minX, real minY, real minZ, real maxX, real maxY, real maxZ, real delta,
-                                   const std::string& device, const std::string& distribution);
+                                   const std::string& device, const std::string& distribution, bool periodictyX, bool periodictyY, bool periodictyZ);
 
 
     VF_PUBLIC virtual void meshGeometry(std::string input, int level);
diff --git a/src/GridGenerator/grid/GridInterface.cu b/src/GridGenerator/grid/GridInterface.cu
index bad079e33..e7d01b0ac 100644
--- a/src/GridGenerator/grid/GridInterface.cu
+++ b/src/GridGenerator/grid/GridInterface.cu
@@ -103,11 +103,16 @@ bool GridInterface::isOnInterface(Interface& interface, const real& x, const rea
     return isOnXYPlanes || isOnXZPlanes || isOnYZPlanes;
 }
 
-uint GridInterface::getIndexOnFinerGrid(const int& factor, const Grid* fineGrid, const real& x, const real& y, const real& z)
+HOSTDEVICE  uint GridInterface::getIndexOnFinerGrid(const real& factor, const Grid* fineGrid, const real& x, const real& y, const real& z)
 {
     const real xFine = x + factor * (fineGrid->delta * 0.5);
     const real yFine = y + factor * (fineGrid->delta * 0.5);
     const real zFine = z + factor * (fineGrid->delta * 0.5);
 
-    return fineGrid->transCoordToIndex(xFine, yFine, zFine);
+    return fineGrid->matrixIndex[fineGrid->transCoordToIndex(xFine, yFine, zFine)];
+}
+
+void GridInterface::print() const
+{
+    printf("Grid Interface - CF nodes: %d, FC nodes: %d\n", cf.numberOfEntries, fc.numberOfEntries);
 }
diff --git a/src/GridGenerator/grid/GridInterface.cuh b/src/GridGenerator/grid/GridInterface.cuh
index 04b859c14..77ce7efca 100644
--- a/src/GridGenerator/grid/GridInterface.cuh
+++ b/src/GridGenerator/grid/GridInterface.cuh
@@ -17,6 +17,8 @@ public:
     HOSTDEVICE void VF_PUBLIC findCF(const uint& index, const Grid* coarseGrid, const Grid* fineGrid);
     HOSTDEVICE void VF_PUBLIC findFC(const uint& index, const Grid* coarseGrid, const Grid* fineGrid);
 
+    HOSTDEVICE void VF_PUBLIC print() const;
+
     struct Interface
     {
         uint *fine, *coarse;
@@ -38,7 +40,7 @@ private:
 
     HOSTDEVICE static void findInterface(Interface& interface, const int& factor, const uint& index, const Grid* coarseGrid, const Grid* fineGrid);
     HOSTDEVICE static bool isOnInterface(Interface& interface, const real& x, const real& y, const real& z);
-    HOSTDEVICE static uint getIndexOnFinerGrid(const int& factor, const Grid* fineGrid, const real& x, const real& y, const real& z);
+    HOSTDEVICE static uint getIndexOnFinerGrid(const real& factor, const Grid* fineGrid, const real& x, const real& y, const real& z);
 };
 
 
diff --git a/src/GridGenerator/grid/GridStrategy/GridCpuStrategy/GridCpuStrategy.cpp b/src/GridGenerator/grid/GridStrategy/GridCpuStrategy/GridCpuStrategy.cpp
index 08ed751d2..ebb2ef384 100644
--- a/src/GridGenerator/grid/GridStrategy/GridCpuStrategy/GridCpuStrategy.cpp
+++ b/src/GridGenerator/grid/GridStrategy/GridCpuStrategy/GridCpuStrategy.cpp
@@ -67,13 +67,13 @@ void GridCpuStrategy::removeOverlapNodes(SPtr<Grid> grid, SPtr<Grid> finerGrid)
 {
     grid->gridInterface = new GridInterface(finerGrid.get());;
 
-    setOverlapNodesToInvalid(grid, finerGrid);
+    createGridInterface(grid, finerGrid);
     grid->removeInvalidNodes();
     findForNeighborsNewIndices(grid);
     findForGridInterfaceNewIndices(grid);
 }
 
-void GridCpuStrategy::setOverlapNodesToInvalid(SPtr<Grid> grid, SPtr<Grid> finerGrid)
+void GridCpuStrategy::createGridInterface(SPtr<Grid> grid, SPtr<Grid> finerGrid)
 {
     for (uint index = 0; index < grid->size; index++)
         grid->createGridInterface(index, *finerGrid.get());
diff --git a/src/GridGenerator/grid/GridStrategy/GridCpuStrategy/GridCpuStrategy.h b/src/GridGenerator/grid/GridStrategy/GridCpuStrategy/GridCpuStrategy.h
index 652d4c5b5..9cd9c9bf3 100644
--- a/src/GridGenerator/grid/GridStrategy/GridCpuStrategy/GridCpuStrategy.h
+++ b/src/GridGenerator/grid/GridStrategy/GridCpuStrategy/GridCpuStrategy.h
@@ -35,7 +35,7 @@ protected:
     static void findForNeighborsNewIndices(SPtr<Grid> grid);
     static void findForGridInterfaceNewIndices(SPtr<Grid> grid);
 
-    static void setOverlapNodesToInvalid(SPtr<Grid> grid, SPtr<Grid> finerGrid);
+    static void createGridInterface(SPtr<Grid> grid, SPtr<Grid> finerGrid);
 
 };
 
diff --git a/src/VirtualFluids_GPU/LBM/Simulation.cpp b/src/VirtualFluids_GPU/LBM/Simulation.cpp
index e3d2d32ad..1df792302 100644
--- a/src/VirtualFluids_GPU/LBM/Simulation.cpp
+++ b/src/VirtualFluids_GPU/LBM/Simulation.cpp
@@ -612,19 +612,19 @@ void Simulation::run()
 		} 
 		else
 		{
-			//KernelKumNewCompSP27(para->getParD(0)->numberofthreads,       
-			//					 para->getParD(0)->omega,			
-			//					 para->getParD(0)->geoSP, 
-			//					 para->getParD(0)->neighborX_SP, 
-			//					 para->getParD(0)->neighborY_SP, 
-			//					 para->getParD(0)->neighborZ_SP,
-			//					 para->getParD(0)->d0SP.f[0],    
-			//					 para->getParD(0)->size_Mat_SP,
-			//					 para->getParD(0)->size_Array_SP,
-			//					 0,
-			//					 para->getForcesDev(),
-			//					 para->getParD(0)->evenOrOdd); 
-			//getLastCudaError("KernelCasSPKum27 execution failed");
+			KernelKumNewCompSP27(para->getParD(0)->numberofthreads,       
+								 para->getParD(0)->omega,			
+								 para->getParD(0)->geoSP, 
+								 para->getParD(0)->neighborX_SP, 
+								 para->getParD(0)->neighborY_SP, 
+								 para->getParD(0)->neighborZ_SP,
+								 para->getParD(0)->d0SP.f[0],    
+								 para->getParD(0)->size_Mat_SP,
+								 para->getParD(0)->size_Array_SP,
+								 0,
+								 para->getForcesDev(),
+								 para->getParD(0)->evenOrOdd); 
+			getLastCudaError("KernelCasSPKum27 execution failed");
 
 			//KernelKumAA2016CompSP27(para->getParD(0)->numberofthreads,       
 			//					 para->getParD(0)->omega, 
@@ -639,18 +639,18 @@ void Simulation::run()
 			//					 para->getParD(0)->evenOrOdd); 
 			//getLastCudaError("KernelKumAA2016CompSP27 execution failed");
 
-			KernelCumulantD3Q27All4(para->getParD(0)->numberofthreads,
-									 para->getParD(0)->omega, 
-									 para->getParD(0)->geoSP, 
-									 para->getParD(0)->neighborX_SP, 
-									 para->getParD(0)->neighborY_SP, 
-									 para->getParD(0)->neighborZ_SP,
-									 para->getParD(0)->d0SP.f[0],    
-									 para->getParD(0)->size_Mat_SP,
-									 0,
-									 para->getForcesDev(),
-									 para->getParD(0)->evenOrOdd); 
-			getLastCudaError("KernelCumulantD3Q27All4 execution failed");
+			//KernelCumulantD3Q27All4(para->getParD(0)->numberofthreads,
+			//						 para->getParD(0)->omega, 
+			//						 para->getParD(0)->geoSP, 
+			//						 para->getParD(0)->neighborX_SP, 
+			//						 para->getParD(0)->neighborY_SP, 
+			//						 para->getParD(0)->neighborZ_SP,
+			//						 para->getParD(0)->d0SP.f[0],    
+			//						 para->getParD(0)->size_Mat_SP,
+			//						 0,
+			//						 para->getForcesDev(),
+			//						 para->getParD(0)->evenOrOdd); 
+			//getLastCudaError("KernelCumulantD3Q27All4 execution failed");
 		}
 		//////////////////////////////////////////////////////////////////////////
 
diff --git a/targets/apps/HULC/main.cpp b/targets/apps/HULC/main.cpp
index a30781123..a021bce38 100644
--- a/targets/apps/HULC/main.cpp
+++ b/targets/apps/HULC/main.cpp
@@ -233,18 +233,21 @@ void setParameters(std::shared_ptr<Parameter> para, std::unique_ptr<input::Input
 void multipleLevel(const std::string& configPath)
 {
     SPtr<LevelGridBuilder> gridBuilder(new LevelGridBuilder());
-    gridBuilder->addGrid(0.0, 0.0, 0.0, 100.0, 100.0, 100.0, 1.0, "cpu", "D3Q27");
-    gridBuilder->addGrid(10.25, 10.25, 10.25, 90.75, 90.75, 90.75, 0.5, "cpu", "D3Q27");
-    gridBuilder->addGrid(25.375, 25.375, 25.375, 75.625, 75.625, 75.625, 0.25, "cpu", "D3Q27");
+    //gridBuilder->addGrid(12.4375, 12.4375, 12.4375, 14.5625, 14.5625, 14.5625, 0.125, "cpu", "D3Q27", false, false, false);
+    //gridBuilder->addGrid(10.375, 10.375, 10.375, 20.625, 20.625, 20.625, 0.25, "cpu", "D3Q27", false, false, false);
+    gridBuilder->addGrid(5.25, 5.25, 5.25, 24.75, 24.75, 24.75, 0.5, "cpu", "D3Q27", false, false, false);
+    gridBuilder->addGrid(0.0, 0.0, 0.0, 30.0, 30.0, 30.0, 1.0, "cpu", "D3Q27", true, true, true);
+
     //gridBuilder->addGrid(40.4375, 40.4375, 40.4375, 60.5625, 60.5625, 60.5625, 0.125, "cpu", "D3Q27");
 
 
-    SimulationFileWriter::write("D:/GRIDGENERATION/couplingVF/periodicTaylorThreeLevel/simu/", gridBuilder, FILEFORMAT::ASCII);
+    //SimulationFileWriter::write("D:/GRIDGENERATION/couplingVF/periodicTaylorThreeLevel/simu/", gridBuilder, FILEFORMAT::ASCII);
 
     //gridBuilder->meshGeometry("D:/GRIDGENERATION/STL/circleBinaer.stl", 1);
     //gridBuilder->meshGeometry("D:/GRIDGENERATION/STL/circleBinaer.stl", 0);
     //gridBuilder->writeGridToVTK("D:/GRIDGENERATION/gridTest_level_1", 1);
     //gridBuilder->writeGridToVTK("D:/GRIDGENERATION/gridTest_level_0", 0);
+    //gridBuilder->writeGridToVTK("D:/GRIDGENERATION/gridTest_level_2", 2);
 
     SPtr<Parameter> para = Parameter::makeShared();
     SPtr<GridProvider> gridGenerator = GridProvider::makeGridGenerator(gridBuilder, para);
-- 
GitLab