1#ifndef DUNE_SPGRID_REFERENCECUBE_HH
2#define DUNE_SPGRID_REFERENCECUBE_HH
11#include <dune/grid/spgrid/multiindex.hh>
12#include <dune/grid/spgrid/normal.hh>
17 namespace SPReferenceCubeHelper
20 inline static unsigned int
21 numSubEntities (
const unsigned int dimension,
const unsigned int codim )
23 assert( codim <= dimension );
26 const unsigned int n0 = (codim < dimension ? numSubEntities( dimension-1, codim ) : 0);
27 const unsigned int n1 = numSubEntities( dimension-1, codim-1 );
41 template<
class ct,
int dim >
44 typedef SPReferenceCube< ct, dim > This;
49 static const int dimension = dim;
54 static const int numCorners = (1 << dimension);
55 static const int numFaces = 2*dimension;
59 const MultiIndex &subId (
const int codim,
const int i )
const
61 assert( (i >= 0) && (i < count( codim )) );
62 return subId_[ codim ][ i ];
65 int count (
const int codim )
const
67 assert( (codim >= 0) && (codim <= dimension) );
68 return subId_[ codim ].size();
72 static GlobalVector corner (
int i );
75 static GlobalVector center ();
78 void subId (
const unsigned int dimension,
const unsigned int codim,
79 const unsigned int i, MultiIndex &sId )
const
81 using SPReferenceCubeHelper::numSubEntities;
82 assert( i < numSubEntities( dimension, codim ) );
86 const unsigned int n0 = (codim < dimension ? numSubEntities( dimension-1, codim ) : 0);
89 subId( dimension-1, codim, i, sId );
90 sId[ dimension-1 ] = 0;
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;
100 std::vector< MultiIndex > subId_[ dimension+1 ];
105 template<
class ct,
int dim >
106 inline SPReferenceCube< ct, dim >::SPReferenceCube ()
108 for(
int codim = 0; codim <= dimension; ++codim )
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 ] );
118 template<
class ct,
int dim >
119 inline typename SPReferenceCube< ct, dim >::GlobalVector
120 SPReferenceCube< ct, dim >::corner (
int i )
122 assert( (i >= 0) && (i < numCorners) );
125 for(
int j = 0; j < dimension; ++j )
127 corner[ j ] = ctype( i & 1 );
134 template<
class ct,
int dim >
135 inline typename SPReferenceCube< ct, dim >::GlobalVector
136 SPReferenceCube< ct, dim >::center ()
139 for(
int j = 0; j < dimension; ++j )
140 center[ j ] = ctype( 1 ) / ctype( 2 );
150 class SPReferenceCube< ct, 0 >
152 typedef SPReferenceCube< ct, 0 > This;
157 static const int dimension = 0;
159 typedef FieldVector< ctype, 0 > GlobalVector;
162 static const int numCorners = 1;
164 int count (
const int codim )
const
166 assert( (codim >= 0) && (codim <= dimension) );
170 static GlobalVector corner (
const int i )
172 assert( (i >= 0) && (i < numCorners) );
173 return GlobalVector();
176 static GlobalVector center ()
178 return GlobalVector();
187 template<
class ct,
int dim >
188 class SPReferenceCubeContainer
190 typedef SPReferenceCubeContainer< ct, dim > This;
193 typedef SPReferenceCube< ct, dim > ReferenceCube;
195 typedef typename ReferenceCube::ctype ctype;
197 static const int dimension = ReferenceCube::dimension;
199 template<
int codim >
202 typedef SPReferenceCube< ct, dim-codim > ReferenceCube;
205 const ReferenceCube &get ()
const {
return get< 0 >(); }
207 template<
int codim >
208 const typename Codim< codim >::ReferenceCube &get ()
const
210 return std::get< codim >( refCubes_ );
214 template<
int... codim >
215 static std::tuple< typename Codim< codim >::ReferenceCube... > makeRefCubeTable ( std::integer_sequence< int, codim... > );
217 decltype( makeRefCubeTable( std::make_integer_sequence< int, dimension+1 >() ) ) refCubes_;
Implements a vector constructed from a given type representing a field and a compile-time given size.
Dune namespace.
Definition: alignedallocator.hh:13