5#ifndef DUNE_ALBERTA_LEVEL_HH
6#define DUNE_ALBERTA_LEVEL_HH
12#include <dune/grid/albertagrid/dofadmin.hh>
13#include <dune/grid/albertagrid/dofvector.hh>
24 class AlbertaGridLevelProvider
26 typedef AlbertaGridLevelProvider< dim > This;
28 typedef unsigned char Level;
30 typedef Alberta::DofVectorPointer< Level > DofVectorPointer;
31 typedef Alberta::DofAccess< dim, 0 > DofAccess;
33 typedef Alberta::FillFlags< dim > FillFlags;
35 static const Level isNewFlag = (1 << 7);
36 static const Level levelMask = (1 << 7) - 1;
41 template< Level flags >
47 typedef Alberta::ElementInfo< dim > ElementInfo;
48 typedef Alberta::MeshPointer< dim > MeshPointer;
49 typedef Alberta::HierarchyDofNumbering< dim > DofNumbering;
51 Level operator() (
const Alberta::Element *element )
const
53 const Level *array = (Level *)level_;
54 return array[ dofAccess_( element, 0 ) ] & levelMask;
57 Level operator() (
const ElementInfo &elementInfo )
const
59 return (*
this)( elementInfo.el() );
62 bool isNew (
const Alberta::Element *element )
const
64 const Level *array = (Level *)level_;
65 return ((array[ dofAccess_( element, 0 ) ] & isNewFlag) != 0);
68 bool isNew (
const ElementInfo &elementInfo )
const
70 return isNew( elementInfo.el() );
73 Level maxLevel ()
const
75 CalcMaxLevel calcFromCache;
76 level_.forEach( calcFromCache );
78 CalcMaxLevel calcFromGrid;
79 mesh().leafTraverse( calcFromGrid, FillFlags::nothing );
80 assert( calcFromCache.maxLevel() == calcFromGrid.maxLevel() );
82 return calcFromCache.maxLevel();;
85 MeshPointer mesh ()
const
87 return MeshPointer( level_.dofSpace()->mesh );
92 ClearFlags< isNewFlag > clearIsNew;
93 level_.forEach( clearIsNew );
96 void create (
const DofNumbering &dofNumbering )
98 const Alberta::DofSpace *
const dofSpace = dofNumbering.dofSpace( 0 );
99 dofAccess_ = DofAccess( dofSpace );
101 level_.create( dofSpace,
"Element level" );
103 level_.template setupInterpolation< Interpolation >();
105 SetLocal setLocal( level_ );
106 mesh().hierarchicTraverse( setLocal, FillFlags::nothing );
112 dofAccess_ = DofAccess();
116 DofVectorPointer level_;
117 DofAccess dofAccess_;
126 class AlbertaGridLevelProvider< dim >::SetLocal
128 DofVectorPointer level_;
129 DofAccess dofAccess_;
132 explicit SetLocal (
const DofVectorPointer &level )
134 dofAccess_( level.dofSpace() )
137 void operator() (
const Alberta::ElementInfo< dim > &elementInfo )
const
139 Level *
const array = (Level *)level_;
140 array[ dofAccess_( elementInfo, 0 ) ] = elementInfo.level();
150 class AlbertaGridLevelProvider< dim >::CalcMaxLevel
159 void operator() (
const Level &dof )
161 maxLevel_ = std::max( maxLevel_, Level( dof & levelMask ) );
164 void operator() (
const Alberta::ElementInfo< dim > &elementInfo )
166 maxLevel_ = std::max( maxLevel_, Level( elementInfo.level() ) );
169 Level maxLevel ()
const
181 template< typename AlbertaGridLevelProvider< dim >::Level flags >
182 struct AlbertaGridLevelProvider< dim >::ClearFlags
184 void operator() ( Level &dof )
const
196 struct AlbertaGridLevelProvider< dim >::Interpolation
198 static const int dimension = dim;
200 typedef Alberta::Patch< dimension > Patch;
202 static void interpolateVector (
const DofVectorPointer &dofVector,
205 const DofAccess dofAccess( dofVector.dofSpace() );
206 Level *array = (Level *)dofVector;
208 for(
int i = 0; i < patch.count(); ++i )
210 const Alberta::Element *
const father = patch[ i ];
211 assert( (array[ dofAccess( father, 0 ) ] & levelMask) < levelMask );
212 const Level childLevel = (array[ dofAccess( father, 0 ) ] + 1) | isNewFlag;
213 for(
int i = 0; i < 2; ++i )
215 const Alberta::Element *child = father->child[ i ];
216 array[ dofAccess( child, 0 ) ] = childLevel;
provides a wrapper for ALBERTA's mesh structure
Dune namespace.
Definition: alignedallocator.hh:13