1#ifndef ALUGRID_GRID_INLINE_HH
2#define ALUGRID_GRID_INLINE_HH
8#include "alu3dinclude.hh"
11#include "datahandle.hh"
14#define alu_inline_tmp inline
22 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
25 const MPICommunicatorType mpiComm,
26 const ALUGridVertexProjectionPairType& bndPrj,
35 , localIdSet_( *this )
36 , levelIndexVec_(1) , leafIndexSet_()
38 , lockPostAdapt_( false )
39 , vertexProjections_( bndPrj )
40 , communications_( new Communications( mpiComm ) )
41 , refinementType_( refinementType )
49 mygrid_.reset( createALUGrid( macroTriangFilename ) );
50 alugrid_assert ( mygrid_ );
52 dverb <<
"************************************************" << std::endl;
53 dverb <<
"Created grid on p=" <<
comm().rank() << std::endl;
54 dverb <<
"************************************************" << std::endl;
62 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
68 return myGrid().indexManager(codim).getMaxIndex();
72 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
76 return myGrid().indexManager(codim).getMaxIndex();
80 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
87 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
88 inline typename ALU3dGrid< dim, dimworld, elType, Comm >::GitterImplType &
91 alugrid_assert ( mygrid_ );
96 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
97 template<
int cd, PartitionIteratorType pitype >
98 inline typename ALU3dGrid< dim, dimworld, elType, Comm >::Traits::template Codim< cd >::template Partition< pitype >::LevelIterator
101 alugrid_assert ( level >= 0 );
103 if( level > maxlevel_ )
104 return this->
template lend<cd,pitype> (level);
110 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
111 template<
int cd, PartitionIteratorType pitype >
115 alugrid_assert ( level >= 0 );
121 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
126 return this->
template lbegin<cd,All_Partition>( level );
130 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
135 alugrid_assert ( level >= 0 );
136 return this->
template lend<cd,All_Partition>( level );
145 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
146 template<
int cd, PartitionIteratorType pitype >
154 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
159 return leafbegin< cd, All_Partition> () ;
168 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
169 template<
int cd, PartitionIteratorType pitype >
177 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
182 return leafend< cd, All_Partition> ();
188 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
190 ::mark (
int ref,
const typename Traits::template Codim< 0 >::Entity &entity )
192 bool marked = entity.impl().mark( ref, conformingRefinement() );
195 if(ref > 0) ++refineMarked_;
196 if(ref < 0) ++coarsenMarked_;
203 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
205 ::getMark (
const typename Traits::template Codim< 0 >::Entity &entity )
const
207 return entity.impl().getMark();
212 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
213 template<
class Gr
idImp,
class DataHandle >
218 for(
int count = std::abs(refCount); count > 0; --count )
220 const LeafIteratorType end = leafend();
221 for( LeafIteratorType it = leafbegin(); it != end; ++it )
222 mark( refCount>0?1:-1 , *it );
230 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
231 template<
class Gr
idImp,
class DataHandle >
239 bool mightCoarse = preAdapt();
241 bool refined = false ;
246 ALU3DSPACE AdaptRestrictProlongGlSet< MyType, AdaptDataHandle, GlobalIdSetImp >
251 refined = myGrid().duneAdapt(rp);
255 ALU3DSPACE AdaptRestrictProlongImpl< MyType, AdaptDataHandle >
259 refined = myGrid().duneAdapt(rp);
262 if(refined || mightCoarse)
277 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
281 return "ALUCubeGrid";
283 return "ALUSimplexGrid";
287 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
292 if( (level > maxlevel_) || (level < 0) )
return 0;
294 alugrid_assert ( codim >= 0);
295 alugrid_assert ( codim < dimension+1 );
297 alugrid_assert ( sizeCache_ );
298 return sizeCache_->size(level,codim);
302 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
305 return macroBoundarySegmentIndexSet().size();
310 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
314 if(elType == tetra && !type.
isSimplex())
return 0;
315 if(elType == hexa && !type.
isCube ())
return 0;
316 return size( level, dimension - type.
dim() );
320 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
324 alugrid_assert ( codim >= 0 );
325 alugrid_assert ( codim <= dimension );
327 alugrid_assert ( sizeCache_ );
328 return sizeCache_->size(codim);
332 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
336 if(elType == tetra && !type.
isSimplex())
return 0;
337 if(elType == hexa && !type.
isCube ())
return 0;
338 return size( dimension - type.
dim() );
342 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
346 return ( ghostCellsEnabled() && codim == 0 ) ? 1 : 0 ;
350 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
354 return ghostSize( codim );
359 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
369 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
380 leafVertexList_.unsetUp2Date();
382 vertexList_.resize( maxlevel_+1 );
383 levelEdgeList_.resize( maxlevel_+1 );
385 for(
int i=0; i<=maxlevel_; ++i)
387 vertexList_[i].unsetUp2Date();
388 levelEdgeList_[i].unsetUp2Date();
394 for(
int i = 0; i < 3; ++i )
396 ghostLeafList_[i].unsetUp2Date();
397 ghostLevelList_[i].resize( maxlevel_+1 );
398 for(
int l=0; l<=maxlevel_; ++l)
399 ghostLevelList_[i][l].unsetUp2Date();
403 levelIndexVec_.resize( maxlevel_ + 1 );
406 for(
size_t i=0; i<levelIndexVec_.size(); ++i)
408 if(levelIndexVec_[i])
410 levelIndexVec_[i]->calcNewIndex( this->
template lbegin<0>( i ),
411 this->
template lend<0>( i ) );
417 leafIndexSet_->calcNewIndex( this->
template leafbegin<0>(), this->
template leafend<0>() );
421 if( globalIdSet_ ) globalIdSet_->updateIdSet();
428 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
436 this->
template leafbegin<0>(),
437 this->
template leafend<0>() ) );
439 return *leafIndexSet_;
443 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
448 assert( (level >= 0) && (level <
int( levelIndexVec_.size() )) );
449 if( ! levelIndexVec_[ level ] )
451 levelIndexVec_[ level ] = createLevelIndexSet( level );
453 return (*levelIndexVec_[ level ]);
460 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
462 std::shared_ptr< typename ALU3dGrid< dim, dimworld, elType, Comm >::LevelIndexSetImp >
465 assert( (level >= 0) && (level <
int( levelIndexVec_.size() )) );
466 if( levelIndexVec_[ level ] )
468 return levelIndexVec_[ level ];
472 return createLevelIndexSet( level );
476 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
478 std::shared_ptr< typename ALU3dGrid< dim, dimworld, elType, Comm >::LevelIndexSetImp >
481 return std::make_shared< LevelIndexSetImp > ( *
this, lbegin< 0 >( level ), lend< 0 >( level ), level );
486 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
490 int marker = refCount > 0 ? 1: -1 ;
491 for(
int count = std::abs(refCount); count > 0; --count )
493 const auto end = leafend< 0, Interior_Partition >();
494 for(
auto it = leafbegin< 0, Interior_Partition >(); it != end; ++it )
505 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
509 return (coarsenMarked_ > 0);
514 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
520 if( lockPostAdapt_ ==
true )
525 bool mightCoarse = preAdapt();
530 int defaultChunk = newElementsChunk_;
531 int actChunk = refineEstimate_ * refineMarked_;
534 int newElements = std::max( actChunk , defaultChunk );
536 globalIdSet_->setChunkSize( newElements );
537 ref = myGrid().duneAdapt(*globalIdSet_);
541 ref = myGrid().adaptWithoutLoadBalancing();
545 if( this->comm().size() == 1 )
547 ref = ref && refineMarked_ > 0;
550 if(ref || mightCoarse)
556 lockPostAdapt_ =
true;
Leaf iterator.
Definition: iterator.hh:648
Definition: iterator.hh:556
[ provides Dune::Grid ]
Definition: grid.hh:434
ALU3dGrid(const std::string ¯oTriangFilename, const MPICommunicatorType mpiComm, const ALUGridVertexProjectionPairType &bndPrj, const ALUGridRefinementType refinementType)
Definition: grid_inline.hh:24
const Traits::LeafIndexSet & leafIndexSet() const
get leaf index set of the grid
Definition: grid_inline.hh:431
bool mark(int refCount, const typename Traits::template Codim< 0 >::Entity &e)
Marks an entity to be refined/coarsened in a subsequent adapt.
Definition: grid_inline.hh:190
int maxLevel() const
Return maximum level defined in this grid. Levels are numbered maxLevel with 0 the coarsest level.
Definition: grid_inline.hh:81
Traits::template Codim< codim >::template Partition< pitype >::LeafIterator leafend() const
General definition for an end iterator on leaf level.
Definition: grid_inline.hh:171
const Traits::LevelIndexSet & levelIndexSet(int level) const
get level index set of the grid
Definition: grid_inline.hh:446
void checkMacroGridFile(const std::string filename)
check whether macro grid format is of our type
Definition: grid_imp.cc:304
void globalRefine(int refCount)
uses the interface, mark on entity and refineLocal
Definition: grid_inline.hh:488
bool adapt()
Refine all positive marked leaf entities, coarsen all negative marked entities if possible.
Definition: grid_inline.hh:516
static std::string name()
for grid identification
Definition: grid_inline.hh:278
std::shared_ptr< LevelIndexSetImp > accessLevelIndexSet(int level) const
return instance of level index set
Definition: grid_inline.hh:463
void clearIsNewMarkers()
clear all entity new markers
Definition: grid_imp.cc:444
Traits::template Codim< cd >::template Partition< pitype >::LevelIterator lbegin(int level) const
Iterator to first entity of given codim on level.
Definition: grid_inline.hh:99
bool preAdapt()
returns if a least one entity was marked for coarsening
Definition: grid_inline.hh:507
void calcExtras()
reset size and global size, update Level- and LeafIndexSet, if they exist
Definition: grid_inline.hh:371
int getMark(const typename Traits::template Codim< 0 >::Entity &e) const
returns adaptation mark for given entity
Definition: grid_inline.hh:205
Traits::template Codim< codim >::template Partition< pitype >::LeafIterator leafbegin() const
General definiton for a leaf iterator.
Definition: grid_inline.hh:148
Traits::template Codim< cd >::template Partition< pitype >::LevelIterator lend(int level) const
one past the end on this level
Definition: grid_inline.hh:113
int global_size(int cd) const
number of grid entities on all levels for given codim
Definition: grid_inline.hh:63
int ghostSize(int level, int codim) const
ghostSize is one for codim 0 and zero otherwise for this grid
Definition: grid_inline.hh:352
int size(int level, int cd) const
number of grid entities per level and codim
Definition: grid_inline.hh:289
size_t numBoundarySegments() const
number of boundary segments
Definition: grid_inline.hh:303
void checkMacroGrid()
check whether macro grid has the right element type
Definition: grid_imp.cc:343
const Communication & comm() const
return const reference to a communication object. The return type is a model of Dune::Communication.
Definition: grid.hh:1009
Interface class for the Grid's adapt method where the parameter is a AdaptDataHandleInterface.
Definition: adaptcallback.hh:33
DefaultIndexSet creates an index set by using the grids persistent container an a given pair of itera...
Definition: defaultindexsets.hh:68
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:125
constexpr unsigned int dim() const
Return dimension of the type.
Definition: type.hh:371
constexpr bool isCube() const
Return true if entity is a cube of any dimension.
Definition: type.hh:335
constexpr bool isSimplex() const
Return true if entity is a simplex of any dimension.
Definition: type.hh:330
Index Set Interface base class.
Definition: indexidset.hh:78
Default exception if a function was called while the object is not in a valid state for that function...
Definition: exceptions.hh:281
organizes the caching of sizes for one grid and one GeometryType
Definition: sizecache.hh:33
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
DVerbType dverb(std::cout)
Singleton of verbose debug stream.
Definition: stdstreams.hh:116
Dune namespace.
Definition: alignedallocator.hh:13
ALUGridRefinementType
available refinement types for ALUGrid
Definition: declaration.hh:24
Standard Dune debug streams.
Static tag representing a codimension.
Definition: dimension.hh:24