dune-grid  2.2.1
alugrid/2d/entity.hh
Go to the documentation of this file.
1 #ifndef DUNE_ALU2DGRIDENTITY_HH
2 #define DUNE_ALU2DGRIDENTITY_HH
3 
4 // System includes
5 
6 // Dune includes
8 //#include <dune/grid/common/intersectioniteratorwrapper.hh>
9 
10 // Local includes
14 
15 namespace Dune {
16  // Forward declarations
17  template<int cd, int dim, class GridImp>
18  class ALU2dGridEntity;
19  template<int cd, PartitionIteratorType pitype, class GridImp >
20  class ALU2dGridLevelIterator;
21  template< int codim, class GridImp >
22  class ALU2dGridEntityPointer;
23  template<int mydim, int coorddim, class GridImp>
24  class ALU2dGridGeometry;
25  template<class GridImp>
26  class ALU2dGridHierarchicIterator;
27  template<class GridImp>
28  class ALU2dGridLevelIntersectionIterator;
29  template<class GridImp>
30  class ALU2dGridLeafIntersectionIterator;
31  template<class GridImp>
32  class ALU2dGridIntersectionIterator;
33  template<int codim, PartitionIteratorType, class GridImp>
34  class ALU2dGridLeafIterator;
35  template< int dim, int dimworld, ALU2DSPACE ElementType eltype >
36  class ALU2dGrid;
37 
38 //**********************************************************************
39 //
40 // --ALU2dGridEntity
41 // --Entity
42 //
43 //**********************************************************************
50 template<int cd, int dim, class GridImp>
52 public EntityDefaultImplementation <cd,dim,GridImp,ALU2dGridEntity>
53 {
54  static const int dimworld = GridImp::dimensionworld;
55  static const ALU2DSPACE ElementType eltype = GridImp::elementType;
56 
57  friend class ALU2dGrid< dim, dimworld, eltype >;
58  friend class ALU2dGridIntersectionIterator < GridImp >;
59  friend class ALU2dGridIntersectionIterator < const GridImp >;
60  friend class ALU2dGridLevelIntersectionIterator < GridImp >;
61  friend class ALU2dGridLevelIntersectionIterator < const GridImp >;
62  friend class ALU2dGridLeafIntersectionIterator < GridImp >;
63  friend class ALU2dGridLeafIntersectionIterator < const GridImp >;
64  friend class ALU2dGridHierarchicIterator < const GridImp >;
65  friend class ALU2dGridHierarchicIterator < GridImp >;
66  friend class ALU2dGridLevelIterator <0,All_Partition,GridImp>;
67  friend class ALU2dGridLevelIterator <1,All_Partition,GridImp>;
68  friend class ALU2dGridLevelIterator <2,All_Partition,GridImp>;
69  friend class ALU2dGridLeafIterator <0, All_Partition,GridImp>;
70  friend class ALU2dGridLeafIterator <1, All_Partition,GridImp>;
71  friend class ALU2dGridLeafIterator <2, All_Partition,GridImp>;
72  friend class ALU2dGridMakeableEntity<0,dim,GridImp>;
73 
74  friend class ALU2dGridHierarchicIndexSet<dim,dimworld,eltype>;
75 
76  typedef typename ALU2dImplTraits< dimworld, eltype >::HElementType HElementType ;
77 
78  typedef typename GridImp::Traits::template Codim< cd >::GeometryImpl GeometryImpl;
79 
80 public:
81  typedef typename GridImp :: GridObjectFactoryType FactoryType;
82 
85 
87  typedef typename GridImp::template Codim<cd>::Entity Entity;
89  typedef typename GridImp::template Codim<cd>::Geometry Geometry;
90 
92  typedef typename GridImp::template Codim<cd>::EntitySeed EntitySeed;
93 
95  typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer;
96 
98  int level () const;
99 
102 
104  ALU2dGridEntity(const ALU2dGridEntity & org);
105 
107  Geometry geometry () const;
108 
110  GeometryType type() const ;
111 
113  void removeElement();
114 
118 
119  void setElement(const ElementType &element, int face=-1, int level = -1) const;
120  void setElement(const EntitySeed& seed ) const;
121  void setElement(const HElementType & el, const VertexType & vx);
122  void setElement(const ALU2dGridEntity & org) const
123  {
124  setElement(*(org.item_), org.face_);
125  }
126 
128  bool equals ( const ALU2dGridEntity<cd,dim,GridImp> & org ) const;
129 
133 
138  int boundaryId () const;
139 
144  EntityPointer ownersFather () const;
145 
147  FieldVector<alu2d_ctype, dim>& positionInOwnersFather () const;
148 
150  const GridImp& grid() const { return factory_.grid(); }
151 
153  const FactoryType& factory() const { return factory_; }
154 
157  {
158  assert( item_ );
159  return *item_;
160  }
161 
163  EntitySeed seed() const
164  {
165  return EntitySeed( getItem(), level(), getFace() );
166  }
167 
168  // return internal face
169  int getFace() const { return face_; }
170 
172  int getIndex () const;
173 
174 private:
176  const FactoryType& factory_;
177 
179  mutable ElementType * item_;
181 
182  mutable GeometryImpl geoObj_;
183 
184  mutable int level_;
185  mutable int face_;
186 };
187 
201 //***********************
202 //
203 // --ALU2dGridEntity
204 // --0Entity
205 //
206 //***********************
207 template<int dim, class GridImp>
208 class ALU2dGridEntity<0,dim,GridImp>
209 : public EntityDefaultImplementation<0,dim,GridImp,ALU2dGridEntity>
210 {
211  static const int dimworld = GridImp::dimensionworld;
212  static const ALU2DSPACE ElementType eltype = GridImp::elementType;
213 
214  friend class ALU2dGrid< dim, dimworld, eltype >;
215  friend class ALU2dGridIntersectionIterator < GridImp >;
216  friend class ALU2dGridIntersectionIterator < const GridImp >;
217  friend class ALU2dGridLevelIntersectionIterator < GridImp >;
218  friend class ALU2dGridLevelIntersectionIterator < const GridImp >;
219  friend class ALU2dGridLeafIntersectionIterator < GridImp >;
220  friend class ALU2dGridLeafIntersectionIterator < const GridImp >;
221  friend class ALU2dGridHierarchicIterator < const GridImp >;
222  friend class ALU2dGridHierarchicIterator < GridImp >;
223  friend class ALU2dGridLevelIterator <0,All_Partition,GridImp>;
224  friend class ALU2dGridLevelIterator <1,All_Partition,GridImp>;
225  friend class ALU2dGridLevelIterator <2,All_Partition,GridImp>;
226  friend class ALU2dGridLeafIterator <0, All_Partition,GridImp>;
227  friend class ALU2dGridLeafIterator <1, All_Partition,GridImp>;
228  friend class ALU2dGridLeafIterator <2, All_Partition,GridImp>;
229  friend class ALU2dGridMakeableEntity<0,dim,GridImp>;
230 
231  friend class ALU2dGridHierarchicIndexSet<dim,dimworld,eltype>;
232 
233  typedef typename ALU2dImplTraits< dimworld, eltype >::HElementType HElementType ;
234 
235  typedef typename GridImp::Traits::template Codim< 0 >::GeometryImpl GeometryImpl;
236  typedef typename GridImp::Traits::template Codim< 0 >::LocalGeometryImpl LocalGeometryImpl;
237 
238 public:
239  typedef typename GridImp :: GridObjectFactoryType FactoryType;
240 
242  typedef typename GridImp::template Codim<0>::Geometry Geometry;
244  typedef typename GridImp::template Codim<0>::LocalGeometry LocalGeometry;
245 
247  typedef typename GridImp::template Codim<0>::EntitySeed EntitySeed;
248 
253 
255  typedef typename GridImp::template Codim<0>::Entity Entity;
257  //typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer;
259 
260  template <int cd>
261  struct Codim
262  {
263  typedef typename GridImp::template Codim<cd>::EntityPointer EntityPointer;
264  };
265 
268 
270  ALU2dGridEntity(const ALU2dGridEntity & org);
271 
273  int level () const ;
274 
276  Geometry geometry () const;
277 
279  GeometryType type() const ;
280 
284  template<int cc>
285  int count () const
286  {
287  assert( item_ );
288  return (cc==0) ? 1 : item_->numvertices();
289  }
290 
295  int boundaryId () const {
296  // elements are always inside of our Domain
297  return 0;
298  }
299 
306  // As ibegin() and iend() are deprecated these methods will deliver a LeafIntersectionIterator
308  {
309  return ileafbegin();
310  }
313  {
314  return ileafend();
315  }
316 
318  {
319  return ALU2dGridLevelIntersectionIteratorType( *this, this->level(),false);
320  }
322  {
323  return ALU2dGridLevelIntersectionIteratorType( *this, this->level(),true);
324  }
326  {
327  return ALU2dGridLeafIntersectionIteratorType( *this, this->level(), false);
328  }
330  {
331  return ALU2dGridLeafIntersectionIteratorType( *this, this->level(),true);
332  }
333 
335  bool isLeaf () const;
336 
339  EntityPointer father () const;
340 
342  bool hasFather () const
343  {
344  return (this->level()>0);
345  }
346 
351  ALU2dGridHierarchicIterator<GridImp> hbegin (int maxLevel) const
352  {
353  return ALU2dGridHierarchicIterator<GridImp> (factory(), *item_ , maxLevel,false);
354  }
355 
357  ALU2dGridHierarchicIterator<GridImp> hend (int maxLevel) const
358  {
359  return ALU2dGridHierarchicIterator<GridImp> (factory(), *item_, maxLevel,true);
360  }
361 
364  template <int cc>
365  typename Codim<cc>::EntityPointer entity (int i) const;
366 
369  template< int codim >
370  typename Codim< codim >::EntityPointer subEntity ( int i ) const
371  {
372  int j = i;
373  // apply mapping for codim 1
374  // dune to alu
375  if( codim == 1 )
376  {
377  if( item_->numvertices() == 3 )
378  j = 2 - i;
379  else
380  switch (i) { case 0: j=2;break;
381  case 1: j=0;break;
382  case 2: j=3;break;
383  case 3: j=1;break;
384  }
385  }
386  else if ( codim == 2 )
387  {
388  if( item_->numvertices() == 4 )
389  {
390  switch (i) { case 0: j=0;break;
391  case 1: j=1;break;
392  case 2: j=3;break;
393  case 3: j=2;break;
394  }
395  }
396  }
397  return entity< codim >( j );
398  }
399 
402  {
403 #if ALU2DGRID_PARALLEL
404  return grid().rankManager().partitionType( item_->getIndex() );
405 #else
406  return InteriorEntity;
407 #endif
408  }
409 
416  template <int cc>
417  int subBoundaryId ( int i ) const;
418 
419 
430  LocalGeometry geometryInFather () const;
431 
433  bool mightVanish () const
434  {
435  return ((item_->is(ALU2DSPACE Refco::crs))==1);
436  }
437 
438  bool isNew () const
439  {
440  return ((item_->wasRefined())==1);
441  }
442 
443  //***************************************************************
444  // Interface for Adaptation
445  //***************************************************************
446 
447  public:
451  bool mark(int refCount) const;
452 
454  int getMark() const;
455 
459  void setElement(const HElementType &element, int face=-1, int level = -1) const;
460  void setElement(const EntitySeed& seed ) const;
461 
462  void setElement(const ALU2dGridEntity & org) const {
463  setElement(*(org.item_));
464  }
465 
467  void reset ( int l );
468 
470  void removeElement();
471 
473  bool equals ( const ALU2dGridEntity<0,dim,GridImp> & org ) const;
474 
475  // return reference to HElement (needed by IntersectionIterator)
476  HElementType & getItem() const
477  {
478  assert( item_ );
479  return *item_;
480  }
481 
483  EntitySeed seed() const
484  {
485  return EntitySeed( getItem() );
486  }
487 
489  const GridImp& grid() const { return factory_.grid(); }
490 
492  const FactoryType& factory() const { return factory_; }
493 
494  // return internal face
495  int getFace() const { return -1; }
496 
498  int getIndex () const;
499 
500 private:
502  int nChild () const;
503 
507  template<int cc> int getSubIndex (int i) const;
508 
509  int subIndex (int i, unsigned int codim) const;
510 
512  const FactoryType& factory_;
513 
515  mutable HElementType *item_;
516 
518  mutable GeometryImpl geoObj_;
519 
521  mutable bool isLeaf_;
522 
523 }; // end of ALU2dGridEntity codim = 0
524 
525 
526 //**********************************************************************
527 //
528 // --ALU2dGridEntityPointer
529 // --EntityPointer
530 // --EnPointer
531 //**********************************************************************
535 template< int codim, class GridImp >
537 {
538  // type of this class
540 
541  static const int dim = GridImp::dimension;
542  static const int dimworld = GridImp::dimensionworld;
543  static const ALU2DSPACE ElementType eltype = GridImp::elementType;
544 
546 
547 public:
548  typedef typename GridImp :: GridObjectFactoryType FactoryType;
549 
550  enum { codimension = codim };
551 
553  typedef typename GridImp::template Codim<codimension>::Entity Entity;
554 
556  typedef typename GridImp::template Codim<codimension>::EntitySeed EntitySeed;
560 
562 
564  ALU2dGridEntityPointer ( const FactoryType& factory,
565  const ElementType &item,
566  int face = -1,
567  int level = -1
568  );
569 
571  ALU2dGridEntityPointer(const FactoryType& factory, const EntitySeed& seed) ;
572 
574  ALU2dGridEntityPointer(const EntityImp& entity) ;
575 
577  ALU2dGridEntityPointer(const FactoryType& factory) ;
578 
580  ALU2dGridEntityPointer(const ThisType & org) ;
581 
584 
586  // this may have to be changed!
587  bool equals (const ThisType & i) const;
588 
590  Entity & dereference() const ;
591 
593  int level () const;
594 
596  ThisType & operator = (const ThisType & org);
597 
599  const GridImp& grid() const { return factory_.grid(); }
600 
601 protected:
602  EntityImp & entityImp();
603  const EntityImp & entityImp() const;
604 
606  void done ();
607 
609  void updateEntityPointer( ElementType * item, int face=-1, int level=-1 );
610 
613 
616 
618  mutable EntityObj * entity_;
619 };
620 
621 } // end namespace Dune
622 
623 #include "entity_imp.cc"
624 #endif