Dune Core Modules (2.4.2)

grid.hh
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_GRID_HH
4#define DUNE_GEOGRID_GRID_HH
5
8
10
11#include <dune/grid/geometrygrid/backuprestore.hh>
12#include <dune/grid/geometrygrid/capabilities.hh>
13#include <dune/grid/geometrygrid/datahandle.hh>
14#include <dune/grid/geometrygrid/gridfamily.hh>
15#include <dune/grid/geometrygrid/identity.hh>
16#include <dune/grid/geometrygrid/persistentcontainer.hh>
17
18namespace Dune
19{
20
21 // DefaultCoordFunction
22 // --------------------
23
24 template< class HostGrid >
25 class DefaultCoordFunction
26 : public IdenticalCoordFunction< typename HostGrid::ctype, HostGrid::dimensionworld >
27 {};
28
29
30
31 // GeometryGrid
32 // ------------
33
74 template< class HostGrid, class CoordFunction = DefaultCoordFunction< HostGrid >, class Allocator = std::allocator< void > >
78 < HostGrid::dimension, CoordFunction::dimRange, typename HostGrid::ctype,
79 GeoGrid::GridFamily< HostGrid, CoordFunction, Allocator > >,
80 public GeoGrid::ExportParams< HostGrid, CoordFunction >,
81 public GeoGrid::BackupRestoreFacilities< GeometryGrid< HostGrid, CoordFunction, Allocator > >
83 {
85
87 < HostGrid::dimension, CoordFunction::dimRange, typename HostGrid::ctype,
88 GeoGrid::GridFamily< HostGrid, CoordFunction, Allocator > >
89 Base;
90
91 friend class GeoGrid::HierarchicIterator< const Grid >;
92
93 template< int, class, bool > friend class GeoGrid::EntityBase;
94 template< int, int, class > friend class GeoGrid::Geometry;
95 template< class, class, class, PartitionIteratorType > friend class GeoGrid::GridView;
96 template< class, class > friend class GeoGrid::Intersection;
97 template< class, class > friend class GeoGrid::IntersectionIterator;
98 template< class, class > friend class GeoGrid::IdSet;
99 template< class, class > friend class GeoGrid::IndexSet;
100 template< class > friend struct HostGridAccess;
101
102 template< class, class > friend class GeoGrid::CommDataHandle;
103
104 public:
106 typedef GeoGrid::GridFamily< HostGrid, CoordFunction, Allocator > GridFamily;
113 typedef typename GridFamily::Traits Traits;
114
121 template< int codim >
122 struct Codim;
123
130 typedef typename Traits::HierarchicIterator HierarchicIterator;
132 typedef typename Traits::LeafIntersectionIterator LeafIntersectionIterator;
134 typedef typename Traits::LevelIntersectionIterator LevelIntersectionIterator;
135
142 template< PartitionIteratorType pitype >
144 {
145 typedef typename GridFamily::Traits::template Partition< pitype >::LevelGridView
146 LevelGridView;
147 typedef typename GridFamily::Traits::template Partition< pitype >::LeafGridView
148 LeafGridView;
149 };
150
152 typedef typename Partition< All_Partition >::LevelGridView LevelGridView;
153 typedef typename Partition< All_Partition >::LeafGridView LeafGridView;
154
169 typedef typename Traits::LeafIndexSet LeafIndexSet;
170
179 typedef typename Traits::LevelIndexSet LevelIndexSet;
180
191 typedef typename Traits::GlobalIdSet GlobalIdSet;
192
208 typedef typename Traits::LocalIdSet LocalIdSet;
209
216 typedef typename Traits::ctype ctype;
217
219 typedef typename Traits::CollectiveCommunication CollectiveCommunication;
220
235 GeometryGrid ( HostGrid &hostGrid, CoordFunction &coordFunction, const Allocator &allocator = Allocator() )
236 : hostGrid_( &hostGrid ),
237 coordFunction_( coordFunction ),
238 removeHostGrid_( false ),
239 levelIndexSets_( hostGrid_->maxLevel()+1, nullptr, allocator ),
240 storageAllocator_( allocator )
241 {}
242
252 GeometryGrid ( HostGrid *hostGrid, CoordFunction *coordFunction, const Allocator &allocator = Allocator() )
253 : hostGrid_( hostGrid ),
254 coordFunction_( *coordFunction ),
255 removeHostGrid_( true ),
256 levelIndexSets_( hostGrid_->maxLevel()+1, nullptr, allocator ),
257 storageAllocator_( allocator )
258 {}
259
263 {
264 for( unsigned int i = 0; i < levelIndexSets_.size(); ++i )
265 {
266 if( levelIndexSets_[ i ] )
267 delete( levelIndexSets_[ i ] );
268 }
269
270 if( removeHostGrid_ )
271 {
272 delete &coordFunction_;
273 delete hostGrid_;
274 }
275 }
276
289 int maxLevel () const
290 {
291 return hostGrid().maxLevel();
292 }
293
302 int size ( int level, int codim ) const
303 {
304 return levelGridView( level ).size( codim );
305 }
306
313 int size ( int codim ) const
314 {
315 return leafGridView().size( codim );
316 }
317
326 int size ( int level, GeometryType type ) const
327 {
328 return levelGridView( level ).size( type );
329 }
330
335 int size ( GeometryType type ) const
336 {
337 return leafGridView().size( type );
338 }
339
344 size_t numBoundarySegments () const
345 {
346 return hostGrid().numBoundarySegments( );
347 }
350 const GlobalIdSet &globalIdSet () const
351 {
352 if( !globalIdSet_ )
353 globalIdSet_ = GlobalIdSet( hostGrid().globalIdSet() );
354 assert( globalIdSet_ );
355 return globalIdSet_;
356 }
357
358 const LocalIdSet &localIdSet () const
359 {
360 if( !localIdSet_ )
361 localIdSet_ = LocalIdSet( hostGrid().localIdSet() );
362 assert( localIdSet_ );
363 return localIdSet_;
364 }
365
366 const LevelIndexSet &levelIndexSet ( int level ) const
367 {
368 assert( levelIndexSets_.size() == (size_t)(maxLevel()+1) );
369 if( (level < 0) || (level > maxLevel()) )
370 {
371 DUNE_THROW( GridError, "LevelIndexSet for nonexisting level " << level
372 << " requested." );
373 }
374
375 LevelIndexSet *&levelIndexSet = levelIndexSets_[ level ];
376 if( !levelIndexSet )
377 levelIndexSet = new LevelIndexSet( hostGrid().levelIndexSet( level ) );
378 assert( levelIndexSet );
379 return *levelIndexSet;
380 }
381
382 const LeafIndexSet &leafIndexSet () const
383 {
384 if( !leafIndexSet_ )
385 leafIndexSet_ = LeafIndexSet( hostGrid().leafIndexSet() );
386 assert( leafIndexSet_ );
387 return leafIndexSet_;
388 }
389
390 void globalRefine ( int refCount )
391 {
392 hostGrid().globalRefine( refCount );
393 update();
394 }
395
396 bool mark ( int refCount, const typename Codim< 0 >::Entity &entity )
397 {
398 return hostGrid().mark( refCount, getHostEntity< 0 >( entity ) );
399 }
400
401 int getMark ( const typename Codim< 0 >::Entity &entity ) const
402 {
403 return hostGrid().getMark( getHostEntity< 0 >( entity ) );
404 }
405
406 bool preAdapt ()
407 {
408 return hostGrid().preAdapt();
409 }
410
411 bool adapt ()
412 {
413 bool ret = hostGrid().adapt();
414 update();
415 return ret;
416 }
417
418 void postAdapt ()
419 {
420 hostGrid().postAdapt();
421 }
422
430 int overlapSize ( int codim ) const
431 {
432 return leafGridView().overlapSize( codim );
433 }
434
439 int ghostSize( int codim ) const
440 {
441 return leafGridView().ghostSize( codim );
442 }
443
449 int overlapSize ( int level, int codim ) const
450 {
451 return levelGridView( level ).overlapSize( codim );
452 }
453
459 int ghostSize ( int level, int codim ) const
460 {
461 return levelGridView( level ).ghostSize( codim );
462 }
463
477 template< class DataHandle, class Data >
479 InterfaceType interface,
480 CommunicationDirection direction,
481 int level ) const
482 {
483 levelGridView( level ).communicate( dataHandle, interface, direction );
484 }
485
498 template< class DataHandle, class Data >
500 InterfaceType interface,
501 CommunicationDirection direction ) const
502 {
503 leafGridView().communicate( dataHandle, interface, direction );
504 }
505
515 {
516 return hostGrid().comm();
517 }
518
519#if 0
520 // data handle interface different between geo and interface
521
531 bool loadBalance ()
532 {
533 const bool gridChanged= hostGrid().loadBalance();
534 if( gridChanged )
535 update();
536 return gridChanged;
537 }
538
554 template< class DataHandle, class Data >
555 bool loadBalance ( CommDataHandleIF< DataHandle, Data > &datahandle )
556 {
557 typedef CommDataHandleIF< DataHandle, Data > DataHandleIF;
558 typedef GeoGrid :: CommDataHandle< Grid, DataHandleIF > WrappedDataHandle;
559
560 WrappedDataHandle wrappedDataHandle( *this, datahandle );
561 const bool gridChanged = hostGrid().loadBalance( wrappedDataHandle );
562 if( gridChanged )
563 update();
564 return gridChanged;
565 }
566#endif
567
569 template< class EntitySeed >
571 DUNE_DEPRECATED_MSG("entityPointer() is deprecated and will be removed after the release of dune-grid 2.4. Use entity() instead to directly obtain an Entity object.")
572 entityPointer ( const EntitySeed &seed ) const
573 {
574 typedef typename Traits::template Codim< EntitySeed::codimension >::Entity Entity;
575 return DefaultEntityPointer< Entity >( entity( seed ) );
576 }
577
579 template< class EntitySeed >
580 typename Traits::template Codim< EntitySeed::codimension >::Entity
581 entity ( const EntitySeed &seed ) const
582 {
583 typedef typename Traits::template Codim< EntitySeed::codimension >::EntityImpl EntityImpl;
584 return EntityImpl( *this, seed );
585 }
586
593 template< PartitionIteratorType pitype >
594 typename Partition< pitype >::LevelGridView levelGridView ( int level ) const
595 {
596 typedef typename Partition< pitype >::LevelGridView View;
597 typedef typename View::GridViewImp ViewImp;
598 return View( ViewImp( *this, hostGrid().levelGridView( level ) ) );
599 }
600
602 template< PartitionIteratorType pitype >
603 typename Partition< pitype >::LeafGridView leafGridView () const
604 {
605 typedef typename Traits::template Partition< pitype >::LeafGridView View;
606 typedef typename View::GridViewImp ViewImp;
607 return View( ViewImp( *this, hostGrid().leafGridView() ) );
608 }
609
611 LevelGridView levelGridView ( int level ) const
612 {
613 typedef typename LevelGridView::GridViewImp ViewImp;
614 return LevelGridView( ViewImp( *this, hostGrid().levelGridView( level ) ) );
615 }
616
618 LeafGridView leafGridView () const
619 {
620 typedef typename LeafGridView::GridViewImp ViewImp;
621 return LeafGridView( ViewImp( *this, hostGrid().leafGridView() ) );
622 }
623
629 const HostGrid &hostGrid () const
630 {
631 return *hostGrid_;
632 }
633
634 HostGrid &hostGrid ()
635 {
636 return *hostGrid_;
637 }
638
647 void update ()
648 {
649 // adapt the coordinate function
650 GeoGrid::AdaptCoordFunction< typename CoordFunction::Interface >::adapt( coordFunction_ );
651
652 const int newNumLevels = maxLevel()+1;
653 const int oldNumLevels = levelIndexSets_.size();
654
655 for( int i = newNumLevels; i < oldNumLevels; ++i )
656 {
657 if( levelIndexSets_[ i ] )
658 delete levelIndexSets_[ i ];
659 }
660 levelIndexSets_.resize( newNumLevels, nullptr );
661 }
662
666
667 const CoordFunction &coordFunction () const { return coordFunction_; }
668 CoordFunction &coordFunction () { return coordFunction_; }
669
670 protected:
671 template< int codim >
672 static const typename HostGrid::template Codim< codim >::Entity &
673 getHostEntity( const typename Codim< codim >::Entity &entity )
674 {
675 return getRealImplementation( entity ).hostEntity();
676 }
677
678 void *allocateStorage ( std::size_t size ) const
679 {
680 return storageAllocator_.allocate( size );
681 }
682
683 void deallocateStorage ( void *p, std::size_t size ) const
684 {
685 storageAllocator_.deallocate( (char *)p, size );
686 }
687
688 private:
689 HostGrid *const hostGrid_;
690 CoordFunction &coordFunction_;
691 bool removeHostGrid_;
692 mutable std::vector< LevelIndexSet *, typename Allocator::template rebind< LevelIndexSet * >::other > levelIndexSets_;
693 mutable LeafIndexSet leafIndexSet_;
694 mutable GlobalIdSet globalIdSet_;
695 mutable LocalIdSet localIdSet_;
696 mutable typename Allocator::template rebind< char >::other storageAllocator_;
697 };
698
699
700
701 // GeometryGrid::Codim
702 // -------------------
703
704 template< class HostGrid, class CoordFunction, class Allocator >
705 template< int codim >
706 struct GeometryGrid< HostGrid, CoordFunction, Allocator >::Codim
707 : public Base::template Codim< codim >
708 {
716 typedef typename Traits::template Codim< codim >::Entity Entity;
717
722 typedef typename Traits::template Codim< codim >::EntityPointer EntityPointer;
723
737 typedef typename Traits::template Codim< codim >::Geometry Geometry;
738
747 typedef typename Traits::template Codim< codim >::LocalGeometry LocalGeometry;
748
754 template< PartitionIteratorType pitype >
755 struct Partition
756 {
757 typedef typename Traits::template Codim< codim >
758 ::template Partition< pitype >::LeafIterator
760 typedef typename Traits::template Codim< codim >
761 ::template Partition< pitype >::LevelIterator
763 };
764
772 typedef typename Partition< All_Partition >::LeafIterator LeafIterator;
773
781 typedef typename Partition< All_Partition >::LevelIterator LevelIterator;
782
784 };
785
786} // namespace Dune
787
788#endif // #ifndef DUNE_GEOGRID_GRID_HH
CommDataHandleIF describes the features of a data handle for communication in parallel runs using the...
Definition: datahandleif.hh:73
Store a reference to an entity with a minimal memory footprint.
Definition: entityseed.hh:24
Wrapper class for entities.
Definition: entity.hh:62
actual implementation of the entity
Definition: entity.hh:34
grid wrapper replacing the geometries
Definition: grid.hh:83
Partition< All_Partition >::LevelGridView LevelGridView
View types for All_Partition.
Definition: grid.hh:152
int maxLevel() const
obtain maximal grid level
Definition: grid.hh:289
static std::conditional< std::is_reference< InterfaceType >::value, typenamestd::add_lvalue_reference< typenameReturnImplementationType< typenamestd::remove_reference< InterfaceType >::type >::ImplementationType >::type, typenamestd::remove_const< typenameReturnImplementationType< typenamestd::remove_reference< InterfaceType >::type >::ImplementationType >::type >::type getRealImplementation(InterfaceType &&i)
return real implementation of interface class
Definition: grid.hh:1305
Traits::template Codim< EntitySeed::codimension >::EntityPointer DUNE_DEPRECATED_MSG("entityPointer() is deprecated and will be removed after the release of dune-grid 2.4. Use entity() instead to directly obtain an Entity object.") entityPointer(const EntitySeed &seed) const
obtain EntityPointer from EntitySeed.
Definition: grid.hh:571
int size(int codim) const
obtain number of leaf entities
Definition: grid.hh:313
int size(int level, GeometryType type) const
obtain number of entites on a level
Definition: grid.hh:326
LeafGridView leafGridView() const
View for the leaf grid for All_Partition.
Definition: grid.hh:618
Traits::LevelIntersectionIterator LevelIntersectionIterator
iterator over intersections with other entities on the same level
Definition: grid.hh:134
Traits::template Codim< EntitySeed::codimension >::Entity entity(const EntitySeed &seed) const
obtain Entity from EntitySeed.
Definition: grid.hh:581
LevelGridView levelGridView(int level) const
View for a grid level for All_Partition.
Definition: grid.hh:611
int size(int level, int codim) const
obtain number of entites on a level
Definition: grid.hh:302
Traits::LeafIndexSet LeafIndexSet
type of leaf index set
Definition: grid.hh:169
Partition< pitype >::LeafGridView leafGridView() const
View for the leaf grid.
Definition: grid.hh:603
GeometryGrid(HostGrid *hostGrid, CoordFunction *coordFunction, const Allocator &allocator=Allocator())
constructor
Definition: grid.hh:252
Partition< pitype >::LevelGridView levelGridView(int level) const
View for a grid level.
Definition: grid.hh:594
Traits::HierarchicIterator HierarchicIterator
iterator over the grid hierarchy
Definition: grid.hh:130
Traits::ctype ctype
type of vector coordinates (e.g., double)
Definition: grid.hh:216
GridFamily::Traits Traits
type of the grid traits
Definition: grid.hh:113
~GeometryGrid()
destructor
Definition: grid.hh:262
int overlapSize(int codim) const
obtain size of overlap region for the leaf grid
Definition: grid.hh:430
void communicate(CommDataHandleIF< DataHandle, Data > &dataHandle, InterfaceType interface, CommunicationDirection direction) const
communicate information on leaf entities
Definition: grid.hh:499
Traits::LevelIndexSet LevelIndexSet
type of level index set
Definition: grid.hh:179
int ghostSize(int level, int codim) const
obtain size of ghost region for a grid level
Definition: grid.hh:459
void communicate(CommDataHandleIF< DataHandle, Data > &dataHandle, InterfaceType interface, CommunicationDirection direction, int level) const
communicate information on a grid level
Definition: grid.hh:478
Traits::LocalIdSet LocalIdSet
type of local id set
Definition: grid.hh:208
Traits::GlobalIdSet GlobalIdSet
type of global id set
Definition: grid.hh:191
Traits::LeafIntersectionIterator LeafIntersectionIterator
iterator over intersections with other entities on the leaf level
Definition: grid.hh:132
int ghostSize(int codim) const
obtain size of ghost region for the leaf grid
Definition: grid.hh:439
Traits::CollectiveCommunication CollectiveCommunication
communicator with all other processes having some part of the grid
Definition: grid.hh:219
size_t numBoundarySegments() const
returns the number of boundary segments within the macro grid
Definition: grid.hh:344
int size(GeometryType type) const
obtain number of leaf entities
Definition: grid.hh:335
GeometryGrid(HostGrid &hostGrid, CoordFunction &coordFunction, const Allocator &allocator=Allocator())
constructor
Definition: grid.hh:235
void update()
update grid caches
Definition: grid.hh:647
int overlapSize(int level, int codim) const
obtain size of overlap region for a grid level
Definition: grid.hh:449
const CollectiveCommunication & comm() const
obtain CollectiveCommunication object
Definition: grid.hh:514
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:25
Definition: grid.hh:1030
static std::conditional< std::is_reference< InterfaceType >::value, typenamestd::add_lvalue_reference< typenameReturnImplementationType< typenamestd::remove_reference< InterfaceType >::type >::ImplementationType >::type, typenamestd::remove_const< typenameReturnImplementationType< typenamestd::remove_reference< InterfaceType >::type >::ImplementationType >::type >::type getRealImplementation(InterfaceType &&i)
return real implementation of interface class
Definition: grid.hh:1305
Different resources needed by all grid implementations.
Definition of the DUNE_DEPRECATED macro for the case that config.h is not available.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:243
CommunicationDirection
Define a type for communication direction parameter.
Definition: gridenums.hh:168
InterfaceType
Parameter to be used for the communication functions.
Definition: gridenums.hh:84
Dune namespace.
Definition: alignment.hh:10
Fallback implementation of the nullptr object in C++0x.
Static tag representing a codimension.
Definition: dimension.hh:22
traits structure containing types for a codimension
Definition: grid.hh:708
Traits::template Codim< codim >::LocalGeometry LocalGeometry
type of local geometry
Definition: grid.hh:747
Partition< All_Partition >::LeafIterator LeafIterator
type of level iterator
Definition: grid.hh:772
Traits::template Codim< codim >::Entity Entity
type of entity
Definition: grid.hh:716
Partition< All_Partition >::LevelIterator LevelIterator
type of leaf iterator
Definition: grid.hh:781
Traits::template Codim< codim >::EntityPointer EntityPointer
type of entity pointer
Definition: grid.hh:722
Traits::template Codim< codim >::Geometry Geometry
type of world geometry
Definition: grid.hh:737
Types for GridView.
Definition: grid.hh:144
provides access to host grid objects from GeometryGrid
Definition: identitygrid.hh:37
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 21, 23:30, 2024)