5#ifndef DUNE_ALBERTAGRIDINDEXSETS_HH
6#define DUNE_ALBERTAGRIDINDEXSETS_HH
11#include <dune/common/hybridutilities.hh>
12#include <dune/common/stdstreams.hh>
39 template<
int dim,
int dimworld >
41 :
public IndexSet< AlbertaGridFamily< dim, dimworld >, AlbertaGridHierarchicIndexSet< dim,dimworld >, int, std::array< GeometryType, 1 > >
69 struct CreateEntityNumbers;
72 struct RefineNumbering;
75 struct CoarsenNumbering;
85 template<
class Entity >
96 IndexType index (
const typename Traits::template Codim< cc >::Entity &entity )
const
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
108 const EntityImp &entityImp = entity.impl();
113 auto refElement = ReferenceElements< Alberta::Real, dimension >::simplex();
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 );
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();
136 assert( (codim >= 0) && (codim <=
dimension) );
137 return {{ GeometryTypes::simplex(
dimension - codim ) }};
141 const std::vector< GeometryType > &
geomTypes(
int codim )
const
143 assert( (codim >= 0) && (codim <=
dimension) );
144 return geomTypes_[ codim ];
149 assert( !elementInfo ==
false );
172 assert( currentIndexStack ==
nullptr );
173 currentIndexStack = indexStack_;
181 currentIndexStack =
nullptr;
185 void read (
const std::string &filename );
186 bool write (
const std::string &filename )
const;
195 template<
int codim >
196 static IndexStack &getIndexStack (
const IndexVectorPointer &dofVector )
200 indexStack = dofVector.template getAdaptationData< IndexStack >();
202 indexStack = ¤tIndexStack[ codim ];
203 assert( indexStack != 0 );
214 IndexVectorPointer entityNumbers_[
dimension+1 ];
217 std::vector< GeometryType > geomTypes_[
dimension+1 ];
225 template<
int dim,
int dimworld >
232 : indexStack_( indexStack )
235 void operator() (
int &dof )
237 dof = indexStack_.getIndex();
246 template<
int dim,
int dimworld >
247 template<
int codim >
255 static void apply (
const std::string &filename,
265 template<
int dim,
int dimworld >
266 template<
int codim >
267 struct AlbertaGridHierarchicIndexSet< dim, dimworld >::RefineNumbering
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() )
284 typedef Alberta::Patch< dimension > Patch;
285 static void interpolateVector (
const IndexVectorPointer &dofVector,
286 const Patch &patch );
290 IndexVectorPointer dofVector_;
291 DofAccess dofAccess_;
299 template<
int dim,
int dimworld >
300 template<
int codim >
301 struct AlbertaGridHierarchicIndexSet< dim, dimworld >::CoarsenNumbering
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() )
318 typedef Alberta::Patch< dimension > Patch;
319 static void restrictVector (
const IndexVectorPointer &dofVector,
320 const Patch &patch );
323 IndexVectorPointer dofVector_;
324 DofAccess dofAccess_;
332 template<
int dim,
int dimworld >
334 :
public IndexSet< AlbertaGrid< dim, dimworld >, AlbertaGridIndexSet< dim, dimworld >, int, std::array< GeometryType, 1 > >
354 template<
int codim >
359 : dofNumbering_( dofNumbering )
361 for(
int codim = 0; codim <=
dimension; ++codim )
363 indices_[ codim ] = 0;
364 geomTypes_[ codim ].push_back( GeometryTypes::simplex(
dimension - codim ) );
370 for(
int codim = 0; codim <=
dimension; ++codim )
371 delete[] indices_[ codim ];
374 template<
class Entity >
383 const IndexType *
const array = indices_[ codim ];
394 IndexType index (
const typename Traits::template Codim< cc >::Entity &entity )
const
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
406 const EntityImp &entityImp = entity.impl();
411 auto refElement = ReferenceElements< Alberta::Real, dimension >::simplex();
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 );
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 ];
432 assert( (codim >= 0) && (codim <=
dimension) );
433 return {{ GeometryTypes::simplex(
dimension - codim ) }};
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 )
462 Hybrid::forEach( std::make_index_sequence< dimension+1 >{},
463 [ & ](
auto i ){ Insert< i >::apply( element, *
this ); } );
470 assert( !elementInfo ==
false );
471 return subIndex( elementInfo.element(), i, codim );
482 const IndexType *
const array = indices_[ codim ];
498 std::vector< GeometryType > geomTypes_[
dimension+1 ];
506 template<
int dim,
int dimworld >
507 template<
int codim >
508 struct AlbertaGridIndexSet< dim, dimworld >::Insert
511 AlbertaGridIndexSet< dim, dimworld > &indexSet )
513 int *
const array = indexSet.indices_[ 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 >
553 : hIndexSet_( hIndexSet )
558 template<
class Entity >
562 return id< codim >( e );
566 template<
int codim >
567 IdType id (
const typename Grid::template Codim< codim >::Entity &e )
const
569 assert( (codim >= 0) && (codim <= dimension) );
571 return (index << 2) |
IdType( codim );
575 IdType subId (
const typename Grid::template Codim< 0 >::Entity &e,
int i,
unsigned int subcodim )
const
577 assert(
int( subcodim ) <= dimension );
579 return (index << 2) |
IdType( subcodim );
582 template<
int codim >
583 IdType subId (
const typename Grid::template Codim< codim >::Entity &e,
int i,
unsigned int subcodim )
const
585 assert( (codim >= 0) && (codim <= dimension) && (
int( codim + subcodim ) <= dimension) );
587 return (index << 2) |
IdType( codim + subcodim );
590 template<
class Entity >
593 return subId< Entity::codimension >( e, i, subcodim );
600 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:60
Dune::IndexStack< int, 100000 > IndexStack
Definition: albertagrid/indexsets.hh:31
ALBERTA EL Element
Definition: misc.hh:54
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:132
[ provides Dune::Grid ]
Definition: agrid.hh:109
static const int dimension
Definition: agrid.hh:145
int size(int codim) const
Definition: dofadmin.hh:163
static const bool supportsAdaptationData
Definition: dofvector.hh:187
Element * el() const
Definition: elementinfo.hh:737
const Element * element() const
Definition: elementinfo.hh:721
Definition: albertagrid/entity.hh:46
const ElementInfo & elementInfo() const
Definition: albertagrid/entity.hh:130
int subEntity() const
obtain number of the subentity within the element (in ALBERTA numbering)
Definition: albertagrid/entity.hh:148
Definition: albertagrid/indexsets.hh:42
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:105
Base::IndexType IndexType
Definition: albertagrid/indexsets.hh:52
void read(const std::string &filename)
Definition: indexsets.cc:148
void release()
Definition: albertagrid/indexsets.hh:188
const std::vector< GeometryType > & geomTypes(int codim) const
return geometry types this set has indices for
Definition: albertagrid/indexsets.hh:141
Alberta::IndexStack IndexStack
Definition: albertagrid/indexsets.hh:82
AlbertaGrid< dim, dimworld > Grid
Definition: albertagrid/indexsets.hh:49
IndexType index(const typename Traits::template Codim< cc >::Entity &entity) const
return hierarchic index of given entity
Definition: albertagrid/indexsets.hh:96
std::size_t size(const GeometryType &type) const
return size of set for given GeometryType
Definition: albertagrid/indexsets.hh:122
bool contains(const Entity &) const
return true if entity is contained in set
Definition: albertagrid/indexsets.hh:86
IndexType subIndex(const Alberta::Element *element, int i, unsigned int codim) const
obtain hierarchic subindex
Definition: albertagrid/indexsets.hh:159
void create()
Definition: indexsets.cc:140
Base::Types Types
Definition: albertagrid/indexsets.hh:54
bool write(const std::string &filename) const
Definition: indexsets.cc:156
Alberta::ElementInfo< dimension > ElementInfo
Definition: albertagrid/indexsets.hh:58
void postAdapt()
Definition: albertagrid/indexsets.hh:177
IndexType subIndex(const ElementInfo &elementInfo, int i, unsigned int codim) const
Definition: albertagrid/indexsets.hh:147
Alberta::HierarchyDofNumbering< dimension > DofNumbering
Definition: albertagrid/indexsets.hh:59
Types types(int codim) const
Definition: albertagrid/indexsets.hh:134
std::size_t size(int codim) const
return size of set
Definition: albertagrid/indexsets.hh:128
AlbertaGridFamily< dim, dimworld > GridFamily
Definition: albertagrid/indexsets.hh:50
static const int dimension
Definition: albertagrid/indexsets.hh:56
void preAdapt()
Definition: albertagrid/indexsets.hh:167
hierarchic index set of AlbertaGrid
Definition: albertagrid/indexsets.hh:534
IdType id(const typename Grid::template Codim< codim >::Entity &e) const
Definition: albertagrid/indexsets.hh:567
IdType id(const Entity &e) const
Definition: albertagrid/indexsets.hh:559
Base::IdType IdType
export type of id
Definition: albertagrid/indexsets.hh:542
IdType subId(const typename Grid::template Codim< 0 >::Entity &e, int i, unsigned int subcodim) const
Definition: albertagrid/indexsets.hh:575
IdType subId(const typename Grid::template Codim< codim >::Entity &e, int i, unsigned int subcodim) const
Definition: albertagrid/indexsets.hh:583
IdType subId(const Entity &e, int i, unsigned int subcodim) const
Definition: albertagrid/indexsets.hh:591
Definition: albertagrid/indexsets.hh:335
Base::Types Types
Definition: albertagrid/indexsets.hh:344
Alberta::ElementInfo< dimension > ElementInfo
Definition: albertagrid/indexsets.hh:348
IndexType index(const typename Traits::template Codim< cc >::Entity &entity) const
return hierarchic index of given entity
Definition: albertagrid/indexsets.hh:394
AlbertaGridIndexSet(const DofNumbering &dofNumbering)
Definition: albertagrid/indexsets.hh:358
Alberta::HierarchyDofNumbering< dimension > DofNumbering
Definition: albertagrid/indexsets.hh:349
bool contains(const Entity &entity) const
Definition: albertagrid/indexsets.hh:375
const std::vector< GeometryType > & geomTypes(int codim) const
Definition: albertagrid/indexsets.hh:436
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:403
Base::IndexType IndexType
Definition: albertagrid/indexsets.hh:342
Types types(int codim) const
Definition: albertagrid/indexsets.hh:430
~AlbertaGridIndexSet()
Definition: albertagrid/indexsets.hh:368
std::size_t size(int codim) const
Definition: albertagrid/indexsets.hh:424
std::size_t size(const GeometryType &type) const
Definition: albertagrid/indexsets.hh:419
void update(const Iterator &begin, const Iterator &end)
Definition: albertagrid/indexsets.hh:443
static const int dimension
Definition: albertagrid/indexsets.hh:346
AlbertaGrid< dim, dimworld > Grid
Definition: albertagrid/indexsets.hh:340
Definition: albertagrid/gridfamily.hh:83
static const int dimension
Definition: albertagrid/gridfamily.hh:88
Definition: albertagrid/gridfamily.hh:98
Definition: albertagrid/indexsets.hh:227
InitEntityNumber(IndexStack &indexStack)
Definition: albertagrid/indexsets.hh:231
Definition: indexstack.hh:26
int size() const
return maxIndex which is also the
Definition: indexstack.hh:79
Wrapper class for entities.
Definition: common/entity.hh:66
static constexpr int codimension
Know your own codimension.
Definition: common/entity.hh:106
Implementation & impl()
access to the underlying implementation
Definition: common/entity.hh:80
Index Set Interface base class.
Definition: indexidset.hh:78
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
Id Set Interface.
Definition: indexidset.hh:452
IdTypeImp IdType
Type used to represent an id.
Definition: indexidset.hh:458
provides the GridFamily for AlbertaGrid
Different resources needed by all grid implementations.