dune-alugrid  3.0.0
entity_inline.hh
Go to the documentation of this file.
1 #ifndef ALUGRID_ENTITY_INLINE_HH
2 #define ALUGRID_ENTITY_INLINE_HH
3 #include <dune/common/exceptions.hh>
4 
5 #include "geometry.hh"
6 #include "grid.hh"
7 
8 namespace Dune {
9 
11  //
12  // --Entity0
13  // --Codim0Entity
14  //
16  template<int dim, class GridImp>
19  {
20  item_ = 0;
21  ghost_ = 0;
22  geo_.invalidate();
23  }
24 
25  template<int dim, class GridImp>
27  reset (int walkLevel )
28  {
29  item_ = 0;
30  ghost_ = 0;
31 
32  // reset geometry information
33  geo_.invalidate();
34  }
35 
36  // works like assignment
37  template<int dim, class GridImp>
38  inline void
40  {
41  item_ = org.item_;
42  ghost_ = org.ghost_;
43 
44  // reset geometry information
45  geo_.invalidate();
46  }
47 
48  template<int dim, class GridImp>
49  inline void
51  setElement(const EntitySeed& key )
52  {
53  if( ! key.isGhost() )
54  setElement( *key.interior() );
55  else
56  setGhost( *key.ghost() );
57  }
58 
59  template<int dim, class GridImp>
60  inline void
62  setElement(HElementType & element)
63  {
64  item_ = static_cast<IMPLElementType *> (&element);
65  alugrid_assert ( item_ );
66  // make sure this method is not called for ghosts
67  alugrid_assert ( ! item_->isGhost() );
68  ghost_ = 0;
69 
70  // reset geometry information
71  geo_.invalidate();
72  }
73 
74  template<int dim, class GridImp>
75  inline void
77  {
78  // use element as ghost
79  item_ = static_cast<IMPLElementType *> ( ghost.getGhost().first );
80 
81  // method getGhost can return 0, but then is something wrong
82  alugrid_assert (item_);
83  alugrid_assert (item_->isGhost());
84 
85  // remember pointer to ghost face
86  ghost_ = static_cast<BNDFaceType *> (&ghost);
87  alugrid_assert ( ghost_ );
88 
89  // check wether ghost is leaf or not, ghost leaf means
90  // that this is the ghost that we want in the leaf iterator
91  // not necessarily is real leaf element
92  // see Intersection Iterator, same story
93 
94  // reset geometry information
95  geo_.invalidate();
96  }
97 
98  template<int dim, class GridImp>
99  inline int
101  {
102  alugrid_assert( item_ );
103  return item_->level();
104  }
105 
106  template<int dim, class GridImp>
109  {
110  return (item_ == org.item_);
111  }
112 
113  template<int dim, class GridImp>
114  inline GeometryType
116  {
117  return geo_.type();
118  }
119 
120  template<int dim, class GridImp>
122  {
123  alugrid_assert ( item_ );
124  return (*item_).getIndex();
125  }
126 
127  template<int dim, class GridImp>
128  template<int cc>
130  {
131  return subEntities( cc );
132  }
133 
134  template<int dim, class GridImp>
135  inline unsigned int ALU3dGridEntity<0,dim,GridImp> :: subEntities (unsigned int codim) const
136  {
137  return GridImp::referenceElement().size( codim );
138  }
139 
140  template<int dim, class GridImp>
141  inline PartitionType ALU3dGridEntity<0,dim,GridImp> ::
143  {
144  alugrid_assert ( item_ );
145  // make sure we really got a ghost
146  alugrid_assert ( (isGhost()) ? item_->isGhost() : true );
147  return (isGhost() ? GhostEntity : InteriorEntity);
148  }
149 
150  template<int dim, class GridImp>
152  {
153  alugrid_assert( item_ );
154  if( isGhost() )
155  {
156  alugrid_assert( ghost_ );
157  // for ghost elements the situation is more complicated
158  // we have to compare the ghost level with our current level
159  BNDFaceType * dwn = static_cast<BNDFaceType *> (ghost_->down());
160  return ( dwn ) ? (dwn->ghostLevel() == level()) : true;
161  }
162  else
163  {
164  // no children means leaf entity
165  return ! item_->down();
166  }
167  }
168 
169  template<int dim, class GridImp>
172  {
173  alugrid_assert (item_ != 0);
174  // if isGhost is true the end iterator will be returned
175  if( isGhost() )
176  {
177  return ALU3dGridHierarchicIterator<GridImp>( *ghost_, maxlevel, isLeaf() );
178  }
179  else
180  return ALU3dGridHierarchicIterator<GridImp>( *item_, maxlevel, isLeaf() );
181  }
182 
183  template<int dim, class GridImp>
185  {
186  alugrid_assert (item_ != 0);
187  return ALU3dGridHierarchicIterator<GridImp> ( *item_, maxlevel, true);
188  }
189 
190  // Adaptation methods
191  template<int dim, class GridImp>
193  {
194  alugrid_assert ( item_ );
195  return item_->hasBeenRefined();
196  }
197 
198  template<int dim, class GridImp>
200  {
201  alugrid_assert ( item_ );
202  return ((*item_).requestrule() == coarse_element_t);
203  }
204 
205  //*******************************************************************
206  //
207  // --EntityPointer
208  // --EnPointer
209  //
210  //*******************************************************************
211  template<int codim, class GridImp >
213  ALU3dGridEntityPointerBase( const HElementType &item )
214  : seed_( item )
215  , entity_( EntityImp( item ) )
216  {
217  }
218 
219  template<int codim, class GridImp >
221  ALU3dGridEntityPointerBase( const HBndSegType & ghostFace )
222  : seed_( ghostFace )
223  , entity_ ( EntityImp( ghostFace ) )
224  {
225  }
226 
227  template<int codim, class GridImp >
230  : seed_( key )
231  , entity_( EntityImp( seed_ ) )
232  {
233  }
234 
235  // constructor Level,Leaf and HierarchicIterator
236  template<int codim, class GridImp >
239  : seed_()
240  , entity_ ( EntityImp() )
241  {
242  }
243 
244  template<int codim, class GridImp >
247  : seed_( org.seed_ )
248  , entity_( GridImp::getRealImplementation(org.entity_) )
249  {
250  alugrid_assert( seed_ == org.seed_ );
251  alugrid_assert( entity_ == org.entity_ );
252  }
253 
254  template<int codim, class GridImp >
258  {
259  clone( org );
260  return *this;
261  }
262 
263  template<int codim, class GridImp >
264  inline void
267  {
268  // copy seed
269  seed_ = org.seed_;
270 
271  if( seed_.isValid() )
272  {
273  // update entity if seed is valid
274  entityImp().setEntity( org.entityImp() );
275  }
276  else // otherwise mark as finished (iterators)
277  {
278  this->done();
279  }
280  }
281 
282  template<int codim, class GridImp >
284  {
285  seed_.clear();
286  }
287 
288  template<int codim, class GridImp >
291  {
292  // check equality of underlying items
293  return (seed_.equals( i.seed_ ));
294  }
295 
296  template<int codim, class GridImp >
298  updateGhostPointer( HBndSegType & ghostFace )
299  {
300  seed_.set( ghostFace );
301  if( seed_.isValid() )
302  {
303  entityImp().setGhost( ghostFace );
304  }
305  }
306 
307  template<int codim, class GridImp >
309  updateEntityPointer( HElementType * item , int )
310  {
311  seed_.set( *item );
312  if( seed_.isValid() )
313  {
314  entityImp().setElement( *item );
315  }
316  }
317 
319  //
320  // specialisation for higher codims
321  //
323 
324  template<int codim, class GridImp >
327  {
328  seed_.set( *item, level );
329  if( seed_.isValid() )
330  {
331  entityImp().setElement( seed_ );
332  }
333  }
334 
335 } // end namespace Dune
336 #endif
geometry.hh
Dune::ALU3dGridEntity< 0, dim, GridImp >::ghost_
BNDFaceType * ghost_
not zero if entity is ghost entity
Definition: entity.hh:442
Dune::ALU3dGridEntity::setGhost
void setGhost(const HBndSegType &ghost)
setGhost is not valid for this codim
Definition: entity_imp.cc:80
Dune::ALU3dGridEntity::partitionType
PartitionType partitionType() const
return partition type of this entity ( see grid.hh )
Definition: entity.hh:152
Dune::ALU3dGridEntity< 0, dim, GridImp >
Definition: entity.hh:188
Dune::ALU3dGridEntityPointerBase::seed_
ALU3dGridEntitySeedType seed_
Definition: entity.hh:543
Dune::ALU3dGridHierarchicIterator
Definition: entity.hh:30
Dune::ALU3dGridEntity::type
GeometryType type() const
type of geometry of this entity
Definition: entity.hh:113
Dune::ALU3dGridEntityPointerBase::entity_
EntityObject entity_
Definition: entity.hh:546
Dune::ALU3dGridEntitySeed< codimension, GridImp >
Dune::ALU3dGridEntity::level
int level() const
level of this element
Definition: entity.hh:149
Dune::ALU3dGridEntity::setElement
void setElement(const HItemType &item)
Definition: entity_imp.cc:48
alugrid_assert
#define alugrid_assert(EX)
Definition: alugrid_assert.hh:20
Dune::ALU3dGridEntity::equals
bool equals(const ALU3dGridEntity< cd, dim, GridImp > &org) const
compare 2 elements by comparing the item pointers
Definition: entity.hh:134
Dune::ALU3dGridEntity< 0, dim, GridImp >::EntitySeed
GridImp::template Codim< 0 >::EntitySeed EntitySeed
typedef of my type
Definition: entity.hh:260
Dune::ALU3dGridEntity::getIndex
int getIndex() const
index is unique within the grid hierarchy and per codim
Definition: entity.hh:156
Dune::ALU3dGridEntityPointer< cdim, GridImp >::HElementType
ImplTraits::template Codim< dim, cd >::InterfaceType HElementType
Definition: entity.hh:643
Dune::ALU3dGridEntityPointerBase::ALU3dGridEntityPointerBase
ALU3dGridEntityPointerBase()
default empty constructor
Definition: entity_inline.hh:238
Dune::ALU3dGridEntity
Definition: entity.hh:22
grid.hh
Dune::ALU3dGridEntity::geo_
GeometryImpl geo_
the current geometry
Definition: entity.hh:162
Dune::ALU3dGridEntity::removeElement
void removeElement()
reset item pointer to NULL
Definition: entity.hh:127
Dune::ALU3dGridEntityPointer
Definition: entity.hh:26
Dune::ALU3dGridEntityPointerBase::entityImp
EntityImp & entityImp() const
Definition: entity.hh:549
Dune::ALU3dGridEntity< 0, dim, GridImp >::item_
IMPLElementType * item_
Definition: entity.hh:439
Dune
Definition: alu3dinclude.hh:79
Dune::ALU3dGridEntityPointerBase
Definition: entity.hh:457
Dune::ALU3dGridEntity::setEntity
void setEntity(const ALU3dGridEntity< cd, dim, GridImp > &org)
set item from other entity, mainly for copy constructor of entity pointer
Definition: entity_imp.cc:41