1 #ifndef DUNE_ALBERTA_ELEMENTINFO_HH
2 #define DUNE_ALBERTA_ELEMENTINFO_HH
29 struct BasicNodeProjection;
50 static const int numVertices = NumSubEntities< dimension, dimension >::value;
51 static const int numFaces = NumSubEntities< dimension, 1 >::value;
61 #if !DUNE_ALBERTA_CACHE_COORDINATES
68 explicit ElementInfo (
const InstancePtr &instance );
82 operator bool ()
const {
return (instance_ != null()); }
105 void setMark (
int refCount )
const;
122 template<
int codim >
123 int twist (
int subEntity )
const;
132 #if !DUNE_ALBERTA_CACHE_COORDINATES
139 template<
class Functor >
142 template<
class Functor >
162 void addReference ()
const;
163 void removeReference ()
const;
165 static InstancePtr null ();
166 static Stack &stack ();
168 InstancePtr instance_;
190 #if !DUNE_ALBERTA_CACHE_COORDINATES
249 Seed (
const int macroIndex,
const int level,
const unsigned long path )
250 : macroIndex_( macroIndex ), level_( level ), path_( path )
258 bool operator< (
const Seed &other )
const
260 const bool ml = (macroIndex() < other.
macroIndex());
261 const bool me = (macroIndex() == other.
macroIndex());
264 const bool pl = (path() < other.
path());
265 return ml | (me & (ll | (le & pl)));
269 bool operator<= (
const Seed &other )
const {
return !(other < *
this); }
270 bool operator> (
const Seed &other )
const {
return (other < *
this); }
271 bool operator>= (
const Seed &other )
const {
return !(*
this < other); }
274 int level ()
const {
return level_; }
275 unsigned long path ()
const {
return path_; }
290 : instance_( instance )
298 : instance_( null() )
309 instance_ = stack().allocate();
310 instance_->parent() = null();
311 ++(instance_->parent()->refCount);
315 elInfo().fill_flag = fillFlags;
318 for(
int k = 0; k < maxNeighbors; ++k )
319 elInfo().opp_vertex[ k ] = -1;
321 fill( mesh, ¯oElement, elInfo() );
330 instance_ = stack().allocate();
331 instance_->parent() = null();
332 ++(instance_->parent()->refCount);
337 elInfo().fill_flag = fillFlags;
340 for(
int k = 0; k < maxNeighbors; ++k )
341 elInfo().opp_vertex[ k ] = -1;
343 fill( mesh, ((
Mesh *)mesh)->macro_els + seed.
macroIndex(), elInfo() );
346 unsigned long path = seed.
path();
347 for(
int i = 0; i < seed.
level(); ++i )
350 child->
parent() = instance_;
353 for(
int k = 0; k < maxNeighbors; ++k )
354 child->
elInfo.opp_vertex[ k ] = -2;
356 fill( path & 1, elInfo(), child->
elInfo );
364 assert( this->seed() == seed );
370 : instance_( other.instance_ )
387 other.addReference();
389 instance_ = other.instance_;
398 return (instance_->elInfo.el == other.instance_->elInfo.el);
406 return (instance_->elInfo.el != other.instance_->elInfo.el);
415 assert( elInfo().macro_el != NULL );
416 return static_cast< const MacroElement &
>( *(elInfo().macro_el) );
432 #if DUNE_ALBERTA_VERSION >= 0x300
433 const Element *father = elInfo().parent->el;
435 const Element *father = elInfo().parent;
437 assert( father != NULL );
439 const int index = (father->child[ 0 ] == element ? 0 : 1);
440 assert( father->child[ index ] == element );
451 child->
parent() = instance_;
455 for(
int k = 0; k < maxNeighbors; ++k )
456 child->
elInfo.opp_vertex[ k ] = -2;
458 fill( i, elInfo(), child->
elInfo );
466 assert( !(*
this) ==
false );
467 return isLeaf( el() );
477 unsigned long path = 0;
481 const Element *father = p->parent()->elInfo.el;
482 const unsigned long child =
static_cast< unsigned long >( father->child[ 1 ] == element );
483 path = (path << 1) | child;
487 if( level != elInfo().level )
488 DUNE_THROW( NotImplemented,
"Seed for fake elements not implemented." );
490 return Seed( macroElement().index, level, path );
504 return mightVanish( el(), 0 );
511 return elInfo().level;
525 return instance_->elInfo.el_type;
540 assert( (refCount >= -128) && (refCount < 127) );
541 el()->mark = refCount;
545 #if DUNE_ALBERTA_VERSION >= 0x300
550 assert( (face >= 0) && (face < maxNeighbors) );
553 const int macroFace = elInfo().macro_wall[ face ];
555 return (macroElement().neighbor( macroFace ) != NULL);
559 #endif // DUNE_ALBERTA_VERSION >= 0x300
561 #if DUNE_ALBERTA_VERSION < 0x300
565 return (neighbor( face ) != NULL);
567 #endif // DUNE_ALBERTA_VERSION < 0x300
573 assert( (face >= 0) && (face < numFaces) );
584 assert( (face >= 0) && (face < numFaces) );
590 template<
int codim >
600 assert( neighbor( face ) != NULL );
605 #if DUNE_ALBERTA_VERSION >= 0x300
610 assert( (face >= 0) && (face < maxNeighbors) );
613 const int macroFace = elInfo().macro_wall[ face ];
615 return macroElement().isBoundary( macroFace );
619 #endif // DUNE_ALBERTA_VERSION >= 0x300
621 #if DUNE_ALBERTA_VERSION <= 0x200
626 assert( (face >= 0) && (face < maxNeighbors) );
627 return (elInfo().neigh[ face ] == 0);
629 #endif // DUNE_ALBERTA_VERSION <= 0x200
632 #if DUNE_ALBERTA_VERSION >= 0x300
637 assert( (face >= 0) && (face < N_WALLS_MAX) );
640 const int macroFace = elInfo().macro_wall[ face ];
641 const int id = macroElement().boundaryId( macroFace );
646 #endif // #if DUNE_ALBERTA_VERSION >= 0x300
649 #if DUNE_ALBERTA_VERSION == 0x200
654 assert( (face >= 0) && (face < N_VERTICES_MAX) );
655 return elInfo().vertex_bound[ 1-face ];
662 assert( (face >= 0) && (face < N_EDGES_MAX) );
663 return elInfo().edge_bound[ face ];
670 assert( (face >= 0) && (face < N_FACES_MAX) );
671 return elInfo().face_bound[ face ];
673 #endif // #if DUNE_ALBERTA_VERSION == 0x200
676 #if DUNE_ALBERTA_VERSION >= 0x300
678 inline AffineTransformation *
682 assert( (face >= 0) && (face < N_WALLS_MAX) );
685 const int macroFace = elInfo().macro_wall[ face ];
686 return (macroFace < 0 ? NULL : macroElement().wall_trafo[ macroFace ]);
688 #endif // #if DUNE_ALBERTA_VERSION >= 0x300
690 #if DUNE_ALBERTA_VERSION <= 0x200
692 inline AffineTransformation *
697 #endif // #if DUNE_ALBERTA_VERSION <= 0x200
700 #if DUNE_ALBERTA_VERSION >= 0x300
706 assert( (face >= 0) && (face < N_WALLS_MAX) );
709 const int macroFace = elInfo().macro_wall[ face ];
715 #endif // #if DUNE_ALBERTA_VERSION >= 0x300
717 #if DUNE_ALBERTA_VERSION <= 0x200
719 inline BasicNodeProjection *
723 assert( (face >= 0) && (face < maxNeighbors) );
724 const int idx = (dim == 1 ? 2-face : 1+face);
727 #endif // #if DUNE_ALBERTA_VERSION <= 0x200
739 assert( hasCoordinates() );
740 assert( (vertex >= 0) && (vertex < numVertices) );
741 return elInfo().coord[
vertex ];
746 template<
class Functor >
752 child( 0 ).hierarchicTraverse( functor );
753 child( 1 ).hierarchicTraverse( functor );
759 template<
class Functor >
764 child( 0 ).leafTraverse( functor );
765 child( 1 ).leafTraverse( functor );
782 assert( (face >= 0) && (face < numFaces) );
784 return elInfo().neigh[ face ];
798 return (instance_->elInfo);
805 const Element *element,
int level,
int type )
808 instance->
parent() = null();
811 instance->
elInfo.mesh = mesh;
812 instance->
elInfo.macro_el = NULL;
814 instance->
elInfo.parent = NULL;
816 instance->
elInfo.level = level;
817 instance->
elInfo.el_type = type;
828 instance->
parent() = null();
831 instance->
elInfo = elInfo;
839 return IS_LEAF_EL( element );
846 if( isLeaf( element ) )
847 return (element->mark < depth);
849 return (mightVanish( element->child[ 0 ], depth-1 ) && mightVanish( element->child[ 1 ], depth-1 ));
854 inline void ElementInfo< dim >
857 ALBERTA fill_macro_info( mesh, mel, &elInfo );
859 #if DUNE_ALBERTA_VERSION < 0x300
861 if( (dim == 1) && (elInfo.fill_flag & FILL_PROJECTION) )
863 for(
int i = 0; i <= N_VERTICES_1D; ++i )
864 elInfo.projections[ i ] = mel->projection[ i ];
870 inline void ElementInfo< dim >
871 ::fill (
int ichild,
const ALBERTA EL_INFO &parentInfo,
ALBERTA EL_INFO &elInfo )
873 #if DUNE_ALBERTA_VERSION >= 0x300
874 ALBERTA fill_elinfo( ichild, FILL_ANY, &parentInfo, &elInfo );
876 ALBERTA fill_elinfo( ichild, &parentInfo, &elInfo );
879 if( (dim == 1) && (elInfo.fill_flag & FILL_PROJECTION) )
881 elInfo.projections[ 0 ] = parentInfo.projections[ 0 ];
884 elInfo.projections[ 1 ] = parentInfo.projections[ 0 ];
885 elInfo.projections[ 2 ] = parentInfo.projections[ 2 ];
889 elInfo.projections[ 1 ] = parentInfo.projections[ 1 ];
890 elInfo.projections[ 2 ] = parentInfo.projections[ 0 ];
898 inline void ElementInfo< dim >::addReference ()
const
900 ++(instance_->refCount);
905 inline void ElementInfo< dim >::removeReference ()
const
908 for( InstancePtr instance = instance_; --(instance->refCount) == 0; )
910 const InstancePtr parent = instance->parent();
911 stack().release( instance );
918 inline typename ElementInfo< dim >::InstancePtr
919 ElementInfo< dim >::null ()
921 return stack().null();
926 inline typename ElementInfo< dim >::Stack &
927 ElementInfo< dim >::stack ()
977 assert( (p != null()) && (p->
refCount == 0) );
994 #endif // #if HAVE_ALBERTA
996 #endif // #ifndef DUNE_ALBERTA_ELEMENTINFO_HH