3#ifndef DUNE_ALBERTAGRIDINDEXSETS_HH
4#define DUNE_ALBERTAGRIDINDEXSETS_HH
12#include <dune/grid/albertagrid/misc.hh>
13#include <dune/grid/albertagrid/dofadmin.hh>
14#include <dune/grid/albertagrid/dofvector.hh>
27 extern IndexStack *currentIndexStack;
35 template<
int dim,
int dimworld >
36 class AlbertaGridHierarchicIndexSet
37 :
public IndexSet< AlbertaGridFamily< dim, dimworld >, AlbertaGridHierarchicIndexSet< dim,dimworld >, int >
39 typedef AlbertaGridHierarchicIndexSet< dim, dimworld > This;
40 typedef IndexSet< AlbertaGridFamily< dim, dimworld >, This,
int > Base;
42 friend class AlbertaGrid< dim, dimworld >;
46 typedef AlbertaGridFamily< dim, dimworld > GridFamily;
50 static const int dimension = GridFamily::dimension;
52 typedef Alberta::ElementInfo< dimension > ElementInfo;
53 typedef Alberta::HierarchyDofNumbering< dimension > DofNumbering;
56 typedef typename GridFamily::Traits Traits;
58 typedef Alberta::DofVectorPointer< IndexType > IndexVectorPointer;
60 class InitEntityNumber;
63 struct CreateEntityNumbers;
66 struct RefineNumbering;
69 struct CoarsenNumbering;
71 explicit AlbertaGridHierarchicIndexSet (
const DofNumbering &dofNumbering );
74 typedef Alberta::IndexStack IndexStack;
77 template<
class Entity >
78 bool contains (
const Entity & )
const
88 IndexType
index (
const typename Traits::template Codim< cc >::Entity &entity )
const
90 typedef AlbertaGridEntity< cc, dim, const Grid > EntityImp;
92 return subIndex( entityImp.elementInfo(), entityImp.subEntity(), cc );
97 IndexType subIndex (
const typename Traits::template Codim< cc >::Entity &entity,
int i,
unsigned int codim )
const
99 typedef AlbertaGridEntity< cc, dim, const Grid > EntityImp;
105 const ReferenceElement< Alberta::Real, dimension > &refElement
107 k = refElement.subEntity( entityImp.subEntity(), cc, i, codim );
110 const int j = entityImp.grid().generic2alberta( codim, k );
111 return subIndex( entityImp.elementInfo(), j, codim );
115 IndexType
size (
const GeometryType &type )
const
117 return (type.isSimplex() ?
size( dimension - type.dim() ) : 0);
121 IndexType
size (
int codim )
const
123 assert( (codim >= 0) && (codim <= dimension) );
124 return indexStack_[ codim ].size();
128 const std::vector< GeometryType > &geomTypes(
int codim )
const
130 assert( (codim >= 0) && (codim <= dimension) );
131 return geomTypes_[ codim ];
134 IndexType subIndex (
const ElementInfo &elementInfo,
int i,
unsigned int codim )
const
136 assert( !elementInfo ==
false );
137 return subIndex( elementInfo.element(), i, codim );
146 IndexType subIndex (
const Alberta::Element *element,
int i,
unsigned int codim )
const
148 IndexType *array = (IndexType *)entityNumbers_[ codim ];
149 const IndexType subIndex = array[ dofNumbering_( element, codim, i ) ];
150 assert( (subIndex >= 0) && (subIndex <
size( codim )) );
157 if( !IndexVectorPointer::supportsAdaptationData )
159 assert( Alberta::currentIndexStack == 0 );
160 Alberta::currentIndexStack = indexStack_;
167 if( !IndexVectorPointer::supportsAdaptationData )
168 Alberta::currentIndexStack = 0;
172 void read (
const std::string &filename );
173 bool write (
const std::string &filename )
const;
177 for(
int i = 0; i <= dimension; ++i )
178 entityNumbers_[ i ].release();
182 template<
int codim >
183 static IndexStack &getIndexStack (
const IndexVectorPointer &dofVector )
185 IndexStack *indexStack;
186 if( IndexVectorPointer::supportsAdaptationData )
187 indexStack = dofVector.template getAdaptationData< IndexStack >();
189 indexStack = &Alberta::currentIndexStack[ codim ];
190 assert( indexStack != 0 );
195 const DofNumbering &dofNumbering_;
198 IndexStack indexStack_[ dimension+1 ];
201 IndexVectorPointer entityNumbers_[ dimension+1 ];
204 std::vector< GeometryType > geomTypes_[ dimension+1 ];
212 template<
int dim,
int dimworld >
213 class AlbertaGridHierarchicIndexSet< dim, dimworld >::InitEntityNumber
215 IndexStack &indexStack_;
218 InitEntityNumber ( IndexStack &indexStack )
219 : indexStack_( indexStack )
222 void operator() (
int &dof )
224 dof = indexStack_.getIndex();
233 template<
int dim,
int dimworld >
234 template<
int codim >
235 struct AlbertaGridHierarchicIndexSet< dim, dimworld >::CreateEntityNumbers
237 static void setup ( AlbertaGridHierarchicIndexSet< dim, dimworld > &indexSet );
239 static void apply (
const Alberta::HierarchyDofNumbering< dimension > &dofNumbering,
240 AlbertaGridHierarchicIndexSet< dim, dimworld > &indexSet );
242 static void apply (
const std::string &filename,
243 const Alberta::MeshPointer< dimension > &mesh,
244 AlbertaGridHierarchicIndexSet< dim, dimworld > &indexSet );
252 template<
int dim,
int dimworld >
253 template<
int codim >
254 struct AlbertaGridHierarchicIndexSet< dim, dimworld >::RefineNumbering
256 static const int dimension = dim;
257 static const int codimension = codim;
260 typedef Alberta::DofAccess< dimension, codimension > DofAccess;
262 explicit RefineNumbering (
const IndexVectorPointer &dofVector )
263 : indexStack_( getIndexStack< codimension >( dofVector ) ),
264 dofVector_( dofVector ),
265 dofAccess_( dofVector.dofSpace() )
269 void operator() (
const Alberta::Element *child,
int subEntity );
271 typedef Alberta::Patch< dimension > Patch;
272 static void interpolateVector (
const IndexVectorPointer &dofVector,
273 const Patch &patch );
276 IndexStack &indexStack_;
277 IndexVectorPointer dofVector_;
278 DofAccess dofAccess_;
286 template<
int dim,
int dimworld >
287 template<
int codim >
288 struct AlbertaGridHierarchicIndexSet< dim, dimworld >::CoarsenNumbering
290 static const int dimension = dim;
291 static const int codimension = codim;
294 typedef Alberta::DofAccess< dimension, codimension > DofAccess;
296 explicit CoarsenNumbering (
const IndexVectorPointer &dofVector )
297 : indexStack_( getIndexStack< codimension >( dofVector ) ),
298 dofVector_( dofVector ),
299 dofAccess_( dofVector.dofSpace() )
303 void operator() (
const Alberta::Element *child,
int subEntity );
305 typedef Alberta::Patch< dimension > Patch;
306 static void restrictVector (
const IndexVectorPointer &dofVector,
307 const Patch &patch );
309 IndexStack &indexStack_;
310 IndexVectorPointer dofVector_;
311 DofAccess dofAccess_;
319 template<
int dim,
int dimworld >
320 class AlbertaGridIndexSet
321 :
public IndexSet< AlbertaGrid< dim, dimworld >, AlbertaGridIndexSet< dim, dimworld >, int >
323 typedef AlbertaGridIndexSet< dim, dimworld > This;
324 typedef IndexSet< AlbertaGrid< dim, dimworld >, This,
int > Base;
331 static const int dimension = Grid::dimension;
333 typedef Alberta::ElementInfo< dimension > ElementInfo;
334 typedef Alberta::HierarchyDofNumbering< dimension > DofNumbering;
337 typedef typename Grid::Traits Traits;
339 template<
int codim >
343 explicit AlbertaGridIndexSet (
const DofNumbering &dofNumbering )
344 : dofNumbering_( dofNumbering )
346 for(
int codim = 0; codim <= dimension; ++codim )
348 indices_[ codim ] = 0;
351 geomTypes_[ codim ].push_back( type );
355 ~AlbertaGridIndexSet ()
357 for(
int codim = 0; codim <= dimension; ++codim )
358 delete[] indices_[ codim ];
361 template<
class Entity >
362 bool contains (
const Entity &entity )
const
366 const AlbertaGridEntity< codim, dim, const Grid > &entityImp
368 const Alberta::Element *element = entityImp.elementInfo().el();
370 const IndexType *
const array = indices_[ codim ];
371 const IndexType subIndex = array[ dofNumbering_( element, codim, entityImp.subEntity() ) ];
373 return (subIndex >= 0);
381 IndexType
index (
const typename Traits::template Codim< cc >::Entity &entity )
const
383 typedef AlbertaGridEntity< cc, dim, const Grid > EntityImp;
385 return subIndex( entityImp.elementInfo(), entityImp.subEntity(), cc );
390 IndexType subIndex (
const typename Traits::template Codim< cc >::Entity &entity,
int i,
unsigned int codim )
const
392 typedef AlbertaGridEntity< cc, dim, const Grid > EntityImp;
398 const ReferenceElement< Alberta::Real, dimension > &refElement
400 k = refElement.subEntity( entityImp.subEntity(), cc, i, codim );
403 const int j = entityImp.grid().generic2alberta( codim, k );
404 return subIndex( entityImp.elementInfo(), j, codim );
407 IndexType
size (
const GeometryType &type )
const
409 return (type.isSimplex() ?
size( dimension - type.dim() ) : 0);
412 IndexType
size (
int codim )
const
414 assert( (codim >= 0) && (codim <= dimension) );
415 return size_[ codim ];
418 const std::vector< GeometryType > &geomTypes(
int codim )
const
420 assert( (codim >= 0) && (codim <= dimension) );
421 return geomTypes_[ codim ];
424 template<
class Iterator >
425 void update (
const Iterator &begin,
const Iterator &end )
427 for(
int codim = 0; codim <= dimension; ++codim )
429 delete[] indices_[ codim ];
431 const unsigned int dofSize = dofNumbering_.size( codim );
432 indices_[ codim ] =
new IndexType[ dofSize ];
433 for(
unsigned int i = 0; i < dofSize; ++i )
434 indices_[ codim ][ i ] = -1;
439 for( Iterator it = begin; it != end; ++it )
441 const AlbertaGridEntity< 0, dim, const Grid > &entityImp
443 const Alberta::Element *element = entityImp.elementInfo().el();
444 ForLoop< Insert, 0, dimension >::apply( element, *
this );
449 IndexType subIndex (
const ElementInfo &elementInfo,
int i,
unsigned int codim )
const
451 assert( !elementInfo ==
false );
452 return subIndex( elementInfo.element(), i, codim );
461 IndexType subIndex (
const Alberta::Element *element,
int i,
unsigned int codim )
const
463 const IndexType *
const array = indices_[ codim ];
464 const IndexType subIndex = array[ dofNumbering_( element, codim, i ) ];
465 assert( (subIndex >= 0) && (subIndex <
size( codim )) );
470 const DofNumbering &dofNumbering_;
473 IndexType *indices_[ dimension+1 ];
476 IndexType size_[ dimension+1 ];
479 std::vector< GeometryType > geomTypes_[ dimension+1 ];
487 template<
int dim,
int dimworld >
488 template<
int codim >
489 struct AlbertaGridIndexSet< dim, dimworld >::Insert
491 static void apply (
const Alberta::Element *
const element,
492 AlbertaGridIndexSet< dim, dimworld > &indexSet )
494 int *
const array = indexSet.indices_[ codim ];
495 IndexType &
size = indexSet.size_[ codim ];
497 for(
int i = 0; i < Alberta::NumSubEntities< dim, codim >::value; ++i )
499 int &
index = array[ indexSet.dofNumbering_( element, codim, i ) ];
512 template<
int dim,
int dimworld >
514 :
public IdSet< AlbertaGrid< dim, dimworld >, AlbertaGridIdSet< dim, dimworld >, unsigned int >
528 static const int dimension = Grid::dimension;
534 : hIndexSet_( hIndexSet )
539 template<
class Entity >
543 return id< codim >( e );
547 template<
int codim >
548 IdType id (
const typename Grid::template Codim< codim >::Entity &e )
const
550 assert( (codim >= 0) && (codim <= dimension) );
551 const IdType index = hIndexSet_.index( e );
552 return (index << 2) |
IdType( codim );
556 IdType subId (
const typename Grid::template Codim< 0 >::Entity &e,
int i,
unsigned int subcodim )
const
558 assert(
int( subcodim ) <= dimension );
559 const IdType index = hIndexSet_.subIndex( e, i, subcodim );
560 return (index << 2) |
IdType( subcodim );
563 template<
int codim >
564 IdType subId (
const typename Grid::template Codim< codim >::Entity &e,
int i,
unsigned int subcodim )
const
566 assert( (codim >= 0) && (codim <= dimension) && (
int( codim + subcodim ) <= dimension) );
567 const IdType index = hIndexSet_.subIndex( e, i, subcodim );
568 return (index << 2) |
IdType( codim + subcodim );
571 template<
class Entity >
572 IdType subId (
const Entity &e,
int i,
unsigned int subcodim )
const
574 return subId< Entity::codimension >( e, i, subcodim );
579 AlbertaGridIdSet (
const This & );
581 const HierarchicIndexSet &hIndexSet_;
provides the GridFamily for AlbertaGrid
hierarchic index set of AlbertaGrid
Definition: indexsets.hh:515
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:548
IdType id(const Entity &e) const
Get id of an entity. This method is simpler to use than the one below.
Definition: indexsets.hh:540
Base::IdType IdType
export type of id
Definition: indexsets.hh:523
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:556
Traits::HierarchicIndexSet HierarchicIndexSet
type of hierarchic index set
Definition: agrid.hh:189
Wrapper class for entities.
Definition: entity.hh:57
@ codimension
Know your own codimension.
Definition: entity.hh:99
@ simplex
Simplicial element in any nonnegative dimension.
Definition: type.hh:30
static ReturnImplementationType< InterfaceType >::ImplementationType & getRealImplementation(InterfaceType &i)
return real implementation of interface class
Definition: grid.hh:1223
Id Set Interface.
Definition: indexidset.hh:403
IdTypeImp IdType
Type used to represent an id.
Definition: indexidset.hh:406
IndexType index(const typename remove_const< GridImp >::type::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:107
IndexType size(GeometryType type) const
Return total number of entities of given geometry type in entity set .
Definition: indexidset.hh:204
IndexTypeImp IndexType
The type used for the indices.
Definition: indexidset.hh:85
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:146
bool contains(const EntityType &e) const
Return true if the given entity is contained in .
Definition: indexidset.hh:228
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:14
Standard Dune debug streams.
static const ReferenceElement< ctype, dim > & simplex()
get simplex reference elements
Definition: referenceelements.hh:574