Dune Core Modules (2.3.1)

entity_inline.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
4
5#include "geometry.hh"
6#include "grid.hh"
7
8namespace 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>
49 partitionType () const
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
105 ALU3dGridEntity<0,dim,GridImp>::
106 setElement(const EntitySeed& key )
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>
175 equals (const ALU3dGridEntity<0,dim,GridImp> &org ) const
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>
203 partitionType () const
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>
218 inline ALU3dGridHierarchicIterator<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>
231 inline ALU3dGridHierarchicIterator<GridImp> ALU3dGridEntity<0,dim,GridImp> :: hend (int maxlevel) const
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 >
293 ALU3dGridEntityPointerBase(const FactoryType& factory,
294 const HElementType &item)
295 : factory_(factory)
296 , seed_( item )
297 , entity_( 0 )
298 {}
299
300 template<int codim, class GridImp >
302 ALU3dGridEntityPointerBase(const FactoryType& factory,
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 >
314 ALU3dGridEntityPointerBase(const FactoryType& factory,
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 >
337 ALU3dGridEntityPointerBase(const FactoryType& factory,
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 >
360 getEntity(const ALU3dGridEntityPointerType & org)
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 >
373 inline ALU3dGridEntityPointerBase<codim,GridImp> &
376 {
377 clone( org );
378 return *this;
379 }
380
381 template<int codim, class GridImp >
382 inline void
384 clone (const ALU3dGridEntityPointerType & org)
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 >
493 inline void ALU3dGridEntityPointerBase<codim,GridImp>::
494 updateEntityPointer( HElementType * item , int )
495 {
496 seed_.set( *item );
497 if( item && entity_ )
498 {
499 entityImp().setElement( seed_ );
500 }
502
504 //
505 // specialisation for higher codims
506 //
508
509 template<int codim, class GridImp >
510 inline ALU3dGridEntityPointer<codim,GridImp> ::
511 ALU3dGridEntityPointer(const FactoryType& factory,
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 >
520 inline ALU3dGridEntityPointer<codim,GridImp> ::
521 ALU3dGridEntityPointer(const ALU3dGridEntityPointerType & org)
522 : ALU3dGridEntityPointerBase<codim,GridImp>(org)
523 {}
525 template<int codim, class GridImp >
526 inline ALU3dGridEntityPointer<codim,GridImp> &
527 ALU3dGridEntityPointer<codim,GridImp>::
528 operator = (const ALU3dGridEntityPointerType & org)
529 {
530 // clone pointer
531 clone(org);
532 return *this;
534
535 template<int codim, class GridImp >
536 inline void
537 ALU3dGridEntityPointer<codim,GridImp> ::
538 clone (const ALU3dGridEntityPointerType & org)
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 ;
557
558 template<int codim, class GridImp >
559 inline typename ALU3dGridEntityPointer<codim,GridImp>::Entity &
560 ALU3dGridEntityPointer<codim,GridImp>::dereference () const
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 >
574 inline int ALU3dGridEntityPointer<codim,GridImp>::level () const
575 {
576 return seed_.level();
577 }
578
579 template<int codim, class GridImp >
580 inline void ALU3dGridEntityPointer<codim,GridImp>::
581 updateEntityPointer( HElementType * item, int level)
582 {
583 seed_.set( *item, level );
584 if( item && entity_ )
585 {
586 entityImp().setElement( seed_ );
587 }
588 }
589
590
591} // end namespace Dune
Definition: entity.hh:464
GridImp::template Codim< codimension >::Entity Entity
type of Entity
Definition: entity.hh:486
void freeEntity()
put entity to entity stack
Definition: entity_inline.hh:440
~ALU3dGridEntityPointerBase()
Destructor.
Definition: entity_inline.hh:426
int level() const
ask for level of entities
Definition: entity_inline.hh:475
ALU3dGridEntityPointerBase(const FactoryType &factory, const HElementType &item)
Constructor for EntityPointer that points to an element.
Definition: entity_inline.hh:293
bool equals(const ALU3dGridEntityPointerType &i) const
equality
Definition: entity_inline.hh:453
ALU3dGridEntitySeed< codimension, GridImp > ALU3dGridEntitySeedType
type of entity seed
Definition: entity.hh:498
Entity & dereference() const
dereferencing
Definition: entity_inline.hh:461
ThisType & operator=(const ThisType &org)
assignment operator
Definition: entity_inline.hh:375
void done()
has to be called when iterator is finished
Definition: entity_inline.hh:432
Definition: entity.hh:47
GeometryType type() const
type of geometry of this entity
Definition: entity_inline.hh:56
void setEntity(const ALU3dGridEntity< cd, dim, GridImp > &org)
set item from other entity, mainly for copy constructor of entity pointer
void removeElement()
reset item pointer to NULL
Definition: entity_inline.hh:22
int level() const
level of this element
Definition: entity_inline.hh:42
PartitionType partitionType() const
return partition type of this entity ( see grid.hh )
Definition: entity_inline.hh:49
void setGhost(const HBndSegType &ghost)
setGhost is not valid for this codim
const GridImp & grid() const
return reference to grid
Definition: entity.hh:147
void reset(int l)
reset item pointer to NULL
Definition: entity_inline.hh:12
bool equals(const ALU3dGridEntity< cd, dim, GridImp > &org) const
compare 2 elements by comparing the item pointers
Definition: entity_inline.hh:30
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:25
Class that wraps IntersectionIteratorImp of a grid and gets it's internal object from a object stack ...
Definition: intersectioniteratorwrapper.hh:239
Class that wraps IntersectionIteratorImp of a grid and gets it's internal object from a object stack ...
Definition: intersectioniteratorwrapper.hh:334
A few common exception classes.
Dune namespace.
Definition: alignment.hh:14
PartitionType
Attributes used in the generic overlap model.
Definition: gridenums.hh:24
@ InteriorEntity
all interior entities
Definition: gridenums.hh:25
@ GhostEntity
ghost entities
Definition: gridenums.hh:29
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)