dune-grid  2.2.1
alugrid/3d/entity.hh
Go to the documentation of this file.
1 #ifndef DUNE_ALU3DGRIDENTITY_HH
2 #define DUNE_ALU3DGRIDENTITY_HH
3 
4 // System includes
5 
6 // Dune includes
9 
10 // Local includes
11 #include "alu3dinclude.hh"
12 #include "iterator.hh"
13 #include "entityseed.hh"
14 
15 namespace Dune
16 {
17 
18  // Forward declarations
19  template<int cd, int dim, class GridImp>
20  class ALU3dGridEntity;
21  template<int cd, PartitionIteratorType pitype, class GridImp >
22  class ALU3dGridLevelIterator;
23  template<int cd, class GridImp >
24  class ALU3dGridEntityPointer;
25  template<int mydim, int coorddim, class GridImp>
26  class ALU3dGridGeometry;
27  template<class GridImp>
28  class ALU3dGridHierarchicIterator;
29  template<class GridImp>
30  class ALU3dGridIntersectionIterator;
31  template<int codim, PartitionIteratorType, class GridImp>
32  class ALU3dGridLeafIterator;
33  template< ALU3dGridElementType, class >
34  class ALU3dGrid;
35 
42 template<int cd, int dim, class GridImp>
44 public EntityDefaultImplementation <cd,dim,GridImp,ALU3dGridEntity>
45 {
46  // default just returns level
47  template <class GridType, int cdim>
48  struct GetLevel
49  {
50  template <class ItemType>
51  static int getLevel(const GridType & grid, const ItemType & item )
52  {
53  return item.level();
54  }
55  };
56 
57  // for leaf vertices the level is somewhat difficult to obtain, because
58  // this the maximum of levels of elements that have this vertex as sub
59  // entity
60  template <class GridType>
61  struct GetLevel<GridType,3>
62  {
63  template <class ItemType>
64  static int getLevel(const GridType & grid, const ItemType & item)
65  {
66  return (item.isLeafEntity()) ? grid.getLevelOfLeafVertex(item) : item.level();
67  }
68  };
69 
70  enum { dimworld = GridImp::dimensionworld };
71 
72  typedef typename GridImp::MPICommunicatorType Comm;
73 
74  friend class ALU3dGrid< GridImp::elementType, Comm >;
75  friend class ALU3dGridEntity < 0, dim, GridImp >;
76  friend class ALU3dGridLevelIterator < cd, All_Partition, GridImp >;
77 
78  friend class ALU3dGridHierarchicIndexSet< GridImp::elementType, Comm >;
79 
80  template< class > friend class ALU3dGridFactory;
81 
82  typedef typename GridImp::Traits::template Codim< cd >::GeometryImpl GeometryImpl;
83 
84 public:
85  typedef typename GridImp::GridObjectFactoryType FactoryType;
86 
87  typedef ALU3dImplTraits< GridImp::elementType, Comm > ImplTraits;
88  typedef typename ImplTraits::template Codim<cd>::InterfaceType HItemType;
89  typedef typename ImplTraits::template Codim<cd>::ImplementationType ItemType;
90  typedef typename ImplTraits::VertexType VertexType;
91  typedef typename ImplTraits::HBndSegType HBndSegType;
92 
93  typedef typename GridImp::template Codim<cd>::Entity Entity;
94  typedef typename GridImp::template Codim<cd>::Geometry Geometry;
95 
96  typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer;
97 
99  typedef typename GridImp::template Codim<cd>::EntitySeed EntitySeed;
100 
102  int level () const;
103 
106 
108  ALU3dGridEntity(const FactoryType &factory, int level);
109 
111  ALU3dGridEntity(const ALU3dGridEntity & org);
112 
114  Geometry geometry () const;
115 
117  GeometryType type () const;
118 
119  // set element as normal entity
120  void setElement(const HItemType & item);
121  void setElement(const HItemType & item, const int level, int twist=0, int face = -1);
122 
123  /* set entity from seed */
124  void setElement(const EntitySeed& seed);
125 
127  void setGhost(const HBndSegType &ghost);
128 
130  void removeElement ();
131 
133  void reset ( int l );
134 
136  bool equals ( const ALU3dGridEntity<cd,dim,GridImp> & org ) const;
137 
139  void setEntity ( const ALU3dGridEntity<cd,dim,GridImp> & org );
140 
141  // return reference to internal item
142  const ItemType & getItem () const { return *item_; }
143 
145  const GridImp& grid() const { return factory_.grid(); }
146 
148  const FactoryType& factory() const { return factory_; }
149 
151  EntitySeed seed() const
152  {
153  return EntitySeed( getItem(), level(), twist_, face_ );
154  }
155 
156 private:
158  int getIndex () const;
159 
161  PartitionType convertBndId(const HItemType & item) const ;
162 
164  mutable GeometryImpl geo_;
165 
166  // the factory that created this entity
167  const FactoryType& factory_;
168 
169  // corresponding ALU3dGrid item, here face, edge, or vertex
170  const ItemType * item_;
171 
172  int level_;
173  int gIndex_;
174  int twist_;
175  int face_;
176 
177  mutable PartitionType partitionType_;
178 };
179 
193 //***********************
194 //
195 // --ALU3dGridEntity
196 // --0Entity
197 //
198 //***********************
199 template<int dim, class GridImp>
200 class ALU3dGridEntity<0,dim,GridImp>
201 : public EntityDefaultImplementation<0,dim,GridImp,ALU3dGridEntity>
202 {
203  static const int dimworld = remove_const< GridImp >::type::dimensionworld;
204  static const ALU3dGridElementType elementType = remove_const< GridImp >::type::elementType;
205 
206  typedef typename GridImp::MPICommunicatorType Comm;
207 
208  typedef ALU3dImplTraits< elementType, Comm > ImplTraits;
209  typedef typename ImplTraits::template Codim<0>::InterfaceType HElementType;
210 
211  typedef typename ImplTraits::GEOElementType GEOElementType;
212  typedef typename ImplTraits::BNDFaceType BNDFaceType;
213  typedef typename ImplTraits::IMPLElementType IMPLElementType;
214  typedef typename ImplTraits::HBndSegType HBndSegType;
215 
216  enum { refine_element_t = ImplTraits::refine_element_t };
217  enum { bisect_element_t = ImplTraits::bisect_element_t };
218  enum { coarse_element_t = ImplTraits::coarse_element_t };
219  enum { nosplit_element_t = ImplTraits::nosplit_element_t };
220 
221  typedef typename ImplTraits::MarkRuleType MarkRuleType;
222 
223  friend class ALU3dGrid< elementType, Comm >;
224  friend class ALU3dGridIntersectionIterator < GridImp >;
225  friend class ALU3dGridIntersectionIterator < const GridImp >;
226  friend class ALU3dGridHierarchicIterator < const GridImp >;
227  friend class ALU3dGridHierarchicIterator < GridImp >;
228  friend class ALU3dGridLevelIterator <0,All_Partition,GridImp>;
229  friend class ALU3dGridLevelIterator <1,All_Partition,GridImp>;
230  friend class ALU3dGridLevelIterator <2,All_Partition,GridImp>;
231  friend class ALU3dGridLevelIterator <3,All_Partition,GridImp>;
232  friend class ALU3dGridLeafIterator <0, All_Partition,GridImp>;
233  friend class ALU3dGridLeafIterator <1, All_Partition,GridImp>;
234  friend class ALU3dGridLeafIterator <2, All_Partition,GridImp>;
235  friend class ALU3dGridLeafIterator <3, All_Partition,GridImp>;
236 
237  friend class ALU3dGridHierarchicIndexSet< elementType, Comm >;
238 
239  template< class > friend class ALU3dGridFactory;
240 
241  // type of reference element
242  typedef typename GridImp :: ReferenceElementType ReferenceElementType;
243 
244  typedef typename GridImp::Traits::template Codim< 0 >::GeometryImpl GeometryImpl;
245  typedef typename GridImp::Traits::template Codim< 0 >::LocalGeometryImpl LocalGeometryImpl;
246 
247 public:
248  typedef typename GridImp::GridObjectFactoryType FactoryType;
249 
250  typedef typename GridImp::template Codim< 0 >::Geometry Geometry;
251  typedef typename GridImp::template Codim< 0 >::LocalGeometry LocalGeometry;
253 
257 
258  typedef typename GridImp::template Codim<0>::Entity Entity;
259  typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer;
260 
261  template <int cd>
262  struct Codim
263  {
264  typedef typename GridImp::template Codim<cd>::EntityPointer EntityPointer;
265  };
266 
268  typedef typename GridImp::template Codim<0>::EntitySeed EntitySeed;
269 
272 
274  ALU3dGridEntity(const ALU3dGridEntity & org);
275 
277  int level () const ;
278 
280  Geometry geometry () const;
281 
283  GeometryType type () const;
284 
287 
291  template<int cc> int count () const ;
292 
295  template <int codim>
296  typename Codim< codim >::EntityPointer entity (int i) const
297  {
298  typedef GenericGeometry::MapNumberingProvider< GridImp::dimension > Numbering;
299  const unsigned int tid = type().id();
300  const int j = Numbering::template dune2generic< codim >( tid, i );
301  return subEntity< codim >( j );
302  }
303 
304  template< int codim >
305  typename Codim< codim >::EntityPointer subEntity ( int i ) const;
306 
312  ALU3dGridLeafIntersectionIteratorType ileafbegin () const;
313 
315  ALU3dGridLeafIntersectionIteratorType ileafend () const;
316 
322  ALU3dGridLevelIntersectionIteratorType ilevelbegin () const;
323 
325  ALU3dGridLevelIntersectionIteratorType ilevelend () const;
326 
328  bool isLeaf () const;
329 
332  EntityPointer father () const;
334  bool hasFather () const
335  {
336  return (this->level()>0);
337  }
338 
348  LocalGeometry geometryInFather () const;
349 
354  ALU3dGridHierarchicIterator<GridImp> hbegin (int maxlevel) const;
355 
357  ALU3dGridHierarchicIterator<GridImp> hend (int maxlevel) const;
358 
359  //***************************************************************
360  // Interface for Adaptation
361  //***************************************************************
362 
364  bool isNew () const;
365 
367  bool mightVanish () const;
368 
370  bool hasBoundaryIntersections () const;
371 
372  // private method
376  bool mark( int refCount ) const;
377 
379  int getMark() const;
380 
384  void setElement(HElementType &element);
385 
386  /* set entity from seed */
387  void setElement(const EntitySeed& seed);
388 
390  void setGhost(HBndSegType & ghost);
391 
393  void reset ( int l );
394 
396  void removeElement();
397 
399  bool equals ( const ALU3dGridEntity<0,dim,GridImp> & org ) const;
400 
401  void setEntity ( const ALU3dGridEntity<0,dim,GridImp> & org );
402 
406  template<int cc> int getSubIndex (int i) const;
407 
411  int subIndex(int i, unsigned int codim) const;
412 
413  // return reference to internal item
414  const IMPLElementType& getItem () const { return *item_; }
415 
416  // return reference to internal item
417  const BNDFaceType& getGhost () const
418  {
419  assert( isGhost() );
420  return *ghost_;
421  }
422 
424  const GridImp& grid() const { return factory_.grid(); }
425 
427  const FactoryType& factory() const { return factory_; }
428 
430  bool isGhost () const{ return ImplTraits::isGhost( ghost_ ); }
431 
433  EntitySeed seed() const
434  {
435  if( isGhost() )
436  return EntitySeed( getGhost () );
437  else
438  return EntitySeed( getItem() );
439  }
440 
441 private:
443  int getIndex () const;
444 
446  mutable GeometryImpl geo_;
447 
448  // corresponding factory
449  const FactoryType& factory_;
450 
451  // the current element of grid
452  mutable IMPLElementType* item_;
453 
455  mutable BNDFaceType* ghost_;
456 
457  int level_;
458  bool isLeaf_;
459 
460 }; // end of ALU3dGridEntity codim = 0
461 //**********************************************************************
462 //
463 // --ALU3dGridEntityPointer
464 // --EntityPointer
465 // --EnPointer
469 template< int codim, class GridImp >
471 //: public EntityPointerDefaultImplementation <codim, GridImp, ALU3dGridEntityPointer<cd,GridImp> >
472 {
474  enum { dim = GridImp::dimension };
475  enum { dimworld = GridImp::dimensionworld };
476 
477  typedef typename GridImp::MPICommunicatorType Comm;
478 
479  friend class ALU3dGridEntity<codim,dim,GridImp>;
480  friend class ALU3dGridEntity< 0,dim,GridImp>;
481  friend class ALU3dGrid < GridImp::elementType, Comm >;
482 
483  typedef ALU3dImplTraits<GridImp::elementType, Comm > ImplTraits;
484  typedef typename ImplTraits::template Codim<codim>::InterfaceType HElementType;
485 
486  typedef typename ImplTraits::HBndSegType HBndSegType;
487  typedef typename ImplTraits::BNDFaceType BNDFaceType;
488 public:
489  typedef typename GridImp::GridObjectFactoryType FactoryType;
490 
491  enum { codimension = codim };
492 
494  typedef typename GridImp::template Codim<codimension>::Entity Entity;
498 
501 
504 
507 
509  ALU3dGridEntityPointerBase(const FactoryType& factory,
510  const HElementType & item);
511 
514  const HElementType & item,
515  const int level,
516  const int twist,
517  const int duneFace
518  );
519 
521  ALU3dGridEntityPointerBase(const FactoryType& factory,
522  const HBndSegType & ghostFace );
523 
525  ALU3dGridEntityPointerBase(const FactoryType& factory,
526  const ALU3dGridEntitySeedType& seed );
527 
530 
533 
535  bool equals (const ALU3dGridEntityPointerType& i) const;
536 
538  ThisType & operator = (const ThisType & org);
539 
541  Entity & dereference () const ;
542 
544  int level () const ;
545 
546 protected:
547  // clones object
548  void clone (const ALU3dGridEntityPointerType & org);
549 
550  // get entity and assign from org.entity
551  void getEntity (const ALU3dGridEntityPointerType & org);
552 
554  void done ();
555 
557  void freeEntity ();
558 
560  const GridImp& grid () const { return factory_.grid(); }
561 
564  ALU3dGridEntityPointerBase(const FactoryType& factory, int level );
565 
566  // update underlying item pointer and set ghost entity
567  void updateGhostPointer( HBndSegType & ghostFace );
568  // update underlying item pointer and set entity
569  void updateEntityPointer( HElementType * item , int level = -1 );
570 
571  // reference to factory
573 
574  // key to gererate entity
576 
577  // entity that this EntityPointer points to
579 
580  // is true if entity must not be released
581  bool locked_;
582 
583  // return reference to internal entity implementation
584  EntityImp & entityImp () const {
585  assert( entity_ );
586  return GridImp :: getRealImplementation(*entity_);
587  }
588 };
589 
593 template<class GridImp>
594 class ALU3dGridEntityPointer<0,GridImp> :
595 public ALU3dGridEntityPointerBase<0,GridImp>
596 {
597 protected:
599 
600  enum { cd = 0 };
602  enum { dim = GridImp::dimension };
603  enum { dimworld = GridImp::dimensionworld };
604 
605  typedef typename GridImp::MPICommunicatorType Comm;
606 
607  friend class ALU3dGridEntity<cd,dim,GridImp>;
608  friend class ALU3dGridEntity< 0,dim,GridImp>;
609  friend class ALU3dGrid < GridImp::elementType, Comm >;
610 
611  typedef ALU3dImplTraits<GridImp::elementType, Comm > ImplTraits;
612  typedef typename ImplTraits::template Codim<cd>::InterfaceType HElementType;
613 
614  typedef typename ImplTraits::HBndSegType HBndSegType;
615  typedef typename ImplTraits::BNDFaceType BNDFaceType;
616 
617  typedef ALU3dGridEntity< 0,dim,GridImp> ALU3dGridEntityType ;
618 
619  using BaseType :: seed_;
620  using BaseType :: entity_;
621  using BaseType :: entityImp;
622  using BaseType :: factory_;
623 public:
624  typedef typename GridImp::GridObjectFactoryType FactoryType;
625 
628 
630  typedef typename GridImp::template Codim<cd>::Entity Entity;
631 
634 
636  ALU3dGridEntityPointer(const FactoryType& factory,
637  const HElementType & item)
638  : ALU3dGridEntityPointerBase<cd,GridImp> (factory,item) {}
639 
642  const HBndSegType & ghostFace )
643  : ALU3dGridEntityPointerBase<cd,GridImp> (factory,ghostFace) {}
644 
647  : ALU3dGridEntityPointerBase<cd,GridImp> (factory, seed)
648  {
649  // for ghost entities we have to copy right away
650  if( seed.isGhost() )
651  {
652  assert( entity_ == 0 );
653  entity_ = factory_.template getNewEntity<0> ();
654  assert( entity_ );
655  entityImp().setGhost( *seed.ghost() );
656 
657  // don't free on compactify, otherwise ghost info is lost
658  this->locked_ = true ;
659  }
660  }
661 
664  : ALU3dGridEntityPointerBase<cd,GridImp> (entity.factory(),
665  entity.seed() )
666  {
667  // for ghost entities we have to copy right away
668  if( entity.isGhost() )
669  {
670  assert( entity_ == 0 );
671  entity_ = factory_.template getNewEntity<0> ();
672  assert( entity_ );
673  entityImp().setEntity( entity );
674 
675  // don't free on compactify, otherwise ghost info is lost
676  this->locked_ = true ;
677  }
678  }
679 
682  : ALU3dGridEntityPointerBase<cd,GridImp> (org)
683  {
684  }
685 
686 protected:
690  : ALU3dGridEntityPointerBase<cd,GridImp> (factory,level) {}
691 };
692 
693 
694 template<int cd, class GridImp>
696 public ALU3dGridEntityPointerBase<cd,GridImp>
697 {
698 protected:
701  enum { dim = GridImp::dimension };
702  enum { dimworld = GridImp::dimensionworld };
703 
704  typedef typename GridImp::MPICommunicatorType Comm;
705 
706  friend class ALU3dGridEntity<cd,dim,GridImp>;
707  friend class ALU3dGridEntity< 0,dim,GridImp>;
708  friend class ALU3dGrid < GridImp::elementType, Comm >;
709 
710  typedef ALU3dImplTraits< GridImp::elementType, Comm > ImplTraits;
711  typedef typename ImplTraits::template Codim<cd>::InterfaceType HElementType;
712 
713  typedef typename ImplTraits::HBndSegType HBndSegType;
714  typedef typename ImplTraits::BNDFaceType BNDFaceType;
715  typedef ALU3dGridEntity<cd,dim,GridImp> ALU3dGridEntityType;
716 
717  using BaseType :: seed_;
718  using BaseType :: entity_;
719  using BaseType :: entityImp;
720  using BaseType :: factory_;
721  using BaseType :: getEntity;
722 
723 public:
724  typedef typename GridImp::GridObjectFactoryType FactoryType;
725 
728 
730  typedef typename GridImp::template Codim<cd>::Entity Entity;
731 
734 
735 protected:
736  static const int defaultValue = -665; //ALU3dGridEntityPointerType :: defaultValue;
737 
738 public:
740  ALU3dGridEntityPointer(const FactoryType& factory,
741  const int level,
742  const HElementType & item,
743  const int twist = defaultValue,
744  const int duneFace = defaultValue
745  );
746 
748  ALU3dGridEntityPointer(const ALU3dGridEntityType& entity)
749  : ALU3dGridEntityPointerBase<cd,GridImp> (entity.factory(),
750  entity.seed())
751  {}
752 
755  : ALU3dGridEntityPointerBase<cd,GridImp> ( factory, seed )
756  {}
757 
760 
762  Entity & dereference () const ;
763 
765  ThisType & operator = (const ThisType & org);
766 
768  int level () const ;
769 
770 protected:
771  // clones object
772  void clone (const ALU3dGridEntityPointerType & org);
773 
774  void updateEntityPointer( HElementType * item , int level );
775 
778  ALU3dGridEntityPointer(const FactoryType& factory, int level )
779  : ALU3dGridEntityPointerBase<cd,GridImp> (factory,level)
780  {}
781 };
782 
783 } // end namespace Dune
784 
785 #include "entity_inline.hh"
786 
787 #if COMPILE_ALUGRID_INLINE
788  #include "entity_imp.cc"
789 #endif
790 
791 #endif