Dune Core Modules (2.9.0)

hindexset.hh
1#ifndef DUNE_SPGRID_HINDEXSET_HH
2#define DUNE_SPGRID_HINDEXSET_HH
3
4#include <array>
5#include <vector>
6#include <type_traits>
7
8#include <dune/grid/spgrid/indexset.hh>
9
10namespace Dune
11{
12
13 // SPHierarchyIndexSet
14 // -------------------
15
16 template< class Grid >
17 class SPHierarchyIndexSet
18 : public IndexSet< Grid, SPHierarchyIndexSet< Grid >, unsigned int, std::array< GeometryType, 1 > >
19 {
20 typedef SPHierarchyIndexSet< Grid > This;
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 {
34 typedef __SPGrid::EntityInfo< Grid, codim > EntityInfo;
35 typedef typename Traits::template Codim< codim >::Entity Entity;
36 };
37
38 typedef SPGridLevel< typename std::remove_const< Grid >::type > GridLevel;
39
40 private:
41 typedef SPIndexSet< Grid > LevelIndexSet;
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< class Entity >
88 IndexType subIndex ( const Entity &entity,
89 const int i, const unsigned int codim ) const
90 {
91 return subIndex< Entity::codimension >( entity, i, codim );
92 }
93
94 template< int cd >
95 IndexType subIndex ( const typename Codim< cd >::Entity &entity,
96 const int i, const unsigned int codim ) const
97 {
98 const int level = entity.level();
99 const IndexType offset = offsets_[ level ][ codim ];
100 return offset + levelIndexSet( level ).subIndex( entity, i, codim );
101 }
102
103 Types types ( int codim ) const { return {{ GeometryTypes::cube( dimension - codim ) }}; }
104
105 const std::vector< GeometryType > &geomTypes ( const int codim ) const
106 {
107 return levelIndexSet( 0 ).geomTypes( codim );
108 }
109
110 IndexType size ( const GeometryType &type ) const
111 {
112 return (type.isCube() ? size( dimension - type.dim() ) : 0);
113 }
114
115 IndexType size ( const int codim ) const
116 {
117 assert( (codim >= 0) && (codim <= dimension) );
118 return size_[ codim ];
119 }
120
121 template< class Entity >
122 bool contains ( const Entity &entity ) const
123 {
124 return contains< Entity::codimension >( entity );
125 }
126
127 template< int codim >
128 bool contains ( const typename Codim< codim >::Entity &entity ) const
129 {
130 return true;
131 }
132
133 const Grid &grid () const
134 {
135 return *grid_;
136 }
137
138 const LevelIndexSet &levelIndexSet ( const int level ) const
139 {
140 assert( (level >= 0) && (level <= (int)levelIndexSets_.size()) );
141 assert( (int)levelIndexSets_.size() == grid().maxLevel()+1 );
142 return *levelIndexSets_[ level ];
143 }
144
145 private:
146 const Grid *grid_;
147 std::vector< const LevelIndexSet * > levelIndexSets_;
148 std::vector< CodimIndexArray > offsets_;
149 CodimIndexArray size_;
150 };
151
152} // namespace Dune
153
154#endif // #ifndef DUNE_SPGRID_HINDEXSET_HH
auto size(GeometryType type) const
Return total number of entities of given geometry type in entity set .
Definition: indexidset.hh:223
IndexType subIndex(const typename Traits::template Codim< cc >::Entity &e, int i, unsigned int codim) const
Map a subentity to an index.
Definition: indexidset.hh:153
TypesImp Types
iterator range for geometry types in domain
Definition: indexidset.hh:95
IndexType index(const typename Traits::template Codim< cc >::Entity &e) const
Map entity to index. The result of calling this method with an entity that is not in the index set is...
Definition: indexidset.hh:113
IndexTypeImp IndexType
The type used for the indices.
Definition: indexidset.hh:92
constexpr GeometryType cube(unsigned int dim)
Returns a GeometryType representing a hypercube of dimension dim.
Definition: type.hh:472
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)