diff --git a/apps/gpu/Cases_1_3_5_7/CMakeLists.txt b/apps/gpu/Cases_1_3_5_7/CMakeLists.txt index b143c2d7ac9dad0fb0c73b704c9aabd3f3f2a91f..6062e81f889869e8eed4e32f3efed8eb29dad1fb 100644 --- a/apps/gpu/Cases_1_3_5_7/CMakeLists.txt +++ b/apps/gpu/Cases_1_3_5_7/CMakeLists.txt @@ -1,3 +1,3 @@ -project(LidDrivenCavityGPU LANGUAGES CUDA CXX) +project(Cases_1_3_5_7 LANGUAGES CUDA CXX) vf_add_library(BUILDTYPE binary PRIVATE_LINK basics GridGenerator VirtualFluids_GPU GksMeshAdapter GksGpu FILES Cases_1_3_5_7.cpp) diff --git a/apps/gpu/Cases_1_3_5_7/Cases_1_3_5_7.cpp b/apps/gpu/Cases_1_3_5_7/Cases_1_3_5_7.cpp index beac3b5123ab76d8009e8fc2742ed7f55e589961..99e600558c33942942674ae5fea395a061ba2c9e 100644 --- a/apps/gpu/Cases_1_3_5_7/Cases_1_3_5_7.cpp +++ b/apps/gpu/Cases_1_3_5_7/Cases_1_3_5_7.cpp @@ -31,14 +31,14 @@ //! \author Martin Schoenherr, Stephan Lenz, Damilola Adekanye //======================================================================================= #define _USE_MATH_DEFINES +#include <exception> +#include <fstream> +#include <iostream> #include <math.h> -#include <string> +#include <memory> #include <sstream> -#include <iostream> #include <stdexcept> -#include <fstream> -#include <exception> -#include <memory> +#include <string> #include "PointerDefinitions.h" @@ -46,44 +46,42 @@ #include "Core/DataTypes.h" #include "Core/LbmOrGks.h" -#include "Core/VectorTypes.h" #include "Core/Logger/Logger.h" +#include "Core/VectorTypes.h" ////////////////////////////////////////////////////////////////////////// +#include "GridGenerator/grid/BoundaryConditions/Side.h" #include "GridGenerator/grid/GridBuilder/LevelGridBuilder.h" #include "GridGenerator/grid/GridBuilder/MultipleGridBuilder.h" -#include "GridGenerator/grid/BoundaryConditions/Side.h" #include "GridGenerator/grid/GridFactory.h" ////////////////////////////////////////////////////////////////////////// -#include "VirtualFluids_GPU/LBM/Simulation.h" -#include "VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/GridGenerator.h" #include "VirtualFluids_GPU/DataStructureInitializer/GridProvider.h" -#include "VirtualFluids_GPU/Parameter/Parameter.h" -#include "VirtualFluids_GPU/Output/FileWriter.h" +#include "VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/GridGenerator.h" #include "VirtualFluids_GPU/GPU/CudaMemoryManager.h" +#include "VirtualFluids_GPU/LBM/Simulation.h" +#include "VirtualFluids_GPU/Output/FileWriter.h" +#include "VirtualFluids_GPU/Parameter/Parameter.h" ////////////////////////////////////////////////////////////////////////// -int main( int argc, char* argv[]) +int main(int argc, char *argv[]) { - srand (time(nullptr)); - try - { + srand(time(nullptr)); + try { ////////////////////////////////////////////////////////////////////////// // Simulation parameters ////////////////////////////////////////////////////////////////////////// std::string path("Insert Path to Results Directory Here"); std::string simulationName("Insert Simulation Name Here"); - const real Re = 8950; //Set Reynolds number for given case - const real Sc = 1; //Set Schmidt number - const real L = 1; //Set height of channel (H) - const uint nx = 100; //Set the number of nodes discrtizing channel depth - const real Gate = L; //Set distance to gate (x0) - + const real Re = 8950; // Set Reynolds number for given case + const real Sc = 1; // Set Schmidt number + const real L = 1; // Set height of channel (H) + const uint nx = 100; // Set the number of nodes discrtizing channel depth + const real Gate = L; // Set distance to gate (x0) // this testcase is implemented for LBM(GPU) only LbmOrGks lbmOrGks = LBM; @@ -104,53 +102,51 @@ int main( int argc, char* argv[]) auto gridFactory = GridFactory::make(); gridFactory->setGridStrategy(Device::CPU); auto gridBuilder = MultipleGridBuilder::makeShared(gridFactory); - + ////////////////////////////////////////////////////////////////////////// // create grid ////////////////////////////////////////////////////////////////////////// - real dx = L / real(nx); + real dx = L / real(nx); - gridBuilder->addCoarseGrid(-12.5 * L, 0 * L, 0 * L, - 12.5 * L, 1.5 * L, 1 * L, dx); + gridBuilder->addCoarseGrid(-12.5 * L, 0 * L, 0 * L, 12.5 * L, 1.5 * L, 1 * L, dx); - gridBuilder->setPeriodicBoundaryCondition(true, true, false); + gridBuilder->setPeriodicBoundaryCondition(true, true, false); - gridBuilder->buildGrids(lbmOrGks, false); + gridBuilder->buildGrids(lbmOrGks, false); - ////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////// // branch between LBM and GKS ////////////////////////////////////////////////////////////////////////// - if( lbmOrGks == LBM ) - { - SPtr<Parameter> para = Parameter::make(); + if (lbmOrGks == LBM) { + SPtr<Parameter> para = Parameter::make(); - real DeltaT = 2.5*(real)nx/para->getVelocityLB(); + real DeltaT = 2.5 * (real)nx / para->getVelocityLB(); - const uint timeStepOut = (int)DeltaT ; - const uint timeStepEnd = (int)DeltaT*12; - std::cout << "DeltaT=" << timeStepOut <<"\n"; - ////////////////////////////////////////////////////////////////////////// + const uint timeStepOut = (int)DeltaT; + const uint timeStepEnd = (int)DeltaT * 12; + std::cout << "DeltaT=" << timeStepOut << "\n"; + ////////////////////////////////////////////////////////////////////////// // compute parameters in lattice units ////////////////////////////////////////////////////////////////////////// - const real velocityLB = para->getVelocityLB(); //Using default velocity in Parameter constructor (LB units) - const real dt = velocityLB/nx; - const real velocity = velocityLB * dx / dt; + const real velocityLB = para->getVelocityLB(); // Using default velocity in Parameter constructor (LB units) + const real dt = velocityLB / nx; + const real velocity = velocityLB * dx / dt; const real viscosityLB = nx * velocityLB / Re; // LB units - const real g_r = (velocityLB*velocityLB)/nx; // LB units + const real g_r = (velocityLB * velocityLB) / nx; // LB units *logging::out << logging::Logger::INFO_HIGH << "velocity [dx/dt] = " << velocityLB << " \n"; *logging::out << logging::Logger::INFO_HIGH << "viscosity [dx^2/dt] = " << viscosityLB << "\n"; - + ////////////////////////////////////////////////////////////////////////// // set parameters ////////////////////////////////////////////////////////////////////////// - para->setOutputPath( path ); - para->setOutputPrefix( simulationName ); + para->setOutputPath(path); + para->setOutputPrefix(simulationName); para->setPathAndFilename(para->getOutputPath() + "/" + para->getOutputPrefix()); @@ -161,53 +157,52 @@ int main( int argc, char* argv[]) para->setVelocityRatio(velocity / velocityLB); - para->setTimestepOut( timeStepOut ); - para->setTimestepEnd( timeStepEnd ); + para->setTimestepOut(timeStepOut); + para->setTimestepEnd(timeStepEnd); - para->setIsADcalculationOn(true); + para->setIsADcalculationOn(true); para->setIsBodyForceOn(true); - para->setSc( (real)Sc ); - para->setNx( (real)nx ); - para->setG_r( (real)g_r); - ////////////////////////////////////////////////////////////////////////// - // set initial conditions - ////////////////////////////////////////////////////////////////////////// - para->setInitialCondition([&](real coordX, real coordY, real coordZ, real& rho, real& vx, real& vy, real& vz) { - rho = (real)0.0; - vx = (real)0.0; - vy = (real)0.0; - vz = (real)0.0; - }); - - // set concentration - if (para->getIsADcalculationOn()) - { - para->setInitialConditionAD([&](real coordX, real coordY, real coordZ, real& concentration, real dist) { - if (sqrt(coordX*coordX)<Gate + dist){ + para->setSc((real)Sc); + para->setNx((real)nx); + para->setG_r((real)g_r); + ////////////////////////////////////////////////////////////////////////// + // set initial conditions + ////////////////////////////////////////////////////////////////////////// + para->setInitialCondition( + [&](real coordX, real coordY, real coordZ, real &rho, real &vx, real &vy, real &vz) { + rho = (real)0.0; + vx = (real)0.0; + vy = (real)0.0; + vz = (real)0.0; + }); + + // set concentration + if (para->getIsADcalculationOn()) { + para->setInitialConditionAD([&](real coordX, real coordY, real coordZ, real &concentration, real dist) { + if (sqrt(coordX * coordX) < Gate + dist) { concentration = (real)1.0; + } else { + concentration = (real)0.0; } - else { - concentration = (real)0.0; - } - }); - } + }); + } - ////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////// // set boundary conditions ////////////////////////////////////////////////////////////////////////// - gridBuilder->setNoSlipBoundaryCondition (SideType::PZ); - gridBuilder->setNoSlipBoundaryCondition (SideType::MZ); - + gridBuilder->setNoSlipBoundaryCondition(SideType::PZ); + gridBuilder->setNoSlipBoundaryCondition(SideType::MZ); + ////////////////////////////////////////////////////////////////////////// // set copy mesh to simulation ////////////////////////////////////////////////////////////////////////// - SPtr<CudaMemoryManager> cudaMemoryManager = CudaMemoryManager::make(para); + SPtr<CudaMemoryManager> cudaMemoryManager = CudaMemoryManager::make(para); SPtr<GridProvider> gridGenerator = GridProvider::makeGridGenerator(gridBuilder, para, cudaMemoryManager); - + ////////////////////////////////////////////////////////////////////////// // run simulation ////////////////////////////////////////////////////////////////////////// @@ -219,25 +214,17 @@ int main( int argc, char* argv[]) sim.free(); } - } - catch (const std::bad_alloc& e) - { + } catch (const std::bad_alloc &e) { *logging::out << logging::Logger::LOGGER_ERROR << "Bad Alloc:" << e.what() << "\n"; - } - catch (const std::exception& e) - { - + } catch (const std::exception &e) { + *logging::out << logging::Logger::LOGGER_ERROR << e.what() << "\n"; - } - catch (std::string& s) - { - + } catch (std::string &s) { + *logging::out << logging::Logger::LOGGER_ERROR << s << "\n"; - } - catch (...) - { + } catch (...) { *logging::out << logging::Logger::LOGGER_ERROR << "Unknown exception!\n"; } - return 0; + return 0; } diff --git a/apps/gpu/Cases_2_4_6_8/CMakeLists.txt b/apps/gpu/Cases_2_4_6_8/CMakeLists.txt index bb4234a90808194dc63beb391ce525545de1ed0b..f05abae095b523bd5e572c3c35750ffc7cf3a073 100644 --- a/apps/gpu/Cases_2_4_6_8/CMakeLists.txt +++ b/apps/gpu/Cases_2_4_6_8/CMakeLists.txt @@ -1,3 +1,3 @@ -project(LidDrivenCavityGPU LANGUAGES CUDA CXX) +project(Cases_2_4_6_8 LANGUAGES CUDA CXX) vf_add_library(BUILDTYPE binary PRIVATE_LINK basics GridGenerator VirtualFluids_GPU GksMeshAdapter GksGpu FILES Cases_2_4_6_8.cpp) diff --git a/apps/gpu/Cases_2_4_6_8/Cases_2_4_6_8.cpp b/apps/gpu/Cases_2_4_6_8/Cases_2_4_6_8.cpp index 42f66d0f64d1b70f922926307d74b1a9dcc28a20..378064fe2f89c7d5a3784d71531103507449fd0b 100644 --- a/apps/gpu/Cases_2_4_6_8/Cases_2_4_6_8.cpp +++ b/apps/gpu/Cases_2_4_6_8/Cases_2_4_6_8.cpp @@ -31,14 +31,14 @@ //! \author Martin Schoenherr, Stephan Lenz, Damilola Adekanye //======================================================================================= #define _USE_MATH_DEFINES +#include <exception> +#include <fstream> +#include <iostream> #include <math.h> -#include <string> +#include <memory> #include <sstream> -#include <iostream> #include <stdexcept> -#include <fstream> -#include <exception> -#include <memory> +#include <string> #include "PointerDefinitions.h" @@ -46,44 +46,42 @@ #include "Core/DataTypes.h" #include "Core/LbmOrGks.h" -#include "Core/VectorTypes.h" #include "Core/Logger/Logger.h" +#include "Core/VectorTypes.h" ////////////////////////////////////////////////////////////////////////// +#include "GridGenerator/grid/BoundaryConditions/Side.h" #include "GridGenerator/grid/GridBuilder/LevelGridBuilder.h" #include "GridGenerator/grid/GridBuilder/MultipleGridBuilder.h" -#include "GridGenerator/grid/BoundaryConditions/Side.h" #include "GridGenerator/grid/GridFactory.h" ////////////////////////////////////////////////////////////////////////// -#include "VirtualFluids_GPU/LBM/Simulation.h" -#include "VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/GridGenerator.h" #include "VirtualFluids_GPU/DataStructureInitializer/GridProvider.h" -#include "VirtualFluids_GPU/Parameter/Parameter.h" -#include "VirtualFluids_GPU/Output/FileWriter.h" +#include "VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/GridGenerator.h" #include "VirtualFluids_GPU/GPU/CudaMemoryManager.h" +#include "VirtualFluids_GPU/LBM/Simulation.h" +#include "VirtualFluids_GPU/Output/FileWriter.h" +#include "VirtualFluids_GPU/Parameter/Parameter.h" ////////////////////////////////////////////////////////////////////////// -int main( int argc, char* argv[]) +int main(int argc, char *argv[]) { - srand (time(nullptr)); - try - { + srand(time(nullptr)); + try { ////////////////////////////////////////////////////////////////////////// // Simulation parameters ////////////////////////////////////////////////////////////////////////// std::string path("Insert Path to Results Directory Here"); std::string simulationName("Insert Simulation Name Here"); - const real Re = 1000; //Set Reynolds number for given case - const real Sc = 1; //Set Schmidt number - const real L = 1; //Set height of channel (H) - const uint nx = 100; //Set the number of nodes discrtizing channel depth - const real Gate = L; //Set distance to gate (x0) - + const real Re = 1000; // Set Reynolds number for given case + const real Sc = 1; // Set Schmidt number + const real L = 1; // Set height of channel (H) + const uint nx = 100; // Set the number of nodes discrtizing channel depth + const real Gate = L; // Set distance to gate (x0) // this testcase is implemented for LBM-GPU only LbmOrGks lbmOrGks = LBM; @@ -104,53 +102,51 @@ int main( int argc, char* argv[]) auto gridFactory = GridFactory::make(); gridFactory->setGridStrategy(Device::CPU); auto gridBuilder = MultipleGridBuilder::makeShared(gridFactory); - + ////////////////////////////////////////////////////////////////////////// // create grid ////////////////////////////////////////////////////////////////////////// - real dx = L / real(nx); + real dx = L / real(nx); - gridBuilder->addCoarseGrid(0 * L, 0 * L, 0 * L, - 15 * L, 1 * L, 1 * L, dx); + gridBuilder->addCoarseGrid(0 * L, 0 * L, 0 * L, 15 * L, 1 * L, 1 * L, dx); - gridBuilder->setPeriodicBoundaryCondition(false, false, false); + gridBuilder->setPeriodicBoundaryCondition(false, false, false); - gridBuilder->buildGrids(lbmOrGks, false); + gridBuilder->buildGrids(lbmOrGks, false); - ////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////// // branch between LBM and GKS ////////////////////////////////////////////////////////////////////////// - if( lbmOrGks == LBM ) - { - SPtr<Parameter> para = Parameter::make(); + if (lbmOrGks == LBM) { + SPtr<Parameter> para = Parameter::make(); - real DeltaT = 0.5*(real)nx/para->getVelocityLB(); + real DeltaT = 0.5 * (real)nx / para->getVelocityLB(); - const uint timeStepOut = (int)DeltaT ; - const uint timeStepEnd = (int)DeltaT*12; - std::cout << "DeltaT=" << timeStepOut <<"\n"; - ////////////////////////////////////////////////////////////////////////// + const uint timeStepOut = (int)DeltaT; + const uint timeStepEnd = (int)DeltaT * 12; + std::cout << "DeltaT=" << timeStepOut << "\n"; + ////////////////////////////////////////////////////////////////////////// // compute parameters in lattice units ////////////////////////////////////////////////////////////////////////// - const real velocityLB = para->getVelocityLB(); //Using default velocity in Parameter constructor (LB units) - const real dt = velocityLB/nx; - const real velocity = velocityLB * dx / dt; + const real velocityLB = para->getVelocityLB(); // Using default velocity in Parameter constructor (LB units) + const real dt = velocityLB / nx; + const real velocity = velocityLB * dx / dt; const real viscosityLB = nx * velocityLB / Re; // LB units - const real g_r = (velocityLB*velocityLB)/nx; // LB units + const real g_r = (velocityLB * velocityLB) / nx; // LB units *logging::out << logging::Logger::INFO_HIGH << "velocity [dx/dt] = " << velocityLB << " \n"; *logging::out << logging::Logger::INFO_HIGH << "viscosity [dx^2/dt] = " << viscosityLB << "\n"; - + ////////////////////////////////////////////////////////////////////////// // set parameters ////////////////////////////////////////////////////////////////////////// - para->setOutputPath( path ); - para->setOutputPrefix( simulationName ); + para->setOutputPath(path); + para->setOutputPrefix(simulationName); para->setPathAndFilename(para->getOutputPath() + "/" + para->getOutputPrefix()); @@ -161,57 +157,56 @@ int main( int argc, char* argv[]) para->setVelocityRatio(velocity / velocityLB); - para->setTimestepOut( timeStepOut ); - para->setTimestepEnd( timeStepEnd ); + para->setTimestepOut(timeStepOut); + para->setTimestepEnd(timeStepEnd); - para->setIsADcalculationOn(true); + para->setIsADcalculationOn(true); para->setIsBodyForceOn(true); - para->setSc( (real)Sc ); - para->setNx( (real)nx ); - para->setG_r( (real)g_r); - ////////////////////////////////////////////////////////////////////////// - // set initial conditions - ////////////////////////////////////////////////////////////////////////// - para->setInitialCondition([&](real coordX, real coordY, real coordZ, real& rho, real& vx, real& vy, real& vz) { - rho = (real)0.0; - vx = (real)0.0; - vy = (real)0.0; - vz = (real)0.0; - }); - - // set concentration - if (para->getIsADcalculationOn()) - { - para->setInitialConditionAD([&](real coordX, real coordY, real coordZ, real& concentration, real dist) { - if (sqrt(coordX*coordX)<Gate + dist){ + para->setSc((real)Sc); + para->setNx((real)nx); + para->setG_r((real)g_r); + ////////////////////////////////////////////////////////////////////////// + // set initial conditions + ////////////////////////////////////////////////////////////////////////// + para->setInitialCondition( + [&](real coordX, real coordY, real coordZ, real &rho, real &vx, real &vy, real &vz) { + rho = (real)0.0; + vx = (real)0.0; + vy = (real)0.0; + vz = (real)0.0; + }); + + // set concentration + if (para->getIsADcalculationOn()) { + para->setInitialConditionAD([&](real coordX, real coordY, real coordZ, real &concentration, real dist) { + if (sqrt(coordX * coordX) < Gate + dist) { concentration = (real)1.0; + } else { + concentration = (real)0.0; } - else { - concentration = (real)0.0; - } - }); - } + }); + } - ////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////// // set boundary conditions ////////////////////////////////////////////////////////////////////////// - gridBuilder->setNoSlipBoundaryCondition (SideType::PX); - gridBuilder->setNoSlipBoundaryCondition (SideType::MX); - gridBuilder->setNoSlipBoundaryCondition (SideType::PY); - gridBuilder->setNoSlipBoundaryCondition (SideType::MY); - gridBuilder->setNoSlipBoundaryCondition (SideType::PZ); - gridBuilder->setNoSlipBoundaryCondition (SideType::MZ); - + gridBuilder->setNoSlipBoundaryCondition(SideType::PX); + gridBuilder->setNoSlipBoundaryCondition(SideType::MX); + gridBuilder->setNoSlipBoundaryCondition(SideType::PY); + gridBuilder->setNoSlipBoundaryCondition(SideType::MY); + gridBuilder->setNoSlipBoundaryCondition(SideType::PZ); + gridBuilder->setNoSlipBoundaryCondition(SideType::MZ); + ////////////////////////////////////////////////////////////////////////// // set copy mesh to simulation ////////////////////////////////////////////////////////////////////////// - SPtr<CudaMemoryManager> cudaMemoryManager = CudaMemoryManager::make(para); + SPtr<CudaMemoryManager> cudaMemoryManager = CudaMemoryManager::make(para); SPtr<GridProvider> gridGenerator = GridProvider::makeGridGenerator(gridBuilder, para, cudaMemoryManager); - + ////////////////////////////////////////////////////////////////////////// // run simulation ////////////////////////////////////////////////////////////////////////// @@ -223,25 +218,17 @@ int main( int argc, char* argv[]) sim.free(); } - } - catch (const std::bad_alloc& e) - { + } catch (const std::bad_alloc &e) { *logging::out << logging::Logger::LOGGER_ERROR << "Bad Alloc:" << e.what() << "\n"; - } - catch (const std::exception& e) - { - + } catch (const std::exception &e) { + *logging::out << logging::Logger::LOGGER_ERROR << e.what() << "\n"; - } - catch (std::string& s) - { - + } catch (std::string &s) { + *logging::out << logging::Logger::LOGGER_ERROR << s << "\n"; - } - catch (...) - { + } catch (...) { *logging::out << logging::Logger::LOGGER_ERROR << "Unknown exception!\n"; } - return 0; + return 0; }