5 #ifndef DUNE_ALBERTAGRIDINDEXSETS_HH
6 #define DUNE_ALBERTAGRIDINDEXSETS_HH
11 #include <dune/common/hybridutilities.hh>
18 #include <dune/grid/albertagrid/misc.hh>
19 #include <dune/grid/albertagrid/dofadmin.hh>
20 #include <dune/grid/albertagrid/dofvector.hh>
39 template<
int dim,
int dimworld >
40 class AlbertaGridHierarchicIndexSet
41 :
public IndexSet< AlbertaGridFamily< dim, dimworld >, AlbertaGridHierarchicIndexSet< dim,dimworld >, int, std::array< GeometryType, 1 > >
43 typedef AlbertaGridHierarchicIndexSet< dim, dimworld > This;
44 typedef IndexSet< AlbertaGridFamily< dim, dimworld >, AlbertaGridHierarchicIndexSet< dim,dimworld >, int, std::array< GeometryType, 1 > > Base;
46 friend class AlbertaGrid< dim, dimworld >;
49 typedef AlbertaGrid< dim, dimworld > Grid;
50 typedef AlbertaGridFamily< dim, dimworld > GridFamily;
56 static const int dimension = GridFamily::dimension;
58 typedef Alberta::ElementInfo< dimension > ElementInfo;
59 typedef Alberta::HierarchyDofNumbering< dimension > DofNumbering;
62 typedef typename GridFamily::Traits Traits;
64 typedef Alberta::DofVectorPointer< IndexType > IndexVectorPointer;
66 class InitEntityNumber;
69 struct CreateEntityNumbers;
72 struct RefineNumbering;
75 struct CoarsenNumbering;
77 explicit AlbertaGridHierarchicIndexSet (
const DofNumbering &dofNumbering );
79 static Alberta::IndexStack *currentIndexStack;
82 typedef Alberta::IndexStack IndexStack;
85 template<
class Entity >
86 bool contains (
const Entity & )
const
96 IndexType
index (
const typename Traits::template Codim< cc >::Entity &entity )
const
98 typedef AlbertaGridEntity< cc, dim, const Grid > EntityImp;
99 const EntityImp &entityImp = entity.impl();
100 return subIndex( entityImp.elementInfo(), entityImp.subEntity(), cc );
105 IndexType
subIndex (
const typename Traits::template Codim< cc >::Entity &entity,
int i,
unsigned int codim )
const
107 typedef AlbertaGridEntity< cc, dim, const Grid > EntityImp;
108 const EntityImp &entityImp = entity.impl();
114 k = refElement.subEntity( entityImp.subEntity(), cc, i, codim );
117 const int j = entityImp.grid().generic2alberta( codim, k );
118 return subIndex( entityImp.elementInfo(), j, codim );
122 std::size_t
size (
const GeometryType &type )
const
124 return (type.isSimplex() ?
size( dimension - type.dim() ) : 0);
128 std::size_t
size (
int codim )
const
130 assert( (codim >= 0) && (codim <= dimension) );
131 return indexStack_[ codim ].size();
134 Types types (
int codim )
const
136 assert( (codim >= 0) && (codim <= dimension) );
141 const std::vector< GeometryType > &geomTypes(
int codim )
const
143 assert( (codim >= 0) && (codim <= dimension) );
144 return geomTypes_[ codim ];
147 IndexType
subIndex (
const ElementInfo &elementInfo,
int i,
unsigned int codim )
const
149 assert( !elementInfo ==
false );
150 return subIndex( elementInfo.element(), i, codim );
159 IndexType
subIndex (
const Alberta::Element *element,
int i,
unsigned int codim )
const
161 IndexType *array = (IndexType *)entityNumbers_[ codim ];
162 const IndexType
subIndex = array[ dofNumbering_( element, codim, i ) ];
163 assert( (subIndex >= 0) && (subIndex < IndexType(
size( codim ))) );
170 if( !IndexVectorPointer::supportsAdaptationData )
172 assert( currentIndexStack ==
nullptr );
173 currentIndexStack = indexStack_;
180 if( !IndexVectorPointer::supportsAdaptationData )
181 currentIndexStack =
nullptr;
185 void read (
const std::string &filename );
186 bool write (
const std::string &filename )
const;
190 for(
int i = 0; i <= dimension; ++i )
191 entityNumbers_[ i ].release();
195 template<
int codim >
196 static IndexStack &getIndexStack (
const IndexVectorPointer &dofVector )
198 IndexStack *indexStack;
199 if( IndexVectorPointer::supportsAdaptationData )
200 indexStack = dofVector.template getAdaptationData< IndexStack >();
202 indexStack = ¤tIndexStack[ codim ];
203 assert( indexStack != 0 );
208 const DofNumbering &dofNumbering_;
211 IndexStack indexStack_[ dimension+1 ];
214 IndexVectorPointer entityNumbers_[ dimension+1 ];
217 std::vector< GeometryType > geomTypes_[ dimension+1 ];
225 template<
int dim,
int dimworld >
226 class AlbertaGridHierarchicIndexSet< dim, dimworld >::InitEntityNumber
228 IndexStack &indexStack_;
231 InitEntityNumber ( IndexStack &indexStack )
232 : indexStack_( indexStack )
235 void operator() (
int &dof )
237 dof = indexStack_.getIndex();
246 template<
int dim,
int dimworld >
247 template<
int codim >
248 struct AlbertaGridHierarchicIndexSet< dim, dimworld >::CreateEntityNumbers
250 static void setup ( AlbertaGridHierarchicIndexSet< dim, dimworld > &indexSet );
252 static void apply (
const Alberta::HierarchyDofNumbering< dimension > &dofNumbering,
253 AlbertaGridHierarchicIndexSet< dim, dimworld > &indexSet );
255 static void apply (
const std::string &filename,
256 const Alberta::MeshPointer< dimension > &mesh,
257 AlbertaGridHierarchicIndexSet< dim, dimworld > &indexSet );
265 template<
int dim,
int dimworld >
266 template<
int codim >
267 struct AlbertaGridHierarchicIndexSet< dim, dimworld >::RefineNumbering
269 static const int dimension = dim;
270 static const int codimension = codim;
273 typedef Alberta::DofAccess< dimension, codimension > DofAccess;
275 explicit RefineNumbering (
const IndexVectorPointer &dofVector )
276 : indexStack_( getIndexStack< codimension >( dofVector ) ),
277 dofVector_( dofVector ),
278 dofAccess_( dofVector.dofSpace() )
282 void operator() (
const Alberta::Element *
child,
int subEntity );
284 typedef Alberta::Patch< dimension > Patch;
285 static void interpolateVector (
const IndexVectorPointer &dofVector,
286 const Patch &patch );
289 IndexStack &indexStack_;
290 IndexVectorPointer dofVector_;
291 DofAccess dofAccess_;
299 template<
int dim,
int dimworld >
300 template<
int codim >
301 struct AlbertaGridHierarchicIndexSet< dim, dimworld >::CoarsenNumbering
303 static const int dimension = dim;
304 static const int codimension = codim;
307 typedef Alberta::DofAccess< dimension, codimension > DofAccess;
309 explicit CoarsenNumbering (
const IndexVectorPointer &dofVector )
310 : indexStack_( getIndexStack< codimension >( dofVector ) ),
311 dofVector_( dofVector ),
312 dofAccess_( dofVector.dofSpace() )
316 void operator() (
const Alberta::Element *
child,
int subEntity );
318 typedef Alberta::Patch< dimension > Patch;
319 static void restrictVector (
const IndexVectorPointer &dofVector,
320 const Patch &patch );
322 IndexStack &indexStack_;
323 IndexVectorPointer dofVector_;
324 DofAccess dofAccess_;
332 template<
int dim,
int dimworld >
333 class AlbertaGridIndexSet
334 :
public IndexSet< AlbertaGrid< dim, dimworld >, AlbertaGridIndexSet< dim, dimworld >, int, std::array< GeometryType, 1 > >
336 typedef AlbertaGridIndexSet< dim, dimworld > This;
337 typedef IndexSet< AlbertaGrid< dim, dimworld >, AlbertaGridIndexSet< dim, dimworld >, int, std::array< GeometryType, 1 > > Base;
340 typedef AlbertaGrid< dim, dimworld > Grid;
346 static const int dimension = Grid::dimension;
348 typedef Alberta::ElementInfo< dimension > ElementInfo;
349 typedef Alberta::HierarchyDofNumbering< dimension > DofNumbering;
352 typedef typename Grid::Traits Traits;
354 template<
int codim >
358 explicit AlbertaGridIndexSet (
const DofNumbering &dofNumbering )
359 : dofNumbering_( dofNumbering )
361 for(
int codim = 0; codim <= dimension; ++codim )
363 indices_[ codim ] = 0;
368 ~AlbertaGridIndexSet ()
370 for(
int codim = 0; codim <= dimension; ++codim )
371 delete[] indices_[ codim ];
374 template<
class Entity >
375 bool contains (
const Entity &entity )
const
379 const AlbertaGridEntity< codim, dim, const Grid > &entityImp
381 const Alberta::Element *element = entityImp.elementInfo().el();
383 const IndexType *
const array = indices_[ codim ];
384 const IndexType subIndex = array[ dofNumbering_( element, codim, entityImp.subEntity() ) ];
386 return (subIndex >= 0);
394 IndexType
index (
const typename Traits::template Codim< cc >::Entity &entity )
const
396 typedef AlbertaGridEntity< cc, dim, const Grid > EntityImp;
397 const EntityImp &entityImp = entity.impl();
398 return subIndex( entityImp.elementInfo(), entityImp.subEntity(), cc );
403 IndexType subIndex (
const typename Traits::template Codim< cc >::Entity &entity,
int i,
unsigned int codim )
const
405 typedef AlbertaGridEntity< cc, dim, const Grid > EntityImp;
406 const EntityImp &entityImp = entity.impl();
412 k = refElement.subEntity( entityImp.subEntity(), cc, i, codim );
415 const int j = entityImp.grid().generic2alberta( codim, k );
416 return subIndex( entityImp.elementInfo(), j, codim );
419 std::size_t
size (
const GeometryType &type )
const
421 return (type.isSimplex() ?
size( dimension - type.dim() ) : 0);
424 std::size_t
size (
int codim )
const
426 assert( (codim >= 0) && (codim <= dimension) );
427 return size_[ codim ];
430 Types types (
int codim )
const
432 assert( (codim >= 0) && (codim <= dimension) );
436 const std::vector< GeometryType > &geomTypes(
int codim )
const
438 assert( (codim >= 0) && (codim <= dimension) );
439 return geomTypes_[ codim ];
442 template<
class Iterator >
443 void update (
const Iterator &begin,
const Iterator &end )
445 for(
int codim = 0; codim <= dimension; ++codim )
447 delete[] indices_[ codim ];
449 const unsigned int dofSize = dofNumbering_.size( codim );
450 indices_[ codim ] =
new IndexType[ dofSize ];
451 for(
unsigned int i = 0; i < dofSize; ++i )
452 indices_[ codim ][ i ] = -1;
457 for( Iterator it = begin; it != end; ++it )
459 const AlbertaGridEntity< 0, dim, const Grid > &entityImp
461 const Alberta::Element *element = entityImp.elementInfo().el();
463 [ & ](
auto i ){ Insert< i >::apply( element, *
this ); } );
468 IndexType subIndex (
const ElementInfo &elementInfo,
int i,
unsigned int codim )
const
470 assert( !elementInfo ==
false );
471 return subIndex( elementInfo.element(), i, codim );
480 IndexType subIndex (
const Alberta::Element *element,
int i,
unsigned int codim )
const
482 const IndexType *
const array = indices_[ codim ];
483 const IndexType subIndex = array[ dofNumbering_( element, codim, i ) ];
484 assert( (subIndex >= 0) && (
static_cast<unsigned int>(subIndex) <
size( codim )) );
489 const DofNumbering &dofNumbering_;
492 IndexType *indices_[ dimension+1 ];
495 IndexType size_[ dimension+1 ];
498 std::vector< GeometryType > geomTypes_[ dimension+1 ];
506 template<
int dim,
int dimworld >
507 template<
int codim >
508 struct AlbertaGridIndexSet< dim, dimworld >::Insert
510 static void apply (
const Alberta::Element *
const element,
511 AlbertaGridIndexSet< dim, dimworld > &indexSet )
513 int *
const array = indexSet.indices_[ codim ];
514 IndexType &
size = indexSet.size_[ codim ];
516 for(
int i = 0; i < Alberta::NumSubEntities< dim, codim >::value; ++i )
518 int &
index = array[ indexSet.dofNumbering_( element, codim, i ) ];
531 template<
int dim,
int dimworld >
533 :
public IdSet< AlbertaGrid< dim, dimworld >, AlbertaGridIdSet< dim, dimworld >, unsigned int >
547 static const int dimension = Grid::dimension;
553 : hIndexSet_( hIndexSet )
558 template<
class Entity >
562 return id< codim >( e );
566 template<
int codim >
569 assert( (codim >= 0) && (codim <= dimension) );
570 const IdType index = hIndexSet_.index( e );
571 return (index << 2) |
IdType( codim );
577 assert(
int( subcodim ) <= dimension );
578 const IdType index = hIndexSet_.subIndex( e, i, subcodim );
579 return (index << 2) |
IdType( subcodim );
582 template<
int codim >
585 assert( (codim >= 0) && (codim <= dimension) && (
int( codim + subcodim ) <= dimension) );
586 const IdType index = hIndexSet_.subIndex( e, i, subcodim );
587 return (index << 2) |
IdType( codim + subcodim );
590 template<
class Entity >
591 IdType subId (
const Entity &e,
int i,
unsigned int subcodim )
const
593 return subId< Entity::codimension >( e, i, subcodim );
598 AlbertaGridIdSet (
const This & );
600 const HierarchicIndexSet &hIndexSet_;
provides the GridFamily for AlbertaGrid
hierarchic index set of AlbertaGrid
Definition: indexsets.hh:534
IdType id(const typename Grid::template Codim< codim >::Entity &e) const
Definition: indexsets.hh:567
IdType id(const Entity &e) const
Definition: indexsets.hh:559
Base::IdType IdType
export type of id
Definition: indexsets.hh:542
IdType subId(const typename Grid::template Codim< 0 >::Entity &e, int i, unsigned int subcodim) const
Definition: indexsets.hh:575
[ provides Dune::Grid ]
Definition: agrid.hh:109
Traits::HierarchicIndexSet HierarchicIndexSet
type of hierarchic index set
Definition: agrid.hh:157
Wrapper class for entities.
Definition: entity.hh:66
constexpr static int codimension
Know your own codimension.
Definition: entity.hh:106
Id Set Interface.
Definition: indexidset.hh:452
IdTypeImp IdType
Type used to represent an id.
Definition: indexidset.hh:458
auto size(GeometryType type) const
Return total number of entities of given geometry type in entity set .
Definition: indexidset.hh:223
IndexType subIndex(const Entity &e, int i, unsigned int codim) const
Map a subentity to an index.
Definition: indexidset.hh:182
IndexType subIndex(const typename Traits::template Codim< cc >::Entity &e, int i, unsigned int codim) const
Map a subentity to an index.
Definition: indexidset.hh:153
std::array< GeometryType, 1 > Types
iterator range for geometry types in domain
Definition: indexidset.hh:95
IndexType index(const typename Traits::template Codim< cc >::Entity &e) const
Map entity to index. The result of calling this method with an entity that is not in the index set is...
Definition: indexidset.hh:113
int IndexType
The type used for the indices.
Definition: indexidset.hh:92
IndexType index(const Entity &e) const
Map entity to index. Easier to use than the above because codimension template parameter need not be ...
Definition: indexidset.hh:129
Definition: indexstack.hh:26
Different resources needed by all grid implementations.
provides a wrapper for ALBERTA's el_info structure
constexpr GeometryType simplex(unsigned int dim)
Returns a GeometryType representing a simplex of dimension dim.
Definition: type.hh:463
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition: hybridutilities.hh:268
Provides base classes for index and id sets.
Provides an index stack that supplies indices for element numbering for a grid (i....
Dune namespace.
Definition: alignedallocator.hh:13
Standard Dune debug streams.
Static tag representing a codimension.
Definition: dimension.hh:24
static const ReferenceElement & simplex()
get simplex reference elements
Definition: referenceelements.hh:204