dune-grid
2.2.0
|
00001 #include <dune/common/exceptions.hh> 00002 00003 #include "geometry.hh" 00004 #include "grid.hh" 00005 00006 namespace Dune { 00007 00008 template<int cd, int dim, class GridImp> 00009 inline void ALU3dGridEntity<cd,dim,GridImp> :: 00010 reset( int l ) 00011 { 00012 item_ = 0; 00013 level_ = l; 00014 twist_ = 0; 00015 face_ = -1; 00016 } 00017 00018 template<int cd, int dim, class GridImp> 00019 inline void ALU3dGridEntity<cd,dim,GridImp> :: 00020 removeElement() 00021 { 00022 item_ = 0; 00023 geo_.invalidate(); 00024 } 00025 00026 template<int cd, int dim, class GridImp> 00027 inline bool ALU3dGridEntity<cd,dim,GridImp> :: 00028 equals(const ALU3dGridEntity<cd,dim,GridImp> & org) const 00029 { 00030 return (item_ == org.item_); 00031 } 00032 00033 template<int cd, int dim, class GridImp> 00034 inline int ALU3dGridEntity<cd,dim,GridImp> :: getIndex () const 00035 { 00036 return gIndex_; 00037 } 00038 00039 template<int cd, int dim, class GridImp> 00040 inline int ALU3dGridEntity<cd,dim,GridImp> :: level () const 00041 { 00042 return level_; 00043 } 00044 00045 template<int cd, int dim, class GridImp> 00046 inline PartitionType ALU3dGridEntity<cd,dim,GridImp> :: 00047 partitionType () const 00048 { 00049 return partitionType_; 00050 } 00051 00052 template<int cd, int dim, class GridImp> 00053 inline GeometryType 00054 ALU3dGridEntity<cd,dim,GridImp>:: type () const 00055 { 00056 return geo_.type(); 00057 } 00058 00060 // 00061 // --Entity0 00062 // --Codim0Entity 00063 // 00065 template<int dim, class GridImp> 00066 inline void ALU3dGridEntity<0,dim,GridImp> :: 00067 removeElement () 00068 { 00069 item_ = 0; 00070 ghost_ = 0; 00071 geo_.invalidate(); 00072 } 00073 00074 template<int dim, class GridImp> 00075 inline void ALU3dGridEntity<0,dim,GridImp> :: 00076 reset (int walkLevel ) 00077 { 00078 item_ = 0; 00079 ghost_ = 0; 00080 level_ = -1; 00081 isLeaf_ = false; 00082 00083 // reset geometry information 00084 geo_.invalidate(); 00085 } 00086 00087 // works like assignment 00088 template<int dim, class GridImp> 00089 inline void 00090 ALU3dGridEntity<0,dim,GridImp> :: setEntity(const ALU3dGridEntity<0,dim,GridImp> & org) 00091 { 00092 item_ = org.item_; 00093 ghost_ = org.ghost_; 00094 level_ = org.level_; 00095 isLeaf_ = org.isLeaf_; 00096 00097 // reset geometry information 00098 geo_.invalidate(); 00099 } 00100 00101 template<int dim, class GridImp> 00102 inline void 00103 ALU3dGridEntity<0,dim,GridImp>:: 00104 setElement(const EntitySeed& key ) 00105 { 00106 if( ! key.isGhost() ) 00107 setElement( *key.interior() ); 00108 else 00109 setGhost( *key.ghost() ); 00110 } 00111 00112 template<int dim, class GridImp> 00113 inline void 00114 ALU3dGridEntity<0,dim,GridImp>:: 00115 setElement(HElementType & element) 00116 { 00117 item_ = static_cast<IMPLElementType *> (&element); 00118 assert( item_ ); 00119 // make sure this method is not called for ghosts 00120 assert( ! item_->isGhost() ); 00121 ghost_ = 0; 00122 level_ = (*item_).level(); 00123 isLeaf_ = ((*item_).down() == 0); 00124 00125 // reset geometry information 00126 geo_.invalidate(); 00127 } 00128 00129 template<int dim, class GridImp> 00130 inline void 00131 ALU3dGridEntity<0,dim,GridImp> :: setGhost(HBndSegType & ghost) 00132 { 00133 // use element as ghost 00134 item_ = static_cast<IMPLElementType *> ( ghost.getGhost().first ); 00135 00136 // method getGhost can return 0, but then is something wrong 00137 assert(item_); 00138 assert(item_->isGhost()); 00139 00140 level_ = item_->level(); 00141 // remember pointer to ghost face 00142 ghost_ = static_cast<BNDFaceType *> (&ghost); 00143 assert( ghost_ ); 00144 00145 BNDFaceType * dwn = static_cast<BNDFaceType *> (ghost.down()); 00146 if ( ! dwn ) isLeaf_ = true; 00147 else 00148 { 00149 assert( ghost.level() == level_ ); 00150 if(dwn->ghostLevel() == level_) 00151 isLeaf_ = true; 00152 else 00153 isLeaf_ = false; 00154 } 00155 // check wether ghost is leaf or not, ghost leaf means 00156 // that this is the ghost that we want in the leaf iterator 00157 // not necessarily is real leaf element 00158 // see Intersection Iterator, same story 00159 00160 // reset geometry information 00161 geo_.invalidate(); 00162 } 00163 00164 template<int dim, class GridImp> 00165 inline int 00166 ALU3dGridEntity<0,dim,GridImp> :: level() const 00167 { 00168 return level_; 00169 } 00170 00171 template<int dim, class GridImp> 00172 inline bool ALU3dGridEntity<0,dim,GridImp> :: 00173 equals (const ALU3dGridEntity<0,dim,GridImp> &org ) const 00174 { 00175 return (item_ == org.item_); 00176 } 00177 00178 template<int dim, class GridImp> 00179 inline GeometryType 00180 ALU3dGridEntity<0,dim,GridImp> :: type () const 00181 { 00182 return geo_.type(); 00183 } 00184 00185 template<int dim, class GridImp> 00186 inline int ALU3dGridEntity<0,dim,GridImp> :: getIndex() const 00187 { 00188 assert( item_ ); 00189 return (*item_).getIndex(); 00190 } 00191 00192 template<int dim, class GridImp> 00193 template<int cc> 00194 inline int ALU3dGridEntity<0,dim,GridImp> :: count () const 00195 { 00196 return grid().referenceElement().size(cc); 00197 } 00198 00199 template<int dim, class GridImp> 00200 inline PartitionType ALU3dGridEntity<0,dim,GridImp> :: 00201 partitionType () const 00202 { 00203 assert( item_ ); 00204 // make sure we really got a ghost 00205 assert( (isGhost()) ? item_->isGhost() : true ); 00206 return (isGhost() ? GhostEntity : InteriorEntity); 00207 } 00208 00209 template<int dim, class GridImp> 00210 inline bool ALU3dGridEntity<0,dim,GridImp> :: isLeaf() const 00211 { 00212 return isLeaf_; 00213 } 00214 00215 template<int dim, class GridImp> 00216 inline ALU3dGridHierarchicIterator<GridImp> 00217 ALU3dGridEntity<0,dim,GridImp> :: hbegin (int maxlevel) const 00218 { 00219 assert(item_ != 0); 00220 // if isGhost is true the end iterator will be returned 00221 if( isGhost() ) 00222 { 00223 return ALU3dGridHierarchicIterator<GridImp>(factory_,*ghost_,maxlevel, isLeaf() ); 00224 } 00225 return ALU3dGridHierarchicIterator<GridImp>(factory_,*item_,maxlevel, isLeaf() ); 00226 } 00227 00228 template<int dim, class GridImp> 00229 inline ALU3dGridHierarchicIterator<GridImp> ALU3dGridEntity<0,dim,GridImp> :: hend (int maxlevel) const 00230 { 00231 assert(item_ != 0); 00232 return ALU3dGridHierarchicIterator<GridImp> (factory_, *item_, maxlevel, true); 00233 } 00234 00235 template<int dim, class GridImp> 00236 inline typename ALU3dGridEntity<0,dim,GridImp> :: ALU3dGridLeafIntersectionIteratorType 00237 ALU3dGridEntity<0,dim,GridImp> :: ileafbegin () const 00238 { 00239 assert(item_ != 0); 00240 return ALU3dGridIntersectionIteratorType (*this, this->level(), false ); 00241 } 00242 00243 template<int dim, class GridImp> 00244 inline typename ALU3dGridEntity<0,dim,GridImp> :: ALU3dGridLeafIntersectionIteratorType 00245 ALU3dGridEntity<0,dim,GridImp> :: ileafend () const 00246 { 00247 assert(item_ != 0); 00248 return ALU3dGridLeafIntersectionIteratorType (*this , this->level(), true); 00249 } 00250 00251 template<int dim, class GridImp> 00252 inline typename ALU3dGridEntity<0,dim,GridImp> :: ALU3dGridLevelIntersectionIteratorType 00253 ALU3dGridEntity<0,dim,GridImp> :: ilevelbegin () const 00254 { 00255 assert(item_ != 0); 00256 return ALU3dGridLevelIntersectionIteratorType (*this, this->level(), false ); 00257 } 00258 00259 template<int dim, class GridImp> 00260 inline typename ALU3dGridEntity<0,dim,GridImp> :: ALU3dGridLevelIntersectionIteratorType 00261 ALU3dGridEntity<0,dim,GridImp> :: ilevelend () const 00262 { 00263 assert(item_ != 0); 00264 return ALU3dGridLevelIntersectionIteratorType (*this, this->level(),true); 00265 } 00266 00267 // Adaptation methods 00268 template<int dim, class GridImp> 00269 inline bool ALU3dGridEntity<0,dim,GridImp> :: isNew () const 00270 { 00271 assert( item_ ); 00272 return item_->hasBeenRefined(); 00273 } 00274 00275 template<int dim, class GridImp> 00276 inline bool ALU3dGridEntity<0,dim,GridImp> :: mightVanish () const 00277 { 00278 assert( item_ ); 00279 return ((*item_).requestrule() == coarse_element_t); 00280 } 00281 00282 //******************************************************************* 00283 // 00284 // --EntityPointer 00285 // --EnPointer 00286 // 00287 //******************************************************************* 00288 template<int codim, class GridImp > 00289 inline ALU3dGridEntityPointerBase<codim,GridImp> :: 00290 ALU3dGridEntityPointerBase(const FactoryType& factory, 00291 const HElementType &item) 00292 : factory_(factory) 00293 , seed_( item ) 00294 , entity_( 0 ) 00295 , locked_ ( false ) // entity can be released 00296 { 00297 } 00298 00299 template<int codim, class GridImp > 00300 inline ALU3dGridEntityPointerBase<codim,GridImp> :: 00301 ALU3dGridEntityPointerBase(const FactoryType& factory, 00302 const HBndSegType & ghostFace ) 00303 : factory_(factory) 00304 , seed_( ghostFace ) 00305 , entity_ ( factory_.template getNewEntity<codim> ( ghostFace.level() )) 00306 , locked_( true ) // entity should not be released, otherwise is ghost info lost 00307 { 00308 // sets entity and item pointer 00309 updateGhostPointer( const_cast<HBndSegType &> (ghostFace) ); 00310 } 00311 00312 template<int codim, class GridImp > 00313 inline ALU3dGridEntityPointerBase<codim,GridImp> :: 00314 ALU3dGridEntityPointerBase(const FactoryType& factory, 00315 const ALU3dGridEntitySeedType& key ) 00316 : factory_(factory) 00317 , seed_( key ) 00318 , entity_ ( 0 ) 00319 , locked_( false ) 00320 { 00321 } 00322 00323 // constructor Level,Leaf and HierarchicIterator 00324 template<int codim, class GridImp > 00325 inline ALU3dGridEntityPointerBase<codim,GridImp> :: 00326 ALU3dGridEntityPointerBase(const FactoryType& factory, int level ) 00327 : factory_(factory) 00328 , seed_() 00329 , entity_ ( factory_.template getNewEntity<codim> ( level ) ) 00330 , locked_ ( false ) // entity can be released 00331 { 00332 // this needs to be called 00333 // have to investigate why 00334 entityImp().reset(level); 00335 } 00336 00337 00338 template<int codim, class GridImp > 00339 inline ALU3dGridEntityPointerBase<codim,GridImp> :: 00340 ALU3dGridEntityPointerBase(const FactoryType& factory, 00341 const HElementType &item, 00342 const int level, 00343 const int twist, 00344 const int duneFace ) 00345 : factory_(factory) 00346 , seed_( item, level, twist, duneFace ) 00347 , entity_( 0 ) 00348 , locked_ ( false ) // entity can be released 00349 {} 00350 00351 template<int codim, class GridImp > 00352 inline ALU3dGridEntityPointerBase<codim,GridImp> :: 00353 ALU3dGridEntityPointerBase(const ALU3dGridEntityPointerType & org) 00354 : factory_(org.factory_) 00355 , seed_( org.seed_ ) 00356 , entity_( 0 ) 00357 , locked_( org.locked_ ) 00358 { 00359 // if entity exists then copy entity 00360 getEntity( org ); 00361 } 00362 00363 template<int codim, class GridImp > 00364 inline void ALU3dGridEntityPointerBase<codim,GridImp> :: 00365 getEntity(const ALU3dGridEntityPointerType & org) 00366 { 00367 // if entity existed for original pointer then copy 00368 if( org.entity_ ) 00369 { 00370 assert( entity_ == 0 ); 00371 entity_ = factory_.template getNewEntity<codim> (); 00372 // set entity right away 00373 entityImp().setEntity( org.entityImp() ); 00374 } 00375 } 00376 00377 template<int codim, class GridImp > 00378 inline ALU3dGridEntityPointerBase<codim,GridImp> & 00379 ALU3dGridEntityPointerBase<codim,GridImp> :: 00380 operator = (const ALU3dGridEntityPointerType & org) 00381 { 00382 clone( org ); 00383 return *this; 00384 } 00385 00386 template<int codim, class GridImp > 00387 inline void 00388 ALU3dGridEntityPointerBase<codim,GridImp> :: 00389 clone (const ALU3dGridEntityPointerType & org) 00390 { 00391 assert( &factory_ == &org.factory_ ); 00392 00393 // set item 00394 seed_ = org.seed_; 00395 00396 HElementType* item = seed_.item(); 00397 // copy locked info 00398 locked_ = org.locked_; 00399 00400 if( item ) 00401 { 00402 // if no entity check org entity 00403 // if no org entity then nothing is done 00404 if( !entity_ ) 00405 { 00406 getEntity(org); 00407 } 00408 else 00409 { 00410 // in case of ghost element use different set method 00411 if( item->isGhost() ) 00412 { 00413 // on ghosts entity pointers entity always exists 00414 assert( org.entity_ ); 00415 entityImp().setEntity( org.entityImp() ); 00416 locked_ = true ; 00417 } 00418 else 00419 { 00420 // otherwise item is set 00421 entityImp().setElement( seed_ ); 00422 } 00423 } 00424 } 00425 else 00426 { 00427 this->done(); 00428 } 00429 return ; 00430 } 00431 00432 template<int codim, class GridImp > 00433 inline ALU3dGridEntityPointerBase<codim,GridImp> :: 00434 ~ALU3dGridEntityPointerBase() 00435 { 00436 this->done(); 00437 } 00438 00439 template<int codim, class GridImp > 00440 inline void ALU3dGridEntityPointerBase<codim,GridImp>::done () 00441 { 00442 seed_.clear(); 00443 locked_ = false; 00444 // free entity 00445 freeEntity(); 00446 } 00447 00448 template<int codim, class GridImp > 00449 inline void ALU3dGridEntityPointerBase<codim,GridImp>::freeEntity () 00450 { 00451 // sets entity pointer in the status of an empty entity 00452 if( entity_ ) 00453 { 00454 entityImp().removeElement(); 00455 factory_.template freeEntity<codim> ( (EntityObject *) entity_ ); 00456 entity_ = 0; 00457 } 00458 } 00459 00460 template<int codim, class GridImp > 00461 inline bool ALU3dGridEntityPointerBase<codim,GridImp>:: 00462 equals (const ALU3dGridEntityPointerBase<codim,GridImp>& i) const 00463 { 00464 // check equality of underlying items 00465 return (seed_.equals( i.seed_ )); 00466 } 00467 00468 template<int codim, class GridImp > 00469 inline typename ALU3dGridEntityPointerBase<codim,GridImp>::Entity & 00470 ALU3dGridEntityPointerBase<codim,GridImp>::dereference () const 00471 { 00472 // don't dereference empty entity pointer 00473 assert( seed_.item() ); 00474 assert( (seed_.item()->isGhost()) ? locked_ :true ); 00475 assert( (locked_) ? (entity_ != 0) : true); 00476 if( ! entity_ ) 00477 { 00478 entity_ = factory_.template getNewEntity<codim> (); 00479 entityImp().setElement( seed_ ); 00480 } 00481 assert( seed_.item() == & entityImp().getItem() ); 00482 return (*entity_); 00483 } 00484 00485 template<int codim, class GridImp > 00486 inline int ALU3dGridEntityPointerBase<codim,GridImp>::level () const 00487 { 00488 assert( seed_.item() ); 00489 return seed_.item()->level(); 00490 } 00491 00492 template<int codim, class GridImp > 00493 inline void ALU3dGridEntityPointerBase<codim,GridImp>:: 00494 updateGhostPointer( HBndSegType & ghostFace ) 00495 { 00496 assert( entity_ ); 00497 entityImp().setGhost( ghostFace ); 00498 // inside the method setGhost the method getGhost of the ghostFace is 00499 // called and set as item 00500 seed_.set( ghostFace ); 00501 } 00502 00503 template<int codim, class GridImp > 00504 inline void ALU3dGridEntityPointerBase<codim,GridImp>:: 00505 updateEntityPointer( HElementType * item , int ) 00506 { 00507 seed_.set( *item ); 00508 if( item && entity_ ) 00509 { 00510 entityImp().setElement( seed_ ); 00511 } 00512 } 00513 00515 // 00516 // specialisation for higher codims 00517 // 00519 00520 template<int codim, class GridImp > 00521 inline ALU3dGridEntityPointer<codim,GridImp> :: 00522 ALU3dGridEntityPointer(const FactoryType& factory, 00523 const int level, 00524 const HElementType &item, 00525 const int twist, 00526 const int duneFace ) 00527 : ALU3dGridEntityPointerBase<codim,GridImp> (factory,item,level,twist,duneFace) 00528 { 00529 } 00530 00531 template<int codim, class GridImp > 00532 inline ALU3dGridEntityPointer<codim,GridImp> :: 00533 ALU3dGridEntityPointer(const ALU3dGridEntityPointerType & org) 00534 : ALU3dGridEntityPointerBase<codim,GridImp>(org) 00535 { 00536 } 00537 00538 template<int codim, class GridImp > 00539 inline ALU3dGridEntityPointer<codim,GridImp> & 00540 ALU3dGridEntityPointer<codim,GridImp>:: 00541 operator = (const ALU3dGridEntityPointerType & org) 00542 { 00543 // clone pointer 00544 clone(org); 00545 return *this; 00546 } 00547 00548 template<int codim, class GridImp > 00549 inline void 00550 ALU3dGridEntityPointer<codim,GridImp> :: 00551 clone (const ALU3dGridEntityPointerType & org) 00552 { 00553 // copy key 00554 seed_ = org.seed_; 00555 00556 assert( &factory_ == &org.factory_ ); 00557 // copy lock status 00558 this->locked_ = org.locked_; 00559 00560 // if entity exists, just remove item pointer 00561 if( seed_.item() ) 00562 { 00563 if( ! entity_ ) 00564 getEntity(org); 00565 else 00566 entityImp().setElement( seed_ ); 00567 } 00568 else 00569 this->done(); 00570 return ; 00571 } 00572 00573 template<int codim, class GridImp > 00574 inline typename ALU3dGridEntityPointer<codim,GridImp>::Entity & 00575 ALU3dGridEntityPointer<codim,GridImp>::dereference () const 00576 { 00577 // don't dereference empty entity pointer 00578 assert( seed_.item() ); 00579 if( ! entity_ ) 00580 { 00581 entity_ = factory_.template getNewEntity<codim> (); 00582 entityImp().setElement( seed_ ); 00583 } 00584 assert( seed_.item() == & entityImp().getItem() ); 00585 return (*entity_); 00586 } 00587 00588 template<int codim, class GridImp > 00589 inline int ALU3dGridEntityPointer<codim,GridImp>::level () const 00590 { 00591 return seed_.level(); 00592 } 00593 00594 template<int codim, class GridImp > 00595 inline void ALU3dGridEntityPointer<codim,GridImp>:: 00596 updateEntityPointer( HElementType * item, int level) 00597 { 00598 seed_.set( *item, level ); 00599 if( item && entity_ ) 00600 { 00601 entityImp().setElement( seed_ ); 00602 } 00603 } 00604 00605 00606 } // end namespace Dune