dune-alugrid 3.0.0
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
17namespace 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
69 int subIndex ( const EntityCodim0Type &e, int i, unsigned int codim ) const
70 {
71 // call method subIndex on real implementation
72 return GridType::getRealImplementation( e ).subIndex( i, codim );
73 }
74
77 int size ( GeometryType type ) const
78 {
79 if( elType == tetra && !type.isSimplex() ) return 0;
80 if( elType == hexa && !type.isCube() ) return 0;
81 // return size of hierarchic index set
82 return this->size(GridType::dimension-type.dim());
83 }
84
86 int size ( int codim ) const
87 {
88 // return size of hierarchic index set
89 return grid_.hierSetSize(codim);
90 }
91
93 const std::vector<GeometryType>& geomTypes (int codim) const
94 {
95 return grid_.geomTypes(codim);
96 }
97
99 template <class EntityType>
100 bool contains (const EntityType &) const { return true; }
101
102 private:
103 // our Grid
104 const GridType & grid_;
105 };
106
111
112 class ALUMacroKey : public ALU3DSPACE Key4<int>
113 {
114 typedef int A;
115 typedef ALUMacroKey ThisType;
116 typedef ALU3DSPACE Key4<A> BaseType;
117
118 public:
119 ALUMacroKey() : BaseType(-1,-1,-1,-1) {}
120 ALUMacroKey(const A&a,const A&b,const A&c,const A&d) : BaseType(a,b,c,d) {}
121 ALUMacroKey(const ALUMacroKey & org ) : BaseType(org) {}
123 {
124 BaseType::operator = (org);
125 return *this;
126 }
127
128 bool operator == (const ALUMacroKey & org) const
129 {
130 return ( (this->_a == org._a) &&
131 (this->_b == org._b) &&
132 (this->_c == org._c) &&
133 (this->_d == org._d) );
134 }
135
136 // operator < is already implemented in BaseType
137 bool operator > (const ALUMacroKey & org) const
138 {
139 return ( (!this->operator == (org)) && (!this->operator <(org)) );
140 }
141
142
143 void extractKey(std::vector<int> &key) const
144 {
145 alugrid_assert ( key.size() == 4 );
146 key[0] = this->_a;
147 key[1] = this->_b;
148 key[2] = this->_c;
149 key[3] = this->_d;
150 }
151
152 void print(std::ostream & out) const
153 {
154 out << "[" << this->_a << "," << this->_b << "," << this->_c << "," << this->_d << "]";
155 }
156
157#ifdef HAVE_DUNE_HASH
158 inline friend std::size_t hash_value(const ALUMacroKey& arg)
159 {
160 std::size_t seed = 0;
161 hash_combine(seed,arg._a);
162 hash_combine(seed,arg._b);
163 hash_combine(seed,arg._c);
164 hash_combine(seed,arg._d);
165 return seed;
166 }
167#endif // HAVE_DUNE_HASH
168
169 };
170
171 template <class MacroKeyImp>
173 {
174 MacroKeyImp key_;
175 int nChild_;
176 int codim_;
177
178 public:
179 ALUGridId() : key_()
180 , nChild_(-1)
181 , codim_(-1)
182 {}
183
184 ALUGridId(const MacroKeyImp & key, int nChild , int cd)
185 : key_(key) , nChild_(nChild)
186 , codim_(cd)
187 {}
188
189 ALUGridId(const ALUGridId & org )
190 : key_(org.key_)
191 , nChild_(org.nChild_)
192 , codim_(org.codim_)
193 {}
194
196 {
197 key_ = org.key_;
198 nChild_ = org.nChild_;
199 codim_ = org.codim_;
200 return *this;
201 }
202
203 bool operator == (const ALUGridId & org) const
204 {
205 return equals(org);
206 }
207
208 bool operator != (const ALUGridId & org) const
209 {
210 return ! equals(org);
211 }
212
213 bool operator <= (const ALUGridId & org) const
214 {
215 if(equals(org)) return true;
216 else return lesser(org);
217 }
218
219 bool operator >= (const ALUGridId & org) const
220 {
221 if(equals(org)) return true;
222 else return ! lesser(org);
223 }
224
225 bool operator < (const ALUGridId & org) const
226 {
227 return lesser(org);
228 }
229
230 bool operator > (const ALUGridId & org) const
231 {
232 return (!equals(org) && ! lesser(org));
233 }
234
235 const MacroKeyImp & getKey() const { return key_; }
236 int nChild() const { return nChild_; }
237 int codim() const { return codim_; }
238
239 bool isValid () const
240 {
241 return ( (nChild_ >= 0) && (codim_ >= 0) );
242 }
243
244 void reset()
245 {
246 nChild_ = -1;
247 codim_ = -1;
248 }
249
250 void print(std::ostream & out) const
251 {
252 out << "(" << getKey() << "," << nChild_ << "," << codim_ << ")";
253 }
254
255#ifdef HAVE_DUNE_HASH
256
257 inline friend std::size_t hash_value(const ALUGridId& arg)
258 {
259 std::size_t seed = hash<MacroKeyImp>()(arg.getKey());
260 hash_combine(seed,arg.nChild());
261 hash_combine(seed,arg.codim());
262 return seed;
263 }
264
265#endif // HAVE_DUNE_HASH
266
267 protected:
268 // returns true is the id is lesser then org
269 bool lesser(const ALUGridId & org) const
270 {
271 if(getKey() < org.getKey() ) return true;
272 if(getKey() > org.getKey() ) return false;
273 if(getKey() == org.getKey() )
274 {
275 if(nChild_ == org.nChild_)
276 {
277 return codim_ < org.codim_;
278 }
279 else
280 return nChild_ < org.nChild_;
281 }
282 alugrid_assert ( equals(org) );
283 return false;
284 }
285
286 // returns true if this id equals org
287 bool equals(const ALUGridId & org) const
288 {
289 return ( (getKey() == org.getKey() ) && (nChild_ == org.nChild_)
290 && (codim_ == org.codim_) );
291 }
292 };
293
294} // drop out of namespace Dune, as hash definitions have to be done in global namespace
295
296#if HAVE_DUNE_HASH
297DUNE_DEFINE_HASH(DUNE_HASH_TEMPLATE_ARGS(),DUNE_HASH_TYPE(Dune::ALUMacroKey))
298DUNE_DEFINE_HASH(DUNE_HASH_TEMPLATE_ARGS(typename MacroKeyImp),DUNE_HASH_TYPE(Dune::ALUGridId<MacroKeyImp>))
299#endif
300
301namespace Dune {
302
303 inline std::ostream& operator<< (std::ostream& s, const ALUMacroKey & key)
304 {
305 key.print(s);
306 return s;
307 }
308
309 template <class KeyImp>
310 inline std::ostream& operator<< (std::ostream& s, const ALUGridId<KeyImp> & id)
311 {
312 id.print(s);
313 return s;
314 }
315
316
317
318 // ALU3dGlobalIdSet
319 // ----------------
320
321 template<int dim, int dimworld, ALU3dGridElementType elType, class Comm >
323 : public IdSet< ALU3dGrid< dim, dimworld, elType, Comm >, ALU3dGridGlobalIdSet< dim, dimworld, elType, Comm >,
324 typename ALU3dGrid< dim, dimworld, elType, Comm >::Traits::GlobalIdType >,
325 public ALU3DSPACE AdaptRestrictProlongType
326 {
329
330 typedef ALU3dImplTraits< elType, Comm > ImplTraitsType;
331 typedef typename ImplTraitsType::IMPLElementType IMPLElementType;
332 typedef typename ImplTraitsType::GEOElementType GEOElementType;
333 typedef typename ImplTraitsType::GEOFaceType GEOFaceType;
334 typedef typename ImplTraitsType::GEOEdgeType GEOEdgeType;
335
336 typedef typename ImplTraitsType::GitterImplType GitterImplType;
337
338 typedef typename ImplTraitsType::HElementType HElementType;
339 typedef typename ImplTraitsType::HFaceType HFaceType;
340 typedef typename ImplTraitsType::HEdgeType HEdgeType;
341 typedef typename ImplTraitsType::VertexType VertexType;
342 typedef typename ImplTraitsType::HBndSegType HBndSegType;
343
344 typedef EntityCount< elType > EntityCountType;
345
346 using ALU3DSPACE AdaptRestrictProlongType::postRefinement;
347 using ALU3DSPACE AdaptRestrictProlongType::preCoarsening;
348
349 public:
350 typedef typename GridType::Traits::GlobalIdType IdType;
351
352 private:
354
355 typedef ALUGridId < MacroKeyType > MacroIdType;
356 enum { numCodim = 4 }; // we are always using the 3d grid here
357
358 typedef typename GridType::Traits::template Codim<0>::Entity EntityCodim0Type;
359
360 private:
361 mutable std::map< int , IdType > ids_[ numCodim ];
362
363 // our Grid
364 const GridType & grid_;
365
366 // the hierarchicIndexSet
367 const HierarchicIndexSetType & hset_;
368
369 int vertexKey_[4];
370
371 enum { startOffSet_ = 0 };
372
373 public:
374
377 using IdSet < GridType , ALU3dGridGlobalIdSet, IdType > :: subId;
378
381 : grid_(grid), hset_(grid.hierarchicIndexSet())
382 {
383 if(elType == hexa)
384 {
385 // see dune/alugrid/impl/serial/gitter_mgb.cc
386 // InsertUniqueHexa
387 const int vxKey[4] = {0,1,3,4};
388 for(int i=0; i<4; i++) vertexKey_[i] = vxKey[i];
389 }
390 else
391 {
392 alugrid_assert ( elType == tetra );
393 // see dune/alugrid/impl/serial/gitter_mgb.cc
394 // InsertUniqueTetra
395 const int vxKey[4] = {0,1,2,3};
396 for(int i=0; i<4; i++) vertexKey_[i] = vxKey[i];
397 }
398
399 // setup the id set
400 buildIdSet();
401 }
402
404
405 // update id set after adaptation
407 {
408 // to be revised
409 buildIdSet();
410 }
411
412 // print all ids
413 void print () const
414 {
415 for(int i=0 ;i<numCodim; ++i)
416 {
417 std::cout << "*****************************************************\n";
418 std::cout << "Ids for codim " << i << "\n";
419 std::cout << "*****************************************************\n";
420 for(unsigned int k=0; k<ids_[i].size(); ++k)
421 {
422 std::cout << "Item[" << i << "," << k <<"] has id " << ids_[i][k] << "\n";
423 }
424 std::cout << "\n\n\n";
425 }
426 }
427
428 template <class IterType>
429 void checkId(const IdType & macroId, const IterType & idIter) const //int codim , unsigned int num ) const
430 {
431
432 IdType id = getId(macroId);
433 for(int i=0 ;i<numCodim; ++i)
434 {
435 typedef typename std::map<int,IdType>::iterator IteratorType;
436 IteratorType end = ids_[i].end();
437 for(IteratorType it = ids_[i].begin(); it != end; ++it)
438 {
439 if(idIter == it) continue;
440 const IdType & checkMId = (*it).second;
441 IdType checkId = getId(checkMId);
442 if( id == checkId )
443 {
444 //std::cout << "Check(codim,num = " << codim<< "," << num <<") failed for k="<<k << " codim = " << i << "\n";
445 std::cout << id << " equals " << checkId << "\n";
446 alugrid_assert ( id != checkId );
447 DUNE_THROW(GridError," " << id << " equals " << checkId << "\n");
448 }
449 else
450 {
451 bool lesser = (id < checkId);
452 bool greater = (id > checkId);
453 alugrid_assert ( lesser != greater );
454 if( lesser == greater )
455 {
456 alugrid_assert ( lesser != greater );
457 DUNE_THROW(GridError," lesser equals greater of one id ");
458 }
459 }
460 }
461 }
462 }
463
464 // check id set for uniqueness
465 void uniquenessCheck() const
466 {
467 for(int i=0 ;i<numCodim; i++)
468 {
469 typedef typename std::map<int,IdType>::iterator IteratorType;
470 IteratorType end = ids_[i].end();
471 for(IteratorType it = ids_[i].begin(); it != end; ++it)
472 {
473 const IdType & id = (*it).second;
474 if( id.isValid() )
475 checkId(id,it);
476 }
477 }
478 }
479
480 void setChunkSize( int chunkSize )
481 {
482 }
483
484 // creates the id set
486 {
487 for(int i=0; i<numCodim; ++i)
488 {
489 ids_[i].clear();
490 }
491
492 GitterImplType &gitter = grid_.myGrid();
493
494 // all interior and border vertices
495 {
496 typename ALU3DSPACE AccessIterator< VertexType >::Handle fw( gitter.container() );
497 for( fw.first (); !fw.done(); fw.next() )
498 {
499 int idx = fw.item().getIndex();
500 ids_[3][idx] = buildMacroVertexId( fw.item() );
501 }
502 }
503
504 // all ghost vertices
505 {
506 typedef typename ALU3DSPACE ALU3dGridLevelIteratorWrapper< 3, Ghost_Partition, Comm > IteratorType;
507 IteratorType fw (grid_ , 0 , grid_.nlinks() );
508 typedef typename IteratorType :: val_t val_t;
509 for (fw.first () ; ! fw.done () ; fw.next ())
510 {
511 val_t & item = fw.item();
512 alugrid_assert ( item.first );
513 VertexType & vx = * (item.first);
514 int idx = vx.getIndex();
515 ids_[3][idx] = buildMacroVertexId( vx );
516 }
517 }
518
519 {
520 // create ids for all macro edges
521 {
522 typename ALU3DSPACE AccessIterator< HEdgeType >::Handle w( gitter.container() );
523 for (w.first(); !w.done(); w.next())
524 {
525 int idx = w.item().getIndex();
526 ids_[2][idx] = buildMacroEdgeId( w.item() );
527 buildEdgeIds( w.item() , ids_[2][idx] , startOffSet_ );
528 }
529 }
530
531 // all ghost edges
532 {
533 typedef typename ALU3DSPACE ALU3dGridLevelIteratorWrapper< 2, Ghost_Partition, Comm > IteratorType;
534 IteratorType fw( grid_, 0, grid_.nlinks() );
535 typedef typename IteratorType :: val_t val_t;
536 for (fw.first () ; ! fw.done () ; fw.next ())
537 {
538 val_t & item = fw.item();
539 alugrid_assert ( item.first );
540 HEdgeType & edge = * (item.first);
541 int idx = edge.getIndex();
542
543 ids_[2][idx] = buildMacroEdgeId( edge );
544 buildEdgeIds( edge , ids_[2][idx] , startOffSet_ );
545 }
546 }
547 }
548
549
550 // for all macro faces and all children
551 {
552 typename ALU3DSPACE AccessIterator< HFaceType >::Handle w( gitter.container() );
553 for (w.first () ; ! w.done () ; w.next ())
554 {
555 int idx = w.item().getIndex();
556 ids_[1][idx] = buildMacroFaceId( w.item() );
557 buildFaceIds( w.item() , ids_[1][idx] , startOffSet_ );
558 }
559 }
560
561 // all ghost faces
562 {
563 typedef typename ALU3DSPACE ALU3dGridLevelIteratorWrapper< 1, Ghost_Partition, Comm > IteratorType;
564 IteratorType fw (grid_ , 0 , grid_.nlinks() );
565 typedef typename IteratorType :: val_t val_t;
566 for (fw.first () ; ! fw.done () ; fw.next ())
567 {
568 val_t & item = fw.item();
569 alugrid_assert ( item.first );
570 HFaceType & face = * (item.first);
571 int idx = face.getIndex();
572 ids_[1][idx] = buildMacroFaceId( face );
573 buildFaceIds( face , ids_[1][idx] , startOffSet_ );
574 }
575 }
576
577 // for all macro elements and all internal entities
578 {
579 typename ALU3DSPACE AccessIterator< HElementType >::Handle w( gitter.container() );
580 for (w.first () ; ! w.done () ; w.next ())
581 {
582 int idx = w.item().getIndex();
583 ids_[0][idx] = buildMacroElementId( w.item() );
584 buildElementIds( w.item() , ids_[0][idx] , startOffSet_ );
585 }
586 }
587
588 // all ghost elements
589 {
590 typedef typename ALU3DSPACE ALU3dGridLevelIteratorWrapper< 0, Ghost_Partition, Comm > IteratorType;
591 IteratorType fw (grid_ , 0 , grid_.nlinks() );
592 typedef typename IteratorType :: val_t val_t;
593 for (fw.first () ; ! fw.done () ; fw.next ())
594 {
595 val_t & item = fw.item();
596 alugrid_assert ( item.second );
597 HElementType & elem = * ( item.second->getGhost().first );
598 int idx = elem.getIndex();
599 ids_[0][idx] = buildMacroElementId( elem );
600 buildElementIds( elem , ids_[0][idx] , startOffSet_ );
601 }
602 }
603
604 // check uniqueness of id only in serial, because
605 // in parallel some faces and edges of ghost exists more than once
606 // but have the same id, but not the same index, there for the check
607 // will fail for ghost elements
608 // be carefull with this check, it's complexity is O(N^2)
609 //uniquenessCheck();
610 }
611
612 IdType buildMacroVertexId(const VertexType & item )
613 {
614 int vx[4] = { item.ident(), -1, -1, -1};
615 enum { codim = 3 };
616 MacroKeyType key(vx[0],vx[1],vx[2],vx[3]);
617 MacroIdType id(key,1, codim + startOffSet_ );
618 return id;
619 }
620
621 IdType buildMacroEdgeId(const HEdgeType & item )
622 {
623 const GEOEdgeType & edge = static_cast<const GEOEdgeType &> (item);
624 int vx[4] = {-1,-1,-1,-1};
625 for(int i=0; i<2; ++i)
626 {
627 vx[i] = edge.myvertex(i)->ident();
628 }
629
630 enum { codim = 2 };
631 MacroKeyType key(vx[0],vx[1],vx[2],vx[3]);
632 MacroIdType id( key,1, codim + startOffSet_ );
633 return id;
634 }
635
636 IdType buildMacroFaceId(const HFaceType & item )
637 {
638 const GEOFaceType & face = static_cast<const GEOFaceType &> (item);
639 int vx[4] = {-1,-1,-1,-1};
640 for(int i=0; i<3; ++i)
641 {
642 vx[i] = face.myvertex(i)->ident();
643 }
644
645 enum { codim = 1 };
646 MacroKeyType key(vx[0],vx[1],vx[2],vx[3]);
647 MacroIdType id(key,1, codim + startOffSet_ );
648 return id;
649 }
650
651 IdType buildMacroElementId(const HElementType & item )
652 {
653 const GEOElementType & elem = static_cast<const GEOElementType &> (item);
654 int vx[4] = {-1,-1,-1,-1};
655 for(int i=0; i<4; ++i)
656 {
657 vx[i] = elem.myvertex(vertexKey_[i])->ident();
658 }
659 enum { codim = 0 };
660 MacroKeyType key(vx[0],vx[1],vx[2],vx[3]);
661 return MacroIdType(key,1, codim + startOffSet_ );
662 }
663
664 template <int cd, class Item>
665 IdType createId(const Item& item , const IdType& creatorId , int nChild )
666 {
667 alugrid_assert ( creatorId.isValid() );
668
669 // we have up to 12 internal hexa faces, therefore need 100 offset
670 enum { childOffSet = (dim == 2) ? 4 : ((cd == 1) && (elType == hexa)) ? 16 : 8 };
671 enum { codimOffSet = 4 };
672
673 alugrid_assert ( nChild < childOffSet );
674
675 int newChild = (creatorId.nChild() * childOffSet ) + nChild;
676 int level = ((creatorId.codim()-startOffSet_)/codimOffSet) +1;
677 int newCodim = (codimOffSet * level + cd +startOffSet_);
678
679 IdType newId( creatorId.getKey() , newChild , newCodim );
680 alugrid_assert ( newId != creatorId );
681 return newId;
682 }
683
684 // build ids for all children of this element
685 void buildElementIds(const HElementType & item , const IdType & macroId , int nChild)
686 {
687 enum { codim = 0 };
688 ids_[codim][item.getIndex()] = createId<codim>(item,macroId,nChild);
689
690 const IdType & itemId = ids_[codim][item.getIndex()];
691
692 buildInteriorElementIds(item,itemId);
693 }
694
695 // build ids for all children of this element
696 void buildInteriorElementIds(const HElementType & item , const IdType & fatherId)
697 {
698 alugrid_assert ( fatherId.isValid() );
699
700 // build id for inner vertex
701 {
702 const VertexType * v = item.innerVertex() ;
703 // for tetras there is no inner vertex, therefore check
704 if(v) buildVertexIds(*v,fatherId );
705 }
706
707 // build edge ids for all inner edges
708 {
709 int inneredge = startOffSet_;
710 for(const HEdgeType * e = item.innerHedge () ; e ; e = e->next ())
711 {
712 buildEdgeIds(*e,fatherId,inneredge);
713 ++inneredge;
714 }
715 }
716
717 // build face ids for all inner faces
718 {
719 int innerface = startOffSet_;
720 for(const HFaceType * f = item.innerHface () ; f ; f = f->next ())
721 {
722 buildFaceIds(*f,fatherId,innerface);
723 ++innerface;
724 }
725 }
726
727 // build ids of all children
728 {
729 int numChild = startOffSet_;
730 for(const HElementType * child = item.down(); child; child =child->next() )
731 {
732 //alugrid_assert ( numChild == child->nChild() );
733 buildElementIds(*child, fatherId, numChild);
734 ++numChild;
735 }
736 }
737 }
738
739 // build ids for all children of this face
740 void buildFaceIds(const HFaceType & face, const IdType & fatherId , int innerFace )
741 {
742 enum { codim = 1 };
743 ids_[codim][face.getIndex()] = createId<codim>(face,fatherId,innerFace);
744 const IdType & faceId = ids_[codim][face.getIndex()];
745
746 buildInteriorFaceIds(face,faceId);
747 }
748
749 // build ids for all children of this face
750 void buildInteriorFaceIds(const HFaceType & face, const IdType & faceId)
751 {
752 alugrid_assert ( faceId.isValid () );
753
754 // build id for inner vertex
755 {
756 const VertexType * v = face.innerVertex() ;
757 //std::cout << "create inner vertex of face " << face.getIndex() << "\n";
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 >
942 : public IdSet< ALU3dGrid< dim, dimworld, elType, Comm >, ALU3dGridLocalIdSet< dim, dimworld, elType, Comm >, int >,
943 public ALU3DSPACE AdaptRestrictProlongType
944 {
946
947 typedef ALU3dImplTraits< elType, Comm > ImplTraitsType;
948 typedef typename ImplTraitsType::HElementType HElementType;
949 typedef typename ImplTraitsType::HBndSegType HBndSegType;
950
953
954 // this means that only up to 300000000 entities are allowed
955 enum { codimMultiplier = 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 * codimMultiplier;
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) < codimMultiplier );
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) < codimMultiplier );
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 ) < codimMultiplier );
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
#define alugrid_assert(EX)
Definition alugrid_assert.hh:20
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
Definition alu3dinclude.hh:259
[ provides Dune::Grid ]
Definition 3d/grid.hh:468
int hierSetSize(int cd) const
Definition grid_inline.hh:100
const std::vector< GeometryType > & geomTypes(int codim) const
deliver all geometry types used in this grid
Definition 3d/grid.hh:1134
static const int dimension
Definition 3d/grid.hh:529
Definition indexsets.hh:326
void setChunkSize(int chunkSize)
Definition indexsets.hh:480
void buildVertexIds(const VertexType &vertex, const IdType &fatherId)
Definition indexsets.hh:815
virtual ~ALU3dGridGlobalIdSet()
Definition indexsets.hh:403
int preCoarsening(HElementType &elem)
Definition indexsets.hh:899
IdType buildMacroElementId(const HElementType &item)
Definition indexsets.hh:651
void checkId(const IdType &macroId, const IterType &idIter) const
Definition indexsets.hh:429
IdType buildMacroVertexId(const VertexType &item)
Definition indexsets.hh:612
ALU3dGridGlobalIdSet(const GridType &grid)
create id set, only allowed for ALU3dGrid
Definition indexsets.hh:380
void buildEdgeIds(const HEdgeType &edge, const IdType &fatherId, int inneredge)
Definition indexsets.hh:784
void updateIdSet()
Definition indexsets.hh:406
GridType::Traits::GlobalIdType IdType
Definition indexsets.hh:350
void buildFaceIds(const HFaceType &face, const IdType &fatherId, int innerFace)
Definition indexsets.hh:740
int preCoarsening(HBndSegType &el)
Definition indexsets.hh:926
void buildIdSet()
Definition indexsets.hh:485
void buildInteriorElementIds(const HElementType &item, const IdType &fatherId)
Definition indexsets.hh:696
IdType buildMacroEdgeId(const HEdgeType &item)
Definition indexsets.hh:621
void buildInteriorFaceIds(const HFaceType &face, const IdType &faceId)
Definition indexsets.hh:750
void uniquenessCheck() const
Definition indexsets.hh:465
IdType id(const EntityType &ep) const
return global id of given entity
Definition indexsets.hh:833
int postRefinement(HElementType &item)
Definition indexsets.hh:866
int postRefinement(HBndSegType &el)
prolong data, elem is the father
Definition indexsets.hh:929
void buildElementIds(const HElementType &item, const IdType &macroId, int nChild)
Definition indexsets.hh:685
const IdType & getId(const IdType &macroId) const
Definition indexsets.hh:825
void buildInteriorEdgeIds(const HEdgeType &edge, const IdType &edgeId)
Definition indexsets.hh:792
IdType subId(const EntityCodim0Type &e, int i, unsigned int codim) const
return subId of given entity
Definition indexsets.hh:854
IdType createId(const Item &item, const IdType &creatorId, int nChild)
Definition indexsets.hh:665
IdType buildMacroFaceId(const HFaceType &item)
Definition indexsets.hh:636
IdType id(const typename GridType::template Codim< cd > ::Entity &ep) const
return global id of given entity
Definition indexsets.hh:844
void print() const
Definition indexsets.hh:413
hierarchic index set of ALU3dGrid
Definition indexsets.hh:944
int id(const typename GridType::template Codim< codim > ::Entity &ep) const
return global id of given entity
Definition indexsets.hh:992
int postRefinement(HBndSegType &el)
prolong data, elem is the father
Definition indexsets.hh:1015
void setChunkSize(int chunkSize)
Definition indexsets.hh:1017
int id(const EntityType &ep) const
return global id of given entity
Definition indexsets.hh:983
int preCoarsening(HElementType &elem)
Definition indexsets.hh:1007
int preCoarsening(HBndSegType &el)
Definition indexsets.hh:1012
int IdType
export type of id
Definition indexsets.hh:975
int postRefinement(HElementType &item)
Definition indexsets.hh:1009
IdType subId(const EntityCodim0Type &e, int i, unsigned int codim) const
return subId of given entity
Definition indexsets.hh:1000
hierarchic index set of ALU3dGrid
Definition indexsets.hh:38
int size(GeometryType type) const
Definition indexsets.hh:77
int size(int codim) const
return size of indexset, i.e. maxindex+1
Definition indexsets.hh:86
const std::vector< GeometryType > & geomTypes(int codim) const
deliver all geometry types used in this grid
Definition indexsets.hh:93
bool contains(const EntityType &) const
return true because all entities are contained in this set
Definition indexsets.hh:100
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 EntityCodim0Type &e, int i, unsigned int codim) const
return subIndex i of given entity for subEntity with codim
Definition indexsets.hh:69
Definition indexsets.hh:113
void extractKey(std::vector< int > &key) const
Definition indexsets.hh:143
bool operator==(const ALUMacroKey &org) const
Definition indexsets.hh:128
void print(std::ostream &out) const
Definition indexsets.hh:152
ALUMacroKey(const A &a, const A &b, const A &c, const A &d)
Definition indexsets.hh:120
ALUMacroKey & operator=(const ALUMacroKey &org)
Definition indexsets.hh:122
ALUMacroKey(const ALUMacroKey &org)
Definition indexsets.hh:121
bool operator>(const ALUMacroKey &org) const
Definition indexsets.hh:137
ALUMacroKey()
Definition indexsets.hh:119
Definition indexsets.hh:173
bool operator!=(const ALUGridId &org) const
Definition indexsets.hh:208
bool isValid() const
Definition indexsets.hh:239
bool operator>=(const ALUGridId &org) const
Definition indexsets.hh:219
int codim() const
Definition indexsets.hh:237
void print(std::ostream &out) const
Definition indexsets.hh:250
const MacroKeyImp & getKey() const
Definition indexsets.hh:235
bool operator<=(const ALUGridId &org) const
Definition indexsets.hh:213
bool operator<(const ALUGridId &org) const
Definition indexsets.hh:225
ALUGridId & operator=(const ALUGridId &org)
Definition indexsets.hh:195
void reset()
Definition indexsets.hh:244
ALUGridId(const MacroKeyImp &key, int nChild, int cd)
Definition indexsets.hh:184
bool equals(const ALUGridId &org) const
Definition indexsets.hh:287
ALUGridId(const ALUGridId &org)
Definition indexsets.hh:189
bool lesser(const ALUGridId &org) const
Definition indexsets.hh:269
bool operator==(const ALUGridId &org) const
Definition indexsets.hh:203
bool operator>(const ALUGridId &org) const
Definition indexsets.hh:230
int nChild() const
Definition indexsets.hh:236
ALUGridId()
Definition indexsets.hh:179
Definition topology.hh:15