3 #ifndef DUNE_GEOGRID_GRID_HH
4 #define DUNE_GEOGRID_GRID_HH
6 #include <dune/common/nullptr.hh>
7 #include <dune/common/static_assert.hh>
24 template<
class HostGr
id >
74 template<
class HostGr
id,
class CoordFunction = DefaultCoordFunction< HostGr
id >,
class Allocator = std::allocator<
void > >
78 < HostGrid::dimension, CoordFunction::dimRange, typename HostGrid::ctype,
79 GeoGrid::GridFamily< HostGrid, CoordFunction, Allocator > >,
87 < HostGrid::dimension, CoordFunction::dimRange,
typename HostGrid::ctype,
115 typedef typename GridFamily::Traits
Traits;
123 template<
int codim >
144 template< PartitionIteratorType pitype >
218 typedef typename Traits::ctype
ctype;
238 : hostGrid_( &hostGrid ),
239 coordFunction_( coordFunction ),
240 removeHostGrid_( false ),
241 levelIndexSets_( hostGrid_->
maxLevel()+1, nullptr, allocator ),
242 storageAllocator_( allocator )
254 GeometryGrid ( HostGrid *hostGrid, CoordFunction *coordFunction,
const Allocator &allocator = Allocator() )
255 : hostGrid_( hostGrid ),
256 coordFunction_( *coordFunction ),
257 removeHostGrid_( true ),
258 levelIndexSets_( hostGrid_->
maxLevel()+1, nullptr, allocator ),
259 storageAllocator_( allocator )
266 for(
unsigned int i = 0; i < levelIndexSets_.size(); ++i )
268 if( levelIndexSets_[ i ] )
269 delete( levelIndexSets_[ i ] );
272 if( removeHostGrid_ )
274 delete &coordFunction_;
304 int size (
int level,
int codim )
const
348 return hostGrid().numBoundarySegments( );
352 template<
int codim >
355 return levelView( level ).template begin< codim >();
358 template<
int codim >
361 return levelView( level ).template end< codim >();
364 template<
int codim, PartitionIteratorType pitype >
365 typename Codim< codim >::template Partition< pitype >::LevelIterator
368 return levelView( level ).template begin< codim, pitype >();
371 template<
int codim, PartitionIteratorType pitype >
372 typename Codim< codim >::template Partition< pitype >::LevelIterator
375 return levelView( level ).template end< codim, pitype >();
378 template<
int codim >
381 return leafView().template begin< codim >();
384 template<
int codim >
387 return leafView().template end< codim >();
390 template<
int codim, PartitionIteratorType pitype >
391 typename Codim< codim >::template Partition< pitype >::LeafIterator
394 return leafView().template begin< codim, pitype >();
397 template<
int codim, PartitionIteratorType pitype >
398 typename Codim< codim >::template Partition< pitype >::LeafIterator
401 return leafView().template end< codim, pitype >();
408 assert( globalIdSet_ );
416 assert( localIdSet_ );
422 assert( levelIndexSets_.size() == (size_t)(
maxLevel()+1) );
423 if( (level < 0) || (level >
maxLevel()) )
425 DUNE_THROW(
GridError,
"LevelIndexSet for nonexisting level " << level
432 assert( levelIndexSet );
440 assert( leafIndexSet_ );
441 return leafIndexSet_;
446 hostGrid().globalRefine( refCount );
452 return hostGrid().mark( refCount, getHostEntity< 0 >( entity ) );
457 return hostGrid().getMark( getHostEntity< 0 >( entity ) );
486 return leafView().overlapSize( codim );
495 return leafView().ghostSize( codim );
505 return levelView( level ).overlapSize( codim );
515 return levelView( level ).ghostSize( codim );
531 template<
class DataHandle,
class Data >
537 levelView( level ).communicate( dataHandle, interface, direction );
552 template<
class DataHandle,
class Data >
557 leafView().communicate( dataHandle, interface, direction );
587 const bool gridChanged=
hostGrid().loadBalance();
608 template<
class DataHandle,
class Data >
609 bool loadBalance ( CommDataHandleIF< DataHandle, Data > &datahandle )
611 typedef CommDataHandleIF< DataHandle, Data > DataHandleIF;
612 typedef GeoGrid :: CommDataHandle< Grid, DataHandleIF > WrappedDataHandle;
614 WrappedDataHandle wrappedDataHandle( *
this, datahandle );
615 const bool gridChanged =
hostGrid().loadBalance( wrappedDataHandle );
623 template<
class EntitySeed >
624 typename Traits::template Codim< EntitySeed::codimension >::EntityPointer
628 return EntityPointerImpl( *
this, seed );
637 template< PartitionIteratorType pitype >
641 typedef typename View::GridViewImp ViewImp;
645 template< PartitionIteratorType pitype >
648 return levelView<pitype>(level);
652 template< PartitionIteratorType pitype >
656 typedef typename View::GridViewImp ViewImp;
660 template< PartitionIteratorType pitype >
663 return leafGridView<pitype>();
669 typedef typename LevelGridView::GridViewImp ViewImp;
682 typedef typename LeafGridView::GridViewImp ViewImp;
719 const int newNumLevels =
maxLevel()+1;
720 const int oldNumLevels = levelIndexSets_.size();
722 for(
int i = newNumLevels; i < oldNumLevels; ++i )
724 if( levelIndexSets_[ i ] )
725 delete levelIndexSets_[ i ];
727 levelIndexSets_.resize( newNumLevels,
nullptr );
737 return coordFunction_;
740 template<
int codim >
741 static const typename HostGrid::template Codim< codim >::Entity &
744 return getRealImplementation( entity ).hostEntity();
749 return storageAllocator_.allocate( size );
754 storageAllocator_.deallocate( (
char *)p, size );
758 HostGrid *
const hostGrid_;
759 CoordFunction &coordFunction_;
760 bool removeHostGrid_;
761 mutable std::vector< LevelIndexSet *, typename Allocator::template rebind< LevelIndexSet * >::other > levelIndexSets_;
765 mutable typename Allocator::template rebind< char >::other storageAllocator_;
773 template<
class HostGr
id,
class CoordFunction,
class Allocator >
774 template<
int codim >
776 :
public Base::template
Codim< codim >
823 template< PartitionIteratorType pitype >
857 #endif // #ifndef DUNE_GEOGRID_GRID_HH