1 #ifndef DUNE_SPHEREGRID_INDEXSETS_HH 2 #define DUNE_SPHEREGRID_INDEXSETS_HH 3 4 #include <cassert> 5 6 #include <array> 7 #include <type_traits> 8 #include <vector> 9 10 #include <dune/grid/common/gridenums.hh> 11 #include <dune/grid/common/indexidset.hh> 12 13 #include <dune/grid/spheregrid/declaration.hh> 14 15 namespace Dune 16 { 17 18 // SphereGridIndexSet 19 // ------------------ 20 21 template< class Grid, class HostIndexSet > 22 class SphereGridIndexSet 23 : public IndexSet< Grid, SphereGridIndexSet< Grid, HostIndexSet >, typename HostIndexSet::IndexType, std::array< GeometryType, 1 > > 24 { 25 typedef SphereGridIndexSet< Grid, HostIndexSet > This; 26 typedef IndexSet< Grid, SphereGridIndexSet< Grid, HostIndexSet >, typename HostIndexSet::IndexType, std::array< GeometryType, 1 > > Base; 27 28 typedef typename std::remove_const_t< Grid >::Traits Traits; 29 30 typedef typename Traits::HostGrid HostGrid; 31 32 public: 33 static constexpr int dimension = Traits::dimension; 34 35 using typename Base::IndexType; 36 using typename Base::Types; 37 38 SphereGridIndexSet () = default; 39 SphereGridIndexSet(const HostIndexSet & hostIndexSet)40 explicit SphereGridIndexSet ( const HostIndexSet &hostIndexSet ) : hostIndexSet_( &hostIndexSet ) {} 41 SphereGridIndexSet(const This & other)42 SphereGridIndexSet ( const This &other ) : hostIndexSet_( other.hostIndexSet_ ) {} 43 operator =(const This & other)44 const This &operator= ( const This &other ) 45 { 46 hostIndexSet_ = other.hostIndexSet_; 47 return *this; 48 } 49 50 template< class Entity > index(const Entity & entity) const51 IndexType index ( const Entity &entity ) const 52 { 53 return index< Entity::codimension >( entity ); 54 } 55 56 template< int cd > index(const typename Traits::template Codim<cd>::Entity & entity) const57 IndexType index ( const typename Traits::template Codim< cd >::Entity &entity ) const 58 { 59 return index( Grid::template getHostEntity< cd >( entity ) ); 60 } 61 62 template< int cd > index(const typename Traits::HostGrid::template Codim<cd>::Entity & entity) const63 IndexType index ( const typename Traits::HostGrid::template Codim< cd >::Entity &entity ) const 64 { 65 return hostIndexSet().index( entity ); 66 } 67 68 template< class Entity > subIndex(const Entity & entity,int i,unsigned int codim) const69 IndexType subIndex ( const Entity &entity, int i, unsigned int codim ) const 70 { 71 return subIndex< Entity::codimension >( entity, i, codim ); 72 } 73 74 template< int cd > subIndex(const typename Traits::template Codim<cd>::Entity & entity,int i,unsigned int codim) const75 IndexType subIndex ( const typename Traits::template Codim< cd >::Entity &entity, int i, unsigned int codim ) const 76 { 77 return subIndex( Grid::template getHostEntity< cd >( entity ), i, codim ); 78 } 79 80 template< int cd > subIndex(const typename Traits::HostGrid::template Codim<cd>::Entity & entity,int i,unsigned int codim) const81 IndexType subIndex ( const typename Traits::HostGrid::template Codim< cd >::Entity &entity, int i, unsigned int codim ) const 82 { 83 return hostIndexSet().subIndex( entity, i, codim ); 84 } 85 size(GeometryType type) const86 IndexType size ( GeometryType type ) const 87 { 88 return hostIndexSet().size( type ); 89 } 90 size(int codim) const91 int size ( int codim ) const 92 { 93 return hostIndexSet().size( codim ); 94 } 95 96 template< class Entity > contains(const Entity & entity) const97 bool contains ( const Entity &entity ) const 98 { 99 static const int cc = Entity::codimension; 100 return hostIndexSet().contains( Grid::template getHostEntity< cc >( entity ) ); 101 } 102 types(int codim) const103 Types types ( int codim ) const { return {{ GeometryTypes::simplex( dimension - codim ) }}; } 104 operator bool() const105 explicit operator bool () const { return bool( hostIndexSet_ ); } 106 107 private: hostIndexSet() const108 const HostIndexSet &hostIndexSet () const 109 { 110 assert( hostIndexSet_ ); 111 return *hostIndexSet_; 112 } 113 114 const HostIndexSet *hostIndexSet_ = nullptr; 115 }; 116 117 } // namespace Dune 118 119 #endif // #ifndef DUNE_SPHEREGRID_INDEXSETS_HH 120