- Home
- About DUNE
- Download
- Documentation
- Community
- Development
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 } 00024 00025 template<int cd, int dim, class GridImp> 00026 inline bool ALU3dGridEntity<cd,dim,GridImp> :: 00027 equals(const ALU3dGridEntity<cd,dim,GridImp> & org) const 00028 { 00029 return (item_ == org.item_); 00030 } 00031 00032 template<int cd, int dim, class GridImp> 00033 inline int ALU3dGridEntity<cd,dim,GridImp> :: getIndex () const 00034 { 00035 return gIndex_; 00036 } 00037 00038 template<int cd, int dim, class GridImp> 00039 inline int ALU3dGridEntity<cd,dim,GridImp> :: level () const 00040 { 00041 return level_; 00042 } 00043 00044 template<int cd, int dim, class GridImp> 00045 inline PartitionType ALU3dGridEntity<cd,dim,GridImp> :: 00046 partitionType () const 00047 { 00048 return partitionType_; 00049 } 00050 00051 template<int cd, int dim, class GridImp> 00052 inline GeometryType 00053 ALU3dGridEntity<cd,dim,GridImp>:: type () const 00054 { 00055 return geo_.type(); 00056 } 00057 00059 // 00060 // --Entity0 00061 // --Codim0Entity 00062 // 00064 template<int dim, class GridImp> 00065 inline void ALU3dGridEntity<0,dim,GridImp> :: 00066 removeElement () 00067 { 00068 item_ = 0; 00069 ghost_ = 0; 00070 } 00071 00072 template<int dim, class GridImp> 00073 inline void ALU3dGridEntity<0,dim,GridImp> :: 00074 reset (int walkLevel ) 00075 { 00076 item_ = 0; 00077 ghost_ = 0; 00078 builtgeometry_ = false; 00079 level_ = -1; 00080 isLeaf_ = false; 00081 } 00082 00083 // works like assignment 00084 template<int dim, class GridImp> 00085 inline void 00086 ALU3dGridEntity<0,dim,GridImp> :: setEntity(const ALU3dGridEntity<0,dim,GridImp> & org) 00087 { 00088 item_ = org.item_; 00089 ghost_ = org.ghost_; 00090 builtgeometry_ = false; 00091 level_ = org.level_; 00092 isLeaf_ = org.isLeaf_; 00093 } 00094 00095 template<int dim, class GridImp> 00096 inline void 00097 ALU3dGridEntity<0,dim,GridImp>:: 00098 setElement(const EntitySeed& key ) 00099 { 00100 if( ! key.isGhost() ) 00101 setElement( *key.interior() ); 00102 else 00103 setGhost( *key.ghost() ); 00104 } 00105 00106 template<int dim, class GridImp> 00107 inline void 00108 ALU3dGridEntity<0,dim,GridImp>:: 00109 setElement(HElementType & element) 00110 { 00111 item_ = static_cast<IMPLElementType *> (&element); 00112 assert( item_ ); 00113 // make sure this method is not called for ghosts 00114 assert( ! item_->isGhost() ); 00115 ghost_ = 0; 00116 builtgeometry_ = false; 00117 level_ = (*item_).level(); 00118 isLeaf_ = ((*item_).down() == 0); 00119 } 00120 00121 template<int dim, class GridImp> 00122 inline void 00123 ALU3dGridEntity<0,dim,GridImp> :: setGhost(HBndSegType & ghost) 00124 { 00125 // use element as ghost 00126 item_ = static_cast<IMPLElementType *> ( ghost.getGhost().first ); 00127 00128 // method getGhost can return 0, but then is something wrong 00129 assert(item_); 00130 assert(item_->isGhost()); 00131 00132 level_ = item_->level(); 00133 // remember pointer to ghost face 00134 ghost_ = static_cast<BNDFaceType *> (&ghost); 00135 assert( ghost_ ); 00136 builtgeometry_ = false; 00137 00138 BNDFaceType * dwn = static_cast<BNDFaceType *> (ghost.down()); 00139 if ( ! dwn ) isLeaf_ = true; 00140 else 00141 { 00142 assert( ghost.level() == level_ ); 00143 if(dwn->ghostLevel() == level_) 00144 isLeaf_ = true; 00145 else 00146 isLeaf_ = false; 00147 } 00148 // check wether ghost is leaf or not, ghost leaf means 00149 // that this is the ghost that we want in the leaf iterator 00150 // not necessarily is real leaf element 00151 // see Intersection Iterator, same story 00152 } 00153 00154 template<int dim, class GridImp> 00155 inline int 00156 ALU3dGridEntity<0,dim,GridImp> :: level() const 00157 { 00158 return level_; 00159 } 00160 00161 template<int dim, class GridImp> 00162 inline bool ALU3dGridEntity<0,dim,GridImp> :: 00163 equals (const ALU3dGridEntity<0,dim,GridImp> &org ) const 00164 { 00165 return (item_ == org.item_); 00166 } 00167 00168 template<int dim, class GridImp> 00169 inline GeometryType 00170 ALU3dGridEntity<0,dim,GridImp> :: type () const 00171 { 00172 return geo_.type(); 00173 } 00174 00175 template<int dim, class GridImp> 00176 inline int ALU3dGridEntity<0,dim,GridImp> :: getIndex() const 00177 { 00178 assert( item_ ); 00179 return (*item_).getIndex(); 00180 } 00181 00182 template<int dim, class GridImp> 00183 template<int cc> 00184 inline int ALU3dGridEntity<0,dim,GridImp> :: count () const 00185 { 00186 return grid().referenceElement().size(cc); 00187 } 00188 00189 template<int dim, class GridImp> 00190 inline PartitionType ALU3dGridEntity<0,dim,GridImp> :: 00191 partitionType () const 00192 { 00193 assert( item_ ); 00194 // make sure we really got a ghost 00195 assert( (isGhost()) ? item_->isGhost() : true ); 00196 return (isGhost() ? GhostEntity : InteriorEntity); 00197 } 00198 00199 template<int dim, class GridImp> 00200 inline bool ALU3dGridEntity<0,dim,GridImp> :: isLeaf() const 00201 { 00202 return isLeaf_; 00203 } 00204 00205 template<int dim, class GridImp> 00206 inline ALU3dGridHierarchicIterator<GridImp> 00207 ALU3dGridEntity<0,dim,GridImp> :: hbegin (int maxlevel) const 00208 { 00209 assert(item_ != 0); 00210 // if isGhost is true the end iterator will be returned 00211 if( isGhost() ) 00212 { 00213 return ALU3dGridHierarchicIterator<GridImp>(factory_,*ghost_,maxlevel, isLeaf() ); 00214 } 00215 return ALU3dGridHierarchicIterator<GridImp>(factory_,*item_,maxlevel, isLeaf() ); 00216 } 00217 00218 template<int dim, class GridImp> 00219 inline ALU3dGridHierarchicIterator<GridImp> ALU3dGridEntity<0,dim,GridImp> :: hend (int maxlevel) const 00220 { 00221 assert(item_ != 0); 00222 return ALU3dGridHierarchicIterator<GridImp> (factory_, *item_, maxlevel, true); 00223 } 00224 00225 template<int dim, class GridImp> 00226 inline typename ALU3dGridEntity<0,dim,GridImp> :: ALU3dGridLeafIntersectionIteratorType 00227 ALU3dGridEntity<0,dim,GridImp> :: ileafbegin () const 00228 { 00229 assert(item_ != 0); 00230 return ALU3dGridIntersectionIteratorType (*this, this->level(), false ); 00231 } 00232 00233 template<int dim, class GridImp> 00234 inline typename ALU3dGridEntity<0,dim,GridImp> :: ALU3dGridLeafIntersectionIteratorType 00235 ALU3dGridEntity<0,dim,GridImp> :: ileafend () const 00236 { 00237 assert(item_ != 0); 00238 return ALU3dGridLeafIntersectionIteratorType (*this , this->level(), true); 00239 } 00240 00241 template<int dim, class GridImp> 00242 inline typename ALU3dGridEntity<0,dim,GridImp> :: ALU3dGridLevelIntersectionIteratorType 00243 ALU3dGridEntity<0,dim,GridImp> :: ilevelbegin () const 00244 { 00245 assert(item_ != 0); 00246 return ALU3dGridLevelIntersectionIteratorType (*this, this->level(), false ); 00247 } 00248 00249 template<int dim, class GridImp> 00250 inline typename ALU3dGridEntity<0,dim,GridImp> :: ALU3dGridLevelIntersectionIteratorType 00251 ALU3dGridEntity<0,dim,GridImp> :: ilevelend () const 00252 { 00253 assert(item_ != 0); 00254 return ALU3dGridLevelIntersectionIteratorType (*this, this->level(),true); 00255 } 00256 00257 // Adaptation methods 00258 template<int dim, class GridImp> 00259 inline bool ALU3dGridEntity<0,dim,GridImp> :: isNew () const 00260 { 00261 assert( item_ ); 00262 return item_->hasBeenRefined(); 00263 } 00264 00265 template<int dim, class GridImp> 00266 inline bool ALU3dGridEntity<0,dim,GridImp> :: mightVanish () const 00267 { 00268 assert( item_ ); 00269 return ((*item_).requestrule() == coarse_element_t); 00270 } 00271 00272 //******************************************************************* 00273 // 00274 // --EntityPointer 00275 // --EnPointer 00276 // 00277 //******************************************************************* 00278 template<int codim, class GridImp > 00279 inline ALU3dGridEntityPointerBase<codim,GridImp> :: 00280 ALU3dGridEntityPointerBase(const FactoryType& factory, 00281 const HElementType &item) 00282 : factory_(factory) 00283 , seed_( item ) 00284 , entity_( 0 ) 00285 , locked_ ( false ) // entity can be released 00286 { 00287 } 00288 00289 template<int codim, class GridImp > 00290 inline ALU3dGridEntityPointerBase<codim,GridImp> :: 00291 ALU3dGridEntityPointerBase(const FactoryType& factory, 00292 const HBndSegType & ghostFace ) 00293 : factory_(factory) 00294 , seed_( ghostFace ) 00295 , entity_ ( factory_.template getNewEntity<codim> ( ghostFace.level() )) 00296 , locked_( true ) // entity should not be released, otherwise is ghost info lost 00297 { 00298 // sets entity and item pointer 00299 updateGhostPointer( const_cast<HBndSegType &> (ghostFace) ); 00300 } 00301 00302 template<int codim, class GridImp > 00303 inline ALU3dGridEntityPointerBase<codim,GridImp> :: 00304 ALU3dGridEntityPointerBase(const FactoryType& factory, 00305 const ALU3dGridEntitySeedType& key ) 00306 : factory_(factory) 00307 , seed_( key ) 00308 , entity_ ( 0 ) 00309 , locked_( false ) 00310 { 00311 } 00312 00313 // constructor Level,Leaf and HierarchicIterator 00314 template<int codim, class GridImp > 00315 inline ALU3dGridEntityPointerBase<codim,GridImp> :: 00316 ALU3dGridEntityPointerBase(const FactoryType& factory, int level ) 00317 : factory_(factory) 00318 , seed_() 00319 , entity_ ( factory_.template getNewEntity<codim> ( level ) ) 00320 , locked_ ( false ) // entity can be released 00321 { 00322 // this needs to be called 00323 // have to investigate why 00324 entityImp().reset(level); 00325 } 00326 00327 00328 template<int codim, class GridImp > 00329 inline ALU3dGridEntityPointerBase<codim,GridImp> :: 00330 ALU3dGridEntityPointerBase(const FactoryType& factory, 00331 const HElementType &item, 00332 const int level, 00333 const int twist, 00334 const int duneFace ) 00335 : factory_(factory) 00336 , seed_( item, level, twist, duneFace ) 00337 , entity_( 0 ) 00338 , locked_ ( false ) // entity can be released 00339 {} 00340 00341 template<int codim, class GridImp > 00342 inline ALU3dGridEntityPointerBase<codim,GridImp> :: 00343 ALU3dGridEntityPointerBase(const ALU3dGridEntityPointerType & org) 00344 : factory_(org.factory_) 00345 , seed_( org.seed_ ) 00346 , entity_( 0 ) 00347 , locked_( org.locked_ ) 00348 { 00349 // if entity exists then copy entity 00350 getEntity( org ); 00351 } 00352 00353 template<int codim, class GridImp > 00354 inline void ALU3dGridEntityPointerBase<codim,GridImp> :: 00355 getEntity(const ALU3dGridEntityPointerType & org) 00356 { 00357 // if entity existed for original pointer then copy 00358 if( org.entity_ ) 00359 { 00360 assert( entity_ == 0 ); 00361 entity_ = factory_.template getNewEntity<codim> (); 00362 // set entity right away 00363 entityImp().setEntity( org.entityImp() ); 00364 } 00365 } 00366 00367 template<int codim, class GridImp > 00368 inline ALU3dGridEntityPointerBase<codim,GridImp> & 00369 ALU3dGridEntityPointerBase<codim,GridImp> :: 00370 operator = (const ALU3dGridEntityPointerType & org) 00371 { 00372 clone( org ); 00373 return *this; 00374 } 00375 00376 template<int codim, class GridImp > 00377 inline void 00378 ALU3dGridEntityPointerBase<codim,GridImp> :: 00379 clone (const ALU3dGridEntityPointerType & org) 00380 { 00381 assert( &factory_ == &org.factory_ ); 00382 00383 // set item 00384 seed_ = org.seed_; 00385 00386 HElementType* item = seed_.item(); 00387 // copy locked info 00388 locked_ = org.locked_; 00389 00390 if( item ) 00391 { 00392 // if no entity check org entity 00393 // if no org entity then nothing is done 00394 if( !entity_ ) 00395 { 00396 getEntity(org); 00397 } 00398 else 00399 { 00400 // in case of ghost element use different set method 00401 if( item->isGhost() ) 00402 { 00403 // on ghosts entity pointers entity always exists 00404 assert( org.entity_ ); 00405 entityImp().setEntity( org.entityImp() ); 00406 locked_ = true ; 00407 } 00408 else 00409 { 00410 // otherwise item is set 00411 entityImp().setElement( seed_ ); 00412 } 00413 } 00414 } 00415 else 00416 { 00417 this->done(); 00418 } 00419 return ; 00420 } 00421 00422 template<int codim, class GridImp > 00423 inline ALU3dGridEntityPointerBase<codim,GridImp> :: 00424 ~ALU3dGridEntityPointerBase() 00425 { 00426 this->done(); 00427 } 00428 00429 template<int codim, class GridImp > 00430 inline void ALU3dGridEntityPointerBase<codim,GridImp>::done () 00431 { 00432 seed_.clear(); 00433 locked_ = false; 00434 // free entity 00435 freeEntity(); 00436 } 00437 00438 template<int codim, class GridImp > 00439 inline void ALU3dGridEntityPointerBase<codim,GridImp>::freeEntity () 00440 { 00441 // sets entity pointer in the status of an empty entity 00442 if( entity_ ) 00443 { 00444 entityImp().removeElement(); 00445 factory_.template freeEntity<codim> ( (EntityObject *) entity_ ); 00446 entity_ = 0; 00447 } 00448 } 00449 00450 template<int codim, class GridImp > 00451 inline void ALU3dGridEntityPointerBase<codim,GridImp>::compactify() 00452 { 00453 // sets entity pointer in the status of an empty entity 00454 if( ! locked_ ) 00455 { 00456 freeEntity (); 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
Generated on Fri Apr 29 2011 with Doxygen (ver 1.7.1) [doxygen-log,error-log].