dune-grid  2.3.1
alugrid/2d/entity.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_ALU2DGRIDENTITY_HH
4 #define DUNE_ALU2DGRIDENTITY_HH
5 
6 // System includes
7 
8 // Dune includes
10 //#include <dune/grid/common/intersectioniteratorwrapper.hh>
11 
12 // Local includes
16 
17 namespace Dune {
18  // Forward declarations
19  template<int cd, int dim, class GridImp>
20  class ALU2dGridEntity;
21  template<int cd, PartitionIteratorType pitype, class GridImp >
22  class ALU2dGridLevelIterator;
23  template< int codim, class GridImp >
24  class ALU2dGridEntityPointer;
25  template<int mydim, int coorddim, class GridImp>
26  class ALU2dGridGeometry;
27  template<class GridImp>
28  class ALU2dGridHierarchicIterator;
29  template<class GridImp>
30  class ALU2dGridLevelIntersectionIterator;
31  template<class GridImp>
32  class ALU2dGridLeafIntersectionIterator;
33  template<class GridImp>
34  class ALU2dGridIntersectionIterator;
35  template<int codim, PartitionIteratorType, class GridImp>
36  class ALU2dGridLeafIterator;
37  template< int dim, int dimworld, ALU2DSPACE ElementType eltype >
38  class ALU2dGrid;
39 
40  //**********************************************************************
41  //
42  // --ALU2dGridEntity
43  // --Entity
44  //
45  //**********************************************************************
52  template<int cd, int dim, class GridImp>
54  public EntityDefaultImplementation <cd,dim,GridImp,ALU2dGridEntity>
55  {
56  static const int dimworld = GridImp::dimensionworld;
57  static const ALU2DSPACE ElementType eltype = GridImp::elementType;
58 
59  friend class ALU2dGrid< dim, dimworld, eltype >;
60  friend class ALU2dGridIntersectionIterator < GridImp >;
61  friend class ALU2dGridIntersectionIterator < const GridImp >;
62  friend class ALU2dGridLevelIntersectionIterator < GridImp >;
63  friend class ALU2dGridLevelIntersectionIterator < const GridImp >;
64  friend class ALU2dGridLeafIntersectionIterator < GridImp >;
65  friend class ALU2dGridLeafIntersectionIterator < const GridImp >;
66  friend class ALU2dGridHierarchicIterator < const GridImp >;
67  friend class ALU2dGridHierarchicIterator < GridImp >;
68  friend class ALU2dGridLevelIterator <0,All_Partition,GridImp>;
69  friend class ALU2dGridLevelIterator <1,All_Partition,GridImp>;
70  friend class ALU2dGridLevelIterator <2,All_Partition,GridImp>;
71  friend class ALU2dGridLeafIterator <0, All_Partition,GridImp>;
72  friend class ALU2dGridLeafIterator <1, All_Partition,GridImp>;
73  friend class ALU2dGridLeafIterator <2, All_Partition,GridImp>;
74  friend class ALU2dGridMakeableEntity<0,dim,GridImp>;
75 
76  friend class ALU2dGridHierarchicIndexSet<dim,dimworld,eltype>;
77 
78  typedef typename ALU2dImplTraits< dimworld, eltype >::HElementType HElementType ;
79 
80  typedef typename GridImp::Traits::template Codim< cd >::GeometryImpl GeometryImpl;
81 
82  public:
83  typedef typename GridImp :: GridObjectFactoryType FactoryType;
84 
87 
89  typedef typename GridImp::template Codim<cd>::Entity Entity;
91  typedef typename GridImp::template Codim<cd>::Geometry Geometry;
92 
94  typedef typename GridImp::template Codim<cd>::EntitySeed EntitySeed;
95 
97  typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer;
98 
100  int level () const;
101 
104 
106  ALU2dGridEntity(const ALU2dGridEntity & org);
107 
109  Geometry geometry () const;
110 
112  GeometryType type() const ;
113 
115  void removeElement();
116 
120 
121  void setElement(const ElementType &element, int face=-1, int level = -1) const;
122  void setElement(const EntitySeed& seed ) const;
123  void setElement(const HElementType & el, const VertexType & vx);
124  void setElement(const ALU2dGridEntity & org) const
125  {
126  setElement(*(org.item_), org.face_);
127  }
128 
130  bool equals ( const ALU2dGridEntity<cd,dim,GridImp> & org ) const;
131 
135 
140  int boundaryId () const;
141 
146  EntityPointer ownersFather () const;
147 
149  FieldVector<alu2d_ctype, dim>& positionInOwnersFather () const;
150 
152  const GridImp& grid() const { return factory_.grid(); }
153 
155  const FactoryType& factory() const { return factory_; }
156 
159  {
160  assert( item_ );
161  return *item_;
162  }
163 
165  EntitySeed seed() const
166  {
167  return EntitySeed( getItem(), level(), getFace() );
168  }
169 
170  // return internal face
171  int getFace() const { return face_; }
172 
174  int getIndex () const;
175 
176  private:
178  const FactoryType& factory_;
179 
181  mutable ElementType * item_;
183 
184  mutable GeometryImpl geoObj_;
185 
186  mutable int level_;
187  mutable int face_;
188  };
189 
203  //***********************
204  //
205  // --ALU2dGridEntity
206  // --0Entity
207  //
208  //***********************
209  template<int dim, class GridImp>
210  class ALU2dGridEntity<0,dim,GridImp>
211  : public EntityDefaultImplementation<0,dim,GridImp,ALU2dGridEntity>
212  {
213  static const int dimworld = GridImp::dimensionworld;
214  static const ALU2DSPACE ElementType eltype = GridImp::elementType;
215 
216  friend class ALU2dGrid< dim, dimworld, eltype >;
217  friend class ALU2dGridIntersectionIterator < GridImp >;
218  friend class ALU2dGridIntersectionIterator < const GridImp >;
219  friend class ALU2dGridLevelIntersectionIterator < GridImp >;
220  friend class ALU2dGridLevelIntersectionIterator < const GridImp >;
221  friend class ALU2dGridLeafIntersectionIterator < GridImp >;
222  friend class ALU2dGridLeafIntersectionIterator < const GridImp >;
223  friend class ALU2dGridHierarchicIterator < const GridImp >;
224  friend class ALU2dGridHierarchicIterator < GridImp >;
225  friend class ALU2dGridLevelIterator <0,All_Partition,GridImp>;
226  friend class ALU2dGridLevelIterator <1,All_Partition,GridImp>;
227  friend class ALU2dGridLevelIterator <2,All_Partition,GridImp>;
228  friend class ALU2dGridLeafIterator <0, All_Partition,GridImp>;
229  friend class ALU2dGridLeafIterator <1, All_Partition,GridImp>;
230  friend class ALU2dGridLeafIterator <2, All_Partition,GridImp>;
231  friend class ALU2dGridMakeableEntity<0,dim,GridImp>;
232 
233  friend class ALU2dGridHierarchicIndexSet<dim,dimworld,eltype>;
234 
235  typedef typename ALU2dImplTraits< dimworld, eltype >::HElementType HElementType ;
236 
237  typedef typename GridImp::Traits::template Codim< 0 >::GeometryImpl GeometryImpl;
238  typedef typename GridImp::Traits::template Codim< 0 >::LocalGeometryImpl LocalGeometryImpl;
239 
240  public:
241  typedef typename GridImp :: GridObjectFactoryType FactoryType;
242 
244  typedef typename GridImp::template Codim<0>::Geometry Geometry;
246  typedef typename GridImp::template Codim<0>::LocalGeometry LocalGeometry;
247 
249  typedef typename GridImp::template Codim<0>::EntitySeed EntitySeed;
250 
255 
257  typedef typename GridImp::template Codim<0>::Entity Entity;
259  //typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer;
261 
262  template <int cd>
263  struct Codim
264  {
265  typedef typename GridImp::template Codim<cd>::EntityPointer EntityPointer;
266  };
267 
270 
272  ALU2dGridEntity(const ALU2dGridEntity & org);
273 
275  int level () const ;
276 
278  Geometry geometry () const;
279 
281  GeometryType type() const ;
282 
286  template<int cc>
287  int count () const
288  {
289  assert( item_ );
290  return (cc==0) ? 1 : item_->numvertices();
291  }
292 
297  int boundaryId () const {
298  // elements are always inside of our Domain
299  return 0;
300  }
301 
307 
308  // As ibegin() and iend() are deprecated these methods will deliver a LeafIntersectionIterator
310  DUNE_DEPRECATED_MSG("Use ileafbegin() instead.")
311  {
312  return ileafbegin();
313  }
317  DUNE_DEPRECATED_MSG("Use ileafend() instead.")
318  {
319  return ileafend();
320  }
321 
323  {
324  return ALU2dGridLevelIntersectionIteratorType( *this, this->level(),false);
325  }
327  {
328  return ALU2dGridLevelIntersectionIteratorType( *this, this->level(),true);
329  }
331  {
332  return ALU2dGridLeafIntersectionIteratorType( *this, this->level(), false);
333  }
335  {
336  return ALU2dGridLeafIntersectionIteratorType( *this, this->level(),true);
337  }
338 
340  bool isLeaf () const;
341 
344  EntityPointer father () const;
345 
347  bool hasFather () const
348  {
349  return (this->level()>0);
350  }
351 
356  ALU2dGridHierarchicIterator<GridImp> hbegin (int maxLevel) const
357  {
358  return ALU2dGridHierarchicIterator<GridImp> (factory(), *item_ , maxLevel,false);
359  }
360 
362  ALU2dGridHierarchicIterator<GridImp> hend (int maxLevel) const
363  {
364  return ALU2dGridHierarchicIterator<GridImp> (factory(), *item_, maxLevel,true);
365  }
366 
369  template <int cc>
370  typename Codim<cc>::EntityPointer entity (int i) const;
371 
374  template< int codim >
375  typename Codim< codim >::EntityPointer subEntity ( int i ) const
376  {
377  int j = i;
378  // apply mapping for codim 1
379  // dune to alu
380  if( codim == 1 )
381  {
382  if( item_->numvertices() == 3 )
383  j = 2 - i;
384  else
385  switch (i) { case 0 : j=2;break;
386  case 1 : j=0;break;
387  case 2 : j=3;break;
388  case 3 : j=1;break;}
389  }
390  else if ( codim == 2 )
391  {
392  if( item_->numvertices() == 4 )
393  {
394  switch (i) { case 0 : j=0;break;
395  case 1 : j=1;break;
396  case 2 : j=3;break;
397  case 3 : j=2;break;}
398  }
399  }
400  return entity< codim >( j );
401  }
402 
405  {
406 #if ALU2DGRID_PARALLEL
407  return grid().rankManager().partitionType( item_->getIndex() );
408 #else
409  return InteriorEntity;
410 #endif
411  }
412 
419  template <int cc>
420  int subBoundaryId ( int i ) const;
421 
422 
433  LocalGeometry geometryInFather () const;
434 
436  bool mightVanish () const
437  {
438  return ((item_->is(ALU2DSPACE Refco::crs))==1);
439  }
440 
441  bool isNew () const
442  {
443  return ((item_->wasRefined())==1);
444  }
445 
446  //***************************************************************
447  // Interface for Adaptation
448  //***************************************************************
449 
450  public:
454  bool mark(int refCount) const;
455 
457  int getMark() const;
458 
462  void setElement(const HElementType &element, int face=-1, int level = -1) const;
463  void setElement(const EntitySeed& seed ) const;
464 
465  void setElement(const ALU2dGridEntity & org) const {
466  setElement(*(org.item_));
467  }
468 
470  void reset ( int l );
471 
473  void removeElement();
474 
476  bool equals ( const ALU2dGridEntity<0,dim,GridImp> & org ) const;
477 
478  // return reference to HElement (needed by IntersectionIterator)
479  HElementType & getItem() const
480  {
481  assert( item_ );
482  return *item_;
483  }
484 
486  EntitySeed seed() const
487  {
488  return EntitySeed( getItem() );
489  }
490 
492  const GridImp& grid() const { return factory_.grid(); }
493 
495  const FactoryType& factory() const { return factory_; }
496 
497  // return internal face
498  int getFace() const { return -1; }
499 
501  int getIndex () const;
502 
503  private:
505  int nChild () const;
506 
510  template<int cc> int getSubIndex (int i) const;
511 
512  int subIndex (int i, unsigned int codim) const;
513 
515  const FactoryType& factory_;
516 
518  mutable HElementType *item_;
519 
521  mutable GeometryImpl geoObj_;
522 
524  mutable bool isLeaf_;
525 
526  }; // end of ALU2dGridEntity codim = 0
527 
528 
529  //**********************************************************************
530  //
531  // --ALU2dGridEntityPointer
532  // --EntityPointer
533  // --EnPointer
534  //**********************************************************************
538  template< int codim, class GridImp >
540  {
541  // type of this class
543 
544  static const int dim = GridImp::dimension;
545  static const int dimworld = GridImp::dimensionworld;
546  static const ALU2DSPACE ElementType eltype = GridImp::elementType;
547 
549 
550  public:
551  typedef typename GridImp :: GridObjectFactoryType FactoryType;
552 
553  enum { codimension = codim };
554 
556  typedef typename GridImp::template Codim<codimension>::Entity Entity;
557 
559  typedef typename GridImp::template Codim<codimension>::EntitySeed EntitySeed;
563 
565 
567  ALU2dGridEntityPointer ( const FactoryType& factory,
568  const ElementType &item,
569  int face = -1,
570  int level = -1
571  );
572 
574  ALU2dGridEntityPointer(const FactoryType& factory, const EntitySeed& seed) ;
575 
577  ALU2dGridEntityPointer(const EntityImp& entity) ;
578 
580  ALU2dGridEntityPointer(const FactoryType& factory) ;
581 
583  ALU2dGridEntityPointer(const ThisType & org) ;
584 
587 
589  // this may have to be changed!
590  bool equals (const ThisType & i) const;
591 
593  Entity & dereference() const ;
594 
596  int level () const;
597 
599  ThisType & operator = (const ThisType & org);
600 
602  const GridImp& grid() const { return factory_.grid(); }
603 
604  protected:
605  EntityImp & entityImp();
606  const EntityImp & entityImp() const;
607 
609  void done ();
610 
612  void updateEntityPointer( ElementType * item, int face=-1, int level=-1 );
613 
616 
619 
621  mutable EntityObj * entity_;
622  };
623 
624 } // end namespace Dune
625 
626 #include "entity_imp.cc"
627 #endif