1 #ifndef DUNE_POLYGONGRID_GRID_HH 2 #define DUNE_POLYGONGRID_GRID_HH 3 4 #include <memory> 5 #include <utility> 6 7 #include <dune/geometry/dimension.hh> 8 9 #include <dune/grid/common/grid.hh> 10 11 #include <dune/polygongrid/capabilities.hh> 12 #include <dune/polygongrid/gridfamily.hh> 13 14 namespace Dune 15 { 16 17 // PolygonGrid 18 // ----------- 19 20 template< class ct > 21 class PolygonGrid 22 : public Dune::GridDefaultImplementation< 2, 2, ct, __PolygonGrid::GridFamily< ct > > 23 { 24 typedef PolygonGrid< ct > This; 25 typedef Dune::GridDefaultImplementation< 2, 2, ct, __PolygonGrid::GridFamily< ct > > Base; 26 27 friend class __PolygonGrid::IdSet< ct >; 28 friend class __PolygonGrid::IndexSet< ct >; 29 friend class __PolygonGrid::GridView< ct >; 30 31 public: 32 typedef __PolygonGrid::GridFamily< ct > GridFamily; 33 34 typedef typename GridFamily::Traits Traits; 35 36 static const int dimension = 2; 37 static const int dimensionworld = 2; 38 39 typedef typename Traits::MacroGridView MacroGridView; 40 41 typedef typename Base::LeafGridView LeafGridView; 42 typedef typename Base::LevelGridView LevelGridView; 43 44 typedef typename Base::GlobalIdSet GlobalIdSet; 45 typedef typename Base::LocalIdSet LocalIdSet; 46 47 typedef typename Base::LeafIndexSet LeafIndexSet; 48 typedef typename Base::LevelIndexSet LevelIndexSet; 49 50 typedef typename Base::CollectiveCommunication CollectiveCommunication; 51 52 typedef __PolygonGrid::Mesh< ct > Mesh; 53 typedef __PolygonGrid::MeshType MeshType; 54 PolygonGrid(std::shared_ptr<Mesh> mesh,__PolygonGrid::MeshType type)55 PolygonGrid ( std::shared_ptr< Mesh > mesh, __PolygonGrid::MeshType type ) 56 : mesh_( std::move( mesh ) ), type_( std::move( type ) ), 57 indexSet_( *mesh_, type_ ) 58 {} 59 PolygonGrid(const This & other)60 PolygonGrid ( const This &other ) 61 : mesh_( other.mesh_ ), type_( other.type_ ), 62 indexSet_( *mesh_, type_ ) 63 {} 64 PolygonGrid(This & other)65 PolygonGrid ( This &other ) 66 : mesh_( std::move( other.mesh_ ) ), type_( std::move( other.type_ ) ), 67 indexSet_( *mesh_, type_ ) 68 {} 69 maxLevel() const70 int maxLevel () const { return 0; } 71 numBoundarySegments() const72 std::size_t numBoundarySegments () const { return mesh().numBoundaries( type() ); } 73 macroGridView() const74 MacroGridView macroGridView () const { return __PolygonGrid::GridView< ct > ( *this ); } 75 levelGridView(int level) const76 LevelGridView levelGridView ( int level ) const { assert( level == 0 ); return macroGridView(); } leafGridView() const77 LeafGridView leafGridView () const { return macroGridView(); } 78 globalIdSet() const79 const GlobalIdSet &globalIdSet () const { return idSet_; } localIdSet() const80 const LocalIdSet &localIdSet () const { return idSet_; } 81 globalRefine(int refCount)82 bool globalRefine ( int refCount ) { return false; } 83 mark(int refCount,const typename Traits::template Codim<0>::Entity & entity) const84 bool mark ( int refCount, const typename Traits::template Codim< 0 >::Entity &entity ) const { return false; } getMark(const typename Traits::template Codim<0>::Entity & entity) const85 int getMark ( const typename Traits::template Codim< 0 >::Entity &entity ) const { return 0; } 86 preAdapt()87 bool preAdapt () { return false; } adapt()88 bool adapt () { return false; } postAdapt()89 void postAdapt () {} 90 comm() const91 const CollectiveCommunication &comm () const { return comm_; } 92 loadBalance()93 bool loadBalance () { return false; } 94 95 template< class DataHandle > loadBalance(DataHandle & data)96 bool loadBalance ( DataHandle &data ) 97 { 98 return false; 99 } 100 101 template< class Seed > entity(const Seed & seed) const102 typename Traits::template Codim< Seed::codimension >::Entity entity ( const Seed &seed ) const noexcept 103 { 104 typedef __PolygonGrid::Entity< Seed::codimension, 2, const This > EntityImpl; 105 typedef typename std::conditional< Seed::codimension == 1, __PolygonGrid::HalfEdge< ct >, __PolygonGrid::Node< ct > >::type Item; 106 return EntityImpl( Item( mesh_.get(), seed.impl().index() ) ); 107 } 108 109 // deprecated interface methods 110 size(int codim) const111 int size ( int codim ) const { return leafGridView().size( codim ); } size(GeometryType type) const112 int size ( GeometryType type ) const { return leafGridView().size( type ); } size(int level,int codim) const113 int size ( int level, int codim ) const { return levelGridView( level ).size( codim ); } size(int level,GeometryType type) const114 int size ( int level, GeometryType type ) const { return levelGridView( level ).size( type ); } 115 ghostSize(int) const116 int ghostSize( int ) const { return 0; } overlapSize(int) const117 int overlapSize( int ) const { return 0; } 118 leafIndexSet() const119 const LeafIndexSet &leafIndexSet () const { return indexSet_; } levelIndexSet(int level) const120 const LevelIndexSet &levelIndexSet ( int level ) const { assert( level == 0 ); return indexSet_; } 121 122 // non-interface methods 123 dualGrid() const124 This dualGrid () const { return This( mesh_, dual( type() ) ); } 125 mesh() const126 const Mesh &mesh () const { return *mesh_; } type() const127 MeshType type () const { return type_; } 128 129 private: 130 std::shared_ptr< Mesh > mesh_; 131 __PolygonGrid::MeshType type_; 132 CollectiveCommunication comm_; 133 LocalIdSet idSet_; 134 __PolygonGrid::IndexSet< ct > indexSet_; 135 }; 136 137 } // namespace Dune 138 139 #endif // #ifndef DUNE_POLYGONGRID_GRID_HH 140