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

Fix bug and add some tests in NeighborDebugWriter

parent dbfe4d72
No related branches found
No related tags found
1 merge request!182Fix bug and add some tests in NeighborDebugWriter
......@@ -5,25 +5,27 @@
#include "Logger.h"
#include "Parameter/Parameter.h"
#include "basics/utilities/UbSystem.h"
#include "grid/NodeValues.h"
#include "gpu/GridGenerator/grid/NodeValues.h"
#include "lbm/constants/D3Q27.h"
#include <basics/writer/WbWriterVtkXmlBinary.h>
#include "Utilities/FindNeighbors.h"
#include "VirtualFluids_GPU/Communication/Communicator.h"
#include "Core/StringUtilities/StringUtil.h"
#include "Utilities/FindNeighbors.h"
#include "gpu/VirtualFluids_GPU/Communication/Communicator.h"
namespace NeighborDebugWriter
{
inline void writeNeighborLinkLines(Parameter *para, const int level, const unsigned long long numberOfNodes, const int direction,
const std::string &name)
inline void writeNeighborLinkLines(Parameter *para, int level, int direction, const std::string &name,
WbWriter *writer)
{
VF_LOG_INFO("Write node links in direction {}.", direction);
std::vector<UbTupleFloat3> nodes(numberOfNodes * 2);
std::vector<UbTupleInt2> cells(numberOfNodes);
std::vector<UbTupleFloat3> nodes;
nodes.reserve(para->getParH(level)->numberOfNodes);
std::vector<UbTupleInt2> cells;
cells.reserve(para->getParH(level)->numberOfNodes/2);
for (size_t position = 0; position < numberOfNodes; position++) {
for (size_t position = 0; position < para->getParH(level)->numberOfNodes; position++) {
if (para->getParH(level)->typeOfGridNode[position] != GEO_FLUID)
continue;
......@@ -42,7 +44,7 @@ inline void writeNeighborLinkLines(Parameter *para, const int level, const unsig
cells.emplace_back((int)nodes.size() - 2, (int)nodes.size() - 1);
}
WbWriterVtkXmlBinary::getInstance()->writeLines(name, nodes, cells);
writer->writeLines(name, nodes, cells);
}
inline void writeNeighborLinkLinesDebug(Parameter *para)
......@@ -51,7 +53,7 @@ inline void writeNeighborLinkLinesDebug(Parameter *para)
for (size_t direction = vf::lbm::dir::STARTDIR; direction <= vf::lbm::dir::ENDDIR; direction++) {
const std::string fileName = para->getFName() + "_" + StringUtil::toString<int>(level) + "_Link_" +
std::to_string(direction) + "_Debug.vtk";
writeNeighborLinkLines(para, level, para->getParH(level)->numberOfNodes, (int)direction, fileName);
writeNeighborLinkLines(para, level, (int)direction, fileName, WbWriterVtkXmlBinary::getInstance());
}
}
}
......
#include "NeighborDebugWriter.hpp"
#include "LBM/LB.h"
#include "PreCollisionInteractor/PreCollisionInteractor.h"
#include "UbTuple.h"
#include "gpu/VirtualFluids_GPU/Utilities/testUtilitiesGPU.h"
#include "lbm/constants/D3Q27.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <iostream>
#include <iterator>
#include <memory>
#include <vector>
class WbWriterSpy : public WbWriter
{
public:
std::string writeLines(const std::string & /*filename*/, std::vector<UbTupleFloat3> &nodes,
std::vector<UbTupleInt2> &lines) override
{
this->nodes = nodes;
this->lines = lines;
return "";
}
std::vector<UbTupleFloat3> nodes;
std::vector<UbTupleInt2> lines;
std::string getFileExtension() override { return ""; }
};
class NeighborDebugWriterTest : public testing::Test
{
protected:
void SetUp() override
{
typeOfGridNode = std::vector<uint>(numberOfNodes, GEO_FLUID);
neighbors = std::vector<uint>(numberOfNodes, 2);
coordinates = std::vector<real>(numberOfNodes, 1.0);
coordinates[2] = 3.0;
para = testingVF::createParameterForLevel(0);
para->getParH(level)->numberOfNodes = numberOfNodes;
para->getParH(level)->coordinateX = coordinates.data();
para->getParH(level)->coordinateY = coordinates.data();
para->getParH(level)->coordinateZ = coordinates.data();
para->getParH(level)->neighborX = neighbors.data();
para->getParH(level)->typeOfGridNode = typeOfGridNode.data();
}
const int level = 0;
const unsigned long long numberOfNodes = 3;
const uint direction = vf::lbm::dir::DIR_P00; // x
std::shared_ptr<Parameter> para;
WbWriterSpy writerSpy;
std::vector<uint> typeOfGridNode;
std::vector<uint> neighbors;
std::vector<real> coordinates;
};
TEST_F(NeighborDebugWriterTest, writeNeighborLinkLinesOnlyFLuidNodes)
{
UbTupleFloat3 oneCoord(1.0, 1.0, 1.0);
UbTupleFloat3 threeCoord(3.0, 3.0, 3.0);
std::vector<UbTupleFloat3> expectedNodes = { oneCoord, threeCoord, oneCoord, threeCoord, threeCoord, threeCoord };
std::vector<UbTupleInt2> expectedLines = { UbTupleInt2(0, 1), UbTupleInt2(2, 3), UbTupleInt2(4, 5) };
NeighborDebugWriter::writeNeighborLinkLines(para.get(), level, direction, "name", &writerSpy);
EXPECT_THAT(writerSpy.nodes.size(), testing::Eq(numberOfNodes * 2));
EXPECT_THAT(writerSpy.lines.size(), testing::Eq(numberOfNodes));
EXPECT_THAT(writerSpy.nodes, testing::Eq(expectedNodes));
EXPECT_THAT(writerSpy.lines, testing::Eq(expectedLines));
}
TEST_F(NeighborDebugWriterTest, writeNeighborLinkLinesOneSolidNode)
{
typeOfGridNode[2] = GEO_SOLID;
UbTupleFloat3 oneCoord(1.0, 1.0, 1.0);
UbTupleFloat3 threeCoord(3.0, 3.0, 3.0);
std::vector<UbTupleFloat3> expectedNodes = { oneCoord, threeCoord, oneCoord, threeCoord};
std::vector<UbTupleInt2> expectedLines = { UbTupleInt2(0, 1), UbTupleInt2(2, 3)};
NeighborDebugWriter::writeNeighborLinkLines(para.get(), level, direction, "name", &writerSpy);
EXPECT_THAT(writerSpy.nodes.size(), testing::Eq((numberOfNodes-1) * 2));
EXPECT_THAT(writerSpy.lines.size(), testing::Eq(numberOfNodes-1));
EXPECT_THAT(writerSpy.nodes, testing::Eq(expectedNodes));
EXPECT_THAT(writerSpy.lines, testing::Eq(expectedLines));
}
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