5 #ifndef DUNE_ALBERTA_REFINEMENT_HH
6 #define DUNE_ALBERTA_REFINEMENT_HH
16 #include <dune/grid/albertagrid/misc.hh>
30 template<
int dim,
int codim >
31 struct ForEachInteriorSubChild;
41 typedef Patch< dim > This;
43 static_assert(((dim >= 1) && (dim <= 3)),
44 "Alberta supports only dimensions 1, 2, 3");
47 static const int dimension = dim;
49 typedef Alberta::ElementInfo< dimension > ElementInfo;
51 typedef ALBERTA RC_LIST_EL ElementList;
58 Patch ( ElementList *list,
int count )
65 Element *operator[] (
int i )
const;
72 template<
class LevelProv
ider >
73 ElementInfo elementInfo (
int i,
const LevelProvider &levelProvider )
const;
75 int elementType (
int i )
const;
76 bool hasNeighbor (
int i,
int neighbor )
const;
77 int neighborIndex (
int i,
int neighbor )
const;
79 template<
class Functor >
80 void forEach ( Functor &functor )
const
82 for(
int i = 0; i < count(); ++i )
83 functor( (*
this)[ i ] );
86 template<
int codim,
class Functor >
87 void forEachInteriorSubChild ( Functor &functor )
const
89 ForEachInteriorSubChild< dim, codim >::apply( functor, *
this );
95 inline Element *Patch< dim >::operator[] (
int i )
const
97 assert( (i >= 0) && (i < count()) );
98 return list_[ i ].el_info.el;
103 template<
class LevelProv
ider >
104 inline typename Patch< dim >::ElementInfo
105 Patch< dim >::elementInfo (
int i,
const LevelProvider &levelProvider )
const
107 assert( (i >= 0) && (i < count()) );
108 return ElementInfo::createFake( list_[ i ].el_info );
112 template<
class LevelProv
ider >
113 inline typename Patch< 2 >::ElementInfo
114 Patch< 2 >::elementInfo (
int i,
const LevelProvider &levelProvider )
const
116 assert( (i >= 0) && (i < count()) );
117 const MeshPointer< 2 > &mesh = levelProvider.mesh();
118 const Element *element = (*this)[ i ];
119 const int level = levelProvider( element );
120 return ElementInfo::createFake( mesh, element, level );
125 inline int Patch< dim >::elementType (
int i )
const
127 assert( (i >= 0) && (i < count()) );
128 return list_[ i ].el_info.el_type;
133 inline bool Patch< dim >::hasNeighbor (
int i,
int neighbor )
const
135 return (list_[ i ].neigh[ neighbor ] != NULL);
139 inline int Patch< dim >::neighborIndex (
int i,
int neighbor )
const
141 assert( hasNeighbor( i, neighbor ) );
142 return (list_[ i ].neigh[ neighbor ]->no);
151 struct ForEachInteriorSubChild< dim, 0 >
153 template<
class Functor >
154 static void apply ( Functor &functor,
const Patch< dim > &patch )
156 for(
int i = 0; i < patch.count(); ++i )
158 Element *
const father = patch[ i ];
159 functor( father->child[ 0 ], 0 );
160 functor( father->child[ 1 ], 0 );
166 struct ForEachInteriorSubChild< dim, dim >
168 template<
class Functor >
169 static void apply ( Functor &functor,
const Patch< dim > &patch )
171 functor( patch[ 0 ]->child[ 0 ], dim );
176 struct ForEachInteriorSubChild< 2, 1 >
178 template<
class Functor >
179 static void apply ( Functor &functor,
const Patch< 2 > &patch )
182 Element *
const firstFather = patch[ 0 ];
184 Element *
const firstChild = firstFather->child[ 0 ];
185 functor( firstChild, 0 );
186 functor( firstChild, 1 );
188 functor( firstFather->child[ 1 ], 1 );
190 if( patch.count() > 1 )
192 Element *
const father = patch[ 1 ];
193 functor( father->child[ 0 ], 1 );
199 struct ForEachInteriorSubChild< 3, 1 >
201 template<
class Functor >
202 static void apply ( Functor &functor,
const Patch< 3 > &patch )
205 Element *
const firstFather = patch[ 0 ];
207 Element *
const firstChild = firstFather->child[ 0 ];
208 functor( firstChild, 0 );
209 functor( firstChild, 1 );
210 functor( firstChild, 2 );
212 Element *
const secondChild = firstFather->child[ 1 ];
213 functor( secondChild, 1 );
214 functor( secondChild, 2 );
216 for(
int i = 1; i < patch.count(); ++i )
218 Element *
const father = patch[ i ];
219 const int type = patch.elementType( i );
222 if( patch.hasNeighbor( i, 0 ) && (patch.neighborIndex( i, 0 ) < i) )
224 if( patch.hasNeighbor( i, 1 ) && (patch.neighborIndex( i, 1 ) < i) )
226 assert( lr_set != 0 );
228 functor( father->child[ 0 ], 0 );
232 functor( father->child[ 0 ], 2 );
233 functor( father->child[ 1 ], (type == 0 ? 1 : 2) );
237 functor( father->child[ 0 ], 1 );
238 functor( father->child[ 1 ], (type == 0 ? 2 : 1) );
246 struct ForEachInteriorSubChild< 3, 2 >
248 template<
class Functor >
249 static void apply ( Functor &functor,
const Patch< 3 > &patch )
252 Element *
const firstFather = patch[ 0 ];
254 Element *
const firstChild = firstFather->child[ 0 ];
255 functor( firstChild, 2 );
256 functor( firstChild, 4 );
257 functor( firstChild, 5 );
259 functor( firstFather->child[ 1 ], 2 );
261 for(
int i = 1; i < patch.count(); ++i )
263 Element *
const father = patch[ i ];
266 if( patch.hasNeighbor( i, 0 ) && (patch.neighborIndex( i, 0 ) < i) )
268 if( patch.hasNeighbor( i, 1 ) && (patch.neighborIndex( i, 1 ) < i) )
270 assert( lr_set != 0 );
275 functor( father->child[ 0 ], 4 );
279 functor( father->child[ 0 ], 5 );
292 struct GeometryInFather;
295 struct GeometryInFather< 1 >
297 static const int dim = 1;
299 typedef Real LocalVector[ dim ];
301 static const LocalVector &
302 coordinate (
int child,
int ,
int i )
304 static const Real coords[ 2 ][ dim+1 ][ dim ]
305 = { { {0.0}, {0.5} }, { {0.5}, {1.0} } };
306 assert( (i >= 0) && (i <= dim) );
307 return coords[ child ][ i ];
312 struct GeometryInFather< 2 >
314 static const int dim = 2;
316 typedef Real LocalVector[ dim ];
318 static const LocalVector &
319 coordinate (
int child,
int ,
int i )
321 static const Real coords[ 2 ][ dim+1 ][ dim ]
322 = { { {0.0, 1.0}, {0.0, 0.0}, {0.5, 0.0} },
323 { {1.0, 0.0}, {0.0, 1.0}, {0.5, 0.0} } };
324 assert( (i >= 0) && (i <= dim) );
325 return coords[ child ][ i ];
330 struct GeometryInFather< 3 >
332 static const int dim = 3;
334 typedef Real LocalVector[ dim ];
336 static const LocalVector &
337 coordinate (
int child,
int orientation,
int i )
339 static const Real coords[ 2 ][ dim+1 ][ dim ]
340 = { { {0.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}, {0.5, 0.0, 0.0} },
341 { {1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}, {0.5, 0.0, 0.0} } };
342 static const int flip[ 2 ][ 2 ][ dim+1 ]
343 = { { {0, 1, 2, 3}, {0, 1, 2, 3} }, { {0, 2, 1, 3}, {0, 1, 2, 3} } };
344 assert( (i >= 0) && (i <= dim) );
345 i = flip[ child ][ orientation ][ i ];
346 return coords[ child ][ i ];
provides a wrapper for ALBERTA's el_info structure
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition: hybridutilities.hh:256
Dune namespace.
Definition: alignedallocator.hh:13