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 >;
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 ];
220 template<
int dim,
int dimworld >
221 Alberta::IndexStack* AlbertaGridHierarchicIndexSet<dim,dimworld>::currentIndexStack =
nullptr;
228 template<
int dim,
int dimworld >
229 class AlbertaGridHierarchicIndexSet< dim, dimworld >::InitEntityNumber
231 IndexStack &indexStack_;
234 InitEntityNumber ( IndexStack &indexStack )
235 : indexStack_( indexStack )
238 void operator() (
int &dof )
240 dof = indexStack_.getIndex();
249 template<
int dim,
int dimworld >
250 template<
int codim >
251 struct AlbertaGridHierarchicIndexSet< dim, dimworld >::CreateEntityNumbers
253 static void setup ( AlbertaGridHierarchicIndexSet< dim, dimworld > &indexSet );
255 static void apply (
const Alberta::HierarchyDofNumbering< dimension > &dofNumbering,
256 AlbertaGridHierarchicIndexSet< dim, dimworld > &indexSet );
258 static void apply (
const std::string &filename,
259 const Alberta::MeshPointer< dimension > &mesh,
260 AlbertaGridHierarchicIndexSet< dim, dimworld > &indexSet );
268 template<
int dim,
int dimworld >
269 template<
int codim >
270 struct AlbertaGridHierarchicIndexSet< dim, dimworld >::RefineNumbering
272 static const int dimension = dim;
273 static const int codimension = codim;
276 typedef Alberta::DofAccess< dimension, codimension > DofAccess;
278 explicit RefineNumbering (
const IndexVectorPointer &dofVector )
279 : indexStack_( getIndexStack< codimension >( dofVector ) ),
280 dofVector_( dofVector ),
281 dofAccess_( dofVector.dofSpace() )
285 void operator() (
const Alberta::Element *child,
int subEntity );
287 typedef Alberta::Patch< dimension > Patch;
288 static void interpolateVector (
const IndexVectorPointer &dofVector,
289 const Patch &patch );
292 IndexStack &indexStack_;
293 IndexVectorPointer dofVector_;
294 DofAccess dofAccess_;
302 template<
int dim,
int dimworld >
303 template<
int codim >
304 struct AlbertaGridHierarchicIndexSet< dim, dimworld >::CoarsenNumbering
306 static const int dimension = dim;
307 static const int codimension = codim;
310 typedef Alberta::DofAccess< dimension, codimension > DofAccess;
312 explicit CoarsenNumbering (
const IndexVectorPointer &dofVector )
313 : indexStack_( getIndexStack< codimension >( dofVector ) ),
314 dofVector_( dofVector ),
315 dofAccess_( dofVector.dofSpace() )
319 void operator() (
const Alberta::Element *child,
int subEntity );
321 typedef Alberta::Patch< dimension > Patch;
322 static void restrictVector (
const IndexVectorPointer &dofVector,
323 const Patch &patch );
325 IndexStack &indexStack_;
326 IndexVectorPointer dofVector_;
327 DofAccess dofAccess_;
335 template<
int dim,
int dimworld >
336 class AlbertaGridIndexSet
337 :
public IndexSet< AlbertaGrid< dim, dimworld >, AlbertaGridIndexSet< dim, dimworld >, int, std::array< GeometryType, 1 > >
339 typedef AlbertaGridIndexSet< dim, dimworld > This;
340 typedef IndexSet< AlbertaGrid< dim, dimworld >, AlbertaGridIndexSet< dim, dimworld >, int, std::array< GeometryType, 1 > > Base;
349 static const int dimension = Grid::dimension;
351 typedef Alberta::ElementInfo< dimension > ElementInfo;
352 typedef Alberta::HierarchyDofNumbering< dimension > DofNumbering;
355 typedef typename Grid::Traits Traits;
357 template<
int codim >
361 explicit AlbertaGridIndexSet (
const DofNumbering &dofNumbering )
362 : dofNumbering_( dofNumbering )
364 for(
int codim = 0; codim <= dimension; ++codim )
366 indices_[ codim ] = 0;
371 ~AlbertaGridIndexSet ()
373 for(
int codim = 0; codim <= dimension; ++codim )
374 delete[] indices_[ codim ];
377 template<
class Entity >
378 bool contains (
const Entity &entity )
const
382 const AlbertaGridEntity< codim, dim, const Grid > &entityImp
384 const Alberta::Element *element = entityImp.elementInfo().el();
386 const IndexType *
const array = indices_[ codim ];
387 const IndexType subIndex = array[ dofNumbering_( element, codim, entityImp.subEntity() ) ];
389 return (subIndex >= 0);
397 IndexType
index (
const typename Traits::template Codim< cc >::Entity &entity )
const
399 typedef AlbertaGridEntity< cc, dim, const Grid > EntityImp;
400 const EntityImp &entityImp = entity.impl();
401 return subIndex( entityImp.elementInfo(), entityImp.subEntity(), cc );
406 IndexType subIndex (
const typename Traits::template Codim< cc >::Entity &entity,
int i,
unsigned int codim )
const
408 typedef AlbertaGridEntity< cc, dim, const Grid > EntityImp;
409 const EntityImp &entityImp = entity.impl();
415 k = refElement.subEntity( entityImp.subEntity(), cc, i, codim );
418 const int j = entityImp.grid().generic2alberta( codim, k );
419 return subIndex( entityImp.elementInfo(), j, codim );
422 std::size_t
size (
const GeometryType &type )
const
424 return (type.isSimplex() ?
size( dimension - type.dim() ) : 0);
427 std::size_t
size (
int codim )
const
429 assert( (codim >= 0) && (codim <= dimension) );
430 return size_[ codim ];
433 Types types (
int codim )
const
435 assert( (codim >= 0) && (codim <= dimension) );
439 const std::vector< GeometryType > &geomTypes(
int codim )
const
441 assert( (codim >= 0) && (codim <= dimension) );
442 return geomTypes_[ codim ];
445 template<
class Iterator >
446 void update (
const Iterator &begin,
const Iterator &end )
448 for(
int codim = 0; codim <= dimension; ++codim )
450 delete[] indices_[ codim ];
452 const unsigned int dofSize = dofNumbering_.size( codim );
453 indices_[ codim ] =
new IndexType[ dofSize ];
454 for(
unsigned int i = 0; i < dofSize; ++i )
455 indices_[ codim ][ i ] = -1;
460 for( Iterator it = begin; it != end; ++it )
462 const AlbertaGridEntity< 0, dim, const Grid > &entityImp
464 const Alberta::Element *element = entityImp.elementInfo().el();
466 [ & ](
auto i ){ Insert< i >::apply( element, *
this ); } );
471 IndexType subIndex (
const ElementInfo &elementInfo,
int i,
unsigned int codim )
const
473 assert( !elementInfo ==
false );
474 return subIndex( elementInfo.element(), i, codim );
483 IndexType subIndex (
const Alberta::Element *element,
int i,
unsigned int codim )
const
485 const IndexType *
const array = indices_[ codim ];
486 const IndexType subIndex = array[ dofNumbering_( element, codim, i ) ];
487 assert( (subIndex >= 0) && (
static_cast<unsigned int>(subIndex) <
size( codim )) );
492 const DofNumbering &dofNumbering_;
495 IndexType *indices_[ dimension+1 ];
498 IndexType size_[ dimension+1 ];
501 std::vector< GeometryType > geomTypes_[ dimension+1 ];
509 template<
int dim,
int dimworld >
510 template<
int codim >
511 struct AlbertaGridIndexSet< dim, dimworld >::Insert
513 static void apply (
const Alberta::Element *
const element,
514 AlbertaGridIndexSet< dim, dimworld > &indexSet )
516 int *
const array = indexSet.indices_[ codim ];
517 IndexType &
size = indexSet.size_[ codim ];
519 for(
int i = 0; i < Alberta::NumSubEntities< dim, codim >::value; ++i )
521 int &
index = array[ indexSet.dofNumbering_( element, codim, i ) ];
534 template<
int dim,
int dimworld >
536 :
public IdSet< AlbertaGrid< dim, dimworld >, AlbertaGridIdSet< dim, dimworld >, unsigned int >
550 static const int dimension = Grid::dimension;
556 : hIndexSet_( hIndexSet )
561 template<
class Entity >
565 return id< codim >( e );
569 template<
int codim >
572 assert( (codim >= 0) && (codim <= dimension) );
573 const IdType index = hIndexSet_.index( e );
574 return (index << 2) |
IdType( codim );
580 assert(
int( subcodim ) <= dimension );
581 const IdType index = hIndexSet_.subIndex( e, i, subcodim );
582 return (index << 2) |
IdType( subcodim );
585 template<
int codim >
588 assert( (codim >= 0) && (codim <= dimension) && (
int( codim + subcodim ) <= dimension) );
589 const IdType index = hIndexSet_.subIndex( e, i, subcodim );
590 return (index << 2) |
IdType( codim + subcodim );
593 template<
class Entity >
594 IdType subId (
const Entity &e,
int i,
unsigned int subcodim )
const
596 return subId< Entity::codimension >( e, i, subcodim );
601 AlbertaGridIdSet (
const This & );
603 const HierarchicIndexSet &hIndexSet_;
provides the GridFamily for AlbertaGrid
hierarchic index set of AlbertaGrid
Definition: indexsets.hh:537
IdType id(const typename Grid::template Codim< codim >::Entity &e) const
Definition: indexsets.hh:570
IdType id(const Entity &e) const
Definition: indexsets.hh:562
Base::IdType IdType
export type of id
Definition: indexsets.hh:545
IdType subId(const typename Grid::template Codim< 0 >::Entity &e, int i, unsigned int subcodim) const
Definition: indexsets.hh:578
Traits::HierarchicIndexSet HierarchicIndexSet
type of hierarchic index set
Definition: agrid.hh:157
Wrapper class for entities.
Definition: entity.hh:66
static constexpr 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:464
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