opm-grid
indexset.hh
1 // -*- mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=2 sw=2 sts=2:
3 #ifndef DUNE_POLYHEDRALGRID_INDEXSET_HH
4 #define DUNE_POLYHEDRALGRID_INDEXSET_HH
5 
6 #include <vector>
7 
8 #include <dune/common/typetraits.hh>
9 #include <dune/common/version.hh>
10 
11 #include <dune/grid/common/gridenums.hh>
12 #include <dune/grid/common/indexidset.hh>
13 
14 #include <opm/grid/polyhedralgrid/declaration.hh>
15 
16 namespace Dune
17 {
18 
19  // PolyhedralGridIndexSet
20  // --------------
21 
22  template< int dim, int dimworld, typename coord_t >
24  : public IndexSet< PolyhedralGrid< dim, dimworld, coord_t >, PolyhedralGridIndexSet< dim, dimworld, coord_t >, int >
25  {
27 
28  protected:
30  typedef IndexSet< GridType, This, int > Base;
31 
32  typedef typename std::remove_const< GridType >::type::Traits Traits;
33 
34  public:
35  static const int dimension = Traits::dimension;
36 
37  typedef typename Base::IndexType IndexType;
38 
39  explicit PolyhedralGridIndexSet ( const GridType& grid )
40  : grid_(&grid)
41  {
42  }
43 
44  template< class Entity >
45  IndexType index ( const Entity &entity ) const
46  {
47  return index< Entity::codimension >( entity );
48  }
49 
50  template< int cd >
51  IndexType index ( const typename Traits::template Codim< cd >::Entity &entity ) const
52  {
53  return entity.impl().index();
54  }
55 
56  template< int cd >
57  IndexType subIndex ( const typename Traits::template Codim< cd >::Entity &entity, int i, unsigned int codim ) const
58  {
59  return subIndex( entity, i, codim );
60  }
61 
62  template< class Entity >
63  IndexType subIndex ( const Entity &entity, int i, unsigned int codim ) const
64  {
65  if( codim == 0 )
66  return index( entity );
67  else if ( codim == 1 )
68  return index( entity.impl().template subEntity< 1 > ( i ) );
69  else if ( codim == dimension )
70  {
71  return index( entity.impl().template subEntity< dimension > ( i ) );
72  }
73  else
74  {
75  DUNE_THROW(NotImplemented,"codimension not available");
76  return IndexType( -1 );
77  }
78  }
79 
80  IndexType size ( GeometryType type ) const
81  {
82  return grid().size( type );
83  }
84 
85  int size ( int codim ) const
86  {
87  return grid().size( codim );
88  }
89 
90  template< class Entity >
91  bool contains ( const Entity &entity ) const
92  {
93  return index(entity) >= 0 && index(entity) < size(Entity::codimension);
94  }
95 
96  const std::vector< GeometryType > &geomTypes ( int codim ) const
97  {
98  return grid().geomTypes(codim);
99  }
100 
101  // Dune 2.10 concept IndexSet requires same_as<IS::Types> (by value).
102  // Fixed in Dune 2.11 to convertible_to (see dune-grid MR !786).
103 #if DUNE_VERSION_EQUAL(DUNE_GRID, 2, 10)
104  std::vector< GeometryType > types(int codim) const
105 #else
106  const std::vector< GeometryType >& types(int codim) const
107 #endif
108  {
109  return grid().geomTypes(codim);
110  }
111 
112  const GridType& grid() const { assert( grid_ ); return *grid_; }
113 
114  protected:
115  const GridType *grid_;
116  };
117 
118 } // namespace Dune
119 
120 #endif // #ifndef DUNE_POLYHEDRALGRID_INDEXSET_HH
int size(int, int codim) const
obtain number of entites on a level
Definition: grid.hh:428
The namespace Dune is the main namespace for all Dune code.
Definition: CartesianIndexMapper.hpp:9
identical grid wrapper
Definition: declaration.hh:10
Definition: indexset.hh:23