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