Dune Core Modules (2.9.0)

idset.hh
1#ifndef DUNE_SPGRID_IDSET_HH
2#define DUNE_SPGRID_IDSET_HH
3
4#include <type_traits>
5
7
8#include <dune/grid/spgrid/entityinfo.hh>
9#include <dune/grid/spgrid/gridlevel.hh>
10
11namespace Dune
12{
13
14 // SPLocalIdSet
15 // ------------
16
17 template< class Grid >
18 class SPLocalIdSet
19 : public IdSet< Grid, SPLocalIdSet< Grid >, unsigned long >
20 {
21 typedef SPLocalIdSet< Grid > This;
22 typedef IdSet< Grid, This, unsigned long > Base;
23
24 typedef typename std::remove_const< Grid >::type::Traits Traits;
25
26 public:
27 typedef typename Base::IdType IdType;
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 typename GridLevel::MultiIndex MultiIndex;
42 typedef typename GridLevel::Mesh Mesh;
43
44 static const int levelShift = 8*sizeof( IdType ) - 8;
45
46 IdType computeId ( const GridLevel &gridLevel, const MultiIndex &id ) const;
47
48 template< int cd >
49 IdType computeSubId ( const GridLevel &gridLevel, const MultiIndex &id,
50 int i, int codim, std::integral_constant< int, cd > ) const;
51 IdType computeSubId ( const GridLevel &gridLevel, const MultiIndex &id,
52 int i, int codim, std::integral_constant< int, 0 > ) const;
53 IdType computeSubId ( const GridLevel &gridLevel, const MultiIndex &id,
54 int i, int codim, std::integral_constant< int, dimension > ) const;
55
56 public:
57 template< class Entity >
58 IdType id ( const Entity &entity ) const
59 {
60 return id< Entity::codimension >( entity );
61 }
62
63 template< int codim >
64 IdType id ( const typename Codim< codim >::Entity &entity ) const
65 {
66 const typename Codim< codim >::EntityInfo &entityInfo
67 = entity.impl().entityInfo();
68 return computeId( entityInfo.gridLevel(), entityInfo.id() );
69 }
70
71 template< class Entity >
72 IdType subId ( const Entity &entity, int i, unsigned int codim ) const
73 {
74 return subId< Entity::codimension >( entity, i, codim );
75 }
76
77 template< int cd >
78 IdType subId ( const typename Codim< cd >::Entity &entity, int i, unsigned int codim ) const
79 {
80 const typename Codim< cd >::EntityInfo &entityInfo
81 = entity.impl().entityInfo();
82 const GridLevel &gridLevel = entityInfo.gridLevel();
83 return computeSubId( gridLevel, entityInfo.id(), i, codim, std::integral_constant< int, cd >() );
84 }
85 };
86
87
88 template< class Grid >
89 typename SPLocalIdSet< Grid >::IdType
90 inline SPLocalIdSet< Grid >
91 ::computeId ( const GridLevel &gridLevel, const MultiIndex &id ) const
92 {
93 const unsigned int level = gridLevel.level();
94 if( (level > 0) && gridLevel.refinement().isCopy( id ) )
95 {
96 const Grid &grid = gridLevel.grid();
97 MultiIndex fatherId( id );
98 gridLevel.refinement().father( fatherId );
99 return computeId( grid.gridLevel( level-1 ), fatherId );
100 }
101
102 const Mesh &globalMesh = gridLevel.globalMesh();
103
104 IdType index = 0;
105 IdType factor = 1;
106 for( int i = 0; i < dimension; ++i )
107 {
108 index += IdType( id[ i ] ) * factor;
109 factor *= IdType( 2*globalMesh.width( i ) + 1 );
110 }
111 return index | (IdType( level ) << levelShift);
112 }
113
114
115 template< class Grid >
116 template< int cd >
117 typename SPLocalIdSet< Grid >::IdType
118 inline SPLocalIdSet< Grid >
119 ::computeSubId ( const GridLevel &gridLevel, const MultiIndex &id,
120 int i, int codim, std::integral_constant< int, cd > ) const
121 {
122 const int mydim = dimension - cd;
123 const SPMultiIndex< mydim > refId = gridLevel.template referenceCube< cd >().subId( codim - cd, i );
124 MultiIndex subId( id );
125 for( int k = 0, l = 0; k < dimension; ++k )
126 {
127 if( (id[ k ] & 1) != 0 )
128 subId[ k ] += refId[ l++ ];
129 }
130 return computeId( gridLevel, subId );
131 }
132
133 template< class Grid >
134 typename SPLocalIdSet< Grid >::IdType
135 inline SPLocalIdSet< Grid >
136 ::computeSubId ( const GridLevel &gridLevel, const MultiIndex &id,
137 int i, int codim, std::integral_constant< int, 0 > ) const
138 {
139 return computeId( gridLevel, id + gridLevel.referenceCube().subId( codim, i ) );
140 }
141
142 template< class Grid >
143 typename SPLocalIdSet< Grid >::IdType
144 inline SPLocalIdSet< Grid >
145 ::computeSubId ( const GridLevel &gridLevel, const MultiIndex &id,
146 int i, int codim, std::integral_constant< int, dimension > ) const
147 {
148 assert( (codim == dimension) && (i == 0) );
149 return computeId( gridLevel, id );
150 }
151
152
153
154 // SPGlobalIdSet
155 // -------------
156
157 template< class Grid >
158 class SPGlobalIdSet
159 : public SPLocalIdSet< Grid >
160 {};
161
162} // namespace Dune
163
164#endif // #ifndef DUNE_SPGRID_IDSET_HH
IdType subId(const typename Codim< 0 >::Entity &e, int i, unsigned int codim) const
Get id of subentity i of co-dimension codim of a co-dimension 0 entity.
Definition: indexidset.hh:486
IdType id(const typename Codim< cc >::Entity &e) const
Get id of an entity of codim cc. Unhandy because template parameter must be supplied explicitly.
Definition: indexidset.hh:479
IdTypeImp IdType
Type used to represent an id.
Definition: indexidset.hh:458
Provides base classes for index and id sets.
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)