DUNE PDELab (git)

grid.hh
1// SPDX-FileCopyrightText: Copyright © 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
11
13
14#include <dune/grid/geometrygrid/backuprestore.hh>
15#include <dune/grid/geometrygrid/capabilities.hh>
16#include <dune/grid/geometrygrid/datahandle.hh>
17#include <dune/grid/geometrygrid/gridfamily.hh>
18#include <dune/grid/geometrygrid/identity.hh>
19#include <dune/grid/geometrygrid/persistentcontainer.hh>
20
21namespace Dune
22{
23
24 // DefaultCoordFunction
25 // --------------------
26
27 template< class HostGrid >
28 class DefaultCoordFunction
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,
91 GeoGrid::GridFamily< HostGrid, CoordFunction, Allocator > >
92 Base;
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:
109 typedef GeoGrid::GridFamily< HostGrid, CoordFunction, Allocator > GridFamily;
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
229 GeometryGrid ( HostGrid &hostGrid, CoordFunction &coordFunction, const Allocator &allocator = Allocator() )
230 : hostGrid_( Dune::stackobject_to_shared_ptr(hostGrid) ),
231 coordFunction_( Dune::stackobject_to_shared_ptr(coordFunction) ),
232 levelIndexSets_( hostGrid_->maxLevel()+1 ),
233 storageAllocator_( allocator )
234 {}
235
245 GeometryGrid ( std::shared_ptr<HostGrid> hostGrid, std::shared_ptr<CoordFunction> coordFunction, const Allocator &allocator = Allocator() )
246 : hostGrid_( hostGrid ),
247 coordFunction_( coordFunction ),
248 levelIndexSets_( hostGrid_->maxLevel()+1 ),
249 storageAllocator_( allocator )
250 {}
251
261 GeometryGrid ( std::shared_ptr<HostGrid> hostGrid, const Allocator &allocator = Allocator() )
262 : hostGrid_( hostGrid ),
263 coordFunction_( std::make_shared<CoordFunction>( this->hostGrid() ) ),
264 levelIndexSets_( hostGrid_->maxLevel()+1 ),
265 storageAllocator_( allocator )
266 {}
267
268
269
282 int maxLevel () const
283 {
284 return hostGrid().maxLevel();
285 }
286
295 int size ( int level, int codim ) const
296 {
297 return levelGridView( level ).size( codim );
298 }
299
306 int size ( int codim ) const
307 {
308 return leafGridView().size( codim );
309 }
310
319 int size ( int level, GeometryType type ) const
320 {
321 return levelGridView( level ).size( type );
322 }
323
328 int size ( GeometryType type ) const
329 {
330 return leafGridView().size( type );
331 }
332
337 size_t numBoundarySegments () const
338 {
339 return hostGrid().numBoundarySegments( );
340 }
343 const GlobalIdSet &globalIdSet () const
344 {
345 if( !globalIdSet_ )
346 globalIdSet_ = GlobalIdSet( hostGrid().globalIdSet() );
347 assert( globalIdSet_ );
348 return globalIdSet_;
349 }
350
351 const LocalIdSet &localIdSet () const
352 {
353 if( !localIdSet_ )
354 localIdSet_ = LocalIdSet( hostGrid().localIdSet() );
355 assert( localIdSet_ );
356 return localIdSet_;
357 }
358
359 const LevelIndexSet &levelIndexSet ( int level ) const
360 {
361 assert( levelIndexSets_.size() == (size_t)(maxLevel()+1) );
362 if( (level < 0) || (level > maxLevel()) )
363 {
364 DUNE_THROW( GridError, "LevelIndexSet for nonexisting level " << level
365 << " requested." );
366 }
367
368 auto& levelIndexSetPtr = levelIndexSets_[ level ];
369 if( !levelIndexSetPtr )
370 levelIndexSetPtr = std::make_unique<LevelIndexSet>( hostGrid().levelIndexSet( level ) );
371 assert( levelIndexSetPtr );
372 return *levelIndexSetPtr;
373 }
374
375 const LeafIndexSet &leafIndexSet () const
376 {
377 if( !leafIndexSet_ )
378 leafIndexSet_.reset( hostGrid().leafIndexSet() );
379 assert( leafIndexSet_ );
380 return leafIndexSet_;
381 }
382
383 void globalRefine ( int refCount )
384 {
385 hostGrid().globalRefine( refCount );
386 update();
387 }
388
389 bool mark ( int refCount, const typename Codim< 0 >::Entity &entity_ )
390 {
391 return hostGrid().mark( refCount, getHostEntity< 0 >( entity_ ) );
392 }
393
394 int getMark ( const typename Codim< 0 >::Entity &entity_ ) const
395 {
396 return hostGrid().getMark( getHostEntity< 0 >( entity_ ) );
397 }
398
399 bool preAdapt ()
400 {
401 return hostGrid().preAdapt();
402 }
403
404 bool adapt ()
405 {
406 bool ret = hostGrid().adapt();
407 update();
408 return ret;
409 }
410
411 void postAdapt ()
412 {
413 hostGrid().postAdapt();
414 }
415
427 const Communication &comm () const
428 {
429 return hostGrid().comm();
430 }
431
432#if 0
433 // data handle interface different between geo and interface
434
444 bool loadBalance ()
445 {
446 const bool gridChanged= hostGrid().loadBalance();
447 if( gridChanged )
448 update();
449 return gridChanged;
450 }
451
467 template< class DataHandle, class Data >
468 bool loadBalance ( CommDataHandleIF< DataHandle, Data > &datahandle )
469 {
470 typedef CommDataHandleIF< DataHandle, Data > DataHandleIF;
471 typedef GeoGrid :: CommDataHandle< Grid, DataHandleIF > WrappedDataHandle;
472
473 WrappedDataHandle wrappedDataHandle( *this, datahandle );
474 const bool gridChanged = hostGrid().loadBalance( wrappedDataHandle );
475 if( gridChanged )
476 update();
477 return gridChanged;
478 }
479#endif
480
500 template< class EntitySeed >
501 typename Traits::template Codim< EntitySeed::codimension >::Entity
502 entity ( const EntitySeed &seed ) const
503 {
504 typedef typename Traits::template Codim< EntitySeed::codimension >::EntityImpl EntityImpl;
505 return EntityImpl( *this, seed );
506 }
507
514 LevelGridView levelGridView ( int level ) const
515 {
516 typedef typename LevelGridView::GridViewImp ViewImp;
517 return LevelGridView( ViewImp( *this, hostGrid().levelGridView( level ) ) );
518 }
519
522 {
523 typedef typename LeafGridView::GridViewImp ViewImp;
524 return LeafGridView( ViewImp( *this, hostGrid().leafGridView() ) );
525 }
526
533 const HostGrid &hostGrid () const
534 {
535 return *hostGrid_;
536 }
537
539 HostGrid &hostGrid ()
540 {
541 return *hostGrid_;
542 }
543
552 void update ()
553 {
554 // adapt the coordinate function
555 GeoGrid::AdaptCoordFunction< typename CoordFunction::Interface >::adapt( coordFunction() );
556
557 levelIndexSets_.resize( maxLevel()+1 );
558 }
559
560
562 const CoordFunction &coordFunction () const { return *coordFunction_; }
563
565 CoordFunction &coordFunction () { return *coordFunction_; }
566
569 protected:
570 template< int codim >
571 static const typename HostGrid::template Codim< codim >::Entity &
572 getHostEntity( const typename Codim< codim >::Entity &entity )
573 {
574 return entity.impl().hostEntity();
575 }
576
577 void *allocateStorage ( std::size_t size ) const
578 {
579 return storageAllocator_.allocate( size );
580 }
581
582 void deallocateStorage ( void *p, std::size_t size ) const
583 {
584 storageAllocator_.deallocate( (char *)p, size );
585 }
586
587 private:
588 std::shared_ptr<HostGrid> const hostGrid_;
589 std::shared_ptr<CoordFunction> coordFunction_;
590 mutable std::vector<std::unique_ptr<LevelIndexSet>> levelIndexSets_;
591 mutable LeafIndexSet leafIndexSet_;
592 mutable GlobalIdSet globalIdSet_;
593 mutable LocalIdSet localIdSet_;
594 mutable typename std::allocator_traits<Allocator>::template rebind_alloc< char > storageAllocator_;
595 };
596
597
598
599 // GeometryGrid::Codim
600 // -------------------
601
602 template< class HostGrid, class CoordFunction, class Allocator >
603 template< int codim >
604 struct GeometryGrid< HostGrid, CoordFunction, Allocator >::Codim
605 : public Base::template Codim< codim >
606 {
614 typedef typename Traits::template Codim< codim >::Entity Entity;
615
629 typedef typename Traits::template Codim< codim >::Geometry Geometry;
630
639 typedef typename Traits::template Codim< codim >::LocalGeometry LocalGeometry;
640
646 template< PartitionIteratorType pitype >
647 struct Partition
648 {
649 typedef typename Traits::template Codim< codim >
650 ::template Partition< pitype >::LeafIterator
652 typedef typename Traits::template Codim< codim >
653 ::template Partition< pitype >::LevelIterator
655 };
656
664 typedef typename Partition< All_Partition >::LeafIterator LeafIterator;
665
673 typedef typename Partition< All_Partition >::LevelIterator LevelIterator;
674
676 };
677
678} // namespace Dune
679
680#endif // #ifndef DUNE_GEOGRID_GRID_HH
Store a reference to an entity with a minimal memory footprint.
Definition: entityseed.hh:26
Implementation & impl()
access to the underlying implementation
Definition: entity.hh:80
actual implementation of the entity
Definition: entity.hh:34
grid wrapper replacing the geometries
Definition: grid.hh:86
int maxLevel() const
obtain maximal grid level
Definition: grid.hh:282
CoordFunction & coordFunction()
obtain mutable reference to the coordinate function.
Definition: grid.hh:565
int size(int codim) const
obtain number of leaf entities
Definition: grid.hh:306
int size(int level, GeometryType type) const
obtain number of entities on a level
Definition: grid.hh:319
const CoordFunction & coordFunction() const
obtain constant reference to the coordinate function
Definition: grid.hh:562
LeafGridView leafGridView() const
View for the leaf grid.
Definition: grid.hh:521
Traits::LevelIntersectionIterator LevelIntersectionIterator
iterator over intersections with other entities on the same level
Definition: grid.hh:137
Traits::template Codim< EntitySeed::codimension >::Entity entity(const EntitySeed &seed) const
obtain Entity from EntitySeed
Definition: grid.hh:502
LevelGridView levelGridView(int level) const
View for a grid level.
Definition: grid.hh:514
GeometryGrid(std::shared_ptr< HostGrid > hostGrid, std::shared_ptr< CoordFunction > coordFunction, const Allocator &allocator=Allocator())
constructor
Definition: grid.hh:245
int size(int level, int codim) const
obtain number of entities on a level
Definition: grid.hh:295
Traits::LeafIndexSet LeafIndexSet
type of leaf index set
Definition: grid.hh:163
Traits::HierarchicIterator HierarchicIterator
iterator over the grid hierarchy
Definition: grid.hh:133
Traits::Communication Communication
communicator with all other processes having some part of the grid
Definition: grid.hh:213
const HostGrid & hostGrid() const
obtain constant reference to the host grid
Definition: grid.hh:533
Traits::ctype ctype
type of vector coordinates (e.g., double)
Definition: grid.hh:210
const Communication & comm() const
obtain Communication object
Definition: grid.hh:427
GridFamily::Traits Traits
type of the grid traits
Definition: grid.hh:116
GridFamily::Traits::LevelGridView LevelGridView
type of view for level grid
Definition: grid.hh:147
HostGrid & hostGrid()
obtain mutable reference to the host grid
Definition: grid.hh:539
Traits::LevelIndexSet LevelIndexSet
type of level index set
Definition: grid.hh:173
Traits::LocalIdSet LocalIdSet
type of local id set
Definition: grid.hh:202
Traits::GlobalIdSet GlobalIdSet
type of global id set
Definition: grid.hh:185
Traits::LeafIntersectionIterator LeafIntersectionIterator
iterator over intersections with other entities on the leaf level
Definition: grid.hh:135
GeometryGrid(std::shared_ptr< HostGrid > hostGrid, const Allocator &allocator=Allocator())
constructor
Definition: grid.hh:261
GridFamily::Traits::LeafGridView LeafGridView
type of view for leaf grid
Definition: grid.hh:145
size_t numBoundarySegments() const
returns the number of boundary segments within the macro grid
Definition: grid.hh:337
int size(GeometryType type) const
obtain number of leaf entities
Definition: grid.hh:328
GeometryGrid(HostGrid &hostGrid, CoordFunction &coordFunction, const Allocator &allocator=Allocator())
constructor
Definition: grid.hh:229
void update()
update grid caches
Definition: grid.hh:552
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:114
Definition: grid.hh:848
Different resources needed by all grid implementations.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
Dune namespace.
Definition: alignedallocator.hh:13
std::shared_ptr< T > stackobject_to_shared_ptr(T &t)
Create a shared_ptr for a stack-allocated object.
Definition: shared_ptr.hh:72
STL namespace.
This file implements several utilities related to std::shared_ptr.
Static tag representing a codimension.
Definition: dimension.hh:24
traits structure containing types for a codimension
Definition: grid.hh:606
Traits::template Codim< codim >::LocalGeometry LocalGeometry
type of local geometry
Definition: grid.hh:639
Partition< All_Partition >::LeafIterator LeafIterator
type of leaf iterator
Definition: grid.hh:664
Traits::template Codim< codim >::Entity Entity
type of entity
Definition: grid.hh:614
Partition< All_Partition >::LevelIterator LevelIterator
type of level iterator
Definition: grid.hh:673
Traits::template Codim< codim >::Geometry Geometry
type of world geometry
Definition: grid.hh:629
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 (Nov 12, 23:30, 2024)