dune-grid  2.2.0
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  switch (codim)
376  {
377  case 1:
378  if( item_->numvertices() == 3 )
379  j = 2 - i;
380  else
381  switch (i) { case 0: j=2;break;
382  case 1: j=0;break;
383  case 2: j=3;break;
384  case 3: j=1;break;
385  }
386  break;
387  case 2:
388  if( item_->numvertices() == 4 )
389  switch (i) { case 0: j=0;break;
390  case 1: j=1;break;
391  case 2: j=3;break;
392  case 3: j=2;break;
393  }
394  break;
395  }
396  return entity< codim >( j );
397  }
398 
401  {
402 #if ALU2DGRID_PARALLEL
403  return grid().rankManager().partitionType( item_->getIndex() );
404 #else
405  return InteriorEntity;
406 #endif
407  }
408 
415  template <int cc>
416  int subBoundaryId ( int i ) const;
417 
418 
429  LocalGeometry geometryInFather () const;
430 
432  bool mightVanish () const
433  {
434  return ((item_->is(ALU2DSPACE Refco::crs))==1);
435  }
436 
437  bool isNew () const
438  {
439  return ((item_->wasRefined())==1);
440  }
441 
442  //***************************************************************
443  // Interface for Adaptation
444  //***************************************************************
445 
446  public:
450  bool mark(int refCount) const;
451 
453  int getMark() const;
454 
458  void setElement(const HElementType &element, int face=-1, int level = -1) const;
459  void setElement(const EntitySeed& seed ) const;
460 
461  void setElement(const ALU2dGridEntity & org) const {
462  setElement(*(org.item_));
463  }
464 
466  void reset ( int l );
467 
469  void removeElement();
470 
472  bool equals ( const ALU2dGridEntity<0,dim,GridImp> & org ) const;
473 
474  // return reference to HElement (needed by IntersectionIterator)
475  HElementType & getItem() const
476  {
477  assert( item_ );
478  return *item_;
479  }
480 
482  EntitySeed seed() const
483  {
484  return EntitySeed( getItem() );
485  }
486 
488  const GridImp& grid() const { return factory_.grid(); }
489 
491  const FactoryType& factory() const { return factory_; }
492 
493  // return internal face
494  int getFace() const { return -1; }
495 
497  int getIndex () const;
498 
499 private:
501  int nChild () const;
502 
506  template<int cc> int getSubIndex (int i) const;
507 
508  int subIndex (int i, unsigned int codim) const;
509 
511  const FactoryType& factory_;
512 
514  mutable HElementType *item_;
515 
517  mutable GeometryImpl geoObj_;
518 
520  mutable bool isLeaf_;
521 
522 }; // end of ALU2dGridEntity codim = 0
523 
524 
525 //**********************************************************************
526 //
527 // --ALU2dGridEntityPointer
528 // --EntityPointer
529 // --EnPointer
530 //**********************************************************************
534 template< int codim, class GridImp >
536 {
537  // type of this class
539 
540  static const int dim = GridImp::dimension;
541  static const int dimworld = GridImp::dimensionworld;
542  static const ALU2DSPACE ElementType eltype = GridImp::elementType;
543 
545 
546 public:
547  typedef typename GridImp :: GridObjectFactoryType FactoryType;
548 
549  enum { codimension = codim };
550 
552  typedef typename GridImp::template Codim<codimension>::Entity Entity;
553 
555  typedef typename GridImp::template Codim<codimension>::EntitySeed EntitySeed;
559 
561 
563  ALU2dGridEntityPointer ( const FactoryType& factory,
564  const ElementType &item,
565  int face = -1,
566  int level = -1
567  );
568 
570  ALU2dGridEntityPointer(const FactoryType& factory, const EntitySeed& seed) ;
571 
573  ALU2dGridEntityPointer(const EntityImp& entity) ;
574 
576  ALU2dGridEntityPointer(const FactoryType& factory) ;
577 
579  ALU2dGridEntityPointer(const ThisType & org) ;
580 
583 
585  // this may have to be changed!
586  bool equals (const ThisType & i) const;
587 
589  Entity & dereference() const ;
590 
592  int level () const;
593 
595  ThisType & operator = (const ThisType & org);
596 
598  const GridImp& grid() const { return factory_.grid(); }
599 
600 protected:
601  EntityImp & entityImp();
602  const EntityImp & entityImp() const;
603 
605  void done ();
606 
608  void updateEntityPointer( ElementType * item, int face=-1, int level=-1 );
609 
612 
615 
617  mutable EntityObj * entity_;
618 };
619 
620 } // end namespace Dune
621 
622 #include "entity_imp.cc"
623 #endif