5#ifndef DUNE_ALBERTA_MISC_HH
6#define DUNE_ALBERTA_MISC_HH
11#include <dune/common/exceptions.hh>
12#include <dune/common/hybridutilities.hh>
13#include <dune/common/typetraits.hh>
20#ifndef DUNE_ALBERTA_CACHE_COORDINATES
21#define DUNE_ALBERTA_CACHE_COORDINATES 1
72 template<
class Data >
75 return MEM_ALLOC( size, Data );
78 template<
class Data >
81 return MEM_CALLOC( size, Data );
84 template<
class Data >
85 inline Data *
memReAlloc ( Data *ptr,
size_t oldSize,
size_t newSize )
87 return MEM_REALLOC( ptr, oldSize, newSize, Data );
90 template<
class Data >
91 inline void memFree ( Data *ptr,
size_t size )
93 return MEM_FREE( ptr, size, Data );
118 identityMatrix_[ i ][ j ] =
Real( 0 );
119 identityMatrix_[ i ][ i ] =
Real( 1 );
120 nullVector_[ i ] =
Real( 0 );
124 static This &instance ()
126 static This theInstance;
133 return instance().identityMatrix_;
138 return instance().nullVector_;
147 template<
int dim,
int codim >
153 static const int value = 1;
159 static const int value = dim+1;
165 static const int value = 1;
171 static const int value = 3;
177 static const int value = 4;
183 static const int value = 6;
191 template<
int dim,
int codim >
197 static const int value = CENTER;
203 static const int value = VERTEX;
209 static const int value = EDGE;
215 static const int value = FACE;
221 static const int value = EDGE;
255#if DUNE_ALBERTA_CACHE_COORDINATES
284 template<
int dim,
int codim >
301 assert( (i >= 0) && (i < numSubEntities) );
302 static int dune2alberta[ numSubEntities ] = { 0, 3, 1, 2, 4, 5 };
303 return dune2alberta[ i ];
312 template<
int dim,
int codim >
349 assert( (i >= 0) && (i < numSubEntities) );
350 static int generic2alberta[ numSubEntities ] = { 0, 1, 3, 2, 4, 5 };
351 return generic2alberta[ i ];
360 template<
int dim,
template<
int,
int >
class Numbering = Generic2AlbertaNumbering >
365 template<
int codim >
368 int *dune2alberta_[ dim+1 ];
369 int *alberta2dune_[ dim+1 ];
370 int numSubEntities_[ dim+1 ];
378 Hybrid::forEach( std::make_index_sequence< dim+1 >{}, [ & ](
auto i ){ Initialize< i >::apply( *
this ); } );
383 for(
int codim = 0; codim <= dim; ++codim )
385 delete[]( dune2alberta_[ codim ] );
386 delete[]( alberta2dune_[ codim ] );
392 assert( (codim >= 0) && (codim <= dim) );
394 return dune2alberta_[ codim ][ i ];
399 assert( (codim >= 0) && (codim <= dim) );
401 return alberta2dune_[ codim ][ i ];
406 assert( (codim >= 0) && (codim <= dim) );
407 return numSubEntities_[ codim ];
416 template<
int dim,
template<
int,
int >
class Numbering >
417 template<
int codim >
418 struct NumberingMap< dim, Numbering >::Initialize
420 static const int numSubEntities = NumSubEntities< dim, codim >::value;
422 static void apply ( NumberingMap< dim, Numbering > &map )
430 const int j = Numbering< dim, codim >::apply( i );
431 map.dune2alberta_[ codim ][ i ] = j;
432 map.alberta2dune_[ codim ][ j ] = i;
442 template<
int dim,
int codim >
450 assert( subEntity == 0 );
461 assert( (subEntity >= 0) && (subEntity < 3) );
464 static const int map[ 3 ][ 2 ] = { {1,2}, {0,2}, {0,1} };
465 return map[ subEntity ][
vertex ];
474 assert( (subEntity >= 0) && (subEntity < 4) );
477 static const int map[ 4 ][ 3 ] = { {1,2,3}, {0,2,3}, {0,1,3}, {0,1,2} };
478 return map[ subEntity ][
vertex ];
487 assert( (subEntity >= 0) && (subEntity < 6) );
489 static const int map[ 6 ][ 2 ] = { {0,1}, {0,2}, {0,3}, {1,2}, {1,3}, {2,3} };
490 return map[ subEntity ][
vertex ];
530 template<
int dim,
int subdim >
539 [[maybe_unused]]
int subEntity )
558 int dof[ numVertices ];
559 for(
int i = 0; i < numVertices; ++i )
562 dof[ i ] = element->dof[ j ][ 0 ];
564 return (dof[ 0 ] < dof[ 1 ] ? 0 : 1);
576 [[maybe_unused]]
int subEntity )
578 assert( subEntity == 0 );
596 int dof[ numVertices ];
597 for(
int i = 0; i < numVertices; ++i )
600 dof[ i ] = element->dof[ j ][ 0 ];
603 const int twist[ 8 ] = { -2, 1, 666, -1, 2, 666, -3, 0 };
604 const int k = int( dof[ 0 ] < dof[ 1 ] )
605 | (int( dof[ 0 ] < dof[ 2 ] ) << 1)
606 | (
int( dof[ 1 ] < dof[ 2 ] ) << 2);
607 assert(
twist[ k ] != 666 );
620 [[maybe_unused]]
int subEntity )
622 assert( subEntity == 0 );
633 return (twist < 0 ? (2*numCorners + 1 - i + twist) : i + twist) % numCorners;
640 return (twist < 0 ? (2*numCorners + 1 - i + twist) : numCorners + i - twist) % numCorners;
#define DIM_OF_WORLD
Definition: albertaheader.hh:23
#define ALBERTA
Definition: albertaheader.hh:29
Include standard header files.
Definition: agrid.hh:60
int applyInverseTwist(int twist, int i)
Definition: misc.hh:637
ALBERTA MESH Mesh
Definition: misc.hh:53
int applyTwist(int twist, int i)
Definition: misc.hh:630
void memFree(Data *ptr, size_t size)
Definition: misc.hh:91
ALBERTA REAL_DD GlobalMatrix
Definition: misc.hh:51
ALBERTA AFF_TRAFO AffineTransformation
Definition: misc.hh:52
ALBERTA REAL_B LocalVector
Definition: misc.hh:49
ALBERTA EL Element
Definition: misc.hh:54
ALBERTA BNDRY_TYPE BoundaryId
Definition: misc.hh:61
static const int InteriorBoundary
Definition: misc.hh:59
ALBERTA REAL Real
Definition: misc.hh:48
static const int meshRefined
Definition: misc.hh:56
Data * memAlloc(size_t size)
Definition: misc.hh:73
Data * memReAlloc(Data *ptr, size_t oldSize, size_t newSize)
Definition: misc.hh:85
static const int DirichletBoundary
Definition: misc.hh:60
ALBERTA FE_SPACE DofSpace
Definition: misc.hh:65
Data * memCAlloc(size_t size)
Definition: misc.hh:79
static const int dimWorld
Definition: misc.hh:46
U_CHAR ElementType
Definition: misc.hh:63
static const int meshCoarsened
Definition: misc.hh:57
ALBERTA REAL_D GlobalVector
Definition: misc.hh:50
@ vertex
Definition: common.hh:133
static const Matrix & identityMatrix()
Definition: misc.hh:131
static const Vector & nullVector()
Definition: misc.hh:136
GlobalMatrix Matrix
Definition: misc.hh:106
GlobalVector Vector
Definition: misc.hh:107
static const Flags nothing
Definition: misc.hh:234
static const Flags nonPeriodic
Definition: misc.hh:248
static const Flags boundaryId
Definition: misc.hh:246
static const Flags elementType
Definition: misc.hh:244
ALBERTA FLAGS Flags
Definition: misc.hh:232
static const Flags projection
Definition: misc.hh:242
static const Flags coords
Definition: misc.hh:236
static const Flags orientation
Definition: misc.hh:240
static const Flags standard
Definition: misc.hh:256
static const Flags neighbor
Definition: misc.hh:238
static const Flags all
Definition: misc.hh:250
static const Flags standardWithCoords
Definition: misc.hh:253
static const int value
Definition: misc.hh:270
static int apply(const int i)
Definition: misc.hh:287
static int apply(const int i)
Definition: misc.hh:299
static int apply(const int i)
Definition: misc.hh:315
static int apply(const int i)
Definition: misc.hh:325
static int apply(const int i)
Definition: misc.hh:335
static int apply(const int i)
Definition: misc.hh:347
int alberta2dune(int codim, int i) const
Definition: misc.hh:397
int numSubEntities(int codim) const
Definition: misc.hh:404
int dune2alberta(int codim, int i) const
Definition: misc.hh:390
~NumberingMap()
Definition: misc.hh:381
NumberingMap()
Definition: misc.hh:376
static int apply(int subEntity, int vertex)
Definition: misc.hh:448
static int apply(int subEntity, int vertex)
Definition: misc.hh:459
static int apply(int subEntity, int vertex)
Definition: misc.hh:472
static int apply(int subEntity, int vertex)
Definition: misc.hh:485
static int apply(int subEntity, int vertex)
Definition: misc.hh:497
static const int maxTwist
Definition: misc.hh:536
static const int minTwist
Definition: misc.hh:535
static int twist(const Element *element, int subEntity)
Definition: misc.hh:538
static const int numSubEntities
Definition: misc.hh:533
static int twist(const Element *element, int subEntity)
Definition: misc.hh:554
static int twist(const Element *element, int subEntity)
Definition: misc.hh:575
static int twist(const Element *element, int subEntity)
Definition: misc.hh:592
static int twist(const Element *element, int subEntity)
Definition: misc.hh:619