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 assert( Fem :: ThreadManager :: singleThreadMode() );
328 const bool supportsCallback = Capabilities :: supportsCallbackAdaptation< GridType > :: v;
329 CallAdaptationMethod< ThisType, GridType, supportsCallback >
330 :: adapt(*
this,grid_,dm_,rpOp_,this->adaptationMethod_);
333 adaptTime_ = timer.elapsed();
357 return DofManagerType :: instance( grid );
366 template <PartitionIteratorType pitype>
367 void genericAdapt ()
const
374 bool restr = grid_.preAdapt();
377 typedef typename GridType::LevelGridView MacroGridView;
378 typedef typename MacroGridView :: template Codim<0>::
379 template Partition<pitype> :: Iterator MacroIterator;
382 wasChanged_ = false ;
388 MacroGridView macroView = grid_.levelGridView( 0 );
395 MacroIterator endit = macroView.template end<0,pitype> ();
396 for(MacroIterator it = macroView.template begin<0,pitype>();
399 hierarchicRestrict( *it , dm_.indexSetRestrictProlongNoResize() );
407 dm_.resizeForRestrict();
412 MacroIterator endit = macroView.template end<0,pitype> ();
413 for(MacroIterator it = macroView.template begin<0,pitype>();
416 hierarchicRestrict( *it , rpOp_ );
424 const bool refined = grid_.adapt();
428 if( refined || restr )
439 MacroGridView macroView = grid_.levelGridView( 0 );
442 MacroIterator endit = macroView.template end<0,pitype> ();
443 for(MacroIterator it = macroView.template begin<0,pitype>();
446 hierarchicProlong( *it , rpOp_ );
451 if( dm_.notifyGlobalChange( wasChanged_ ) )
467 template <
class EntityType,
class RestrictOperatorType >
468 bool hierarchicRestrict (
const EntityType& entity, RestrictOperatorType & restop )
const
470 if( ! entity.isLeaf() )
473 bool doRestrict =
true;
476 const bool isGhost = entity.partitionType() == GhostEntity ;
479 const int childLevel = entity.level() + 1;
480 typedef typename EntityType::HierarchicIterator HierarchicIterator;
484 const HierarchicIterator endit = entity.hend( childLevel );
485 for(HierarchicIterator it = entity.hbegin( childLevel ); it != endit; ++it)
487 doRestrict &= hierarchicRestrict( *it , restop );
503 bool initialize =
true;
504 const HierarchicIterator endit = entity.hend( childLevel );
505 for(HierarchicIterator it = entity.hbegin( childLevel ); it != endit; ++it)
508 restop.restrictLocal( entity, *it , initialize);
512 restop.restrictFinalize(entity);
519 return entity.mightVanish();
522 template <
class EntityType,
class Pro
longOperatorType >
523 void hierarchicProlong (
const EntityType &entity, ProlongOperatorType & prolop )
const
525 typedef typename EntityType::HierarchicIterator HierarchicIterator;
531 bool initialize =
true;
534 const bool isGhost = entity.partitionType() == GhostEntity ;
536 const int maxLevel = grid_.maxLevel();
537 const HierarchicIterator endit = entity.hend( maxLevel );
538 for( HierarchicIterator it = entity.hbegin( maxLevel ); it != endit; ++it )
541 assert( !entity.isLeaf() );
543 const EntityType & son = *it;
554 EntityType vati = son.father();
555 prolop.prolongLocal( vati , son , initialize );
580 template <
class KeyType,
class ObjectType>
585 return new ObjectType(0);
598 template <
class Gr
idType,
class RestProlOperatorImp>
605 typedef const GridType* KeyType;
607 typedef size_t ObjectType;
617 using BaseType :: rpOp_;
620 ObjectType& referenceCounter_;
647 , referenceCounter_(
ProviderType :: getObject( &grid ) )
648 , balanceStep_( parameter.getValue< int >(
"fem.loadbalancing.step", 1 ) )
649 , balanceCounter_( balanceCounter )
651 if( ++referenceCounter_ > 1 )
652 DUNE_THROW(InvalidStateException,
"Only one instance of AdaptationManager allowed per grid instance");
654 std::cout <<
"Created LoadBalancer: balanceStep = " << balanceStep_ << std::endl;
682 -- referenceCounter_;
683 ProviderType :: removeObject( referenceCounter_ );
690 rpOp_.initialize () ;
693 const bool result = Base2Type :: loadBalance( );
703 return Base2Type::loadBalanceTime();
710 BaseType :: adapt ();
713 if( this->adaptive() && (balanceStep_ > 0) )
716 const bool callBalance = (++balanceCounter_ >= balanceStep_);
720 int willCall = (callBalance) ? 1 : 0;
721 const int iCall = willCall;
724 Base2Type::grid_.comm().broadcast(&willCall, 1 , 0);
726 assert( willCall == iCall );
738 Base2Type::communicate();
749 std::tuple<const int& > value( balanceCounter_ );
756 std::tuple< int& > value( balanceCounter_ );
762 const int balanceStep_ ;
780 template<
class DiscreteFunctionSpace,
class DataProjection >
793 using GridType =
typename DiscreteFunctionSpaceType::GridType;
806 dofManager_(
DofManagerType::instance( space.gridPart().grid() ) ),
807 commList_( dataProjection_ ),
840 space().adapt( wrapper );
842 if( dofManager().notifyGlobalChange(
static_cast< bool >( wrapper ) ) )
843 dofManager().compress();
845 commList_.exchange();
847 time_ = timer.elapsed();
851 const char *
methodName ()
const {
return "discrete function space adaptation"; }
875 DiscreteFunctionSpaceType &space () {
return space_.get(); }
877 const DiscreteFunctionSpaceType &space ()
const {
return space_.get(); }
879 DofManagerType &dofManager () {
return dofManager_.get(); }
881 const DofManagerType &dofManager ()
const {
return dofManager_.get(); }
883 std::reference_wrapper< DiscreteFunctionSpaceType > space_;
884 DataProjectionType dataProjection_;
885 std::reference_wrapper< DofManagerType > dofManager_;
886 mutable CommunicationManagerList commList_;
893 template<
class DiscreteFunctionSpace,
class DataProjection >
904 : dataProjection_( dataProjection ),
905 dofManager_( dofManager ),
912 const std::vector< std::size_t > &origin,
913 const std::vector< std::size_t > &destination )
915 dofManager_.get().resizeMemory();
916 dataProjection_.get()( entity, prior, present, origin, destination );
920 template <
class TemporaryStorage>
921 void operator() ( TemporaryStorage& tmp )
923 dataProjection_.get()( tmp );
927 explicit operator bool ()
const
933 std::reference_wrapper< DataProjectionType > dataProjection_;
934 std::reference_wrapper< DofManagerType > dofManager_;
954 template <
class Gr
idType>
955 static void apply(GridType& grid,
const int step)
958 DofManagerType& dm = DofManagerType :: instance(grid);
959 grid.globalRefine(step);
977 template <
class Gr
idType>
981 DofManagerType& dm = DofManagerType :: instance(grid);
interfaces and wrappers needed for the callback adaptation provided by AlbertaGrid and ALUGrid
Definition: bindguard.hh:11
base class for persistent objects
Definition: persistencemanager.hh:101
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 isMaster()
return true if the current thread is the master thread (i.e. thread 0)
Definition: threadmanager.hh:68
static bool singleThreadMode()
returns true if program is operating on one thread currently
Definition: threadmanager.hh:74
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:343
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:573
GridType & grid_
corresponding grid
Definition: adaptationmanager.hh:564
bool wasChanged_
flag for restriction
Definition: adaptationmanager.hh:576
RestProlOperatorImp & rpOp_
Restriction and Prolongation Operator.
Definition: adaptationmanager.hh:570
virtual bool loadBalance()
default load balancing method which does nothing
Definition: adaptationmanager.hh:337
virtual double adaptationTime() const
time that last adaptation cycle took
Definition: adaptationmanager.hh:349
static DofManagerType & getDofManager(const GridType &grid)
Definition: adaptationmanager.hh:355
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:567
factory class to create adaptation manager reference counter
Definition: adaptationmanager.hh:582
static ObjectType * createObject(const KeyType &key)
Definition: adaptationmanager.hh:583
static void deleteObject(ObjectType *obj)
Definition: adaptationmanager.hh:587
This class manages the adaptation process including a load balancing after the adaptation step....
Definition: adaptationmanager.hh:603
int balanceCounter() const
returns actual balanceCounter for checkpointing
Definition: adaptationmanager.hh:744
void restore()
retore internal data
Definition: adaptationmanager.hh:754
AdaptationManager(GridType &grid, RestProlOperatorImp &rpOp, int balanceCounter, const ParameterReader ¶meter=Parameter::container())
constructor of AdaptationManager
Definition: adaptationmanager.hh:644
virtual double loadBalanceTime() const
time that last load balance cycle took
Definition: adaptationmanager.hh:701
void backup() const
backup internal data
Definition: adaptationmanager.hh:747
virtual bool loadBalance()
call load balance, returns true if grid was changed
Definition: adaptationmanager.hh:687
virtual void adapt()
on call of this method the internal adaptation operator is called.
Definition: adaptationmanager.hh:707
AdaptationManager(GridType &grid, RestProlOperatorImp &rpOp, const ParameterReader ¶meter=Parameter::container())
constructor of AdaptationManager
Definition: adaptationmanager.hh:674
~AdaptationManager()
destructor decreasing reference counter
Definition: adaptationmanager.hh:680
Manages the testriction and prolongation of discrete functions in -adaptive computations.
Definition: adaptationmanager.hh:783
void adapt()
perform adaptation
Definition: adaptationmanager.hh:833
AdaptationManager(DiscreteFunctionSpaceType &space, DataProjectionType &&dataProjection)
Definition: adaptationmanager.hh:803
int balanceCounter() const
please doc me
Definition: adaptationmanager.hh:866
bool adaptive() const
returns true
Definition: adaptationmanager.hh:830
AdaptationManager(const ThisType &)=delete
Deleted methods.
double adaptationTime() const
return time spent on adaptation
Definition: adaptationmanager.hh:854
DataProjection & dataProjection()
Definition: adaptationmanager.hh:873
bool loadBalance()
please doc me
Definition: adaptationmanager.hh:863
const char * methodName() const
return name of adaptation method
Definition: adaptationmanager.hh:851
double loadBalanceTime() const
please doc me
Definition: adaptationmanager.hh:869
Definition: adaptationmanager.hh:896
typename BaseType::EntityType EntityType
Definition: adaptationmanager.hh:901
DataProjectionWrapper(DataProjectionType &dataProjection, DofManagerType &dofManager)
Definition: adaptationmanager.hh:903
typename BaseType::BasisFunctionSetType BasisFunctionSetType
Definition: adaptationmanager.hh:900
A class with one static method apply to globally refine a grid. All index sets are adapted to the new...
Definition: adaptationmanager.hh:948
static void apply(GridType &grid, const int step)
apply global refinement and also adjust index sets and managed dof storage. However,...
Definition: adaptationmanager.hh:955
A class with one static method apply for invoking the local adaptation procedure on a given grid inst...
Definition: adaptationmanager.hh:972
static void apply(GridType &grid)
apply local refinement and also adjust index sets and managed dof storage. However,...
Definition: adaptationmanager.hh:978
Definition: adaptcallbackhandle.hh:26
Definition: dofmanager.hh:762
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