My Project
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
8namespace Dune
9{
10
11 // PolyhedralGridIdSet
12 // -------------------
13
14 template< int dim, int dimworld, typename coord_t >
16 : public IdSet< PolyhedralGrid< dim, dimworld, coord_t >, PolyhedralGridIdSet< dim, dimworld, coord_t >, std::size_t /*IdType=size_t*/ >
17 {
18 public:
20 typedef typename std::remove_const< Grid >::type::Traits Traits;
21 typedef std::size_t IdType;
22
24 typedef IdSet< Grid, This, IdType > Base;
25
26 PolyhedralGridIdSet (const Grid& grid)
27 : grid_( grid ),
28 globalCellPtr_( grid_.globalCellPtr() )
29 {
30 codimOffset_[ 0 ] = 0;
31 for( int i=1; i<=dim; ++i )
32 {
33 codimOffset_[ i ] = codimOffset_[ i-1 ] + grid.size( i-1 );
34 }
35 }
36
38 template< int codim >
39 IdType id ( const typename Traits::template Codim< codim >::Entity &entity ) const
40 {
41 const int index = entity.seed().index();
42 // in case
43 if (codim == 0 && globalCellPtr_ )
44 return IdType( globalCellPtr_[ index ] );
45 else
46 {
47 return codimOffset_[ codim ] + index;
48 }
49 }
50
52 template< class Entity >
53 IdType id ( const Entity &entity ) const
54 {
55 return id< Entity::codimension >( entity );
56 }
57
59 template< class IntersectionImpl >
60 IdType id ( const Dune::Intersection< const Grid, IntersectionImpl >& intersection ) const
61 {
62#if DUNE_VERSION_NEWER(DUNE_GRID, 2, 7)
63 return intersection.impl().id();
64#else
65 return Grid::getRealImplementation( intersection ).id();
66#endif
67 }
68
70 template< class Entity >
71 IdType subId ( const Entity &entity, int i, unsigned int codim ) const
72 {
73 if( codim == 0 )
74 return id( entity );
75 else if ( codim == 1 )
76 return id( entity.template subEntity< 1 >( i ) );
77 else if ( codim == dim )
78 {
79 return id( entity.template subEntity< dim >( i ) );
80 }
81 else
82 {
83 DUNE_THROW(NotImplemented,"codimension not available");
84 return IdType( -1 );
85 }
86 }
87
88 protected:
89 const Grid& grid_;
90 const int* globalCellPtr_;
91 IdType codimOffset_[ dim+1 ];
92 };
93
94} // namespace Dune
95
96#endif // #ifndef DUNE_POLYHEDRALGRID_IDSET_HH
Definition: idset.hh:17
IdType id(const typename Traits::template Codim< codim >::Entity &entity) const
id meethod for entity and specific codim
Definition: idset.hh:39
IdType id(const Dune::Intersection< const Grid, IntersectionImpl > &intersection) const
id method of all entities
Definition: idset.hh:60
IdType subId(const Entity &entity, int i, unsigned int codim) const
subId method for entities
Definition: idset.hh:71
IdType id(const Entity &entity) const
id method of all entities
Definition: idset.hh:53
identical grid wrapper
Definition: grid.hh:163
Copyright 2019 Equinor AS.
Definition: CartesianIndexMapper.hpp:10