dune-grid 3.0-git
level.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_ALBERTA_LEVEL_HH
4#define DUNE_ALBERTA_LEVEL_HH
5
6#include <cassert>
7#include <cstdlib>
8
12
13#if HAVE_ALBERTA
14
15namespace Dune
16{
17
18 // AlbertaGridLevelProvider
19 // ------------------------
20
21 template< int dim >
23 {
25
26 typedef unsigned char Level;
27
30
32
33 static const Level isNewFlag = (1 << 7);
34 static const Level levelMask = (1 << 7) - 1;
35
36 class SetLocal;
37 class CalcMaxLevel;
38
39 template< Level flags >
40 struct ClearFlags;
41
42 struct Interpolation;
43
44 public:
48
49 Level operator() ( const Alberta::Element *element ) const
50 {
51 const Level *array = (Level *)level_;
52 return array[ dofAccess_( element, 0 ) ] & levelMask;
53 }
54
55 Level operator() ( const ElementInfo &elementInfo ) const
56 {
57 return (*this)( elementInfo.el() );
58 }
59
60 bool isNew ( const Alberta::Element *element ) const
61 {
62 const Level *array = (Level *)level_;
63 return ((array[ dofAccess_( element, 0 ) ] & isNewFlag) != 0);
64 }
65
66 bool isNew ( const ElementInfo &elementInfo ) const
67 {
68 return isNew( elementInfo.el() );
69 }
70
71 Level maxLevel () const
72 {
73 CalcMaxLevel calcFromCache;
74 level_.forEach( calcFromCache );
75#ifndef NDEBUG
76 CalcMaxLevel calcFromGrid;
77 mesh().leafTraverse( calcFromGrid, FillFlags::nothing );
78 assert( calcFromCache.maxLevel() == calcFromGrid.maxLevel() );
79#endif
80 return calcFromCache.maxLevel();;
81 }
82
84 {
85 return MeshPointer( level_.dofSpace()->mesh );
86 }
87
88 void markAllOld ()
89 {
90 ClearFlags< isNewFlag > clearIsNew;
91 level_.forEach( clearIsNew );
92 }
93
94 void create ( const DofNumbering &dofNumbering )
95 {
96 const Alberta::DofSpace *const dofSpace = dofNumbering.dofSpace( 0 );
97 dofAccess_ = DofAccess( dofSpace );
98
99 level_.create( dofSpace, "Element level" );
100 assert( level_ );
101 level_.template setupInterpolation< Interpolation >();
102
103 SetLocal setLocal( level_ );
105 }
106
107 void release ()
108 {
109 level_.release();
110 dofAccess_ = DofAccess();
111 }
112
113 private:
114 DofVectorPointer level_;
115 DofAccess dofAccess_;
116 };
117
118
119
120 // AlbertaGridLevelProvider::SetLocal
121 // ----------------------------------
122
123 template< int dim >
125 {
126 DofVectorPointer level_;
127 DofAccess dofAccess_;
128
129 public:
130 explicit SetLocal ( const DofVectorPointer &level )
131 : level_( level ),
132 dofAccess_( level.dofSpace() )
133 {}
134
135 void operator() ( const Alberta::ElementInfo< dim > &elementInfo ) const
136 {
137 Level *const array = (Level *)level_;
138 array[ dofAccess_( elementInfo, 0 ) ] = elementInfo.level();
139 }
140 };
141
142
143
144 // AlbertaGridLevelProvider::CalcMaxLevel
145 // --------------------------------------
146
147 template< int dim >
149 {
150 Level maxLevel_;
151
152 public:
154 : maxLevel_( 0 )
155 {}
156
157 void operator() ( const Level &dof )
158 {
159 maxLevel_ = std::max( maxLevel_, Level( dof & levelMask ) );
160 }
161
162 void operator() ( const Alberta::ElementInfo< dim > &elementInfo )
163 {
164 maxLevel_ = std::max( maxLevel_, Level( elementInfo.level() ) );
165 }
166
167 Level maxLevel () const
168 {
169 return maxLevel_;
170 }
171 };
172
173
174
175 // AlbertaGridLevelProvider::ClearFlags
176 // ------------------------------------
177
178 template< int dim >
179 template< typename AlbertaGridLevelProvider< dim >::Level flags >
180 struct AlbertaGridLevelProvider< dim >::ClearFlags
181 {
182 void operator() ( Level &dof ) const
183 {
184 dof &= ~flags;
185 }
186 };
187
188
189
190 // AlbertaGridLevelProvider::Interpolation
191 // ---------------------------------------
192
193 template< int dim >
195 {
196 static const int dimension = dim;
197
199
200 static void interpolateVector ( const DofVectorPointer &dofVector,
201 const Patch &patch )
202 {
203 const DofAccess dofAccess( dofVector.dofSpace() );
204 Level *array = (Level *)dofVector;
205
206 for( int i = 0; i < patch.count(); ++i )
207 {
208 const Alberta::Element *const father = patch[ i ];
209 assert( (array[ dofAccess( father, 0 ) ] & levelMask) < levelMask );
210 const Level childLevel = (array[ dofAccess( father, 0 ) ] + 1) | isNewFlag;
211 for( int i = 0; i < 2; ++i )
212 {
213 const Alberta::Element *child = father->child[ i ];
214 array[ dofAccess( child, 0 ) ] = childLevel;
215 }
216 }
217 }
218 };
219
220}
221
222#endif // #if HAVE_ALBERTA
223
224#endif
provides a wrapper for ALBERTA's mesh structure
Include standard header files.
Definition agrid.hh:60
ALBERTA EL Element
Definition misc.hh:51
ALBERTA FE_SPACE DofSpace
Definition misc.hh:62
Definition meshpointer.hh:38
void leafTraverse(Functor &functor, typename FillFlags::Flags fillFlags=FillFlags::standard) const
Definition meshpointer.hh:383
void hierarchicTraverse(Functor &functor, typename FillFlags::Flags fillFlags=FillFlags::standard) const
Definition meshpointer.hh:368
Definition dofadmin.hh:87
const DofSpace * dofSpace(int codim) const
Definition dofadmin.hh:139
void create(const DofSpace *dofSpace, const std::string &name="")
Definition dofvector.hh:234
void release()
Definition dofvector.hh:252
const DofSpace * dofSpace() const
Definition dofvector.hh:221
void forEach(Functor &functor) const
Definition dofvector.hh:262
Definition elementinfo.hh:41
int level() const
Definition elementinfo.hh:531
Element * el() const
Definition elementinfo.hh:735
Definition level.hh:23
bool isNew(const Alberta::Element *element) const
Definition level.hh:60
bool isNew(const ElementInfo &elementInfo) const
Definition level.hh:66
Alberta::MeshPointer< dim > MeshPointer
Definition level.hh:46
MeshPointer mesh() const
Definition level.hh:83
void create(const DofNumbering &dofNumbering)
Definition level.hh:94
Level maxLevel() const
Definition level.hh:71
Alberta::HierarchyDofNumbering< dim > DofNumbering
Definition level.hh:47
void release()
Definition level.hh:107
Level operator()(const Alberta::Element *element) const
Definition level.hh:49
void markAllOld()
Definition level.hh:88
Alberta::ElementInfo< dim > ElementInfo
Definition level.hh:45
SetLocal(const DofVectorPointer &level)
Definition level.hh:130
Level maxLevel() const
Definition level.hh:167
Alberta::Patch< dimension > Patch
Definition level.hh:198
static void interpolateVector(const DofVectorPointer &dofVector, const Patch &patch)
Definition level.hh:200
Definition misc.hh:228
static const Flags nothing
Definition misc.hh:231
Definition refinement.hh:38
int count() const
Definition refinement.hh:65