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();
135 Types types (
int codim )
const
137 assert( (codim >= 0) && (codim <= dimension) );
141 IndexType
subIndex (
const ElementInfo &elementInfo,
int i,
unsigned int codim )
const
143 assert( !elementInfo ==
false );
144 return subIndex( elementInfo.element(), i, codim );
153 IndexType
subIndex (
const Alberta::Element *element,
int i,
unsigned int codim )
const
155 IndexType *array = (IndexType *)entityNumbers_[ codim ];
156 const IndexType
subIndex = array[ dofNumbering_( element, codim, i ) ];
157 assert( (subIndex >= 0) && (subIndex < IndexType(
size( codim ))) );
164 if( !IndexVectorPointer::supportsAdaptationData )
166 assert( currentIndexStack ==
nullptr );
167 currentIndexStack = indexStack_;
174 if( !IndexVectorPointer::supportsAdaptationData )
175 currentIndexStack =
nullptr;
179 void read (
const std::string &filename );
180 bool write (
const std::string &filename )
const;
184 for(
int i = 0; i <= dimension; ++i )
185 entityNumbers_[ i ].release();
189 template<
int codim >
190 static IndexStack &getIndexStack (
const IndexVectorPointer &dofVector )
192 IndexStack *indexStack;
193 if( IndexVectorPointer::supportsAdaptationData )
194 indexStack = dofVector.template getAdaptationData< IndexStack >();
196 indexStack = ¤tIndexStack[ codim ];
197 assert( indexStack != 0 );
202 const DofNumbering &dofNumbering_;
205 IndexStack indexStack_[ dimension+1 ];
208 IndexVectorPointer entityNumbers_[ dimension+1 ];
211 template<
int dim,
int dimworld >
212 Alberta::IndexStack* AlbertaGridHierarchicIndexSet<dim,dimworld>::currentIndexStack =
nullptr;
219 template<
int dim,
int dimworld >
220 class AlbertaGridHierarchicIndexSet< dim, dimworld >::InitEntityNumber
222 IndexStack &indexStack_;
225 InitEntityNumber ( IndexStack &indexStack )
226 : indexStack_( indexStack )
229 void operator() (
int &dof )
231 dof = indexStack_.getIndex();
240 template<
int dim,
int dimworld >
241 template<
int codim >
242 struct AlbertaGridHierarchicIndexSet< dim, dimworld >::CreateEntityNumbers
244 static void setup ( AlbertaGridHierarchicIndexSet< dim, dimworld > &indexSet );
246 static void apply (
const Alberta::HierarchyDofNumbering< dimension > &dofNumbering,
247 AlbertaGridHierarchicIndexSet< dim, dimworld > &indexSet );
249 static void apply (
const std::string &filename,
250 const Alberta::MeshPointer< dimension > &mesh,
251 AlbertaGridHierarchicIndexSet< dim, dimworld > &indexSet );
259 template<
int dim,
int dimworld >
260 template<
int codim >
261 struct AlbertaGridHierarchicIndexSet< dim, dimworld >::RefineNumbering
263 static const int dimension = dim;
264 static const int codimension = codim;
267 typedef Alberta::DofAccess< dimension, codimension > DofAccess;
269 explicit RefineNumbering (
const IndexVectorPointer &dofVector )
270 : indexStack_( getIndexStack< codimension >( dofVector ) ),
271 dofVector_( dofVector ),
272 dofAccess_( dofVector.dofSpace() )
276 void operator() (
const Alberta::Element *
child,
int subEntity );
278 typedef Alberta::Patch< dimension > Patch;
279 static void interpolateVector (
const IndexVectorPointer &dofVector,
280 const Patch &patch );
283 IndexStack &indexStack_;
284 IndexVectorPointer dofVector_;
285 DofAccess dofAccess_;
293 template<
int dim,
int dimworld >
294 template<
int codim >
295 struct AlbertaGridHierarchicIndexSet< dim, dimworld >::CoarsenNumbering
297 static const int dimension = dim;
298 static const int codimension = codim;
301 typedef Alberta::DofAccess< dimension, codimension > DofAccess;
303 explicit CoarsenNumbering (
const IndexVectorPointer &dofVector )
304 : indexStack_( getIndexStack< codimension >( dofVector ) ),
305 dofVector_( dofVector ),
306 dofAccess_( dofVector.dofSpace() )
310 void operator() (
const Alberta::Element *
child,
int subEntity );
312 typedef Alberta::Patch< dimension > Patch;
313 static void restrictVector (
const IndexVectorPointer &dofVector,
314 const Patch &patch );
316 IndexStack &indexStack_;
317 IndexVectorPointer dofVector_;
318 DofAccess dofAccess_;
326 template<
int dim,
int dimworld >
327 class AlbertaGridIndexSet
328 :
public IndexSet< AlbertaGrid< dim, dimworld >, AlbertaGridIndexSet< dim, dimworld >, int, std::array< GeometryType, 1 > >
330 typedef AlbertaGridIndexSet< dim, dimworld > This;
331 typedef IndexSet< AlbertaGrid< dim, dimworld >, AlbertaGridIndexSet< dim, dimworld >, int, std::array< GeometryType, 1 > > Base;
340 static const int dimension = Grid::dimension;
342 typedef Alberta::ElementInfo< dimension > ElementInfo;
343 typedef Alberta::HierarchyDofNumbering< dimension > DofNumbering;
346 typedef typename Grid::Traits Traits;
348 template<
int codim >
352 explicit AlbertaGridIndexSet (
const DofNumbering &dofNumbering )
353 : dofNumbering_( dofNumbering )
355 for(
int codim = 0; codim <= dimension; ++codim )
357 indices_[ codim ] = 0;
361 ~AlbertaGridIndexSet ()
363 for(
int codim = 0; codim <= dimension; ++codim )
364 delete[] indices_[ codim ];
367 template<
class Entity >
368 bool contains (
const Entity &entity )
const
372 const AlbertaGridEntity< codim, dim, const Grid > &entityImp
374 const Alberta::Element *element = entityImp.elementInfo().el();
376 const IndexType *
const array = indices_[ codim ];
377 const IndexType subIndex = array[ dofNumbering_( element, codim, entityImp.subEntity() ) ];
379 return (subIndex >= 0);
387 IndexType
index (
const typename Traits::template Codim< cc >::Entity &entity )
const
389 typedef AlbertaGridEntity< cc, dim, const Grid > EntityImp;
390 const EntityImp &entityImp = entity.impl();
391 return subIndex( entityImp.elementInfo(), entityImp.subEntity(), cc );
396 IndexType subIndex (
const typename Traits::template Codim< cc >::Entity &entity,
int i,
unsigned int codim )
const
398 typedef AlbertaGridEntity< cc, dim, const Grid > EntityImp;
399 const EntityImp &entityImp = entity.impl();
405 k = refElement.subEntity( entityImp.subEntity(), cc, i, codim );
408 const int j = entityImp.grid().generic2alberta( codim, k );
409 return subIndex( entityImp.elementInfo(), j, codim );
412 std::size_t
size (
const GeometryType &type )
const
414 return (type.isSimplex() ?
size( dimension - type.dim() ) : 0);
417 std::size_t
size (
int codim )
const
419 assert( (codim >= 0) && (codim <= dimension) );
420 return size_[ codim ];
423 Types types (
int codim )
const
425 assert( (codim >= 0) && (codim <= dimension) );
429 template<
class Iterator >
430 void update (
const Iterator &begin,
const Iterator &end )
432 for(
int codim = 0; codim <= dimension; ++codim )
434 delete[] indices_[ codim ];
436 const unsigned int dofSize = dofNumbering_.size( codim );
437 indices_[ codim ] =
new IndexType[ dofSize ];
438 for(
unsigned int i = 0; i < dofSize; ++i )
439 indices_[ codim ][ i ] = -1;
444 for( Iterator it = begin; it != end; ++it )
446 const AlbertaGridEntity< 0, dim, const Grid > &entityImp
448 const Alberta::Element *element = entityImp.elementInfo().el();
450 [ & ](
auto i ){ Insert< i >::apply( element, *
this ); } );
455 IndexType subIndex (
const ElementInfo &elementInfo,
int i,
unsigned int codim )
const
457 assert( !elementInfo ==
false );
458 return subIndex( elementInfo.element(), i, codim );
467 IndexType subIndex (
const Alberta::Element *element,
int i,
unsigned int codim )
const
469 const IndexType *
const array = indices_[ codim ];
470 const IndexType subIndex = array[ dofNumbering_( element, codim, i ) ];
471 assert( (subIndex >= 0) && (
static_cast<unsigned int>(subIndex) <
size( codim )) );
476 const DofNumbering &dofNumbering_;
479 IndexType *indices_[ dimension+1 ];
482 IndexType size_[ dimension+1 ];
490 template<
int dim,
int dimworld >
491 template<
int codim >
492 struct AlbertaGridIndexSet< dim, dimworld >::Insert
494 static void apply (
const Alberta::Element *
const element,
495 AlbertaGridIndexSet< dim, dimworld > &indexSet )
497 int *
const array = indexSet.indices_[ codim ];
498 IndexType &
size = indexSet.size_[ codim ];
500 for(
int i = 0; i < Alberta::NumSubEntities< dim, codim >::value; ++i )
502 int &
index = array[ indexSet.dofNumbering_( element, codim, i ) ];
515 template<
int dim,
int dimworld >
517 :
public IdSet< AlbertaGrid< dim, dimworld >, AlbertaGridIdSet< dim, dimworld >, unsigned int >
531 static const int dimension = Grid::dimension;
537 : hIndexSet_( hIndexSet )
542 template<
class Entity >
546 return id< codim >( e );
550 template<
int codim >
553 assert( (codim >= 0) && (codim <= dimension) );
554 const IdType index = hIndexSet_.index( e );
555 return (index << 2) |
IdType( codim );
561 assert(
int( subcodim ) <= dimension );
562 const IdType index = hIndexSet_.subIndex( e, i, subcodim );
563 return (index << 2) |
IdType( subcodim );
566 template<
int codim >
569 assert( (codim >= 0) && (codim <= dimension) && (
int( codim + subcodim ) <= dimension) );
570 const IdType index = hIndexSet_.subIndex( e, i, subcodim );
571 return (index << 2) |
IdType( codim + subcodim );
574 template<
class Entity >
575 IdType subId (
const Entity &e,
int i,
unsigned int subcodim )
const
577 return subId< Entity::codimension >( e, i, subcodim );
582 AlbertaGridIdSet (
const This & );
584 const HierarchicIndexSet &hIndexSet_;
provides the GridFamily for AlbertaGrid
hierarchic index set of AlbertaGrid
Definition: indexsets.hh:518
IdType id(const typename Grid::template Codim< codim >::Entity &e) const
Definition: indexsets.hh:551
IdType id(const Entity &e) const
Definition: indexsets.hh:543
Base::IdType IdType
export type of id
Definition: indexsets.hh:526
IdType subId(const typename Grid::template Codim< 0 >::Entity &e, int i, unsigned int subcodim) const
Definition: indexsets.hh:559
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:447
IdTypeImp IdType
Type used to represent an id.
Definition: indexidset.hh:453
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 base classes for index and id sets.
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:453
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition: hybridutilities.hh:256
Provides an index stack that supplies indices for element numbering for a grid (i....
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
constexpr std::bool_constant<((II==value)||...)> contains(std::integer_sequence< T, II... >, std::integral_constant< T, value >)
Checks whether or not a given sequence contains a value.
Definition: integersequence.hh:137
Standard Dune debug streams.
Static tag representing a codimension.
Definition: dimension.hh:24
static const ReferenceElement & simplex()
get simplex reference elements
Definition: referenceelements.hh:162