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 
11  // PolyhedralGridIdSet
12  // -----------
13 
14  template< int dim, int dimworld >
16  : public IdSet< PolyhedralGrid< dim, dimworld >, PolyhedralGridIdSet< dim, dimworld >, /*IdType=*/int >
17  {
18  public:
20  typedef typename std::remove_const< Grid >::type::Traits Traits;
21  typedef typename Traits::Index IdType;
22 
24  typedef IdSet< Grid, PolyhedralGridIdSet< dim, dimworld >, IdType > Base;
25 
26  PolyhedralGridIdSet (const Grid& grid)
27  : grid_(grid)
28  {}
29 
31  template< int codim >
32  IdType id ( const typename Traits::template Codim< codim >::Entity &entity ) const
33  {
34  const int index = entity.seed().index();
35  if (codim == 0)
36  return grid_.globalCell()[ index ];
37  else
38  return index;
39  }
40 
41 #if ! DUNE_VERSION_NEWER(DUNE_GRID,2,4)
42  template< int codim >
44  IdType id ( const typename Traits::template Codim< codim >::EntityPointer &entityPointer ) const
45  {
46  return id( *entityPointer );
47  }
48 #endif
49 
51  template< class Entity >
52  IdType id ( const Entity &entity ) const
53  {
54  return id< Entity::codimension >( entity );
55  }
56 
58  template< class IntersectionImpl >
59  IdType id ( const Dune::Intersection< const Grid, IntersectionImpl >& intersection ) const
60  {
61  return Grid::getRealImplementation( intersection ).id();
62  }
63 
65  template< class Entity >
66  IdType subId ( const Entity &entity, int i, unsigned int codim ) const
67  {
68  if( codim == 0 )
69  return id( entity );
70  else if ( codim == 1 )
71  return id( entity.template subEntity< 1 >( i ) );
72  else if ( codim == dim )
73  return id( entity.template subEntity< dim >( i ) );
74  else
75  {
76  DUNE_THROW(NotImplemented,"codimension not available");
77  return IdType( -1 );
78  }
79  }
80 
81  protected:
82  const Grid& grid_;
83  };
84 
85 } // namespace Dune
86 
87 #endif // #ifndef DUNE_POLYHEDRALGRID_IDSET_HH
IdType id(const Entity &entity) const
id method of all entities
Definition: idset.hh:52
Definition: idset.hh:15
IdType subId(const Entity &entity, int i, unsigned int codim) const
subId method for entities
Definition: idset.hh:66
Holds the implementation of the CpGrid as a pimple.
Definition: OpmParserIncludes.hpp:42
identical grid wrapper
Definition: declaration.hh:10
IdType id(const typename Traits::template Codim< codim >::EntityPointer &entityPointer) const
id meethod for entity and specific codim
Definition: idset.hh:44
IdType id(const typename Traits::template Codim< codim >::Entity &entity) const
id meethod for entity and specific codim
Definition: idset.hh:32
IdType id(const Dune::Intersection< const Grid, IntersectionImpl > &intersection) const
id method of all entities
Definition: idset.hh:59