dune-spgrid 2.8.0
Loading...
Searching...
No Matches
hindexset.hh
Go to the documentation of this file.
1#ifndef DUNE_SPGRID_HINDEXSET_HH
2#define DUNE_SPGRID_HINDEXSET_HH
3
4#include <array>
5#include <vector>
6#include <type_traits>
7
9
10namespace Dune
11{
12
13 // SPHierarchyIndexSet
14 // -------------------
15
16 template< class Grid >
18 : public IndexSet< Grid, SPHierarchyIndexSet< Grid >, unsigned int, std::array< GeometryType, 1 > >
19 {
21 typedef IndexSet< Grid, This, unsigned int, std::array< GeometryType, 1 > > Base;
22
23 typedef typename std::remove_const< Grid >::type::Traits Traits;
24
25 public:
26 typedef typename Base::IndexType IndexType;
27 typedef typename Base::Types Types;
28
29 static const int dimension = Traits::ReferenceCube::dimension;
30
31 template< int codim >
32 struct Codim
33 {
35 typedef typename Traits::template Codim< codim >::Entity Entity;
36 };
37
39
40 private:
42
43 typedef std::array< IndexType, dimension+1 > CodimIndexArray;
44
45 public:
46 explicit SPHierarchyIndexSet ( const Grid &grid )
47 : grid_( &grid )
48 {
49 for( int codim = 0; codim <= dimension; ++codim )
50 size_[ codim ] = 0;
51 }
52
53 void update ()
54 {
55 for( int codim = 0; codim <= dimension; ++codim )
56 size_[ codim ] = 0;
57
58 const int maxLevel = grid().maxLevel();
59 levelIndexSets_.resize( maxLevel+1 );
60 offsets_.resize( maxLevel+1 );
61 for( int level = 0; level <= maxLevel; ++level )
62 {
63 const LevelIndexSet &levelIndexSet = grid().levelIndexSet( level );
64 levelIndexSets_[ level ] = &levelIndexSet;
65 for( int codim = 0; codim <= dimension; ++codim )
66 {
67 offsets_[ level ][ codim ] = size_[ codim ];
68 size_[ codim ] += levelIndexSet.size( codim );
69 }
70 }
71 }
72
73 template< class Entity >
74 IndexType index ( const Entity &entity ) const
75 {
76 return index< Entity::codimension >( entity );
77 }
78
79 template< int codim >
80 IndexType index ( const typename Codim< codim >::Entity &entity ) const
81 {
82 const int level = entity.level();
83 const IndexType offset = offsets_[ level ][ codim ];
84 return offset + levelIndexSet( level ).index( entity );
85 }
86
87 template< int codim >
88 IndexType DUNE_DEPRECATED
89 subIndex ( const typename Codim< 0 >::Entity &entity, const int i ) const
90 {
91 DUNE_THROW( NotImplemented, "SPHierarchyIndexSet does not implement the old subIndex method." );
92 }
93
94 template< class Entity >
95 IndexType subIndex ( const Entity &entity,
96 const int i, const unsigned int codim ) const
97 {
98 return subIndex< Entity::codimension >( entity, i, codim );
99 }
100
101 template< int cd >
102 IndexType subIndex ( const typename Codim< cd >::Entity &entity,
103 const int i, const unsigned int codim ) const
104 {
105 const int level = entity.level();
106 const IndexType offset = offsets_[ level ][ codim ];
107 return offset + levelIndexSet( level ).subIndex( entity, i, codim );
108 }
109
110 Types types ( int codim ) const { return {{ GeometryTypes::cube( dimension - codim ) }}; }
111
112 const std::vector< GeometryType > &geomTypes ( const int codim ) const
113 {
114 return levelIndexSet( 0 ).geomTypes( codim );
115 }
116
117 IndexType size ( const GeometryType &type ) const
118 {
119 return (type.isCube() ? size( dimension - type.dim() ) : 0);
120 }
121
122 IndexType size ( const int codim ) const
123 {
124 assert( (codim >= 0) && (codim <= dimension) );
125 return size_[ codim ];
126 }
127
128 template< class Entity >
129 bool contains ( const Entity &entity ) const
130 {
131 return contains< Entity::codimension >( entity );
132 }
133
134 template< int codim >
135 bool contains ( const typename Codim< codim >::Entity &entity ) const
136 {
137 return true;
138 }
139
140 const Grid &grid () const
141 {
142 return *grid_;
143 }
144
145 const LevelIndexSet &levelIndexSet ( const int level ) const
146 {
147 assert( (level >= 0) && (level <= (int)levelIndexSets_.size()) );
148 assert( (int)levelIndexSets_.size() == grid().maxLevel()+1 );
149 return *levelIndexSets_[ level ];
150 }
151
152 private:
153 const Grid *grid_;
154 std::vector< const LevelIndexSet * > levelIndexSets_;
155 std::vector< CodimIndexArray > offsets_;
156 CodimIndexArray size_;
157 };
158
159} // namespace Dune
160
161#endif // #ifndef DUNE_SPGRID_HINDEXSET_HH
Definition: iostream.hh:7
Definition: entityinfo.hh:24
Definition: gridlevel.hh:35
Definition: indexset.hh:19
IndexType size(const GeometryType &type) const
Definition: indexset.hh:239
Definition: hindexset.hh:19
IndexType size(const GeometryType &type) const
Definition: hindexset.hh:117
IndexType subIndex(const typename Codim< cd >::Entity &entity, const int i, const unsigned int codim) const
Definition: hindexset.hh:102
bool contains(const typename Codim< codim >::Entity &entity) const
Definition: hindexset.hh:135
SPHierarchyIndexSet(const Grid &grid)
Definition: hindexset.hh:46
Base::IndexType IndexType
Definition: hindexset.hh:26
IndexType index(const typename Codim< codim >::Entity &entity) const
Definition: hindexset.hh:80
IndexType index(const Entity &entity) const
Definition: hindexset.hh:74
IndexType subIndex(const typename Codim< 0 >::Entity &entity, const int i) const
Definition: hindexset.hh:89
void update()
Definition: hindexset.hh:53
SPGridLevel< typename std::remove_const< Grid >::type > GridLevel
Definition: hindexset.hh:38
const Grid & grid() const
Definition: hindexset.hh:140
IndexType subIndex(const Entity &entity, const int i, const unsigned int codim) const
Definition: hindexset.hh:95
IndexType size(const int codim) const
Definition: hindexset.hh:122
const LevelIndexSet & levelIndexSet(const int level) const
Definition: hindexset.hh:145
static const int dimension
Definition: hindexset.hh:29
Types types(int codim) const
Definition: hindexset.hh:110
bool contains(const Entity &entity) const
Definition: hindexset.hh:129
const std::vector< GeometryType > & geomTypes(const int codim) const
Definition: hindexset.hh:112
Base::Types Types
Definition: hindexset.hh:27
Definition: hindexset.hh:33
Traits::template Codim< codim >::Entity Entity
Definition: hindexset.hh:35
__SPGrid::EntityInfo< Grid, codim > EntityInfo
Definition: hindexset.hh:34