From c512d74de7f1a5d2b14037e8b1c073474c5d49f7 Mon Sep 17 00:00:00 2001 From: Anna Wellmann <a.wellmann@tu-bs.de> Date: Thu, 19 Jan 2023 10:36:58 +0000 Subject: [PATCH] Check velocity and viscosity user inputs --- .../VirtualFluids_GPU/Parameter/Parameter.cpp | 25 ++++++ .../VirtualFluids_GPU/Parameter/Parameter.h | 2 + .../Parameter/ParameterTest.cpp | 87 ++++++++++++++++++- 3 files changed, 113 insertions(+), 1 deletion(-) diff --git a/src/gpu/VirtualFluids_GPU/Parameter/Parameter.cpp b/src/gpu/VirtualFluids_GPU/Parameter/Parameter.cpp index 133b6dccf..0786c85e5 100644 --- a/src/gpu/VirtualFluids_GPU/Parameter/Parameter.cpp +++ b/src/gpu/VirtualFluids_GPU/Parameter/Parameter.cpp @@ -43,6 +43,7 @@ #include <basics/config/ConfigurationFile.h> +#include "Logger.h" #include "Parameter/CudaStreamManager.h" Parameter::Parameter() : Parameter(1, 0, {}) {} @@ -588,6 +589,30 @@ void Parameter::initLBMSimulationParameter() parD[i]->distY = parH[i]->distY; parD[i]->distZ = parH[i]->distZ; } + + checkParameterValidityCumulantK17(); +} + +void Parameter::checkParameterValidityCumulantK17() +{ + if (this->mainKernel != "CumulantK17") + return; + + real viscosity = this->parH[maxlevel]->vis; + real viscosityLimit = 1.0 / 42.0; + if (viscosity > viscosityLimit) { + VF_LOG_WARNING("The viscosity (in LB units) at level {} is {:1.3g}. It is recommended to keep it smaller than {:1.3g} " + "for the CumulantK17 collision kernel.", + maxlevel, viscosity, viscosityLimit); + } + + real velocity = this->ic.u0; + real velocityLimit = 0.1; + if (velocity > velocityLimit) { + VF_LOG_WARNING("The velocity (in LB units) is {:1.4g}. It is recommended to keep it smaller than {:1.4g} for the " + "CumulantK17 collision kernel.", + velocity, velocityLimit); + } } void Parameter::copyMeasurePointsArrayToVector(int lev) diff --git a/src/gpu/VirtualFluids_GPU/Parameter/Parameter.h b/src/gpu/VirtualFluids_GPU/Parameter/Parameter.h index 2e6d99fa6..3e8f1232e 100644 --- a/src/gpu/VirtualFluids_GPU/Parameter/Parameter.h +++ b/src/gpu/VirtualFluids_GPU/Parameter/Parameter.h @@ -938,6 +938,8 @@ private: void setPathAndFilename(std::string fname); + void checkParameterValidityCumulantK17(); + private: bool compOn{ false }; bool diffOn{ false }; diff --git a/src/gpu/VirtualFluids_GPU/Parameter/ParameterTest.cpp b/src/gpu/VirtualFluids_GPU/Parameter/ParameterTest.cpp index 4025acf7a..167ee6cbc 100644 --- a/src/gpu/VirtualFluids_GPU/Parameter/ParameterTest.cpp +++ b/src/gpu/VirtualFluids_GPU/Parameter/ParameterTest.cpp @@ -199,4 +199,89 @@ TEST(ParameterTest, userMissedSlashMultiGPU) EXPECT_THAT(para.getGridPath(), testing::Eq("gridPathTest/0/")); EXPECT_THAT(para.getConcentration(), testing::Eq("gridPathTest/0/conc.dat")); -} \ No newline at end of file +} + +TEST(ParameterTest, CumulantK17_VelocityIsTooHigh_expectWarning) +{ + testing::internal::CaptureStdout(); + + Parameter para; + para.setVelocityLB(0.11); + para.setMainKernel("CumulantK17"); + + para.initLBMSimulationParameter(); + + std::string output = testing::internal::GetCapturedStdout(); + EXPECT_FALSE(output.find("warning") == std::string::npos); +} + +TEST(ParameterTest, CumulantK17_VelocityIsOk_expectNoWarning) +{ + testing::internal::CaptureStdout(); + + Parameter para; + para.setVelocityLB(0.09); + para.setMainKernel("CumulantK17"); + + para.initLBMSimulationParameter(); + + std::string output = testing::internal::GetCapturedStdout(); + EXPECT_TRUE(output.find("warning") == std::string::npos); +} + +TEST(ParameterTest, NotCumulantK17_VelocityIsTooHigh_expectNoWarning) +{ + testing::internal::CaptureStdout(); + + Parameter para; + para.setVelocityLB(42); + para.setMainKernel("K"); + + para.initLBMSimulationParameter(); + + std::string output = testing::internal::GetCapturedStdout(); + EXPECT_TRUE(output.find("warning") == std::string::npos); +} + + +TEST(ParameterTest, CumulantK17_ViscosityIsTooHigh_expectWarning) +{ + testing::internal::CaptureStdout(); + + Parameter para; + para.setViscosityLB(0.024); + para.setMainKernel("CumulantK17"); + + para.initLBMSimulationParameter(); + + std::string output = testing::internal::GetCapturedStdout(); + EXPECT_FALSE(output.find("warning") == std::string::npos); +} + +TEST(ParameterTest, CumulantK17_ViscosityIsOk_expectNoWarning) +{ + testing::internal::CaptureStdout(); + + Parameter para; + para.setViscosityLB(0.023); + para.setMainKernel("CumulantK17"); + + para.initLBMSimulationParameter(); + + std::string output = testing::internal::GetCapturedStdout(); + EXPECT_TRUE(output.find("warning") == std::string::npos); +} + +TEST(ParameterTest, NotCumulantK17_ViscosityIsTooHigh_expectNoWarning) +{ + testing::internal::CaptureStdout(); + + Parameter para; + para.setViscosityLB(10); + para.setMainKernel("K"); + + para.initLBMSimulationParameter(); + + std::string output = testing::internal::GetCapturedStdout(); + EXPECT_TRUE(output.find("warning") == std::string::npos); +} -- GitLab