dune-spgrid 2.7
referencecube.hh
Go to the documentation of this file.
1#ifndef DUNE_SPGRID_REFERENCECUBE_HH
2#define DUNE_SPGRID_REFERENCECUBE_HH
3
4#include <tuple>
5#include <type_traits>
6#include <utility>
7#include <vector>
8
9#include <dune/common/fvector.hh>
10
13
14namespace Dune
15{
16
17 namespace SPReferenceCubeHelper
18 {
19
20 inline static unsigned int
21 numSubEntities ( const unsigned int dimension, const unsigned int codim )
22 {
23 assert( codim <= dimension );
24 if( codim > 0 )
25 {
26 const unsigned int n0 = (codim < dimension ? numSubEntities( dimension-1, codim ) : 0);
27 const unsigned int n1 = numSubEntities( dimension-1, codim-1 );
28 return n0 + 2*n1;
29 }
30 else
31 return 1;
32 }
33
34 } // namespace SPReferenceCubeHelper
35
36
37
38 // SPReferenceCube
39 // ---------------
40
41 template< class ct, int dim >
43 {
45
46 public:
47 typedef ct ctype;
48
49 static const int dimension = dim;
50
51 typedef FieldVector< ctype, dimension > GlobalVector;
53
54 static const int numCorners = (1 << dimension);
55 static const int numFaces = 2*dimension;
56
58
59 const MultiIndex &subId ( const int codim, const int i ) const
60 {
61 assert( (i >= 0) && (i < count( codim )) );
62 return subId_[ codim ][ i ];
63 }
64
65 int count ( const int codim ) const
66 {
67 assert( (codim >= 0) && (codim <= dimension) );
68 return subId_[ codim ].size();
69 }
70
72 static GlobalVector corner ( int i );
73
75 static GlobalVector center ();
76
77 private:
78 void subId ( const unsigned int dimension, const unsigned int codim,
79 const unsigned int i, MultiIndex &sId ) const
80 {
82 assert( i < numSubEntities( dimension, codim ) );
83 if( dimension == 0 )
84 return;
85
86 const unsigned int n0 = (codim < dimension ? numSubEntities( dimension-1, codim ) : 0);
87 if( i < n0 )
88 {
89 subId( dimension-1, codim, i, sId );
90 sId[ dimension-1 ] = 0;
91 }
92 else
93 {
94 const unsigned int n1 = numSubEntities( dimension-1, codim-1 );
95 subId( dimension-1, codim-1, (i-n0)%n1, sId );
96 sId[ dimension-1 ] = 2*((i-n0)/n1) - 1;
97 }
98 }
99
100 std::vector< MultiIndex > subId_[ dimension+1 ];
101 };
102
103
104
105 template< class ct, int dim >
107 {
108 for( int codim = 0; codim <= dimension; ++codim )
109 {
110 const unsigned int size = SPReferenceCubeHelper::numSubEntities( dimension, codim );
111 subId_[ codim ].resize( size );
112 for( unsigned int i = 0; i < size; ++i )
113 subId( dimension, codim, i, subId_[ codim ][ i ] );
114 }
115 }
116
117
118 template< class ct, int dim >
121 {
122 assert( (i >= 0) && (i < numCorners) );
123
124 GlobalVector corner;
125 for( int j = 0; j < dimension; ++j )
126 {
127 corner[ j ] = ctype( i & 1 );
128 i /= 2;
129 }
130 return corner;
131 }
132
133
134 template< class ct, int dim >
137 {
138 GlobalVector center;
139 for( int j = 0; j < dimension; ++j )
140 center[ j ] = ctype( 1 ) / ctype( 2 );
141 return center;
142 }
143
144
145
146 // SPReferenceCube (for dim = 0)
147 // -----------------------------
148
149 template< class ct >
150 class SPReferenceCube< ct, 0 >
151 {
153
154 public:
155 typedef ct ctype;
156
157 static const int dimension = 0;
158
159 typedef FieldVector< ctype, 0 > GlobalVector;
161
162 static const int numCorners = 1;
163
164 int count ( const int codim ) const
165 {
166 assert( (codim >= 0) && (codim <= dimension) );
167 return 1;
168 }
169
170 static GlobalVector corner ( const int i )
171 {
172 assert( (i >= 0) && (i < numCorners) );
173 return GlobalVector();
174 }
175
177 {
178 return GlobalVector();
179 }
180 };
181
182
183
184 // SPReferenceCubeContainer
185 // ------------------------
186
187 template< class ct, int dim >
189 {
191
192 public:
194
195 typedef typename ReferenceCube::ctype ctype;
196
198
199 template< int codim >
200 struct Codim
201 {
202 typedef SPReferenceCube< ct, dim-codim > ReferenceCube;
203 };
204
205 const ReferenceCube &get () const { return get< 0 >(); }
206
207 template< int codim >
208 const typename Codim< codim >::ReferenceCube &get () const
209 {
210 return std::get< codim >( refCubes_ );
211 }
212
213 private:
214 template< int... codim >
215 static std::tuple< typename Codim< codim >::ReferenceCube... > makeRefCubeTable ( std::integer_sequence< int, codim... > );
216
217 decltype( makeRefCubeTable( std::make_integer_sequence< int, dimension+1 >() ) ) refCubes_;
218 };
219
220} // namespace Dune
221
222#endif // #ifndef DUNE_SPGRID_REFERENCECUBE_HH
Definition: iostream.hh:7
static unsigned int numSubEntities(const unsigned int dimension, const unsigned int codim)
Definition: referencecube.hh:21
Definition: referencecube.hh:43
SPReferenceCube()
Definition: referencecube.hh:106
SPMultiIndex< dimension > MultiIndex
Definition: referencecube.hh:52
static const int numFaces
Definition: referencecube.hh:55
int count(const int codim) const
Definition: referencecube.hh:65
static GlobalVector corner(int i)
return i-th corner
Definition: referencecube.hh:120
FieldVector< ctype, dimension > GlobalVector
Definition: referencecube.hh:51
static GlobalVector center()
return center
Definition: referencecube.hh:136
const MultiIndex & subId(const int codim, const int i) const
Definition: referencecube.hh:59
ct ctype
Definition: referencecube.hh:47
static const int numCorners
Definition: referencecube.hh:54
static const int dimension
Definition: referencecube.hh:49
Definition: referencecube.hh:151
SPMultiIndex< dimension > MultiIndex
Definition: referencecube.hh:160
int count(const int codim) const
Definition: referencecube.hh:164
FieldVector< ctype, 0 > GlobalVector
Definition: referencecube.hh:159
ct ctype
Definition: referencecube.hh:155
static GlobalVector corner(const int i)
Definition: referencecube.hh:170
static GlobalVector center()
Definition: referencecube.hh:176
Definition: referencecube.hh:189
const Codim< codim >::ReferenceCube & get() const
Definition: referencecube.hh:208
const ReferenceCube & get() const
Definition: referencecube.hh:205
static const int dimension
Definition: referencecube.hh:197
ReferenceCube::ctype ctype
Definition: referencecube.hh:195
SPReferenceCube< ct, dim > ReferenceCube
Definition: referencecube.hh:193
Definition: referencecube.hh:201
SPReferenceCube< ct, dim-codim > ReferenceCube
Definition: referencecube.hh:202