3 #ifndef DUNE_ALBERTA_REFINEMENT_HH
4 #define DUNE_ALBERTA_REFINEMENT_HH
14 #include <dune/grid/albertagrid/misc.hh>
28 template<
int dim,
int codim >
29 struct ForEachInteriorSubChild;
39 typedef Patch< dim > This;
41 static_assert(((dim >= 1) && (dim <= 3)),
42 "Alberta supports only dimensions 1, 2, 3");
45 static const int dimension = dim;
47 typedef Alberta::ElementInfo< dimension > ElementInfo;
49 typedef ALBERTA RC_LIST_EL ElementList;
56 Patch ( ElementList *list,
int count )
63 Element *operator[] (
int i )
const;
70 template<
class LevelProv
ider >
71 ElementInfo elementInfo (
int i,
const LevelProvider &levelProvider )
const;
73 int elementType (
int i )
const;
74 bool hasNeighbor (
int i,
int neighbor )
const;
75 int neighborIndex (
int i,
int neighbor )
const;
77 template<
class Functor >
78 void forEach ( Functor &functor )
const
80 for(
int i = 0; i < count(); ++i )
81 functor( (*
this)[ i ] );
84 template<
int codim,
class Functor >
85 void forEachInteriorSubChild ( Functor &functor )
const
93 inline Element *Patch< dim >::operator[] (
int i )
const
95 assert( (i >= 0) && (i < count()) );
96 return list_[ i ].el_info.el;
101 template<
class LevelProv
ider >
102 inline typename Patch< dim >::ElementInfo
103 Patch< dim >::elementInfo (
int i,
const LevelProvider &levelProvider )
const
105 assert( (i >= 0) && (i < count()) );
106 return ElementInfo::createFake( list_[ i ].el_info );
110 template<
class LevelProv
ider >
111 inline typename Patch< 2 >::ElementInfo
112 Patch< 2 >::elementInfo (
int i,
const LevelProvider &levelProvider )
const
114 assert( (i >= 0) && (i < count()) );
115 const MeshPointer< 2 > &mesh = levelProvider.mesh();
116 const Element *element = (*this)[ i ];
117 const int level = levelProvider( element );
118 return ElementInfo::createFake( mesh, element, level );
123 inline int Patch< dim >::elementType (
int i )
const
125 assert( (i >= 0) && (i < count()) );
126 return list_[ i ].el_info.el_type;
131 inline bool Patch< dim >::hasNeighbor (
int i,
int neighbor )
const
133 return (list_[ i ].neigh[ neighbor ] != NULL);
137 inline int Patch< dim >::neighborIndex (
int i,
int neighbor )
const
139 assert( hasNeighbor( i, neighbor ) );
140 return (list_[ i ].neigh[ neighbor ]->no);
149 struct ForEachInteriorSubChild< dim, 0 >
151 template<
class Functor >
152 static void apply ( Functor &functor,
const Patch< dim > &patch )
154 for(
int i = 0; i < patch.count(); ++i )
156 Element *
const father = patch[ i ];
157 functor( father->child[ 0 ], 0 );
158 functor( father->child[ 1 ], 0 );
164 struct ForEachInteriorSubChild< dim, dim >
166 template<
class Functor >
167 static void apply ( Functor &functor,
const Patch< dim > &patch )
169 functor( patch[ 0 ]->child[ 0 ], dim );
174 struct ForEachInteriorSubChild< 2, 1 >
176 template<
class Functor >
177 static void apply ( Functor &functor,
const Patch< 2 > &patch )
180 Element *
const firstFather = patch[ 0 ];
182 Element *
const firstChild = firstFather->child[ 0 ];
183 functor( firstChild, 0 );
184 functor( firstChild, 1 );
186 functor( firstFather->child[ 1 ], 1 );
188 if( patch.count() > 1 )
190 Element *
const father = patch[ 1 ];
191 functor( father->child[ 0 ], 1 );
197 struct ForEachInteriorSubChild< 3, 1 >
199 template<
class Functor >
200 static void apply ( Functor &functor,
const Patch< 3 > &patch )
203 Element *
const firstFather = patch[ 0 ];
205 Element *
const firstChild = firstFather->child[ 0 ];
206 functor( firstChild, 0 );
207 functor( firstChild, 1 );
208 functor( firstChild, 2 );
210 Element *
const secondChild = firstFather->child[ 1 ];
211 functor( secondChild, 1 );
212 functor( secondChild, 2 );
214 for(
int i = 1; i < patch.count(); ++i )
216 Element *
const father = patch[ i ];
217 const int type = patch.elementType( i );
220 if( patch.hasNeighbor( i, 0 ) && (patch.neighborIndex( i, 0 ) < i) )
222 if( patch.hasNeighbor( i, 1 ) && (patch.neighborIndex( i, 1 ) < i) )
224 assert( lr_set != 0 );
226 functor( father->child[ 0 ], 0 );
230 functor( father->child[ 0 ], 2 );
231 functor( father->child[ 1 ], (type == 0 ? 1 : 2) );
235 functor( father->child[ 0 ], 1 );
236 functor( father->child[ 1 ], (type == 0 ? 2 : 1) );
244 struct ForEachInteriorSubChild< 3, 2 >
246 template<
class Functor >
247 static void apply ( Functor &functor,
const Patch< 3 > &patch )
250 Element *
const firstFather = patch[ 0 ];
252 Element *
const firstChild = firstFather->child[ 0 ];
253 functor( firstChild, 2 );
254 functor( firstChild, 4 );
255 functor( firstChild, 5 );
257 functor( firstFather->child[ 1 ], 2 );
259 for(
int i = 1; i < patch.count(); ++i )
261 Element *
const father = patch[ i ];
264 if( patch.hasNeighbor( i, 0 ) && (patch.neighborIndex( i, 0 ) < i) )
266 if( patch.hasNeighbor( i, 1 ) && (patch.neighborIndex( i, 1 ) < i) )
268 assert( lr_set != 0 );
273 functor( father->child[ 0 ], 4 );
277 functor( father->child[ 0 ], 5 );
290 struct GeometryInFather;
293 struct GeometryInFather< 1 >
295 static const int dim = 1;
297 typedef Real LocalVector[ dim ];
299 static const LocalVector &
300 coordinate (
int child,
int orientation,
int i )
302 static const Real coords[ 2 ][ dim+1 ][ dim ]
303 = { { {0.0}, {0.5} }, { {0.5}, {1.0} } };
304 assert( (i >= 0) && (i <= dim) );
305 return coords[ child ][ i ];
310 struct GeometryInFather< 2 >
312 static const int dim = 2;
314 typedef Real LocalVector[ dim ];
316 static const LocalVector &
317 coordinate (
int child,
int orientation,
int i )
319 static const Real coords[ 2 ][ dim+1 ][ dim ]
320 = { { {0.0, 1.0}, {0.0, 0.0}, {0.5, 0.0} },
321 { {1.0, 0.0}, {0.0, 1.0}, {0.5, 0.0} } };
322 assert( (i >= 0) && (i <= dim) );
323 return coords[ child ][ i ];
328 struct GeometryInFather< 3 >
330 static const int dim = 3;
332 typedef Real LocalVector[ dim ];
334 static const LocalVector &
335 coordinate (
int child,
int orientation,
int i )
337 static const Real coords[ 2 ][ dim+1 ][ dim ]
338 = { { {0.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}, {0.5, 0.0, 0.0} },
339 { {1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}, {0.5, 0.0, 0.0} } };
340 static const int flip[ 2 ][ 2 ][ dim+1 ]
341 = { { {0, 1, 2, 3}, {0, 1, 2, 3} }, { {0, 2, 1, 3}, {0, 1, 2, 3} } };
342 assert( (i >= 0) && (i <= dim) );
343 i = flip[ child ][ orientation ][ i ];
344 return coords[ child ][ i ];
provides a wrapper for ALBERTA's el_info structure
decltype(auto) apply(F &&f, ArgTuple &&args)
Apply function with arguments given as tuple.
Definition: apply.hh:58
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition: hybridutilities.hh:308
Dune namespace.
Definition: alignedallocator.hh:10