3#ifndef DUNE_ALBERTAGRIDINDEXSETS_HH
4#define DUNE_ALBERTAGRIDINDEXSETS_HH
14#include <dune/grid/albertagrid/misc.hh>
15#include <dune/grid/albertagrid/dofadmin.hh>
16#include <dune/grid/albertagrid/dofvector.hh>
29 extern IndexStack *currentIndexStack;
37 template<
int dim,
int dimworld >
38 class AlbertaGridHierarchicIndexSet
39 :
public IndexSet< AlbertaGridFamily< dim, dimworld >, AlbertaGridHierarchicIndexSet< dim,dimworld >, int, std::array< GeometryType, 1 > >
41 typedef AlbertaGridHierarchicIndexSet< dim, dimworld > This;
42 typedef IndexSet< AlbertaGridFamily< dim, dimworld >, AlbertaGridHierarchicIndexSet< dim,dimworld >, int, std::array< GeometryType, 1 > > Base;
44 friend class AlbertaGrid< dim, dimworld >;
48 typedef AlbertaGridFamily< dim, dimworld > GridFamily;
54 static const int dimension = GridFamily::dimension;
56 typedef Alberta::ElementInfo< dimension > ElementInfo;
57 typedef Alberta::HierarchyDofNumbering< dimension > DofNumbering;
60 typedef typename GridFamily::Traits Traits;
62 typedef Alberta::DofVectorPointer< IndexType > IndexVectorPointer;
64 class InitEntityNumber;
67 struct CreateEntityNumbers;
70 struct RefineNumbering;
73 struct CoarsenNumbering;
75 explicit AlbertaGridHierarchicIndexSet (
const DofNumbering &dofNumbering );
78 typedef Alberta::IndexStack IndexStack;
81 template<
class Entity >
82 bool contains (
const Entity & )
const
92 IndexType
index (
const typename Traits::template Codim< cc >::Entity &entity )
const
94 typedef AlbertaGridEntity< cc, dim, const Grid > EntityImp;
96 return subIndex( entityImp.elementInfo(), entityImp.subEntity(), cc );
101 IndexType
subIndex (
const typename Traits::template Codim< cc >::Entity &entity,
int i,
unsigned int codim )
const
103 typedef AlbertaGridEntity< cc, dim, const Grid > EntityImp;
109 const ReferenceElement< Alberta::Real, dimension > &refElement
111 k = refElement.subEntity( entityImp.subEntity(), cc, i, codim );
114 const int j = entityImp.grid().generic2alberta( codim, k );
115 return subIndex( entityImp.elementInfo(), j, codim );
119 IndexType size (
const GeometryType &type )
const
121 return (type.isSimplex() ? size( dimension - type.dim() ) : 0);
125 IndexType size (
int codim )
const
127 assert( (codim >= 0) && (codim <= dimension) );
128 return indexStack_[ codim ].size();
131 Types types (
int codim )
const
133 assert( (codim >= 0) && (codim <= dimension) );
134 std::array< GeometryType, 1 > types;
140 const std::vector< GeometryType > &geomTypes(
int codim )
const
142 assert( (codim >= 0) && (codim <= dimension) );
143 return geomTypes_[ codim ];
146 IndexType
subIndex (
const ElementInfo &elementInfo,
int i,
unsigned int codim )
const
148 assert( !elementInfo ==
false );
149 return subIndex( elementInfo.element(), i, codim );
158 IndexType
subIndex (
const Alberta::Element *element,
int i,
unsigned int codim )
const
160 IndexType *array = (IndexType *)entityNumbers_[ codim ];
161 const IndexType
subIndex = array[ dofNumbering_( element, codim, i ) ];
162 assert( (subIndex >= 0) && (subIndex < size( codim )) );
169 if( !IndexVectorPointer::supportsAdaptationData )
171 assert( Alberta::currentIndexStack == 0 );
172 Alberta::currentIndexStack = indexStack_;
179 if( !IndexVectorPointer::supportsAdaptationData )
180 Alberta::currentIndexStack = 0;
184 void read (
const std::string &filename );
185 bool write (
const std::string &filename )
const;
189 for(
int i = 0; i <= dimension; ++i )
190 entityNumbers_[ i ].release();
194 template<
int codim >
195 static IndexStack &getIndexStack (
const IndexVectorPointer &dofVector )
197 IndexStack *indexStack;
198 if( IndexVectorPointer::supportsAdaptationData )
199 indexStack = dofVector.template getAdaptationData< IndexStack >();
201 indexStack = &Alberta::currentIndexStack[ codim ];
202 assert( indexStack != 0 );
207 const DofNumbering &dofNumbering_;
210 IndexStack indexStack_[ dimension+1 ];
213 IndexVectorPointer entityNumbers_[ dimension+1 ];
216 std::vector< GeometryType > geomTypes_[ dimension+1 ];
224 template<
int dim,
int dimworld >
225 class AlbertaGridHierarchicIndexSet< dim, dimworld >::InitEntityNumber
227 IndexStack &indexStack_;
230 InitEntityNumber ( IndexStack &indexStack )
231 : indexStack_( indexStack )
234 void operator() (
int &dof )
236 dof = indexStack_.getIndex();
245 template<
int dim,
int dimworld >
246 template<
int codim >
247 struct AlbertaGridHierarchicIndexSet< dim, dimworld >::CreateEntityNumbers
249 static void setup ( AlbertaGridHierarchicIndexSet< dim, dimworld > &indexSet );
251 static void apply (
const Alberta::HierarchyDofNumbering< dimension > &dofNumbering,
252 AlbertaGridHierarchicIndexSet< dim, dimworld > &indexSet );
254 static void apply (
const std::string &filename,
255 const Alberta::MeshPointer< dimension > &mesh,
256 AlbertaGridHierarchicIndexSet< dim, dimworld > &indexSet );
264 template<
int dim,
int dimworld >
265 template<
int codim >
266 struct AlbertaGridHierarchicIndexSet< dim, dimworld >::RefineNumbering
268 static const int dimension = dim;
269 static const int codimension = codim;
272 typedef Alberta::DofAccess< dimension, codimension > DofAccess;
274 explicit RefineNumbering (
const IndexVectorPointer &dofVector )
275 : indexStack_( getIndexStack< codimension >( dofVector ) ),
276 dofVector_( dofVector ),
277 dofAccess_( dofVector.dofSpace() )
281 void operator() (
const Alberta::Element *child,
int subEntity );
283 typedef Alberta::Patch< dimension > Patch;
284 static void interpolateVector (
const IndexVectorPointer &dofVector,
285 const Patch &patch );
288 IndexStack &indexStack_;
289 IndexVectorPointer dofVector_;
290 DofAccess dofAccess_;
298 template<
int dim,
int dimworld >
299 template<
int codim >
300 struct AlbertaGridHierarchicIndexSet< dim, dimworld >::CoarsenNumbering
302 static const int dimension = dim;
303 static const int codimension = codim;
306 typedef Alberta::DofAccess< dimension, codimension > DofAccess;
308 explicit CoarsenNumbering (
const IndexVectorPointer &dofVector )
309 : indexStack_( getIndexStack< codimension >( dofVector ) ),
310 dofVector_( dofVector ),
311 dofAccess_( dofVector.dofSpace() )
315 void operator() (
const Alberta::Element *child,
int subEntity );
317 typedef Alberta::Patch< dimension > Patch;
318 static void restrictVector (
const IndexVectorPointer &dofVector,
319 const Patch &patch );
321 IndexStack &indexStack_;
322 IndexVectorPointer dofVector_;
323 DofAccess dofAccess_;
331 template<
int dim,
int dimworld >
332 class AlbertaGridIndexSet
333 :
public IndexSet< AlbertaGrid< dim, dimworld >, AlbertaGridIndexSet< dim, dimworld >, int, std::array< GeometryType, 1 > >
335 typedef AlbertaGridIndexSet< dim, dimworld > This;
336 typedef IndexSet< AlbertaGrid< dim, dimworld >, AlbertaGridIndexSet< dim, dimworld >, int, std::array< GeometryType, 1 > > Base;
345 static const int dimension = Grid::dimension;
347 typedef Alberta::ElementInfo< dimension > ElementInfo;
348 typedef Alberta::HierarchyDofNumbering< dimension > DofNumbering;
351 typedef typename Grid::Traits Traits;
353 template<
int codim >
357 explicit AlbertaGridIndexSet (
const DofNumbering &dofNumbering )
358 : dofNumbering_( dofNumbering )
360 for(
int codim = 0; codim <= dimension; ++codim )
362 indices_[ codim ] = 0;
365 geomTypes_[ codim ].push_back( type );
369 ~AlbertaGridIndexSet ()
371 for(
int codim = 0; codim <= dimension; ++codim )
372 delete[] indices_[ codim ];
375 template<
class Entity >
376 bool contains (
const Entity &entity )
const
380 const AlbertaGridEntity< codim, dim, const Grid > &entityImp
382 const Alberta::Element *element = entityImp.elementInfo().el();
384 const IndexType *
const array = indices_[ codim ];
385 const IndexType subIndex = array[ dofNumbering_( element, codim, entityImp.subEntity() ) ];
387 return (subIndex >= 0);
395 IndexType
index (
const typename Traits::template Codim< cc >::Entity &entity )
const
397 typedef AlbertaGridEntity< cc, dim, const Grid > EntityImp;
399 return subIndex( entityImp.elementInfo(), entityImp.subEntity(), cc );
404 IndexType subIndex (
const typename Traits::template Codim< cc >::Entity &entity,
int i,
unsigned int codim )
const
406 typedef AlbertaGridEntity< cc, dim, const Grid > EntityImp;
412 const ReferenceElement< Alberta::Real, dimension > &refElement
414 k = refElement.subEntity( entityImp.subEntity(), cc, i, codim );
417 const int j = entityImp.grid().generic2alberta( codim, k );
418 return subIndex( entityImp.elementInfo(), j, codim );
421 IndexType size (
const GeometryType &type )
const
423 return (type.isSimplex() ? size( dimension - type.dim() ) : 0);
426 IndexType size (
int codim )
const
428 assert( (codim >= 0) && (codim <= dimension) );
429 return size_[ codim ];
432 Types types (
int codim )
const
434 assert( (codim >= 0) && (codim <= dimension) );
435 std::array< GeometryType, 1 > types;
440 const std::vector< GeometryType > &geomTypes(
int codim )
const
442 assert( (codim >= 0) && (codim <= dimension) );
443 return geomTypes_[ codim ];
446 template<
class Iterator >
447 void update (
const Iterator &begin,
const Iterator &end )
449 for(
int codim = 0; codim <= dimension; ++codim )
451 delete[] indices_[ codim ];
453 const unsigned int dofSize = dofNumbering_.size( codim );
454 indices_[ codim ] =
new IndexType[ dofSize ];
455 for(
unsigned int i = 0; i < dofSize; ++i )
456 indices_[ codim ][ i ] = -1;
461 for( Iterator it = begin; it != end; ++it )
463 const AlbertaGridEntity< 0, dim, const Grid > &entityImp
465 const Alberta::Element *element = entityImp.elementInfo().el();
466 ForLoop< Insert, 0, dimension >::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) && (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
Get id of an entity of codim cc. Unhandy because template parameter must be supplied explicitely.
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
Get id of subentity i of co-dimension codim of a co-dimension 0 entity.
Definition: indexsets.hh:578
Traits::HierarchicIndexSet HierarchicIndexSet
type of hierarchic index set
Definition: agrid.hh:189
Wrapper class for entities.
Definition: entity.hh:62
@ codimension
Know your own codimension.
Definition: entity.hh:104
@ simplex
Simplicial element in any nonnegative dimension.
Definition: type.hh:30
static std::conditional< std::is_reference< InterfaceType >::value, typenamestd::add_lvalue_reference< typenameReturnImplementationType< typenamestd::remove_reference< InterfaceType >::type >::ImplementationType >::type, typenamestd::remove_const< typenameReturnImplementationType< typenamestd::remove_reference< InterfaceType >::type >::ImplementationType >::type >::type getRealImplementation(InterfaceType &&i)
return real implementation of interface class
Definition: grid.hh:1305
Id Set Interface.
Definition: indexidset.hh:414
IdTypeImp IdType
Type used to represent an id.
Definition: indexidset.hh:417
IndexType subIndex(const Entity &e, int i, unsigned int codim) const
Map a subentity to an index.
Definition: indexidset.hh:179
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: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:115
int IndexType
The type used for the indices.
Definition: indexidset.hh:90
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:131
Definition: indexstack.hh:24
Different resources needed by all grid implementations.
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:178
provides a wrapper for ALBERTA's el_info structure
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: alignment.hh:10
Standard Dune debug streams.
Static tag representing a codimension.
Definition: dimension.hh:22
static const ReferenceElement< ctype, dim > & simplex()
get simplex reference elements
Definition: referenceelements.hh:490