From 6379432292a9abeb3e0d107a1eb0cf42a3f97cac Mon Sep 17 00:00:00 2001 From: Anna Wellmann <a.wellmann@tu-braunschweig.de> Date: Wed, 26 Apr 2023 11:41:07 +0000 Subject: [PATCH] Add some tests for the creation of the Parameter class --- src/gpu/VirtualFluids_GPU/CMakeLists.txt | 2 + .../Parameter/ParameterTest.cpp | 75 +++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/src/gpu/VirtualFluids_GPU/CMakeLists.txt b/src/gpu/VirtualFluids_GPU/CMakeLists.txt index ed647cb40..ffab484b2 100644 --- a/src/gpu/VirtualFluids_GPU/CMakeLists.txt +++ b/src/gpu/VirtualFluids_GPU/CMakeLists.txt @@ -24,5 +24,7 @@ if(BUILD_VF_UNIT_TESTS) set_source_files_properties(DataStructureInitializer/GridReaderGenerator/IndexRearrangementForStreamsTest.cpp PROPERTIES LANGUAGE CUDA) set_source_files_properties(Communication/ExchangeData27Test.cpp PROPERTIES LANGUAGE CUDA) set_source_files_properties(BoundaryConditions/BoundaryConditionFactoryTest.cpp PROPERTIES LANGUAGE CUDA) + set_source_files_properties(Parameter/ParameterTest.cpp PROPERTIES LANGUAGE CUDA) target_include_directories(VirtualFluids_GPUTests PRIVATE "${VF_THIRD_DIR}/cuda_samples/") + target_include_directories(VirtualFluids_GPUTests PRIVATE "${VF_ROOT_DIR}/src/gpu/GridGenerator/") endif() diff --git a/src/gpu/VirtualFluids_GPU/Parameter/ParameterTest.cpp b/src/gpu/VirtualFluids_GPU/Parameter/ParameterTest.cpp index b86d56579..bdd22ab27 100644 --- a/src/gpu/VirtualFluids_GPU/Parameter/ParameterTest.cpp +++ b/src/gpu/VirtualFluids_GPU/Parameter/ParameterTest.cpp @@ -4,9 +4,18 @@ #include <iostream> #include <string> +#include "LBM/Simulation.h" #include "Parameter.h" +#include "PointerDefinitions.h" #include "basics/config/ConfigurationFile.h" +#include "Factories/BoundaryConditionFactory.h" +#include "Factories/GridScalingFactory.h" +#include "Communication/Communicator.h" +#include "DataStructureInitializer/GridReaderGenerator/GridGenerator.h" +#include "GPU/CudaMemoryManager.h" +#include "gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilder.h" + TEST(ParameterTest, passingEmptyFileWithoutPath_ShouldNotThrow) { // assuming that the config files is stored parallel to this file. @@ -198,6 +207,72 @@ TEST(ParameterTest, userMissedSlashMultiGPU) EXPECT_THAT(para.getConcentration(), testing::Eq("gridPathTest/0/conc.dat")); } +class MockGridGenerator : public GridGenerator +{ + +public: + MockGridGenerator(std::shared_ptr<GridBuilder> builder, std::shared_ptr<Parameter> para, + std::shared_ptr<CudaMemoryManager> cudaMemoryManager, vf::gpu::Communicator &communicator) + : GridGenerator(builder, para, cudaMemoryManager, communicator) + { + } + + void initalGridInformations() override + { + para->setGridX({ 2, 8 }); + para->setGridY({ 2, 8 }); + para->setGridZ({ 2, 8 }); + para->setDistX({ 0, 0 }); + para->setDistY({ 0, 0 }); + para->setDistZ({ 0, 0 }); + } + void allocArrays_CoordNeighborGeo() override{}; + void setBoundingBox() override{}; + void allocArrays_OffsetScale() override{}; + void allocArrays_BoundaryValues() override{}; + void allocArrays_BoundaryQs() override{}; +}; + +TEST(ParameterTest, whenCreatingParameterClassWithGridRefinement_afterCallingInitLBMSimulationParameter_shouldNotThrow) +{ + auto para = std::make_shared<Parameter>(); + para->setMaxLevel(2); + + para->setGridX({ 2, 8 }); + para->setGridY({ 2, 8 }); + para->setGridZ({ 2, 8 }); + para->setDistX({ 0, 0 }); + para->setDistY({ 0, 0 }); + para->setDistZ({ 0, 0 }); + + EXPECT_THAT(para->getParH(1), testing::Eq(nullptr)); // Parameter initialization incomplete + para->initLBMSimulationParameter(); + EXPECT_THAT(para->getParH(1), testing::Ne(nullptr)); +} + +TEST(ParameterTest, whenCreatingParameterClassWithGridRefinement_afterCallingSimulationConstructor_shouldNotThrow) +{ + spdlog::set_level(spdlog::level::warn); // avoids logger spam in output + + auto para = std::make_shared<Parameter>(); + para->setMaxLevel(2); + + SPtr<CudaMemoryManager> cudaMemoryManager = std::make_shared<CudaMemoryManager>(para); + vf::gpu::Communicator &communicator = vf::gpu::Communicator::getInstance(); + auto gridFactory = GridFactory::make(); + auto gridBuilder = MultipleGridBuilder::makeShared(gridFactory); + SPtr<GridProvider> gridGenerator = + std::make_shared<MockGridGenerator>(gridBuilder, para, cudaMemoryManager, communicator); + BoundaryConditionFactory bcFactory = BoundaryConditionFactory(); + GridScalingFactory scalingFactory = GridScalingFactory(); + + EXPECT_THAT(para->getParH(1), testing::Eq(nullptr)); // Parameter initialization incomplete + // Simulation() calls para->initLBMSimulationParameter() --> that function completes the initialization of Parameter + Simulation sim(para, cudaMemoryManager, communicator, *gridGenerator, &bcFactory, &scalingFactory); + EXPECT_THAT(para->getParH(1), testing::Ne(nullptr)); + EXPECT_NO_THROW(cudaMemoryManager->cudaAllocLevelForcing(1)); // throws if para->getParH(1) is a null pointer +} + class ParameterTestCumulantK17 : public testing::Test { protected: -- GitLab