3#ifndef DUNE_ALBERTA_MISC_HH
4#define DUNE_ALBERTA_MISC_HH
12#include <dune/grid/albertagrid/albertaheader.hh>
17#ifndef DUNE_ALBERTA_CACHE_COORDINATES
18#define DUNE_ALBERTA_CACHE_COORDINATES 1
43 static const int dimWorld = DIM_OF_WORLD;
45 typedef ALBERTA REAL Real;
46 typedef ALBERTA REAL_B LocalVector;
47 typedef ALBERTA REAL_D GlobalVector;
48 typedef ALBERTA REAL_DD GlobalMatrix;
49 typedef ALBERTA AFF_TRAFO AffineTransformation;
50 typedef ALBERTA MESH Mesh;
51 typedef ALBERTA EL Element;
53 static const int meshRefined = MESH_REFINED;
54 static const int meshCoarsened = MESH_COARSENED;
56 static const int InteriorBoundary = INTERIOR;
57 static const int DirichletBoundary = DIRICHLET;
58 typedef ALBERTA BNDRY_TYPE BoundaryId;
60 typedef U_CHAR ElementType;
62 typedef ALBERTA FE_SPACE DofSpace;
69 template<
class Data >
70 inline Data *memAlloc (
size_t size )
72 return MEM_ALLOC( size, Data );
75 template<
class Data >
76 inline Data *memCAlloc (
size_t size )
78 return MEM_CALLOC( size, Data );
81 template<
class Data >
82 inline Data *memReAlloc ( Data *ptr,
size_t oldSize,
size_t newSize )
84 return MEM_REALLOC( ptr, oldSize, newSize, Data );
87 template<
class Data >
88 inline void memFree ( Data *ptr,
size_t size )
90 return MEM_FREE( ptr, size, Data );
100 typedef GlobalSpace This;
103 typedef GlobalMatrix Matrix;
104 typedef GlobalVector Vector;
107 Matrix identityMatrix_;
112 for(
int i = 0; i < dimWorld; ++i )
114 for(
int j = 0; j < dimWorld; ++j )
115 identityMatrix_[ i ][ j ] = Real( 0 );
116 identityMatrix_[ i ][ i ] = Real( 1 );
117 nullVector_[ i ] = Real( 0 );
121 static This &instance ()
123 static This theInstance;
128 static const Matrix &identityMatrix ()
130 return instance().identityMatrix_;
133 static const Vector &nullVector ()
135 return instance().nullVector_;
144 template<
int dim,
int codim >
145 struct NumSubEntities;
148 struct NumSubEntities< dim, 0 >
150 static const int value = 1;
154 struct NumSubEntities< dim, dim >
156 static const int value = dim+1;
160 struct NumSubEntities< 0, 0 >
162 static const int value = 1;
166 struct NumSubEntities< 2, 1 >
168 static const int value = 3;
172 struct NumSubEntities< 3, 1 >
174 static const int value = 4;
178 struct NumSubEntities< 3, 2 >
180 static const int value = 6;
188 template<
int dim,
int codim >
192 struct CodimType< dim, 0 >
194 static const int value = CENTER;
198 struct CodimType< dim, dim >
200 static const int value = VERTEX;
204 struct CodimType< 2, 1 >
206 static const int value = EDGE;
210 struct CodimType< 3, 1 >
212 static const int value = FACE;
216 struct CodimType< 3, 2 >
218 static const int value = EDGE;
229 typedef ALBERTA FLAGS Flags;
231 static const Flags nothing = FILL_NOTHING;
233 static const Flags coords = FILL_COORDS;
235 static const Flags neighbor = FILL_NEIGH;
237 static const Flags orientation = (dim == 3 ? FILL_ORIENTATION : FILL_NOTHING);
239 static const Flags projection = FILL_PROJECTION;
241 static const Flags elementType = FILL_NOTHING;
243 static const Flags boundaryId = FILL_MACRO_WALLS;
245 static const Flags nonPeriodic = FILL_NON_PERIODIC;
247 static const Flags
all = coords | neighbor | boundaryId | nonPeriodic
248 | orientation | projection | elementType;
250 static const Flags standardWithCoords =
all & ~nonPeriodic & ~projection;
252#if DUNE_ALBERTA_CACHE_COORDINATES
253 static const Flags standard = standardWithCoords & ~coords;
255 static const Flags standard = standardWithCoords;
265 struct RefinementEdge
267 static const int value = 0;
271 struct RefinementEdge< 2 >
273 static const int value = 2;
281 template<
int dim,
int codim >
282 struct Dune2AlbertaNumbering
284 static int apply (
const int i )
286 assert( (i >= 0) && (i < NumSubEntities< dim, codim >::value) );
292 struct Dune2AlbertaNumbering< 3, 2 >
294 static const int numSubEntities = NumSubEntities< 3, 2 >::value;
296 static int apply (
const int i )
298 assert( (i >= 0) && (i < numSubEntities) );
299 static int dune2alberta[ numSubEntities ] = { 0, 3, 1, 2, 4, 5 };
300 return dune2alberta[ i ];
309 template<
int dim,
int codim >
310 struct Generic2AlbertaNumbering
312 static int apply (
const int i )
314 assert( (i >= 0) && (i < NumSubEntities< dim, codim >::value) );
320 struct Generic2AlbertaNumbering< dim, 1 >
322 static int apply (
const int i )
324 assert( (i >= 0) && (i < NumSubEntities< dim, 1 >::value) );
330 struct Generic2AlbertaNumbering< 1, 1 >
332 static int apply (
const int i )
334 assert( (i >= 0) && (i < NumSubEntities< 1, 1 >::value) );
340 struct Generic2AlbertaNumbering< 3, 2 >
342 static const int numSubEntities = NumSubEntities< 3, 2 >::value;
344 static int apply (
const int i )
346 assert( (i >= 0) && (i < numSubEntities) );
347 static int generic2alberta[ numSubEntities ] = { 0, 1, 3, 2, 4, 5 };
348 return generic2alberta[ i ];
357 template<
int dim,
template<
int,
int >
class Numbering = Generic2AlbertaNumbering >
360 typedef NumberingMap< dim, Numbering > This;
362 template<
int codim >
365 int *dune2alberta_[ dim+1 ];
366 int *alberta2dune_[ dim+1 ];
367 int numSubEntities_[ dim+1 ];
369 NumberingMap (
const This & );
370 This &operator= (
const This & );
375 ForLoop< Initialize, 0, dim >::apply( *
this );
380 for(
int codim = 0; codim <= dim; ++codim )
382 delete[]( dune2alberta_[ codim ] );
383 delete[]( alberta2dune_[ codim ] );
387 int dune2alberta (
int codim,
int i )
const
389 assert( (codim >= 0) && (codim <= dim) );
390 assert( (i >= 0) && (i < numSubEntities( codim )) );
391 return dune2alberta_[ codim ][ i ];
394 int alberta2dune (
int codim,
int i )
const
396 assert( (codim >= 0) && (codim <= dim) );
397 assert( (i >= 0) && (i < numSubEntities( codim )) );
398 return alberta2dune_[ codim ][ i ];
401 int numSubEntities (
int codim )
const
403 assert( (codim >= 0) && (codim <= dim) );
404 return numSubEntities_[ codim ];
413 template<
int dim,
template<
int,
int >
class Numbering >
414 template<
int codim >
415 struct NumberingMap< dim, Numbering >::Initialize
417 static const int numSubEntities = NumSubEntities< dim, codim >::value;
419 static void apply ( NumberingMap< dim, Numbering > &map )
421 map.numSubEntities_[ codim ] = numSubEntities;
422 map.dune2alberta_[ codim ] =
new int[ numSubEntities ];
423 map.alberta2dune_[ codim ] =
new int[ numSubEntities ];
425 for(
int i = 0; i < numSubEntities; ++i )
427 const int j = Numbering< dim, codim >::apply( i );
428 map.dune2alberta_[ codim ][ i ] = j;
429 map.alberta2dune_[ codim ][ j ] = i;
439 template<
int dim,
int codim >
443 struct MapVertices< dim, 0 >
445 static int apply (
int subEntity,
int vertex )
447 assert( subEntity == 0 );
448 assert( (vertex >= 0) && (vertex <= NumSubEntities< dim, dim >::value) );
454 struct MapVertices< 2, 1 >
456 static int apply (
int subEntity,
int vertex )
458 assert( (subEntity >= 0) && (subEntity < 3) );
459 assert( (vertex >= 0) && (vertex < 2) );
461 static const int map[ 3 ][ 2 ] = { {1,2}, {0,2}, {0,1} };
462 return map[ subEntity ][ vertex ];
467 struct MapVertices< 3, 1 >
469 static int apply (
int subEntity,
int vertex )
471 assert( (subEntity >= 0) && (subEntity < 4) );
472 assert( (vertex >= 0) && (vertex < 3) );
474 static const int map[ 4 ][ 3 ] = { {1,2,3}, {0,2,3}, {0,1,3}, {0,1,2} };
475 return map[ subEntity ][ vertex ];
480 struct MapVertices< 3, 2 >
482 static int apply (
int subEntity,
int vertex )
484 assert( (subEntity >= 0) && (subEntity < 6) );
485 assert( (vertex >= 0) && (vertex < 2) );
486 static const int map[ 6 ][ 2 ] = { {0,1}, {0,2}, {0,3}, {1,2}, {1,3}, {2,3} };
487 return map[ subEntity ][ vertex ];
492 struct MapVertices< dim, dim >
494 static int apply (
int subEntity,
int vertex )
496 assert( (subEntity >= 0) && (subEntity < NumSubEntities< dim, 1 >::value) );
497 assert( vertex == 0 );
527 template<
int dim,
int subdim >
530 static const int numSubEntities = NumSubEntities< dim, dim-subdim >::value;
532 static const int minTwist = 0;
533 static const int maxTwist = 0;
535 static int twist (
const Element *element,
int subEntity )
537 assert( (subEntity >= 0) && (subEntity < numSubEntities) );
543 struct Twist< dim, 1 >
545 static const int numSubEntities = NumSubEntities< dim, dim-1 >::value;
547 static const int minTwist = 0;
548 static const int maxTwist = 1;
550 static int twist (
const Element *element,
int subEntity )
552 assert( (subEntity >= 0) && (subEntity < numSubEntities) );
553 const int numVertices = NumSubEntities< 1, 1 >::value;
554 int dof[ numVertices ];
555 for(
int i = 0; i < numVertices; ++i )
557 const int j = MapVertices< dim, dim-1 >::apply( subEntity, i );
558 dof[ i ] = element->dof[ j ][ 0 ];
560 return (dof[ 0 ] < dof[ 1 ] ? 0 : 1);
568 static const int minTwist = 0;
569 static const int maxTwist = 0;
571 static int twist (
const Element *element,
int subEntity )
573 assert( subEntity == 0 );
580 struct Twist< dim, 2 >
582 static const int numSubEntities = NumSubEntities< dim, dim-2 >::value;
584 static const int minTwist = -3;
585 static const int maxTwist = 2;
587 static int twist (
const Element *element,
int subEntity )
589 assert( (subEntity >= 0) && (subEntity < numSubEntities) );
590 const int numVertices = NumSubEntities< 2, 2 >::value;
591 int dof[ numVertices ];
592 for(
int i = 0; i < numVertices; ++i )
594 const int j = MapVertices< dim, dim-2 >::apply( subEntity, i );
595 dof[ i ] = element->dof[ j ][ 0 ];
598 const int twist[ 8 ] = { -2, 1, 666, -1, 2, 666, -3, 0 };
599 const int k = int( dof[ 0 ] < dof[ 1 ] )
600 | (int( dof[ 0 ] < dof[ 2 ] ) << 1)
601 | (
int( dof[ 1 ] < dof[ 2 ] ) << 2);
602 assert( twist[ k ] != 666 );
611 static const int minTwist = 0;
612 static const int maxTwist = 0;
614 static int twist (
const Element *element,
int subEntity )
616 assert( subEntity == 0 );
624 inline int applyTwist (
int twist,
int i )
626 const int numCorners = NumSubEntities< dim, dim >::value;
627 return (twist < 0 ? (2*numCorners + 1 - i + twist) : i + twist) % numCorners;
631 inline int applyInverseTwist (
int twist,
int i )
633 const int numCorners = NumSubEntities< dim, dim >::value;
634 return (twist < 0 ? (2*numCorners + 1 - i + twist) : numCorners + i - twist) % numCorners;
A few common exception classes.
A static for loop for template meta-programming.
All all
PartitionSet for all partitions.
Definition: partitionset.hh:244
Dune namespace.
Definition: alignment.hh:11
Traits for type conversions and type information.