1#ifndef DUNE_FEM_TIMEPROVIDER_HH
2#define DUNE_FEM_TIMEPROVIDER_HH
8#include <dune/fem/io/file/persistencemanager.hh>
9#include <dune/fem/io/parameter.hh>
10#include <dune/fem/space/common/dofmanager.hh>
12#include <dune/fem/misc/mpimanager.hh>
40 inline TimeProviderBase (
const ParameterReader ¶meter = Parameter::container() )
41 : time_( parameter.getValue(
"fem.timeprovider.starttime",
42 static_cast<double>(0.0) ) ),
47 dtEstimateValid_(
false ),
48 parameter_( parameter )
50 initTimeStepEstimate();
53 inline explicit TimeProviderBase (
const double startTime,
const ParameterReader ¶meter = Parameter::container() )
59 dtEstimateValid_(
false ),
60 parameter_( parameter )
62 initTimeStepEstimate();
70 std::tuple<const double&,const int&,const double&,const bool&,const double&>
71 values(time_,timeStep_,dt_,valid_,dtEstimate_);
72 PersistenceManager::backupValue(
"timeprovider",values);
77 std::tuple<double&,int&,double&,bool&,double&>
78 values(time_,timeStep_,dt_,valid_,dtEstimate_);
79 PersistenceManager::restoreValue(
"timeprovider",values);
80 dtEstimateValid_ =
true;
87 ThisType &operator= (
const ThisType & ) =
delete;
94 inline double time ()
const
144 dtEstimate_ = std::min( dtEstimate_, dtEstimate );
145 dtEstimateValid_ =
true;
153 dtUpperBound_ = std::min( dtUpperBound_, upperBound );
154 dtEstimateValid_ =
true;
175 bool dtEstimateValid_;
177 double dtUpperBound_;
178 ParameterReader parameter_;
189 void initTimeStepEstimate ()
193 dtEstimateValid_ =
false;
215 template<
class Communication =
typename MPIManager::Communication >
216 class FixedStepTimeProvider
217 :
public TimeProviderBase
219 typedef FixedStepTimeProvider< Communication > ThisType;
220 typedef TimeProviderBase BaseType;
223 typedef Communication CommunicationType;
231 explicit FixedStepTimeProvider (
const double startTime,
const double timeStepSize,
232 const CommunicationType &comm,
233 const ParameterReader ¶meter = Parameter::container() )
234 : BaseType( startTime, parameter ), comm_( comm )
240 explicit FixedStepTimeProvider (
const double startTime,
const double timeStepSize,
241 const ParameterReader ¶meter = Parameter::container() )
242 : BaseType( startTime, parameter ), comm_( MPIManager::comm() )
255 explicit FixedStepTimeProvider (
const ParameterReader ¶meter = Parameter::container() )
256 : BaseType( parameter.getValue< double>(
"fem.timeprovider.starttime", 0.0 ), parameter ), comm_( MPIManager::comm() )
258 dt_ = parameter.getValidValue<
double >(
"fem.timeprovider.fixedtimestep", [] (
double v ) {
return v > 0.0;} );
262 explicit FixedStepTimeProvider (
const CommunicationType &comm,
263 const ParameterReader ¶meter = Parameter::container() )
264 : BaseType( parameter.getValue< double>(
"fem.timeprovider.starttime", 0.0 ), parameter ), comm_( comm )
266 dt_ = parameter.getValidValue<
double >(
"fem.timeprovider.fixedtimestep", [] (
double v ) {
return v > 0.0;} );
269 virtual ~FixedStepTimeProvider () {}
271 FixedStepTimeProvider (
const ThisType & ) =
delete;
272 FixedStepTimeProvider ( ThisType && ) =
delete;
273 ThisType &operator= (
const ThisType & ) =
delete;
274 ThisType &operator= ( ThisType && ) =
delete;
280 DUNE_THROW( InvalidStateException,
"Invalid Time Step in FixedStepTimeProvider" );
286 using BaseType::advance;
287 using BaseType::initTimeStepEstimate;
288 using BaseType::time_;
290 using BaseType::valid_;
292 inline void initTimeStep ()
295 initTimeStepEstimate();
298 const CommunicationType &comm_;
402 template<
class Communication =
typename MPIManager::Communication >
414 using BaseType::parameter_;
416 inline double getCflFactor()
const
418 return parameter_.getValidValue(
"fem.timeprovider.factor",
static_cast<double>(1.0),
419 [] (
double val ) {
return val > 0.0; } );
422 inline int getUpdateStep ()
const
424 return parameter_.getValidValue(
"fem.timeprovider.updatestep",
static_cast<int>(1),
425 [] (
int step ) {
return step > 0; } );
433 explicit TimeProvider (
const ParameterReader ¶meter = Parameter::container() )
435 comm_( MPIManager::comm() ),
436 cfl_( getCflFactor() ),
437 updateStep_( getUpdateStep() ),
438 counter_( updateStep_ )
441 explicit TimeProvider (
const CommunicationType &comm,
const ParameterReader ¶meter = Parameter::container() )
442 : BaseType( parameter ),
444 cfl_( getCflFactor() ),
445 updateStep_( getUpdateStep() ),
446 counter_( updateStep_ )
458 cfl_( getCflFactor() ),
459 updateStep_( getUpdateStep() ),
460 counter_( updateStep_ )
476 counter_( updateStep_ )
484 ThisType &operator= (
const ThisType & ) =
delete;
490 initTimeStep( dtEstimate_ );
510 assert( this->dtEstimateValid_ );
512 initTimeStep( dtEstimate_ );
538 using BaseType::advance;
539 using BaseType::initTimeStepEstimate;
541 void initTimeStep (
const double dtEstimate )
546 if( counter_ >= updateStep_ )
549 dt_ = std::min(cfl_ * dtEstimate,dtUpperBound_);
550 dt_ = comm_.
min( dt_ );
552 valid_ = (dt_ > 0.0);
557 initTimeStepEstimate();
580 const_cast< double &
>( cfl_ ) = getCflFactor();
585 using BaseType::invdt_;
586 using BaseType::dtEstimate_;
587 using BaseType::dtUpperBound_;
588 using BaseType::valid_;
589 using BaseType::timeStep_;
591 const CommunicationType& comm_;
593 const int updateStep_;
606 template<
class Gr
id >
608 :
public TimeProvider< typename Grid::Traits::Communication >
617 typedef typename Grid::Traits::Communication CommunicationType;
648 void initTimeStep (
const double dtEstimate )
650 const int currentSequence = dm_.
sequence();
652 if( sequence_ != currentSequence )
655 counter_ = updateStep_ ;
656 sequence_ = currentSequence ;
660 BaseType :: initTimeStep( dtEstimate );
Collective communication interface and sequential default implementation.
Definition: communication.hh:100
T min(const T &in) const
Compute the minimum of the argument over all processes and return the result in every process....
Definition: communication.hh:228
base class for auto persistent objects
Definition: persistencemanager.hh:580
Definition: dofmanager.hh:786
the same functionality as the Dune::TimeProvider.
Definition: timeprovider.hh:609
base class for persistent objects
Definition: persistencemanager.hh:101
general base for time providers
Definition: timeprovider.hh:36
double timeStepEstimate() const
obtain current estimate on time step
Definition: timeprovider.hh:133
void restore()
restore persistent object
Definition: timeprovider.hh:75
double time() const
obtain the current time
Definition: timeprovider.hh:94
int timeStep() const
obtain number of the current time step
Definition: timeprovider.hh:103
void provideTimeStepEstimate(const double dtEstimate)
set time step estimate to minimum of given value and internal time step estiamte
Definition: timeprovider.hh:142
bool timeStepValid() const
return if this time step should be used
Definition: timeprovider.hh:164
double deltaT() const
obtain the size of the current time step
Definition: timeprovider.hh:113
void provideTimeStepUpperBound(const double upperBound)
set upper bound for time step to minimum of given value and internal bound
Definition: timeprovider.hh:151
double inverseDeltaT() const
obtain the size of the inverse of the current time step
Definition: timeprovider.hh:123
void backup() const
backup persistent object
Definition: timeprovider.hh:68
void invalidateTimeStep()
count current time step a not valid
Definition: timeprovider.hh:158
manager for global simulation time of time-dependent solutions
Definition: timeprovider.hh:405
void init()
init dt with time step estimate
Definition: timeprovider.hh:488
void next()
goto next time step
Definition: timeprovider.hh:508
void init(const double timeStep)
init dt with provided time step
Definition: timeprovider.hh:498
TimeProvider(const double startTime, const double cfl, const CommunicationType &comm=MPIManager::comm())
constructor taking start time and CFL constant
Definition: timeprovider.hh:469
TimeProvider(const ParameterReader ¶meter=Parameter::container())
default constructor
Definition: timeprovider.hh:433
TimeProvider(const double startTime, const CommunicationType &comm=MPIManager::comm())
constructor taking start time
Definition: timeprovider.hh:454
virtual void restore()
restore persistent object
Definition: timeprovider.hh:577
void restore(const double time, const int timeStep)
restore time and timestep from outside (i.e. from former calculation)
Definition: timeprovider.hh:566
void next(const double timeStep)
goto next time step
Definition: timeprovider.hh:523
virtual void backup() const
backup persistent object
Definition: timeprovider.hh:572
double factor() const
return the global factor number
Definition: timeprovider.hh:532
Grid abstract base class.
Definition: grid.hh:375
const Communication & comm() const
return const reference to a communication object. The return type is a model of Dune::Communication.
Definition: grid.hh:722
static ThisType & instance(const GridType &grid)
obtain a reference to the DofManager for a given grid
Definition: dofmanager.hh:1251
int sequence() const
return number of sequence, if dofmanagers memory was changed by calling some method like resize,...
Definition: dofmanager.hh:1007
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
constexpr auto max
Function object that returns the greater of the given values.
Definition: hybridutilities.hh:484
Dune namespace.
Definition: alignedallocator.hh:13