1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 // vi: set et ts=4 sw=2 sts=2: 3 #ifndef DUNE_GEOGRID_ENTITY_HH 4 #define DUNE_GEOGRID_ENTITY_HH 5 6 #include <dune/geometry/referenceelements.hh> 7 8 #include <dune/grid/common/grid.hh> 9 #include <dune/grid/geometrygrid/capabilities.hh> 10 #include <dune/grid/geometrygrid/cornerstorage.hh> 11 12 namespace Dune 13 { 14 15 namespace GeoGrid 16 { 17 18 // Internal Forward Declarations 19 // ----------------------------- 20 21 /** \class EntityBase 22 * \brief actual implementation of the entity 23 * \ingroup GeoGrid 24 * 25 * \tparam codim codimension of the entity 26 * \tparam Grid GeometryGrid, this entity belongs to 27 * \tparam fake \b true, if the host grid does not provide this entity 28 * (do not specify, the default value is already the 29 * intended use) 30 */ 31 template< int codim, class Grid, bool fake = !(Capabilities::hasHostEntity< Grid, codim >::v) > 32 class EntityBase; 33 34 /** \class Entity 35 * \brief DUNE-conform implementation of the entity 36 * \ingroup GeoGrid 37 * 38 * This class merely changes the template parameters of the entity to make 39 * DUNE happy. The actual implementation of the entity can be found in 40 * EntityBase. 41 * 42 * \tparam codim codimension of the entity 43 * \tparam dim dimension of the Grid (redundant information) 44 * \tparam Grid GeometryGrid, this entity belongs to 45 */ 46 template< int codim, int dim, class Grid > 47 class Entity; 48 49 50 51 // External Forward Declarations 52 // ----------------------------- 53 54 template< class Grid > 55 class HierarchicIterator; 56 57 template< class Grid, class HostIntersectionIterator > 58 class IntersectionIterator; 59 60 61 62 // EntityBase (real) 63 // ----------------- 64 65 /** \copydoc EntityBase 66 * 67 * This specialization implements the case, where the host grid provides 68 * the entity for this codimension, i.e., \em fake = \b false. 69 * 70 * \nosubgrouping 71 */ 72 template< int codim, class Grid > 73 class EntityBase< codim, Grid, false > 74 { 75 typedef typename std::remove_const< Grid >::type::Traits Traits; 76 77 public: 78 /** \name Attributes 79 * \{ */ 80 81 //! codimensioon of the entity 82 static const int codimension = codim; 83 //! dimension of the grid 84 static const int dimension = Traits::dimension; 85 //! dimension of the entity 86 static const int mydimension = dimension - codimension; 87 //! dimension of the world 88 static const int dimensionworld = Traits::dimensionworld; 89 90 //! \b true, if the entity is faked, i.e., if there is no corresponding host entity 91 static const bool fake = false; 92 93 /** \} */ 94 95 /** \name Types Required by DUNE 96 * \{ */ 97 98 //! coordinate type of the grid 99 typedef typename Traits::ctype ctype; 100 101 //! type of corresponding geometry 102 typedef typename Traits::template Codim< codimension >::Geometry Geometry; 103 /** \} */ 104 105 private: 106 typedef typename Traits::HostGrid HostGrid; 107 typedef typename Traits::CoordFunction CoordFunction; 108 109 public: 110 /** \name Host Types 111 * \{ */ 112 113 //! type of corresponding host entity 114 typedef typename HostGrid::template Codim< codimension >::Entity HostEntity; 115 116 //! type of corresponding entity seed 117 typedef typename Traits::template Codim< codimension >::EntitySeed EntitySeed; 118 119 //! type of host elements, i.e., of host entities of codimension 0 120 typedef typename HostGrid::template Codim< 0 >::Entity HostElement; 121 /** \} */ 122 123 typedef typename Traits::template Codim< codim >::GeometryImpl GeometryImpl; 124 125 private: 126 typedef typename HostGrid::template Codim< codimension >::Geometry HostGeometry; 127 128 typedef GeoGrid::CoordVector< mydimension, Grid, fake > CoordVector; 129 130 public: 131 /** \name Construction, Initialization and Destruction 132 * \{ */ 133 EntityBase()134 EntityBase () 135 : hostEntity_() 136 , grid_( nullptr ) 137 , geo_() 138 {} 139 EntityBase(const Grid & grid,const EntitySeed & seed)140 EntityBase ( const Grid &grid, const EntitySeed &seed ) 141 : hostEntity_( grid.hostGrid().entity( seed.impl().hostEntitySeed() ) ) 142 , grid_( &grid ) 143 {} 144 EntityBase(const Grid & grid,const HostElement & hostElement,int i)145 EntityBase ( const Grid &grid, const HostElement &hostElement, int i ) 146 : hostEntity_( hostElement.template subEntity<codim>(i) ) 147 , grid_( &grid ) 148 {} 149 150 EntityBase(const GeometryImpl & geo,const HostEntity & hostEntity)151 EntityBase ( const GeometryImpl &geo, const HostEntity &hostEntity ) 152 : hostEntity_( hostEntity ) 153 , grid_( &geo.grid() ) 154 , geo_( geo ) 155 {} 156 EntityBase(const GeometryImpl & geo,HostEntity && hostEntity)157 EntityBase ( const GeometryImpl &geo, HostEntity&& hostEntity ) 158 : hostEntity_( std::move( hostEntity ) ) 159 , grid_( &geo.grid() ) 160 , geo_( geo ) 161 {} 162 EntityBase(const Grid & grid,const HostEntity & hostEntity)163 EntityBase ( const Grid &grid, const HostEntity& hostEntity ) 164 : hostEntity_( hostEntity ) 165 , grid_( &grid ) 166 {} 167 EntityBase(const Grid & grid,HostEntity && hostEntity)168 EntityBase ( const Grid &grid, HostEntity&& hostEntity ) 169 : hostEntity_( std::move( hostEntity ) ) 170 , grid_( &grid ) 171 {} 172 173 EntityBase(const EntityBase & other)174 EntityBase ( const EntityBase &other ) 175 : hostEntity_( other.hostEntity_ ) 176 , grid_( other.grid_ ) 177 , geo_( other.geo_ ) 178 {} 179 EntityBase(EntityBase && other)180 EntityBase ( EntityBase&& other ) 181 : hostEntity_( std::move( other.hostEntity_ ) ) 182 , grid_( other.grid_ ) 183 , geo_( std::move( other.geo_ ) ) 184 {} 185 186 /** \} */ 187 operator =(const EntityBase & other)188 const EntityBase &operator= ( const EntityBase &other ) 189 { 190 hostEntity_ = other.hostEntity_; 191 grid_ = other.grid_; 192 geo_ = other.geo_; 193 return *this; 194 } 195 operator =(EntityBase && other)196 const EntityBase &operator= ( EntityBase&& other ) 197 { 198 hostEntity_ = std::move( other.hostEntity_ ); 199 grid_ = std::move( other.grid_ ); 200 geo_ = std::move( other.geo_ ); 201 return *this; 202 } 203 204 /** \brief compare two entities */ equals(const EntityBase & other) const205 bool equals ( const EntityBase &other) const 206 { 207 return hostEntity_ == other.hostEntity_; 208 } 209 210 public: 211 /** \name Methods Shared by Entities of All Codimensions 212 * \{ */ 213 214 /** \brief obtain the name of the corresponding reference element 215 * 216 * This type can be used to access the DUNE reference element. 217 */ type() const218 GeometryType type () const 219 { 220 return hostEntity().type(); 221 } 222 223 /** \brief obtain the level of this entity */ level() const224 int level () const 225 { 226 return hostEntity().level(); 227 } 228 229 /** \brief obtain the partition type of this entity */ partitionType() const230 PartitionType partitionType () const 231 { 232 return hostEntity().partitionType(); 233 } 234 235 /** obtain the geometry of this entity 236 * 237 * Each DUNE entity encapsulates a geometry object, representing the map 238 * from the reference element to world coordinates. Wrapping the geometry 239 * is the main objective of the GeometryGrid. 240 * 241 * The GeometryGrid provides geometries of order 1, obtained by 242 * interpolation of its corners \f$y_i\f$. There corners are calculated 243 * from the corners \f$x_i\f$ of the host geometry through the 244 * GeometryGrid's coordinate function \f$c\f$, i.e., 245 * \f$y_i = c( x_i )\f$. 246 * 247 * \returns a const reference to the geometry 248 */ geometry() const249 Geometry geometry () const 250 { 251 if( !geo_ ) 252 { 253 CoordVector coords( hostEntity(), grid().coordFunction() ); 254 geo_ = GeometryImpl( grid(), type(), coords ); 255 } 256 return Geometry( geo_ ); 257 } 258 subEntities(unsigned int cc) const259 unsigned int subEntities ( unsigned int cc ) const 260 { 261 return hostEntity().subEntities( cc ); 262 } 263 264 /** \brief return EntitySeed of host grid entity */ seed() const265 EntitySeed seed () const { return typename EntitySeed::Implementation( hostEntity().seed() ); } 266 /** \} */ 267 268 269 /** \name Methods Supporting the Grid Implementation 270 * \{ */ 271 grid() const272 const Grid &grid () const { assert( grid_ ); return *grid_; } 273 hostEntity() const274 const HostEntity &hostEntity () const 275 { 276 return hostEntity_; 277 } 278 279 /** \brief initiliaze an entity 280 * 281 * \param[in] hostEntity reference to the host entity 282 * 283 */ initialize(const HostEntity & hostEntity)284 void initialize ( const HostEntity &hostEntity ) { hostEntity_ = hostEntity; } 285 286 /** \brief obtain the entity's index from a host IndexSet 287 * 288 * \internal This method is provided by the entity, because its 289 * implementation is different for fake and non-fake entities. 290 * 291 * \param[in] indexSet host IndexSet to use 292 */ 293 template< class HostIndexSet > 294 typename HostIndexSet::IndexType index(const HostIndexSet & indexSet) const295 index ( const HostIndexSet &indexSet ) const 296 { 297 return indexSet.template index< codimension >( hostEntity() ); 298 } 299 300 /** \brief obtain the index of a subentity from a host IndexSet 301 * 302 * \internal This method is provided by the entity, because its 303 * implementation is different for fake and non-fake entities. 304 * 305 * \param[in] indexSet host IndexSet to use 306 * \param[in] i number of the subentity 307 * \param[in] cd codimension of the subentity 308 */ 309 template< class HostIndexSet > 310 typename HostIndexSet::IndexType subIndex(const HostIndexSet & indexSet,int i,unsigned int cd) const311 subIndex ( const HostIndexSet &indexSet, int i, unsigned int cd ) const 312 { 313 return indexSet.subIndex( hostEntity(), i, cd ); 314 } 315 316 /** \brief check whether the entity is contained in a host index set 317 * 318 * \internal This method is provided by the entity, because its 319 * implementation is different for fake and non-fake entities. 320 * 321 * \param indexSet host IndexSet to use 322 */ 323 template< class HostIndexSet > isContained(const HostIndexSet & indexSet) const324 bool isContained ( const HostIndexSet &indexSet ) const 325 { 326 return indexSet.contains( hostEntity() ); 327 } 328 329 /** \brief obtain the entity's id from a host IdSet 330 * 331 * \internal This method is provided by the entity, because its 332 * implementation is different for fake and non-fake entities. 333 * 334 * \param idSet host IdSet to use 335 */ 336 template< class HostIdSet > id(const HostIdSet & idSet) const337 typename HostIdSet::IdType id ( const HostIdSet &idSet ) const 338 { 339 return idSet.template id< codimension >( hostEntity() ); 340 } 341 /** \} */ 342 343 private: 344 HostEntity hostEntity_; 345 const Grid *grid_; 346 mutable GeometryImpl geo_; 347 }; 348 349 350 351 // EntityBase (fake) 352 // ----------------- 353 354 /** \copydoc EntityBase 355 * 356 * This specialization implements the case, where the host grid does not 357 * provide the entity for this codimension, i.e., \em fake = \b true. 358 * 359 * \nosubgrouping 360 */ 361 template< int codim, class Grid > 362 class EntityBase< codim, Grid, true > 363 { 364 typedef typename std::remove_const< Grid >::type::Traits Traits; 365 366 public: 367 /** \name Attributes 368 * \{ */ 369 370 //! codimensioon of the entity 371 static const int codimension = codim; 372 //! dimension of the grid 373 static const int dimension = Traits::dimension; 374 //! dimension of the entity 375 static const int mydimension = dimension - codimension; 376 //! dimension of the world 377 static const int dimensionworld = Traits::dimensionworld; 378 379 //! \b true, if the entity is faked, i.e., if there is no corresponding host entity 380 static const bool fake = true; 381 /** \} */ 382 383 /** \name Types Required by DUNE 384 * \{ */ 385 386 //! coordinate type of the grid 387 typedef typename Traits::ctype ctype; 388 389 //! type of corresponding geometry 390 typedef typename Traits::template Codim< codimension >::Geometry Geometry; 391 /** \} */ 392 393 private: 394 typedef typename Traits::HostGrid HostGrid; 395 typedef typename Traits::CoordFunction CoordFunction; 396 397 public: 398 /** \name Host Types 399 * \{ */ 400 401 //! type of corresponding host entity 402 typedef typename HostGrid::template Codim< codimension >::Entity HostEntity; 403 404 //! type of corresponding entity seed 405 typedef typename Traits::template Codim< codimension >::EntitySeed EntitySeed; 406 407 //! type of host elements, i.e., of host entities of codimension 0 408 typedef typename HostGrid::template Codim< 0 >::Entity HostElement; 409 /** \} */ 410 411 typedef typename Traits::template Codim< codimension >::GeometryImpl GeometryImpl; 412 413 private: 414 typedef typename HostGrid::template Codim< 0 >::Geometry HostGeometry; 415 416 typedef GeoGrid::CoordVector< mydimension, Grid, fake > CoordVector; 417 418 public: 419 /** \name Construction, Initialization and Destruction 420 * \{ */ 421 EntityBase()422 EntityBase () 423 : hostElement_() 424 , subEntity_(-1) 425 , grid_(nullptr) 426 , geo_() 427 {} 428 EntityBase(const Grid & grid,const HostElement & hostElement,unsigned int subEntity)429 EntityBase(const Grid& grid, const HostElement& hostElement, unsigned int subEntity) 430 : hostElement_(hostElement) 431 , subEntity_(subEntity) 432 , grid_(&grid) 433 {} 434 EntityBase(const Grid & grid,const EntitySeed & seed)435 EntityBase ( const Grid &grid, const EntitySeed &seed ) 436 : hostElement_( grid.hostGrid().entity( seed.impl().hostElementSeed() ) ) 437 , subEntity_( seed.impl().subEntity() ) 438 , grid_( &grid ) 439 {} 440 EntityBase(const EntityBase & other)441 EntityBase ( const EntityBase &other ) 442 : hostElement_( other.hostElement_ ) 443 , subEntity_( other.subEntity_ ) 444 , grid_(other.grid_) 445 , geo_( other.geo_ ) 446 {} 447 EntityBase(EntityBase && other)448 EntityBase ( EntityBase &&other ) 449 : hostElement_( std::move( other.hostElement_ ) ) 450 , subEntity_( std::move( other.subEntity_ ) ) 451 , grid_( std::move( other.grid_ ) ) 452 , geo_( std::move( other.geo_ ) ) 453 {} 454 455 /* 456 * This method is required by constructors in the `Entity` class 457 * below, however it cannot do anything useful for fake 458 * entities. 459 */ EntityBase(const Grid & grid,const HostEntity & hostEntity)460 EntityBase(const Grid& grid, const HostEntity& hostEntity) 461 { 462 DUNE_THROW(Dune::Exception, "GeometryGrid: Cannot create fake entity of codim " << codimension << " from real host entity."); 463 } 464 465 /** \} */ 466 operator =(const EntityBase & other)467 const EntityBase &operator= ( const EntityBase &other ) 468 { 469 hostElement_ = other.hostElement_; 470 subEntity_ = other.subEntity_; 471 grid_ = other.grid_; 472 geo_ = other.geo_; 473 return *this; 474 } 475 operator =(EntityBase && other)476 const EntityBase &operator= ( EntityBase&& other ) 477 { 478 hostElement_ = std::move( other.hostElement_ ); 479 subEntity_ = std::move( other.subEntity_ ); 480 grid_ = std::move( other.grid_ ); 481 geo_ = std::move( other.geo_ ); 482 return *this; 483 } 484 485 /** \brief compare two entities */ equals(const EntityBase & other) const486 bool equals ( const EntityBase &other) const 487 { 488 const bool thisEnd = (subEntity() < 0); 489 const bool otherEnd = (other.subEntity() < 0); 490 if( thisEnd || otherEnd ) 491 return thisEnd && otherEnd; 492 493 const int lvl = level(); 494 if( lvl != other.level() ) 495 return false; 496 497 const typename Traits::HostGrid::Traits::LevelIndexSet &indexSet 498 = grid().hostGrid().levelIndexSet( lvl ); 499 500 const HostElement &thisElement = hostElement(); 501 assert( indexSet.contains( thisElement ) ); 502 const HostElement &otherElement = other.hostElement(); 503 assert( indexSet.contains( otherElement ) ); 504 505 const int thisIndex = indexSet.subIndex( thisElement, subEntity(), codimension ); 506 const int otherIndex = indexSet.subIndex( otherElement, other.subEntity(), codimension ); 507 return (thisIndex == otherIndex); 508 } 509 510 /** \name Methods Shared by Entities of All Codimensions 511 * \{ */ 512 513 /** \brief obtain the name of the corresponding reference element 514 * 515 * This type can be used to access the DUNE reference element. 516 */ type() const517 GeometryType type () const 518 { 519 auto refElement = referenceElement< ctype, dimension >( hostElement().type() ); 520 return refElement.type( subEntity_, codimension ); 521 } 522 523 /** \brief obtain the level of this entity */ level() const524 int level () const 525 { 526 return hostElement().level(); 527 } 528 529 /** \brief obtain the partition type of this entity */ partitionType() const530 PartitionType partitionType () const 531 { 532 auto refElement = referenceElement< ctype, dimension >( hostElement().type() ); 533 534 PartitionType type = vertexPartitionType( refElement, 0 ); 535 if( (type != BorderEntity) && (type != FrontEntity) ) 536 return type; 537 538 const int numVertices = refElement.size( subEntity_, codimension, dimension ); 539 for( int i = 1; i < numVertices; ++i ) 540 { 541 PartitionType vtxType = vertexPartitionType( refElement, i ); 542 if( (vtxType != BorderEntity) && (vtxType != FrontEntity) ) 543 return vtxType; 544 if( type != vtxType ) 545 return OverlapEntity; 546 } 547 assert( (type == BorderEntity) || (type == FrontEntity) ); 548 return type; 549 } 550 551 /** obtain the geometry of this entity 552 * 553 * Each DUNE entity encapsulates a geometry object, representing the map 554 * from the reference element to world coordinates. Wrapping the geometry 555 * is the main objective of the GeometryGrid. 556 * 557 * The GeometryGrid provides geometries of order 1, obtained by 558 * interpolation of its corners \f$y_i\f$. There corners are calculated 559 * from the corners \f$x_i\f$ of the host geometry through the 560 * GeometryGrid's coordinate function \f$c\f$, i.e., 561 * \f$y_i = c( x_i )\f$. 562 * 563 * \returns a geometry object 564 */ geometry() const565 Geometry geometry () const 566 { 567 if( !geo_ ) 568 { 569 CoordVector coords( hostElement(), subEntity_, grid().coordFunction() ); 570 geo_ = GeometryImpl( grid(), type(), coords ); 571 } 572 return Geometry( geo_ ); 573 } 574 subEntities(unsigned int cc) const575 unsigned int subEntities ( unsigned int cc ) const 576 { 577 auto refElement = referenceElement< ctype, dimension >( hostElement().type() ); 578 return refElement.size( subEntity_, codimension, cc ); 579 } 580 581 /** \brief return EntitySeed of host grid entity */ seed() const582 EntitySeed seed () const { return typename EntitySeed::Implementation( hostElement().seed(), subEntity_ ); } 583 /** \} */ 584 585 /** \name Methods Supporting the Grid Implementation 586 * \{ */ 587 grid() const588 const Grid &grid () const { assert( grid_ ); return *grid_; } 589 hostEntity() const590 const HostEntity &hostEntity () const 591 { 592 DUNE_THROW( NotImplemented, "HostGrid has no entities of codimension " << codimension << "." ); 593 } 594 hostElement() const595 const HostElement &hostElement () const 596 { 597 return hostElement_; 598 } 599 subEntity() const600 int subEntity () const { return subEntity_; } 601 602 /** \brief initiliaze an entity 603 * 604 * \param[in] hostElement reference to the host element 605 * 606 * \note The reference must remain valid as long as this entity is in 607 * use. 608 */ initialize(const HostElement & hostElement)609 void initialize ( const HostElement &hostElement ) { hostElement_ = hostElement; } 610 611 /** \brief obtain the entity's index from a host IndexSet 612 * 613 * \internal This method is provided by the entity, because its 614 * implementation is different for fake and non-fake entities. 615 * 616 * \param[in] indexSet host IndexSet to use 617 */ 618 template< class HostIndexSet > index(const HostIndexSet & indexSet) const619 typename HostIndexSet::IndexType index ( const HostIndexSet &indexSet ) const 620 { 621 return indexSet.subIndex( hostElement(), subEntity_, codimension ); 622 } 623 624 /** \brief obtain the index of a subentity from a host IndexSet 625 * 626 * \internal This method is provided by the entity, because its 627 * implementation is different for fake and non-fake entities. 628 * 629 * \param[in] indexSet host IndexSet to use 630 * \param[in] i number of the subentity 631 * \param[in] cd codimension of the subentity 632 */ 633 template< class HostIndexSet > 634 typename HostIndexSet::IndexType subIndex(const HostIndexSet & indexSet,int i,unsigned int cd) const635 subIndex ( const HostIndexSet &indexSet, int i, unsigned int cd ) const 636 { 637 auto refElement = referenceElement< ctype, dimension >( hostElement().type() ); 638 const int j = refElement.subEntity( subEntity_, codimension, i, codimension+cd ); 639 return indexSet.subIndex( hostElement(), j, codimension+cd ); 640 } 641 642 /** \brief check whether the entity is contained in a host index set 643 * 644 * \internal This method is provided by the entity, because its 645 * implementation is different for fake and non-fake entities. 646 * 647 * \param indexSet host IndexSet to use 648 */ 649 template< class HostIndexSet > isContained(const HostIndexSet & indexSet) const650 bool isContained ( const HostIndexSet &indexSet ) const 651 { 652 return indexSet.contains( hostElement() ); 653 } 654 655 /** \brief obtain the entity's id from a host IdSet 656 * 657 * \internal This method is provided by the entity, because its 658 * implementation is different for fake and non-fake entities. 659 * 660 * \param idSet host IdSet to use 661 */ 662 template< class HostIdSet > id(const HostIdSet & idSet) const663 typename HostIdSet::IdType id ( const HostIdSet &idSet ) const 664 { 665 return idSet.subId( hostElement(), subEntity_, codimension ); 666 } 667 /** \} */ 668 669 private: 670 PartitionType vertexPartitionType(Dune::Transitional::ReferenceElement<ctype,Dim<dimension>> refElement,int i) const671 vertexPartitionType ( Dune::Transitional::ReferenceElement< ctype, Dim<dimension> > refElement, int i ) const 672 { 673 const int j = refElement.subEntity( subEntity_, codimension, i, dimension ); 674 return hostElement().template subEntity< dimension >( j ).partitionType(); 675 } 676 677 private: 678 HostElement hostElement_; 679 unsigned int subEntity_; 680 const Grid *grid_; 681 mutable GeometryImpl geo_; 682 }; 683 684 685 686 // Entity 687 // ------ 688 689 template< int codim, int dim, class Grid > 690 class Entity 691 : public EntityBase< codim, Grid > 692 { 693 typedef EntityBase< codim, Grid > Base; 694 695 public: 696 typedef typename Base::HostEntity HostEntity; 697 typedef typename Base::HostElement HostElement; 698 typedef typename Base::GeometryImpl GeometryImpl; 699 typedef typename Base::EntitySeed EntitySeed; 700 Entity()701 Entity () : Base() {} 702 Entity(const Grid & grid,const EntitySeed & seed)703 Entity ( const Grid &grid, const EntitySeed &seed ) : Base( grid, seed ) {} 704 Entity(const Grid & grid,const HostEntity & hostEntity)705 Entity ( const Grid &grid, const HostEntity &hostEntity ) : Base( grid, hostEntity ) {} Entity(const Grid & grid,HostEntity && hostEntity)706 Entity ( const Grid &grid, HostEntity&& hostEntity ) : Base( grid, std::move( hostEntity ) ) {} 707 Entity(const Grid & grid,const HostElement & hostEntity,int i)708 Entity ( const Grid &grid, const HostElement &hostEntity, int i ) : Base( grid, hostEntity, i ) {} 709 710 }; 711 712 713 714 // Entity for codimension 0 715 // ------------------------ 716 717 template< int dim, class Grid > 718 class Entity< 0, dim, Grid > 719 : public EntityBase< 0, Grid > 720 { 721 typedef EntityBase< 0, Grid > Base; 722 723 typedef typename std::remove_const< Grid >::type::Traits Traits; 724 725 typedef typename Traits::HostGrid HostGrid; 726 727 public: 728 /** \name Attributes 729 * \{ */ 730 731 //! codimensioon of the entity 732 static const int codimension = Base::codimension; 733 //! dimension of the grid 734 static const int dimension = Base::dimension; 735 //! dimension of the entity 736 static const int mydimension = Base::mydimension; 737 //! dimension of the world 738 static const int dimensionworld = Base::dimensionworld; 739 740 //! \b true, if the entity is faked, i.e., if there is no corresponding host entity 741 static const bool fake = Base::fake; 742 /** \} */ 743 744 /** \name Types Required by DUNE 745 * \{ */ 746 747 //! type of corresponding local geometry 748 typedef typename Traits::template Codim< codimension >::LocalGeometry LocalGeometry; 749 750 typedef Dune::Entity< 0, dim, Grid, Dune::GeoGrid::Entity > EntityFacade; 751 752 //! type of hierarchic iterator 753 typedef typename Traits::HierarchicIterator HierarchicIterator; 754 //! type of leaf intersection iterator 755 typedef typename Traits::LeafIntersectionIterator LeafIntersectionIterator; 756 //! type of level intersection iterator 757 typedef typename Traits::LevelIntersectionIterator LevelIntersectionIterator; 758 759 /** \} */ 760 761 typedef typename Base::HostEntity HostEntity; 762 typedef typename Base::HostElement HostElement; 763 typedef typename Base::GeometryImpl GeometryImpl; 764 typedef typename Base::EntitySeed EntitySeed; 765 766 using Base::grid; 767 using Base::hostEntity; 768 Entity()769 Entity () : Base() {} 770 Entity(const Grid & g,const HostEntity & hostE)771 Entity ( const Grid &g, const HostEntity &hostE ) : Base( g, hostE ) {} Entity(const Grid & g,HostEntity && hostE)772 Entity ( const Grid &g, HostEntity&& hostE ) : Base( g, std::move( hostE ) ) {} Entity(const GeometryImpl & geo,const HostEntity & hostE)773 Entity ( const GeometryImpl &geo, const HostEntity& hostE ) : Base( geo, hostE ) {} Entity(const GeometryImpl & geo,HostEntity && hostE)774 Entity ( const GeometryImpl &geo, HostEntity &&hostE ) : Base( geo, std::move( hostE ) ) {} 775 Entity(const Grid & g,const EntitySeed & seed)776 Entity ( const Grid &g, const EntitySeed &seed ) : Base( g, seed ) {} 777 Entity(const Grid & g,const HostEntity & hostE,int i)778 Entity ( const Grid &g, const HostEntity &hostE, int i ) : Base( g, hostE ) 779 { 780 assert( i == 0 ); 781 } 782 783 template< int codim > 784 typename Grid::template Codim< codim >::Entity subEntity(int i) const785 subEntity ( int i ) const 786 { 787 typedef typename Traits::template Codim< codim >::EntityImpl EntityImpl; 788 return EntityImpl( grid(), hostEntity(), i ); 789 } 790 ilevelbegin() const791 LevelIntersectionIterator ilevelbegin () const 792 { 793 typedef GeoGrid::IntersectionIterator< Grid, typename HostGrid::LevelIntersectionIterator > LevelIntersectionIteratorImpl; 794 return LevelIntersectionIteratorImpl( *this, hostEntity().ilevelbegin() ); 795 } 796 ilevelend() const797 LevelIntersectionIterator ilevelend () const 798 { 799 typedef GeoGrid::IntersectionIterator< Grid, typename HostGrid::LevelIntersectionIterator > LevelIntersectionIteratorImpl; 800 return LevelIntersectionIteratorImpl( *this, hostEntity().ilevelend() ); 801 } 802 ileafbegin() const803 LeafIntersectionIterator ileafbegin () const 804 { 805 typedef GeoGrid::IntersectionIterator< Grid, typename HostGrid::LeafIntersectionIterator > LeafIntersectionIteratorImpl; 806 return LeafIntersectionIteratorImpl( *this, hostEntity().ileafbegin() ); 807 } 808 ileafend() const809 LeafIntersectionIterator ileafend () const 810 { 811 typedef GeoGrid::IntersectionIterator< Grid, typename HostGrid::LeafIntersectionIterator > LeafIntersectionIteratorImpl; 812 return LeafIntersectionIteratorImpl( *this, hostEntity().ileafend() ); 813 } 814 hasBoundaryIntersections() const815 bool hasBoundaryIntersections () const 816 { 817 return hostEntity().hasBoundaryIntersections(); 818 } 819 isLeaf() const820 bool isLeaf () const 821 { 822 return hostEntity().isLeaf(); 823 } 824 father() const825 EntityFacade father () const 826 { 827 return Entity( grid(), hostEntity().father() ); 828 } 829 hasFather() const830 bool hasFather () const 831 { 832 return hostEntity().hasFather(); 833 } 834 geometryInFather() const835 LocalGeometry geometryInFather () const 836 { 837 return hostEntity().geometryInFather(); 838 } 839 hbegin(int maxLevel) const840 HierarchicIterator hbegin ( int maxLevel ) const 841 { 842 typedef GeoGrid::HierarchicIterator< Grid > HierarchicIteratorImpl; 843 return HierarchicIteratorImpl( grid(), hostEntity().hbegin( maxLevel ) ); 844 } 845 hend(int maxLevel) const846 HierarchicIterator hend ( int maxLevel ) const 847 { 848 typedef GeoGrid::HierarchicIterator< Grid > HierarchicIteratorImpl; 849 return HierarchicIteratorImpl( grid(), hostEntity().hend( maxLevel ) ); 850 } 851 isRegular() const852 bool isRegular () const 853 { 854 return hostEntity().isRegular(); 855 } 856 isNew() const857 bool isNew () const 858 { 859 return hostEntity().isNew(); 860 } 861 mightVanish() const862 bool mightVanish () const 863 { 864 return hostEntity().mightVanish(); 865 } 866 }; 867 868 } // namespace GeoGrid 869 870 } // namespace Dune 871 872 #endif // #ifndef DUNE_GEOGRID_ENTITY_HH 873