1#ifndef DUNE_FEM_ADAPTATIONMANAGER_HH
2#define DUNE_FEM_ADAPTATIONMANAGER_HH
8#include <dune/common/timer.hh>
77 std::cerr <<
"WARNING: AdaptationManagerInterface::adapt: no adaptation manager assigned! \n";
86 return (am_) ? (am_->
adaptive()) :
false;
94 return (am_) ? (am_->
methodName()) :
"unknown method";
131 template <
class Gr
idType>
154 const std::string methodNames [] = {
"none",
"generic",
"callback" };
155 am = parameter.getEnum(
"fem.adaptation.method", methodNames, am);
159 void init(
int am,
const bool output)
173 std::cerr <<
"WARNING: AdaptationMethod: adaptation disabled for structured grid! \n";
179 std::cout <<
"Created AdaptationMethod: adaptation method = " <<
methodName() << std::endl;
190 case generic:
return "generic";
192 case none:
return "no adaptation";
193 default:
return "unknown method";
210 template <
class Gr
idType,
class RestProlOperatorImp >
218 template <
class AdaptManager,
class Gr
idImp,
bool isGoodGr
id>
219 struct CallAdaptationMethod
221 template <
class DofManagerImp,
class RPOpImp>
222 static void adapt(
const AdaptManager& am, GridImp & grid,
223 DofManagerImp& dm , RPOpImp& rpop,
227 if( adaptMethod == BaseType :: generic )
229 am.template genericAdapt<All_Partition> ();
234 if( adaptMethod == BaseType :: callback )
240 RPType restrictProlongHandle ( dm , rpop );
243 restrictProlongHandle.initialize();
246 grid.adapt( restrictProlongHandle );
249 restrictProlongHandle.finalize();
255 template <
class AdaptManager,
class Gr
idImp>
256 struct CallAdaptationMethod<AdaptManager,GridImp,false>
258 template <
class DofManagerImp,
class RPOpImp>
259 static void adapt(
const AdaptManager& am, GridImp & grid,
260 DofManagerImp& dm , RPOpImp& rpop,
264 if(adaptMethod != BaseType :: none )
269 am.template genericAdapt<All_Partition> ();
282 typedef typename GridType :: Traits :: LocalIdSet
LocalIdSet;
323 if( ! Fem :: MPIManager :: singleThreadMode() )
325 assert( Fem :: MPIManager :: singleThreadMode() );
326 DUNE_THROW(InvalidStateException,
"AdaptationManagerBase::adapt: only call in single thread mode!");
332 const bool supportsCallback = Capabilities :: supportsCallbackAdaptation< GridType > :: v;
333 CallAdaptationMethod< ThisType, GridType, supportsCallback >
334 :: adapt(*
this,grid_,dm_,rpOp_,this->adaptationMethod_);
337 adaptTime_ = timer.elapsed();
361 return DofManagerType :: instance( grid );
370 template <PartitionIteratorType pitype>
371 void genericAdapt ()
const
378 bool restr = grid_.preAdapt();
381 typedef typename GridType::LevelGridView MacroGridView;
382 typedef typename MacroGridView :: template Codim<0>::
383 template Partition<pitype> :: Iterator MacroIterator;
386 wasChanged_ = false ;
392 MacroGridView macroView = grid_.levelGridView( 0 );
399 MacroIterator endit = macroView.template end<0,pitype> ();
400 for(MacroIterator it = macroView.template begin<0,pitype>();
403 hierarchicRestrict( *it , dm_.indexSetRestrictProlongNoResize() );
411 dm_.resizeForRestrict();
416 MacroIterator endit = macroView.template end<0,pitype> ();
417 for(MacroIterator it = macroView.template begin<0,pitype>();
420 hierarchicRestrict( *it , rpOp_ );
428 const bool refined = grid_.adapt();
432 if( refined || restr )
443 MacroGridView macroView = grid_.levelGridView( 0 );
446 MacroIterator endit = macroView.template end<0,pitype> ();
447 for(MacroIterator it = macroView.template begin<0,pitype>();
450 hierarchicProlong( *it , rpOp_ );
455 if( dm_.notifyGlobalChange( wasChanged_ ) )
471 template <
class EntityType,
class RestrictOperatorType >
472 bool hierarchicRestrict (
const EntityType& entity, RestrictOperatorType & restop )
const
474 if( ! entity.isLeaf() )
477 bool doRestrict =
true;
480 const bool isGhost = entity.partitionType() == GhostEntity ;
483 const int childLevel = entity.level() + 1;
484 typedef typename EntityType::HierarchicIterator HierarchicIterator;
488 const HierarchicIterator endit = entity.hend( childLevel );
489 for(HierarchicIterator it = entity.hbegin( childLevel ); it != endit; ++it)
491 doRestrict &= hierarchicRestrict( *it , restop );
507 bool initialize =
true;
508 const HierarchicIterator endit = entity.hend( childLevel );
509 for(HierarchicIterator it = entity.hbegin( childLevel ); it != endit; ++it)
512 restop.restrictLocal( entity, *it , initialize);
516 restop.restrictFinalize(entity);
523 return entity.mightVanish();
526 template <
class EntityType,
class Pro
longOperatorType >
527 void hierarchicProlong (
const EntityType &entity, ProlongOperatorType & prolop )
const
529 typedef typename EntityType::HierarchicIterator HierarchicIterator;
535 bool initialize =
true;
538 const bool isGhost = entity.partitionType() == GhostEntity ;
540 const int maxLevel = grid_.maxLevel();
541 const HierarchicIterator endit = entity.hend( maxLevel );
542 for( HierarchicIterator it = entity.hbegin( maxLevel ); it != endit; ++it )
545 assert( !entity.isLeaf() );
547 const EntityType & son = *it;
558 EntityType vati = son.father();
559 prolop.prolongLocal( vati , son , initialize );
584 template <
class KeyType,
class ObjectType>
589 return new ObjectType(0);
602 template <
class Gr
idType,
class RestProlOperatorImp>
609 typedef const GridType* KeyType;
611 typedef size_t ObjectType;
624 ObjectType& referenceCounter_;
651 , referenceCounter_(
ProviderType :: getObject( &grid ) )
652 , balanceStep_( parameter.getValue< int >(
"fem.loadbalancing.step", 1 ) )
653 , balanceCounter_( balanceCounter )
655 if( ++referenceCounter_ > 1 )
656 DUNE_THROW(InvalidStateException,
"Only one instance of AdaptationManager allowed per grid instance");
658 std::cout <<
"Created LoadBalancer: balanceStep = " << balanceStep_ << std::endl;
686 -- referenceCounter_;
687 ProviderType :: removeObject( referenceCounter_ );
694 rpOp_.initialize () ;
697 const bool result = Base2Type :: loadBalance( );
707 return Base2Type::loadBalanceTime();
714 BaseType :: adapt ();
717 if( this->adaptive() && (balanceStep_ > 0) )
720 const bool callBalance = (++balanceCounter_ >= balanceStep_);
724 int willCall = (callBalance) ? 1 : 0;
725 const int iCall = willCall;
728 Base2Type::grid_.comm().broadcast(&willCall, 1 , 0);
730 assert( willCall == iCall );
742 Base2Type::communicate();
753 std::tuple<const int& > value( balanceCounter_ );
760 std::tuple< int& > value( balanceCounter_ );
766 const int balanceStep_ ;
784 template<
class DiscreteFunctionSpace,
class DataProjection >
797 using GridType =
typename DiscreteFunctionSpaceType::GridType;
810 dofManager_(
DofManagerType::instance( space.gridPart().grid() ) ),
811 commList_( dataProjection_ ),
840 if( ! Fem :: MPIManager :: singleThreadMode() )
842 assert( Fem :: MPIManager :: singleThreadMode() );
843 DUNE_THROW(InvalidStateException,
"AdaptationManager::adapt: only call in single thread mode!");
849 space().adapt( wrapper );
851 if( dofManager().notifyGlobalChange(
static_cast< bool >( wrapper ) ) )
852 dofManager().compress();
854 commList_.exchange();
856 time_ = timer.elapsed();
860 const char *
methodName ()
const {
return "discrete function space adaptation"; }
884 DiscreteFunctionSpaceType &space () {
return space_.get(); }
886 const DiscreteFunctionSpaceType &space ()
const {
return space_.get(); }
888 DofManagerType &dofManager () {
return dofManager_.get(); }
890 const DofManagerType &dofManager ()
const {
return dofManager_.get(); }
892 std::reference_wrapper< DiscreteFunctionSpaceType > space_;
893 DataProjectionType dataProjection_;
894 std::reference_wrapper< DofManagerType > dofManager_;
895 mutable CommunicationManagerList commList_;
902 template<
class DiscreteFunctionSpace,
class DataProjection >
913 : dataProjection_( dataProjection ),
914 dofManager_( dofManager ),
921 const std::vector< std::size_t > &origin,
922 const std::vector< std::size_t > &destination )
924 dofManager_.get().resizeMemory();
925 dataProjection_.get()( entity, prior, present, origin, destination );
929 template <
class TemporaryStorage>
930 void operator() ( TemporaryStorage& tmp )
932 dataProjection_.get()( tmp );
936 explicit operator bool ()
const
942 std::reference_wrapper< DataProjectionType > dataProjection_;
943 std::reference_wrapper< DofManagerType > dofManager_;
963 template <
class Gr
idType>
964 static void apply(GridType& grid,
const int step)
967 DofManagerType& dm = DofManagerType :: instance(grid);
968 grid.globalRefine(step);
986 template <
class Gr
idType>
990 DofManagerType& dm = DofManagerType :: instance(grid);
interfaces and wrappers needed for the callback adaptation provided by AlbertaGrid and ALUGrid
Definition: bindguard.hh:11
static void backupValue(const std::string &token, const T &value)
Definition: persistencemanager.hh:395
static void restoreValue(const std::string &token, T &value)
Definition: persistencemanager.hh:401
base class for auto persistent objects
Definition: persistencemanager.hh:580
static ParameterContainer & container()
Definition: io/parameter.hh:193
static bool verbose()
obtain the cached value for fem.verbose
Definition: io/parameter.hh:445
Definition: misc/capabilities.hh:151
static bool isMainThread()
return true if the current thread is the main thread (i.e. thread 0)
Definition: mpimanager.hh:427
Definition: objpointer.hh:42
AdaptationManagerInterface class.
Definition: adaptationmanager.hh:60
virtual double adaptationTime() const
time that last adaptation cycle took
Definition: adaptationmanager.hh:120
virtual const char * methodName() const
returns name of adaptation method
Definition: adaptationmanager.hh:92
virtual void adapt()
on call of this method the internal adaptation operator is called.
Definition: adaptationmanager.hh:71
virtual bool adaptive() const
returns true if adaptation manager as adaptation method different to NONE
Definition: adaptationmanager.hh:84
virtual ~AdaptationManagerInterface()
destructor
Definition: adaptationmanager.hh:66
virtual bool loadBalance()
call load balance, returns true if grid was changed
Definition: adaptationmanager.hh:108
AdaptationManagerInterface()
default constructor
Definition: adaptationmanager.hh:63
AdaptationManagerInterface & operator=(const AdaptationManagerInterface &am)
Assignment operator, pointer to adaptation manager is stored.
Definition: adaptationmanager.hh:100
virtual int balanceCounter() const
Definition: adaptationmanager.hh:114
AdaptationMethod is a simple adaptation method reader class.
Definition: adaptationmanager.hh:133
AdaptationMethod(const GridType &grid, const ParameterReader ¶meter=Parameter::container())
constructor of AdaptationMethod The following optional parameters are used
Definition: adaptationmanager.hh:149
virtual ~AdaptationMethod()
virtual destructor
Definition: adaptationmanager.hh:184
AdaptationMethodType adaptationMethod_
method identifier
Definition: adaptationmanager.hh:202
virtual const char * methodName() const
returns name of adaptation method
Definition: adaptationmanager.hh:187
virtual bool adaptive() const
returns true if adaptation manager as adaptation method different to NONE
Definition: adaptationmanager.hh:198
AdaptationMethodType
type of adaptation method
Definition: adaptationmanager.hh:136
@ none
no adaptation is performed
Definition: adaptationmanager.hh:136
@ generic
a generic restriction and prolongation algorithm is used
Definition: adaptationmanager.hh:137
@ callback
the callback mechanism from AlbertaGrid and ALUGrid is used
Definition: adaptationmanager.hh:138
This class manages the adaptation process. If the method adapt is called, then the grid is adapted an...
Definition: adaptationmanager.hh:214
virtual int balanceCounter() const
default load balancing counter is zero
Definition: adaptationmanager.hh:347
virtual ~AdaptationManagerBase()
destructor
Definition: adaptationmanager.hh:303
AdaptationManagerBase(GridType &grid, RestProlOperatorImp &rpOp, const ParameterReader ¶meter=Parameter::container())
constructor of AdaptationManagerBase The following optional parameter can be used
Definition: adaptationmanager.hh:293
double adaptTime_
time that adaptation took
Definition: adaptationmanager.hh:577
GridType & grid_
corresponding grid
Definition: adaptationmanager.hh:568
bool wasChanged_
flag for restriction
Definition: adaptationmanager.hh:580
RestProlOperatorImp & rpOp_
Restriction and Prolongation Operator.
Definition: adaptationmanager.hh:574
virtual bool loadBalance()
default load balancing method which does nothing
Definition: adaptationmanager.hh:341
virtual double adaptationTime() const
time that last adaptation cycle took
Definition: adaptationmanager.hh:353
static DofManagerType & getDofManager(const GridType &grid)
Definition: adaptationmanager.hh:359
GridType::Traits::LocalIdSet LocalIdSet
Definition: adaptationmanager.hh:282
virtual void adapt()
according to adaption method parameter the adaption procedure is done, 0 == no adaptation 1 == generi...
Definition: adaptationmanager.hh:320
RestProlOperatorImp & getRestProlOp()
Definition: adaptationmanager.hh:308
DofManagerType & dm_
DofManager corresponding to grid.
Definition: adaptationmanager.hh:571
factory class to create adaptation manager reference counter
Definition: adaptationmanager.hh:586
static ObjectType * createObject(const KeyType &key)
Definition: adaptationmanager.hh:587
static void deleteObject(ObjectType *obj)
Definition: adaptationmanager.hh:591
This class manages the adaptation process including a load balancing after the adaptation step....
Definition: adaptationmanager.hh:607
int balanceCounter() const
returns actual balanceCounter for checkpointing
Definition: adaptationmanager.hh:748
void restore()
retore internal data
Definition: adaptationmanager.hh:758
AdaptationManager(GridType &grid, RestProlOperatorImp &rpOp, int balanceCounter, const ParameterReader ¶meter=Parameter::container())
constructor of AdaptationManager
Definition: adaptationmanager.hh:648
virtual double loadBalanceTime() const
time that last load balance cycle took
Definition: adaptationmanager.hh:705
void backup() const
backup internal data
Definition: adaptationmanager.hh:751
virtual bool loadBalance()
call load balance, returns true if grid was changed
Definition: adaptationmanager.hh:691
virtual void adapt()
on call of this method the internal adaptation operator is called.
Definition: adaptationmanager.hh:711
AdaptationManager(GridType &grid, RestProlOperatorImp &rpOp, const ParameterReader ¶meter=Parameter::container())
constructor of AdaptationManager
Definition: adaptationmanager.hh:678
~AdaptationManager()
destructor decreasing reference counter
Definition: adaptationmanager.hh:684
Manages the testriction and prolongation of discrete functions in -adaptive computations.
Definition: adaptationmanager.hh:787
void adapt()
perform adaptation
Definition: adaptationmanager.hh:837
AdaptationManager(DiscreteFunctionSpaceType &space, DataProjectionType &&dataProjection)
Definition: adaptationmanager.hh:807
int balanceCounter() const
please doc me
Definition: adaptationmanager.hh:875
bool adaptive() const
returns true
Definition: adaptationmanager.hh:834
AdaptationManager(const ThisType &)=delete
Deleted methods.
double adaptationTime() const
return time spent on adaptation
Definition: adaptationmanager.hh:863
DataProjection & dataProjection()
Definition: adaptationmanager.hh:882
bool loadBalance()
please doc me
Definition: adaptationmanager.hh:872
const char * methodName() const
return name of adaptation method
Definition: adaptationmanager.hh:860
double loadBalanceTime() const
please doc me
Definition: adaptationmanager.hh:878
Definition: adaptationmanager.hh:905
typename BaseType::EntityType EntityType
Definition: adaptationmanager.hh:910
DataProjectionWrapper(DataProjectionType &dataProjection, DofManagerType &dofManager)
Definition: adaptationmanager.hh:912
typename BaseType::BasisFunctionSetType BasisFunctionSetType
Definition: adaptationmanager.hh:909
A class with one static method apply to globally refine a grid. All index sets are adapted to the new...
Definition: adaptationmanager.hh:957
static void apply(GridType &grid, const int step)
apply global refinement and also adjust index sets and managed dof storage. However,...
Definition: adaptationmanager.hh:964
A class with one static method apply for invoking the local adaptation procedure on a given grid inst...
Definition: adaptationmanager.hh:981
static void apply(GridType &grid)
apply local refinement and also adjust index sets and managed dof storage. However,...
Definition: adaptationmanager.hh:987
Definition: adaptcallbackhandle.hh:26
Definition: dofmanager.hh:761
Abstract definition of the local restriction and prolongation of discrete functions.
Definition: dataprojection/dataprojection.hh:29
typename BasisFunctionSetType::EntityType EntityType
entity type
Definition: dataprojection/dataprojection.hh:38
typename DiscreteFunctionSpaceType::BasisFunctionSetType BasisFunctionSetType
basis function set type
Definition: dataprojection/dataprojection.hh:36
Interface class for load balancing.
Definition: loadbalancer.hh:37
This class manages the adaptation process. If the method adapt is called, then the grid is adapted an...
Definition: loadbalancer.hh:66
Singleton list for key/object pairs.
Definition: singletonlist.hh:53