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

Refactor tests for splitting the indices CF into border and bulk

parent b90a1e37
No related branches found
No related tags found
1 merge request!104Add Communication Hiding to GPU version
#include <gmock/gmock.h> #include <gmock/gmock.h>
#include <iostream>
#include <algorithm> #include <algorithm>
#include <filesystem> #include <filesystem>
#include <iostream>
#include <basics/config/ConfigurationFile.h>
#include <Parameter/Parameter.h> #include <Parameter/Parameter.h>
#include <basics/config/ConfigurationFile.h>
#include <DataStructureInitializer/GridReaderGenerator/IndexRearrangementForStreams.h> #include <DataStructureInitializer/GridReaderGenerator/IndexRearrangementForStreams.h>
#include <gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.h> #include <gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.h>
#include <gpu/GridGenerator/grid/GridImp.h> #include <gpu/GridGenerator/grid/GridImp.h>
class GridBuilderDouble : public LevelGridBuilder class LevelGridBuilderDouble : public LevelGridBuilder
{ {
private: private:
SPtr<Grid> grid; SPtr<Grid> grid;
GridBuilderDouble()=default; LevelGridBuilderDouble() = default;
public: public:
GridBuilderDouble(SPtr<Grid> grid) : LevelGridBuilder(Device(), ""), grid(grid){}; LevelGridBuilderDouble(SPtr<Grid> grid) : LevelGridBuilder(Device(), ""), grid(grid){};
SPtr<Grid> getGrid(uint level) override{ return grid; }; SPtr<Grid> getGrid(uint level) override { return grid; };
std::shared_ptr<Grid> getGrid(int level, int box) override {return grid; }; std::shared_ptr<Grid> getGrid(int level, int box) override { return grid; };
}; };
class GridImpDouble : public GridImp class GridImpDouble : public GridImp
{ {
private: private:
...@@ -30,13 +30,13 @@ private: ...@@ -30,13 +30,13 @@ private:
public: public:
GridImpDouble(Object *object, real startX, real startY, real startZ, real endX, real endY, real endZ, real delta, GridImpDouble(Object *object, real startX, real startY, real startZ, real endX, real endY, real endZ, real delta,
SPtr<GridStrategy> gridStrategy, Distribution d, uint level) SPtr<GridStrategy> gridStrategy, Distribution d, uint level)
: GridImp(object, startX, startY, startZ, endX, endY, endZ, delta, gridStrategy, d, level) : GridImp(object, startX, startY, startZ, endX, endY, endZ, delta, gridStrategy, d, level)
{ {
} }
static SPtr<GridImpDouble> makeShared(Object *object, real startX, real startY, real startZ, real endX, real endY, static SPtr<GridImpDouble> makeShared(Object *object, real startX, real startY, real startZ, real endX, real endY,
real endZ, real delta, SPtr<GridStrategy> gridStrategy, Distribution d, real endZ, real delta, SPtr<GridStrategy> gridStrategy, Distribution d,
uint level) uint level)
{ {
SPtr<GridImpDouble> grid( SPtr<GridImpDouble> grid(
...@@ -49,8 +49,10 @@ public: ...@@ -49,8 +49,10 @@ public:
this->fluidNodeIndicesBorder = fluidNodeIndicesBorder; this->fluidNodeIndicesBorder = fluidNodeIndicesBorder;
} }
bool isSparseIndexInFluidNodeIndicesBorder(uint& sparseIndex) const override { bool isSparseIndexInFluidNodeIndicesBorder(uint &sparseIndex) const override
return std::find(this->fluidNodeIndicesBorder.begin(), this->fluidNodeIndicesBorder.end(), sparseIndex)!=this->fluidNodeIndicesBorder.end(); {
return std::find(this->fluidNodeIndicesBorder.begin(), this->fluidNodeIndicesBorder.end(), sparseIndex) !=
this->fluidNodeIndicesBorder.end();
} }
}; };
...@@ -59,7 +61,7 @@ struct CFBorderBulk { ...@@ -59,7 +61,7 @@ struct CFBorderBulk {
std::vector<uint> fluidNodeIndicesBorder = { 10, 11, 12, 13, 14, 15, 16 }; std::vector<uint> fluidNodeIndicesBorder = { 10, 11, 12, 13, 14, 15, 16 };
std::vector<uint> iCellCFC = { 1, 11, 3, 13, 5, 15, 7 }; std::vector<uint> iCellCFC = { 1, 11, 3, 13, 5, 15, 7 };
std::vector<uint> iCellCFF = { 2, 12, 4, 14, 6, 16, 8 }; std::vector<uint> iCellCFF = { 2, 12, 4, 14, 6, 16, 8 };
uint sizeOfICellCf = (uint) iCellCFC.size(); uint sizeOfICellCf = (uint)iCellCFC.size();
uint neighborX_SP[17] = { 0u }; uint neighborX_SP[17] = { 0u };
uint neighborY_SP[17] = { 0u }; uint neighborY_SP[17] = { 0u };
uint neighborZ_SP[17] = { 0u }; uint neighborZ_SP[17] = { 0u };
...@@ -69,19 +71,18 @@ struct CFBorderBulk { ...@@ -69,19 +71,18 @@ struct CFBorderBulk {
std::vector<real> offsetCFz = { 1001, 1011, 1003, 1013, 1005, 1015, 1007 }; std::vector<real> offsetCFz = { 1001, 1011, 1003, 1013, 1005, 1015, 1007 };
// expected data // expected data
std::vector<uint> iCellCfcBorder_expected = { 11, 13, 15 }; std::vector<uint> iCellCfcBorder_expected = { 11, 13, 15 };
std::vector<uint> iCellCfcBulk_expected = { 1, 3, 5, 7 }; std::vector<uint> iCellCfcBulk_expected = { 1, 3, 5, 7 };
std::vector<uint> iCellCffBorder_expected = { 12, 14, 16 }; std::vector<uint> iCellCffBorder_expected = { 12, 14, 16 };
std::vector<uint> iCellCffBulk_expected = { 2, 4, 6, 8 }; std::vector<uint> iCellCffBulk_expected = { 2, 4, 6, 8 };
std::vector<uint> offsetCFx_Border_expected = { 11, 13, 15 }; std::vector<real> offsetCFx_Border_expected = { 11, 13, 15 };
std::vector<uint> offsetCFx_Bulk_expected = { 1, 3, 5, 7 }; std::vector<real> offsetCFx_Bulk_expected = { 1, 3, 5, 7 };
std::vector<uint> offsetCFy_Border_expected = { 111, 113, 115 }; std::vector<real> offsetCFy_Border_expected = { 111, 113, 115 };
std::vector<uint> offsetCFy_Bulk_expected = { 101, 103, 105, 107 }; std::vector<real> offsetCFy_Bulk_expected = { 101, 103, 105, 107 };
std::vector<uint> offsetCFz_Border_expected = { 1011, 1013, 1015 }; std::vector<real> offsetCFz_Border_expected = { 1011, 1013, 1015 };
std::vector<uint> offsetCFz_Bulk_expected = { 1001, 1003, 1005, 1007 }; std::vector<real> offsetCFz_Bulk_expected = { 1001, 1003, 1005, 1007 };
}; };
static SPtr<Parameter> initParameterClass() static SPtr<Parameter> initParameterClass()
{ {
std::filesystem::path filePath = __FILE__; // assuming that the config file is stored parallel to this file. std::filesystem::path filePath = __FILE__; // assuming that the config file is stored parallel to this file.
...@@ -91,14 +92,8 @@ static SPtr<Parameter> initParameterClass() ...@@ -91,14 +92,8 @@ static SPtr<Parameter> initParameterClass()
return std::make_shared<Parameter>(config, 1, 0); return std::make_shared<Parameter>(config, 1, 0);
} }
template <typename T> template <typename T>
bool vectorsAreEqual(std::vector<T> vector1, std::vector<T> vectorExpected) bool vectorsAreEqual(T *vector1, std::vector<T> vectorExpected)
{
return vector1 == vectorExpected;
}
bool vectorsAreEqual(uint *vector1, std::vector<uint> vectorExpected)
{ {
for (uint i = 0; i < vectorExpected.size(); i++) { for (uint i = 0; i < vectorExpected.size(); i++) {
if (vector1[i] != vectorExpected[i]) if (vector1[i] != vectorExpected[i])
...@@ -107,31 +102,22 @@ bool vectorsAreEqual(uint *vector1, std::vector<uint> vectorExpected) ...@@ -107,31 +102,22 @@ bool vectorsAreEqual(uint *vector1, std::vector<uint> vectorExpected)
return true; return true;
} }
bool vectorsAreEqual(real *vector1, std::vector<uint> vectorExpected) class IndexRearrangementForStreamsTest_IndicesCFBorderBulkTest : public testing::Test
{ {
for (uint i = 0; i < vectorExpected.size(); i++) { public:
if (vector1[i] != vectorExpected[i])
return false;
}
return true;
}
class IndexRearrangementForStreamsTest_IndicesCFBorderBulkTest : public testing::Test
{
public:
CFBorderBulk cf; CFBorderBulk cf;
SPtr<Parameter> para; SPtr<Parameter> para;
private: private:
static std::unique_ptr<IndexRearrangementForStreams> createTestSubjectCFBorderBulk(CFBorderBulk &cf, std::shared_ptr<Parameter> para) static std::unique_ptr<IndexRearrangementForStreams> createTestSubjectCFBorderBulk(CFBorderBulk &cf,
std::shared_ptr<Parameter> para)
{ {
SPtr<GridImpDouble> grid = SPtr<GridImpDouble> grid =
GridImpDouble::makeShared(nullptr, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, nullptr, Distribution(), 1); GridImpDouble::makeShared(nullptr, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, nullptr, Distribution(), 1);
grid->setFluidNodeIndicesBorder(cf.fluidNodeIndicesBorder); grid->setFluidNodeIndicesBorder(cf.fluidNodeIndicesBorder);
std::shared_ptr<GridBuilderDouble> builder = std::make_shared<GridBuilderDouble>(grid); std::shared_ptr<LevelGridBuilderDouble> builder = std::make_shared<LevelGridBuilderDouble>(grid);
para->setMaxLevel(cf.level + 1); // setMaxLevel resizes parH and parD para->setMaxLevel(cf.level + 1); // setMaxLevel resizes parH and parD
para->parH[cf.level] = std::make_shared<LBMSimulationParameter>(); para->parH[cf.level] = std::make_shared<LBMSimulationParameter>();
para->parD[cf.level] = std::make_shared<LBMSimulationParameter>(); para->parD[cf.level] = std::make_shared<LBMSimulationParameter>();
para->getParH(cf.level)->intCF.ICellCFC = &(cf.iCellCFC.front()); para->getParH(cf.level)->intCF.ICellCFC = &(cf.iCellCFC.front());
...@@ -144,104 +130,46 @@ class IndexRearrangementForStreamsTest_IndicesCFBorderBulkTest : public testing: ...@@ -144,104 +130,46 @@ class IndexRearrangementForStreamsTest_IndicesCFBorderBulkTest : public testing:
para->getParH(cf.level)->offCF.yOffCF = &(cf.offsetCFy.front()); para->getParH(cf.level)->offCF.yOffCF = &(cf.offsetCFy.front());
para->getParH(cf.level)->offCF.zOffCF = &(cf.offsetCFz.front()); para->getParH(cf.level)->offCF.zOffCF = &(cf.offsetCFz.front());
return std::make_unique<IndexRearrangementForStreams>(para, builder); return std::make_unique<IndexRearrangementForStreams>(para, builder);
}; };
public: void SetUp() override
{
void SetUp() override { para = initParameterClass();
para = initParameterClass(); auto testSubject = createTestSubjectCFBorderBulk(cf, para);
auto testSubject = createTestSubjectCFBorderBulk(cf, para);
testSubject->splitCoarseToFineIntoBorderAndBulk(cf.level); testSubject->splitCoarseToFineIntoBorderAndBulk(cf.level);
} }
void TearDown() override {
}
}; };
TEST_F(IndexRearrangementForStreamsTest_IndicesCFBorderBulkTest, splitCoarseToFineIntoBorderAndBulk) TEST_F(IndexRearrangementForStreamsTest_IndicesCFBorderBulkTest, splitCoarseToFineIntoBorderAndBulk)
{ {
EXPECT_THAT(para->getParH(cf.level)->intCFBorder.kCF + para->getParH(cf.level)->intCFBulk.kCF, testing::Eq(cf.sizeOfICellCf)) << "The number of interpolation cells from coarse to fine changed during reordering."; EXPECT_THAT(para->getParH(cf.level)->intCFBorder.kCF + para->getParH(cf.level)->intCFBulk.kCF,
EXPECT_THAT(para->getParH(cf.level)->intCFBorder.kCF, testing::Eq((uint) cf.iCellCfcBorder_expected.size())); testing::Eq(cf.sizeOfICellCf))
<< "The number of interpolation cells from coarse to fine changed during reordering.";
// check coarse to fine border (coarse nodes)
EXPECT_THAT(para->getParH(cf.level)->intCFBorder.kCF, testing::Eq((uint)cf.iCellCfcBorder_expected.size()));
EXPECT_TRUE(vectorsAreEqual(para->getParH(cf.level)->intCFBorder.ICellCFC, cf.iCellCfcBorder_expected))
<< "intCFBorder.ICellCFC does not match the expected border vector";
// check coarse to fine border (fine nodes)
EXPECT_THAT(para->getParH(cf.level)->intCFBorder.kCF, testing::Eq((uint)cf.iCellCffBorder_expected.size()));
EXPECT_TRUE(vectorsAreEqual(para->getParH(cf.level)->intCFBorder.ICellCFF, cf.iCellCffBorder_expected))
<< "intCFBorder.ICellCFF does not match the expected border vector";
// check coarse to fine bulk (coarse nodes)
EXPECT_THAT(para->getParH(cf.level)->intCFBulk.kCF, testing::Eq((uint)cf.iCellCfcBulk_expected.size()));
EXPECT_TRUE(vectorsAreEqual(para->getParH(cf.level)->intCFBulk.ICellCFC, cf.iCellCfcBulk_expected))
<< "intCFBulk.ICellCFC does not match the expected bulk vector";
// check coarse to fine bulk (fine nodes)
EXPECT_THAT(para->getParH(cf.level)->intCFBulk.kCF, testing::Eq((uint)cf.iCellCffBulk_expected.size()));
EXPECT_TRUE(vectorsAreEqual(para->getParH(cf.level)->intCFBulk.ICellCFF, cf.iCellCffBulk_expected))
<< "intCFBulk.ICellCFF does not match the expected bulk vector";
// check offset cells
EXPECT_TRUE(vectorsAreEqual(para->getParH(cf.level)->offCF.xOffCF, cf.offsetCFx_Border_expected));
EXPECT_TRUE(vectorsAreEqual(para->getParH(cf.level)->offCFBulk.xOffCF, cf.offsetCFx_Bulk_expected));
EXPECT_TRUE(vectorsAreEqual(para->getParH(cf.level)->offCF.yOffCF, cf.offsetCFy_Border_expected));
EXPECT_TRUE(vectorsAreEqual(para->getParH(cf.level)->offCFBulk.yOffCF, cf.offsetCFy_Bulk_expected));
EXPECT_TRUE(vectorsAreEqual(para->getParH(cf.level)->offCF.zOffCF, cf.offsetCFz_Border_expected));
EXPECT_TRUE(vectorsAreEqual(para->getParH(cf.level)->offCFBulk.zOffCF, cf.offsetCFz_Bulk_expected));
} }
// TEST(IndexRearrangementForStreamsTest_IndicesCFBorderBulk, borderVectorCFC)
// {
// CFBorderBulk cf;
// SPtr<Parameter> para;
// initParameterClass(para);
// IndexRearrangementForStreamsTest::setUpAndRun_splitCoarseToFineIntoBorderAndBulk(cf, para);
// EXPECT_TRUE(vectorsAreEqual(para->getParH(cf.level)->intCFBorder.ICellCFC, cf.iCellCfcBorder_expected));
// }
// TEST(IndexRearrangementForStreamsTest_IndicesCFBorderBulk, bulkSizeCFC)
// {
// CFBorderBulk cf;
// SPtr<Parameter> para;
// initParameterClass(para);
// IndexRearrangementForStreamsTest::setUpAndRun_splitCoarseToFineIntoBorderAndBulk(cf, para);
// EXPECT_EQ(para->getParH(cf.level)->intCFBulk.kCF, (uint)cf.iCellCfcBulk_expected.size());
// }
// TEST(IndexRearrangementForStreamsTest_IndicesCFBorderBulk, bulkVectorCFC)
// {
// CFBorderBulk cf;
// SPtr<Parameter> para;
// initParameterClass(para);
// IndexRearrangementForStreamsTest::setUpAndRun_splitCoarseToFineIntoBorderAndBulk(cf, para);
// EXPECT_TRUE(vectorsAreEqual(para->getParH(cf.level)->intCFBulk.ICellCFC, cf.iCellCfcBulk_expected));
// }
// TEST(IndexRearrangementForStreamsTest_IndicesCFBorderBulk, borderSizeCFF)
// {
// CFBorderBulk cf;
// SPtr<Parameter> para;
// initParameterClass(para);
// IndexRearrangementForStreamsTest::setUpAndRun_splitCoarseToFineIntoBorderAndBulk(cf, para);
// EXPECT_EQ(para->getParH(cf.level)->intCFBorder.kCF, (uint)cf.iCellCffBorder_expected.size());
// }
// TEST(IndexRearrangementForStreamsTest_IndicesCFBorderBulk, borderVectorCFF)
// {
// CFBorderBulk cf;
// SPtr<Parameter> para;
// initParameterClass(para);
// IndexRearrangementForStreamsTest::setUpAndRun_splitCoarseToFineIntoBorderAndBulk(cf, para);
// EXPECT_TRUE(vectorsAreEqual(para->getParH(cf.level)->intCFBorder.ICellCFF, cf.iCellCffBorder_expected));
// }
// TEST(IndexRearrangementForStreamsTest_IndicesCFBorderBulk, bulkSizeCFF)
// {
// CFBorderBulk cf;
// SPtr<Parameter> para;
// initParameterClass(para);
// IndexRearrangementForStreamsTest::setUpAndRun_splitCoarseToFineIntoBorderAndBulk(cf, para);
// EXPECT_EQ(para->getParH(cf.level)->intCFBulk.kCF, (uint)cf.iCellCffBulk_expected.size());
// }
// TEST(IndexRearrangementForStreamsTest_IndicesCFBorderBulk, bulkVectorCFF)
// {
// CFBorderBulk cf;
// SPtr<Parameter> para;
// initParameterClass(para);
// IndexRearrangementForStreamsTest::setUpAndRun_splitCoarseToFineIntoBorderAndBulk(cf, para);
// EXPECT_TRUE(vectorsAreEqual(para->getParH(cf.level)->intCFBulk.ICellCFF, cf.iCellCffBulk_expected));
// }
// TEST(IndexRearrangementForStreamsTest_IndicesCFBorderBulk, offsetsVectorsCFC)
// {
// CFBorderBulk cf;
// SPtr<Parameter> para;
// initParameterClass(para);
// IndexRearrangementForStreamsTest::setUpAndRun_splitCoarseToFineIntoBorderAndBulk(cf, para);
// EXPECT_TRUE(vectorsAreEqual(para->getParH(cf.level)->offCF.xOffCF, cf.offsetCFx_Border_expected));
// EXPECT_TRUE(vectorsAreEqual(para->getParH(cf.level)->offCFBulk.xOffCF, cf.offsetCFx_Bulk_expected));
// EXPECT_TRUE(vectorsAreEqual(para->getParH(cf.level)->offCF.yOffCF, cf.offsetCFy_Border_expected));
// EXPECT_TRUE(vectorsAreEqual(para->getParH(cf.level)->offCFBulk.yOffCF, cf.offsetCFy_Bulk_expected));
// EXPECT_TRUE(vectorsAreEqual(para->getParH(cf.level)->offCF.zOffCF, cf.offsetCFz_Border_expected));
// EXPECT_TRUE(vectorsAreEqual(para->getParH(cf.level)->offCFBulk.zOffCF, cf.offsetCFz_Bulk_expected));
// }
\ No newline at end of file
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