3#ifndef DUNE_ALBERTAGRIDINDEXSETS_HH
4#define DUNE_ALBERTAGRIDINDEXSETS_HH
9#include <dune/common/hybridutilities.hh>
10#include <dune/common/stdstreams.hh>
37 template<
int dim,
int dimworld >
39 :
public IndexSet< AlbertaGridFamily< dim, dimworld >, AlbertaGridHierarchicIndexSet< dim,dimworld >, int, std::array< GeometryType, 1 > >
67 struct CreateEntityNumbers;
70 struct RefineNumbering;
73 struct CoarsenNumbering;
83 template<
class Entity >
94 IndexType index (
const typename Traits::template Codim< cc >::Entity &entity )
const
97 const EntityImp &entityImp = entity.impl();
98 return subIndex( entityImp.elementInfo(), entityImp.subEntity(), cc );
103 IndexType subIndex (
const typename Traits::template Codim< cc >::Entity &entity,
int i,
unsigned int codim )
const
106 const EntityImp &entityImp = entity.impl();
111 auto refElement = ReferenceElements< Alberta::Real, dimension >::simplex();
112 k = refElement.subEntity( entityImp.subEntity(), cc, i, codim );
115 const int j = entityImp.grid().generic2alberta( codim, k );
116 return subIndex( entityImp.elementInfo(), j, codim );
120 std::size_t
size (
const GeometryType &type )
const
122 return (type.isSimplex() ?
size(
dimension - type.dim() ) : 0);
126 std::size_t
size (
int codim )
const
128 assert( (codim >= 0) && (codim <=
dimension) );
129 return indexStack_[ codim ].
size();
134 assert( (codim >= 0) && (codim <=
dimension) );
135 return {{ GeometryTypes::simplex(
dimension - codim ) }};
139 const std::vector< GeometryType > &
geomTypes(
int codim )
const
141 assert( (codim >= 0) && (codim <=
dimension) );
142 return geomTypes_[ codim ];
147 assert( !elementInfo ==
false );
170 assert( currentIndexStack ==
nullptr );
171 currentIndexStack = indexStack_;
179 currentIndexStack =
nullptr;
183 void read (
const std::string &filename );
184 bool write (
const std::string &filename )
const;
193 template<
int codim >
194 static IndexStack &getIndexStack (
const IndexVectorPointer &dofVector )
198 indexStack = dofVector.template getAdaptationData< IndexStack >();
200 indexStack = ¤tIndexStack[ codim ];
201 assert( indexStack != 0 );
212 IndexVectorPointer entityNumbers_[
dimension+1 ];
215 std::vector< GeometryType > geomTypes_[
dimension+1 ];
223 template<
int dim,
int dimworld >
230 : indexStack_( indexStack )
233 void operator() (
int &dof )
235 dof = indexStack_.getIndex();
244 template<
int dim,
int dimworld >
245 template<
int codim >
253 static void apply (
const std::string &filename,
263 template<
int dim,
int dimworld >
264 template<
int codim >
265 struct AlbertaGridHierarchicIndexSet< dim, dimworld >::RefineNumbering
268 static const int codimension = codim;
271 typedef Alberta::DofAccess< dimension, codimension > DofAccess;
273 explicit RefineNumbering (
const IndexVectorPointer &dofVector )
274 : indexStack_( getIndexStack< codimension >( dofVector ) ),
275 dofVector_( dofVector ),
276 dofAccess_( dofVector.dofSpace() )
282 typedef Alberta::Patch< dimension > Patch;
283 static void interpolateVector (
const IndexVectorPointer &dofVector,
284 const Patch &patch );
288 IndexVectorPointer dofVector_;
289 DofAccess dofAccess_;
297 template<
int dim,
int dimworld >
298 template<
int codim >
299 struct AlbertaGridHierarchicIndexSet< dim, dimworld >::CoarsenNumbering
302 static const int codimension = codim;
305 typedef Alberta::DofAccess< dimension, codimension > DofAccess;
307 explicit CoarsenNumbering (
const IndexVectorPointer &dofVector )
308 : indexStack_( getIndexStack< codimension >( dofVector ) ),
309 dofVector_( dofVector ),
310 dofAccess_( dofVector.dofSpace() )
316 typedef Alberta::Patch< dimension > Patch;
317 static void restrictVector (
const IndexVectorPointer &dofVector,
318 const Patch &patch );
321 IndexVectorPointer dofVector_;
322 DofAccess dofAccess_;
330 template<
int dim,
int dimworld >
332 :
public IndexSet< AlbertaGrid< dim, dimworld >, AlbertaGridIndexSet< dim, dimworld >, int, std::array< GeometryType, 1 > >
352 template<
int codim >
357 : dofNumbering_( dofNumbering )
359 for(
int codim = 0; codim <=
dimension; ++codim )
361 indices_[ codim ] = 0;
362 geomTypes_[ codim ].push_back( GeometryTypes::simplex(
dimension - codim ) );
368 for(
int codim = 0; codim <=
dimension; ++codim )
369 delete[] indices_[ codim ];
372 template<
class Entity >
381 const IndexType *
const array = indices_[ codim ];
392 IndexType index (
const typename Traits::template Codim< cc >::Entity &entity )
const
395 const EntityImp &entityImp = entity.impl();
396 return subIndex( entityImp.elementInfo(), entityImp.subEntity(), cc );
401 IndexType subIndex (
const typename Traits::template Codim< cc >::Entity &entity,
int i,
unsigned int codim )
const
404 const EntityImp &entityImp = entity.impl();
409 auto refElement = ReferenceElements< Alberta::Real, dimension >::simplex();
410 k = refElement.subEntity( entityImp.subEntity(), cc, i, codim );
413 const int j = entityImp.grid().generic2alberta( codim, k );
414 return subIndex( entityImp.elementInfo(), j, codim );
417 std::size_t
size (
const GeometryType &type )
const
419 return (type.isSimplex() ?
size(
dimension - type.dim() ) : 0);
422 std::size_t
size (
int codim )
const
424 assert( (codim >= 0) && (codim <=
dimension) );
425 return size_[ codim ];
430 assert( (codim >= 0) && (codim <=
dimension) );
431 return {{ GeometryTypes::simplex(
dimension - codim ) }};
434 const std::vector< GeometryType > &
geomTypes(
int codim )
const
436 assert( (codim >= 0) && (codim <=
dimension) );
437 return geomTypes_[ codim ];
440 template<
class Iterator >
441 void update (
const Iterator &begin,
const Iterator &end )
443 for(
int codim = 0; codim <=
dimension; ++codim )
445 delete[] indices_[ codim ];
447 const unsigned int dofSize = dofNumbering_.
size( codim );
448 indices_[ codim ] =
new IndexType[ dofSize ];
449 for(
unsigned int i = 0; i < dofSize; ++i )
450 indices_[ codim ][ i ] = -1;
455 for( Iterator it = begin; it != end; ++it )
460 Hybrid::forEach( std::make_index_sequence< dimension+1 >{},
461 [ & ](
auto i ){ Insert< i >::apply( element, *
this ); } );
468 assert( !elementInfo ==
false );
469 return subIndex( elementInfo.element(), i, codim );
480 const IndexType *
const array = indices_[ codim ];
496 std::vector< GeometryType > geomTypes_[
dimension+1 ];
504 template<
int dim,
int dimworld >
505 template<
int codim >
506 struct AlbertaGridIndexSet< dim, dimworld >::Insert
509 AlbertaGridIndexSet< dim, dimworld > &indexSet )
511 int *
const array = indexSet.indices_[ codim ];
514 for(
int i = 0; i < Alberta::NumSubEntities< dim, codim >::value; ++i )
516 int &
index = array[ indexSet.dofNumbering_( element, codim, i ) ];
529 template<
int dim,
int dimworld >
531 :
public IdSet< AlbertaGrid< dim, dimworld >, AlbertaGridIdSet< dim, dimworld >, unsigned int >
551 : hIndexSet_( hIndexSet )
556 template<
class Entity >
560 return id< codim >( e );
564 template<
int codim >
565 IdType id (
const typename Grid::template Codim< codim >::Entity &e )
const
567 assert( (codim >= 0) && (codim <= dimension) );
569 return (index << 2) |
IdType( codim );
573 IdType subId (
const typename Grid::template Codim< 0 >::Entity &e,
int i,
unsigned int subcodim )
const
575 assert(
int( subcodim ) <= dimension );
577 return (index << 2) |
IdType( subcodim );
580 template<
int codim >
581 IdType subId (
const typename Grid::template Codim< codim >::Entity &e,
int i,
unsigned int subcodim )
const
583 assert( (codim >= 0) && (codim <= dimension) && (
int( codim + subcodim ) <= dimension) );
585 return (index << 2) |
IdType( codim + subcodim );
588 template<
class Entity >
591 return subId< Entity::codimension >( e, i, subcodim );
598 const HierarchicIndexSet &hIndexSet_;
Provides base classes for index and id sets.
Provides an index stack that supplies indices for element numbering for a grid (i....
provides a wrapper for ALBERTA's el_info structure
Include standard header files.
Definition: agrid.hh:58
Dune::IndexStack< int, 100000 > IndexStack
Definition: albertagrid/indexsets.hh:29
ALBERTA EL Element
Definition: misc.hh:52
[ provides Dune::Grid ]
Definition: agrid.hh:107
static const int dimension
Definition: agrid.hh:143
int size(int codim) const
Definition: dofadmin.hh:161
static const bool supportsAdaptationData
Definition: dofvector.hh:185
Element * el() const
Definition: elementinfo.hh:735
const Element * element() const
Definition: elementinfo.hh:719
Definition: albertagrid/entity.hh:44
const ElementInfo & elementInfo() const
Definition: albertagrid/entity.hh:128
int subEntity() const
obtain number of the subentity within the element (in ALBERTA numbering)
Definition: albertagrid/entity.hh:146
Definition: albertagrid/indexsets.hh:40
IndexType subIndex(const typename Traits::template Codim< cc >::Entity &entity, int i, unsigned int codim) const
return subIndex of given enitiy's sub entity
Definition: albertagrid/indexsets.hh:103
Base::IndexType IndexType
Definition: albertagrid/indexsets.hh:50
void read(const std::string &filename)
Definition: indexsets.cc:146
void release()
Definition: albertagrid/indexsets.hh:186
const std::vector< GeometryType > & geomTypes(int codim) const
return geometry types this set has indices for
Definition: albertagrid/indexsets.hh:139
Alberta::IndexStack IndexStack
Definition: albertagrid/indexsets.hh:80
AlbertaGrid< dim, dimworld > Grid
Definition: albertagrid/indexsets.hh:47
IndexType index(const typename Traits::template Codim< cc >::Entity &entity) const
return hierarchic index of given entity
Definition: albertagrid/indexsets.hh:94
std::size_t size(const GeometryType &type) const
return size of set for given GeometryType
Definition: albertagrid/indexsets.hh:120
bool contains(const Entity &) const
return true if entity is contained in set
Definition: albertagrid/indexsets.hh:84
IndexType subIndex(const Alberta::Element *element, int i, unsigned int codim) const
obtain hierarchic subindex
Definition: albertagrid/indexsets.hh:157
void create()
Definition: indexsets.cc:138
Base::Types Types
Definition: albertagrid/indexsets.hh:52
bool write(const std::string &filename) const
Definition: indexsets.cc:154
Alberta::ElementInfo< dimension > ElementInfo
Definition: albertagrid/indexsets.hh:56
void postAdapt()
Definition: albertagrid/indexsets.hh:175
IndexType subIndex(const ElementInfo &elementInfo, int i, unsigned int codim) const
Definition: albertagrid/indexsets.hh:145
Alberta::HierarchyDofNumbering< dimension > DofNumbering
Definition: albertagrid/indexsets.hh:57
Types types(int codim) const
Definition: albertagrid/indexsets.hh:132
std::size_t size(int codim) const
return size of set
Definition: albertagrid/indexsets.hh:126
AlbertaGridFamily< dim, dimworld > GridFamily
Definition: albertagrid/indexsets.hh:48
static const int dimension
Definition: albertagrid/indexsets.hh:54
void preAdapt()
Definition: albertagrid/indexsets.hh:165
hierarchic index set of AlbertaGrid
Definition: albertagrid/indexsets.hh:532
IdType id(const typename Grid::template Codim< codim >::Entity &e) const
Definition: albertagrid/indexsets.hh:565
IdType id(const Entity &e) const
Definition: albertagrid/indexsets.hh:557
Base::IdType IdType
export type of id
Definition: albertagrid/indexsets.hh:540
IdType subId(const typename Grid::template Codim< 0 >::Entity &e, int i, unsigned int subcodim) const
Definition: albertagrid/indexsets.hh:573
IdType subId(const typename Grid::template Codim< codim >::Entity &e, int i, unsigned int subcodim) const
Definition: albertagrid/indexsets.hh:581
IdType subId(const Entity &e, int i, unsigned int subcodim) const
Definition: albertagrid/indexsets.hh:589
Definition: albertagrid/indexsets.hh:333
Base::Types Types
Definition: albertagrid/indexsets.hh:342
Alberta::ElementInfo< dimension > ElementInfo
Definition: albertagrid/indexsets.hh:346
IndexType index(const typename Traits::template Codim< cc >::Entity &entity) const
return hierarchic index of given entity
Definition: albertagrid/indexsets.hh:392
AlbertaGridIndexSet(const DofNumbering &dofNumbering)
Definition: albertagrid/indexsets.hh:356
Alberta::HierarchyDofNumbering< dimension > DofNumbering
Definition: albertagrid/indexsets.hh:347
bool contains(const Entity &entity) const
Definition: albertagrid/indexsets.hh:373
const std::vector< GeometryType > & geomTypes(int codim) const
Definition: albertagrid/indexsets.hh:434
IndexType subIndex(const typename Traits::template Codim< cc >::Entity &entity, int i, unsigned int codim) const
return subIndex of given enitiy's sub entity
Definition: albertagrid/indexsets.hh:401
Base::IndexType IndexType
Definition: albertagrid/indexsets.hh:340
Types types(int codim) const
Definition: albertagrid/indexsets.hh:428
~AlbertaGridIndexSet()
Definition: albertagrid/indexsets.hh:366
std::size_t size(int codim) const
Definition: albertagrid/indexsets.hh:422
std::size_t size(const GeometryType &type) const
Definition: albertagrid/indexsets.hh:417
void update(const Iterator &begin, const Iterator &end)
Definition: albertagrid/indexsets.hh:441
static const int dimension
Definition: albertagrid/indexsets.hh:344
AlbertaGrid< dim, dimworld > Grid
Definition: albertagrid/indexsets.hh:338
Definition: albertagrid/gridfamily.hh:81
static const int dimension
Definition: albertagrid/gridfamily.hh:86
Definition: albertagrid/gridfamily.hh:96
Definition: albertagrid/indexsets.hh:225
InitEntityNumber(IndexStack &indexStack)
Definition: albertagrid/indexsets.hh:229
Definition: indexstack.hh:24
int size() const
return maxIndex which is also the
Definition: indexstack.hh:77
Wrapper class for entities.
Definition: common/entity.hh:64
@ codimension
Know your own codimension.
Definition: common/entity.hh:105
Implementation & impl()
access to the underlying implementation
Definition: common/entity.hh:78
Index Set Interface base class.
Definition: indexidset.hh:76
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:151
std::array< GeometryType, 1 > Types
iterator range for geometry types in domain
Definition: indexidset.hh:93
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:111
int IndexType
The type used for the indices.
Definition: indexidset.hh:90
Id Set Interface.
Definition: indexidset.hh:450
IdTypeImp IdType
Type used to represent an id.
Definition: indexidset.hh:456
provides the GridFamily for AlbertaGrid
Different resources needed by all grid implementations.