4 #include <dune/common/stdstreams.hh>
10 #include "datahandle.hh"
19 template< ALU3dGr
idElementType elType,
class Comm >
33 , localIdSet_( *this )
34 , levelIndexVec_(MAXL,0) , leafIndexSet_(0)
35 , referenceElement_( elType ==
tetra
39 #ifdef USE_SMP_PARALLEL
44 , lockPostAdapt_( false )
49 , refinementType_( refinementType )
51 assert( elType ==
tetra || elType ==
hexa );
53 geomTypes_.resize( dimension+1 );
55 for(
int codim = 0; codim <= dimension; ++codim )
58 tmpType.makeSimplex( dimension - codim );
60 tmpType.makeCube( dimension - codim );
62 geomTypes_[ codim ].push_back( tmpType );
66 checkMacroGridFile( macroTriangFilename );
68 mygrid_ = createALUGrid( macroTriangFilename );
71 dverb <<
"************************************************" << std::endl;
72 dverb <<
"Created grid on p=" << comm().rank() << std::endl;
73 dverb <<
"************************************************" << std::endl;
81 template< ALU3dGr
idElementType elType,
class Comm >
87 return myGrid().indexManager(codim).getMaxIndex();
91 template< ALU3dGr
idElementType elType,
class Comm >
95 return myGrid().indexManager(codim).getMaxIndex();
99 template< ALU3dGr
idElementType elType,
class Comm >
106 template< ALU3dGr
idElementType elType,
class Comm >
116 template< ALU3dGr
idElementType elType,
class Comm >
117 template<
int cd, PartitionIteratorType pitype >
121 assert( level >= 0 );
123 if( level > maxlevel_ )
124 return this->
template lend<cd,pitype> (level);
130 template< ALU3dGr
idElementType elType,
class Comm >
131 template<
int cd, PartitionIteratorType pitype >
135 assert( level >= 0 );
141 template< ALU3dGr
idElementType elType,
class Comm >
146 return this->
template lbegin<cd,All_Partition>( level );
150 template< ALU3dGr
idElementType elType,
class Comm >
152 inline typename ALU3dGrid< elType, Comm >::Traits::template Codim< cd >::template Partition< All_Partition >::LevelIterator
155 assert( level >= 0 );
156 return this->
template lend<cd,All_Partition>( level );
165 template< ALU3dGr
idElementType elType,
class Comm >
166 template<
int cd, PartitionIteratorType pitype >
167 inline typename ALU3dGrid< elType, Comm >::Traits::template Codim< cd >::template Partition< pitype >::LeafIterator
168 ALU3dGrid< elType, Comm >::createLeafIteratorBegin (
int level )
const
170 assert( level >= 0 );
171 return ALU3dGridLeafIterator< cd, pitype, const ThisType >( factory(), level, true );
175 template< ALU3dGr
idElementType elType,
class Comm >
176 template<
int cd, PartitionIteratorType pitype >
177 inline typename ALU3dGrid< elType, Comm >::Traits::template Codim< cd >::template Partition< pitype >::LeafIterator
178 ALU3dGrid< elType, Comm >::leafbegin (
int level )
const
180 return createLeafIteratorBegin<cd, pitype> (level) ;
184 template< ALU3dGr
idElementType elType,
class Comm >
186 inline typename ALU3dGrid< elType, Comm >::Traits::template Codim< cd >::LeafIterator
187 ALU3dGrid< elType, Comm >::leafbegin (
int level )
const
189 return createLeafIteratorBegin<cd, All_Partition> (level) ;
193 template< ALU3dGr
idElementType elType,
class Comm >
194 template<
int cd, PartitionIteratorType pitype >
195 inline typename ALU3dGrid< elType, Comm >::Traits::template Codim< cd >::template Partition< pitype >::LeafIterator
196 ALU3dGrid< elType, Comm >::leafbegin ()
const
198 return createLeafIteratorBegin< cd, pitype > (maxlevel_) ;
202 template< ALU3dGr
idElementType elType,
class Comm >
204 inline typename ALU3dGrid< elType, Comm >::Traits::template Codim< cd >::LeafIterator
205 ALU3dGrid< elType, Comm >::leafbegin ()
const
207 return createLeafIteratorBegin< cd, All_Partition> (maxlevel_) ;
211 template< ALU3dGr
idElementType elType,
class Comm >
212 inline typename ALU3dGrid< elType, Comm >::LeafIteratorType
213 ALU3dGrid< elType, Comm >::leafbegin (
int level )
const
215 return createLeafIteratorBegin<0, All_Partition> (level) ;
219 template< ALU3dGr
idElementType elType,
class Comm >
220 inline typename ALU3dGrid< elType, Comm >::LeafIteratorType
221 ALU3dGrid< elType, Comm >::leafbegin ()
const
223 return createLeafIteratorBegin<0, All_Partition> (maxlevel_) ;
232 template< ALU3dGr
idElementType elType,
class Comm >
233 template<
int cd, PartitionIteratorType pitype >
234 inline typename ALU3dGrid< elType, Comm >::Traits::template Codim< cd >::template Partition< pitype >::LeafIterator
235 ALU3dGrid< elType, Comm >::createLeafIteratorEnd (
int level )
const
237 assert( level >= 0 );
238 return ALU3dGridLeafIterator<cd, pitype, const MyType> ( factory() , level);
242 template< ALU3dGr
idElementType elType,
class Comm >
243 template<
int cd, PartitionIteratorType pitype >
244 inline typename ALU3dGrid< elType, Comm >::Traits::template Codim< cd >::template Partition< pitype >::LeafIterator
245 ALU3dGrid< elType, Comm >::leafend (
int level )
const
247 return createLeafIteratorEnd < cd, pitype> (level);
251 template< ALU3dGr
idElementType elType,
class Comm >
253 inline typename ALU3dGrid< elType, Comm >::Traits::template Codim< cd >::LeafIterator
254 ALU3dGrid< elType, Comm >::leafend (
int level )
const
256 return createLeafIteratorEnd < cd, All_Partition> (level);
260 template< ALU3dGr
idElementType elType,
class Comm >
261 template<
int cd, PartitionIteratorType pitype >
262 inline typename ALU3dGrid< elType, Comm >::Traits::template Codim< cd >::template Partition< pitype >::LeafIterator
263 ALU3dGrid< elType, Comm >::leafend ()
const
265 return createLeafIteratorEnd < cd, pitype> (maxlevel_);
269 template< ALU3dGr
idElementType elType,
class Comm >
271 inline typename ALU3dGrid< elType, Comm >::Traits::template Codim< cd >::LeafIterator
272 ALU3dGrid< elType, Comm >::leafend ()
const
274 return createLeafIteratorEnd < cd, All_Partition> (maxlevel_);
278 template< ALU3dGr
idElementType elType,
class Comm >
279 inline typename ALU3dGrid< elType, Comm >::LeafIteratorType
280 ALU3dGrid< elType, Comm >::leafend (
int level )
const
282 return createLeafIteratorEnd <0, All_Partition> (level);
286 template< ALU3dGr
idElementType elType,
class Comm >
287 inline typename ALU3dGrid< elType, Comm >::LeafIteratorType
288 ALU3dGrid< elType, Comm >::leafend ()
const
290 return createLeafIteratorEnd <0,All_Partition> (maxlevel_);
297 template< ALU3dGr
idElementType elType,
class Comm >
301 bool marked = (this->getRealImplementation( entity )).mark(ref);
304 if(ref > 0) ++refineMarked_;
305 if(ref < 0) ++coarsenMarked_;
312 template< ALU3dGr
idElementType elType,
class Comm >
316 return this->getRealImplementation( entity ).getMark();
321 template< ALU3dGr
idElementType elType,
class Comm >
322 template<
class Gr
idImp,
class DataHandle >
327 assert( (refCount + maxLevel()) < MAXL );
329 for(
int count = refCount; count > 0; --count )
341 template< ALU3dGr
idElementType elType,
class Comm >
342 template<
class Gr
idImp,
class DataHandle >
350 EntityObject father( EntityImp( factory(), this->maxLevel() ) );
351 EntityObject son ( EntityImp( factory(), this->maxLevel() ) );
353 int defaultChunk = newElementsChunk_;
354 int actChunk = refineEstimate_ * refineMarked_;
357 int newElements =
std::max( actChunk , defaultChunk );
360 bool mightCoarse = preAdapt();
364 bool refined = false ;
369 ALU3DSPACE AdaptRestrictProlongGlSet< MyType, AdaptDataHandle, GlobalIdSetImp >
371 father,this->getRealImplementation(father),
372 son, this->getRealImplementation(son),
376 refined = myGrid().duneAdapt(rp);
380 ALU3DSPACE AdaptRestrictProlongImpl< MyType, AdaptDataHandle >
382 father,this->getRealImplementation(father),
383 son, this->getRealImplementation(son),
386 refined = myGrid().duneAdapt(rp);
389 if(refined || mightCoarse)
413 template< ALU3dGr
idElementType elType,
class Comm >
414 struct ALU3dGridCommHelper;
416 template< ALU3dGr
idElementType elType >
417 struct ALU3dGridCommHelper< elType, No_Comm >
423 template<
class DataHandle >
426 template<
class DataHandle,
class DataType >
427 static void communicate (
const Grid &grid,
434 template<
class DataHandle,
class DataType >
435 static void communicate (
const Grid &grid,
442 #if ALU3DGRID_PARALLEL
443 template< ALU3dGr
idElementType elType >
444 struct ALU3dGridCommHelper< elType, MPI_Comm >
446 typedef ALU3dGrid< elType, MPI_Comm > Grid;
449 static bool loadBalance ( Grid &grid )
451 if( grid.comm().size() <= 1 )
454 const bool changed = grid.myGrid().duneLoadBalance();
458 grid.myGrid().duneExchangeDynamicState();
466 if( grid.globalIdSet_ )
467 grid.globalIdSet_->updateIdSet();
477 template<
class DataHandle >
478 static bool loadBalance ( Grid &grid, DataHandle &data )
480 if( grid.comm().size() <= 1 )
483 typedef typename Grid :: EntityObject EntityObject;
484 typedef typename EntityObject::ImplementationType EntityImp;
485 EntityObject en ( EntityImp( grid.factory(), grid.maxLevel()) );
486 EntityObject father ( EntityImp( grid.factory(), grid.maxLevel()) );
487 EntityObject son ( EntityImp( grid.factory(), grid.maxLevel()) );
489 typedef ALU3DSPACE LoadBalanceElementCount< Grid, DataHandle > LDBElCountType;
493 LDBElCountType elCount( grid,
494 father, Grid::getRealImplementation( father ),
495 son, Grid::getRealImplementation( son ),
498 ALU3DSPACE GatherScatterLoadBalance< Grid, DataHandle, LDBElCountType >
499 gs( grid, en, Grid::getRealImplementation( en ), data, elCount );
502 const bool changed = grid.myGrid().duneLoadBalance( gs, elCount );
507 grid.myGrid().duneExchangeDynamicState();
515 if( grid.globalIdSet_ )
516 grid.globalIdSet_->updateIdSet();
527 template<
class DataHandle,
class DataType >
528 static void communicate (
const Grid &grid,
529 CommDataHandleIF< DataHandle, DataType > &data,
534 typedef CommDataHandleIF< DataHandle, DataType > DataHandleType;
535 typedef MakeableInterfaceObject< typename Grid::Traits::template Codim< 3 >::Entity > VertexObject;
536 typedef typename VertexObject::ImplementationType VertexImp;
537 typedef MakeableInterfaceObject< typename Grid::Traits::template Codim< 2 >::Entity > EdgeObject;
538 typedef typename EdgeObject::ImplementationType EdgeImp;
539 typedef MakeableInterfaceObject< typename Grid::Traits::template Codim< 1 >::Entity > FaceObject;
540 typedef typename FaceObject::ImplementationType FaceImp;
541 typedef MakeableInterfaceObject< typename Grid::Traits::template Codim< 0 >::Entity> ElementObject;
542 typedef typename ElementObject::ImplementationType ElementImp;
544 if( grid.comm().size() > 1 )
548 const typename Grid::LevelIndexSetImp *levelISet;
549 if( !grid.levelIndexVec_[ level ] )
550 levelISet =
new typename Grid::LevelIndexSetImp(
552 grid.template lbegin<0>( level ),
553 grid.template lend<0>( level ), level );
555 levelISet = grid.levelIndexVec_[ level ];
557 VertexObject vx( VertexImp( grid.factory(), level ) );
558 ALU3DSPACE GatherScatterLevelData< Grid, DataHandleType, 3 >
559 vertexData( grid, vx, Grid::getRealImplementation( vx ), data, *levelISet, level );
561 EdgeObject edge( EdgeImp( grid.factory(), level ) );
562 ALU3DSPACE GatherScatterLevelData< Grid, DataHandleType, 2 >
563 edgeData( grid, edge, Grid::getRealImplementation( edge ), data, *levelISet, level );
565 FaceObject face( FaceImp( grid.factory(), level ) );
566 ALU3DSPACE GatherScatterLevelData< Grid, DataHandleType, 1 >
567 faceData( grid, face, Grid::getRealImplementation( face ), data, *levelISet, level );
569 ElementObject element( ElementImp( grid.factory(), level ) );
570 ALU3DSPACE GatherScatterLevelData< Grid, DataHandleType, 0 >
571 elementData( grid, element, Grid::getRealImplementation( element ), data, *levelISet, level );
573 doCommunication( grid, vertexData, edgeData, faceData, elementData, iftype, dir );
575 if( !grid.levelIndexVec_[ level ] )
580 template<
class DataHandle,
class DataType >
581 static void communicate (
const Grid &grid,
582 CommDataHandleIF< DataHandle, DataType > &data,
586 typedef CommDataHandleIF< DataHandle, DataType > DataHandleType;
587 typedef MakeableInterfaceObject< typename Grid::Traits::template Codim< 3 >::Entity > VertexObject;
588 typedef typename VertexObject::ImplementationType VertexImp;
589 typedef MakeableInterfaceObject< typename Grid::Traits::template Codim< 2 >::Entity > EdgeObject;
590 typedef typename EdgeObject::ImplementationType EdgeImp;
591 typedef MakeableInterfaceObject< typename Grid::Traits::template Codim< 1 >::Entity > FaceObject;
592 typedef typename FaceObject::ImplementationType FaceImp;
593 typedef MakeableInterfaceObject< typename Grid::Traits::template Codim< 0 >::Entity> ElementObject;
594 typedef typename ElementObject::ImplementationType ElementImp;
596 if( grid.comm().size() > 1 )
598 VertexObject vx( VertexImp( grid.factory(), grid.maxLevel() ) );
599 ALU3DSPACE GatherScatterLeafData< Grid, DataHandleType, 3 >
600 vertexData( grid, vx, Grid::getRealImplementation( vx ), data );
602 EdgeObject edge( EdgeImp( grid.factory(), grid.maxLevel() ) );
603 ALU3DSPACE GatherScatterLeafData< Grid, DataHandleType, 2 >
604 edgeData( grid, edge, Grid::getRealImplementation( edge ), data );
606 FaceObject face( FaceImp( grid.factory(), grid.maxLevel()) );
607 ALU3DSPACE GatherScatterLeafData< Grid, DataHandleType, 1 >
608 faceData( grid, face, Grid::getRealImplementation( face ), data );
610 ElementObject element( ElementImp( grid.factory(), grid.maxLevel() ) );
611 ALU3DSPACE GatherScatterLeafData< Grid, DataHandleType, 0 >
612 elementData( grid, element, Grid::getRealImplementation( element ), data );
614 doCommunication( grid, vertexData, edgeData, faceData, elementData, iftype, dir );
619 doCommunication (
const Grid &grid,
627 dverb <<
"ALUGrid contains no overlap, therefore no communication for" << std::endl;
628 dverb <<
"Overlap_OverlapFront_Interface or Overlap_All_Interface interfaces!" << std::endl;
632 grid.myGrid().borderBorderCommunication(vertexData,edgeData,faceData,elementData);
637 grid.myGrid().interiorGhostCommunication(vertexData,edgeData,faceData,elementData);
640 grid.myGrid().ghostInteriorCommunication(vertexData,edgeData,faceData,elementData);
644 grid.myGrid().allAllCommunication(vertexData,edgeData,faceData,elementData);
646 DUNE_THROW( GridError,
"Wrong set of parameters in ALUGridCommHelper::doCommunication" );
649 #endif // #if ALU3DGRID_PARALLEL
653 template< ALU3dGr
idElementType elType,
class Comm >
656 return ALU3dGridCommHelper< elType, Comm >::loadBalance( *
this );
661 template< ALU3dGr
idElementType elType,
class Comm >
662 template<
class DataHandle >
665 return ALU3dGridCommHelper< elType, Comm >::loadBalance( *
this, data );
670 template< ALU3dGr
idElementType elType,
class Comm >
671 template <
class DataHandleImp,
class DataType>
676 ALU3dGridCommHelper< elType, Comm >::communicate( *
this, data, iftype, dir, level );
681 template< ALU3dGr
idElementType elType,
class Comm >
682 template <
class DataHandleImp,
class DataType>
687 ALU3dGridCommHelper< elType, Comm >::communicate( *
this, data, iftype, dir );
692 template< ALU3dGr
idElementType elType,
class Comm >
696 return "ALUCubeGrid";
698 return "ALUSimplexGrid";