1 #ifndef DUNE_GEOGRID_GRID_HH
2 #define DUNE_GEOGRID_GRID_HH
4 #include <dune/common/nullptr.hh>
5 #include <dune/common/static_assert.hh>
22 template<
class HostGr
id >
72 template<
class HostGr
id,
class CoordFunction = DefaultCoordFunction< HostGr
id >,
class Allocator = std::allocator<
void > >
76 < HostGrid::dimension, CoordFunction::dimRange, typename HostGrid::ctype,
77 GeoGrid::GridFamily< HostGrid, CoordFunction, Allocator > >,
85 < HostGrid::dimension, CoordFunction::dimRange,
typename HostGrid::ctype,
117 typedef typename GridFamily::Traits
Traits;
125 template<
int codim >
200 typedef typename Traits::ctype
ctype;
220 : hostGrid_( &hostGrid ),
221 coordFunction_( coordFunction ),
222 removeHostGrid_( false ),
223 levelIndexSets_( hostGrid_->
maxLevel()+1, nullptr, allocator ),
224 storageAllocator_( allocator )
236 GeometryGrid ( HostGrid *hostGrid, CoordFunction *coordFunction,
const Allocator &allocator = Allocator() )
237 : hostGrid_( hostGrid ),
238 coordFunction_( *coordFunction ),
239 removeHostGrid_( true ),
240 levelIndexSets_( hostGrid_->
maxLevel()+1, nullptr, allocator ),
241 storageAllocator_( allocator )
248 for(
unsigned int i = 0; i < levelIndexSets_.size(); ++i )
250 if( levelIndexSets_[ i ] )
251 delete( levelIndexSets_[ i ] );
254 if( removeHostGrid_ )
256 delete &coordFunction_;
286 int size (
int level,
int codim )
const
288 return hostGrid().size( level, codim );
312 return hostGrid().size( level, type );
330 return hostGrid().numBoundarySegments( );
334 template<
int codim >
337 return lbegin< codim, All_Partition >( level );
340 template<
int codim >
343 return lend< codim, All_Partition >( level );
346 template<
int codim, PartitionIteratorType pitype >
347 typename Codim< codim >::template Partition< pitype >::LevelIterator
354 template<
int codim, PartitionIteratorType pitype >
355 typename Codim< codim >::template Partition< pitype >::LevelIterator
362 template<
int codim >
365 return leafbegin< codim, All_Partition >();
368 template<
int codim >
371 return leafend< codim, All_Partition >();
374 template<
int codim, PartitionIteratorType pitype >
375 typename Codim< codim >::template Partition< pitype >::LeafIterator
382 template<
int codim, PartitionIteratorType pitype >
383 typename Codim< codim >::template Partition< pitype >::LeafIterator
394 assert( globalIdSet_ );
402 assert( localIdSet_ );
408 assert( levelIndexSets_.size() == (size_t)(
maxLevel()+1) );
409 if( (level < 0) || (level >
maxLevel()) )
411 DUNE_THROW(
GridError,
"LevelIndexSet for nonexisting level " << level
418 assert( levelIndexSet );
426 assert( leafIndexSet_ );
427 return leafIndexSet_;
432 hostGrid().globalRefine( refCount );
438 return hostGrid().mark( refCount, getHostEntity< 0 >( entity ) );
443 return hostGrid().getMark( getHostEntity< 0 >( entity ) );
472 return hostGrid().overlapSize( codim );
481 return hostGrid().ghostSize( codim );
491 return hostGrid().overlapSize( level, codim );
501 return hostGrid().ghostSize( level, codim );
517 template<
class DataHandle,
class Data >
526 WrappedDataHandle wrappedDataHandle( *
this, datahandle );
527 hostGrid().communicate( wrappedDataHandle, interface, direction, level );
542 template<
class DataHandle,
class Data >
550 WrappedDataHandle wrappedDataHandle( *
this, datahandle );
551 hostGrid().communicate( wrappedDataHandle, interface, direction );
581 const bool gridChanged=
hostGrid().loadBalance();
602 template<
class DataHandle,
class Data >
603 bool loadBalance ( CommDataHandleIF< DataHandle, Data > &datahandle )
605 typedef CommDataHandleIF< DataHandle, Data > DataHandleIF;
606 typedef GeoGrid :: CommDataHandle< Grid, DataHandleIF > WrappedDataHandle;
608 WrappedDataHandle wrappedDataHandle( *
this, datahandle );
609 const bool gridChanged =
hostGrid().loadBalance( wrappedDataHandle );
617 template<
class EntitySeed >
618 typename Traits::template Codim< EntitySeed::codimension >::EntityPointer
622 return EntityPointerImpl( *
this, seed );
653 const int newNumLevels =
maxLevel()+1;
654 const int oldNumLevels = levelIndexSets_.size();
656 for(
int i = newNumLevels; i < oldNumLevels; ++i )
658 if( levelIndexSets_[ i ] )
659 delete levelIndexSets_[ i ];
661 levelIndexSets_.resize( newNumLevels,
nullptr );
671 return coordFunction_;
674 template<
int codim >
675 static const typename HostGrid::template Codim< codim >::Entity &
678 return getRealImplementation( entity ).hostEntity();
681 template<
int codim >
684 assert( gt.dim() == Traits::dimension - codim );
687 return storageAllocator_.allocate( MappingProvider::mappingSize( gt.id() ) );
690 template<
int codim >
693 assert( gt.dim() == Traits::dimension - codim );
696 storageAllocator_.deallocate( p, MappingProvider::mappingSize( gt.id() ) );
700 HostGrid *
const hostGrid_;
701 CoordFunction &coordFunction_;
702 bool removeHostGrid_;
703 mutable std::vector< LevelIndexSet *, typename Allocator::template rebind< LevelIndexSet * >::other > levelIndexSets_;
707 mutable typename Allocator::template rebind< char >::other storageAllocator_;
715 template<
class HostGr
id,
class CoordFunction,
class Allocator >
716 template<
int codim >
717 struct GeometryGrid< HostGrid, CoordFunction, Allocator >::Codim
718 :
public Base::template Codim< codim >
765 template< PartitionIteratorType pitype >
799 #endif // #ifndef DUNE_GEOGRID_GRID_HH