diff --git a/CMake/cmake_config_files/ARAGORN.config.cmake b/CMake/cmake_config_files/ARAGORN.config.cmake index 7643d267aabce7914000face6553fb38135b7a63..7fc74bbcbf39890ebc26d328b4916575c8471a33 100644 --- a/CMake/cmake_config_files/ARAGORN.config.cmake +++ b/CMake/cmake_config_files/ARAGORN.config.cmake @@ -12,4 +12,5 @@ list(APPEND USER_APPS "${GPU_APP}DrivenCavityMultiGPU" "${GPU_APP}SphereScaling" # "${GPU_APP}MusselOyster" + "${GPU_APP}RotatingGrid" ) diff --git a/apps/gpu/RotatingGrid/CMakeLists.txt b/apps/gpu/RotatingGrid/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..bd64b62d4e8aaa6263f6b008ae71601442217023 --- /dev/null +++ b/apps/gpu/RotatingGrid/CMakeLists.txt @@ -0,0 +1,5 @@ +PROJECT(DrivenCavity LANGUAGES CXX) + +#LIST(APPEND CS_COMPILER_FLAGS_CXX "-DOMPI_SKIP_MPICXX" ) + +vf_add_library(BUILDTYPE binary PRIVATE_LINK basics VirtualFluids_GPU GridGenerator FILES RotatingGrid.cpp) diff --git a/apps/gpu/RotatingGrid/RotatingGrid.cpp b/apps/gpu/RotatingGrid/RotatingGrid.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0bbc36d79d5a230e5571c0fc20df586c7e3c8cf2 --- /dev/null +++ b/apps/gpu/RotatingGrid/RotatingGrid.cpp @@ -0,0 +1,213 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file RotatingGrid.cpp +//! \ingroup Applications +//! \author Anna Wellmann +//======================================================================================= +#define _USE_MATH_DEFINES +#include <exception> +#include <fstream> +#include <iostream> +#include <memory> +#include <sstream> +#include <stdexcept> +#include <string> + +////////////////////////////////////////////////////////////////////////// + +#include <basics/DataTypes.h> +#include <basics/PointerDefinitions.h> +#include <logger/Logger.h> +#include <parallel/MPICommunicator.h> + +////////////////////////////////////////////////////////////////////////// + +#include "GridGenerator/geometries/Cuboid/Cuboid.h" +#include "GridGenerator/grid/BoundaryConditions/Side.h" +#include "GridGenerator/grid/GridBuilder/LevelGridBuilder.h" +#include "GridGenerator/grid/GridBuilder/MultipleGridBuilder.h" + +////////////////////////////////////////////////////////////////////////// + +#include "VirtualFluids_GPU/DataStructureInitializer/GridProvider.h" +#include "VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/GridGenerator.h" +#include "VirtualFluids_GPU/Factories/BoundaryConditionFactory.h" +#include "VirtualFluids_GPU/Factories/GridScalingFactory.h" +#include "VirtualFluids_GPU/GPU/CudaMemoryManager.h" +#include "VirtualFluids_GPU/Kernel/Utilities/KernelTypes.h" +#include "VirtualFluids_GPU/LBM/Simulation.h" +#include "VirtualFluids_GPU/Output/FileWriter.h" +#include "VirtualFluids_GPU/Output/NeighborDebugWriter.h" +#include "VirtualFluids_GPU/Parameter/Parameter.h" + +////////////////////////////////////////////////////////////////////////// + +int main() +{ + try { + vf::logging::Logger::initializeLogger(); + ////////////////////////////////////////////////////////////////////////// + // Simulation parameters + ////////////////////////////////////////////////////////////////////////// + std::string path("./output/RotatingGrid"); + std::string simulationName("RotatingGrid"); + + const real L = 1.0; + const real Re = 1000.0; + const real velocity = 1.0; + const real velocityLB = 0.05; // LB units + const uint nx = 64; + + const uint timeStepOut = 1000; + const uint timeStepEnd = 10000; + + ////////////////////////////////////////////////////////////////////////// + // compute parameters in lattice units + ////////////////////////////////////////////////////////////////////////// + + const real dx = L / real(nx); + const real dt = velocityLB / velocity * dx; + + const real vxLB = velocityLB / sqrt(2.0); // LB units + const real vyLB = velocityLB / sqrt(2.0); // LB units + + const real viscosityLB = nx * velocityLB / Re; // LB units + + ////////////////////////////////////////////////////////////////////////// + // create grid + ////////////////////////////////////////////////////////////////////////// + auto gridBuilder = std::make_shared<MultipleGridBuilder>(); + + gridBuilder->addCoarseGrid(-0.5 * L, -0.5 * L, -0.5 * L, 0.5 * L, 0.5 * L, 0.5 * L, dx); + + gridBuilder->addGridWithSameDeltaAsPreviousGrid(std::make_shared<Cuboid>(-0.25, -0.25, -0.25, 0.25, 0.25, 0.25)); + GridScalingFactory scalingFactory = GridScalingFactory(); + scalingFactory.setScalingFactory(GridScalingFactory::GridScaling::ScaleCompressible); + + gridBuilder->setPeriodicBoundaryCondition(false, false, false); + + gridBuilder->buildGrids(false); + + ////////////////////////////////////////////////////////////////////////// + // set parameters + ////////////////////////////////////////////////////////////////////////// + SPtr<Parameter> para = std::make_shared<Parameter>(); + + para->setOutputPath(path); + para->setOutputPrefix(simulationName); + + para->setPrintFiles(true); + + para->setVelocityLB(velocityLB); + para->setViscosityLB(viscosityLB); + + para->setVelocityRatio(velocity / velocityLB); + para->setDensityRatio(1.0); + + para->setTimestepOut(timeStepOut); + para->setTimestepEnd(timeStepEnd); + + para->configureMainKernel(vf::CollisionKernel::Compressible::K17CompressibleNavierStokes); + + ////////////////////////////////////////////////////////////////////////// + // set boundary conditions + ////////////////////////////////////////////////////////////////////////// + + gridBuilder->setNoSlipBoundaryCondition(SideType::PX); + gridBuilder->setNoSlipBoundaryCondition(SideType::MX); + gridBuilder->setNoSlipBoundaryCondition(SideType::PY); + gridBuilder->setNoSlipBoundaryCondition(SideType::MY); + gridBuilder->setNoSlipBoundaryCondition(SideType::MZ); + gridBuilder->setVelocityBoundaryCondition(SideType::PZ, vxLB, vyLB, 0.0); + + BoundaryConditionFactory bcFactory; + + bcFactory.setNoSlipBoundaryCondition(BoundaryConditionFactory::NoSlipBC::NoSlipBounceBack); + bcFactory.setVelocityBoundaryCondition(BoundaryConditionFactory::VelocityBC::VelocitySimpleBounceBackCompressible); + + ////////////////////////////////////////////////////////////////////////// + // set copy mesh to simulation + ////////////////////////////////////////////////////////////////////////// + + vf::parallel::Communicator &communicator = *vf::parallel::MPICommunicator::getInstance(); + + auto cudaMemoryManager = std::make_shared<CudaMemoryManager>(para); + SPtr<GridProvider> gridGenerator = + GridProvider::makeGridGenerator(gridBuilder, para, cudaMemoryManager, communicator); + + ////////////////////////////////////////////////////////////////////////// + // run simulation + ////////////////////////////////////////////////////////////////////////// + + VF_LOG_INFO("Start Running DrivenCavity Showcase..."); + printf("\n"); + VF_LOG_INFO("world parameter:"); + VF_LOG_INFO("--------------"); + VF_LOG_INFO("dt [s] = {}", dt); + VF_LOG_INFO("world_length [m] = {}", L); + VF_LOG_INFO("world_velocity [m/s] = {}", velocity); + VF_LOG_INFO("dx [m] = {}", dx); + printf("\n"); + VF_LOG_INFO("LB parameter:"); + VF_LOG_INFO("--------------"); + VF_LOG_INFO("Re = {}", Re); + VF_LOG_INFO("lb_velocity [dx/dt] = {}", velocityLB); + VF_LOG_INFO("lb_viscosity [dx^2/dt] = {}", viscosityLB); + VF_LOG_INFO("lb_vx [dx/dt] (lb_velocity/sqrt(2)) = {}", vxLB); + VF_LOG_INFO("lb_vy [dx/dt] (lb_velocity/sqrt(2)) = {}", vyLB); + printf("\n"); + VF_LOG_INFO("simulation parameter:"); + VF_LOG_INFO("--------------"); + VF_LOG_INFO("nx = {}", nx); + VF_LOG_INFO("ny = {}", nx); + VF_LOG_INFO("nz = {}", nx); + VF_LOG_INFO("number of nodes = {}", nx * nx * nx); + VF_LOG_INFO("n timesteps = {}", timeStepOut); + VF_LOG_INFO("write_nth_timestep = {}", timeStepEnd); + VF_LOG_INFO("output_path = {}", path); + + Simulation sim(para, cudaMemoryManager, communicator, *gridGenerator, &bcFactory, &scalingFactory); + + // gridBuilder->writeGridsToVtk(para->getOutputPath() + "grid"); + // NeighborDebugWriter::writeNeighborLinkLinesDebug(para.get()); + + // sim.run(); + + } catch (const spdlog::spdlog_ex &ex) { + std::cout << "Log initialization failed: " << ex.what() << std::endl; + } catch (const std::bad_alloc &e) { + VF_LOG_CRITICAL("Bad Alloc: {}", e.what()); + } catch (const std::exception &e) { + VF_LOG_CRITICAL("exception: {}", e.what()); + } catch (...) { + VF_LOG_CRITICAL("Unknown exception!"); + } + + return 0; +} diff --git a/apps/gpu/RotatingGrid/configRotatingGrid.txt b/apps/gpu/RotatingGrid/configRotatingGrid.txt new file mode 100644 index 0000000000000000000000000000000000000000..458346a67c7f001580494af1dc9262034613be68 --- /dev/null +++ b/apps/gpu/RotatingGrid/configRotatingGrid.txt @@ -0,0 +1,34 @@ +################################################## +#GPU Mapping +################################################## +#Devices="0 1 2 3" +#NumberOfDevices=4 + +################################################## +#informations for Writing +################################################## +#Path = "output/" +#Prefix="DrivenCavity" +#WriteGrid=true +################################################## +#informations for reading +################################################## +#GridPath="grid/" + +################################################## +#number of grid levels +################################################## +#NOGL=1 + +################################################## +#LBM Version +################################################## +#D3Qxx=27 +#MainKernelName=CumulantAA2016CompSP27 + +################################################## +#simulation parameter +################################################## +#TimeEnd=100000 +#TimeOut=1000 +#TimeStartOut=0 \ No newline at end of file diff --git a/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilderTest.cpp b/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilderTest.cpp index 4e89a142289af6b99065687becd68d0491217bb2..088cb4820a2daa07432ac330d4fb5bd837f02672 100644 --- a/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilderTest.cpp +++ b/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilderTest.cpp @@ -2,7 +2,27 @@ #include "geometries/Sphere/Sphere.h" #include "grid/GridBuilder/MultipleGridBuilder.h" -TEST(MultipleGridBuilderTest, noCoarseGrid_addFineGrid_warns) +class MultipleGridBuilderTestFixture : public testing::Test +{ +protected: + MultipleGridBuilder gridBuilder; + SPtr<Object> gridShape; + real delta = 0.1; + +public: + void SetUp() override + { + gridShape = std::make_shared<Sphere>(0.0, 0.0, 0.0, 0.0); + gridBuilder.addCoarseGrid(0.0, 0.0, 0.0, 1.0, 1.0, 1.0, delta); + } +}; + +TEST_F(MultipleGridBuilderTestFixture, addCoarseGrid_addsOneGridToGridList) +{ + EXPECT_THAT(gridBuilder.getGrids().size(), testing::Eq(1)); +} + +TEST(MultipleGridBuilderTest, noCoarseGrid_addGrid_warns) { MultipleGridBuilder gridBuilder; SPtr<Object> gridShape; @@ -12,14 +32,109 @@ TEST(MultipleGridBuilderTest, noCoarseGrid_addFineGrid_warns) EXPECT_TRUE(testingVF::stdoutContainsWarning()); } -TEST(MultipleGridBuilderTest, coarseGridExist_addFineGrid_doesNotWarn) +TEST_F(MultipleGridBuilderTestFixture, coarseGridExist_addGrid_doesNotWarn) +{ + testingVF::captureStdOut(); + gridBuilder.addGrid(gridShape, 1); + EXPECT_FALSE(testingVF::stdoutContainsWarning()); +} + +TEST(MultipleGridBuilderTest, noCoarseGrid_addGridWithoutLevel_warns) { MultipleGridBuilder gridBuilder; + SPtr<Object> gridShape; - SPtr<Object> gridShape = std::make_shared<Sphere>(0.0, 0.0, 0.0, 0.0); - gridBuilder.addCoarseGrid(0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.1); + testingVF::captureStdOut(); + gridBuilder.addGrid(gridShape); + EXPECT_TRUE(testingVF::stdoutContainsWarning()); +} +TEST_F(MultipleGridBuilderTestFixture, coarseGridExist_addGridWitoutLevel_doesNotWarn) +{ testingVF::captureStdOut(); - gridBuilder.addGrid(gridShape, 1); + gridBuilder.addGrid(gridShape); EXPECT_FALSE(testingVF::stdoutContainsWarning()); -} \ No newline at end of file +} + +TEST_F(MultipleGridBuilderTestFixture, coarseGridExist_addGrid_addsGridToList) +{ + uint levelFine = 1; + + gridBuilder.addGrid(gridShape, levelFine); + EXPECT_THAT(gridBuilder.getGrids().size(), testing::Eq(2)) << "coarse level + 1 new level = 2 levels"; +} + +TEST_F(MultipleGridBuilderTestFixture, coarseGridExist_addGridAtLevelTwo_addsTwoGridsToList) +{ + uint levelFine = 2; + + gridBuilder.addGrid(gridShape, levelFine); + EXPECT_THAT(gridBuilder.getGrids().size(), testing::Eq(3)) << "coarse level + 2 new levels = 3 levels"; +} + +TEST_F(MultipleGridBuilderTestFixture, fineGridExist_addGridAtLevelTwo_addsOneGridToList) +{ + uint levelFine = 2; + + gridBuilder.addGrid(gridShape, 1); + EXPECT_THAT(gridBuilder.getGrids().size(), testing::Eq(2)) << "coarse level + fineLevel = 2 levels"; + + gridBuilder.addGrid(gridShape, levelFine); + EXPECT_THAT(gridBuilder.getGrids().size(), testing::Eq(3)) << "coarse level + fineLevel + 1 new levels = 3 levels"; +} + +TEST_F(MultipleGridBuilderTestFixture, fineGridExist_addGridAtLevelThree_addsTwoGridsToList) +{ + uint levelFine = 3; + + gridBuilder.addGrid(gridShape, 1); + EXPECT_THAT(gridBuilder.getGrids().size(), testing::Eq(2)) << "coarse level + fineLevel = 2 levels"; + + gridBuilder.addGrid(gridShape, levelFine); + EXPECT_THAT(gridBuilder.getGrids().size(), testing::Eq(4)) << "coarse level + fineLevel + 2 new levels = 4 levels"; +} + +TEST_F(MultipleGridBuilderTestFixture, fineGridExist_addGridAtSameLevel_noGridAdded) +{ + uint levelFine = 1; + + gridBuilder.addGrid(gridShape, 1); + EXPECT_THAT(gridBuilder.getGrids().size(), testing::Eq(2)) << "coarse level + fineLevel = 2 levels"; + + gridBuilder.addGrid(gridShape, levelFine); + EXPECT_THAT(gridBuilder.getGrids().size(), testing::Eq(2)) + << "Can't add grid on same level twice --> no new grid should be added"; +} + +TEST_F(MultipleGridBuilderTestFixture, addGrid_hasHalfDeltaComparedToCoarseGrid) +{ + uint levelFine = 1; + + gridBuilder.addGrid(gridShape, levelFine); + EXPECT_THAT(gridBuilder.getGrid(levelFine)->getDelta(), testing::Eq(0.5 * delta)); +} + +TEST_F(MultipleGridBuilderTestFixture, addGridAtLevelTwo_hasHalfOfHalfDeltaComparedToCoarseGrid) +{ + uint levelFine = 2; + + gridBuilder.addGrid(gridShape, levelFine); + EXPECT_THAT(gridBuilder.getGrid(levelFine)->getDelta(), testing::Eq(0.5 * 0.5 * delta)); +} + +TEST_F(MultipleGridBuilderTestFixture, addGridWithoutLevel_addsGridAtLevelOne) +{ + gridBuilder.addGrid(gridShape); + EXPECT_THAT(gridBuilder.getGrids().size(), testing::Eq(2)); + EXPECT_THAT(gridBuilder.getGrid(1)->getDelta(), testing::Eq(0.5 * delta)); +} + +TEST_F(MultipleGridBuilderTestFixture, fineGridExists_addGridWithoutLevel_addsGridAtLevelTwo) +{ + gridBuilder.addGrid(gridShape); + EXPECT_THAT(gridBuilder.getGrids().size(), testing::Eq(2)); + EXPECT_THAT(gridBuilder.getGrid(1)->getDelta(), testing::Eq(0.5 * delta)); + gridBuilder.addGrid(gridShape); + EXPECT_THAT(gridBuilder.getGrids().size(), testing::Eq(3)); + EXPECT_THAT(gridBuilder.getGrid(2)->getDelta(), testing::Eq(0.5 * 0.5 * delta)); +}