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

Merge branch 'tests/GridScalingFactory' into 'develop'

Add some more tests to GridScalingManager and BCKernelManager

See merge request irmb/VirtualFluids_dev!229
parents 06600ae3 94633e24
No related branches found
No related tags found
1 merge request!229Add some more tests to GridScalingManager and BCKernelManager
......@@ -161,15 +161,14 @@ public:
// void setOutflowBoundaryCondition(...); // TODO:
// https://git.rz.tu-bs.de/m.schoenherr/VirtualFluids_dev/-/issues/16
[[nodiscard]] boundaryCondition getVelocityBoundaryConditionPost(bool isGeometryBC = false) const;
[[nodiscard]] virtual boundaryCondition getVelocityBoundaryConditionPost(bool isGeometryBC = false) const;
[[nodiscard]] boundaryCondition getNoSlipBoundaryConditionPost(bool isGeometryBC = false) const;
[[nodiscard]] boundaryCondition getSlipBoundaryConditionPost(bool isGeometryBC = false) const;
[[nodiscard]] boundaryCondition getPressureBoundaryConditionPre() const;
[[nodiscard]] boundaryCondition getGeometryBoundaryConditionPost() const;
[[nodiscard]] precursorBoundaryConditionFunc getPrecursorBoundaryConditionPost() const;
[[nodiscard]] boundaryConditionWithParameter getStressBoundaryConditionPost() const;
[[nodiscard]] precursorBoundaryConditionFunc getPrecursorBoundaryConditionPost() const;
private:
VelocityBC velocityBoundaryCondition = VelocityBC::NotSpecified;
......
......@@ -55,6 +55,8 @@ TEST(BoundaryConditionFactoryTest, defaultStressBC)
EXPECT_THROW(bc(nullptr, nullptr, 0), std::bad_function_call);
}
// tests for boundary conditions which are set by the user (tests both set and get functions)
bcFunction getVelocityBcTarget(BoundaryConditionFactory &bcFactory)
{
auto bc = bcFactory.getVelocityBoundaryConditionPost();
......@@ -63,8 +65,6 @@ bcFunction getVelocityBcTarget(BoundaryConditionFactory &bcFactory)
return bcTarget;
}
// tests for boundary conditions whcih are set by the user (tests both set and get functions)
TEST(BoundaryConditionFactoryTest, velocityBC)
{
auto bcFactory = BoundaryConditionFactory();
......
#include <gmock/gmock.h>
#include <stdexcept>
......@@ -18,44 +19,123 @@ protected:
}
};
TEST_F(BCKernelManagerTest_BCsNotSpecified, velocityBoundaryConditionPost_NotSpecified)
TEST_F(BCKernelManagerTest_BCsNotSpecified, velocityBoundaryConditionPostNotSpecified_noBoundaryNodes_doesNotThrow)
{
para->getParD(0)->velocityBC.numberOfBCnodes = 0;
EXPECT_NO_THROW(BCKernelManager(para, &bcFactory));
}
TEST_F(BCKernelManagerTest_BCsNotSpecified, velocityBoundaryConditionPostNotSpecified_withBoundaryNodes_throws)
{
para->getParD(0)->velocityBC.numberOfBCnodes = 1;
EXPECT_THROW(BCKernelManager(para, &bcFactory), std::runtime_error);
}
TEST_F(BCKernelManagerTest_BCsNotSpecified, noSlipBoundaryConditionPost_NotSpecified)
TEST_F(BCKernelManagerTest_BCsNotSpecified, noSlipBoundaryConditionPostNotSpecified_noBoundaryNodes_doesNotThrow)
{
para->getParD(0)->noSlipBC.numberOfBCnodes = 0;
EXPECT_NO_THROW(BCKernelManager(para, &bcFactory));
}
TEST_F(BCKernelManagerTest_BCsNotSpecified, noSlipBoundaryConditionPostNotSpecified_withBoundaryNodes_doesNotThrow)
{
para->getParD(0)->noSlipBC.numberOfBCnodes = 1;
EXPECT_NO_THROW(BCKernelManager(para, &bcFactory)); // no throw, as a default is specified
}
TEST_F(BCKernelManagerTest_BCsNotSpecified, slipBoundaryConditionPost_NotSpecified)
TEST_F(BCKernelManagerTest_BCsNotSpecified, slipBoundaryConditionPostNotSpecified_noBoundaryNodes_doesNotThrow)
{
para->getParD(0)->slipBC.numberOfBCnodes = 0;
EXPECT_NO_THROW(BCKernelManager(para, &bcFactory));
}
TEST_F(BCKernelManagerTest_BCsNotSpecified, slipBoundaryConditionPostNotSpecified_withBoundaryNodes_throws)
{
para->getParD(0)->slipBC.numberOfBCnodes = 1;
EXPECT_THROW(BCKernelManager(para, &bcFactory), std::runtime_error);
}
TEST_F(BCKernelManagerTest_BCsNotSpecified, pressureBoundaryConditionPre_NotSpecified)
TEST_F(BCKernelManagerTest_BCsNotSpecified, pressureBoundaryConditionPreNotSpecified_noBoundaryNodes_doesNotThrow)
{
para->getParD(0)->pressureBC.numberOfBCnodes = 0;
EXPECT_NO_THROW(BCKernelManager(para, &bcFactory));
}
TEST_F(BCKernelManagerTest_BCsNotSpecified, pressureBoundaryConditionPreNotSpecified_withBoundaryNodes_throws)
{
para->getParD(0)->pressureBC.numberOfBCnodes = 1;
EXPECT_THROW(BCKernelManager(para, &bcFactory), std::runtime_error);
}
TEST_F(BCKernelManagerTest_BCsNotSpecified, geometryBoundaryConditionPost_NotSpecified)
TEST_F(BCKernelManagerTest_BCsNotSpecified, geometryBoundaryConditionPostNotSpecified_noBoundaryNodes_doesNotThrow)
{
para->getParD(0)->geometryBC.numberOfBCnodes = 0;
EXPECT_NO_THROW(BCKernelManager(para, &bcFactory));
}
TEST_F(BCKernelManagerTest_BCsNotSpecified, geometryBoundaryConditionPostNotSpecified_withBoundaryNodes_doesNotThrow)
{
para->getParD(0)->geometryBC.numberOfBCnodes = 1;
EXPECT_NO_THROW(BCKernelManager(para, &bcFactory)); // no throw, as a default is specified
}
TEST_F(BCKernelManagerTest_BCsNotSpecified, stressBoundaryConditionPost_NotSpecified)
TEST_F(BCKernelManagerTest_BCsNotSpecified, stressBoundaryConditionPostNotSpecified_noBoundaryNodes_doesNotThrow)
{
para->getParD(0)->stressBC.numberOfBCnodes = 0;
EXPECT_NO_THROW(BCKernelManager(para, &bcFactory));
}
TEST_F(BCKernelManagerTest_BCsNotSpecified, stressBoundaryConditionPostNotSpecified_withBoundaryNodes_throws)
{
para->getParD(0)->stressBC.numberOfBCnodes = 1;
EXPECT_THROW(BCKernelManager(para, &bcFactory), std::runtime_error);
}
TEST_F(BCKernelManagerTest_BCsNotSpecified, precursorBoundaryConditionPost_NotSpecified)
TEST_F(BCKernelManagerTest_BCsNotSpecified, precursorBoundaryConditionPostNotSpecified_noBoundaryNodes_doesNotThrow)
{
para->getParD(0)->precursorBC.numberOfBCnodes = 0;
EXPECT_NO_THROW(BCKernelManager(para, &bcFactory));
}
TEST_F(BCKernelManagerTest_BCsNotSpecified, precursorBoundaryConditionPostNotSpecified_withBoundaryNodes_throws)
{
para->getParD(0)->precursorBC.numberOfBCnodes = 1;
EXPECT_THROW(BCKernelManager(para, &bcFactory), std::runtime_error);
}
class BoundaryConditionFactoryMock : public BoundaryConditionFactory
{
public:
mutable uint numberOfCalls = 0;
[[nodiscard]] boundaryCondition getVelocityBoundaryConditionPost(bool) const override
{
return [this](LBMSimulationParameter *, QforBoundaryConditions *) { numberOfCalls++; };
}
};
class BCKernelManagerTest_runBCs : public testing::Test
{
protected:
BoundaryConditionFactoryMock bcFactory;
SPtr<Parameter> para = std::make_shared<Parameter>();
UPtr<BCKernelManager> sut;
void SetUp() override
{
para->initLBMSimulationParameter();
sut = std::make_unique<BCKernelManager>(para, &bcFactory);
}
};
TEST_F(BCKernelManagerTest_runBCs, runVelocityBCKernelPost)
{
para->getParD(0)->velocityBC.numberOfBCnodes = 1;
sut->runVelocityBCKernelPost(0);
EXPECT_THAT(bcFactory.numberOfCalls, testing::Eq(1));
bcFactory.numberOfCalls = 0;
para->getParD(0)->velocityBC.numberOfBCnodes = 0;
sut->runVelocityBCKernelPost(0);
EXPECT_THAT(bcFactory.numberOfCalls, testing::Eq(0));
}
#include <gmock/gmock.h>
#include <stdexcept>
#include "GridScalingKernelManager.h"
#include "Factories/GridScalingFactory.h"
#include "Parameter/Parameter.h"
#include "PointerDefinitions.h"
class GridScalingKernelManagerTest_Initialization : public testing::Test
{
protected:
GridScalingFactory scalingFactory;
SPtr<Parameter> para = std::make_shared<Parameter>();
void SetUp() 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});
}
};
TEST_F(GridScalingKernelManagerTest_Initialization, singleLevel_noScalingFactoryProvided_doesNotThrow)
{
// only one level --> no scaling factory needed --> no error
para->initLBMSimulationParameter();
EXPECT_NO_THROW(GridScalingKernelManager(para, nullptr));
}
TEST_F(GridScalingKernelManagerTest_Initialization, singleLevel_scalingFactoryProvided_doesNotThrow)
{
// only one level --> no scaling function needed --> no error
para->initLBMSimulationParameter();
EXPECT_NO_THROW(GridScalingKernelManager(para, &scalingFactory));
}
TEST_F(GridScalingKernelManagerTest_Initialization, singleLevel_scalingFactoryAndFunctionProvided_doesNotThrow)
{
// only one level, but the user provided a scaling function anyway --> no error
para->initLBMSimulationParameter();
scalingFactory.setScalingFactory(GridScalingFactory::GridScaling::ScaleCompressible);
EXPECT_NO_THROW(GridScalingKernelManager(para, &scalingFactory));
}
TEST_F(GridScalingKernelManagerTest_Initialization, multipleLevels_notScalingFactoryProvided_throws)
{
// multiple levels, but the user forgot the scaling factory --> error
para->setMaxLevel(2);
para->initLBMSimulationParameter();
EXPECT_THROW(GridScalingKernelManager(para, nullptr), std::runtime_error);
}
TEST_F(GridScalingKernelManagerTest_Initialization, multipleLevelWithoutInterpolationNodes_noScalingFunctionProvided_doesNotThrow)
{
// multiple levels, but no interpolation nodes specified --> no scaling function needed --> no error
para->setMaxLevel(2);
para->initLBMSimulationParameter();
EXPECT_NO_THROW(GridScalingKernelManager(para, &scalingFactory));
}
TEST_F(GridScalingKernelManagerTest_Initialization, multipleLevelWithoutInterpolationNodes_scalingFunctionProvided_doesNotThrow)
{
// multiple levels and NO interpolation nodes specified, but the user provided a scaling function anyway --> no error
para->setMaxLevel(2);
para->initLBMSimulationParameter();
scalingFactory.setScalingFactory(GridScalingFactory::GridScaling::ScaleRhoSq);
EXPECT_NO_THROW(GridScalingKernelManager(para, &scalingFactory));
}
TEST_F(GridScalingKernelManagerTest_Initialization, multipleLevelWithInterpolationNodes_noScalingFunctionProvided_throws)
{
// multiple levels and interpolation nodes specified, but the user forgot to set the scalingFunction --> error
para->setMaxLevel(2);
para->initLBMSimulationParameter();
para->getParD(0)->fineToCoarse.numberOfCells = 100;
EXPECT_THROW(GridScalingKernelManager(para, &scalingFactory), std::runtime_error);
}
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