From 12b66e7511ab45e6f4e80ba7b95d99f0cb8b2f92 Mon Sep 17 00:00:00 2001 From: Kilian Weishaupt Date: Mon, 24 Jun 2019 16:11:37 +0200 Subject: [PATCH] [subgridmanager] Fix clang compiler errors * remove unnecessary traits * add test for alu grid --- dumux/io/grid/gridmanager_sub.hh | 21 +--- test/io/gridmanager/CMakeLists.txt | 2 +- .../gridmanager/test_gridmanager_subgrid.cc | 102 +++++++++++------- .../test_gridmanager_subgrid.input | 4 + 4 files changed, 73 insertions(+), 56 deletions(-) diff --git a/dumux/io/grid/gridmanager_sub.hh b/dumux/io/grid/gridmanager_sub.hh index 74765677a1..04a0690b5e 100644 --- a/dumux/io/grid/gridmanager_sub.hh +++ b/dumux/io/grid/gridmanager_sub.hh @@ -40,13 +40,12 @@ #include #endif -#ifndef DUMUX_IO_GRID_MANAGER_BASE_HH -#include +#ifndef DUMUX_IO_GRID_MANAGER_HH +#include #endif #include #include -#include #if HAVE_DUNE_SUBGRID namespace Dumux { @@ -214,15 +213,6 @@ protected: std::unique_ptr hostGridManager_; }; -// helper to distiguish between yasp grid and others -namespace Impl { -template -struct IsYasp : public std::false_type {}; - -template -struct IsYasp> : public std::true_type {}; -} // end namespace Impl - /*! * \ingroup InputOutput * \brief Provides a grid manager for SubGrids @@ -231,9 +221,8 @@ struct IsYasp> : public std::true_type {}; * The following keys are recognized: * - All parameters that the host grid knows */ -template -class GridManager{}, HostGrid>>> +template +class GridManager> : public SubGridManagerBase> {}; @@ -254,7 +243,7 @@ class GridManager>> using ParentType = SubGridManagerBase, GridManager>>; public: - using ParentType::Grid; + using typename ParentType::Grid; using ParentType::init; /*! diff --git a/test/io/gridmanager/CMakeLists.txt b/test/io/gridmanager/CMakeLists.txt index a2a0a00863..573860e17f 100644 --- a/test/io/gridmanager/CMakeLists.txt +++ b/test/io/gridmanager/CMakeLists.txt @@ -35,7 +35,7 @@ dune_add_test(NAME test_gridmanager_subgrid CMD_ARGS --script fuzzy --command "${CMAKE_CURRENT_BINARY_DIR}/test_gridmanager_subgrid" --files ${CMAKE_SOURCE_DIR}/test/references/subgrid-reference.vtu - ${CMAKE_CURRENT_BINARY_DIR}/subgrid_three.vtu + ${CMAKE_CURRENT_BINARY_DIR}/subgrid_circle_yasp.vtu ${CMAKE_SOURCE_DIR}/test/references/test_gridmanager_subgrid_binary_image.vtu ${CMAKE_CURRENT_BINARY_DIR}/subgrid_binary_image.vtu) diff --git a/test/io/gridmanager/test_gridmanager_subgrid.cc b/test/io/gridmanager/test_gridmanager_subgrid.cc index 2ae3fb7455..23673ae230 100644 --- a/test/io/gridmanager/test_gridmanager_subgrid.cc +++ b/test/io/gridmanager/test_gridmanager_subgrid.cc @@ -21,14 +21,20 @@ #include #include #include +#include #include #include #include #include +#include +#if HAVE_DUNE_ALUGRID +#include +#endif -#include #include +#include + /*! * \brief A method providing an () operator in order to select elements for a subgrid. @@ -52,22 +58,10 @@ private: const GlobalPosition center_; }; -int main(int argc, char** argv) try +template +void testSubGrid(const std::string& hostGridName) { - using namespace Dumux; - - // Initialize MPI, finalize is done automatically on exit. - Dune::MPIHelper::instance(argc, argv); - - // First read parameters from input file. - Dumux::Parameters::init(argc, argv); - - constexpr int dim = 2; - using GlobalPosition = Dune::FieldVector; - - Dune::Timer timer; - using HostGrid = Dune::YaspGrid >; - using SubGridTensor = Dune::SubGrid; + using SubGrid = Dune::SubGrid; using HostGridManager = Dumux::GridManager; HostGridManager externalHostGridManager; @@ -75,6 +69,7 @@ int main(int argc, char** argv) try auto& hostGrid = externalHostGridManager.grid(); // Calculate the bounding box of the host grid view. + using GlobalPosition = Dune::FieldVector; GlobalPosition bBoxMin(std::numeric_limits::max()); GlobalPosition bBoxMax(std::numeric_limits::min()); for (const auto& vertex : vertices(hostGrid.leafGridView())) @@ -93,13 +88,13 @@ int main(int argc, char** argv) try // Write out the host grid and the subgrids. { - Dune::VTKWriter vtkWriter(hostGrid.leafGridView()); + Dune::VTKWriter vtkWriter(hostGrid.leafGridView()); vtkWriter.write("hostgrid"); } // Create different subgrids from the same hostgrid { - std::cout << "Constructing SubGrid with tensor host grid and lambda element selector" << std::endl; + std::cout << "Constructing SubGrid with host grid and lambda element selector" << std::endl; // Select all elements right of the center. auto elementSelector = [¢er](const auto& element) @@ -107,23 +102,10 @@ int main(int argc, char** argv) try return element.geometry().center()[0] > center[0]; }; - Dumux::GridManager subgridManager; - subgridManager.init(hostGrid, elementSelector); - Dune::VTKWriter vtkWriter(subgridManager.grid().leafGridView()); - vtkWriter.write("subgrid_one"); - } - { - std::cout << "Constructing SubGrid with tensor host grid and functor selector" << std::endl; - - // Select all elements within a circle around the center. - // Instead of a lambda, we use a class providing an () operator. - // Of course, a lambda would be possible here, too. - CircleSelector elementSelector(center); - - Dumux::GridManager> subgridManager; + Dumux::GridManager subgridManager; subgridManager.init(hostGrid, elementSelector); - Dune::VTKWriter vtkWriter(subgridManager.grid().leafGridView()); - vtkWriter.write("subgrid_three"); + Dune::VTKWriter vtkWriter(subgridManager.grid().leafGridView()); + vtkWriter.write("subgrid_right"); } // create without contructing host grid first @@ -138,11 +120,55 @@ int main(int argc, char** argv) try Dumux::GridManager> subgridManager; subgridManager.init(elementSelector, "Internal"); - Dune::VTKWriter vtkWriter(subgridManager.grid().leafGridView()); - vtkWriter.write("subgrid_two"); + Dune::VTKWriter vtkWriter(subgridManager.grid().leafGridView()); + vtkWriter.write("subgrid_left"); + } + + { + std::cout << "Constructing SubGrid with host grid and functor selector" << std::endl; + + // Select all elements within a circle around the center. + // Instead of a lambda, we use a class providing an () operator. + // Of course, a lambda would be possible here, too. + CircleSelector elementSelector(center); + + Dumux::GridManager subgridManager; + subgridManager.init(hostGrid, elementSelector); + Dune::VTKWriter vtkWriter(subgridManager.grid().leafGridView()); + vtkWriter.write("subgrid_circle_" + hostGridName); + } +} + +int main(int argc, char** argv) try +{ + using namespace Dumux; + + // Initialize MPI, finalize is done automatically on exit. + Dune::MPIHelper::instance(argc, argv); + + // First read parameters from input file. + Dumux::Parameters::init(argc, argv); + + constexpr int dim = 2; + + { + Dune::Timer timer; + using HostGrid = Dune::YaspGrid >; + testSubGrid("yasp"); + std::cout << "Constructing a yasp host grid and three subgrids took " << timer.elapsed() << " seconds.\n"; + } + + { +#if HAVE_DUNE_ALUGRID + Dune::Timer timer; + using HostGrid = Dune::ALUGrid; + testSubGrid("alu"); + std::cout << "Constructing a alu host grid and three subgrids took " << timer.elapsed() << " seconds.\n"; +#else + std::cout << "Skipped test with ALUGrid as host grid.\n"; +#endif } - // create subgrid from image file { std::cout << "Constructing SubGrid from binary image" << std::endl; using HostGrid = Dune::YaspGrid<2, Dune::EquidistantOffsetCoordinates>; @@ -152,8 +178,6 @@ int main(int argc, char** argv) try vtkWriter.write("subgrid_binary_image"); } - std::cout << "Constructing a host grid and four subgrids took " << timer.elapsed() << " seconds.\n"; - return 0; } /////////////////////////////////////// diff --git a/test/io/gridmanager/test_gridmanager_subgrid.input b/test/io/gridmanager/test_gridmanager_subgrid.input index 91d3347d68..466e42cf7b 100644 --- a/test/io/gridmanager/test_gridmanager_subgrid.input +++ b/test/io/gridmanager/test_gridmanager_subgrid.input @@ -3,6 +3,8 @@ Positions0 = 0 1 Positions1 = 0 1 Cells0 = 1 Cells1 = 1 +UpperRight = 1 1 +Cells = 1 1 Refinement = 4 [Internal.Grid] @@ -10,6 +12,8 @@ Positions0 = 0 1 Positions1 = 0 1 Cells0 = 1 Cells1 = 1 +UpperRight = 1 1 +Cells = 1 1 Refinement = 4 [Image.Grid] -- GitLab