From 2bdcae4df6b9d0fea6cd5b55093a26e2f1109648 Mon Sep 17 00:00:00 2001 From: Simon Praetorius Date: Sun, 25 Oct 2020 14:01:58 +0100 Subject: [PATCH 1/3] Add static create method to MeshCreator and implement boundaryIds extraction from gmsh grids --- amdis/MeshCreator.hpp | 46 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/amdis/MeshCreator.hpp b/amdis/MeshCreator.hpp index 080b2838..1db7bc5d 100644 --- a/amdis/MeshCreator.hpp +++ b/amdis/MeshCreator.hpp @@ -66,6 +66,12 @@ namespace AMDiS : name_(name) {} + /// Static create mthod. See \ref create() + static std::shared_ptr create(std::string name) + { + return MeshCreator{name}.create(); + } + /// Create a new grid by inspecting the intifile parameter group `[meshName]` /** * Reads first the parameter `[meshName]->macro file name` and if set @@ -78,7 +84,7 @@ namespace AMDiS * * Otherwise tries to create a grid depending on the grid type. **/ - std::shared_ptr create() const + std::unique_ptr create() const { auto filename = Parameters::get(name_ + "->macro file name"); auto structured = Parameters::get(name_ + "->structured"); @@ -142,15 +148,15 @@ namespace AMDiS } private: - static std::shared_ptr construct(std::unique_ptr hostGrid) + static std::unique_ptr construct(std::unique_ptr hostGrid) { return std::move(hostGrid); } template - static std::shared_ptr construct(std::unique_ptr hostGrid) + static std::unique_ptr construct(std::unique_ptr hostGrid) { - return std::make_shared(std::move(hostGrid)); + return std::make_unique(std::move(hostGrid)); } // use the structured grid factory to create the grid @@ -210,7 +216,37 @@ namespace AMDiS std::unique_ptr read_gmsh_file(std::string const& filename, Dune::PriorityTag<1>) const { Dune::GmshReader reader; - return std::unique_ptr{reader.read(filename)}; // , boundaryIds_, elementIds_)}; + Dune::GridFactory factory; + std::vector boundaryIds, elementIds; + reader.read(factory, filename, boundaryIds, elementIds); + + auto gridPtr = factory.createGrid(); + if (boundaryIds.empty() && elementIds.empty()) + return std::unique_ptr(std::move(gridPtr)); + + // map boundaryIds and elementIds read from file to grid indexing. + + if (!boundaryIds.empty()) + boundaryIds_.resize(gridPtr->numBoundarySegments()); + if (!elementIds.empty()) + elementIds_.resize(gridPtr->size(0)); + + auto const& indexSet = gridPtr->leafIndexSet(); + for (auto const& e : elements(gridPtr->leafGridView())) { + if (!elementIds.empty()) + elementIds_[indexSet.index(e)] = elementIds[factory.insertionIndex(e)]; + + if (boundaryIds.empty() || !e.hasBoundaryIntersections()) + continue; + + for (auto const& it : intersections(gridPtr->leafGridView(), e)) { + if (it.boundary()) + boundaryIds_[it.boundarySegmentIndex()] + = boundaryIds[factory.insertionIndex(it)]; + } + } + + return std::unique_ptr(std::move(gridPtr)); } // fallback if GmshReader cannot be used -- GitLab From f861542413318b884a27cb0fff77ebb53ea63c69 Mon Sep 17 00:00:00 2001 From: Simon Praetorius Date: Thu, 5 Nov 2020 14:22:43 +0100 Subject: [PATCH 2/3] constrain GridFactory access to insertIndex to types that implement this function --- amdis/MeshCreator.hpp | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/amdis/MeshCreator.hpp b/amdis/MeshCreator.hpp index 1db7bc5d..02d5602c 100644 --- a/amdis/MeshCreator.hpp +++ b/amdis/MeshCreator.hpp @@ -205,10 +205,13 @@ namespace AMDiS } } - template - using SupportsGmshReader = decltype(std::declval>().insertBoundarySegment( + template + using SupportsGmshReader = decltype(std::declval>().insertBoundarySegment( std::declval>(), - std::declval >>()) ); + std::declval >>()) ); + + template + using SupportsInsertionIndex = decltype(std::declval>().insertionIndex(std::declval())); // use GmshReader if GridFactory supports insertBoundarySegments template boundaryIds, elementIds; reader.read(factory, filename, boundaryIds, elementIds); + using HasInsertionIndexEntity + = Dune::Std::is_detected::Entity>; + using HasInsertionIndexIntersection + = Dune::Std::is_detected; + auto gridPtr = factory.createGrid(); - if (boundaryIds.empty() && elementIds.empty()) + if ((boundaryIds.empty() && elementIds.empty()) || + (!HasInsertionIndexEntity::value && !HasInsertionIndexIntersection::value)) return std::unique_ptr(std::move(gridPtr)); // map boundaryIds and elementIds read from file to grid indexing. - - if (!boundaryIds.empty()) + if (!boundaryIds.empty() && HasInsertionIndexIntersection::value) boundaryIds_.resize(gridPtr->numBoundarySegments()); - if (!elementIds.empty()) + if (!elementIds.empty() && HasInsertionIndexEntity::value) elementIds_.resize(gridPtr->size(0)); auto const& indexSet = gridPtr->leafIndexSet(); for (auto const& e : elements(gridPtr->leafGridView())) { - if (!elementIds.empty()) - elementIds_[indexSet.index(e)] = elementIds[factory.insertionIndex(e)]; + if constexpr(HasInsertionIndexEntity::value) { + if (!elementIds.empty()) + elementIds_[indexSet.index(e)] = elementIds[factory.insertionIndex(e)]; + } if (boundaryIds.empty() || !e.hasBoundaryIntersections()) continue; for (auto const& it : intersections(gridPtr->leafGridView(), e)) { - if (it.boundary()) - boundaryIds_[it.boundarySegmentIndex()] - = boundaryIds[factory.insertionIndex(it)]; + if constexpr(HasInsertionIndexIntersection::value) { + if (it.boundary()) + boundaryIds_[it.boundarySegmentIndex()] + = boundaryIds[factory.insertionIndex(it)]; + } } } -- GitLab From 6c0019b46c0cf65ffc02578ea8c7c16c56562791 Mon Sep 17 00:00:00 2001 From: Simon Praetorius Date: Thu, 5 Nov 2020 15:31:22 +0100 Subject: [PATCH 3/3] fix tample parameter name --- amdis/MeshCreator.hpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/amdis/MeshCreator.hpp b/amdis/MeshCreator.hpp index 02d5602c..64756f12 100644 --- a/amdis/MeshCreator.hpp +++ b/amdis/MeshCreator.hpp @@ -205,13 +205,13 @@ namespace AMDiS } } - template - using SupportsGmshReader = decltype(std::declval>().insertBoundarySegment( + template + using SupportsGmshReader = decltype(std::declval>().insertBoundarySegment( std::declval>(), - std::declval >>()) ); + std::declval >>()) ); - template - using SupportsInsertionIndex = decltype(std::declval>().insertionIndex(std::declval())); + template + using SupportsInsertionIndex = decltype(std::declval>().insertionIndex(std::declval())); // use GmshReader if GridFactory supports insertBoundarySegments template