dune-grid 2.9.0
geometrygrid/grid.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) DUNE Project contributors, see file LICENSE.md in module root
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4// vi: set et ts=4 sw=2 sts=2:
5#ifndef DUNE_GEOGRID_GRID_HH
6#define DUNE_GEOGRID_GRID_HH
7
8#include <memory>
9
10#include <dune/common/shared_ptr.hh>
11
13
20
21namespace Dune
22{
23
24 // DefaultCoordFunction
25 // --------------------
26
27 template< class HostGrid >
29 : public IdenticalCoordFunction< typename HostGrid::ctype, HostGrid::dimensionworld >
30 {};
31
32
33
34 // GeometryGrid
35 // ------------
36
77 template< class HostGrid, class CoordFunction = DefaultCoordFunction< HostGrid >, class Allocator = std::allocator< void > >
81 < HostGrid::dimension, CoordFunction::dimRange, typename HostGrid::ctype,
82 GeoGrid::GridFamily< HostGrid, CoordFunction, Allocator > >,
83 public GeoGrid::ExportParams< HostGrid, CoordFunction >,
84 public GeoGrid::BackupRestoreFacilities< GeometryGrid< HostGrid, CoordFunction, Allocator > >
86 {
88
90 < HostGrid::dimension, CoordFunction::dimRange, typename HostGrid::ctype,
93
94 friend class GeoGrid::HierarchicIterator< const Grid >;
95
96 template< int, class, bool > friend class GeoGrid::EntityBase;
97 template< int, int, class > friend class GeoGrid::Geometry;
98 template< class, class, class > friend class GeoGrid::GridView;
99 template< class, class > friend class GeoGrid::Intersection;
100 template< class, class > friend class GeoGrid::IntersectionIterator;
101 template< class, class > friend class GeoGrid::IdSet;
102 template< class, class > friend class GeoGrid::IndexSet;
103 template< class > friend struct HostGridAccess;
104
105 template< class, class > friend class GeoGrid::CommDataHandle;
106
107 public:
116 typedef typename GridFamily::Traits Traits;
117
124 template< int codim >
125 struct Codim;
126
133 typedef typename Traits::HierarchicIterator HierarchicIterator;
135 typedef typename Traits::LeafIntersectionIterator LeafIntersectionIterator;
137 typedef typename Traits::LevelIntersectionIterator LevelIntersectionIterator;
138
145 typedef typename GridFamily::Traits::LeafGridView LeafGridView;
147 typedef typename GridFamily::Traits::LevelGridView LevelGridView;
148
163 typedef typename Traits::LeafIndexSet LeafIndexSet;
164
173 typedef typename Traits::LevelIndexSet LevelIndexSet;
174
185 typedef typename Traits::GlobalIdSet GlobalIdSet;
186
202 typedef typename Traits::LocalIdSet LocalIdSet;
203
210 typedef typename Traits::ctype ctype;
211
213 typedef typename Traits::Communication Communication;
214
217 [[deprecated("Use Communication instead!!")]]
219
234 GeometryGrid ( HostGrid &hostGrid, CoordFunction &coordFunction, const Allocator &allocator = Allocator() )
235 : hostGrid_( Dune::stackobject_to_shared_ptr(hostGrid) ),
236 coordFunction_( Dune::stackobject_to_shared_ptr(coordFunction) ),
237 levelIndexSets_( hostGrid_->maxLevel()+1 ),
238 storageAllocator_( allocator )
239 {}
240
250 GeometryGrid ( std::shared_ptr<HostGrid> hostGrid, std::shared_ptr<CoordFunction> coordFunction, const Allocator &allocator = Allocator() )
251 : hostGrid_( hostGrid ),
252 coordFunction_( coordFunction ),
253 levelIndexSets_( hostGrid_->maxLevel()+1 ),
254 storageAllocator_( allocator )
255 {}
256
266 GeometryGrid ( std::shared_ptr<HostGrid> hostGrid, const Allocator &allocator = Allocator() )
267 : hostGrid_( hostGrid ),
268 coordFunction_( std::make_shared<CoordFunction>( this->hostGrid() ) ),
269 levelIndexSets_( hostGrid_->maxLevel()+1 ),
270 storageAllocator_( allocator )
271 {}
272
273
274
287 int maxLevel () const
288 {
289 return hostGrid().maxLevel();
290 }
291
300 int size ( int level, int codim ) const
301 {
302 return levelGridView( level ).size( codim );
303 }
304
311 int size ( int codim ) const
312 {
313 return leafGridView().size( codim );
314 }
315
324 int size ( int level, GeometryType type ) const
325 {
326 return levelGridView( level ).size( type );
327 }
328
333 int size ( GeometryType type ) const
334 {
335 return leafGridView().size( type );
336 }
337
342 size_t numBoundarySegments () const
343 {
344 return hostGrid().numBoundarySegments( );
345 }
348 const GlobalIdSet &globalIdSet () const
349 {
350 if( !globalIdSet_ )
351 globalIdSet_ = GlobalIdSet( hostGrid().globalIdSet() );
352 assert( globalIdSet_ );
353 return globalIdSet_;
354 }
355
356 const LocalIdSet &localIdSet () const
357 {
358 if( !localIdSet_ )
359 localIdSet_ = LocalIdSet( hostGrid().localIdSet() );
360 assert( localIdSet_ );
361 return localIdSet_;
362 }
363
364 const LevelIndexSet &levelIndexSet ( int level ) const
365 {
366 assert( levelIndexSets_.size() == (size_t)(maxLevel()+1) );
367 if( (level < 0) || (level > maxLevel()) )
368 {
369 DUNE_THROW( GridError, "LevelIndexSet for nonexisting level " << level
370 << " requested." );
371 }
372
373 auto& levelIndexSetPtr = levelIndexSets_[ level ];
374 if( !levelIndexSetPtr )
375 levelIndexSetPtr = std::make_unique<LevelIndexSet>( hostGrid().levelIndexSet( level ) );
376 assert( levelIndexSetPtr );
377 return *levelIndexSetPtr;
378 }
379
381 {
382 if( !leafIndexSet_ )
383 leafIndexSet_.reset( hostGrid().leafIndexSet() );
384 assert( leafIndexSet_ );
385 return leafIndexSet_;
386 }
387
388 void globalRefine ( int refCount )
389 {
390 hostGrid().globalRefine( refCount );
391 update();
392 }
393
394 bool mark ( int refCount, const typename Codim< 0 >::Entity &entity_ )
395 {
396 return hostGrid().mark( refCount, getHostEntity< 0 >( entity_ ) );
397 }
398
399 int getMark ( const typename Codim< 0 >::Entity &entity_ ) const
400 {
401 return hostGrid().getMark( getHostEntity< 0 >( entity_ ) );
402 }
403
404 bool preAdapt ()
405 {
406 return hostGrid().preAdapt();
407 }
408
409 bool adapt ()
410 {
411 bool ret = hostGrid().adapt();
412 update();
413 return ret;
414 }
415
416 void postAdapt ()
417 {
418 hostGrid().postAdapt();
419 }
420
432 const Communication &comm () const
433 {
434 return hostGrid().comm();
435 }
436
437#if 0
438 // data handle interface different between geo and interface
439
449 bool loadBalance ()
450 {
451 const bool gridChanged= hostGrid().loadBalance();
452 if( gridChanged )
453 update();
454 return gridChanged;
455 }
456
472 template< class DataHandle, class Data >
473 bool loadBalance ( CommDataHandleIF< DataHandle, Data > &datahandle )
474 {
475 typedef CommDataHandleIF< DataHandle, Data > DataHandleIF;
476 typedef GeoGrid :: CommDataHandle< Grid, DataHandleIF > WrappedDataHandle;
477
478 WrappedDataHandle wrappedDataHandle( *this, datahandle );
479 const bool gridChanged = hostGrid().loadBalance( wrappedDataHandle );
480 if( gridChanged )
481 update();
482 return gridChanged;
483 }
484#endif
485
505 template< class EntitySeed >
506 typename Traits::template Codim< EntitySeed::codimension >::Entity
507 entity ( const EntitySeed &seed ) const
508 {
509 typedef typename Traits::template Codim< EntitySeed::codimension >::EntityImpl EntityImpl;
510 return EntityImpl( *this, seed );
511 }
512
519 LevelGridView levelGridView ( int level ) const
520 {
521 typedef typename LevelGridView::GridViewImp ViewImp;
522 return LevelGridView( ViewImp( *this, hostGrid().levelGridView( level ) ) );
523 }
524
527 {
528 typedef typename LeafGridView::GridViewImp ViewImp;
529 return LeafGridView( ViewImp( *this, hostGrid().leafGridView() ) );
530 }
531
538 const HostGrid &hostGrid () const
539 {
540 return *hostGrid_;
541 }
542
544 HostGrid &hostGrid ()
545 {
546 return *hostGrid_;
547 }
548
557 void update ()
558 {
559 // adapt the coordinate function
561
562 levelIndexSets_.resize( maxLevel()+1 );
563 }
564
565
567 const CoordFunction &coordFunction () const { return *coordFunction_; }
568
570 CoordFunction &coordFunction () { return *coordFunction_; }
571
574 protected:
575 template< int codim >
576 static const typename HostGrid::template Codim< codim >::Entity &
578 {
579 return entity.impl().hostEntity();
580 }
581
582 void *allocateStorage ( std::size_t size ) const
583 {
584 return storageAllocator_.allocate( size );
585 }
586
587 void deallocateStorage ( void *p, std::size_t size ) const
588 {
589 storageAllocator_.deallocate( (char *)p, size );
590 }
591
592 private:
593 std::shared_ptr<HostGrid> const hostGrid_;
594 std::shared_ptr<CoordFunction> coordFunction_;
595 mutable std::vector<std::unique_ptr<LevelIndexSet>> levelIndexSets_;
596 mutable LeafIndexSet leafIndexSet_;
597 mutable GlobalIdSet globalIdSet_;
598 mutable LocalIdSet localIdSet_;
599 mutable typename std::allocator_traits<Allocator>::template rebind_alloc< char > storageAllocator_;
600 };
601
602
603
604 // GeometryGrid::Codim
605 // -------------------
606
607 template< class HostGrid, class CoordFunction, class Allocator >
608 template< int codim >
609 struct GeometryGrid< HostGrid, CoordFunction, Allocator >::Codim
610 : public Base::template Codim< codim >
611 {
619 typedef typename Traits::template Codim< codim >::Entity Entity;
620
634 typedef typename Traits::template Codim< codim >::Geometry Geometry;
635
644 typedef typename Traits::template Codim< codim >::LocalGeometry LocalGeometry;
645
651 template< PartitionIteratorType pitype >
653 {
654 typedef typename Traits::template Codim< codim >
657 typedef typename Traits::template Codim< codim >
660 };
661
670
679
681 };
682
683} // namespace Dune
684
685#endif // #ifndef DUNE_GEOGRID_GRID_HH
STL namespace.
Include standard header files.
Definition: agrid.hh:60
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:132
Implementation & impl()
access to the underlying implementation
Definition: common/entity.hh:80
Store a reference to an entity with a minimal memory footprint.
Definition: common/entityseed.hh:26
Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:20
Definition: common/grid.hh:862
Definition: geometrygrid/backuprestore.hh:27
static void adapt(CoordFunctionInterface &)
Definition: coordfunction.hh:326
Definition: geometrygrid/datahandle.hh:27
grid wrapper replacing the geometries
Definition: geometrygrid/grid.hh:86
const LeafIndexSet & leafIndexSet() const
Definition: geometrygrid/grid.hh:380
int maxLevel() const
obtain maximal grid level
Definition: geometrygrid/grid.hh:287
CoordFunction & coordFunction()
obtain mutable reference to the coordinate function.
Definition: geometrygrid/grid.hh:570
int size(int codim) const
obtain number of leaf entities
Definition: geometrygrid/grid.hh:311
int size(int level, GeometryType type) const
obtain number of entites on a level
Definition: geometrygrid/grid.hh:324
const CoordFunction & coordFunction() const
obtain constant reference to the coordinate function
Definition: geometrygrid/grid.hh:567
void postAdapt()
Definition: geometrygrid/grid.hh:416
static const HostGrid::template Codim< codim >::Entity & getHostEntity(const typename Codim< codim >::Entity &entity)
Definition: geometrygrid/grid.hh:577
LeafGridView leafGridView() const
View for the leaf grid.
Definition: geometrygrid/grid.hh:526
Traits::LevelIntersectionIterator LevelIntersectionIterator
iterator over intersections with other entities on the same level
Definition: geometrygrid/grid.hh:137
Traits::template Codim< EntitySeed::codimension >::Entity entity(const EntitySeed &seed) const
obtain Entity from EntitySeed
Definition: geometrygrid/grid.hh:507
LevelGridView levelGridView(int level) const
View for a grid level.
Definition: geometrygrid/grid.hh:519
const LocalIdSet & localIdSet() const
Definition: geometrygrid/grid.hh:356
GeometryGrid(std::shared_ptr< HostGrid > hostGrid, std::shared_ptr< CoordFunction > coordFunction, const Allocator &allocator=Allocator())
constructor
Definition: geometrygrid/grid.hh:250
int size(int level, int codim) const
obtain number of entites on a level
Definition: geometrygrid/grid.hh:300
Traits::LeafIndexSet LeafIndexSet
type of leaf index set
Definition: geometrygrid/grid.hh:163
bool adapt()
Definition: geometrygrid/grid.hh:409
const GlobalIdSet & globalIdSet() const
Definition: geometrygrid/grid.hh:348
Traits::HierarchicIterator HierarchicIterator
iterator over the grid hierarchy
Definition: geometrygrid/grid.hh:133
Traits::Communication Communication
communicator with all other processes having some part of the grid
Definition: geometrygrid/grid.hh:213
bool mark(int refCount, const typename Codim< 0 >::Entity &entity_)
Definition: geometrygrid/grid.hh:394
const HostGrid & hostGrid() const
obtain constant reference to the host grid
Definition: geometrygrid/grid.hh:538
Traits::ctype ctype
type of vector coordinates (e.g., double)
Definition: geometrygrid/grid.hh:210
const Communication & comm() const
obtain Communication object
Definition: geometrygrid/grid.hh:432
GridFamily::Traits Traits
type of the grid traits
Definition: geometrygrid/grid.hh:116
GridFamily::Traits::LevelGridView LevelGridView
type of view for level grid
Definition: geometrygrid/grid.hh:147
HostGrid & hostGrid()
obtain mutable reference to the host grid
Definition: geometrygrid/grid.hh:544
Traits::LevelIndexSet LevelIndexSet
type of level index set
Definition: geometrygrid/grid.hh:173
int getMark(const typename Codim< 0 >::Entity &entity_) const
Definition: geometrygrid/grid.hh:399
Traits::LocalIdSet LocalIdSet
type of local id set
Definition: geometrygrid/grid.hh:202
void deallocateStorage(void *p, std::size_t size) const
Definition: geometrygrid/grid.hh:587
Traits::GlobalIdSet GlobalIdSet
type of global id set
Definition: geometrygrid/grid.hh:185
Traits::LeafIntersectionIterator LeafIntersectionIterator
iterator over intersections with other entities on the leaf level
Definition: geometrygrid/grid.hh:135
void globalRefine(int refCount)
Definition: geometrygrid/grid.hh:388
GeometryGrid(std::shared_ptr< HostGrid > hostGrid, const Allocator &allocator=Allocator())
constructor
Definition: geometrygrid/grid.hh:266
GridFamily::Traits::LeafGridView LeafGridView
type of view for leaf grid
Definition: geometrygrid/grid.hh:145
bool preAdapt()
Definition: geometrygrid/grid.hh:404
size_t numBoundarySegments() const
returns the number of boundary segments within the macro grid
Definition: geometrygrid/grid.hh:342
Communication CollectiveCommunication
Definition: geometrygrid/grid.hh:218
int size(GeometryType type) const
obtain number of leaf entities
Definition: geometrygrid/grid.hh:333
const LevelIndexSet & levelIndexSet(int level) const
Definition: geometrygrid/grid.hh:364
GeometryGrid(HostGrid &hostGrid, CoordFunction &coordFunction, const Allocator &allocator=Allocator())
constructor
Definition: geometrygrid/grid.hh:234
void update()
update grid caches
Definition: geometrygrid/grid.hh:557
void * allocateStorage(std::size_t size) const
Definition: geometrygrid/grid.hh:582
actual implementation of the entity
Definition: geometrygrid/entity.hh:34
Definition: iterator.hh:374
Definition: geometrygrid/intersectioniterator.hh:21
Definition: geometrygrid/geometry.hh:89
Definition: geometrygrid/grid.hh:30
traits structure containing types for a codimension
Definition: geometrygrid/grid.hh:611
Traits::template Codim< codim >::LocalGeometry LocalGeometry
type of local geometry
Definition: geometrygrid/grid.hh:644
Partition< All_Partition >::LeafIterator LeafIterator
type of leaf iterator
Definition: geometrygrid/grid.hh:669
Traits::template Codim< codim >::Entity Entity
type of entity
Definition: geometrygrid/grid.hh:619
Partition< All_Partition >::LevelIterator LevelIterator
type of level iterator
Definition: geometrygrid/grid.hh:678
Traits::template Codim< codim >::Geometry Geometry
type of world geometry
Definition: geometrygrid/grid.hh:634
Definition: geometrygrid/grid.hh:653
Traits::template Codim< codim >::template Partition< pitype >::LevelIterator LevelIterator
Definition: geometrygrid/grid.hh:659
Traits::template Codim< codim >::template Partition< pitype >::LeafIterator LeafIterator
Definition: geometrygrid/grid.hh:656
Definition: geometrygrid/gridfamily.hh:35
Definition: geometrygrid/gridfamily.hh:51
Definition: geometrygrid/gridview.hh:97
Definition: identity.hh:17
Definition: idset.hh:22
Definition: geometrygrid/indexsets.hh:29
Definition: geometrygrid/intersection.hh:22
provides access to host grid objects from GeometryGrid
Definition: identitygrid.hh:37
Different resources needed by all grid implementations.