3#ifndef DUNE_ALBERTA_MISC_HH
4#define DUNE_ALBERTA_MISC_HH
10#include <dune/common/hybridutilities.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 & );
376 Hybrid::forEach( std::make_index_sequence< dim+1 >{}, [ & ](
auto i ){ Initialize< i >::apply( *
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 )
428 const int j = Numbering< dim, codim >::apply( i );
429 map.dune2alberta_[ codim ][ i ] = j;
430 map.alberta2dune_[ codim ][ j ] = i;
440 template<
int dim,
int codim >
444 struct MapVertices< dim, 0 >
446 static int apply (
int subEntity,
int vertex )
448 assert( subEntity == 0 );
449 assert( (
vertex >= 0) && (
vertex <= NumSubEntities< dim, dim >::value) );
455 struct MapVertices< 2, 1 >
457 static int apply (
int subEntity,
int vertex )
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 >
470 static int apply (
int subEntity,
int vertex )
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 >
483 static int apply (
int subEntity,
int vertex )
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 >
495 static int apply (
int subEntity,
int vertex )
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 ( [[maybe_unused]]
const Element *element,
537 [[maybe_unused]]
int subEntity )
539 assert( (subEntity >= 0) && (subEntity < numSubEntities) );
545 struct Twist< dim, 1 >
547 static const int numSubEntities = NumSubEntities< dim, dim-1 >::value;
549 static const int minTwist = 0;
550 static const int maxTwist = 1;
552 static int twist (
const Element *element,
int subEntity )
554 assert( (subEntity >= 0) && (subEntity < numSubEntities) );
555 const int numVertices = NumSubEntities< 1, 1 >::value;
556 int dof[ numVertices ];
557 for(
int i = 0; i < numVertices; ++i )
559 const int j = MapVertices< dim, dim-1 >::apply( subEntity, i );
560 dof[ i ] = element->dof[ j ][ 0 ];
562 return (dof[ 0 ] < dof[ 1 ] ? 0 : 1);
570 static const int minTwist = 0;
571 static const int maxTwist = 0;
573 static int twist ( [[maybe_unused]]
const Element *element,
574 [[maybe_unused]]
int subEntity )
576 assert( subEntity == 0 );
583 struct Twist< dim, 2 >
585 static const int numSubEntities = NumSubEntities< dim, dim-2 >::value;
587 static const int minTwist = -3;
588 static const int maxTwist = 2;
590 static int twist (
const Element *element,
int subEntity )
592 assert( (subEntity >= 0) && (subEntity < numSubEntities) );
593 const int numVertices = NumSubEntities< 2, 2 >::value;
594 int dof[ numVertices ];
595 for(
int i = 0; i < numVertices; ++i )
597 const int j = MapVertices< dim, dim-2 >::apply( subEntity, i );
598 dof[ i ] = element->dof[ j ][ 0 ];
601 const int twist[ 8 ] = { -2, 1, 666, -1, 2, 666, -3, 0 };
602 const int k = int( dof[ 0 ] < dof[ 1 ] )
603 | (int( dof[ 0 ] < dof[ 2 ] ) << 1)
604 | (
int( dof[ 1 ] < dof[ 2 ] ) << 2);
605 assert( twist[ k ] != 666 );
614 static const int minTwist = 0;
615 static const int maxTwist = 0;
617 static int twist ( [[maybe_unused]]
const Element *element,
618 [[maybe_unused]]
int subEntity )
620 assert( subEntity == 0 );
628 inline int applyTwist (
int twist,
int i )
630 const int numCorners = NumSubEntities< dim, dim >::value;
631 return (twist < 0 ? (2*numCorners + 1 - i + twist) : i + twist) % numCorners;
635 inline int applyInverseTwist (
int twist,
int i )
637 const int numCorners = NumSubEntities< dim, dim >::value;
638 return (twist < 0 ? (2*numCorners + 1 - i + twist) : numCorners + i - twist) % numCorners;
A few common exception classes.
Traits for type conversions and type information.
constexpr GeometryType vertex
GeometryType representing a vertex.
Definition: type.hh:504
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition: hybridutilities.hh:266
constexpr All all
PartitionSet for all partitions.
Definition: partitionset.hh:294
Dune namespace.
Definition: alignedallocator.hh:11