Commit 8ed1b0f8 authored by Praetorius, Simon's avatar Praetorius, Simon

MultiIndexSet cleaned up

parent a1edbfb1
......@@ -17,46 +17,10 @@
#include <dune/grid/common/gridview.hh>
#include "mmiterator.hh"
#include "multiindexset.hh"
namespace Dune
{
template <class HostGrid>
class MultiIndexSet
{
public:
using LeafIndexSet = typename HostGrid::Traits::LeafIndexSet;
using LevelIndexSet = typename HostGrid::Traits::LevelIndexSet;
using IndexType = std::common_type_t<typename LeafIndexSet::IndexType, typename LevelIndexSet::IndexType>;
using IndexSetTypes = std::variant<LeafIndexSet const*, LevelIndexSet const*>;
template <class IndexSet>
MultiIndexSet(IndexSet const* indexSet)
: indexSets_(indexSet)
{}
MultiIndexSet(IndexSetTypes const& indexSet)
: indexSets_(indexSet)
{}
template <class Entity>
IndexType index (const Entity& e) const
{
return std::visit([&e](auto const* is) -> IndexType { return is->index(e); }, indexSets_);
}
template <class Entity>
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 HostGrid>
class MultiGridView;
......@@ -104,8 +68,9 @@ namespace Dune
using Grid = typename Traits::Grid;
using GridViewTypes = std::variant<typename HostGrid::LeafGridView, typename HostGrid::LevelGridView>;
using IndexSet = typename Traits::IndexSet;
using IndexSetTypes = std::variant<const typename HostGrid::LeafIndexSet*, const typename HostGrid::LevelIndexSet*>;
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
......
// -*- 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 <type_traits>
#include <variant>
#include <dune/common/typetraits.hh>
#include <dune/common/exceptions.hh>
#include <dune/common/std/type_traits.hh>
#include <dune/grid/common/indexidset.hh>
namespace Dune
{
// forward declaration
template <class HostGrid>
class MultiGridView;
template <class HostGrid>
class MultiIndexSet
{
private:
using LeafIndexSet = typename HostGrid::Traits::LeafIndexSet;
using LevelIndexSet = typename HostGrid::Traits::LevelIndexSet;
using IndexSetTypes = std::variant<LeafIndexSet const*, LevelIndexSet const*>;
friend class MultiGridView<HostGrid>;
public:
using IndexType = typename LeafIndexSet::IndexType;
using Types = typename LeafIndexSet::Types;
static const int dimension = LeafIndexSet::dimension;
public:
template <class IndexSet>
MultiIndexSet (IndexSet const* indexSet)
: indexSets_(indexSet)
{}
MultiIndexSet (IndexSetTypes const& indexSet)
: indexSets_(indexSet)
{}
/// Map entity to index.
template <class Entity>
IndexType index (const Entity& e) const
{
return std::visit([&e](auto const* is) { return is->index(e); }, indexSets_);
}
/// Map entity to index.
template <int cc>
IndexType index (const typename LeafIndexSet::Traits::template Codim<cc>::Entity& e) const
{
return std::visit([&e](auto const* is) { return is->template index<cc>(e); }, indexSets_);
}
/// Map a subentity to an index.
template <class Entity>
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 <int cc>
IndexType subIndex (const typename LeafIndexSet::Traits::template Codim<cc>::Entity& e,
int i, unsigned int codim) const
{
return std::visit([&e,i,codim](auto const* is) { return is->template subIndex<cc>(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 <class Entity>
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
......@@ -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<GridType> createCubeGrid (
static void createCubeGrid (
GridFactory<GridType>& factory,
const FieldVector<ctype,dimworld>& lowerLeft,
const FieldVector<ctype,dimworld>& 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<GridType>(factory.createGrid());
}
static std::unique_ptr<GridType> createCubeGrid (
......@@ -99,7 +96,8 @@ namespace Dune
const std::array<unsigned int,dim>& elements)
{
GridFactory<GridType> factory;
return createCubeGrid(factory, lowerLeft, upperRight, elements);
createCubeGrid(factory, lowerLeft, upperRight, elements);
return std::unique_ptr<GridType>(factory.createGrid());
}
/// \brief Create a structured simplex grid
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment