1 #ifndef DUNE_ALBERTA_MISC_HH
2 #define DUNE_ALBERTA_MISC_HH
6 #include <dune/common/exceptions.hh>
7 #include <dune/common/typetraits.hh>
8 #include <dune/common/forloop.hh>
15 #ifndef DUNE_ALBERTA_CACHE_COORDINATES
16 #define DUNE_ALBERTA_CACHE_COORDINATES 1
20 #ifndef DUNE_ALBERTA_USE_GENERICGEOMETRY
21 #define DUNE_ALBERTA_USE_GENERICGEOMETRY 0
53 #if DUNE_ALBERTA_VERSION >= 0x300
71 #if DUNE_ALBERTA_VERSION >= 0x300
86 template<
class Data >
89 return MEM_ALLOC( size, Data );
92 template<
class Data >
95 return MEM_CALLOC( size, Data );
98 template<
class Data >
99 inline Data *
memReAlloc ( Data *ptr,
size_t oldSize,
size_t newSize )
101 return MEM_REALLOC( ptr, oldSize, newSize, Data );
104 template<
class Data >
105 inline void memFree ( Data *ptr,
size_t size )
107 return MEM_FREE( ptr, size, Data );
132 identityMatrix_[ i ][ j ] =
Real( 0 );
133 identityMatrix_[ i ][ i ] =
Real( 1 );
134 nullVector_[ i ] =
Real( 0 );
138 static This &instance ()
140 static This theInstance;
147 return instance().identityMatrix_;
152 return instance().nullVector_;
161 template<
int dim,
int codim >
162 struct NumSubEntities;
165 struct NumSubEntities< dim, 0 >
167 static const int value = 1;
171 struct NumSubEntities< dim, dim >
173 static const int value = dim+1;
177 struct NumSubEntities< 0, 0 >
179 static const int value = 1;
183 struct NumSubEntities< 2, 1 >
185 static const int value = 3;
189 struct NumSubEntities< 3, 1 >
191 static const int value = 4;
195 struct NumSubEntities< 3, 2 >
197 static const int value = 6;
205 template<
int dim,
int codim >
209 struct CodimType< dim, 0 >
211 static const int value = CENTER;
215 struct CodimType< dim, dim >
217 static const int value = VERTEX;
221 struct CodimType< 2, 1 >
223 static const int value = EDGE;
227 struct CodimType< 3, 1 >
229 static const int value = FACE;
233 struct CodimType< 3, 2 >
235 static const int value = EDGE;
258 #if DUNE_ALBERTA_VERSION >= 0x300
264 #if DUNE_ALBERTA_VERSION >= 0x300
270 #if DUNE_ALBERTA_VERSION >= 0x300
279 #if DUNE_ALBERTA_VERSION >= 0x300
285 #if DUNE_ALBERTA_CACHE_COORDINATES
314 template<
int dim,
int codim >
319 assert( (i >= 0) && (i < NumSubEntities< dim, codim >::value) );
331 assert( (i >= 0) && (i < numSubEntities) );
332 static int dune2alberta[ numSubEntities ] = { 0, 3, 1, 2, 4, 5 };
333 return dune2alberta[ i ];
342 template<
int dim,
int codim >
347 assert( (i >= 0) && (i < NumSubEntities< dim, codim >::value) );
357 assert( (i >= 0) && (i < NumSubEntities< dim, 1 >::value) );
367 assert( (i >= 0) && (i < NumSubEntities< 1, 1 >::value) );
379 assert( (i >= 0) && (i < numSubEntities) );
380 static int generic2alberta[ numSubEntities ] = { 0, 1, 3, 2, 4, 5 };
381 return generic2alberta[ i ];
390 template<
int dim,
template<
int,
int >
class Numbering = Generic2AlbertaNumbering >
395 template<
int codim >
398 int *dune2alberta_[ dim+1 ];
399 int *alberta2dune_[ dim+1 ];
400 int numSubEntities_[ dim+1 ];
408 ForLoop< Initialize, 0, dim >::apply( *
this );
413 for(
int codim = 0; codim <= dim; ++codim )
415 delete[]( dune2alberta_[ codim ] );
416 delete[]( alberta2dune_[ codim ] );
422 assert( (codim >= 0) && (codim <= dim) );
424 return dune2alberta_[ codim ][ i ];
429 assert( (codim >= 0) && (codim <= dim) );
431 return alberta2dune_[ codim ][ i ];
436 assert( (codim >= 0) && (codim <= dim) );
437 return numSubEntities_[ codim ];
446 template<
int dim,
template<
int,
int >
class Numbering >
447 template<
int codim >
460 const int j = Numbering< dim, codim >::apply( i );
461 map.dune2alberta_[ codim ][ i ] = j;
462 map.alberta2dune_[ codim ][ j ] = i;
472 template<
int dim,
int codim >
476 struct MapVertices< dim, 0 >
478 static int apply (
int subEntity,
int vertex )
480 assert( subEntity == 0 );
487 struct MapVertices< 2, 1 >
489 static int apply (
int subEntity,
int vertex )
491 assert( (subEntity >= 0) && (subEntity < 3) );
492 assert( (vertex >= 0) && (vertex < 2) );
494 static const int map[ 3 ][ 2 ] = { {1,2}, {0,2}, {0,1} };
495 return map[ subEntity ][
vertex ];
500 struct MapVertices< 3, 1 >
502 static int apply (
int subEntity,
int vertex )
504 assert( (subEntity >= 0) && (subEntity < 4) );
505 assert( (vertex >= 0) && (vertex < 3) );
507 static const int map[ 4 ][ 3 ] = { {1,2,3}, {0,2,3}, {0,1,3}, {0,1,2} };
508 return map[ subEntity ][
vertex ];
513 struct MapVertices< 3, 2 >
515 static int apply (
int subEntity,
int vertex )
517 assert( (subEntity >= 0) && (subEntity < 6) );
518 assert( (vertex >= 0) && (vertex < 2) );
519 static const int map[ 6 ][ 2 ] = { {0,1}, {0,2}, {0,3}, {1,2}, {1,3}, {2,3} };
520 return map[ subEntity ][
vertex ];
525 struct MapVertices< dim, dim >
527 static int apply (
int subEntity,
int vertex )
529 assert( (subEntity >= 0) && (subEntity < NumSubEntities< dim, 1 >::value) );
530 assert( vertex == 0 );
560 template<
int dim,
int subdim >
586 const int numVertices = NumSubEntities< 1, 1 >::value;
587 int dof[ numVertices ];
588 for(
int i = 0; i < numVertices; ++i )
590 const int j = MapVertices< dim, dim-1 >::apply( subEntity, i );
591 dof[ i ] = element->dof[ j ][ 0 ];
593 return (dof[ 0 ] < dof[ 1 ] ? 0 : 1);
606 assert( subEntity == 0 );
623 const int numVertices = NumSubEntities< 2, 2 >::value;
624 int dof[ numVertices ];
625 for(
int i = 0; i < numVertices; ++i )
627 const int j = MapVertices< dim, dim-2 >::apply( subEntity, i );
628 dof[ i ] = element->dof[ j ][ 0 ];
631 const int twist[ 8 ] = { -2, 1, 666, -1, 2, 666, -3, 0 };
632 const int k = int( dof[ 0 ] < dof[ 1 ] )
633 | (int( dof[ 0 ] < dof[ 2 ] ) << 1)
634 | (
int( dof[ 1 ] < dof[ 2 ] ) << 2);
635 assert( twist[ k ] != 666 );
649 assert( subEntity == 0 );
660 return (twist < 0 ? (2*numCorners + 1 - i + twist) : i + twist) % numCorners;
667 return (twist < 0 ? (2*numCorners + 1 - i + twist) : numCorners + i - twist) % numCorners;
674 #endif // #if HAVE_ALBERTA
676 #endif // #ifndef DUNE_ALBERTA_MISC_HH