My Project
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  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 #if DUNE_VERSION_NEWER(DUNE_GRID, 2, 7)
54  return entity.impl().index();
55 #else
56  return grid().getRealImplementation(entity).index();
57 #endif
58  }
59 
60  template< int cd >
61  IndexType subIndex ( const typename Traits::template Codim< cd >::Entity &entity, int i, unsigned int codim ) const
62  {
63  return subIndex( entity, i, codim );
64  }
65 
66  template< class Entity >
67  IndexType subIndex ( const Entity &entity, int i, unsigned int codim ) const
68  {
69  if( codim == 0 )
70  return index( entity );
71  else if ( codim == 1 )
72 #if DUNE_VERSION_NEWER(DUNE_GRID, 2, 7)
73  return index( entity.impl().template subEntity< 1 > ( i ) );
74 #else
75  return index( grid().getRealImplementation( entity ).template subEntity< 1 > ( i ) );
76 #endif
77  else if ( codim == dimension )
78  {
79 #if DUNE_VERSION_NEWER(DUNE_GRID, 2, 7)
80  return index( entity.impl().template subEntity< dimension > ( i ) );
81 #else
82  return index( grid().getRealImplementation( entity ).template subEntity< dimension > ( i ) );
83 #endif
84  }
85  else
86  {
87  DUNE_THROW(NotImplemented,"codimension not available");
88  return IndexType( -1 );
89  }
90  }
91 
92  IndexType size ( GeometryType type ) const
93  {
94  return grid().size( type );
95  }
96 
97  int size ( int codim ) const
98  {
99  return grid().size( codim );
100  }
101 
102  template< class Entity >
103  bool contains ( const Entity &entity ) const
104  {
105  return index(entity) >= 0 && index(entity) < size(Entity::codimension);
106  }
107 
108  const std::vector< GeometryType > &geomTypes ( int codim ) const
109  {
110  return grid().geomTypes(codim);
111  }
112 
113  const std::vector< GeometryType >& types(int codim) const
114  {
115  return grid().geomTypes(codim);
116  }
117 
118  const GridType& grid() const { assert( grid_ ); return *grid_; }
119 
120  protected:
121  const GridType *grid_;
122  };
123 
124 } // namespace Dune
125 
126 #endif // #ifndef DUNE_POLYHEDRALGRID_INDEXSET_HH
Definition: indexset.hh:25
identical grid wrapper
Definition: grid.hh:163
Copyright 2019 Equinor AS.
Definition: CartesianIndexMapper.hpp:10