3 #ifndef DUNE_ALBERTA_ELEMENTINFO_HH
4 #define DUNE_ALBERTA_ELEMENTINFO_HH
31 struct BasicNodeProjection;
52 static const int numVertices = NumSubEntities< dimension, dimension >::value;
53 static const int numFaces = NumSubEntities< dimension, 1 >::value;
63 #if !DUNE_ALBERTA_CACHE_COORDINATES
70 explicit ElementInfo (
const InstancePtr &instance );
84 operator bool ()
const {
return (instance_ != null()); }
107 void setMark (
int refCount )
const;
124 template<
int codim >
125 int twist (
int subEntity )
const;
134 #if !DUNE_ALBERTA_CACHE_COORDINATES
141 template<
class Functor >
144 template<
class Functor >
164 void addReference ()
const;
165 void removeReference ()
const;
167 static InstancePtr null ();
168 static Stack &stack ();
170 InstancePtr instance_;
192 #if !DUNE_ALBERTA_CACHE_COORDINATES
252 : macroIndex_( -1 ), level_( 0 ), path_( 0 )
255 Seed (
const int macroIndex,
const int level,
const unsigned long path )
256 : macroIndex_( macroIndex ), level_( level ), path_( path )
264 bool operator< (
const Seed &other )
const
266 const bool ml = (macroIndex() < other.
macroIndex());
267 const bool me = (macroIndex() == other.
macroIndex());
270 const bool pl = (path() < other.
path());
271 return ml | (me & (ll | (le & pl)));
275 bool operator<= (
const Seed &other )
const {
return !(other < *
this); }
276 bool operator> (
const Seed &other )
const {
return (other < *
this); }
277 bool operator>= (
const Seed &other )
const {
return !(*
this < other); }
279 bool isValid ( )
const {
return macroIndex_ != -1; }
282 int level ()
const {
return level_; }
283 unsigned long path ()
const {
return path_; }
298 : instance_( instance )
306 : instance_( null() )
317 instance_ = stack().allocate();
318 instance_->parent() = null();
319 ++(instance_->parent()->refCount);
323 elInfo().fill_flag = fillFlags;
326 for(
int k = 0; k < maxNeighbors; ++k )
327 elInfo().opp_vertex[ k ] = -1;
329 fill( mesh, ¯oElement, elInfo() );
338 instance_ = stack().allocate();
339 instance_->parent() = null();
340 ++(instance_->parent()->refCount);
345 elInfo().fill_flag = fillFlags;
348 for(
int k = 0; k < maxNeighbors; ++k )
349 elInfo().opp_vertex[ k ] = -1;
351 fill( mesh, ((
Mesh *)mesh)->macro_els + seed.
macroIndex(), elInfo() );
354 unsigned long path = seed.
path();
355 for(
int i = 0; i < seed.
level(); ++i )
358 child->
parent() = instance_;
361 for(
int k = 0; k < maxNeighbors; ++k )
362 child->
elInfo.opp_vertex[ k ] = -2;
364 fill( path & 1, elInfo(), child->
elInfo );
372 assert( this->seed() == seed );
378 : instance_( other.instance_ )
395 other.addReference();
397 instance_ = other.instance_;
406 return (instance_->elInfo.el == other.instance_->elInfo.el);
414 return (instance_->elInfo.el != other.instance_->elInfo.el);
423 assert( elInfo().macro_el != NULL );
424 return static_cast< const MacroElement &
>( *(elInfo().macro_el) );
440 #if DUNE_ALBERTA_VERSION >= 0x300
441 const Element *father = elInfo().parent->el;
443 const Element *father = elInfo().parent;
445 assert( father != NULL );
447 const int index = (father->child[ 0 ] == element ? 0 : 1);
448 assert( father->child[ index ] == element );
459 child->
parent() = instance_;
463 for(
int k = 0; k < maxNeighbors; ++k )
464 child->
elInfo.opp_vertex[ k ] = -2;
466 fill( i, elInfo(), child->
elInfo );
474 assert( !(*
this) ==
false );
475 return isLeaf( el() );
485 unsigned long path = 0;
489 const Element *father = p->parent()->elInfo.el;
490 const unsigned long child =
static_cast< unsigned long >( father->child[ 1 ] == element );
491 path = (path << 1) | child;
495 if( level != elInfo().level )
496 DUNE_THROW( NotImplemented,
"Seed for fake elements not implemented." );
498 return Seed( macroElement().index, level, path );
512 return mightVanish( el(), 0 );
519 return elInfo().level;
533 return instance_->elInfo.el_type;
548 assert( (refCount >= -128) && (refCount < 127) );
549 el()->mark = refCount;
553 #if DUNE_ALBERTA_VERSION >= 0x300
558 assert( (face >= 0) && (face < maxNeighbors) );
561 const int macroFace = elInfo().macro_wall[ face ];
563 return (macroElement().neighbor( macroFace ) != NULL);
567 #endif // DUNE_ALBERTA_VERSION >= 0x300
569 #if DUNE_ALBERTA_VERSION < 0x300
573 return (neighbor( face ) != NULL);
575 #endif // DUNE_ALBERTA_VERSION < 0x300
581 assert( (face >= 0) && (face < numFaces) );
592 assert( (face >= 0) && (face < numFaces) );
598 template<
int codim >
608 assert( neighbor( face ) != NULL );
613 #if DUNE_ALBERTA_VERSION >= 0x300
618 assert( (face >= 0) && (face < maxNeighbors) );
621 const int macroFace = elInfo().macro_wall[ face ];
623 return macroElement().isBoundary( macroFace );
627 #endif // DUNE_ALBERTA_VERSION >= 0x300
629 #if DUNE_ALBERTA_VERSION <= 0x200
634 assert( (face >= 0) && (face < maxNeighbors) );
635 return (elInfo().neigh[ face ] == 0);
637 #endif // DUNE_ALBERTA_VERSION <= 0x200
640 #if DUNE_ALBERTA_VERSION >= 0x300
645 assert( (face >= 0) && (face < N_WALLS_MAX) );
648 const int macroFace = elInfo().macro_wall[ face ];
649 const int id = macroElement().boundaryId( macroFace );
654 #endif // #if DUNE_ALBERTA_VERSION >= 0x300
657 #if DUNE_ALBERTA_VERSION == 0x200
662 assert( (face >= 0) && (face < N_VERTICES_MAX) );
663 return elInfo().vertex_bound[ 1-face ];
670 assert( (face >= 0) && (face < N_EDGES_MAX) );
671 return elInfo().edge_bound[ face ];
678 assert( (face >= 0) && (face < N_FACES_MAX) );
679 return elInfo().face_bound[ face ];
681 #endif // #if DUNE_ALBERTA_VERSION == 0x200
684 #if DUNE_ALBERTA_VERSION >= 0x300
686 inline AffineTransformation *
690 assert( (face >= 0) && (face < N_WALLS_MAX) );
693 const int macroFace = elInfo().macro_wall[ face ];
694 return (macroFace < 0 ? NULL : macroElement().wall_trafo[ macroFace ]);
696 #endif // #if DUNE_ALBERTA_VERSION >= 0x300
698 #if DUNE_ALBERTA_VERSION <= 0x200
700 inline AffineTransformation *
705 #endif // #if DUNE_ALBERTA_VERSION <= 0x200
708 #if DUNE_ALBERTA_VERSION >= 0x300
714 assert( (face >= 0) && (face < N_WALLS_MAX) );
717 const int macroFace = elInfo().macro_wall[ face ];
723 #endif // #if DUNE_ALBERTA_VERSION >= 0x300
725 #if DUNE_ALBERTA_VERSION <= 0x200
727 inline BasicNodeProjection *
731 assert( (face >= 0) && (face < maxNeighbors) );
732 const int idx = (dim == 1 ? 2-face : 1+face);
735 #endif // #if DUNE_ALBERTA_VERSION <= 0x200
747 assert( hasCoordinates() );
748 assert( (vertex >= 0) && (vertex < numVertices) );
749 return elInfo().coord[
vertex ];
754 template<
class Functor >
760 child( 0 ).hierarchicTraverse( functor );
761 child( 1 ).hierarchicTraverse( functor );
767 template<
class Functor >
772 child( 0 ).leafTraverse( functor );
773 child( 1 ).leafTraverse( functor );
790 assert( (face >= 0) && (face < numFaces) );
792 return elInfo().neigh[ face ];
806 return (instance_->elInfo);
813 const Element *element,
int level,
int type )
816 instance->
parent() = null();
819 instance->
elInfo.mesh = mesh;
820 instance->
elInfo.macro_el = NULL;
822 instance->
elInfo.parent = NULL;
824 instance->
elInfo.level = level;
825 instance->
elInfo.el_type = type;
836 instance->
parent() = null();
839 instance->
elInfo = elInfo;
847 return IS_LEAF_EL( element );
854 if( isLeaf( element ) )
855 return (element->mark < depth);
857 return (mightVanish( element->child[ 0 ], depth-1 ) && mightVanish( element->child[ 1 ], depth-1 ));
862 inline void ElementInfo< dim >
865 ALBERTA fill_macro_info( mesh, mel, &elInfo );
867 #if DUNE_ALBERTA_VERSION < 0x300
869 if( (dim == 1) && (elInfo.fill_flag & FILL_PROJECTION) )
871 for(
int i = 0; i <= N_VERTICES_1D; ++i )
872 elInfo.projections[ i ] = mel->projection[ i ];
878 inline void ElementInfo< dim >
879 ::fill (
int ichild,
const ALBERTA EL_INFO &parentInfo,
ALBERTA EL_INFO &elInfo )
881 #if DUNE_ALBERTA_VERSION >= 0x300
882 ALBERTA fill_elinfo( ichild, FILL_ANY, &parentInfo, &elInfo );
884 ALBERTA fill_elinfo( ichild, &parentInfo, &elInfo );
887 if( (dim == 1) && (elInfo.fill_flag & FILL_PROJECTION) )
889 elInfo.projections[ 0 ] = parentInfo.projections[ 0 ];
892 elInfo.projections[ 1 ] = parentInfo.projections[ 0 ];
893 elInfo.projections[ 2 ] = parentInfo.projections[ 2 ];
897 elInfo.projections[ 1 ] = parentInfo.projections[ 1 ];
898 elInfo.projections[ 2 ] = parentInfo.projections[ 0 ];
906 inline void ElementInfo< dim >::addReference ()
const
908 ++(instance_->refCount);
913 inline void ElementInfo< dim >::removeReference ()
const
916 for( InstancePtr instance = instance_; --(instance->refCount) == 0; )
918 const InstancePtr parent = instance->parent();
919 stack().release( instance );
926 inline typename ElementInfo< dim >::InstancePtr
927 ElementInfo< dim >::null ()
929 return stack().null();
934 inline typename ElementInfo< dim >::Stack &
935 ElementInfo< dim >::stack ()
985 assert( (p != null()) && (p->
refCount == 0) );
1002 #endif // #if HAVE_ALBERTA
1004 #endif // #ifndef DUNE_ALBERTA_ELEMENTINFO_HH