Dune Core Modules (2.9.0)

referencecube.hh
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
10
11#include <dune/grid/spgrid/multiindex.hh>
12#include <dune/grid/spgrid/normal.hh>
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 >
42 class SPReferenceCube
43 {
44 typedef SPReferenceCube< ct, dim > This;
45
46 public:
47 typedef ct ctype;
48
49 static const int dimension = dim;
50
51 typedef FieldVector< ctype, dimension > GlobalVector;
52 typedef SPMultiIndex< dimension > MultiIndex;
53
54 static const int numCorners = (1 << dimension);
55 static const int numFaces = 2*dimension;
56
57 SPReferenceCube ();
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 {
81 using SPReferenceCubeHelper::numSubEntities;
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 >
106 inline SPReferenceCube< ct, dim >::SPReferenceCube ()
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 >
119 inline typename SPReferenceCube< ct, dim >::GlobalVector
120 SPReferenceCube< ct, dim >::corner ( int i )
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 >
135 inline typename SPReferenceCube< ct, dim >::GlobalVector
136 SPReferenceCube< ct, dim >::center ()
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 {
152 typedef SPReferenceCube< ct, 0 > This;
153
154 public:
155 typedef ct ctype;
156
157 static const int dimension = 0;
158
159 typedef FieldVector< ctype, 0 > GlobalVector;
160 typedef SPMultiIndex< dimension > MultiIndex;
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
176 static GlobalVector center ()
177 {
178 return GlobalVector();
179 }
180 };
181
182
183
184 // SPReferenceCubeContainer
185 // ------------------------
186
187 template< class ct, int dim >
188 class SPReferenceCubeContainer
189 {
190 typedef SPReferenceCubeContainer< ct, dim > This;
191
192 public:
193 typedef SPReferenceCube< ct, dim > ReferenceCube;
194
195 typedef typename ReferenceCube::ctype ctype;
196
197 static const int dimension = ReferenceCube::dimension;
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
Implements a vector constructed from a given type representing a field and a compile-time given size.
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)