dune-grid  2.3.1
entity_inline.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 #include <dune/common/exceptions.hh>
4 
5 #include "geometry.hh"
6 #include "grid.hh"
7 
8 namespace Dune {
9 
10  template<int cd, int dim, class GridImp>
12  reset( int l )
13  {
14  item_ = 0;
15  level_ = l;
16  twist_ = 0;
17  face_ = -1;
18  }
19 
20  template<int cd, int dim, class GridImp>
23  {
24  item_ = 0;
25  geo_.invalidate();
26  }
27 
28  template<int cd, int dim, class GridImp>
31  {
32  return (item_ == org.item_);
33  }
34 
35  template<int cd, int dim, class GridImp>
37  {
38  return gIndex_;
39  }
40 
41  template<int cd, int dim, class GridImp>
43  {
44  return level_;
45  }
46 
47  template<int cd, int dim, class GridImp>
50  {
51  return partitionType_;
52  }
53 
54  template<int cd, int dim, class GridImp>
55  inline GeometryType
57  {
58  return geo_.type();
59  }
60 
62  //
63  // --Entity0
64  // --Codim0Entity
65  //
67  template<int dim, class GridImp>
70  {
71  item_ = 0;
72  ghost_ = 0;
73  geo_.invalidate();
74  }
75 
76  template<int dim, class GridImp>
78  reset (int walkLevel )
79  {
80  item_ = 0;
81  ghost_ = 0;
82  level_ = -1;
83  isLeaf_ = false;
84 
85  // reset geometry information
86  geo_.invalidate();
87  }
88 
89  // works like assignment
90  template<int dim, class GridImp>
91  inline void
93  {
94  item_ = org.item_;
95  ghost_ = org.ghost_;
96  level_ = org.level_;
97  isLeaf_ = org.isLeaf_;
98 
99  // reset geometry information
100  geo_.invalidate();
101  }
102 
103  template<int dim, class GridImp>
104  inline void
107  {
108  if( ! key.isGhost() )
109  setElement( *key.interior() );
110  else
111  setGhost( *key.ghost() );
112  }
113 
114  template<int dim, class GridImp>
115  inline void
117  setElement(HElementType & element)
118  {
119  item_ = static_cast<IMPLElementType *> (&element);
120  assert( item_ );
121  // make sure this method is not called for ghosts
122  assert( ! item_->isGhost() );
123  ghost_ = 0;
124  level_ = (*item_).level();
125  isLeaf_ = ((*item_).down() == 0);
126 
127  // reset geometry information
128  geo_.invalidate();
129  }
130 
131  template<int dim, class GridImp>
132  inline void
134  {
135  // use element as ghost
136  item_ = static_cast<IMPLElementType *> ( ghost.getGhost().first );
137 
138  // method getGhost can return 0, but then is something wrong
139  assert(item_);
140  assert(item_->isGhost());
141 
142  level_ = item_->level();
143  // remember pointer to ghost face
144  ghost_ = static_cast<BNDFaceType *> (&ghost);
145  assert( ghost_ );
146 
147  BNDFaceType * dwn = static_cast<BNDFaceType *> (ghost.down());
148  if ( ! dwn ) isLeaf_ = true;
149  else
150  {
151  assert( ghost.level() == level_ );
152  if(dwn->ghostLevel() == level_)
153  isLeaf_ = true;
154  else
155  isLeaf_ = false;
156  }
157  // check wether ghost is leaf or not, ghost leaf means
158  // that this is the ghost that we want in the leaf iterator
159  // not necessarily is real leaf element
160  // see Intersection Iterator, same story
161 
162  // reset geometry information
163  geo_.invalidate();
164  }
165 
166  template<int dim, class GridImp>
167  inline int
169  {
170  return level_;
171  }
172 
173  template<int dim, class GridImp>
176  {
177  return (item_ == org.item_);
178  }
179 
180  template<int dim, class GridImp>
181  inline GeometryType
183  {
184  return geo_.type();
185  }
186 
187  template<int dim, class GridImp>
189  {
190  assert( item_ );
191  return (*item_).getIndex();
192  }
193 
194  template<int dim, class GridImp>
195  template<int cc>
197  {
198  return grid().referenceElement().size(cc);
199  }
200 
201  template<int dim, class GridImp>
204  {
205  assert( item_ );
206  // make sure we really got a ghost
207  assert( (isGhost()) ? item_->isGhost() : true );
208  return (isGhost() ? GhostEntity : InteriorEntity);
209  }
210 
211  template<int dim, class GridImp>
213  {
214  return isLeaf_;
215  }
216 
217  template<int dim, class GridImp>
220  {
221  assert(item_ != 0);
222  // if isGhost is true the end iterator will be returned
223  if( isGhost() )
224  {
225  return ALU3dGridHierarchicIterator<GridImp>(factory_,*ghost_,maxlevel, isLeaf() );
226  }
227  return ALU3dGridHierarchicIterator<GridImp>(factory_,*item_,maxlevel, isLeaf() );
228  }
229 
230  template<int dim, class GridImp>
232  {
233  assert(item_ != 0);
234  return ALU3dGridHierarchicIterator<GridImp> (factory_, *item_, maxlevel, true);
235  }
236 
237  template<int dim, class GridImp>
238  inline typename ALU3dGridEntity<0,dim,GridImp> :: ALU3dGridLeafIntersectionIteratorType
240  {
241  assert(item_ != 0);
242  return ALU3dGridIntersectionIteratorType (*this, this->level(), false);
243  }
244 
245  template<int dim, class GridImp>
246  inline typename ALU3dGridEntity<0,dim,GridImp> :: ALU3dGridLeafIntersectionIteratorType
248  {
249  assert(item_ != 0);
250  return ALU3dGridLeafIntersectionIteratorType (*this, this->level(), true);
251  }
252 
253  template<int dim, class GridImp>
254  inline typename ALU3dGridEntity<0,dim,GridImp> :: ALU3dGridLevelIntersectionIteratorType
256  {
257  assert(item_ != 0);
258  // disable level intersection iterator for conforming refinement
259  return ALU3dGridLevelIntersectionIteratorType (*this, this->level(), grid().conformingRefinement() );
260  }
261 
262  template<int dim, class GridImp>
263  inline typename ALU3dGridEntity<0,dim,GridImp> :: ALU3dGridLevelIntersectionIteratorType
265  {
266  assert(item_ != 0);
267  return ALU3dGridLevelIntersectionIteratorType (*this, this->level(), true);
268  }
269 
270  // Adaptation methods
271  template<int dim, class GridImp>
273  {
274  assert( item_ );
275  return item_->hasBeenRefined();
276  }
277 
278  template<int dim, class GridImp>
280  {
281  assert( item_ );
282  return ((*item_).requestrule() == coarse_element_t);
283  }
284 
285  //*******************************************************************
286  //
287  // --EntityPointer
288  // --EnPointer
289  //
290  //*******************************************************************
291  template<int codim, class GridImp >
294  const HElementType &item)
295  : factory_(factory)
296  , seed_( item )
297  , entity_( 0 )
298  {}
299 
300  template<int codim, class GridImp >
303  const HBndSegType & ghostFace )
304  : factory_(factory)
305  , seed_( ghostFace )
306  , entity_ ( factory_.template getNewEntity<codim> ( ghostFace.level() ))
307  {
308  // sets entity and item pointer
309  updateGhostPointer( const_cast<HBndSegType &> (ghostFace) );
310  }
311 
312  template<int codim, class GridImp >
315  const ALU3dGridEntitySeedType& key )
316  : factory_(factory)
317  , seed_( key )
318  , entity_ ( 0 )
319  {}
320 
321  // constructor Level,Leaf and HierarchicIterator
322  template<int codim, class GridImp >
324  ALU3dGridEntityPointerBase(const FactoryType& factory, int level )
325  : factory_(factory)
326  , seed_()
327  , entity_ ( factory_.template getNewEntity<codim> ( level ) )
328  {
329  // this needs to be called
330  // have to investigate why
331  entityImp().reset(level);
332  }
333 
334 
335  template<int codim, class GridImp >
338  const HElementType &item,
339  const int level,
340  const int twist,
341  const int duneFace )
342  : factory_(factory)
343  , seed_( item, level, twist, duneFace )
344  , entity_( 0 )
345  {}
346 
347  template<int codim, class GridImp >
350  : factory_(org.factory_)
351  , seed_( org.seed_ )
352  , entity_( 0 )
353  {
354  // if entity exists then copy entity
355  getEntity( org );
356  }
357 
358  template<int codim, class GridImp >
361  {
362  // if entity existed for original pointer then copy
363  if( org.entity_ )
364  {
365  assert( entity_ == 0 );
366  entity_ = factory_.template getNewEntity<codim> ();
367  // set entity right away
368  entityImp().setEntity( org.entityImp() );
369  }
370  }
371 
372  template<int codim, class GridImp >
376  {
377  clone( org );
378  return *this;
379  }
380 
381  template<int codim, class GridImp >
382  inline void
385  {
386  assert( &factory_ == &org.factory_ );
387 
388  // set item
389  seed_ = org.seed_;
390 
391  HElementType* item = seed_.item();
392 
393  if( item )
394  {
395  // if no entity check org entity
396  // if no org entity then nothing is done
397  if( !entity_ )
398  {
399  getEntity(org);
400  }
401  else
402  {
403  // in case of ghost element use different set method
404  if( item->isGhost() )
405  {
406  // on ghosts entity pointers entity always exists
407  assert( org.entity_ );
408  entityImp().setEntity( org.entityImp() );
409  }
410  else
411  {
412  // otherwise item is set
413  entityImp().setElement( seed_ );
414  }
415  }
416  }
417  else
418  {
419  this->done();
420  }
421  return ;
422  }
423 
424  template<int codim, class GridImp >
427  {
428  this->done();
429  }
430 
431  template<int codim, class GridImp >
433  {
434  seed_.clear();
435  // free entity
436  freeEntity();
437  }
438 
439  template<int codim, class GridImp >
441  {
442  // sets entity pointer in the status of an empty entity
443  if( entity_ )
444  {
445  entityImp().removeElement();
446  factory_.template freeEntity<codim> ( (EntityObject *) entity_ );
447  entity_ = 0;
448  }
449  }
450 
451  template<int codim, class GridImp >
454  {
455  // check equality of underlying items
456  return (seed_.equals( i.seed_ ));
457  }
458 
459  template<int codim, class GridImp >
462  {
463  // don't dereference empty entity pointer
464  assert( seed_.item() );
465  if( ! entity_ )
466  {
467  entity_ = factory_.template getNewEntity<codim> ();
468  entityImp().setElement( seed_ );
469  }
470  assert( seed_.item() == & entityImp().getItem() );
471  return (*entity_);
472  }
473 
474  template<int codim, class GridImp >
476  {
477  assert( seed_.item() );
478  return seed_.item()->level();
479  }
480 
481  template<int codim, class GridImp >
483  updateGhostPointer( HBndSegType & ghostFace )
484  {
485  assert( entity_ );
486  entityImp().setGhost( ghostFace );
487  // inside the method setGhost the method getGhost of the ghostFace is
488  // called and set as item
489  seed_.set( ghostFace );
490  }
491 
492  template<int codim, class GridImp >
494  updateEntityPointer( HElementType * item , int )
495  {
496  seed_.set( *item );
497  if( item && entity_ )
498  {
499  entityImp().setElement( seed_ );
500  }
501  }
502 
504  //
505  // specialisation for higher codims
506  //
508 
509  template<int codim, class GridImp >
512  const int level,
513  const HElementType &item,
514  const int twist,
515  const int duneFace )
516  : ALU3dGridEntityPointerBase<codim,GridImp> (factory,item,level,twist,duneFace)
517  {}
518 
519  template<int codim, class GridImp >
522  : ALU3dGridEntityPointerBase<codim,GridImp>(org)
523  {}
524 
525  template<int codim, class GridImp >
529  {
530  // clone pointer
531  clone(org);
532  return *this;
533  }
534 
535  template<int codim, class GridImp >
536  inline void
539  {
540  // copy key
541  seed_ = org.seed_;
542 
543  assert( &factory_ == &org.factory_ );
544 
545  // if entity exists, just remove item pointer
546  if( seed_.item() )
547  {
548  if( ! entity_ )
549  getEntity(org);
550  else
551  entityImp().setElement( seed_ );
552  }
553  else
554  this->done();
555  return ;
556  }
557 
558  template<int codim, class GridImp >
561  {
562  // don't dereference empty entity pointer
563  assert( seed_.item() );
564  if( ! entity_ )
565  {
566  entity_ = factory_.template getNewEntity<codim> ();
567  entityImp().setElement( seed_ );
568  }
569  assert( seed_.item() == & entityImp().getItem() );
570  return (*entity_);
571  }
572 
573  template<int codim, class GridImp >
575  {
576  return seed_.level();
577  }
578 
579  template<int codim, class GridImp >
582  {
583  seed_.set( *item, level );
584  if( item && entity_ )
585  {
586  entityImp().setElement( seed_ );
587  }
588  }
589 
590 
591 } // end namespace Dune