Skip to content
Snippets Groups Projects
Commit 38c78c20 authored by Anna Wellmann's avatar Anna Wellmann
Browse files

Merge branch 'multiLevelTest' into 'develop'

Add some tests for the creation of the Parameter class

See merge request irmb/VirtualFluids_dev!227
parents c1007231 63794322
No related branches found
No related tags found
1 merge request!227Add some tests for the creation of the Parameter class
......@@ -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()
......@@ -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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment