1#ifndef DUNE_SPGRID_GRID_HH
2#define DUNE_SPGRID_GRID_HH
17#include <dune/grid/spgrid/direction.hh>
19#include <dune/grid/spgrid/gridview.hh>
20#include <dune/grid/spgrid/hierarchiciterator.hh>
21#include <dune/grid/spgrid/idset.hh>
22#include <dune/grid/spgrid/indexset.hh>
23#include <dune/grid/spgrid/hindexset.hh>
24#include <dune/grid/spgrid/fileio.hh>
32 template<
class Gr
id >
33 struct BackupRestoreFacility;
38 template<
class,
class >
49 template<
class ct,
int dim,
template<
int >
class Ref = SPIsotropicRefinement,
class Comm = MPI_Comm >
52 template<
class ct,
int dim,
template<
int >
class Ref = SPIsotropicRefinement,
class Comm = No_Comm >
61 template<
class ct,
int dim,
template<
int >
class Ref,
class Comm >
66 typedef SPGrid< ct, dim, Ref, Comm > Grid;
68 typedef SPReferenceCubeContainer< ct, dim > ReferenceCubeContainer;
69 typedef typename ReferenceCubeContainer::ReferenceCube ReferenceCube;
70 typedef SPDomain< ct, dim > Domain;
71 typedef SPMesh< dim > Mesh;
72 typedef Ref< dim > Refinement;
73 typedef typename Refinement::Policy RefinementPolicy;
75 typedef typename SPCommunicationTraits< Comm >::Communication Communication;
79 typedef LevelIntersection LeafIntersection;
82 typedef LevelIntersectionIterator LeafIntersectionIterator;
86 typedef SPIndexSet< const Grid > LevelIndexSet;
87 typedef LevelIndexSet LeafIndexSet;
89 typedef SPGlobalIdSet< const Grid > GlobalIdSet;
90 typedef SPLocalIdSet< const Grid > LocalIdSet;
91 typedef unsigned long GlobalIdType;
92 typedef unsigned long LocalIdType;
97 typedef typename ReferenceCubeContainer::template Codim< codim >::ReferenceCube ReferenceCube;
103 typedef SPLocalGeometry< dim - codim, dim,
const Grid > LocalGeometryImpl;
105 typedef Dune::Geometry< dim - codim, dim,
const Grid, SPGeometry > Geometry;
106 typedef Dune::Geometry< dim - codim, dim,
const Grid, LocalGeometryReference > LocalGeometry;
108 template< PartitionIteratorType pitype >
115 typedef typename Partition< All_Partition >::LevelIterator LevelIterator;
116 typedef typename Partition< All_Partition >::LeafIterator LeafIterator;
134 template<
class ct,
int dim,
template<
int >
class Ref,
class Comm >
143 friend class SPGridLevel<
This >;
145 template<
class,
class >
friend class __SPGrid::TreeIterator;
148 typedef SPGridFamily< ct, dim, Ref, Comm > GridFamily;
150 typedef typename GridFamily::Traits Traits;
152 typedef typename Traits::ReferenceCubeContainer ReferenceCubeContainer;
153 typedef typename Traits::ReferenceCube ReferenceCube;
155 typedef typename Traits::Mesh Mesh;
156 typedef typename Traits::Refinement Refinement;
157 typedef typename Traits::RefinementPolicy RefinementPolicy;
159 typedef typename ReferenceCube::ctype ctype;
161 static const int dimension = ReferenceCube::dimension;
162 static const int dimensionworld = ReferenceCube::dimension;
166 typedef typename Traits::GlobalIdSet GlobalIdSet;
167 typedef typename Traits::LocalIdSet LocalIdSet;
172 template<
int codim >
174 : Base::template Codim< codim >
176 typedef typename Traits::template Codim< codim >::ReferenceCube ReferenceCube;
178 typedef typename Traits::template Codim< codim >::LocalGeometryImpl LocalGeometryImpl;
184 typedef typename LevelGridView::IndexSet LevelIndexSet;
185 typedef typename LeafGridView::IndexSet LeafIndexSet;
187 typedef SPHierarchyIndexSet< const This > HierarchicIndexSet;
189 typedef SPGridLevel< This > GridLevel;
192 static const int numDirections = GridLevel::numDirections;
195 typedef typename GridLevel::PartitionList PartitionList;
197 typedef typename LevelGridView::Traits::GridViewImp LevelGridViewImpl;
198 typedef typename LeafGridView::Traits::GridViewImp LeafGridViewImpl;
202 const Communication &comm = SPCommunicationTraits< Comm >::defaultComm() );
205 const Communication &comm = SPCommunicationTraits< Comm >::defaultComm() );
208 const Communication &comm = SPCommunicationTraits< Comm >::defaultComm() );
212 const Communication &comm = SPCommunicationTraits< Comm >::defaultComm() );
217 const ReferenceCube &referenceCube ()
const
219 return refCubes_.get();
222 template<
int codim >
223 const typename Codim< codim >::ReferenceCube &referenceCube ()
const
225 return refCubes_.template get< codim >();
228 const Domain &domain ()
const {
return domain_; }
230 const MultiIndex &overlap ()
const {
return overlap_; }
232 int maxLevel ()
const
234 return leafLevel().level();
237 int size (
const int level,
const int codim )
const
239 return levelGridView( level ).size( codim );
242 int size (
const int codim )
const
244 return leafGridView().size( codim );
247 int size (
const int level,
const GeometryType &type )
const
249 return levelGridView( level ).size( type );
254 return leafGridView().size( type );
257 LevelGridView levelGridView (
int level )
const
259 assert( (level >= 0) && (level <= maxLevel()) );
260 return levelGridViews_[ level ];
263 LeafGridView leafGridView ()
const {
return leafGridView_; }
265 template<
int codim, PartitionIteratorType pitype >
266 typename Traits::template Codim< codim >::template Partition< pitype >::LevelIterator
267 lbegin (
const int level,
const unsigned int sweepDir = 0 )
const
269 const LevelGridView &view = levelGridView( level );
270 return view.impl().template begin< codim, pitype >( sweepDir );
273 template<
int codim, PartitionIteratorType pitype >
274 typename Traits::template Codim< codim >::template Partition< pitype >::LevelIterator
275 lend (
const int level,
const unsigned int sweepDir = 0 )
const
277 const LevelGridView &view = levelGridView( level );
278 return view.impl().template end< codim, pitype >( sweepDir );
281 template<
int codim >
282 typename Traits::template Codim< codim >::LevelIterator
283 lbegin (
const int level,
const unsigned int sweepDir = 0 )
const
285 const LevelGridView &view = levelGridView( level );
286 return view.impl().template begin< codim >( sweepDir );
289 template<
int codim >
290 typename Traits::template Codim< codim >::LevelIterator
291 lend (
const int level,
const unsigned int sweepDir = 0 )
const
293 const LevelGridView &view = levelGridView( level );
294 return view.impl().template end< codim >( sweepDir );
297 template<
int codim, PartitionIteratorType pitype >
298 typename Traits::template Codim< codim >::template Partition< pitype >::LeafIterator
299 leafbegin (
const unsigned int sweepDir = 0 )
const
301 const LeafGridView &view = leafGridView();
302 return view.impl().template begin< codim, pitype >( sweepDir );
305 template<
int codim, PartitionIteratorType pitype >
306 typename Traits::template Codim< codim >::template Partition< pitype >::LeafIterator
307 leafend (
const unsigned int sweepDir = 0 )
const
309 const LeafGridView &view = leafGridView();
310 return view.impl().template end< codim, pitype >( sweepDir );
313 template<
int codim >
314 typename Traits::template Codim< codim >::LeafIterator
315 leafbegin (
const unsigned int sweepDir = 0 )
const
317 const LeafGridView &view = leafGridView();
318 return view.impl().template begin< codim >( sweepDir );
321 template<
int codim >
322 typename Traits::template Codim< codim >::LeafIterator
323 leafend (
const unsigned int sweepDir = 0 )
const
325 const LeafGridView &view = leafGridView();
326 return view.impl().template end< codim >( sweepDir );
329 const GlobalIdSet &globalIdSet ()
const
334 const LocalIdSet &localIdSet ()
const
339 const LevelIndexSet &levelIndexSet (
const int level )
const
341 return levelGridView( level ).indexSet();
344 const LeafIndexSet &leafIndexSet ()
const
346 return leafGridView().indexSet();
349 const HierarchicIndexSet &hierarchicIndexSet ()
const
351 return hierarchicIndexSet_;
354 bool mark (
const int refCount,
const typename Codim< 0 >::Entity &e );
355 int getMark (
const typename Codim< 0 >::Entity &e )
const;
361 template<
class DataHandle >
366 void globalRefine (
const int refCount,
367 const RefinementPolicy &policy = RefinementPolicy() );
369 template<
class DataHandle >
370 void globalRefine (
const int refCount,
372 const RefinementPolicy &policy = RefinementPolicy() );
374 int overlapSize (
const int level,
const int codim )
const
376 return levelGridView( level ).overlapSize( codim );
379 int overlapSize (
const int codim )
const
381 return leafGridView().overlapSize( codim );
384 int ghostSize (
const int level,
const int codim )
const
386 return levelGridView( level ).ghostSize( codim );
389 int ghostSize (
const int codim )
const
391 return leafGridView().ghostSize( codim );
394 template<
class DataHandle,
class Data >
395 SPCommunication< This, CommDataHandleIF< DataHandle, Data > >
400 LevelGridView view = levelGridView( level );
401 return view.impl().communicate( data, interface, dir );
404 template<
class DataHandle,
class Data >
405 SPCommunication< This, CommDataHandleIF< DataHandle, Data > >
409 LeafGridView view = leafGridView();
410 return view.impl().communicate( data, interface, dir );
415 template<
class Seed >
416 typename Traits::template Codim< Seed::codimension >::Entity entity (
const Seed &seed )
const
418 typedef typename Traits::template Codim< Seed::codimension >::Entity
Entity;
419 typedef SPEntity< Seed::codimension, dimension, const This > EntityImpl;
420 typename EntityImpl::EntityInfo entityInfo( gridLevel( seed.impl().level() ), seed.impl().id(), seed.impl().partitionNumber() );
421 return Entity( EntityImpl( std::move( entityInfo ) ) );
424 template<
int codim >
427 return ((entity.
level() > 0) && entity.
impl().entityInfo().hasFather());
432 return ((intersection.impl().gridLevel().level() > 0) && intersection.impl().entityInfo().hasFather());
435 template<
int codim >
439 assert( hasFather( entity ) );
441 father.
impl().entityInfo().up();
442 return std::move( father );
451 assert( hasFather( intersection ) );
452 typename IntersectionImpl::EntityInfo fatherInfo( intersection.impl().entityInfo() );
454 return Intersection( IntersectionImpl( std::move( fatherInfo ), intersection.indexInInside() ) );
457 const GridLevel &gridLevel (
const int level )
const;
458 const GridLevel &leafLevel ()
const;
460 std::size_t numBoundarySegments ()
const;
464 std::size_t boundaryIndex (
const MultiIndex ¯oId,
465 const unsigned int partitionNumber,
466 const int face )
const;
468 typename Codim< 1 >::LocalGeometry localFaceGeometry (
int face )
const
470 assert( (face >= 0) && (face < ReferenceCube::numFaces) );
471 return typename Codim< 1 >::LocalGeometry( *localFaceGeometry_[ face ] );
474 void createLocalGeometries ();
475 void setupMacroGrid ();
476 void setupBoundaryIndices ();
483 ReferenceCubeContainer refCubes_;
484 std::vector< std::unique_ptr< GridLevel > > gridLevels_;
485 std::vector< LevelGridView > levelGridViews_;
486 LeafGridView leafGridView_;
487 HierarchicIndexSet hierarchicIndexSet_;
488 GlobalIdSet globalIdSet_;
489 LocalIdSet localIdSet_;
491 std::size_t boundarySize_;
492 std::vector< std::array< std::size_t, 2*dimension > > boundaryOffset_;
493 std::array< std::unique_ptr< const typename Codim< 1 >::LocalGeometryImpl >, ReferenceCube::numFaces > localFaceGeometry_;
501 template<
class ct,
int dim,
template<
int >
class Ref,
class Comm >
503 ::SPGrid (
const Domain &domain,
const MultiIndex &cells,
506 globalMesh_( cells ),
507 overlap_( MultiIndex::zero() ),
508 leafGridView_( LeafGridViewImpl() ),
509 hierarchicIndexSet_( *this ),
512 createLocalGeometries();
517 template<
class ct,
int dim,
template<
int >
class Ref,
class Comm >
518 inline SPGrid< ct, dim, Ref, Comm >
519 ::SPGrid (
const Domain &domain,
const MultiIndex &cells,
const MultiIndex &overlap,
520 const Communication &comm )
522 globalMesh_( cells ),
524 leafGridView_( LeafGridViewImpl() ),
525 hierarchicIndexSet_( *this ),
528 createLocalGeometries();
533 template<
class ct,
int dim,
template<
int >
class Ref,
class Comm >
534 inline SPGrid< ct, dim, Ref, Comm >
535 ::SPGrid (
const GlobalVector &a,
const GlobalVector &b,
const MultiIndex &cells,
536 const Communication &comm )
538 globalMesh_( cells ),
539 overlap_( MultiIndex::zero() ),
540 leafGridView_( LeafGridViewImpl() ),
541 hierarchicIndexSet_( *this ),
544 createLocalGeometries();
549 template<
class ct,
int dim,
template<
int >
class Ref,
class Comm >
550 inline SPGrid< ct, dim, Ref, Comm >
551 ::SPGrid (
const GlobalVector &a,
const GlobalVector &b,
const MultiIndex &cells,
552 const MultiIndex &overlap,
const Communication &comm )
554 globalMesh_( cells ),
556 leafGridView_( LeafGridViewImpl() ),
557 hierarchicIndexSet_( *this ),
560 createLocalGeometries();
565 template<
class ct,
int dim,
template<
int >
class Ref,
class Comm >
566 inline SPGrid< ct, dim, Ref, Comm >::SPGrid ( This &&other )
567 : domain_(
std::move( other.domain_ ) ),
568 globalMesh_(
std::move( other.globalMesh_ ) ),
569 overlap_(
std::move( other.overlap_ ) ),
570 leafGridView_( LeafGridViewImpl() ),
571 hierarchicIndexSet_( *this ),
572 comm_(
std::move( other.comm_ ) )
574 createLocalGeometries();
579 template<
class ct,
int dim,
template<
int >
class Ref,
class Comm >
580 inline bool SPGrid< ct, dim, Ref, Comm >
581 ::mark (
const int refCount,
const typename Codim< 0 >::Entity &e )
587 template<
class ct,
int dim,
template<
int >
class Ref,
class Comm >
588 inline int SPGrid< ct, dim, Ref, Comm >
589 ::getMark (
const typename Codim< 0 >::Entity &e )
const
595 template<
class ct,
int dim,
template<
int >
class Ref,
class Comm >
596 inline bool SPGrid< ct, dim, Ref, Comm >::preAdapt ()
602 template<
class ct,
int dim,
template<
int >
class Ref,
class Comm >
603 inline bool SPGrid< ct, dim, Ref, Comm >::adapt ()
609 template<
class ct,
int dim,
template<
int >
class Ref,
class Comm >
610 template<
class DataHandle >
611 inline bool SPGrid< ct, dim, Ref, Comm >
612 ::adapt ( AdaptDataHandleInterface< This, DataHandle > &handle )
618 template<
class ct,
int dim,
template<
int >
class Ref,
class Comm >
619 inline void SPGrid< ct, dim, Ref, Comm >::postAdapt ()
623 template<
class ct,
int dim,
template<
int >
class Ref,
class Comm >
624 inline void SPGrid< ct, dim, Ref, Comm >
625 ::globalRefine (
const int refCount,
const RefinementPolicy &policy )
627 for(
int i = 0; i < refCount; ++i )
629 gridLevels_.emplace_back(
new GridLevel( leafLevel(), policy ) );
630 levelGridViews_.push_back( LevelGridViewImpl( leafLevel() ) );
632 leafGridView_.impl().update( leafLevel() );
633 hierarchicIndexSet_.update();
637 template<
class ct,
int dim,
template<
int >
class Ref,
class Comm >
638 template<
class DataHandle >
639 inline void SPGrid< ct, dim, Ref, Comm >
640 ::globalRefine (
const int refCount,
641 AdaptDataHandleInterface< This, DataHandle > &handle,
642 const RefinementPolicy &policy )
644 for(
int i = 0; i < refCount; ++i )
646 const LevelGridView fatherView =
levelGridView( maxLevel() );
648 gridLevels_.emplace_back(
new GridLevel( leafLevel(), policy ) );
649 levelGridViews_.push_back( LevelGridViewImpl( leafLevel() ) );
651 hierarchicIndexSet_.update();
652 leafGridView_.impl().update( leafLevel() );
654 handle.preAdapt( leafLevel().size() );
655 typedef typename Codim< 0 >::LevelIterator LevelIterator;
656 const LevelIterator end = fatherView.template end< 0 >();
657 for( LevelIterator it = fatherView.template begin< 0 >(); it != end; ++it )
658 handle.postRefinement( *it );
664 template<
class ct,
int dim,
template<
int >
class Ref,
class Comm >
665 inline const typename SPGrid< ct, dim, Ref, Comm >::Communication &
666 SPGrid< ct, dim, Ref, Comm >::comm ()
const
672 template<
class ct,
int dim,
template<
int >
class Ref,
class Comm >
673 inline const typename SPGrid< ct, dim, Ref, Comm >::GridLevel &
674 SPGrid< ct, dim, Ref, Comm >::gridLevel (
const int level )
const
676 assert( (level >= 0) && (level <
int( gridLevels_.size() )) );
677 return *gridLevels_[ level ];
681 template<
class ct,
int dim,
template<
int >
class Ref,
class Comm >
682 inline const typename SPGrid< ct, dim, Ref, Comm >::GridLevel &
683 SPGrid< ct, dim, Ref, Comm >::leafLevel ()
const
685 assert( !gridLevels_.empty() );
686 return *gridLevels_.back();
690 template<
class ct,
int dim,
template<
int >
class Ref,
class Comm >
691 inline std::size_t SPGrid< ct, dim, Ref, Comm >::numBoundarySegments ()
const
693 return boundarySize_;
698 template<
class ct,
int dim,
template<
int >
class Ref,
class Comm >
699 inline std::size_t SPGrid< ct, dim, Ref, Comm >
700 ::boundaryIndex (
const MultiIndex ¯oId,
701 const unsigned int partitionNumber,
702 const int face )
const
704 assert( (face >= 0) && (face < 2*dimension) );
707 const GridLevel &gridLevel = macroView.impl().gridLevel();
708 const PartitionList &partitions = gridLevel.template partition< OverlapFront_Partition >();
709 const typename PartitionList::Partition &partition = partitions.partition( partitionNumber );
711 std::size_t index = 0;
712 std::size_t factor = 1;
713 for(
int i = 0; i < dimension; ++i )
719 const int k = (macroId[ i ] - partition.begin()[ i ]) >> 1;
720 const int w = (partition.end()[ i ] - partition.begin()[ i ]) >> 1;
721 assert( (k >= 0) && (k < w) );
722 index += std::size_t( k ) * factor;
723 factor *= std::size_t( w );
725 return index + boundaryOffset_[ partitionNumber - partitions.minNumber() ][ face ];
729 template<
class ct,
int dim,
template<
int >
class Ref,
class Comm >
730 inline void SPGrid< ct, dim, Ref, Comm >::createLocalGeometries ()
732 typedef typename Codim< 1 >::LocalGeometryImpl LocalGeometryImpl;
734 const GlobalVector unitH( ctype( 1 ) );
735 for(
int face = 0; face < ReferenceCube::numFaces; ++face )
738 for(
int i = 0; i < dimension; ++i )
740 id += referenceCube().subId( 1, face );
741 const SPDirection< dimension > direction(
id );
743 GlobalVector origin( ctype( 0 ) );
744 origin[ face/2 ] = ctype( face & 1 );
745 const SPGeometryCache< ctype, dimension, 1 > cache( unitH, direction );
746 localFaceGeometry_[ face ].reset(
new LocalGeometryImpl( cache, origin ) );
751 template<
class ct,
int dim,
template<
int >
class Ref,
class Comm >
752 inline void SPGrid< ct, dim, Ref, Comm >::setupMacroGrid ()
754 SPDecomposition< dimension > decomposition( globalMesh_, comm().size() );
756 GridLevel *leafLevel =
new GridLevel( *
this, decomposition );
757 gridLevels_.emplace_back( leafLevel );
758 levelGridViews_.push_back( LevelGridViewImpl( *leafLevel ) );
759 leafGridView_.impl().update( *leafLevel );
760 hierarchicIndexSet_.update();
761 setupBoundaryIndices();
765 template<
class ct,
int dim,
template<
int >
class Ref,
class Comm >
766 inline void SPGrid< ct, dim, Ref, Comm >::setupBoundaryIndices ()
769 const GridLevel &gridLevel = macroView.impl().gridLevel();
770 const PartitionList &partitions = gridLevel.template partition< OverlapFront_Partition >();
773 boundaryOffset_.resize( partitions.maxNumber() - partitions.minNumber() + 1 );
774 for(
typename PartitionList::Iterator it = partitions.begin(); it; ++it )
776 const int partitionIndex = it->number() - partitions.minNumber();
777 for(
int i = 0; i < dimension; ++i )
781 std::size_t size = 1;
782 for(
int j = 0; j < dimension; ++j )
783 size *= (i == j ? 1 : std::size_t( (it->end()[ j ] - it->begin()[ j ]) >> 1 ));
786 boundaryOffset_[ partitionIndex ][ 2*i ] = boundarySize_;
787 boundarySize_ += (it->boundary( 2*i ) ? size : 0);
790 boundaryOffset_[ partitionIndex ][ 2*i+1 ] = boundarySize_;
791 boundarySize_ += (it->boundary( 2*i+1 ) ? size : 0);
interfaces and wrappers needed for the callback adaptation provided by AlbertaGrid and dune-ALUGrid
Interface class for the Grid's adapt method where the parameter is a AdaptDataHandleInterface.
Definition: adaptcallback.hh:33
CommDataHandleIF describes the features of a data handle for communication in parallel runs using the...
Definition: datahandleif.hh:78
Collective communication interface and sequential default implementation.
Definition: communication.hh:100
interface class for an iterator over grid entities
Definition: entityiterator.hh:32
Store a reference to an entity with a minimal memory footprint.
Definition: entityseed.hh:26
int level() const
The level of this entity.
Definition: entity.hh:124
Implementation & impl()
access to the underlying implementation
Definition: entity.hh:80
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:125
Wrapper class for geometries.
Definition: geometry.hh:71
Grid view abstract base class.
Definition: gridview.hh:66
GridFamily::Traits::LevelGridView LevelGridView
type of view for level grid
Definition: grid.hh:402
GridFamily::Traits::LeafGridView LeafGridView
type of view for leaf grid
Definition: grid.hh:400
Mesh entities of codimension 0 ("elements") allow to visit all intersections with "neighboring" eleme...
Definition: intersectioniterator.hh:83
Intersection of a mesh entity of codimension 0 ("element") with a "neighboring" element or with the d...
Definition: intersection.hh:164
description of the computational domain
Definition: domain.hh:27
structured, parallel DUNE grid
Definition: grid.hh:137
Different resources needed by all grid implementations.
Wrapper and interface classes for element geometries.
Grid< dim, dimworld, ct, GridFamily >::LevelGridView levelGridView(const Grid< dim, dimworld, ct, GridFamily > &grid, int level)
level grid view for the given grid and level.
Definition: grid.hh:802
Implements an utility class that provides MPI's collective communication methods.
Dune namespace.
Definition: alignedallocator.hh:13
Communication< T > CollectiveCommunication
Definition: communication.hh:541
facility for writing and reading grids
Definition: backuprestore.hh:43