From 4ed6421f431e7a078c1a0c325e4c17c3e26d4e07 Mon Sep 17 00:00:00 2001
From: "LEGOLAS\\lenz" <lenz@irmb.tu-bs.de>
Date: Thu, 27 Jun 2019 10:02:28 +0200
Subject: [PATCH] makes DrivenCavity LBM target runnable, GKS not yet working

---
 .../apps/LBM/DrivenCavity/DrivenCavity.cpp    | 188 +++++++++++++-----
 .../LBM/DrivenCavity/configDrivenCavity.txt   |  22 +-
 2 files changed, 153 insertions(+), 57 deletions(-)

diff --git a/targets/apps/LBM/DrivenCavity/DrivenCavity.cpp b/targets/apps/LBM/DrivenCavity/DrivenCavity.cpp
index 66192340c..7529b9309 100644
--- a/targets/apps/LBM/DrivenCavity/DrivenCavity.cpp
+++ b/targets/apps/LBM/DrivenCavity/DrivenCavity.cpp
@@ -24,8 +24,6 @@
 
 //////////////////////////////////////////////////////////////////////////
 
-//#include "GridGenerator/global.h"
-
 #include "GridGenerator/grid/GridBuilder/LevelGridBuilder.h"
 #include "GridGenerator/grid/GridBuilder/MultipleGridBuilder.h"
 #include "GridGenerator/grid/BoundaryConditions/Side.h"
@@ -73,7 +71,39 @@
 
 #include "GksGpu/CudaUtility/CudaUtility.h"
 
