2 #include <dune/common/stdstreams.hh>
17 template< ALU3dGr
idElementType elType,
class Comm >
31 , localIdSet_( *this )
32 , levelIndexVec_(MAXL,0) , leafIndexSet_(0)
33 , referenceElement_( elType ==
tetra
37 #ifdef USE_SMP_PARALLEL
42 , lockPostAdapt_( false )
47 , refinementType_( refinementType )
49 assert( elType ==
tetra || elType ==
hexa );
51 geomTypes_.resize( dimension+1 );
53 for(
int codim = 0; codim <= dimension; ++codim )
56 tmpType.makeSimplex( dimension - codim );
58 tmpType.makeCube( dimension - codim );
60 geomTypes_[ codim ].push_back( tmpType );
64 checkMacroGridFile( macroTriangFilename );
66 mygrid_ = createALUGrid( macroTriangFilename );
69 dverb <<
"************************************************" << std::endl;
70 dverb <<
"Created grid on p=" << comm().rank() << std::endl;
71 dverb <<
"************************************************" << std::endl;
79 template< ALU3dGr
idElementType elType,
class Comm >
85 return myGrid().indexManager(codim).getMaxIndex();
89 template< ALU3dGr
idElementType elType,
class Comm >
93 return myGrid().indexManager(codim).getMaxIndex();
97 template< ALU3dGr
idElementType elType,
class Comm >
104 template< ALU3dGr
idElementType elType,
class Comm >
114 template< ALU3dGr
idElementType elType,
class Comm >
115 template<
int cd, PartitionIteratorType pitype >
119 assert( level >= 0 );
121 if( level > maxlevel_ )
122 return this->
template lend<cd,pitype> (level);
128 template< ALU3dGr
idElementType elType,
class Comm >
129 template<
int cd, PartitionIteratorType pitype >
133 assert( level >= 0 );
139 template< ALU3dGr
idElementType elType,
class Comm >
144 return this->
template lbegin<cd,All_Partition>( level );
148 template< ALU3dGr
idElementType elType,
class Comm >
153 assert( level >= 0 );
154 return this->
template lend<cd,All_Partition>( level );
163 template< ALU3dGr
idElementType elType,
class Comm >
164 template<
int cd, PartitionIteratorType pitype >
168 assert( level >= 0 );
173 template< ALU3dGr
idElementType elType,
class Comm >
174 template<
int cd, PartitionIteratorType pitype >
178 return createLeafIteratorBegin<cd, pitype> (level) ;
182 template< ALU3dGr
idElementType elType,
class Comm >
184 inline typename ALU3dGrid< elType, Comm >::Traits::template Codim< cd >::LeafIterator
185 ALU3dGrid< elType, Comm >::leafbegin (
int level )
const
187 return createLeafIteratorBegin<cd, All_Partition> (level) ;
191 template< ALU3dGr
idElementType elType,
class Comm >
192 template<
int cd, PartitionIteratorType pitype >
193 inline typename ALU3dGrid< elType, Comm >::Traits::template Codim< cd >::template Partition< pitype >::LeafIterator
194 ALU3dGrid< elType, Comm >::leafbegin ()
const
196 return createLeafIteratorBegin< cd, pitype > (maxlevel_) ;
200 template< ALU3dGr
idElementType elType,
class Comm >
202 inline typename ALU3dGrid< elType, Comm >::Traits::template Codim< cd >::LeafIterator
203 ALU3dGrid< elType, Comm >::leafbegin ()
const
205 return createLeafIteratorBegin< cd, All_Partition> (maxlevel_) ;
209 template< ALU3dGr
idElementType elType,
class Comm >
210 inline typename ALU3dGrid< elType, Comm >::LeafIteratorType
211 ALU3dGrid< elType, Comm >::leafbegin (
int level )
const
213 return createLeafIteratorBegin<0, All_Partition> (level) ;
217 template< ALU3dGr
idElementType elType,
class Comm >
218 inline typename ALU3dGrid< elType, Comm >::LeafIteratorType
219 ALU3dGrid< elType, Comm >::leafbegin ()
const
221 return createLeafIteratorBegin<0, All_Partition> (maxlevel_) ;
230 template< ALU3dGr
idElementType elType,
class Comm >
231 template<
int cd, PartitionIteratorType pitype >
232 inline typename ALU3dGrid< elType, Comm >::Traits::template Codim< cd >::template Partition< pitype >::LeafIterator
235 assert( level >= 0 );
240 template< ALU3dGr
idElementType elType,
class Comm >
241 template<
int cd, PartitionIteratorType pitype >
245 return createLeafIteratorEnd < cd, pitype> (level);
249 template< ALU3dGr
idElementType elType,
class Comm >
251 inline typename ALU3dGrid< elType, Comm >::Traits::template Codim< cd >::LeafIterator
252 ALU3dGrid< elType, Comm >::leafend (
int level )
const
254 return createLeafIteratorEnd < cd, All_Partition> (level);
258 template< ALU3dGr
idElementType elType,
class Comm >
259 template<
int cd, PartitionIteratorType pitype >
260 inline typename ALU3dGrid< elType, Comm >::Traits::template Codim< cd >::template Partition< pitype >::LeafIterator
261 ALU3dGrid< elType, Comm >::leafend ()
const
263 return createLeafIteratorEnd < cd, pitype> (maxlevel_);
267 template< ALU3dGr
idElementType elType,
class Comm >
269 inline typename ALU3dGrid< elType, Comm >::Traits::template Codim< cd >::LeafIterator
270 ALU3dGrid< elType, Comm >::leafend ()
const
272 return createLeafIteratorEnd < cd, All_Partition> (maxlevel_);
276 template< ALU3dGr
idElementType elType,
class Comm >
277 inline typename ALU3dGrid< elType, Comm >::LeafIteratorType
278 ALU3dGrid< elType, Comm >::leafend (
int level )
const
280 return createLeafIteratorEnd <0, All_Partition> (level);
284 template< ALU3dGr
idElementType elType,
class Comm >
285 inline typename ALU3dGrid< elType, Comm >::LeafIteratorType
286 ALU3dGrid< elType, Comm >::leafend ()
const
288 return createLeafIteratorEnd <0,All_Partition> (maxlevel_);
295 template< ALU3dGr
idElementType elType,
class Comm >
299 bool marked = (this->getRealImplementation( entity )).mark(ref);
302 if(ref > 0) ++refineMarked_;
303 if(ref < 0) ++coarsenMarked_;
310 template< ALU3dGr
idElementType elType,
class Comm >
314 return this->getRealImplementation( entity ).getMark();
319 template< ALU3dGr
idElementType elType,
class Comm >
320 template<
class Gr
idImp,
class DataHandle >
325 assert( (refCount + maxLevel()) < MAXL );
327 for(
int count = refCount; count > 0; --count )
339 template< ALU3dGr
idElementType elType,
class Comm >
340 template<
class Gr
idImp,
class DataHandle >
348 EntityObject father( EntityImp( *
this, this->maxLevel() ) );
349 EntityObject son( EntityImp( *
this, this->maxLevel() ) );
351 int defaultChunk = newElementsChunk_;
352 int actChunk = refineEstimate_ * refineMarked_;
355 int newElements =
std::max( actChunk , defaultChunk );
358 bool mightCoarse = preAdapt();
362 bool refined = false ;
367 ALU3DSPACE AdaptRestrictProlongGlSet< MyType, AdaptDataHandle, GlobalIdSetImp >
369 father,this->getRealImplementation(father),
370 son, this->getRealImplementation(son),
374 refined = myGrid().duneAdapt(rp);
378 ALU3DSPACE AdaptRestrictProlongImpl< MyType, AdaptDataHandle >
380 father,this->getRealImplementation(father),
381 son, this->getRealImplementation(son),
384 refined = myGrid().duneAdapt(rp);
387 if(refined || mightCoarse)
411 template< ALU3dGr
idElementType elType,
class Comm >
414 template< ALU3dGr
idElementType elType >
421 template<
class DataHandle >
424 template<
class DataHandle,
class DataType >
425 static void communicate (
const Grid &grid,
432 template<
class DataHandle,
class DataType >
433 static void communicate (
const Grid &grid,
440 #if ALU3DGRID_PARALLEL
441 template< ALU3dGr
idElementType elType >
442 struct ALU3dGridCommHelper< elType, MPI_Comm >
444 typedef ALU3dGrid< elType, MPI_Comm > Grid;
447 static bool loadBalance ( Grid &grid )
449 if( grid.comm().size() <= 1 )
452 const bool changed = grid.myGrid().duneLoadBalance();
456 grid.myGrid().duneExchangeDynamicState();
464 if( grid.globalIdSet_ )
465 grid.globalIdSet_->updateIdSet();
475 template<
class DataHandle >
476 static bool loadBalance ( Grid &grid, DataHandle &data )
478 if( grid.comm().size() <= 1 )
481 typedef typename Grid :: EntityObject EntityObject;
482 typedef typename EntityObject::ImplementationType EntityImp;
483 EntityObject en ( EntityImp( grid, grid.maxLevel()) );
484 EntityObject father ( EntityImp( grid, grid.maxLevel()) );
485 EntityObject son ( EntityImp( grid, grid.maxLevel()) );
487 typedef ALU3DSPACE LoadBalanceElementCount< Grid, DataHandle > LDBElCountType;
491 LDBElCountType elCount( grid,
492 father, Grid::getRealImplementation( father ),
493 son, Grid::getRealImplementation( son ),
496 ALU3DSPACE GatherScatterLoadBalance< Grid, DataHandle, LDBElCountType >
497 gs( grid, en, Grid::getRealImplementation( en ), data, elCount );
500 const bool changed = grid.myGrid().duneLoadBalance( gs, elCount );
505 grid.myGrid().duneExchangeDynamicState();
513 if( grid.globalIdSet_ )
514 grid.globalIdSet_->updateIdSet();
525 template<
class DataHandle,
class DataType >
526 static void communicate (
const Grid &grid,
527 CommDataHandleIF< DataHandle, DataType > &data,
532 typedef CommDataHandleIF< DataHandle, DataType > DataHandleType;
533 typedef MakeableInterfaceObject< typename Grid::Traits::template Codim< 3 >::Entity > VertexObject;
534 typedef typename VertexObject::ImplementationType VertexImp;
535 typedef MakeableInterfaceObject< typename Grid::Traits::template Codim< 2 >::Entity > EdgeObject;
536 typedef typename EdgeObject::ImplementationType EdgeImp;
537 typedef MakeableInterfaceObject< typename Grid::Traits::template Codim< 1 >::Entity > FaceObject;
538 typedef typename FaceObject::ImplementationType FaceImp;
539 typedef MakeableInterfaceObject< typename Grid::Traits::template Codim< 0 >::Entity> ElementObject;
540 typedef typename ElementObject::ImplementationType ElementImp;
542 if( grid.comm().size() > 1 )
546 const typename Grid::LevelIndexSetImp *levelISet;
547 if( !grid.levelIndexVec_[ level ] )
548 levelISet =
new typename Grid::LevelIndexSetImp(
550 grid.template lbegin<0>( level ),
551 grid.template lend<0>( level ), level );
553 levelISet = grid.levelIndexVec_[ level ];
555 VertexObject vx( VertexImp( grid, level ) );
556 ALU3DSPACE GatherScatterLevelData< Grid, DataHandleType, 3 >
557 vertexData( grid, vx, Grid::getRealImplementation( vx ), data, *levelISet, level );
559 EdgeObject edge( EdgeImp( grid, level ) );
560 ALU3DSPACE GatherScatterLevelData< Grid, DataHandleType, 2 >
561 edgeData( grid, edge, Grid::getRealImplementation( edge ), data, *levelISet, level );
563 FaceObject face( FaceImp( grid, level ) );
564 ALU3DSPACE GatherScatterLevelData< Grid, DataHandleType, 1 >
565 faceData( grid, face, Grid::getRealImplementation( face ), data, *levelISet, level );
567 ElementObject element( ElementImp( grid, level ) );
568 ALU3DSPACE GatherScatterLevelData< Grid, DataHandleType, 0 >
569 elementData( grid, element, Grid::getRealImplementation( element ), data, *levelISet, level );
571 doCommunication( grid, vertexData, edgeData, faceData, elementData, iftype, dir );
573 if( !grid.levelIndexVec_[ level ] )
578 template<
class DataHandle,
class DataType >
579 static void communicate (
const Grid &grid,
580 CommDataHandleIF< DataHandle, DataType > &data,
584 typedef CommDataHandleIF< DataHandle, DataType > DataHandleType;
585 typedef MakeableInterfaceObject< typename Grid::Traits::template Codim< 3 >::Entity > VertexObject;
586 typedef typename VertexObject::ImplementationType VertexImp;
587 typedef MakeableInterfaceObject< typename Grid::Traits::template Codim< 2 >::Entity > EdgeObject;
588 typedef typename EdgeObject::ImplementationType EdgeImp;
589 typedef MakeableInterfaceObject< typename Grid::Traits::template Codim< 1 >::Entity > FaceObject;
590 typedef typename FaceObject::ImplementationType FaceImp;
591 typedef MakeableInterfaceObject< typename Grid::Traits::template Codim< 0 >::Entity> ElementObject;
592 typedef typename ElementObject::ImplementationType ElementImp;
594 if( grid.comm().size() > 1 )
596 VertexObject vx( VertexImp( grid, grid.maxLevel() ) );
597 ALU3DSPACE GatherScatterLeafData< Grid, DataHandleType, 3 >
598 vertexData( grid, vx, Grid::getRealImplementation( vx ), data );
600 EdgeObject edge( EdgeImp( grid, grid.maxLevel() ) );
601 ALU3DSPACE GatherScatterLeafData< Grid, DataHandleType, 2 >
602 edgeData( grid, edge, Grid::getRealImplementation( edge ), data );
604 FaceObject face( FaceImp( grid, grid.maxLevel()) );
605 ALU3DSPACE GatherScatterLeafData< Grid, DataHandleType, 1 >
606 faceData( grid, face, Grid::getRealImplementation( face ), data );
608 ElementObject element( ElementImp( grid, grid.maxLevel() ) );
609 ALU3DSPACE GatherScatterLeafData< Grid, DataHandleType, 0 >
610 elementData( grid, element, Grid::getRealImplementation( element ), data );
612 doCommunication( grid, vertexData, edgeData, faceData, elementData, iftype, dir );
617 doCommunication (
const Grid &grid,
625 dverb <<
"ALUGrid contains no overlap, therefore no communication for" << std::endl;
626 dverb <<
"Overlap_OverlapFront_Interface or Overlap_All_Interface interfaces!" << std::endl;
630 grid.myGrid().borderBorderCommunication(vertexData,edgeData,faceData,elementData);
635 grid.myGrid().interiorGhostCommunication(vertexData,edgeData,faceData,elementData);
638 grid.myGrid().ghostInteriorCommunication(vertexData,edgeData,faceData,elementData);
642 grid.myGrid().allAllCommunication(vertexData,edgeData,faceData,elementData);
644 DUNE_THROW( GridError,
"Wrong set of parameters in ALUGridCommHelper::doCommunication" );
647 #endif // #if ALU3DGRID_PARALLEL
651 template< ALU3dGr
idElementType elType,
class Comm >
659 template< ALU3dGr
idElementType elType,
class Comm >
660 template<
class DataHandle >
668 template< ALU3dGr
idElementType elType,
class Comm >
669 template <
class DataHandleImp,
class DataType>
679 template< ALU3dGr
idElementType elType,
class Comm >
680 template <
class DataHandleImp,
class DataType>
690 template< ALU3dGr
idElementType elType,
class Comm >
694 return "ALUCubeGrid";
696 return "ALUSimplexGrid";