From 8728f7f978b38d7399ca334d1479e66d5984ffd2 Mon Sep 17 00:00:00 2001 From: Bernd Flemisch <bernd@iws.uni-stuttgart.de> Date: Wed, 5 Dec 2018 12:55:12 +0100 Subject: [PATCH] [io][gmsh][uggrid] fix reading a Gmsh file into a parallel UGGrid Depending on the Dune version, the boundary markers are present on all processes (<= 2.6) or on the root process only (>= 2.7). Try to handle this in a flexible way in the corresponding data handle: Determine if the minimum size over all processes of the boundary markers vector is zero. If yes, assume that the root process contains all markers and broadcast them. Currently, it isn't possible to refine a parallel UGGrid that has been read by a GmshReader, see dune-grid issue #83. Therefore, don't refine in the corresponding test. --- dumux/io/grid/gmshgriddatahandle.hh | 19 ++++++++++++++++++- dumux/io/grid/griddata.hh | 2 +- test/io/gridmanager/CMakeLists.txt | 6 ++---- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/dumux/io/grid/gmshgriddatahandle.hh b/dumux/io/grid/gmshgriddatahandle.hh index 35bec7cf03..66190d08d7 100644 --- a/dumux/io/grid/gmshgriddatahandle.hh +++ b/dumux/io/grid/gmshgriddatahandle.hh @@ -138,13 +138,29 @@ struct GmshGridDataHandle<Dune::UGGrid<dimgrid>, GridFactory, Data> using Grid = Dune::UGGrid<dimgrid>; using GridView = typename Grid::LevelGridView; - GmshGridDataHandle(const Grid& grid, const GridFactory& gridFactory, Data& elementMarkers) + GmshGridDataHandle(const Grid& grid, const GridFactory& gridFactory, Data& elementMarkers, Data& boundaryMarkers) : gridView_(grid.levelGridView(0)) , idSet_(grid.localIdSet()) , elementMarkers_(elementMarkers) + , boundaryMarkers_(boundaryMarkers) { for (const auto& element : elements(gridView_, Dune::Partitions::interior)) std::swap(elementMarkers_[gridFactory.insertionIndex(element)], data_[idSet_.id(element)]); + + // Depending on the Dune version, the boundary markers are present on + // all processes (<= 2.6) or on the root process only (>= 2.7). Try to + // handle this in a flexible way: determine if the minimum size over + // all processes of the boundary markers vector is zero. If yes, assume + // that the root process contains all markers and broadcast them. + auto bmSizeMin = boundaryMarkers_.size(); + Dune::MPIHelper::getCollectiveCommunication().min(&bmSizeMin, 1); + if (bmSizeMin == 0) + { + auto bmSize = boundaryMarkers_.size(); + Dune::MPIHelper::getCollectiveCommunication().broadcast(&bmSize, 1, 0); + boundaryMarkers_.resize(bmSize); + Dune::MPIHelper::getCollectiveCommunication().broadcast(&boundaryMarkers_.front(), bmSize, 0); + } } ~GmshGridDataHandle() @@ -182,6 +198,7 @@ private: const GridView gridView_; const IdSet &idSet_; Data& elementMarkers_; + Data& boundaryMarkers_; mutable std::map< typename IdSet::IdType, typename Data::value_type> data_; }; diff --git a/dumux/io/grid/griddata.hh b/dumux/io/grid/griddata.hh index f960d0f489..e1b586c25e 100644 --- a/dumux/io/grid/griddata.hh +++ b/dumux/io/grid/griddata.hh @@ -202,7 +202,7 @@ public: template<bool ug = Detail::isUG<Grid>::value, typename std::enable_if_t<ug, int> = 0> DataHandle createGmshDataHandle() { - return DataHandle(*gmshGrid_, *gridFactory_, elementMarkers_); + return DataHandle(*gmshGrid_, *gridFactory_, elementMarkers_, boundaryMarkers_); } private: diff --git a/test/io/gridmanager/CMakeLists.txt b/test/io/gridmanager/CMakeLists.txt index b0c80e77ad..d89013d04b 100644 --- a/test/io/gridmanager/CMakeLists.txt +++ b/test/io/gridmanager/CMakeLists.txt @@ -85,11 +85,9 @@ dune_add_test(NAME test_gridmanager_gmsh_3d_ug_parallel CMAKE_GUARD dune-uggrid_FOUND COMMAND ${CMAKE_SOURCE_DIR}/bin/testing/runtest.py CMD_ARGS --script fuzzy --zeroThreshold {"rank":100} - --command "${MPIEXEC} -np 2 ${CMAKE_CURRENT_BINARY_DIR}/test_gridmanager_gmsh_3d_ug -Problem.Name bifurcation_ug_parallel" + --command "${MPIEXEC} -np 2 ${CMAKE_CURRENT_BINARY_DIR}/test_gridmanager_gmsh_3d_ug -Problem.Name bifurcation_ug_parallel -Grid.Refine false" --files ${CMAKE_SOURCE_DIR}/test/references/gridmanager-bifurcation-3d-reference.vtu - ${CMAKE_CURRENT_BINARY_DIR}/s0002-bifurcation_ug_parallel-00000.pvtu - ${CMAKE_SOURCE_DIR}/test/references/gridmanager-bifurcation-3d-reference-refined.vtu - ${CMAKE_CURRENT_BINARY_DIR}/s0002-bifurcation_ug_parallel-00001.pvtu) + ${CMAKE_CURRENT_BINARY_DIR}/s0002-bifurcation_ug_parallel-00000.pvtu) add_executable(test_gridmanager_gmsh_e_markers_alu EXCLUDE_FROM_ALL test_gridmanager_gmsh_e_markers.cc) target_compile_definitions(test_gridmanager_gmsh_e_markers_alu PUBLIC GRIDTYPE=Dune::ALUGrid<2,2,Dune::simplex,Dune::nonconforming>) -- GitLab