diff --git a/src/basics/tests/testUtilities.h b/src/basics/tests/testUtilities.h index 43fd5d822a10c6e9756c348f3e7dfb71c285ab71..ed7f88d1b757486280c2da88cee4b4b593d2e84a 100644 --- a/src/basics/tests/testUtilities.h +++ b/src/basics/tests/testUtilities.h @@ -19,4 +19,20 @@ inline auto RealNear = [](auto value, auto max_abs_error) { #endif }; +namespace testingVF +{ + +__inline__ void captureStdOut() +{ + testing::internal::CaptureStdout(); +} + +__inline__ bool stdoutContainsWarning() +{ + std::string output = testing::internal::GetCapturedStdout(); + return output.find("warning") != std::string::npos; +} + +} // namespace testingVF + #endif diff --git a/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilder.cpp b/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilder.cpp index 7403888ad231d80f7fbe67b7ac48ddc202c3e7a8..c54ba6f68514a6ea8c6d9e696b9b87fbe24a1ba4 100644 --- a/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilder.cpp +++ b/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilder.cpp @@ -102,18 +102,16 @@ void MultipleGridBuilder::addGrid(SPtr<Object> gridShape) void MultipleGridBuilder::addGrid(SPtr<Object> gridShape, uint levelFine) { - if (!coarseGridExists()) - return emitNoCoarseGridExistsWarning(); + if (!coarseGridExists()) return emitNoCoarseGridExistsWarning(); - for( uint level = this->getNumberOfLevels(); level <= levelFine; level++ ){ + for (uint level = this->getNumberOfLevels(); level <= levelFine; level++) { const auto grid = makeGrid(gridShape, level, levelFine); - if(level != levelFine){ + if (level != levelFine) { grid->setInnerRegionFromFinerGrid(true); - grid->setNumberOfLayers( this->numberOfLayersBetweenLevels ); - } - else{ - grid->setNumberOfLayers( this->numberOfLayersFine ); + grid->setNumberOfLayers(this->numberOfLayersBetweenLevels); + } else { + grid->setNumberOfLayers(this->numberOfLayersFine); } grids.push_back(grid); @@ -124,15 +122,14 @@ void MultipleGridBuilder::addGrid(SPtr<Object> gridShape, uint levelFine) // this did not work for concave geometries ////////////////////////////////////////////////////////////////////////// - //const uint nodesBetweenGrids = 12; - //const uint levelDifference = levelFine - getNumberOfLevels(); - //const uint oldGridSize = this->getNumberOfLevels(); - - //addIntermediateGridsToList(levelDifference, levelFine, nodesBetweenGrids, gridShape); - //addFineGridToList(levelFine, gridShape->clone()); + // const uint nodesBetweenGrids = 12; + // const uint levelDifference = levelFine - getNumberOfLevels(); + // const uint oldGridSize = this->getNumberOfLevels(); + // addIntermediateGridsToList(levelDifference, levelFine, nodesBetweenGrids, gridShape); + // addFineGridToList(levelFine, gridShape->clone()); - //eraseGridsFromListIfInvalid(oldGridSize); + // eraseGridsFromListIfInvalid(oldGridSize); } void MultipleGridBuilder::addFineGridToList(uint level, SPtr<Object> gridShape) diff --git a/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilderTest.cpp b/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilderTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4e89a142289af6b99065687becd68d0491217bb2 --- /dev/null +++ b/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilderTest.cpp @@ -0,0 +1,25 @@ +#include "basics/tests/testUtilities.h" +#include "geometries/Sphere/Sphere.h" +#include "grid/GridBuilder/MultipleGridBuilder.h" + +TEST(MultipleGridBuilderTest, noCoarseGrid_addFineGrid_warns) +{ + MultipleGridBuilder gridBuilder; + SPtr<Object> gridShape; + + testingVF::captureStdOut(); + gridBuilder.addGrid(gridShape, 1); + EXPECT_TRUE(testingVF::stdoutContainsWarning()); +} + +TEST(MultipleGridBuilderTest, coarseGridExist_addFineGrid_doesNotWarn) +{ + MultipleGridBuilder gridBuilder; + + SPtr<Object> gridShape = std::make_shared<Sphere>(0.0, 0.0, 0.0, 0.0); + gridBuilder.addCoarseGrid(0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.1); + + testingVF::captureStdOut(); + gridBuilder.addGrid(gridShape, 1); + EXPECT_FALSE(testingVF::stdoutContainsWarning()); +} \ No newline at end of file diff --git a/src/gpu/VirtualFluids_GPU/Parameter/ParameterTest.cpp b/src/gpu/VirtualFluids_GPU/Parameter/ParameterTest.cpp index 2eee0f7f2e88ee3315e6c80fe6e7827141979a80..6e512623fb4a4b4869aff7893216f732bb5d15a9 100644 --- a/src/gpu/VirtualFluids_GPU/Parameter/ParameterTest.cpp +++ b/src/gpu/VirtualFluids_GPU/Parameter/ParameterTest.cpp @@ -18,6 +18,8 @@ #include <parallel/Communicator.h> +using namespace testingVF; + TEST(ParameterTest, passingEmptyFileWithoutPath_ShouldNotThrow) { // assuming that the config files is stored parallel to this file. @@ -259,12 +261,6 @@ protected: { } - bool stdoutContainsWarning() - { - std::string output = testing::internal::GetCapturedStdout(); - return output.find("warning") != std::string::npos; - } - Parameter para; };