dune-grid  2.3.1-rc1
albertagrid/indexsets.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_ALBERTAGRIDINDEXSETS_HH
4 #define DUNE_ALBERTAGRIDINDEXSETS_HH
5 
6 #include <dune/common/stdstreams.hh>
7 
10 
17 
18 #if HAVE_ALBERTA
19 
20 namespace Dune
21 {
22 
23  namespace Alberta
24  {
26 
28  }
29 
30 
31 
32  // AlbertaGridHierarchicIndexSet
33  // -----------------------------
34 
35  template< int dim, int dimworld >
37  : public IndexSet< AlbertaGridFamily< dim, dimworld >, AlbertaGridHierarchicIndexSet< dim,dimworld >, int >
38  {
40  typedef IndexSet< AlbertaGridFamily< dim, dimworld >, This, int > Base;
41 
42  friend class AlbertaGrid< dim, dimworld >;
43 
44  public:
47 
48  typedef typename Base::IndexType IndexType;
49 
50  static const int dimension = GridFamily::dimension;
51 
54 
55  private:
56  typedef typename GridFamily::Traits Traits;
57 
59 
60  class InitEntityNumber;
61 
62  template< int codim >
63  struct CreateEntityNumbers;
64 
65  template< int codim >
66  struct RefineNumbering;
67 
68  template< int codim >
69  struct CoarsenNumbering;
70 
71  explicit AlbertaGridHierarchicIndexSet ( const DofNumbering &dofNumbering );
72 
73  public:
75 
77  template< class Entity >
78  bool contains ( const Entity & ) const
79  {
80  return true;
81  }
82 
83  using Base::index;
84  using Base::subIndex;
85 
87  template< int cc >
88  IndexType index ( const typename Traits::template Codim< cc >::Entity &entity ) const
89  {
91  const EntityImp &entityImp = Grid::getRealImplementation( entity );
92  return subIndex( entityImp.elementInfo(), entityImp.subEntity(), cc );
93  }
94 
96  template< int cc >
97  IndexType subIndex ( const typename Traits::template Codim< cc >::Entity &entity, int i, unsigned int codim ) const
98  {
100  const EntityImp &entityImp = Grid::getRealImplementation( entity );
101 
102  int k = i;
103  if( cc > 0 )
104  {
105  const ReferenceElement< Alberta::Real, dimension > &refElement
107  k = refElement.subEntity( entityImp.subEntity(), cc, i, codim );
108  }
109 
110  const int j = entityImp.grid().generic2alberta( codim, k );
111  return subIndex( entityImp.elementInfo(), j, codim );
112  }
113 
115  IndexType size ( const GeometryType &type ) const
116  {
117  return (type.isSimplex() ? size( dimension - type.dim() ) : 0);
118  }
119 
121  IndexType size ( int codim ) const
122  {
123  assert( (codim >= 0) && (codim <= dimension) );
124  return indexStack_[ codim ].size();
125  }
126 
128  const std::vector< GeometryType > &geomTypes( int codim ) const
129  {
130  assert( (codim >= 0) && (codim <= dimension) );
131  return geomTypes_[ codim ];
132  }
133 
134  IndexType subIndex ( const ElementInfo &elementInfo, int i, unsigned int codim ) const
135  {
136  assert( !elementInfo == false );
137  return subIndex( elementInfo.element(), i, codim );
138  }
139 
146  IndexType subIndex ( const Alberta::Element *element, int i, unsigned int codim ) const
147  {
148  IndexType *array = (IndexType *)entityNumbers_[ codim ];
149  const IndexType subIndex = array[ dofNumbering_( element, codim, i ) ];
150  assert( (subIndex >= 0) && (subIndex < size( codim )) );
151  return subIndex;
152  }
153 
154  void preAdapt ()
155  {
156  // set global pointer to index stack
158  {
159  assert( Alberta::currentIndexStack == 0 );
160  Alberta::currentIndexStack = indexStack_;
161  }
162  }
163 
164  void postAdapt ()
165  {
166  // remove global pointer to index stack
169  }
170 
171  void create ();
172  void read ( const std::string &filename );
173  bool write ( const std::string &filename ) const;
174 
175  void release ()
176  {
177  for( int i = 0; i <= dimension; ++i )
178  entityNumbers_[ i ].release();
179  }
180 
181  private:
182  template< int codim >
183  static IndexStack &getIndexStack ( const IndexVectorPointer &dofVector )
184  {
185  IndexStack *indexStack;
187  indexStack = dofVector.template getAdaptationData< IndexStack >();
188  else
189  indexStack = &Alberta::currentIndexStack[ codim ];
190  assert( indexStack != 0 );
191  return *indexStack;
192  }
193 
194  // access to the dof vectors
195  const DofNumbering &dofNumbering_;
196 
197  // index stacks providing new numbers during adaptation
198  IndexStack indexStack_[ dimension+1 ];
199 
200  // dof vectors storing the (persistent) numbering
201  IndexVectorPointer entityNumbers_[ dimension+1 ];
202 
203  // all geometry types contained in the grid
204  std::vector< GeometryType > geomTypes_[ dimension+1 ];
205  };
206 
207 
208 
209  // AlbertaGridHierarchicIndexSet::InitEntityNumber
210  // -----------------------------------------------
211 
212  template< int dim, int dimworld >
214  {
215  IndexStack &indexStack_;
216 
217  public:
218  InitEntityNumber ( IndexStack &indexStack )
219  : indexStack_( indexStack )
220  {}
221 
222  void operator() ( int &dof )
223  {
224  dof = indexStack_.getIndex();
225  }
226  };
227 
228 
229 
230  // AlbertaGridHierarchicIndexSet::CreateEntityNumbers
231  // --------------------------------------------------
232 
233  template< int dim, int dimworld >
234  template< int codim >
235  struct AlbertaGridHierarchicIndexSet< dim, dimworld >::CreateEntityNumbers
236  {
237  static void setup ( AlbertaGridHierarchicIndexSet< dim, dimworld > &indexSet );
238 
239  static void apply ( const Alberta::HierarchyDofNumbering< dimension > &dofNumbering,
241 
242  static void apply ( const std::string &filename,
245  };
246 
247 
248 
249  // AlbertaGridHierarchicIndexSet::RefineNumbering
250  // ----------------------------------------------
251 
252  template< int dim, int dimworld >
253  template< int codim >
254  struct AlbertaGridHierarchicIndexSet< dim, dimworld >::RefineNumbering
255  {
256  static const int dimension = dim;
257  static const int codimension = codim;
258 
259  private:
260  typedef Alberta::DofAccess< dimension, codimension > DofAccess;
261 
262  explicit RefineNumbering ( const IndexVectorPointer &dofVector )
263  : indexStack_( getIndexStack< codimension >( dofVector ) ),
264  dofVector_( dofVector ),
265  dofAccess_( dofVector.dofSpace() )
266  {}
267 
268  public:
269  void operator() ( const Alberta::Element *child, int subEntity );
270 
271  typedef Alberta::Patch< dimension > Patch;
272  static void interpolateVector ( const IndexVectorPointer &dofVector,
273  const Patch &patch );
274 
275  private:
276  IndexStack &indexStack_;
277  IndexVectorPointer dofVector_;
278  DofAccess dofAccess_;
279  };
280 
281 
282 
283  // AlbertaGridHierarchicIndexSet::CoarsenNumbering
284  // -----------------------------------------------
285 
286  template< int dim, int dimworld >
287  template< int codim >
288  struct AlbertaGridHierarchicIndexSet< dim, dimworld >::CoarsenNumbering
289  {
290  static const int dimension = dim;
291  static const int codimension = codim;
292 
293  private:
294  typedef Alberta::DofAccess< dimension, codimension > DofAccess;
295 
296  explicit CoarsenNumbering ( const IndexVectorPointer &dofVector )
297  : indexStack_( getIndexStack< codimension >( dofVector ) ),
298  dofVector_( dofVector ),
299  dofAccess_( dofVector.dofSpace() )
300  {}
301 
302  public:
303  void operator() ( const Alberta::Element *child, int subEntity );
304 
305  typedef Alberta::Patch< dimension > Patch;
306  static void restrictVector ( const IndexVectorPointer &dofVector,
307  const Patch &patch );
308  private:
309  IndexStack &indexStack_;
310  IndexVectorPointer dofVector_;
311  DofAccess dofAccess_;
312  };
313 
314 
315 
316  // AlbertaGridIndexSet
317  // -------------------
318 
319  template< int dim, int dimworld >
320  class AlbertaGridIndexSet
321  : public IndexSet< AlbertaGrid< dim, dimworld >, AlbertaGridIndexSet< dim, dimworld >, int >
322  {
323  typedef AlbertaGridIndexSet< dim, dimworld > This;
324  typedef IndexSet< AlbertaGrid< dim, dimworld >, This, int > Base;
325 
326  public:
328 
329  typedef typename Base::IndexType IndexType;
330 
331  static const int dimension = Grid::dimension;
332 
335 
336  private:
337  typedef typename Grid::Traits Traits;
338 
339  template< int codim >
340  struct Insert;
341 
342  public:
343  explicit AlbertaGridIndexSet ( const DofNumbering &dofNumbering )
344  : dofNumbering_( dofNumbering )
345  {
346  for( int codim = 0; codim <= dimension; ++codim )
347  {
348  indices_[ codim ] = 0;
349 
350  const GeometryType type( GeometryType::simplex, dimension - codim );
351  geomTypes_[ codim ].push_back( type );
352  }
353  }
354 
356  {
357  for( int codim = 0; codim <= dimension; ++codim )
358  delete[] indices_[ codim ];
359  }
360 
361  template< class Entity >
362  bool contains ( const Entity &entity ) const
363  {
364  const int codim = Entity::codimension;
365 
367  = Grid::getRealImplementation( entity );
368  const Alberta::Element *element = entityImp.elementInfo().el();
369 
370  const IndexType *const array = indices_[ codim ];
371  const IndexType subIndex = array[ dofNumbering_( element, codim, entityImp.subEntity() ) ];
372 
373  return (subIndex >= 0);
374  }
375 
376  using Base::index;
377  using Base::subIndex;
378 
380  template< int cc >
381  IndexType index ( const typename Traits::template Codim< cc >::Entity &entity ) const
382  {
384  const EntityImp &entityImp = Grid::getRealImplementation( entity );
385  return subIndex( entityImp.elementInfo(), entityImp.subEntity(), cc );
386  }
387 
389  template< int cc >
390  IndexType subIndex ( const typename Traits::template Codim< cc >::Entity &entity, int i, unsigned int codim ) const
391  {
393  const EntityImp &entityImp = Grid::getRealImplementation( entity );
394 
395  int k = i;
396  if( cc > 0 )
397  {
398  const ReferenceElement< Alberta::Real, dimension > &refElement
400  k = refElement.subEntity( entityImp.subEntity(), cc, i, codim );
401  }
402 
403  const int j = entityImp.grid().generic2alberta( codim, k );
404  return subIndex( entityImp.elementInfo(), j, codim );
405  }
406 
407  IndexType size ( const GeometryType &type ) const
408  {
409  return (type.isSimplex() ? size( dimension - type.dim() ) : 0);
410  }
411 
412  IndexType size ( int codim ) const
413  {
414  assert( (codim >= 0) && (codim <= dimension) );
415  return size_[ codim ];
416  }
417 
418  const std::vector< GeometryType > &geomTypes( int codim ) const
419  {
420  assert( (codim >= 0) && (codim <= dimension) );
421  return geomTypes_[ codim ];
422  }
423 
424  template< class Iterator >
425  void update ( const Iterator &begin, const Iterator &end )
426  {
427  for( int codim = 0; codim <= dimension; ++codim )
428  {
429  delete[] indices_[ codim ];
430 
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;
435 
436  size_[ codim ] = 0;
437  }
438 
439  for( Iterator it = begin; it != end; ++it )
440  {
443  const Alberta::Element *element = entityImp.elementInfo().el();
444  ForLoop< Insert, 0, dimension >::apply( element, *this );
445  }
446  }
447 
448  private:
449  IndexType subIndex ( const ElementInfo &elementInfo, int i, unsigned int codim ) const
450  {
451  assert( !elementInfo == false );
452  return subIndex( elementInfo.element(), i, codim );
453  }
454 
461  IndexType subIndex ( const Alberta::Element *element, int i, unsigned int codim ) const
462  {
463  const IndexType *const array = indices_[ codim ];
464  const IndexType subIndex = array[ dofNumbering_( element, codim, i ) ];
465  assert( (subIndex >= 0) && (subIndex < size( codim )) );
466  return subIndex;
467  }
468 
469  // access to the dof vectors
470  const DofNumbering &dofNumbering_;
471 
472  // an array of indices for each codimension
473  IndexType *indices_[ dimension+1 ];
474 
475  // the size of each codimension
476  IndexType size_[ dimension+1 ];
477 
478  // all geometry types contained in the grid
479  std::vector< GeometryType > geomTypes_[ dimension+1 ];
480  };
481 
482 
483 
484  // AlbertaGridIndexSet::Insert
485  // ---------------------------
486 
487  template< int dim, int dimworld >
488  template< int codim >
489  struct AlbertaGridIndexSet< dim, dimworld >::Insert
490  {
491  static void apply ( const Alberta::Element *const element,
492  AlbertaGridIndexSet< dim, dimworld > &indexSet )
493  {
494  int *const array = indexSet.indices_[ codim ];
495  IndexType &size = indexSet.size_[ codim ];
496 
497  for( int i = 0; i < Alberta::NumSubEntities< dim, codim >::value; ++i )
498  {
499  int &index = array[ indexSet.dofNumbering_( element, codim, i ) ];
500  if( index < 0 )
501  index = size++;
502  }
503  }
504  };
505 
506 
507 
508  // AlbertaGridIdSet
509  // ----------------
510 
512  template< int dim, int dimworld >
513  class AlbertaGridIdSet
514  : public IdSet< AlbertaGrid< dim, dimworld >, AlbertaGridIdSet< dim, dimworld >, unsigned int >
515  {
516  typedef AlbertaGridIdSet< dim, dimworld > This;
517  typedef IdSet< AlbertaGrid< dim, dimworld >, This, unsigned int > Base;
518 
519  friend class AlbertaGrid< dim, dimworld >;
520 
521  public:
523  typedef typename Base::IdType IdType;
524 
525  private:
527 
528  static const int dimension = Grid::dimension;
529 
531 
532  // create id set, only allowed for AlbertaGrid
533  AlbertaGridIdSet ( const HierarchicIndexSet &hIndexSet )
534  : hIndexSet_( hIndexSet )
535  {}
536 
537  public:
539  template< class Entity >
540  IdType id ( const Entity &e ) const
541  {
542  const int codim = Entity::codimension;
543  return id< codim >( e );
544  }
545 
547  template< int codim >
548  IdType id ( const typename Grid::template Codim< codim >::Entity &e ) const
549  {
550  assert( (codim >= 0) && (codim <= dimension) );
551  const IdType index = hIndexSet_.index( e );
552  return (index << 2) | IdType( codim );
553  }
554 
556  IdType subId ( const typename Grid::template Codim< 0 >::Entity &e, int i, unsigned int subcodim ) const
557  {
558  assert( int( subcodim ) <= dimension );
559  const IdType index = hIndexSet_.subIndex( e, i, subcodim );
560  return (index << 2) | IdType( subcodim );
561  }
562 
563  template< int codim >
564  IdType subId ( const typename Grid::template Codim< codim >::Entity &e, int i, unsigned int subcodim ) const
565  {
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 );
569  }
570 
571  template< class Entity >
572  IdType subId ( const Entity &e, int i, unsigned int subcodim ) const
573  {
574  return subId< Entity::codimension >( e, i, subcodim );
575  }
576 
577  private:
578  // prohibit copying
579  AlbertaGridIdSet ( const This & );
580 
581  const HierarchicIndexSet &hIndexSet_;
582  };
583 
584 } // namespace Dune
585 
586 #endif // #if HAVE_ALBERTA
587 
588 #endif // #ifndef DUNE_ALBERTAGRIDINDEXSETS_HH
Base::IdType IdType
export type of id
Definition: albertagrid/indexsets.hh:523
Know your own codimension.
Definition: common/entity.hh:99
IndexType size(const GeometryType &type) const
return size of set for given GeometryType
Definition: albertagrid/indexsets.hh:115
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: albertagrid/indexsets.hh:556
Definition: albertagrid/gridfamily.hh:81
IndexType size(const GeometryType &type) const
Definition: albertagrid/indexsets.hh:407
Dune::IndexStack< int, 100000 > IndexStack
Definition: albertagrid/indexsets.hh:25
int size(int codim) const
Definition: dofadmin.hh:157
static ReturnImplementationType< InterfaceType >::ImplementationType & getRealImplementation(InterfaceType &i)
return real implementation of interface class
Definition: common/grid.hh:1223
IndexType size(int codim) const
return size of set
Definition: albertagrid/indexsets.hh:121
Wrapper class for entities.
Definition: common/entity.hh:56
void preAdapt()
Definition: albertagrid/indexsets.hh:154
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:178
void update(const Iterator &begin, const Iterator &end)
Definition: albertagrid/indexsets.hh:425
Index Set Interface base class.
Definition: common/grid.hh:359
IndexType subIndex(const ElementInfo &elementInfo, int i, unsigned int codim) const
Definition: albertagrid/indexsets.hh:134
const std::vector< GeometryType > & geomTypes(int codim) const
Definition: albertagrid/indexsets.hh:418
bool contains(const Entity &entity) const
Definition: albertagrid/indexsets.hh:362
Provides an index stack that supplies indices for element numbering for a grid (i.e. AlbertaGrid and ALUGrid)
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:97
Alberta::HierarchyDofNumbering< dimension > DofNumbering
Definition: albertagrid/indexsets.hh:53
IdTypeImp IdType
Type used to represent an id.
Definition: indexidset.hh:406
const Element * element() const
Definition: elementinfo.hh:781
~AlbertaGridIndexSet()
Definition: albertagrid/indexsets.hh:355
Alberta::ElementInfo< dimension > ElementInfo
Definition: albertagrid/indexsets.hh:333
IdType subId(const typename Grid::template Codim< codim >::Entity &e, int i, unsigned int subcodim) const
Definition: albertagrid/indexsets.hh:564
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:390
IndexStack * currentIndexStack
Definition: indexsets.cc:17
IndexTypeImp IndexType
The type used for the indices.
Definition: indexidset.hh:85
Provides base classes for index and id sets.
Base::IndexType IndexType
Definition: albertagrid/indexsets.hh:329
InitEntityNumber(IndexStack &indexStack)
Definition: albertagrid/indexsets.hh:218
AlbertaGrid< dim, dimworld > Grid
Definition: albertagrid/indexsets.hh:45
IndexType size(int codim) const
Definition: albertagrid/indexsets.hh:412
AlbertaGridFamily< dim, dimworld > GridFamily
Definition: albertagrid/indexsets.hh:46
IdType subId(const Entity &e, int i, unsigned int subcodim) const
Definition: albertagrid/indexsets.hh:572
void create()
Definition: indexsets.cc:146
Definition: albertagrid/gridfamily.hh:51
Definition: albertagrid/indexsets.hh:213
provides the GridFamily for AlbertaGrid
int size() const
return maxIndex which is also the
Definition: indexstack.hh:77
AlbertaGridIndexSet(const DofNumbering &dofNumbering)
Definition: albertagrid/indexsets.hh:343
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: albertagrid/indexsets.hh:548
[ provides Dune::Grid ]
Definition: agrid.hh:137
static const int dimension
Definition: albertagrid/indexsets.hh:50
static const int dimension
Definition: albertagrid/gridfamily.hh:87
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
Alberta::HierarchyDofNumbering< dimension > DofNumbering
Definition: albertagrid/indexsets.hh:334
Alberta::ElementInfo< dimension > ElementInfo
Definition: albertagrid/indexsets.hh:52
provides a wrapper for ALBERTA's el_info structure
static const int dimension
Definition: albertagrid/indexsets.hh:331
Definition: albertagrid/gridfamily.hh:96
IndexType subIndex(const Alberta::Element *element, int i, unsigned int codim) const
obtain hierarchic subindex
Definition: albertagrid/indexsets.hh:146
Alberta::IndexStack IndexStack
Definition: albertagrid/indexsets.hh:74
static const int dimension
Definition: agrid.hh:177
AlbertaGrid< dim, dimworld > Grid
Definition: albertagrid/indexsets.hh:327
ALBERTA EL Element
Definition: misc.hh:61
static const bool supportsAdaptationData
Definition: dofvector.hh:185
const std::vector< GeometryType > & geomTypes(int codim) const
return geometry types this set has indices for
Definition: albertagrid/indexsets.hh:128
void postAdapt()
Definition: albertagrid/indexsets.hh:164
bool contains(const Entity &) const
return true if entity is contained in set
Definition: albertagrid/indexsets.hh:78
void release()
Definition: albertagrid/indexsets.hh:175
Different resources needed by all grid implementations.
IndexType index(const typename Traits::template Codim< cc >::Entity &entity) const
return hierarchic index of given entity
Definition: albertagrid/indexsets.hh:88
Definition: alugrid/common/declaration.hh:18
T getIndex()
restore index from stack or create new index
Definition: indexstack.hh:137
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 write(const std::string &filename) const
Definition: indexsets.cc:160
Base::IndexType IndexType
Definition: albertagrid/indexsets.hh:48
void read(const std::string &filename)
Definition: indexsets.cc:153
IndexType index(const typename Traits::template Codim< cc >::Entity &entity) const
return hierarchic index of given entity
Definition: albertagrid/indexsets.hh:381
IdType id(const Entity &e) const
Get id of an entity. This method is simpler to use than the one below.
Definition: albertagrid/indexsets.hh:540
hierarchic index set of AlbertaGrid
Definition: albertagrid/gridfamily.hh:63
int subEntity() const
obtain number of the subentity within the element (in ALBERTA numbering)
Definition: albertagrid/entity.hh:124
Definition: albertagrid/entity.hh:45
Definition: indexstack.hh:23
Element * el() const
Definition: elementinfo.hh:797
const ElementInfo & elementInfo() const
Definition: albertagrid/entity.hh:106