dune-grid  2.4.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>
21  template<int cd, PartitionIteratorType pitype, class GridImp >
23  template< int codim, class GridImp >
25  template<int mydim, int coorddim, class GridImp>
27  template<class GridImp>
29  template<class GridImp>
31  template<class GridImp>
33  template<class GridImp>
35  template<int codim, PartitionIteratorType, class GridImp>
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>
53  class ALU2dGridEntity :
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 
103  ALU2dGridEntity(const FactoryType& factory, int level);
104 
106  ALU2dGridEntity(const ALU2dGridEntity & org);
107 
109  Geometry geometry () const;
110 
112  GeometryType type() const ;
113 
115  void removeElement();
116 
120  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 
158  ElementType& getItem() const
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 
254  typedef ALU2dGridLeafIntersectionIteratorType ALU2dGridIntersectionIteratorType;
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 
269  ALU2dGridEntity(const FactoryType& factory, int level);
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 
296  unsigned int subEntities (unsigned int codim) const
297  {
298  assert( item_ );
299  return (codim==0) ? 1 : item_->numvertices();
300  }
301 
306  int boundaryId () const {
307  // elements are always inside of our Domain
308  return 0;
309  }
310 
316  // As ibegin() and iend() are deprecated these methods will deliver a LeafIntersectionIterator
318  ALU2dGridIntersectionIteratorType ibegin () const
319  DUNE_DEPRECATED_MSG("Use ileafbegin() instead.")
320  {
321  return ileafbegin();
322  }
325  ALU2dGridIntersectionIteratorType iend () const
326  DUNE_DEPRECATED_MSG("Use ileafend() instead.")
327  {
328  return ileafend();
329  }
330 
331  ALU2dGridLevelIntersectionIteratorType ilevelbegin () const
332  {
333  return ALU2dGridLevelIntersectionIteratorType( *this, this->level(),false);
334  }
335  ALU2dGridLevelIntersectionIteratorType ilevelend () const
336  {
337  return ALU2dGridLevelIntersectionIteratorType( *this, this->level(),true);
338  }
339  ALU2dGridLeafIntersectionIteratorType ileafbegin () const
340  {
341  return ALU2dGridLeafIntersectionIteratorType( *this, this->level(), false);
342  }
343  ALU2dGridLeafIntersectionIteratorType ileafend () const
344  {
345  return ALU2dGridLeafIntersectionIteratorType( *this, this->level(),true);
346  }
347 
349  bool isLeaf () const;
350 
353  EntityPointer father () const;
354 
356  bool hasFather () const
357  {
358  return (this->level()>0);
359  }
360 
366  {
367  return ALU2dGridHierarchicIterator<GridImp> (factory(), *item_ , maxLevel,false);
368  }
369 
372  {
373  return ALU2dGridHierarchicIterator<GridImp> (factory(), *item_, maxLevel,true);
374  }
375 
378  template <int cc>
379  typename Codim<cc>::EntityPointer entity (int i) const;
380 
383  template< int codim >
384  typename Codim< codim >::EntityPointer subEntity ( int i ) const
385  {
386  int j = i;
387  // apply mapping for codim 1
388  // dune to alu
389  if( codim == 1 )
390  {
391  if( item_->numvertices() == 3 )
392  j = 2 - i;
393  else
394  switch (i) { case 0 : j=2;break;
395  case 1 : j=0;break;
396  case 2 : j=3;break;
397  case 3 : j=1;break;}
398  }
399  else if ( codim == 2 )
400  {
401  if( item_->numvertices() == 4 )
402  {
403  switch (i) { case 0 : j=0;break;
404  case 1 : j=1;break;
405  case 2 : j=3;break;
406  case 3 : j=2;break;}
407  }
408  }
409  return entity< codim >( j );
410  }
411 
414  {
415 #if ALU2DGRID_PARALLEL
416  return grid().rankManager().partitionType( item_->getIndex() );
417 #else
418  return InteriorEntity;
419 #endif
420  }
421 
428  template <int cc>
429  int subBoundaryId ( int i ) const;
430 
431 
442  LocalGeometry geometryInFather () const;
443 
445  bool mightVanish () const
446  {
447  return ((item_->is(ALU2DSPACE Refco::crs))==1);
448  }
449 
450  bool isNew () const
451  {
452  return ((item_->wasRefined())==1);
453  }
454 
455  //***************************************************************
456  // Interface for Adaptation
457  //***************************************************************
458 
459  public:
463  bool mark(int refCount) const;
464 
466  int getMark() const;
467 
471  void setElement(const HElementType &element, int face=-1, int level = -1) const;
472  void setElement(const EntitySeed& seed ) const;
473 
474  void setElement(const ALU2dGridEntity & org) const {
475  setElement(*(org.item_));
476  }
477 
479  void reset ( int l );
480 
482  void removeElement();
483 
485  bool equals ( const ALU2dGridEntity<0,dim,GridImp> & org ) const;
486 
487  // return reference to HElement (needed by IntersectionIterator)
488  HElementType & getItem() const
489  {
490  assert( item_ );
491  return *item_;
492  }
493 
495  EntitySeed seed() const
496  {
497  return EntitySeed( getItem() );
498  }
499 
501  const GridImp& grid() const { return factory_.grid(); }
502 
504  const FactoryType& factory() const { return factory_; }
505 
506  // return internal face
507  int getFace() const { return -1; }
508 
510  int getIndex () const;
511 
512  private:
514  int nChild () const;
515 
519  template<int cc> int getSubIndex (int i) const;
520 
521  int subIndex (int i, unsigned int codim) const;
522 
524  const FactoryType& factory_;
525 
527  mutable HElementType *item_;
528 
530  mutable GeometryImpl geoObj_;
531 
533  mutable bool isLeaf_;
534 
535  }; // end of ALU2dGridEntity codim = 0
536 
537 
538  //**********************************************************************
539  //
540  // --ALU2dGridEntityPointer
541  // --EntityPointer
542  // --EnPointer
543  //**********************************************************************
547  template< int codim, class GridImp >
548  class ALU2dGridEntityPointer
549  {
550  // type of this class
551  typedef ALU2dGridEntityPointer< codim, GridImp > ThisType;
552 
553  static const int dim = GridImp::dimension;
554  static const int dimworld = GridImp::dimensionworld;
555  static const ALU2DSPACE ElementType eltype = GridImp::elementType;
556 
558 
559  public:
560  typedef typename GridImp :: GridObjectFactoryType FactoryType;
561 
562  enum { codimension = codim };
563 
565  typedef typename GridImp::template Codim<codimension>::Entity Entity;
566 
568  typedef typename GridImp::template Codim<codimension>::EntitySeed EntitySeed;
572 
574 
576  ALU2dGridEntityPointer ( const FactoryType& factory,
577  const ElementType &item,
578  int face = -1,
579  int level = -1
580  );
581 
583  ALU2dGridEntityPointer(const FactoryType& factory, const EntitySeed& seed) ;
584 
586  ALU2dGridEntityPointer(const EntityImp& entity) ;
587 
589  ALU2dGridEntityPointer(const FactoryType& factory) ;
590 
592  ALU2dGridEntityPointer(const ThisType & org) ;
593 
596 
598  // this may have to be changed!
599  bool equals (const ThisType & i) const;
600 
602  Entity & dereference() const ;
603 
605  int level () const;
606 
608  ThisType & operator = (const ThisType & org);
609 
611  const GridImp& grid() const { return factory_.grid(); }
612 
613  protected:
614  EntityImp & entityImp();
615  const EntityImp & entityImp() const;
616 
618  void done ();
619 
621  void updateEntityPointer( ElementType * item, int face=-1, int level=-1 );
622 
624  const FactoryType& factory_;
625 
627  EntitySeed seed_ ;
628 
630  mutable EntityObj * entity_;
631  };
632 
633 } // end namespace Dune
634 
635 #include "entity_imp.cc"
636 #endif
ElementType & getItem() const
return reference to current item
Definition: alugrid/2d/entity.hh:158
GridImp::GridObjectFactoryType FactoryType
Definition: alugrid/2d/entity.hh:560
Definition: alugrid/2d/entity.hh:30
HmeshType::helement_t HElementType
Definition: alu2dinclude.hh:108
Definition: alugrid/2d/entity.hh:562
int count() const
Definition: alugrid/2d/entity.hh:287
Dune::ALU2dImplTraits< dimworld, eltype >::template Codim< 2 >::InterfaceType VertexType
Definition: alugrid/2d/entity.hh:86
void done()
has to be called when iterator is finished
ALU2dGridEntityPointer< 0, GridImp > EntityPointer
tpye of entitypointer interface
Definition: alugrid/2d/entity.hh:260
void removeElement()
set item pointer to NULL
PartitionType partitionType() const
Definition: alugrid/2d/entity.hh:134
void setElement(const ALU2dGridEntity &org) const
Definition: alugrid/2d/entity.hh:124
ALU2dGridEntityPointer< codimension, GridImp > EntityPointerImp
Definition: alugrid/2d/entity.hh:573
EntityObj * entity_
entity that this EntityPointer points to
Definition: alugrid/2d/entity.hh:630
Definition: alugrid/2d/entity.hh:26
ALU2dGridLeafIntersectionIteratorType ileafbegin() const
Definition: alugrid/2d/entity.hh:339
const GridImp & grid() const
return reference to grid
Definition: alugrid/2d/entity.hh:501
bool hasFather() const
returns true if father entity exists
Definition: alugrid/2d/entity.hh:356
Definition: alugrid/2d/entity.hh:32
GridImp::template Codim< cd >::Entity Entity
type of our interface entity
Definition: alugrid/2d/entity.hh:89
GridImp::template Codim< 0 >::EntitySeed EntitySeed
typedef of my type
Definition: alugrid/2d/entity.hh:249
void setElement(const ALU2dGridEntity &org) const
Definition: alugrid/2d/entity.hh:474
GridImp::template Codim< codimension >::EntitySeed EntitySeed
type of the seed
Definition: alugrid/2d/entity.hh:568
GridImp::template Codim< cd >::EntityPointer EntityPointer
Definition: alugrid/2d/entity.hh:265
const FactoryType & factory() const
return reference to factory
Definition: alugrid/2d/entity.hh:155
ALU2dGridLeafIntersectionIteratorType ileafend() const
Definition: alugrid/2d/entity.hh:343
GridImp::template Codim< 0 >::EntityPointer EntityPointer
tpye of EntityPointer
Definition: alugrid/2d/entity.hh:97
LeafIntersectionIteratorWrapper< GridImp > ALU2dGridLeafIntersectionIteratorType
tpye of intersection iterator
Definition: alugrid/2d/entity.hh:252
~ALU2dGridEntityPointer()
Destructor.
const GridImp & grid() const
return reference top grid
Definition: alugrid/2d/entity.hh:611
unsigned int subEntities(unsigned int codim) const
Definition: alugrid/2d/entity.hh:296
all interior entities
Definition: gridenums.hh:29
Definition: alugrid/2d/entity.hh:34
Default Implementations for EntityImp.
Definition: common/entity.hh:739
Hierarchic Iterator of ALU2dGrid.
Definition: alugrid/2d/entity.hh:28
all entities
Definition: gridenums.hh:139
GridImp::template Codim< cd >::EntitySeed EntitySeed
typedef of my type
Definition: alugrid/2d/entity.hh:94
EntitySeed seed() const
return seed of entity
Definition: alugrid/2d/entity.hh:165
ALU2dGridHierarchicIterator< GridImp > hbegin(int maxLevel) const
Definition: alugrid/2d/entity.hh:365
int boundaryId() const
Id of the boundary which is associated with the entity, returns 0 for inner entities, arbitrary int otherwise.
Definition: alugrid/2d/entity.hh:306
ALU2dGridHierarchicIterator< GridImp > hend(int maxLevel) const
Returns iterator to one past the last son.
Definition: alugrid/2d/entity.hh:371
const FactoryType & factory() const
return reference to factory
Definition: alugrid/2d/entity.hh:504
HElementType & getItem() const
Definition: alugrid/2d/entity.hh:488
ALU2dGridLeafIntersectionIteratorType ALU2dGridIntersectionIteratorType
Definition: alugrid/2d/entity.hh:254
InterfaceType
Parameter to be used for the communication functions.
Definition: gridenums.hh:84
PartitionType partitionType() const
return partition type of this entity ( see grid.hh )
Definition: alugrid/2d/entity.hh:413
ALU2dGridIntersectionIteratorType iend() const
Definition: alugrid/2d/entity.hh:325
MakeableInterfaceObject< Entity > EntityObj
Definition: alugrid/2d/entity.hh:571
Class that wraps IntersectionIteratorImp of a grid and gets it's internal object from a object stack ...
Definition: intersectioniteratorwrapper.hh:327
EntitySeed seed_
the essential information
Definition: alugrid/2d/entity.hh:627
int getFace() const
Definition: alugrid/2d/entity.hh:171
GridImp::GridObjectFactoryType FactoryType
Definition: alugrid/2d/entity.hh:83
Definition: alu2dinclude.hh:97
ALU2dGridEntity(const FactoryType &factory, int level)
Constructor.
ALU2dGridLevelIntersectionIteratorType ilevelbegin() const
Definition: alugrid/2d/entity.hh:331
void updateEntityPointer(ElementType *item, int face=-1, int level=-1)
update underlying item pointer and set entity
void setElement(const ElementType &element, int face=-1, int level=-1) const
set element as normal entity
EntityPointer ownersFather() const
bool equals(const ThisType &i) const
equality
GridImp::template Codim< 0 >::Entity Entity
type of entity interface
Definition: alugrid/2d/entity.hh:257
Definition: alugrid/2d/entity.hh:210
GridImp::template Codim< 0 >::LocalGeometry LocalGeometry
type of corresponding interface local geometry
Definition: alugrid/2d/entity.hh:246
Entity & dereference() const
dereferencing
GridImp::template Codim< codimension >::Entity Entity
type of stored entity (interface)
Definition: alugrid/2d/entity.hh:565
GeometryType type() const
return type of geometry
Codim< codim >::EntityPointer subEntity(int i) const
Definition: alugrid/2d/entity.hh:384
Definition: alugrid/2d/entity.hh:22
Class that wraps IntersectionIteratorImp of a grid and gets it's internal object from a object stack ...
Definition: intersectioniteratorwrapper.hh:232
bool mightVanish() const
The former state() method has been replaced by:
Definition: alugrid/2d/entity.hh:445
const GridImp & grid() const
return reference to grid
Definition: alugrid/2d/entity.hh:152
GridImp::template Codim< 0 >::Geometry Geometry
type of our Geometry interface
Definition: alugrid/2d/entity.hh:244
LevelIntersectionIteratorWrapper< GridImp > ALU2dGridLevelIntersectionIteratorType
Definition: alugrid/2d/entity.hh:253
Definition: alugrid/2d/grid.hh:60
int level() const
ask for level of entities
ALU2dGridIntersectionIteratorType ibegin() const
Definition: alugrid/2d/entity.hh:318
GridImp::GridObjectFactoryType FactoryType
Definition: alugrid/2d/entity.hh:241
ALU2dGridEntity< codimension, dim, GridImp > EntityImp
tpye of stored entity (implementation)
Definition: alugrid/2d/entity.hh:570
ALU2dGridEntityPointer(const FactoryType &factory, const ElementType &item, int face=-1, int level=-1)
Constructor for EntityPointer that points to an element.
EntitySeed seed() const
return seed of entity
Definition: alugrid/2d/entity.hh:495
bool equals(const ALU2dGridEntity< cd, dim, GridImp > &org) const
compare 2 elements
hierarchic index set of ALU2dGrid
Definition: alugrid/2d/grid.hh:66
int getIndex() const
index is unique within the grid hierachie and per codim
bool isNew() const
Definition: alugrid/2d/entity.hh:450
#define ALU2DSPACE
Definition: alu2dinclude.hh:34
int getFace() const
Definition: alugrid/2d/entity.hh:507
Definition: alugrid/2d/entity.hh:36
GridImp::template Codim< cd >::Geometry Geometry
type of corresponding interface geometry
Definition: alugrid/2d/entity.hh:91
Definition: alugrid/2d/entity.hh:24
Geometry geometry() const
geometry of this entity
ThisType & operator=(const ThisType &org)
assigment operator
Definition: alugrid/2d/entity.hh:20
Include standard header files.
Definition: agrid.hh:59
FieldVector< alu2d_ctype, dim > & positionInOwnersFather() const
my position in local coordinates of the owners father
Dune::ALU2dImplTraits< dimworld, eltype >::template Codim< cd >::InterfaceType ElementType
Definition: alugrid/2d/entity.hh:85
const FactoryType & factory_
reference to entity factory
Definition: alugrid/2d/entity.hh:624
ALU2dGridLevelIntersectionIteratorType ilevelend() const
Definition: alugrid/2d/entity.hh:335
int level() const
level of this element
[ provides Dune::Grid ]
Definition: alugrid/2d/entity.hh:38
int boundaryId() const
Id of the boundary which is associated with the entity, returns 0 for inner entities, arbitrary int otherwise.
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:178
PartitionType
Attributes used in the generic overlap model.
Definition: gridenums.hh:28