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>
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 
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 
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  // 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 
357  {
358  return ALU2dGridHierarchicIterator<GridImp> (factory(), *item_ , maxLevel,false);
359  }
360 
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 >
539  class ALU2dGridEntityPointer
540  {
541  // type of this class
542  typedef ALU2dGridEntityPointer< codim, GridImp > ThisType;
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
EntitySeed seed() const
return seed of entity
Definition: alugrid/2d/entity.hh:486
int boundaryId() const
Id of the boundary which is associated with the entity, returns 0 for inner entities, arbitrary int otherwise.
const FactoryType & factory() const
return reference to factory
Definition: alugrid/2d/entity.hh:155
Dune::ALU2dImplTraits< dimworld, eltype >::template Codim< 2 >::InterfaceType VertexType
Definition: alugrid/2d/entity.hh:86
Definition: alugrid/2d/entity.hh:22
int getFace() const
Definition: alugrid/2d/entity.hh:498
PartitionType partitionType() const
Definition: alugrid/2d/entity.hh:134
ThisType & operator=(const ThisType &org)
assigment operator
EntityObj * entity_
entity that this EntityPointer points to
Definition: alugrid/2d/entity.hh:621
#define ALU2DSPACE
Definition: alu2dinclude.hh:34
all entities
Definition: gridenums.hh:135
void updateEntityPointer(ElementType *item, int face=-1, int level=-1)
update underlying item pointer and set entity
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:178
ALU2dGridIntersectionIteratorType iend() const
Definition: alugrid/2d/entity.hh:316
hierarchic index set of ALU2dGrid
Definition: alugrid/2d/grid.hh:67
void done()
has to be called when iterator is finished
int level() const
level of this element
void setElement(const ALU2dGridEntity &org) const
Definition: alugrid/2d/entity.hh:124
Definition: alugrid/2d/entity.hh:36
ALU2dGridEntityPointer< codimension, GridImp > EntityPointerImp
Definition: alugrid/2d/entity.hh:564
HmeshType::helement_t HElementType
Definition: alu2dinclude.hh:108
ALU2dGridLevelIntersectionIteratorType ilevelbegin() const
Definition: alugrid/2d/entity.hh:322
GridImp::template Codim< cd >::EntitySeed EntitySeed
typedef of my type
Definition: alugrid/2d/entity.hh:94
Definition: alugrid/2d/entity.hh:34
Wrapper class for pointers to entities.
Definition: common/entitypointer.hh:91
ALU2dGridHierarchicIterator< GridImp > hbegin(int maxLevel) const
Definition: alugrid/2d/entity.hh:356
ElementType & getItem() const
return reference to current item
Definition: alugrid/2d/entity.hh:158
Definition: alugrid/2d/entity.hh:20
GridImp::template Codim< 0 >::Entity Entity
type of entity interface
Definition: alugrid/2d/entity.hh:257
GridImp::template Codim< 0 >::LocalGeometry LocalGeometry
type of corresponding interface local geometry
Definition: alugrid/2d/entity.hh:246
HElementType & getItem() const
Definition: alugrid/2d/entity.hh:479
Definition: alugrid/2d/entity.hh:30
GridImp::template Codim< codimension >::EntitySeed EntitySeed
type of the seed
Definition: alugrid/2d/entity.hh:559
GridImp::template Codim< 0 >::EntityPointer EntityPointer
tpye of EntityPointer
Definition: alugrid/2d/entity.hh:97
GridImp::GridObjectFactoryType FactoryType
Definition: alugrid/2d/entity.hh:241
EntitySeed seed_
the essential information
Definition: alugrid/2d/entity.hh:618
void removeElement()
set item pointer to NULL
ALU2dGridEntity(const FactoryType &factory, int level)
Constructor.
const GridImp & grid() const
return reference to grid
Definition: alugrid/2d/entity.hh:492
Class that wraps IntersectionIteratorImp of a grid and gets it's internal object from a object stack ...
Definition: intersectioniteratorwrapper.hh:238
Definition: alugrid/2d/entity.hh:32
ALU2dGridEntityPointer(const FactoryType &factory, const ElementType &item, int face=-1, int level=-1)
Constructor for EntityPointer that points to an element.
Entity & dereference() const
dereferencing
GeometryType type() const
return type of geometry
Codim< codim >::EntityPointer subEntity(int i) const
Definition: alugrid/2d/entity.hh:375
EntitySeed seed() const
return seed of entity
Definition: alugrid/2d/entity.hh:165
bool mightVanish() const
The former state() method has been replaced by:
Definition: alugrid/2d/entity.hh:436
const GridImp & grid() const
return reference to grid
Definition: alugrid/2d/entity.hh:152
Definition: alugrid/2d/entity.hh:26
ALU2dGridLevelIntersectionIteratorType ilevelend() const
Definition: alugrid/2d/entity.hh:326
Default Implementations for EntityImp.
Definition: common/entity.hh:552
Class that wraps IntersectionIteratorImp of a grid and gets it's internal object from a object stack ...
Definition: intersectioniteratorwrapper.hh:333
ALU2dGridEntityPointer< 0, GridImp > EntityPointer
tpye of entitypointer interface
Definition: alugrid/2d/entity.hh:260
ALU2dGridEntity< codimension, dim, GridImp > EntityImp
tpye of stored entity (implementation)
Definition: alugrid/2d/entity.hh:561
GridImp::GridObjectFactoryType FactoryType
Definition: alugrid/2d/entity.hh:551
PartitionType
Attributes used in the generic overlap model.
Definition: gridenums.hh:24
bool isNew() const
Definition: alugrid/2d/entity.hh:441
bool hasFather() const
returns true if father entity exists
Definition: alugrid/2d/entity.hh:347
GridImp::template Codim< 0 >::EntitySeed EntitySeed
typedef of my type
Definition: alugrid/2d/entity.hh:249
int getFace() const
Definition: alugrid/2d/entity.hh:171
GridImp::GridObjectFactoryType FactoryType
Definition: alugrid/2d/entity.hh:83
~ALU2dGridEntityPointer()
Destructor.
ALU2dGridLeafIntersectionIteratorType ileafend() const
Definition: alugrid/2d/entity.hh:334
Definition: alugrid/2d/entity.hh:24
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:297
LeafIntersectionIteratorWrapper< GridImp > ALU2dGridLeafIntersectionIteratorType
tpye of intersection iterator
Definition: alugrid/2d/entity.hh:252
Store a reference to an entity with a minimal memory footprint.
Definition: common/entityseed.hh:23
const FactoryType & factory() const
return reference to factory
Definition: alugrid/2d/entity.hh:495
bool equals(const ALU2dGridEntity< cd, dim, GridImp > &org) const
compare 2 elements
GridImp::template Codim< codimension >::Entity Entity
type of stored entity (interface)
Definition: alugrid/2d/entity.hh:556
int getIndex() const
index is unique within the grid hierachie and per codim
PartitionType partitionType() const
return partition type of this entity ( see grid.hh )
Definition: alugrid/2d/entity.hh:404
Hierarchic Iterator of ALU2dGrid.
Definition: alugrid/2d/entity.hh:28
GridImp::template Codim< cd >::Geometry Geometry
type of corresponding interface geometry
Definition: alugrid/2d/entity.hh:91
Definition: alu2dinclude.hh:97
void setElement(const ALU2dGridEntity &org) const
Definition: alugrid/2d/entity.hh:465
Geometry geometry() const
geometry of this entity
InterfaceType
Parameter to be used for the communication functions.
Definition: gridenums.hh:80
const GridImp & grid() const
return reference top grid
Definition: alugrid/2d/entity.hh:602
GridImp::template Codim< cd >::EntityPointer EntityPointer
Definition: alugrid/2d/entity.hh:265
FieldVector< alu2d_ctype, dim > & positionInOwnersFather() const
my position in local coordinates of the owners father
int count() const
Definition: alugrid/2d/entity.hh:287
void setElement(const ElementType &element, int face=-1, int level=-1) const
set element as normal entity
EntityPointer ownersFather() const
MakeableInterfaceObject< Entity > EntityObj
Definition: alugrid/2d/entity.hh:562
const FactoryType & factory_
reference to entity factory
Definition: alugrid/2d/entity.hh:615
Definition: alugrid/2d/entity.hh:553
Definition: alugrid/2d/entity.hh:210
ALU2dGridHierarchicIterator< GridImp > hend(int maxLevel) const
Returns iterator to one past the last son.
Definition: alugrid/2d/entity.hh:362
ALU2dGridLeafIntersectionIteratorType ileafbegin() const
Definition: alugrid/2d/entity.hh:330
ALU2dGridLeafIntersectionIteratorType ALU2dGridIntersectionIteratorType
Definition: alugrid/2d/entity.hh:254
Dune::ALU2dImplTraits< dimworld, eltype >::template Codim< cd >::InterfaceType ElementType
Definition: alugrid/2d/entity.hh:85
all interior entities
Definition: gridenums.hh:25
Definition: alugrid/2d/grid.hh:61
[ provides Dune::Grid ]
Definition: alugrid/2d/entity.hh:38
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
bool equals(const ThisType &i) const
equality
GridImp::template Codim< cd >::Entity Entity
type of our interface entity
Definition: alugrid/2d/entity.hh:89
int level() const
ask for level of entities
ALU2dGridIntersectionIteratorType ibegin() const
Definition: alugrid/2d/entity.hh:309