dune-alugrid  2.6-git
indexsets.hh
Go to the documentation of this file.
1 #ifndef DUNE_ALU3DGRIDINDEXSETS_HH
2 #define DUNE_ALU3DGRIDINDEXSETS_HH
3 
4 #include <vector>
5 
6 #include <dune/common/stdstreams.hh>
7 #include <dune/common/bigunsignedint.hh>
8 #include <dune/common/hash.hh>
9 
10 #include <dune/grid/common/grid.hh>
11 #include <dune/grid/common/indexidset.hh>
12 
13 #include "alu3dinclude.hh"
14 #include "topology.hh"
15 #include "alu3diterators.hh"
16 
17 namespace Dune
18 {
19 
20  // External Forward Declarations
21  // -----------------------------
22 
23  template<int dim, int dimworld, ALU3dGridElementType, class >
24  class ALU3dGrid;
25 
26  template<int cd, int dim, class GridImp>
27  class ALU3dGridEntity;
28 
29 
30 
31  // ALU3dGridHierarchicIndexSet
32  // ---------------------------
33 
35  template<int dim, int dimworld, ALU3dGridElementType elType, class Comm >
37  : public IndexSet< ALU3dGrid< dim, dimworld, elType, Comm >, ALU3dGridHierarchicIndexSet< dim, dimworld, elType, Comm > >
38  {
40 
42 
43  friend class ALU3dGrid<dim, dimworld, elType, Comm >;
44 
45  // constructor
47  : grid_( grid )
48  {}
49 
50  public:
51  typedef typename GridType::Traits::template Codim<0>::Entity EntityCodim0Type;
52 
54  template <class EntityType>
55  int index (const EntityType & ep) const
56  {
57  enum { cd = EntityType :: codimension };
58  return index<cd>(ep);
59  }
60 
62  template< int codim >
63  int index ( const typename GridType::Traits::template Codim< codim >::Entity &entity ) const
64  {
65  return GridType::getRealImplementation( entity ).getIndex();
66  }
67 
68  template< class Entity >
69  int subIndex ( const Entity &entity, int i, unsigned int codim ) const
70  {
71  return subIndex< Entity::codimension >( entity, i, codim );
72  }
73 
75  template< int cd >
76  int subIndex ( const typename GridType::Traits::template Codim< cd >::Entity &e, int i, unsigned int codim ) const
77  {
78  // call method subIndex on real implementation
79  return GridType::getRealImplementation( e ).subIndex( i, codim );
80  }
81 
84  int size ( GeometryType type ) const
85  {
86  if( elType == tetra && !type.isSimplex() ) return 0;
87  if( elType == hexa && !type.isCube() ) return 0;
88  // return size of hierarchic index set
89  return this->size(GridType::dimension-type.dim());
90  }
91 
93  int size ( int codim ) const
94  {
95  // return size of hierarchic index set
96  return grid_.hierSetSize(codim);
97  }
98 
100  const std::vector<GeometryType>& geomTypes (int codim) const
101  {
102  return grid_.geomTypes(codim);
103  }
104 
106  template <class EntityType>
107  bool contains (const EntityType &) const { return true; }
108 
109  private:
110  // our Grid
111  const GridType & grid_;
112  };
113 
118 
119  class ALUMacroKey : public ALU3DSPACE Key4<int>
120  {
121  typedef int A;
122  typedef ALUMacroKey ThisType;
123  typedef ALU3DSPACE Key4<A> BaseType;
124 
125  public:
126  ALUMacroKey() : BaseType(-1,-1,-1,-1) {}
127  ALUMacroKey(const A&a,const A&b,const A&c,const A&d) : BaseType(a,b,c,d) {}
128  ALUMacroKey(const ALUMacroKey & org ) : BaseType(org) {}
130  {
131  BaseType::operator = (org);
132  return *this;
133  }
134 
135  bool operator == (const ALUMacroKey & org) const
136  {
137  return ( (this->_a == org._a) &&
138  (this->_b == org._b) &&
139  (this->_c == org._c) &&
140  (this->_d == org._d) );
141  }
142 
143  // operator < is already implemented in BaseType
144  bool operator > (const ALUMacroKey & org) const
145  {
146  return ( (!this->operator == (org)) && (!this->operator <(org)) );
147  }
148 
149 
150  void extractKey(std::vector<int> &key) const
151  {
152  alugrid_assert ( key.size() == 4 );
153  key[0] = this->_a;
154  key[1] = this->_b;
155  key[2] = this->_c;
156  key[3] = this->_d;
157  }
158 
159  void print(std::ostream & out) const
160  {
161  out << "[" << this->_a << "," << this->_b << "," << this->_c << "," << this->_d << "]";
162  }
163 
164  inline friend std::size_t hash_value(const ALUMacroKey& arg)
165  {
166  std::size_t seed = 0;
167  hash_combine(seed,arg._a);
168  hash_combine(seed,arg._b);
169  hash_combine(seed,arg._c);
170  hash_combine(seed,arg._d);
171  return seed;
172  }
173  };
174 
175  template <class MacroKeyImp>
176  class ALUGridId
177  {
178  MacroKeyImp key_;
179  int nChild_;
180  int codimLevel_;
181 
182  // this means that only up to 300000000 entities are allowed
183  static constexpr int codimOffset = 300000000 ;
184 
185  public:
186  ALUGridId() : key_()
187  , nChild_(-1)
188  , codimLevel_(-1)
189  {}
190 
191  explicit ALUGridId(const MacroKeyImp & key, const int nChild , const int codim, const int level)
192  : key_(key) , nChild_(nChild)
193  , codimLevel_( codim * codimOffset + level )
194  {}
195 
196  ALUGridId(const ALUGridId & org )
197  : key_(org.key_)
198  , nChild_(org.nChild_)
199  , codimLevel_(org.codimLevel_)
200  {}
201 
203  {
204  key_ = org.key_;
205  nChild_ = org.nChild_;
206  codimLevel_ = org.codimLevel_;
207  return *this;
208  }
209 
210  bool operator == (const ALUGridId & org) const
211  {
212  return equals(org);
213  }
214 
215  bool operator != (const ALUGridId & org) const
216  {
217  return ! equals(org);
218  }
219 
220  bool operator <= (const ALUGridId & org) const
221  {
222  if(equals(org)) return true;
223  else return lesser(org);
224  }
225 
226  bool operator >= (const ALUGridId & org) const
227  {
228  if(equals(org)) return true;
229  else return ! lesser(org);
230  }
231 
232  bool operator < (const ALUGridId & org) const
233  {
234  return lesser(org);
235  }
236 
237  bool operator > (const ALUGridId & org) const
238  {
239  return (!equals(org) && ! lesser(org));
240  }
241 
242  const MacroKeyImp & getKey() const { return key_; }
243  int nChild() const { return nChild_; }
244  int codim() const { return codimLevel_ / codimOffset ; }
245  int level() const { return codimLevel_ % codimOffset ; }
246 
247  bool isValid () const
248  {
249  return ( (nChild_ >= 0) && (codimLevel_ >= 0) );
250  }
251 
252  void reset()
253  {
254  nChild_ = -1;
255  codimLevel_ = -1;
256  }
257 
258  void print(std::ostream & out) const
259  {
260  out << "(" << getKey() << "," << nChild_ << "," << codimLevel_ << ")";
261  }
262 
263  inline friend std::size_t hash_value(const ALUGridId& arg)
264  {
265  std::size_t seed = hash<MacroKeyImp>()(arg.getKey());
266  hash_combine(seed,arg.nChild_);
267  hash_combine(seed,arg.codimLevel_);
268  return seed;
269  }
270 
271  protected:
272  // returns true is the id is lesser then org
273  bool lesser(const ALUGridId & org) const
274  {
275  if(getKey() < org.getKey() ) return true;
276  if(getKey() > org.getKey() ) return false;
277  if(getKey() == org.getKey() )
278  {
279  if(nChild_ == org.nChild_)
280  {
281  return codimLevel_ < org.codimLevel_;
282  }
283  else
284  return nChild_ < org.nChild_;
285  }
286  alugrid_assert ( equals(org) );
287  return false;
288  }
289 
290  // returns true if this id equals org
291  bool equals(const ALUGridId & org) const
292  {
293  return ( (getKey() == org.getKey() ) && (nChild_ == org.nChild_)
294  && (codimLevel_ == org.codimLevel_) );
295  }
296  };
297 
298 } // drop out of namespace Dune, as hash definitions have to be done in global namespace
299 
301 DUNE_DEFINE_HASH(DUNE_HASH_TEMPLATE_ARGS(typename MacroKeyImp),DUNE_HASH_TYPE(Dune::ALUGridId<MacroKeyImp>))
302 
303 namespace Dune {
304 
305  inline std::ostream& operator<< (std::ostream& s, const ALUMacroKey & key)
306  {
307  key.print(s);
308  return s;
309  }
310 
311  template <class KeyImp>
312  inline std::ostream& operator<< (std::ostream& s, const ALUGridId<KeyImp> & id)
313  {
314  id.print(s);
315  return s;
316  }
317 
318 
319 
320  // ALU3dGlobalIdSet
321  // ----------------
322 
323  template<int dim, int dimworld, ALU3dGridElementType elType, class Comm >
324  class ALU3dGridGlobalIdSet
325  : public IdSet< ALU3dGrid< dim, dimworld, elType, Comm >, ALU3dGridGlobalIdSet< dim, dimworld, elType, Comm >,
326  typename ALU3dGrid< dim, dimworld, elType, Comm >::Traits::GlobalIdType >,
328  {
329  typedef ALU3dGrid< dim, dimworld, elType, Comm > GridType;
330  typedef typename GridType::HierarchicIndexSet HierarchicIndexSetType;
331 
332  typedef ALU3dImplTraits< elType, Comm > ImplTraitsType;
333  typedef typename ImplTraitsType::IMPLElementType IMPLElementType;
334  typedef typename ImplTraitsType::GEOElementType GEOElementType;
335  typedef typename ImplTraitsType::GEOFaceType GEOFaceType;
336  typedef typename ImplTraitsType::GEOEdgeType GEOEdgeType;
337 
338  typedef typename ImplTraitsType::GitterImplType GitterImplType;
339 
340  typedef typename ImplTraitsType::HElementType HElementType;
341  typedef typename ImplTraitsType::HFaceType HFaceType;
342  typedef typename ImplTraitsType::HEdgeType HEdgeType;
343  typedef typename ImplTraitsType::VertexType VertexType;
344  typedef typename ImplTraitsType::HBndSegType HBndSegType;
345 
346  typedef EntityCount< elType > EntityCountType;
347 
348  using ALU3DSPACE AdaptRestrictProlongType::postRefinement;
349  using ALU3DSPACE AdaptRestrictProlongType::preCoarsening;
350 
351  public:
352  typedef typename GridType::Traits::GlobalIdType IdType;
353 
354  private:
355  typedef ALUMacroKey MacroKeyType;
356 
357  typedef ALUGridId < MacroKeyType > MacroIdType;
358  enum { numCodim = 4 }; // we are always using the 3d grid here
359 
360  typedef typename GridType::Traits::template Codim<0>::Entity EntityCodim0Type;
361 
362  private:
363  mutable std::map< int , IdType > ids_[ numCodim ];
364 
365  // our Grid
366  const GridType & grid_;
367 
368  // the hierarchicIndexSet
369  const HierarchicIndexSetType & hset_;
370 
371  int vertexKey_[4];
372 
373  enum { startOffSet_ = 0 };
374 
375  public:
376 
379  using IdSet < GridType , ALU3dGridGlobalIdSet, IdType > :: subId;
380 
382  ALU3dGridGlobalIdSet(const GridType & grid)
383  : grid_(grid), hset_(grid.hierarchicIndexSet())
384  {
385  if(elType == hexa)
386  {
387  // see dune/alugrid/impl/serial/gitter_mgb.cc
388  // InsertUniqueHexa
389  const int vxKey[4] = {0,1,3,4};
390  for(int i=0; i<4; i++) vertexKey_[i] = vxKey[i];
391  }
392  else
393  {
394  alugrid_assert ( elType == tetra );
395  // see dune/alugrid/impl/serial/gitter_mgb.cc
396  // InsertUniqueTetra
397  const int vxKey[4] = {0,1,2,3};
398  for(int i=0; i<4; i++) vertexKey_[i] = vxKey[i];
399  }
400 
401  // setup the id set
402  buildIdSet();
403  }
404 
405  virtual ~ALU3dGridGlobalIdSet() {}
406 
407  // update id set after adaptation
408  void updateIdSet()
409  {
410  // to be revised
411  buildIdSet();
412  }
413 
414  // print all ids
415  void print () const
416  {
417  for(int i=0 ;i<numCodim; ++i)
418  {
419  std::cout << "*****************************************************\n";
420  std::cout << "Ids for codim " << i << "\n";
421  std::cout << "*****************************************************\n";
422  for(unsigned int k=0; k<ids_[i].size(); ++k)
423  {
424  std::cout << "Item[" << i << "," << k <<"] has id " << ids_[i][k] << "\n";
425  }
426  std::cout << "\n\n\n";
427  }
428  }
429 
430  template <class IterType>
431  void checkId(const IdType & macroId, const IterType & idIter) const //int codim , unsigned int num ) const
432  {
433 
434  IdType id = getId(macroId);
435  for(int i=0 ;i<numCodim; ++i)
436  {
437  typedef typename std::map<int,IdType>::iterator IteratorType;
438  IteratorType end = ids_[i].end();
439  for(IteratorType it = ids_[i].begin(); it != end; ++it)
440  {
441  if(idIter == it) continue;
442  const IdType & checkMId = (*it).second;
443  IdType checkId = getId(checkMId);
444  if( id == checkId )
445  {
446  //std::cout << "Check(codim,num = " << codim<< "," << num <<") failed for k="<<k << " codim = " << i << "\n";
447  std::cout << id << " equals " << checkId << std::endl;
448  std::cout << idIter->first << " != " << it->first << std::endl;
449  alugrid_assert ( id != checkId );
450  DUNE_THROW(GridError," " << id << " equals " << checkId << "\n");
451  }
452  else
453  {
454  bool lesser = (id < checkId);
455  bool greater = (id > checkId);
456  alugrid_assert ( lesser != greater );
457  if( lesser == greater )
458  {
459  alugrid_assert ( lesser != greater );
460  DUNE_THROW(GridError," lesser equals greater of one id ");
461  }
462  }
463  }
464  }
465  }
466 
467  // check id set for uniqueness
468  void uniquenessCheck() const
469  {
470  for(int i=0 ;i<numCodim; i++)
471  {
472  typedef typename std::map<int,IdType>::iterator IteratorType;
473  IteratorType end = ids_[i].end();
474  for(IteratorType it = ids_[i].begin(); it != end; ++it)
475  {
476  const IdType & id = (*it).second;
477  if( id.isValid() )
478  checkId(id,it);
479  }
480  }
481  }
482 
483  void setChunkSize( int chunkSize )
484  {
485  }
486 
487  // creates the id set
488  void buildIdSet ()
489  {
490  for(int i=0; i<numCodim; ++i)
491  {
492  ids_[i].clear();
493  }
494 
495  GitterImplType &gitter = grid_.myGrid();
496 
497  // all interior and border vertices
498  {
499  typename ALU3DSPACE AccessIterator< VertexType >::Handle fw( gitter.container() );
500  for( fw.first (); !fw.done(); fw.next() )
501  {
502  int idx = fw.item().getIndex();
503  ids_[3][idx] = buildMacroVertexId( fw.item() );
504  }
505  }
506 
507  // all ghost vertices
508  {
509  typedef typename ALU3DSPACE ALU3dGridLevelIteratorWrapper< 3, Ghost_Partition, Comm > IteratorType;
510  IteratorType fw (grid_ , 0 , grid_.nlinks() );
511  typedef typename IteratorType :: val_t val_t;
512  for (fw.first () ; ! fw.done () ; fw.next ())
513  {
514  val_t & item = fw.item();
515  alugrid_assert ( item.first );
516  VertexType & vx = * (item.first);
517  int idx = vx.getIndex();
518  ids_[3][idx] = buildMacroVertexId( vx );
519  }
520  }
521 
522  {
523  // create ids for all macro edges
524  {
525  typename ALU3DSPACE AccessIterator< HEdgeType >::Handle w( gitter.container() );
526  for (w.first(); !w.done(); w.next())
527  {
528  int idx = w.item().getIndex();
529  ids_[2][idx] = buildMacroEdgeId( w.item() );
530  buildEdgeIds( w.item() , ids_[2][idx] , startOffSet_ );
531  }
532  }
533 
534  // all ghost edges
535  {
536  typedef typename ALU3DSPACE ALU3dGridLevelIteratorWrapper< 2, Ghost_Partition, Comm > IteratorType;
537  IteratorType fw( grid_, 0, grid_.nlinks() );
538  typedef typename IteratorType :: val_t val_t;
539  for (fw.first () ; ! fw.done () ; fw.next ())
540  {
541  val_t & item = fw.item();
542  alugrid_assert ( item.first );
543  HEdgeType & edge = * (item.first);
544  int idx = edge.getIndex();
545 
546  ids_[2][idx] = buildMacroEdgeId( edge );
547  buildEdgeIds( edge , ids_[2][idx] , startOffSet_ );
548  }
549  }
550  }
551 
552 
553  // for all macro faces and all children
554  {
555  typename ALU3DSPACE AccessIterator< HFaceType >::Handle w( gitter.container() );
556  for (w.first () ; ! w.done () ; w.next ())
557  {
558  int idx = w.item().getIndex();
559  ids_[1][idx] = buildMacroFaceId( w.item() );
560  buildFaceIds( w.item() , ids_[1][idx] , startOffSet_ );
561  }
562  }
563 
564  // all ghost faces
565  if( grid_.comm().size() > 1 )
566  {
567  typedef typename ALU3DSPACE ALU3dGridLevelIteratorWrapper< 1, Ghost_Partition, Comm > IteratorType;
568  IteratorType fw (grid_ , 0 , grid_.nlinks() );
569  typedef typename IteratorType :: val_t val_t;
570  for (fw.first () ; ! fw.done () ; fw.next ())
571  {
572  val_t & item = fw.item();
573  alugrid_assert ( item.first );
574  HFaceType & face = * (item.first);
575  int idx = face.getIndex();
576  ids_[1][idx] = buildMacroFaceId( face );
577  buildFaceIds( face , ids_[1][idx] , startOffSet_ );
578  }
579  }
580 
581  // for all macro elements and all internal entities
582  {
583  typename ALU3DSPACE AccessIterator< HElementType >::Handle w( gitter.container() );
584  for (w.first () ; ! w.done () ; w.next ())
585  {
586  int idx = w.item().getIndex();
587  ids_[0][idx] = buildMacroElementId( w.item() );
588  buildElementIds( w.item() , ids_[0][idx] , startOffSet_ );
589  }
590  }
591 
592  // all ghost elements
593  if( grid_.comm().size() > 1 )
594  {
595  typedef typename ALU3DSPACE ALU3dGridLevelIteratorWrapper< 0, Ghost_Partition, Comm > IteratorType;
596  IteratorType fw (grid_ , 0 , grid_.nlinks() );
597  typedef typename IteratorType :: val_t val_t;
598  for (fw.first () ; ! fw.done () ; fw.next ())
599  {
600  val_t & item = fw.item();
601  alugrid_assert ( item.second );
602  HElementType & elem = * ( item.second->getGhost().first );
603  int idx = elem.getIndex();
604  ids_[0][idx] = buildMacroElementId( elem );
605  buildElementIds( elem , ids_[0][idx] , startOffSet_ );
606  }
607  }
608 
609  // check uniqueness of id only in serial, because
610  // in parallel some faces and edges of ghost exists more than once
611  // but have the same id, but not the same index, there for the check
612  // will fail for ghost elements
613  // be carefull with this check, it's complexity is O(N^2)
614 #ifdef ALUGRID_CHECK_GLOBALIDSET_UNIQUENESS
615 #warning "GlobalIdSet uniqueness check enabled!"
616  uniquenessCheck();
617 #endif
618  }
619 
620  IdType buildMacroVertexId(const VertexType & item )
621  {
622  int vx[4] = { item.ident(), -1, -1, -1};
623  enum { codim = 3 };
624  MacroKeyType key(vx[0],vx[1],vx[2],vx[3]);
625  return MacroIdType(key, 1, codim, startOffSet_ );
626  }
627 
628  IdType buildMacroEdgeId(const HEdgeType & item )
629  {
630  const GEOEdgeType & edge = static_cast<const GEOEdgeType &> (item);
631  int vx[4] = {-1,-1,-1,-1};
632  for(int i=0; i<2; ++i)
633  {
634  vx[i] = edge.myvertex(i)->ident();
635  }
636 
637  enum { codim = 2 };
638  MacroKeyType key(vx[0],vx[1],vx[2],vx[3]);
639  return MacroIdType(key, 1, codim, startOffSet_ );
640  }
641 
642  IdType buildMacroFaceId(const HFaceType & item )
643  {
644  const GEOFaceType & face = static_cast<const GEOFaceType &> (item);
645  int vx[4] = {-1,-1,-1,-1};
646  for(int i=0; i<3; ++i)
647  {
648  vx[i] = face.myvertex(i)->ident();
649  }
650 
651  enum { codim = 1 };
652  MacroKeyType key(vx[0],vx[1],vx[2],vx[3]);
653  return MacroIdType(key,1, codim, startOffSet_ );
654  }
655 
656  IdType buildMacroElementId(const HElementType & item )
657  {
658  const GEOElementType & elem = static_cast<const GEOElementType &> (item);
659  int vx[4] = {-1,-1,-1,-1};
660  for(int i=0; i<4; ++i)
661  {
662  vx[i] = elem.myvertex(vertexKey_[i])->ident();
663  }
664  enum { codim = 0 };
665  MacroKeyType key(vx[0],vx[1],vx[2],vx[3]);
666  return MacroIdType(key,1, codim, startOffSet_ );
667  }
668 
669  template <int cd, class Item>
670  IdType createId(const Item& item , const IdType& creatorId , int nChild )
671  {
672  alugrid_assert ( creatorId.isValid() );
673 
674  // we have up to 12 internal hexa faces, therefore need 100 offset
675  enum { childOffSet = (dim == 2) ? 4 : ((cd == 1) && (elType == hexa)) ? 16 : 8 };
676  alugrid_assert ( nChild < childOffSet );
677 
678  const int newChild = ((creatorId.codim()+1) * creatorId.nChild() * childOffSet ) + nChild;
679 
680  IdType newId( creatorId.getKey() , newChild , cd, creatorId.level() + 1 );
681  alugrid_assert( newId != creatorId );
682  return newId;
683  }
684 
685  // build ids for all children of this element
686  void buildElementIds(const HElementType & item , const IdType & macroId , int nChild)
687  {
688  enum { codim = 0 };
689  ids_[codim][item.getIndex()] = createId<codim>(item,macroId,nChild);
690 
691  const IdType & itemId = ids_[codim][item.getIndex()];
692 
693  buildInteriorElementIds(item,itemId);
694  }
695 
696  // build ids for all children of this element
697  void buildInteriorElementIds(const HElementType & item , const IdType & fatherId)
698  {
699  alugrid_assert ( fatherId.isValid() );
700 
701  // build id for inner vertex
702  {
703  const VertexType * v = item.innerVertex() ;
704  // for tetras there is no inner vertex, therefore check
705  if(v) buildVertexIds(*v,fatherId );
706  }
707 
708  // build edge ids for all inner edges
709  {
710  int inneredge = startOffSet_;
711  for(const HEdgeType * e = item.innerHedge () ; e ; e = e->next ())
712  {
713  buildEdgeIds(*e,fatherId,inneredge);
714  ++inneredge;
715  }
716  }
717 
718  // build face ids for all inner faces
719  {
720  int innerface = startOffSet_;
721  for(const HFaceType * f = item.innerHface () ; f ; f = f->next ())
722  {
723  buildFaceIds(*f,fatherId,innerface);
724  ++innerface;
725  }
726  }
727 
728  // build ids of all children
729  {
730  int numChild = startOffSet_;
731  for(const HElementType * child = item.down(); child; child =child->next() )
732  {
733  alugrid_assert ( numChild == child->nChild() );
734  buildElementIds(*child, fatherId, numChild);
735  ++numChild;
736  }
737  }
738  }
739 
740  // build ids for all children of this face
741  void buildFaceIds(const HFaceType & face, const IdType & fatherId , int innerFace )
742  {
743  enum { codim = 1 };
744  ids_[codim][face.getIndex()] = createId<codim>(face,fatherId,innerFace);
745  const IdType & faceId = ids_[codim][face.getIndex()];
746 
747  buildInteriorFaceIds(face,faceId);
748  }
749 
750  // build ids for all children of this face
751  void buildInteriorFaceIds(const HFaceType & face, const IdType & faceId)
752  {
753  alugrid_assert ( faceId.isValid () );
754 
755  // build id for inner vertex
756  {
757  const VertexType * v = face.innerVertex() ;
758  if(v) buildVertexIds(*v,faceId );
759  }
760 
761  // build ids for all inner edges
762  {
763  int inneredge = startOffSet_;
764  for (const HEdgeType * e = face.innerHedge () ; e ; e = e->next ())
765  {
766  buildEdgeIds(*e,faceId ,inneredge );
767  ++inneredge;
768  }
769  }
770 
771  // build ids for all child faces
772  {
773  int child = startOffSet_;
774  for(const HFaceType * f = face.down () ; f ; f = f->next ())
775  {
776  alugrid_assert ( child == f->nChild()+startOffSet_);
777  buildFaceIds(*f,faceId,child);
778  ++child;
779  }
780  }
781  }
782 
783  // build ids for all children of this edge
784  void buildEdgeIds(const HEdgeType & edge, const IdType & fatherId , int inneredge)
785  {
786  enum { codim = 2 };
787  ids_[codim][edge.getIndex()] = createId<codim>(edge,fatherId,inneredge);
788  const IdType & edgeId = ids_[codim][edge.getIndex()];
789  buildInteriorEdgeIds(edge,edgeId);
790  }
791 
792  void buildInteriorEdgeIds(const HEdgeType & edge, const IdType & edgeId)
793  {
794  alugrid_assert ( edgeId.isValid() );
795 
796  // build id for inner vertex
797  {
798  const VertexType * v = edge.innerVertex() ;
799  if(v) buildVertexIds(*v,edgeId );
800  }
801 
802  // build ids for all inner edges
803  {
804  int child = startOffSet_;
805  for (const HEdgeType * e = edge.down () ; e ; e = e->next ())
806  {
807  alugrid_assert ( child == e->nChild()+ startOffSet_ );
808  buildEdgeIds(*e,edgeId , child );
809  ++child;
810  }
811  }
812  }
813 
814  // build id for this vertex
815  void buildVertexIds(const VertexType & vertex, const IdType & fatherId )
816  {
817  enum { codim = 3 };
818  // inner vertex number is 1
819  ids_[codim][vertex.getIndex()] = createId<codim>(vertex,fatherId,1);
820  alugrid_assert ( ids_[codim][vertex.getIndex()].isValid() );
821  }
822 
823  friend class ALU3dGrid< dim, dimworld, elType, Comm >;
824 
825  const IdType & getId(const IdType & macroId) const
826  {
827  return macroId;
828  }
829 
830  public:
832  template <class EntityType>
833  IdType id (const EntityType & ep) const
834  {
835  enum { codim = ( dim == EntityType :: codimension ) ? 3 : EntityType :: codimension };
836  alugrid_assert ( ids_[codim].find( hset_.index(ep) ) != ids_[codim].end() );
837  const IdType & macroId = ids_[codim][hset_.index(ep)];
838  alugrid_assert ( macroId.isValid() );
839  return getId(macroId);
840  }
841 
843  template <int cd>
844  IdType id (const typename GridType:: template Codim<cd> :: Entity & ep) const
845  {
846  const unsigned int codim = ( dim == cd ) ? 3 : cd ;
847  alugrid_assert ( ids_[codim].find( hset_.index(ep) ) != ids_[codim].end() );
848  const IdType & macroId = ids_[codim][hset_.index(ep)];
849  alugrid_assert ( macroId.isValid() );
850  return getId(macroId);
851  }
852 
854  IdType subId ( const EntityCodim0Type &e, int i, unsigned int codim ) const
855  {
856  const int hIndex = hset_.subIndex( e, i, codim );
857  // idCodim is the codim used in the id storage which relates to the 3d grid
858  const unsigned int idCodim = ( dim == codim ) ? 3 : codim ;
859  alugrid_assert ( ids_[ idCodim ].find( hIndex ) != ids_[ idCodim ].end() );
860  const IdType &macroId = ids_[ idCodim ][ hIndex ];
861  alugrid_assert ( macroId.isValid() );
862  return getId( macroId );
863  }
864 
865  // create ids for refined elements
866  int postRefinement( HElementType & item )
867  {
868  {
869  enum { elCodim = 0 };
870  const IdType & fatherId = ids_[elCodim][item.getIndex()];
871  alugrid_assert ( fatherId.isValid() );
872  buildInteriorElementIds(item, fatherId );
873  }
874 
875  const IMPLElementType & elem = static_cast<const IMPLElementType &> (item);
876  for(int i=0; i<EntityCountType::numFaces; ++i)
877  {
878  enum { faceCodim = 1 };
879  const HFaceType & face = *( elem.myhface( i ) );
880  const IdType & id = ids_[faceCodim][face.getIndex()];
881  alugrid_assert ( id.isValid() );
882  buildInteriorFaceIds( face, id);
883  }
884 
885  {
886  for(int i=0; i<EntityCountType::numEdges; ++i)
887  {
888  enum { edgeCodim = 2 };
889  const HEdgeType & edge = *( elem.myhedge(i));
890  const IdType & id = ids_[edgeCodim][edge.getIndex()];
891  alugrid_assert ( id.isValid() );
892  buildInteriorEdgeIds(edge,id);
893  }
894  }
895  return 0;
896  }
897 
898  // dummy functions
899  int preCoarsening( HElementType & elem )
900  {
901  /*
902  const IdType & fatherId = ids_[0][item.getIndex()];
903 
904  removeElementIds(item,fatherId,item.nChild());
905 
906  for(int i=0; i<EntityCountType::numFaces; ++i)
907  BuildIds<dim,elType>::buildFace(*this,item,i,ids_[1]);
908 
909  for(int i=0; i<EntityCountType::numEdges; ++i)
910  {
911  const IMPLElementType & elem = static_cast<const IMPLElementType &> (item);
912  const HEdgeType & edge = *( elem.myhedge(i));
913  const HEdgeType * child = edge.down();
914  alugrid_assert ( child );
915  if( ids_[2][child->getIndex() ] > zero_ ) continue;
916  buildEdgeIds(edge,ids_[2][edge.getIndex()],0);
917  }
918 #ifdef ALUGRIDDEBUG
919  //uniquenessCheck();
920 #endif
921  */
922  return 0;
923  }
924 
925  // dummy functions
926  int preCoarsening ( HBndSegType & el ) { return 0; }
927 
929  int postRefinement ( HBndSegType & el ) { return 0; }
930 
931  };
932 
933  //***********************************************************
934  //
935  // --LocalIdSet
936  //
937  //***********************************************************
938 
940  template< int dim, int dimworld, ALU3dGridElementType elType, class Comm >
941  class ALU3dGridLocalIdSet
942  : public IdSet< ALU3dGrid< dim, dimworld, elType, Comm >, ALU3dGridLocalIdSet< dim, dimworld, elType, Comm >, int >,
944  {
945  typedef ALU3dGridLocalIdSet< dim, dimworld, elType, Comm > This;
946 
947  typedef ALU3dImplTraits< elType, Comm > ImplTraitsType;
948  typedef typename ImplTraitsType::HElementType HElementType;
949  typedef typename ImplTraitsType::HBndSegType HBndSegType;
950 
951  typedef ALU3dGrid< dim, dimworld, elType, Comm > GridType;
952  typedef typename GridType::HierarchicIndexSet HierarchicIndexSetType;
953 
954  // this means that only up to 300000000 entities are allowed
955  enum { codimOffSet = 300000000 };
956  typedef typename GridType::Traits::template Codim<0>::Entity EntityCodim0Type;
957 
958  // create local id set , only for the grid allowed
959  ALU3dGridLocalIdSet(const GridType & grid) : hset_(grid.hierarchicIndexSet())
960  {
961  for( int codim = 0; codim <= GridType::dimension; ++codim )
962  codimStart_[ codim ] = codim * codimOffSet;
963  }
964 
965  friend class ALU3dGrid< dim, dimworld, elType, Comm >;
966 
967  // fake method to have the same method like GlobalIdSet
968  void updateIdSet() {}
969 
970  using ALU3DSPACE AdaptRestrictProlongType :: postRefinement ;
971  using ALU3DSPACE AdaptRestrictProlongType :: preCoarsening ;
972 
973  public:
975  typedef int IdType;
976 
979  using IdSet < GridType , ALU3dGridLocalIdSet, IdType > :: subId;
980 
982  template <class EntityType>
983  int id (const EntityType & ep) const
984  {
985  enum { cd = EntityType :: codimension };
986  alugrid_assert ( hset_.size(cd) < codimOffSet );
987  return codimStart_[cd] + hset_.index(ep);
988  }
989 
991  template <int codim>
992  int id (const typename GridType:: template Codim<codim> :: Entity & ep) const
993  {
994  //enum { cd = EntityType :: codimension };
995  alugrid_assert ( hset_.size(codim) < codimOffSet );
996  return codimStart_[codim] + hset_.index(ep);
997  }
998 
1000  IdType subId ( const EntityCodim0Type &e, int i, unsigned int codim ) const
1001  {
1002  alugrid_assert ( hset_.size( codim ) < codimOffSet );
1003  return codimStart_[ codim ] + hset_.subIndex( e, i, codim );
1004  }
1005 
1006  // dummy functions
1007  int preCoarsening( HElementType & elem ) { return 0; }
1008  // create ids for refined elements
1009  int postRefinement( HElementType & item ) { return 0; }
1010 
1011  // dummy functions
1012  int preCoarsening ( HBndSegType & el ) { return 0; }
1013 
1015  int postRefinement ( HBndSegType & el ) { return 0; }
1016 
1017  void setChunkSize( int chunkSize ) {}
1018 
1019  private:
1020  // our HierarchicIndexSet
1021  const HierarchicIndexSetType & hset_;
1022 
1023  // store start of each codim numbers
1024  int codimStart_[ GridType::dimension+1 ];
1025  };
1026 
1027 } // end namespace Dune
1028 
1029 #endif // #ifndef DUNE_ALU3DGRIDINDEXSETS_HH
#define ALU3DSPACE
Definition: alu3dinclude.hh:24
DUNE_DEFINE_HASH(DUNE_HASH_TEMPLATE_ARGS(), DUNE_HASH_TYPE(Dune::ALUMacroKey)) DUNE_DEFINE_HASH(DUNE_HASH_TEMPLATE_ARGS(typename MacroKeyImp)
DUNE_HASH_TYPE(Dune::ALUGridId< MacroKeyImp >)) namespace Dune
Definition: indexsets.hh:301
#define alugrid_assert(EX)
Definition: alugrid_assert.hh:20
Gitter::AdaptRestrictProlong AdaptRestrictProlongType
Definition: alu3dinclude.hh:52
Definition: alu3dinclude.hh:80
@ hexa
Definition: topology.hh:12
@ tetra
Definition: topology.hh:12
std ::ostream & operator<<(std ::ostream &out, const ALU3dGridEntitySeed< cd, GridImp > &key)
print alugrid entity key to std::stream
Definition: entityseed.hh:372
[ provides Dune::Grid ]
Definition: alugrid/3d/grid.hh:463
int hierSetSize(int cd) const
Definition: grid_inline.hh:99
static const int dimension
Definition: alugrid/3d/grid.hh:524
const std::vector< GeometryType > & geomTypes(int codim) const
deliver all geometry types used in this grid
Definition: alugrid/3d/grid.hh:1141
hierarchic index set of ALU3dGrid
Definition: indexsets.hh:38
int size(GeometryType type) const
Definition: indexsets.hh:84
int size(int codim) const
return size of indexset, i.e. maxindex+1
Definition: indexsets.hh:93
bool contains(const EntityType &) const
return true because all entities are contained in this set
Definition: indexsets.hh:107
int index(const EntityType &ep) const
return hierarchic index of given entity
Definition: indexsets.hh:55
int index(const typename GridType::Traits::template Codim< codim >::Entity &entity) const
return hierarchic index of given entity
Definition: indexsets.hh:63
GridType::Traits::template Codim< 0 >::Entity EntityCodim0Type
Definition: indexsets.hh:51
int subIndex(const Entity &entity, int i, unsigned int codim) const
Definition: indexsets.hh:69
const std::vector< GeometryType > & geomTypes(int codim) const
deliver all geometry types used in this grid
Definition: indexsets.hh:100
int subIndex(const typename GridType::Traits::template Codim< cd >::Entity &e, int i, unsigned int codim) const
return subIndex i of given entity for subEntity with codim
Definition: indexsets.hh:76
Definition: indexsets.hh:120
ALUMacroKey & operator=(const ALUMacroKey &org)
Definition: indexsets.hh:129
void extractKey(std::vector< int > &key) const
Definition: indexsets.hh:150
bool operator==(const ALUMacroKey &org) const
Definition: indexsets.hh:135
void print(std::ostream &out) const
Definition: indexsets.hh:159
friend std::size_t hash_value(const ALUMacroKey &arg)
Definition: indexsets.hh:164
ALUMacroKey(const A &a, const A &b, const A &c, const A &d)
Definition: indexsets.hh:127
ALUMacroKey(const ALUMacroKey &org)
Definition: indexsets.hh:128
bool operator>(const ALUMacroKey &org) const
Definition: indexsets.hh:144
ALUMacroKey()
Definition: indexsets.hh:126
Definition: indexsets.hh:177
bool operator!=(const ALUGridId &org) const
Definition: indexsets.hh:215
bool isValid() const
Definition: indexsets.hh:247
int level() const
Definition: indexsets.hh:245
bool operator>=(const ALUGridId &org) const
Definition: indexsets.hh:226
int codim() const
Definition: indexsets.hh:244
void print(std::ostream &out) const
Definition: indexsets.hh:258
bool operator<=(const ALUGridId &org) const
Definition: indexsets.hh:220
bool operator<(const ALUGridId &org) const
Definition: indexsets.hh:232
friend std::size_t hash_value(const ALUGridId &arg)
Definition: indexsets.hh:263
void reset()
Definition: indexsets.hh:252
ALUGridId & operator=(const ALUGridId &org)
Definition: indexsets.hh:202
const MacroKeyImp & getKey() const
Definition: indexsets.hh:242
bool equals(const ALUGridId &org) const
Definition: indexsets.hh:291
ALUGridId(const ALUGridId &org)
Definition: indexsets.hh:196
bool lesser(const ALUGridId &org) const
Definition: indexsets.hh:273
bool operator==(const ALUGridId &org) const
Definition: indexsets.hh:210
bool operator>(const ALUGridId &org) const
Definition: indexsets.hh:237
int nChild() const
Definition: indexsets.hh:243
ALUGridId()
Definition: indexsets.hh:186
ALUGridId(const MacroKeyImp &key, const int nChild, const int codim, const int level)
Definition: indexsets.hh:191