diff --git a/dune/multimesh/multigridview.hh b/dune/multimesh/multigridview.hh index 6f08151ff06ed348988b19c791d9e539fbc6265d..d9942373e36cb0957db72d7fdc0eb6232aac076f 100644 --- a/dune/multimesh/multigridview.hh +++ b/dune/multimesh/multigridview.hh @@ -17,46 +17,10 @@ #include #include "mmiterator.hh" +#include "multiindexset.hh" namespace Dune { - template - class MultiIndexSet - { - public: - using LeafIndexSet = typename HostGrid::Traits::LeafIndexSet; - using LevelIndexSet = typename HostGrid::Traits::LevelIndexSet; - - using IndexType = std::common_type_t; - - using IndexSetTypes = std::variant; - - template - MultiIndexSet(IndexSet const* indexSet) - : indexSets_(indexSet) - {} - - MultiIndexSet(IndexSetTypes const& indexSet) - : indexSets_(indexSet) - {} - - template - IndexType index (const Entity& e) const - { - return std::visit([&e](auto const* is) -> IndexType { return is->index(e); }, indexSets_); - } - - template - IndexType subIndex (const Entity& e, int i, unsigned int codim) const - { - return std::visit([&e,i,codim](auto const* is) -> IndexType { return is->subIndex(e,i,codim); }, indexSets_); - } - - private: - IndexSetTypes indexSets_; - }; - - // forward declaration template class MultiGridView; @@ -104,8 +68,9 @@ namespace Dune using Grid = typename Traits::Grid; using GridViewTypes = std::variant; + using IndexSet = typename Traits::IndexSet; - using IndexSetTypes = std::variant; + using IndexSetTypes = typename IndexSet::IndexSetTypes; using IntersectionIterator = typename Traits::IntersectionIterator; using CollectiveCommunication = typename Traits::CollectiveCommunication; @@ -194,14 +159,16 @@ namespace Dune // NOTE: IntersectionIterator is one of {LeafIntersectionIterator, LevelIntersectionIterator} IntersectionIterator ibegin (std::size_t idx, const typename Codim<0>::Entity& entity) const { - return std::visit([&entity](auto const& gv) { return gv.ibegin(entity); }, gridViews_[idx]); + using II = IntersectionIterator; + return std::visit([&entity](auto const& gv) -> II { return gv.ibegin(entity); }, gridViews_[idx]); } /// Obtain end intersection iterator with respect to this view // NOTE: IntersectionIterator is one of {LeafIntersectionIterator, LevelIntersectionIterator} IntersectionIterator iend (std::size_t idx, const typename Codim<0>::Entity& entity) const { - return std::visit([&entity](auto const& gv) { return gv.iend(entity); }, gridViews_[idx]); + using II = IntersectionIterator; + return std::visit([&entity](auto const& gv) -> II { return gv.iend(entity); }, gridViews_[idx]); } /// Obtain collective communication object diff --git a/dune/multimesh/multiindexset.hh b/dune/multimesh/multiindexset.hh new file mode 100644 index 0000000000000000000000000000000000000000..1ebfb38a6b88d01dc76558f6d7051d98b85f8c8a --- /dev/null +++ b/dune/multimesh/multiindexset.hh @@ -0,0 +1,113 @@ +// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- +// vi: set et ts=4 sw=2 sts=2: +#ifndef DUNE_MULTI_INDEXSET_HH +#define DUNE_MULTI_INDEXSET_HH + +#if ! DUNE_HAVE_CXX_VARIANT +#error "Require C++17 variant!" +#endif + +#include +#include + +#include +#include +#include + +#include + +namespace Dune +{ + // forward declaration + template + class MultiGridView; + + template + class MultiIndexSet + { + private: + using LeafIndexSet = typename HostGrid::Traits::LeafIndexSet; + using LevelIndexSet = typename HostGrid::Traits::LevelIndexSet; + using IndexSetTypes = std::variant; + + friend class MultiGridView; + + public: + using IndexType = typename LeafIndexSet::IndexType; + using Types = typename LeafIndexSet::Types; + + static const int dimension = LeafIndexSet::dimension; + + public: + template + MultiIndexSet (IndexSet const* indexSet) + : indexSets_(indexSet) + {} + + MultiIndexSet (IndexSetTypes const& indexSet) + : indexSets_(indexSet) + {} + + /// Map entity to index. + template + IndexType index (const Entity& e) const + { + return std::visit([&e](auto const* is) { return is->index(e); }, indexSets_); + } + + /// Map entity to index. + template + IndexType index (const typename LeafIndexSet::Traits::template Codim::Entity& e) const + { + return std::visit([&e](auto const* is) { return is->template index(e); }, indexSets_); + } + + /// Map a subentity to an index. + template + IndexType subIndex (const Entity& e, int i, unsigned int codim) const + { + return std::visit([&e,i,codim](auto const* is) { return is->subIndex(e,i,codim); }, indexSets_); + } + + /// Map a subentity to an index. + template + IndexType subIndex (const typename LeafIndexSet::Traits::template Codim::Entity& e, + int i, unsigned int codim) const + { + return std::visit([&e,i,codim](auto const* is) { return is->template subIndex(e,i,codim); }, indexSets_); + } + + + /// Obtain all geometry types of entities in domain + Types types (int codim) const + { + return std::visit([codim](auto const* is) { return is->types(codim); }, indexSets_); + } + + /// Return total number of entities of given geometry type in entity set \f$E\f$. + IndexType size (GeometryType type) const + { + return std::visit([&type](auto const* is) { return is->size(type); }, indexSets_); + } + + /// Return total number of entities of given codim in the entity set \f$E\f$. This + /// is simply a sum over all geometry types. + IndexType size (int codim) const + { + return std::visit([codim](auto const* is) { return is->size(codim); }, indexSets_); + } + + /// Return true if the given entity is contained in \f$E\f$. + template + bool contains (const Entity& e) const + { + return std::visit([&e](auto const* is) { return is->contains(e); }, indexSets_); + } + + private: + IndexSetTypes indexSets_; + }; + +} // end namespace Dune + +#endif // DUNE_MULTI_INDEXSET_HH diff --git a/dune/multimesh/utility/structuredgridbuilder.hh b/dune/multimesh/utility/structuredgridbuilder.hh index 4d90433ffea0f723e7b6ba2b107d4292b77c593c..db7d1b619c66e5bc3b4fa59477b06c11ef06ed2a 100644 --- a/dune/multimesh/utility/structuredgridbuilder.hh +++ b/dune/multimesh/utility/structuredgridbuilder.hh @@ -37,7 +37,7 @@ namespace Dune * \param upperRight Upper right corner of the grid * \param elements Number of elements in each coordinate direction **/ - static std::unique_ptr createCubeGrid ( + static void createCubeGrid ( GridFactory& factory, const FieldVector& lowerLeft, const FieldVector& upperRight, @@ -88,9 +88,6 @@ namespace Dune factory.insertElement(GeometryTypes::cube(dim), corners); } } - - // Create the grid and hand it to the calling method - return std::unique_ptr(factory.createGrid()); } static std::unique_ptr createCubeGrid ( @@ -99,7 +96,8 @@ namespace Dune const std::array& elements) { GridFactory factory; - return createCubeGrid(factory, lowerLeft, upperRight, elements); + createCubeGrid(factory, lowerLeft, upperRight, elements); + return std::unique_ptr(factory.createGrid()); } /// \brief Create a structured simplex grid