dune-grid  2.7.0
geometrygrid/indexsets.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_GEOGRID_INDEXSETS_HH
4 #define DUNE_GEOGRID_INDEXSETS_HH
5 
6 #include <vector>
7 
8 #include <dune/common/typetraits.hh>
9 
12 
14 
15 namespace Dune
16 {
17 
18  namespace GeoGrid
19  {
20 
21  // IndexSet
22  // --------
23 
24  template< class Grid, class HostIndexSet >
25  class IndexSet
26  : public Dune::IndexSet< Grid, IndexSet< Grid, HostIndexSet >, typename HostIndexSet::IndexType, typename HostIndexSet::Types >
27  {
30 
31  typedef typename std::remove_const< Grid >::type::Traits Traits;
32 
33  typedef typename Traits::HostGrid HostGrid;
34 
35  public:
36  static const int dimension = Traits::dimension;
37 
38  typedef typename Base::IndexType IndexType;
39 
40  typedef typename Base::Types Types;
41 
42  IndexSet () = default;
43 
44  explicit IndexSet ( const HostIndexSet &hostIndexSet )
45  : hostIndexSet_( &hostIndexSet )
46  {}
47 
48  // The index set contains a pointer to the host index set, so copying or assigning this can be dangerous.
49  IndexSet ( const This & ) = delete;
50  IndexSet ( This && ) = delete;
51 
52  IndexSet &operator= ( const This & ) = delete;
53  IndexSet &operator= ( This && ) = delete;
54 
55  using Base::index;
56  using Base::subIndex;
57 
58  template< int cc >
59  IndexType index ( const typename Traits::template Codim< cc >::Entity &entity ) const
60  {
61  return entity.impl().index( hostIndexSet() );
62  }
63 
64  template< int cc >
65  IndexType subIndex ( const typename Traits::template Codim< cc >::Entity &entity, int i, unsigned int codim ) const
66  {
67  return entity.impl().subIndex( hostIndexSet(), i, codim );
68  }
69 
70  IndexType size ( GeometryType type ) const
71  {
72  return hostIndexSet().size( type );
73  }
74 
75  int size ( int codim ) const
76  {
77  return hostIndexSet().size( codim );
78  }
79 
80  template< class Entity >
81  bool contains ( const Entity &entity ) const
82  {
83  return entity.impl().isContained( hostIndexSet() );
84  }
85 
86  Types types ( int codim ) const { return hostIndexSet().types( codim ); }
87 
88  const std::vector< GeometryType > &geomTypes ( int codim ) const
89  {
90  return hostIndexSet().geomTypes( codim );
91  }
92 
93  explicit operator bool () const { return bool( hostIndexSet_ ); }
94 
95  void reset () { hostIndexSet_ = nullptr; }
96  void reset ( const HostIndexSet &hostIndexSet ) { hostIndexSet_ = &hostIndexSet; }
97 
98  private:
99  const HostIndexSet &hostIndexSet () const
100  {
101  assert( *this );
102  return *hostIndexSet_;
103  }
104 
105  const HostIndexSet *hostIndexSet_ = nullptr;
106  };
107 
108  } // namespace GeoGrid
109 
110 } // namespace Dune
111 
112 #endif // #ifndef DUNE_GEOGRID_INDEXSETS_HH
Dune::GeoGrid::IndexSet::Types
Base::Types Types
Definition: geometrygrid/indexsets.hh:40
Dune::GeoGrid::IndexSet::dimension
static const int dimension
Definition: geometrygrid/indexsets.hh:36
indexidset.hh
Provides base classes for index and id sets.
Dune::GeoGrid::IndexSet
Definition: geometrygrid/indexsets.hh:25
Dune::GeoGrid::IndexSet::IndexSet
IndexSet()=default
Dune::GeoGrid::IndexSet::contains
bool contains(const Entity &entity) const
Definition: geometrygrid/indexsets.hh:81
Dune::GeoGrid::IndexSet::operator=
IndexSet & operator=(const This &)=delete
Dune::GeoGrid::IndexSet::size
IndexType size(GeometryType type) const
Definition: geometrygrid/indexsets.hh:70
Dune::IndexSet::Types
TypesImp Types
iterator range for geometry types in domain
Definition: indexidset.hh:93
Dune::IndexSet::index
IndexType index(const typename Traits::template Codim< cc >::Entity &e) const
Map entity to index. The result of calling this method with an entity that is not in the index set is...
Definition: indexidset.hh:111
Dune::GeoGrid::IndexSet::IndexType
Base::IndexType IndexType
Definition: geometrygrid/indexsets.hh:38
Dune::GeoGrid::IndexSet::index
IndexType index(const typename Traits::template Codim< cc >::Entity &entity) const
Definition: geometrygrid/indexsets.hh:59
Dune::GeoGrid::IndexSet::IndexSet
IndexSet(const HostIndexSet &hostIndexSet)
Definition: geometrygrid/indexsets.hh:44
Dune::GeoGrid::IndexSet::reset
void reset()
Definition: geometrygrid/indexsets.hh:95
Dune::GeoGrid::Entity
DUNE-conform implementation of the entity.
Definition: geometrygrid/entity.hh:47
declaration.hh
Dune::IndexSet::subIndex
IndexType subIndex(const typename Traits::template Codim< cc >::Entity &e, int i, unsigned int codim) const
Map a subentity to an index.
Definition: indexidset.hh:151
Dune::IndexSet::IndexType
IndexTypeImp IndexType
The type used for the indices.
Definition: indexidset.hh:90
Dune::GeoGrid::IndexSet::geomTypes
const std::vector< GeometryType > & geomTypes(int codim) const
Definition: geometrygrid/indexsets.hh:88
Dune::GeoGrid::IndexSet::subIndex
IndexType subIndex(const typename Traits::template Codim< cc >::Entity &entity, int i, unsigned int codim) const
Definition: geometrygrid/indexsets.hh:65
Dune::GeoGrid::IndexSet::size
int size(int codim) const
Definition: geometrygrid/indexsets.hh:75
Dune::IndexSet
Index Set Interface base class.
Definition: common/grid.hh:346
Dune::GeoGrid::IndexSet::reset
void reset(const HostIndexSet &hostIndexSet)
Definition: geometrygrid/indexsets.hh:96
Dune::GeoGrid::IndexSet::types
Types types(int codim) const
Definition: geometrygrid/indexsets.hh:86
Dune
Include standard header files.
Definition: agrid.hh:58
gridenums.hh
Dune::VTK::GeometryType
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:180