3#ifndef DUNE_ALBERTA_MISC_HH
4#define DUNE_ALBERTA_MISC_HH
9#include <dune/common/hybridutilities.hh>
10#include <dune/common/std/utility.hh>
13#include <dune/grid/albertagrid/albertaheader.hh>
18#ifndef DUNE_ALBERTA_CACHE_COORDINATES
19#define DUNE_ALBERTA_CACHE_COORDINATES 1
44 static const int dimWorld = DIM_OF_WORLD;
46 typedef ALBERTA REAL Real;
47 typedef ALBERTA REAL_B LocalVector;
48 typedef ALBERTA REAL_D GlobalVector;
49 typedef ALBERTA REAL_DD GlobalMatrix;
50 typedef ALBERTA AFF_TRAFO AffineTransformation;
51 typedef ALBERTA MESH Mesh;
52 typedef ALBERTA EL Element;
54 static const int meshRefined = MESH_REFINED;
55 static const int meshCoarsened = MESH_COARSENED;
57 static const int InteriorBoundary = INTERIOR;
58 static const int DirichletBoundary = DIRICHLET;
59 typedef ALBERTA BNDRY_TYPE BoundaryId;
61 typedef U_CHAR ElementType;
63 typedef ALBERTA FE_SPACE DofSpace;
70 template<
class Data >
71 inline Data *memAlloc (
size_t size )
73 return MEM_ALLOC( size, Data );
76 template<
class Data >
77 inline Data *memCAlloc (
size_t size )
79 return MEM_CALLOC( size, Data );
82 template<
class Data >
83 inline Data *memReAlloc ( Data *ptr,
size_t oldSize,
size_t newSize )
85 return MEM_REALLOC( ptr, oldSize, newSize, Data );
88 template<
class Data >
89 inline void memFree ( Data *ptr,
size_t size )
91 return MEM_FREE( ptr, size, Data );
101 typedef GlobalSpace This;
104 typedef GlobalMatrix Matrix;
105 typedef GlobalVector Vector;
108 Matrix identityMatrix_;
113 for(
int i = 0; i < dimWorld; ++i )
115 for(
int j = 0; j < dimWorld; ++j )
116 identityMatrix_[ i ][ j ] = Real( 0 );
117 identityMatrix_[ i ][ i ] = Real( 1 );
118 nullVector_[ i ] = Real( 0 );
122 static This &instance ()
124 static This theInstance;
129 static const Matrix &identityMatrix ()
131 return instance().identityMatrix_;
134 static const Vector &nullVector ()
136 return instance().nullVector_;
145 template<
int dim,
int codim >
146 struct NumSubEntities;
149 struct NumSubEntities< dim, 0 >
151 static const int value = 1;
155 struct NumSubEntities< dim, dim >
157 static const int value = dim+1;
161 struct NumSubEntities< 0, 0 >
163 static const int value = 1;
167 struct NumSubEntities< 2, 1 >
169 static const int value = 3;
173 struct NumSubEntities< 3, 1 >
175 static const int value = 4;
179 struct NumSubEntities< 3, 2 >
181 static const int value = 6;
189 template<
int dim,
int codim >
193 struct CodimType< dim, 0 >
195 static const int value = CENTER;
199 struct CodimType< dim, dim >
201 static const int value = VERTEX;
205 struct CodimType< 2, 1 >
207 static const int value = EDGE;
211 struct CodimType< 3, 1 >
213 static const int value = FACE;
217 struct CodimType< 3, 2 >
219 static const int value = EDGE;
230 typedef ALBERTA FLAGS Flags;
232 static const Flags nothing = FILL_NOTHING;
234 static const Flags coords = FILL_COORDS;
236 static const Flags neighbor = FILL_NEIGH;
238 static const Flags orientation = (dim == 3 ? FILL_ORIENTATION : FILL_NOTHING);
240 static const Flags projection = FILL_PROJECTION;
242 static const Flags elementType = FILL_NOTHING;
244 static const Flags boundaryId = FILL_MACRO_WALLS;
246 static const Flags nonPeriodic = FILL_NON_PERIODIC;
248 static const Flags
all = coords | neighbor | boundaryId | nonPeriodic
249 | orientation | projection | elementType;
251 static const Flags standardWithCoords =
all & ~nonPeriodic & ~projection;
253#if DUNE_ALBERTA_CACHE_COORDINATES
254 static const Flags standard = standardWithCoords & ~coords;
256 static const Flags standard = standardWithCoords;
266 struct RefinementEdge
268 static const int value = 0;
272 struct RefinementEdge< 2 >
274 static const int value = 2;
282 template<
int dim,
int codim >
283 struct Dune2AlbertaNumbering
285 static int apply (
const int i )
287 assert( (i >= 0) && (i < NumSubEntities< dim, codim >::value) );
293 struct Dune2AlbertaNumbering< 3, 2 >
295 static const int numSubEntities = NumSubEntities< 3, 2 >::value;
297 static int apply (
const int i )
299 assert( (i >= 0) && (i < numSubEntities) );
300 static int dune2alberta[ numSubEntities ] = { 0, 3, 1, 2, 4, 5 };
301 return dune2alberta[ i ];
310 template<
int dim,
int codim >
311 struct Generic2AlbertaNumbering
313 static int apply (
const int i )
315 assert( (i >= 0) && (i < NumSubEntities< dim, codim >::value) );
321 struct Generic2AlbertaNumbering< dim, 1 >
323 static int apply (
const int i )
325 assert( (i >= 0) && (i < NumSubEntities< dim, 1 >::value) );
331 struct Generic2AlbertaNumbering< 1, 1 >
333 static int apply (
const int i )
335 assert( (i >= 0) && (i < NumSubEntities< 1, 1 >::value) );
341 struct Generic2AlbertaNumbering< 3, 2 >
343 static const int numSubEntities = NumSubEntities< 3, 2 >::value;
345 static int apply (
const int i )
347 assert( (i >= 0) && (i < numSubEntities) );
348 static int generic2alberta[ numSubEntities ] = { 0, 1, 3, 2, 4, 5 };
349 return generic2alberta[ i ];
358 template<
int dim,
template<
int,
int >
class Numbering = Generic2AlbertaNumbering >
361 typedef NumberingMap< dim, Numbering > This;
363 template<
int codim >
366 int *dune2alberta_[ dim+1 ];
367 int *alberta2dune_[ dim+1 ];
368 int numSubEntities_[ dim+1 ];
370 NumberingMap (
const This & );
371 This &operator= (
const This & );
381 for(
int codim = 0; codim <= dim; ++codim )
383 delete[]( dune2alberta_[ codim ] );
384 delete[]( alberta2dune_[ codim ] );
388 int dune2alberta (
int codim,
int i )
const
390 assert( (codim >= 0) && (codim <= dim) );
391 assert( (i >= 0) && (i < numSubEntities( codim )) );
392 return dune2alberta_[ codim ][ i ];
395 int alberta2dune (
int codim,
int i )
const
397 assert( (codim >= 0) && (codim <= dim) );
398 assert( (i >= 0) && (i < numSubEntities( codim )) );
399 return alberta2dune_[ codim ][ i ];
402 int numSubEntities (
int codim )
const
404 assert( (codim >= 0) && (codim <= dim) );
405 return numSubEntities_[ codim ];
414 template<
int dim,
template<
int,
int >
class Numbering >
415 template<
int codim >
416 struct NumberingMap< dim, Numbering >::Initialize
418 static const int numSubEntities = NumSubEntities< dim, codim >::value;
420 static void apply ( NumberingMap< dim, Numbering > &map )
422 map.numSubEntities_[ codim ] = numSubEntities;
423 map.dune2alberta_[ codim ] =
new int[ numSubEntities ];
424 map.alberta2dune_[ codim ] =
new int[ numSubEntities ];
426 for(
int i = 0; i < numSubEntities; ++i )
429 map.dune2alberta_[ codim ][ i ] = j;
430 map.alberta2dune_[ codim ][ j ] = i;
440 template<
int dim,
int codim >
444 struct MapVertices< dim, 0 >
448 assert( subEntity == 0 );
449 assert( (
vertex >= 0) && (
vertex <= NumSubEntities< dim, dim >::value) );
455 struct MapVertices< 2, 1 >
459 assert( (subEntity >= 0) && (subEntity < 3) );
462 static const int map[ 3 ][ 2 ] = { {1,2}, {0,2}, {0,1} };
463 return map[ subEntity ][
vertex ];
468 struct MapVertices< 3, 1 >
472 assert( (subEntity >= 0) && (subEntity < 4) );
475 static const int map[ 4 ][ 3 ] = { {1,2,3}, {0,2,3}, {0,1,3}, {0,1,2} };
476 return map[ subEntity ][
vertex ];
481 struct MapVertices< 3, 2 >
485 assert( (subEntity >= 0) && (subEntity < 6) );
487 static const int map[ 6 ][ 2 ] = { {0,1}, {0,2}, {0,3}, {1,2}, {1,3}, {2,3} };
488 return map[ subEntity ][
vertex ];
493 struct MapVertices< dim, dim >
497 assert( (subEntity >= 0) && (subEntity < NumSubEntities< dim, 1 >::value) );
528 template<
int dim,
int subdim >
531 static const int numSubEntities = NumSubEntities< dim, dim-subdim >::value;
533 static const int minTwist = 0;
534 static const int maxTwist = 0;
536 static int twist (
const Element *element,
int subEntity )
538 assert( (subEntity >= 0) && (subEntity < numSubEntities) );
544 struct Twist< dim, 1 >
546 static const int numSubEntities = NumSubEntities< dim, dim-1 >::value;
548 static const int minTwist = 0;
549 static const int maxTwist = 1;
551 static int twist (
const Element *element,
int subEntity )
553 assert( (subEntity >= 0) && (subEntity < numSubEntities) );
554 const int numVertices = NumSubEntities< 1, 1 >::value;
555 int dof[ numVertices ];
556 for(
int i = 0; i < numVertices; ++i )
559 dof[ i ] = element->dof[ j ][ 0 ];
561 return (dof[ 0 ] < dof[ 1 ] ? 0 : 1);
569 static const int minTwist = 0;
570 static const int maxTwist = 0;
572 static int twist (
const Element *element,
int subEntity )
574 assert( subEntity == 0 );
581 struct Twist< dim, 2 >
583 static const int numSubEntities = NumSubEntities< dim, dim-2 >::value;
585 static const int minTwist = -3;
586 static const int maxTwist = 2;
588 static int twist (
const Element *element,
int subEntity )
590 assert( (subEntity >= 0) && (subEntity < numSubEntities) );
591 const int numVertices = NumSubEntities< 2, 2 >::value;
592 int dof[ numVertices ];
593 for(
int i = 0; i < numVertices; ++i )
596 dof[ i ] = element->dof[ j ][ 0 ];
599 const int twist[ 8 ] = { -2, 1, 666, -1, 2, 666, -3, 0 };
600 const int k = int( dof[ 0 ] < dof[ 1 ] )
601 | (int( dof[ 0 ] < dof[ 2 ] ) << 1)
602 | (
int( dof[ 1 ] < dof[ 2 ] ) << 2);
603 assert( twist[ k ] != 666 );
612 static const int minTwist = 0;
613 static const int maxTwist = 0;
615 static int twist (
const Element *element,
int subEntity )
617 assert( subEntity == 0 );
625 inline int applyTwist (
int twist,
int i )
627 const int numCorners = NumSubEntities< dim, dim >::value;
628 return (twist < 0 ? (2*numCorners + 1 - i + twist) : i + twist) % numCorners;
632 inline int applyInverseTwist (
int twist,
int i )
634 const int numCorners = NumSubEntities< dim, dim >::value;
635 return (twist < 0 ? (2*numCorners + 1 - i + twist) : numCorners + i - twist) % numCorners;
A few common exception classes.
decltype(auto) apply(F &&f, ArgTuple &&args)
Apply function with arguments given as tuple.
Definition: apply.hh:58
constexpr GeometryType vertex
GeometryType representing a vertex.
Definition: type.hh:727
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition: hybridutilities.hh:308
constexpr All all
PartitionSet for all partitions.
Definition: partitionset.hh:294
Dune namespace.
Definition: alignedallocator.hh:10
Traits for type conversions and type information.