-//////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//
+//          U s e r    s e t t i n g s
+//
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+LbmOrGks lbmOrGks = GKS;
+//LbmOrGks lbmOrGks = LBM;
+
+const real L  = 1.0;
+
+const real Re = 1000.0;
+
+const real velocity  = 1.0;
+
+const real dt = 1.0e-3;
+
+const uint nx = 64;
+
+std::string path("F:/Work/Computations/out/DrivenCavity/");
+
+std::string simulationName("DrivenCavity");
+
+const uint timeStepOut = 10000;
+const uint timeStepEnd = 100000;
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
 void multipleLevel(const std::string& configPath)
 {
@@ -94,27 +124,6 @@ void multipleLevel(const std::string& configPath)
 
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-    LbmOrGks lbmOrGks = LBM;
-
-	const real L = 1.0;
-
-    const real Re = 1000;
-
-    const uint nx = 64;
-
-	const real vx = 0.05; // LB units
-	const real vy = 0.05; // LB units
-
-	const real velocity = sqrt(vx*vx + vy*vy);
-
-    const real viscosity = nx * velocity / Re; // LB units
-
-    *logging::out << logging::Logger::INFO_HIGH << "velocity  = " << velocity << " s\n";
-
-    *logging::out << logging::Logger::INFO_HIGH << "viscosity = " << viscosity << "\n";
-
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
 	real dx = L / real(nx);
@@ -124,7 +133,7 @@ void multipleLevel(const std::string& configPath)
 
 	gridBuilder->setPeriodicBoundaryCondition(false, false, false);
 
-	gridBuilder->buildGrids(LBM, false); // buildGrids() has to be called before setting the BCs!!!!
+	gridBuilder->buildGrids(lbmOrGks, false); // buildGrids() has to be called before setting the BCs!!!!
 
 	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -137,32 +146,57 @@ void multipleLevel(const std::string& configPath)
 
     if( lbmOrGks == LBM )
     {
-	    gridBuilder->setVelocityBoundaryCondition(SideType::PX, 0.0, 0.0, 0.0);
-	    gridBuilder->setVelocityBoundaryCondition(SideType::MX, 0.0, 0.0, 0.0);
-	    gridBuilder->setVelocityBoundaryCondition(SideType::PY, 0.0, 0.0, 0.0);
-	    gridBuilder->setVelocityBoundaryCondition(SideType::MY, 0.0, 0.0, 0.0);
-	    gridBuilder->setVelocityBoundaryCondition(SideType::PZ,  vx,  vy, 0.0);
-	    gridBuilder->setVelocityBoundaryCondition(SideType::MZ, 0.0, 0.0, 0.0);
 
         ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
         SPtr<Parameter> para = Parameter::make(configData, comm);
-        //SPtr<Parameter> para = Parameter::make();
 
-        SPtr<CudaMemoryManager> cudaMemoryManager = CudaMemoryManager::make(para);
+        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
-        SPtr<GridProvider> gridGenerator = GridProvider::makeGridGenerator(gridBuilder, para, cudaMemoryManager);
+        const real velocityLB = velocity * dt / dx; // LB units
+
+	    const real vx = velocityLB / sqrt(2.0); // LB units
+	    const real vy = velocityLB / sqrt(2.0); // LB units
+
+        const real viscosityLB = nx * velocityLB / Re; // LB units
+
+        *logging::out << logging::Logger::INFO_HIGH << "velocity  [dx/dt] = " << velocityLB << " \n";
+        *logging::out << logging::Logger::INFO_HIGH << "viscosity [dx/dt] = " << viscosityLB << "\n";
 
         ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
-        para->setVelocity(velocity);
+        para->setOutputPath( path );
+        para->setOutputPrefix( simulationName );
+
+        para->setFName(para->getOutputPath() + "/" + para->getOutputPrefix());
+
+        para->setPrintFiles(true);
 
-        para->setViscosity(viscosity);
+        para->setMaxLevel(1);
 
-        para->setVelocityRatio(1.0 / velocity);
+        para->setVelocity(velocityLB);
+        para->setViscosity(viscosityLB);
+
+        para->setVelocityRatio(1.0 / velocityLB);
+
+        para->setTOut( timeStepOut );
+        para->setTEnd( timeStepEnd );
 
         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
+	    gridBuilder->setVelocityBoundaryCondition(SideType::PX, 0.0, 0.0, 0.0);
+	    gridBuilder->setVelocityBoundaryCondition(SideType::MX, 0.0, 0.0, 0.0);
+	    gridBuilder->setVelocityBoundaryCondition(SideType::PY, 0.0, 0.0, 0.0);
+	    gridBuilder->setVelocityBoundaryCondition(SideType::MY, 0.0, 0.0, 0.0);
+	    gridBuilder->setVelocityBoundaryCondition(SideType::PZ,  vx,  vy, 0.0);
+	    gridBuilder->setVelocityBoundaryCondition(SideType::MZ, 0.0, 0.0, 0.0);
+
+        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+        SPtr<CudaMemoryManager> cudaMemoryManager = CudaMemoryManager::make(para);
+
+        SPtr<GridProvider> gridGenerator = GridProvider::makeGridGenerator(gridBuilder, para, cudaMemoryManager);
+
         Simulation sim;
         SPtr<FileWriter> fileWriter = SPtr<FileWriter>(new FileWriter());
         SPtr<KernelFactoryImp> kernelFactory = KernelFactoryImp::getInstance();
@@ -177,9 +211,40 @@ void multipleLevel(const std::string& configPath)
     else
     {
         CudaUtility::setCudaDevice(0);
+        
+        Parameters parameters;
 
         ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+	    const real vx = velocity / sqrt(2.0);
+	    const real vy = velocity / sqrt(2.0);
+    
+        parameters.K  = 2.0;
+        parameters.Pr = 1.0;
+        parameters.K  = 2.0;
         
+        const real Ma = 0.1;
+
+        real rho = 1.0;
+
+        real cs = velocity / Ma;
+        real lambda = c1o2 * ( ( parameters.K + 5.0 ) / ( parameters.K + 3.0 ) ) / ( cs * cs );
+
+        const real mu = velocity * L * rho / Re;
+
+        *logging::out << logging::Logger::INFO_HIGH << "CFL = " << dx / ( dt * ( velocity + cs ) ) << " s\n";
+
+        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+        parameters.mu = mu;
+
+        parameters.dt = dt;
+        parameters.dx = dx;
+
+        parameters.lambdaRef = lambda;
+
+        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
         GksMeshAdapter meshAdapter( gridBuilder );
 
         meshAdapter.inputGrid();
@@ -193,9 +258,7 @@ void multipleLevel(const std::string& configPath)
         ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
         ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
-        real lambda = 0.1;
-
-        SPtr<BoundaryCondition> bcLid  = std::make_shared<IsothermalWall>( dataBase, Vec3(  vx, 0.0, 0.0 ), lambda, false );
+        SPtr<BoundaryCondition> bcLid  = std::make_shared<IsothermalWall>( dataBase, Vec3(  vx,  vy, 0.0 ), lambda, false );
         SPtr<BoundaryCondition> bcWall = std::make_shared<IsothermalWall>( dataBase, Vec3( 0.0, 0.0, 0.0 ), lambda, false );
 
         bcLid->findBoundaryCells ( meshAdapter, true,  [&](Vec3 center){ return center.y > 0.5; } );
@@ -205,6 +268,45 @@ void multipleLevel(const std::string& configPath)
         dataBase->boundaryConditions.push_back( bcWall );
     
         ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+        dataBase->setMesh( meshAdapter );
+
+        Initializer::interpret(dataBase, [&] ( Vec3 cellCenter ) -> ConservedVariables {
+
+            return toConservedVariables( PrimitiveVariables( rho, 0.0, 0.0, 0.0, lambda ), parameters.K );
+        });
+
+        dataBase->copyDataHostToDevice();
+
+        Initializer::initializeDataUpdate(dataBase);
+
+        writeVtkXML( dataBase, parameters, 0, path + simulationName + "_0" );
+
+        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+        CupsAnalyzer cupsAnalyzer( dataBase, false, 60.0, true, 10000 );
+
+        ConvergenceAnalyzer convergenceAnalyzer( dataBase, 10000 );
+
+        cupsAnalyzer.start();
+
+        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+        for( uint iter = 1; iter <= 1000000; iter++ )
+        {
+            TimeStepping::nestedTimeStep(dataBase, parameters, 0);
+
+            if( iter % 10000 == 0 )
+            {
+                dataBase->copyDataDeviceToHost();
+
+                writeVtkXML( dataBase, parameters, 0, path + simulationName + "_" + std::to_string( iter ) );
+            }
+
+            cupsAnalyzer.run( iter, parameters.dt );
+
+            convergenceAnalyzer.run( iter );
+        }
     }
 }
 
@@ -220,12 +322,6 @@ int main( int argc, char* argv[])
         {
             //////////////////////////////////////////////////////////////////////////
 
-			
-
-			//std::stringstream targetPath; targetPath << __FILE__;
-			//
-			//std::cout << targetPath.str() << std::endl;
-
 			std::string targetPath;
 
 			targetPath = __FILE__;
diff --git a/targets/apps/LBM/DrivenCavity/configDrivenCavity.txt b/targets/apps/LBM/DrivenCavity/configDrivenCavity.txt
index 16102c7fe..a3d6622d5 100644
--- a/targets/apps/LBM/DrivenCavity/configDrivenCavity.txt
+++ b/targets/apps/LBM/DrivenCavity/configDrivenCavity.txt
@@ -1,36 +1,36 @@
 ##################################################
 #GPU Mapping
 ##################################################
-Devices="0 1 2 3"
-NumberOfDevices=4
+#Devices="0 1 2 3"
+#NumberOfDevices=4
 
 ##################################################
 #informations for Writing
 ##################################################
 #Path="E:/DrivenCavity/results"
-Path="F:/Work/Computations/out/DrivenCavity/"
-Prefix="DrivenCavity" 
-WriteGrid=true
+#Path="F:/Work/Computations/out/DrivenCavity/"
+#Prefix="DrivenCavity" 
+#WriteGrid=true
 ##################################################
 #informations for reading
 ##################################################
 #GridPath="E:/DrivenCavity/dummy"
-GridPath="F:/Work/Computations/out/DrivenCavity/dummy"
+GridPath="C:"
 
 ##################################################
 #number of grid levels
 ##################################################
-NOGL=1
+#NOGL=1
 
 ##################################################
 #LBM Version
 ##################################################
-D3Qxx=27
+#D3Qxx=27
 #MainKernelName=CumulantAA2016CompSP27
 
 ##################################################
 #simulation parameter
 ##################################################
-TimeEnd=100000
-TimeOut=1000 
-TimeStartOut=0
\ No newline at end of file
+#TimeEnd=100000
+#TimeOut=1000 
+#TimeStartOut=0
\ No newline at end of file
-- 
GitLab