opm-grid
idset.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_IDSET_HH
4 #define DUNE_POLYHEDRALGRID_IDSET_HH
5 
6 #include <dune/grid/common/indexidset.hh>
7 
8 namespace Dune
9 {
10  template <int dim, int dimworld, typename coord_t> class PolyhedralGrid;
11 
12  // PolyhedralGridIdSet
13  // -------------------
14 
15  template< int dim, int dimworld, typename coord_t >
17  : public IdSet< PolyhedralGrid< dim, dimworld, coord_t >, PolyhedralGridIdSet< dim, dimworld, coord_t >, std::size_t /*IdType=size_t*/ >
18  {
19  public:
21  typedef typename std::remove_const< Grid >::type::Traits Traits;
22  typedef std::size_t IdType;
23 
25  typedef IdSet< Grid, This, IdType > Base;
26 
27  explicit PolyhedralGridIdSet (const Grid& grid)
28  : grid_( grid ),
29  globalCellPtr_( grid_.globalCellPtr() )
30  {
31  codimOffset_[ 0 ] = 0;
32  for( int i=1; i<=dim; ++i )
33  {
34  codimOffset_[ i ] = codimOffset_[ i-1 ] + grid.size( i-1 );
35  }
36  }
37 
39  template< int codim >
40  IdType id ( const typename Traits::template Codim< codim >::Entity &entity ) const
41  {
42  const int index = entity.seed().index();
43  // in case
44  if (codim == 0 && globalCellPtr_ )
45  return IdType( globalCellPtr_[ index ] );
46  else
47  {
48  return codimOffset_[ codim ] + index;
49  }
50  }
51 
53  template< class Entity >
54  IdType id ( const Entity &entity ) const
55  {
56  return id< Entity::codimension >( entity );
57  }
58 
60  template< class IntersectionImpl >
61  IdType id ( const Dune::Intersection< const Grid, IntersectionImpl >& intersection ) const
62  {
63  return intersection.impl().id();
64  }
65 
67  template< class Entity >
68  IdType subId ( const Entity &entity, int i, unsigned int codim ) const
69  {
70  if( codim == 0 )
71  return id( entity );
72  else if ( codim == 1 )
73  return id( entity.template subEntity< 1 >( i ) );
74  else if ( codim == dim )
75  {
76  return id( entity.template subEntity< dim >( i ) );
77  }
78  else
79  {
80  DUNE_THROW(NotImplemented,"codimension not available");
81  return IdType( -1 );
82  }
83  }
84 
85  protected:
86  const Grid& grid_;
87  const int* globalCellPtr_;
88  IdType codimOffset_[ dim+1 ];
89  };
90 
91 } // namespace Dune
92 
93 #endif // #ifndef DUNE_POLYHEDRALGRID_IDSET_HH
Definition: idset.hh:16
int size(int, int codim) const
obtain number of entites on a level
Definition: grid.hh:428
IdType id(const Dune::Intersection< const Grid, IntersectionImpl > &intersection) const
id method of all entities
Definition: idset.hh:61
The namespace Dune is the main namespace for all Dune code.
Definition: CartesianIndexMapper.hpp:9
IdType id(const Entity &entity) const
id method of all entities
Definition: idset.hh:54
identical grid wrapper
Definition: declaration.hh:10
IdType id(const typename Traits::template Codim< codim >::Entity &entity) const
id meethod for entity and specific codim
Definition: idset.hh:40
IdType subId(const Entity &entity, int i, unsigned int codim) const
subId method for entities
Definition: idset.hh:68