Dune Core Modules (2.4.2)

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>
202 inline unsigned int ALU3dGridEntity<0,dim,GridImp> :: subEntities (unsigned int codim) const
203 {
204 return grid().referenceElement().size(codim);
205 }
206
207 template<int dim, class GridImp>
209 partitionType () const
210 {
211 assert( item_ );
212 // make sure we really got a ghost
213 assert( (isGhost()) ? item_->isGhost() : true );
214 return (isGhost() ? GhostEntity : InteriorEntity);
215 }
216
217 template<int dim, class GridImp>
219 {
220 return isLeaf_;
221 }
222
223 template<int dim, class GridImp>
224 inline ALU3dGridHierarchicIterator<GridImp>
226 {
227 assert(item_ != 0);
228 // if isGhost is true the end iterator will be returned
229 if( isGhost() )
230 {
231 return ALU3dGridHierarchicIterator<GridImp>(factory_,*ghost_,maxlevel, isLeaf() );
232 }
233 return ALU3dGridHierarchicIterator<GridImp>(factory_,*item_,maxlevel, isLeaf() );
234 }
235
236 template<int dim, class GridImp>
237 inline ALU3dGridHierarchicIterator<GridImp> ALU3dGridEntity<0,dim,GridImp> :: hend (int maxlevel) const
238 {
239 assert(item_ != 0);
240 return ALU3dGridHierarchicIterator<GridImp> (factory_, *item_, maxlevel, true);
241 }
242
243 template<int dim, class GridImp>
244 inline typename ALU3dGridEntity<0,dim,GridImp> :: ALU3dGridLeafIntersectionIteratorType
246 {
247 assert(item_ != 0);
248 return ALU3dGridIntersectionIteratorType (*this, this->level(), false);
249 }
250
251 template<int dim, class GridImp>
252 inline typename ALU3dGridEntity<0,dim,GridImp> :: ALU3dGridLeafIntersectionIteratorType
254 {
255 assert(item_ != 0);
256 return ALU3dGridLeafIntersectionIteratorType (*this, this->level(), true);
257 }
258
259 template<int dim, class GridImp>
260 inline typename ALU3dGridEntity<0,dim,GridImp> :: ALU3dGridLevelIntersectionIteratorType
262 {
263 assert(item_ != 0);
264 // disable level intersection iterator for conforming refinement
265 return ALU3dGridLevelIntersectionIteratorType (*this, this->level(), grid().conformingRefinement() );
266 }
267
268 template<int dim, class GridImp>
269 inline typename ALU3dGridEntity<0,dim,GridImp> :: ALU3dGridLevelIntersectionIteratorType
271 {
272 assert(item_ != 0);
273 return ALU3dGridLevelIntersectionIteratorType (*this, this->level(), true);
274 }
275
276 // Adaptation methods
277 template<int dim, class GridImp>
279 {
280 assert( item_ );
281 return item_->hasBeenRefined();
282 }
283
284 template<int dim, class GridImp>
286 {
287 assert( item_ );
288 return ((*item_).requestrule() == coarse_element_t);
289 }
290
291 //*******************************************************************
292 //
293 // --EntityPointer
294 // --EnPointer
295 //
296 //*******************************************************************
297 template<int codim, class GridImp >
299 ALU3dGridEntityPointerBase(const FactoryType& factory,
300 const HElementType &item)
301 : factory_(factory)
302 , seed_( item )
303 , entity_( 0 )
304 {}
305
306 template<int codim, class GridImp >
308 ALU3dGridEntityPointerBase(const FactoryType& factory,
309 const HBndSegType & ghostFace )
310 : factory_(factory)
311 , seed_( ghostFace )
312 , entity_ ( factory_.template getNewEntity<codim> ( ghostFace.level() ))
313 {
314 // sets entity and item pointer
315 updateGhostPointer( const_cast<HBndSegType &> (ghostFace) );
316 }
317
318 template<int codim, class GridImp >
320 ALU3dGridEntityPointerBase(const FactoryType& factory,
321 const ALU3dGridEntitySeedType& key )
322 : factory_(factory)
323 , seed_( key )
324 , entity_ ( 0 )
325 {}
326
327 // constructor Level,Leaf and HierarchicIterator
328 template<int codim, class GridImp >
330 ALU3dGridEntityPointerBase(const FactoryType& factory, int level )
331 : factory_(factory)
332 , seed_()
333 , entity_ ( factory_.template getNewEntity<codim> ( level ) )
334 {
335 // this needs to be called
336 // have to investigate why
337 entityImp().reset(level);
338 }
339
340
341 template<int codim, class GridImp >
343 ALU3dGridEntityPointerBase(const FactoryType& factory,
344 const HElementType &item,
345 const int level,
346 const int twist,
347 const int duneFace )
348 : factory_(factory)
349 , seed_( item, level, twist, duneFace )
350 , entity_( 0 )
351 {}
352
353 template<int codim, class GridImp >
356 : factory_(org.factory_)
357 , seed_( org.seed_ )
358 , entity_( 0 )
359 {
360 // if entity exists then copy entity
361 getEntity( org );
362 }
363
364 template<int codim, class GridImp >
366 getEntity(const ALU3dGridEntityPointerType & org)
367 {
368 // if entity existed for original pointer then copy
369 if( org.entity_ )
370 {
371 assert( entity_ == 0 );
372 entity_ = factory_.template getNewEntity<codim> ();
373 // set entity right away
374 entityImp().setEntity( org.entityImp() );
375 }
376 }
377
378 template<int codim, class GridImp >
379 inline ALU3dGridEntityPointerBase<codim,GridImp> &
382 {
383 clone( org );
384 return *this;
385 }
386
387 template<int codim, class GridImp >
388 inline void
390 clone (const ALU3dGridEntityPointerType & org)
391 {
392 assert( &factory_ == &org.factory_ );
393
394 // set item
395 seed_ = org.seed_;
396
397 HElementType* item = seed_.item();
398
399 if( item )
400 {
401 // if no entity check org entity
402 // if no org entity then nothing is done
403 if( !entity_ )
404 {
405 getEntity(org);
406 }
407 else
408 {
409 // in case of ghost element use different set method
410 if( item->isGhost() )
411 {
412 // on ghosts entity pointers entity always exists
413 assert( org.entity_ );
414 entityImp().setEntity( org.entityImp() );
415 }
416 else
417 {
418 // otherwise item is set
419 entityImp().setElement( seed_ );
420 }
421 }
422 }
423 else
424 {
425 this->done();
426 }
427 return ;
428 }
429
430 template<int codim, class GridImp >
433 {
434 this->done();
435 }
436
437 template<int codim, class GridImp >
439 {
440 seed_.clear();
441 // free entity
442 freeEntity();
443 }
444
445 template<int codim, class GridImp >
447 {
448 // sets entity pointer in the status of an empty entity
449 if( entity_ )
450 {
451 entityImp().removeElement();
452 factory_.template freeEntity<codim> ( (EntityObject *) entity_ );
453 entity_ = 0;
454 }
455 }
456
457 template<int codim, class GridImp >
460 {
461 // check equality of underlying items
462 return (seed_.equals( i.seed_ ));
463 }
464
465 template<int codim, class GridImp >
468 {
469 // don't dereference empty entity pointer
470 assert( seed_.item() );
471 if( ! entity_ )
472 {
473 entity_ = factory_.template getNewEntity<codim> ();
474 entityImp().setElement( seed_ );
475 }
476 assert( seed_.item() == & entityImp().getItem() );
477 return (*entity_);
478 }
479
480 template<int codim, class GridImp >
482 {
483 assert( seed_.item() );
484 return seed_.item()->level();
485 }
486
487 template<int codim, class GridImp >
489 updateGhostPointer( HBndSegType & ghostFace )
490 {
491 assert( entity_ );
492 entityImp().setGhost( ghostFace );
493 // inside the method setGhost the method getGhost of the ghostFace is
494 // called and set as item
495 seed_.set( ghostFace );
496 }
497
498 template<int codim, class GridImp >
499 inline void ALU3dGridEntityPointerBase<codim,GridImp>::
500 updateEntityPointer( HElementType * item , int )
501 {
502 seed_.set( *item );
503 if( item && entity_ )
504 {
505 entityImp().setElement( seed_ );
507 }
508
510 //
511 // specialisation for higher codims
512 //
514
515 template<int codim, class GridImp >
516 inline ALU3dGridEntityPointer<codim,GridImp> ::
517 ALU3dGridEntityPointer(const FactoryType& factory,
518 const int level,
519 const HElementType &item,
520 const int twist,
521 const int duneFace )
522 : ALU3dGridEntityPointerBase<codim,GridImp> (factory,item,level,twist,duneFace)
523 {}
524
525 template<int codim, class GridImp >
526 inline ALU3dGridEntityPointer<codim,GridImp> ::
527 ALU3dGridEntityPointer(const ALU3dGridEntityPointerType & org)
528 : ALU3dGridEntityPointerBase<codim,GridImp>(org)
529 {}
530
531 template<int codim, class GridImp >
532 inline ALU3dGridEntityPointer<codim,GridImp> &
533 ALU3dGridEntityPointer<codim,GridImp>::
534 operator = (const ALU3dGridEntityPointerType & org)
536 // clone pointer
537 clone(org);
538 return *this;
539 }
540
541 template<int codim, class GridImp >
542 inline void
543 ALU3dGridEntityPointer<codim,GridImp> ::
544 clone (const ALU3dGridEntityPointerType & org)
545 {
546 // copy key
547 seed_ = org.seed_;
548
549 assert( &factory_ == &org.factory_ );
550
551 // if entity exists, just remove item pointer
552 if( seed_.item() )
553 {
554 if( ! entity_ )
555 getEntity(org);
556 else
557 entityImp().setElement( seed_ );
558 }
559 else
560 this->done();
561 return ;
562 }
563
564 template<int codim, class GridImp >
565 inline typename ALU3dGridEntityPointer<codim,GridImp>::Entity &
566 ALU3dGridEntityPointer<codim,GridImp>::dereference () const
567 {
568 // don't dereference empty entity pointer
569 assert( seed_.item() );
570 if( ! entity_ )
571 {
572 entity_ = factory_.template getNewEntity<codim> ();
573 entityImp().setElement( seed_ );
574 }
575 assert( seed_.item() == & entityImp().getItem() );
576 return (*entity_);
577 }
578
579 template<int codim, class GridImp >
580 inline int ALU3dGridEntityPointer<codim,GridImp>::level () const
581 {
582 return seed_.level();
583 }
584
585 template<int codim, class GridImp >
586 inline void ALU3dGridEntityPointer<codim,GridImp>::
587 updateEntityPointer( HElementType * item, int level)
588 {
589 seed_.set( *item, level );
590 if( item && entity_ )
591 {
592 entityImp().setElement( seed_ );
593 }
594 }
595
596
597} // end namespace Dune
Definition: entity.hh:469
GridImp::template Codim< codimension >::Entity Entity
type of Entity
Definition: entity.hh:491
void freeEntity()
put entity to entity stack
Definition: entity_inline.hh:446
~ALU3dGridEntityPointerBase()
Destructor.
Definition: entity_inline.hh:432
int level() const
ask for level of entities
Definition: entity_inline.hh:481
ALU3dGridEntityPointerBase(const FactoryType &factory, const HElementType &item)
Constructor for EntityPointer that points to an element.
Definition: entity_inline.hh:299
bool equals(const ALU3dGridEntityPointerType &i) const
equality
Definition: entity_inline.hh:459
ALU3dGridEntitySeed< codimension, GridImp > ALU3dGridEntitySeedType
type of entity seed
Definition: entity.hh:503
Entity & dereference() const
dereferencing
Definition: entity_inline.hh:467
ThisType & operator=(const ThisType &org)
assignment operator
Definition: entity_inline.hh:381
void done()
has to be called when iterator is finished
Definition: entity_inline.hh:438
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:233
Class that wraps IntersectionIteratorImp of a grid and gets it's internal object from a object stack ...
Definition: intersectioniteratorwrapper.hh:328
A few common exception classes.
PartitionType
Attributes used in the generic overlap model.
Definition: gridenums.hh:28
@ InteriorEntity
all interior entities
Definition: gridenums.hh:29
@ GhostEntity
ghost entities
Definition: gridenums.hh:33
Dune namespace.
Definition: alignment.hh:10
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 21, 23:30, 2024)