Reference documentation for deal.II version 9.6.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
TimeStepBase Class Referenceabstract

#include <deal.II/numerics/time_dependent.h>

Inheritance diagram for TimeStepBase:

Public Types

enum  SolutionState { primal_problem = 0x0 , dual_problem = 0x1 , postprocess = 0x2 }
 

Public Member Functions

 TimeStepBase (const double time)
 
virtual ~TimeStepBase () override=default
 
 TimeStepBase (const TimeStepBase &)=delete
 
TimeStepBaseoperator= (const TimeStepBase &)=delete
 
virtual void wake_up (const unsigned int)
 
virtual void sleep (const unsigned int)
 
virtual void start_sweep ()
 
virtual void end_sweep ()
 
virtual void init_for_primal_problem ()
 
virtual void init_for_dual_problem ()
 
virtual void init_for_postprocessing ()
 
virtual void solve_primal_problem ()=0
 
virtual void solve_dual_problem ()
 
virtual void postprocess_timestep ()
 
double get_time () const
 
unsigned int get_timestep_no () const
 
double get_backward_timestep () const
 
double get_forward_timestep () const
 
virtual std::size_t memory_consumption () const
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 
Subscriptor functionality

Classes derived from Subscriptor provide a facility to subscribe to this object. This is mostly used by the SmartPointer class.

void subscribe (std::atomic< bool > *const validity, const std::string &identifier="") const
 
void unsubscribe (std::atomic< bool > *const validity, const std::string &identifier="") const
 
unsigned int n_subscriptions () const
 
template<typename StreamType >
void list_subscribers (StreamType &stream) const
 
void list_subscribers () const
 

Static Public Member Functions

static ::ExceptionBaseExcInUse (int arg1, std::string arg2, std::string arg3)
 
static ::ExceptionBaseExcNoSubscriber (std::string arg1, std::string arg2)
 

Protected Attributes

const TimeStepBaseprevious_timestep
 
const TimeStepBasenext_timestep
 
unsigned int sweep_no
 
unsigned int timestep_no
 
const double time
 
unsigned int next_action
 

Private Types

using map_value_type = decltype(counter_map)::value_type
 
using map_iterator = decltype(counter_map)::iterator
 

Private Member Functions

void set_previous_timestep (const TimeStepBase *previous)
 
void set_next_timestep (const TimeStepBase *next)
 
void set_timestep_no (const unsigned int step_no)
 
void set_sweep_no (const unsigned int sweep_no)
 
void check_no_subscribers () const noexcept
 

Private Attributes

std::atomic< unsigned intcounter
 
std::map< std::string, unsigned intcounter_map
 
std::vector< std::atomic< bool > * > validity_pointers
 
const std::type_info * object_info
 

Static Private Attributes

static std::mutex mutex
 

Friends

class TimeDependent
 

Detailed Description

Base class for a time step in time dependent problems. This class provides barely more than the basic framework, defining the necessary virtual functions (namely sleep and wake_up), the interface to previous and following grids, and some functions to be called before a new loop over all time steps is started.

Definition at line 663 of file time_dependent.h.

Member Typedef Documentation

◆ map_value_type

using Subscriptor::map_value_type = decltype(counter_map)::value_type
privateinherited

The data type used in counter_map.

Definition at line 229 of file subscriptor.h.

◆ map_iterator

using Subscriptor::map_iterator = decltype(counter_map)::iterator
privateinherited

The iterator type used in counter_map.

Definition at line 234 of file subscriptor.h.

Member Enumeration Documentation

◆ SolutionState

Enum denoting the type of problem which will have to be solved next.

Enumerator
primal_problem 

Solve the primal problem next.

dual_problem 

Solve the dual problem next.

postprocess 

Perform postprocessing next.

Definition at line 669 of file time_dependent.h.

Constructor & Destructor Documentation

◆ TimeStepBase() [1/2]

TimeStepBase::TimeStepBase ( const double time)

Constructor. Does nothing here apart from setting the time.

Definition at line 267 of file time_dependent.cc.

◆ ~TimeStepBase()

virtual TimeStepBase::~TimeStepBase ( )
overridevirtualdefault

Destructor. At present, this does nothing.

◆ TimeStepBase() [2/2]

TimeStepBase::TimeStepBase ( const TimeStepBase & )
delete

The copy constructor is deleted to avoid shallow copies with unexpected behavior.

Member Function Documentation

◆ operator=()

TimeStepBase & TimeStepBase::operator= ( const TimeStepBase & )
delete

The copy assignment operator is deleted to avoid shallow copies with unexpected behavior.

◆ wake_up()

void TimeStepBase::wake_up ( const unsigned int )
virtual

Reconstruct all the data that is needed for this time level to work. This function serves to reget all the variables and data structures to work again after they have been send to sleep some time before, or at the first time we visit this time level. In particular, it is used to reconstruct the triangulation, degree of freedom handlers, to reload data vectors in case they have been stored to disk, etc.

The actual implementation of this function does nothing.

Since this is an important task, you should call this function from your own function, should you choose to overload it in your own class (which likely is the case), preferably at the beginning so that your function can take effect of the triangulation already existing.

Reimplemented in TimeStepBase_Tria< dim >.

Definition at line 279 of file time_dependent.cc.

◆ sleep()

void TimeStepBase::sleep ( const unsigned int )
virtual

This is the opposite function to wake_up. It is used to delete data or save it to disk after they are no more needed for the present sweep. Typical kinds of data for this are data vectors, degree of freedom handlers, triangulation objects, etc. which occupy large amounts of memory and may therefore be externalized.

By default, this function does nothing.

Reimplemented in TimeStepBase_Tria< dim >.

Definition at line 285 of file time_dependent.cc.

◆ start_sweep()

void TimeStepBase::start_sweep ( )
virtual

This function is called each time before a new sweep is started. You may want to set up some fields needed in the course of the computations, and so on. You should take good care, however, not to install large objects, which should be deferred until the wake_up function is called.

A typical action of this function would be sorting out names of temporary files needed in the process of solving, etc.

At the time this function is called, the values of timestep_no, sweep_no and the pointer to the previous and next time step object already have their correct value.

The default implementation of this function does nothing.

Definition at line 291 of file time_dependent.cc.

◆ end_sweep()

void TimeStepBase::end_sweep ( )
virtual

This is the analogous to the above function, but it is called at the end of a sweep. You will usually want to do clean-ups in this function, such as deleting temporary files and the like.

Definition at line 297 of file time_dependent.cc.

◆ init_for_primal_problem()

void TimeStepBase::init_for_primal_problem ( )
virtual

Before the primal problem is solved on each time level, this function is called (i.e. before the solution takes place on the first time level). By default, this function sets the next_action variable of this class. You may overload this function, but you should call this function within your own one.

Definition at line 303 of file time_dependent.cc.

◆ init_for_dual_problem()

void TimeStepBase::init_for_dual_problem ( )
virtual

Same as above, but called before a round of dual problem solves.

Definition at line 311 of file time_dependent.cc.

◆ init_for_postprocessing()

void TimeStepBase::init_for_postprocessing ( )
virtual

Same as above, but called before a round of postprocessing steps.

Definition at line 319 of file time_dependent.cc.

◆ solve_primal_problem()

virtual void TimeStepBase::solve_primal_problem ( )
pure virtual

This function is called by the manager object when solving the primal problem on this time level is needed. It is called after the wake_up function was called and before the sleep function will be called. There is no default implementation for obvious reasons, so you have to overload this function.

◆ solve_dual_problem()

void TimeStepBase::solve_dual_problem ( )
virtual

This function is called by the manager object when solving the dual problem on this time level is needed. It is called after the wake_up function was called and before the sleep function will be called. There is a default implementation doing plain nothing since some problems may not need solving a dual problem. However, it will abort the program when being called anyway, since then you should really overload the function.

Definition at line 327 of file time_dependent.cc.

◆ postprocess_timestep()

void TimeStepBase::postprocess_timestep ( )
virtual

This function is called by the manager object when postprocessing this time level is needed. It is called after the wake_up function was called and before the sleep function will be called. There is a default implementation doing plain nothing since some problems may not need doing a postprocess step, e.g. if everything was already done when solving the primal problem. However, it will abort the program when being called anyway, since then you should really overload the function.

Definition at line 335 of file time_dependent.cc.

◆ get_time()

double TimeStepBase::get_time ( ) const

Return the time value of this time step.

Definition at line 343 of file time_dependent.cc.

◆ get_timestep_no()

unsigned int TimeStepBase::get_timestep_no ( ) const

Return the number of this time step. Note that this number may vary between different sweeps, if timesteps are added or deleted.

Definition at line 351 of file time_dependent.cc.

◆ get_backward_timestep()

double TimeStepBase::get_backward_timestep ( ) const

Compute the time difference to the last time step. If this timestep is the first one, this function will result in an exception. Though this behavior seems a bit drastic, it is appropriate in most cases since if there is no previous time step you will need special treatment anyway and this way no invalid value is returned which could lead to wrong but unnoticed results of your computation. (The only sensible value to return in that case would not be zero, since valid computation can be done with that, but would be a denormalized value such as NaN. However, there is not much difference in finding that the results of a computation are all denormalized values or in getting an exception; in the latter case you at least get the exact place where your problem lies.)

Definition at line 359 of file time_dependent.cc.

◆ get_forward_timestep()

double TimeStepBase::get_forward_timestep ( ) const

Return the time difference to the next time step. With regard to the case that there is no next time step, the same applies as for the function above.

Definition at line 370 of file time_dependent.cc.

◆ memory_consumption()

std::size_t TimeStepBase::memory_consumption ( ) const
virtual

Determine an estimate for the memory consumption (in bytes) of this object.

You will want to overload this function in derived classes to compute the amount memory used by the derived class, and add the result of this function to your result.

Reimplemented in TimeStepBase_Tria< dim >.

Definition at line 413 of file time_dependent.cc.

◆ set_previous_timestep()

void TimeStepBase::set_previous_timestep ( const TimeStepBase * previous)
private

Reset the pointer to the previous time step; shall only be called by the time level manager object.

This function is called at the set-up of the manager object and whenever a timestep is inserted or deleted.

Definition at line 381 of file time_dependent.cc.

◆ set_next_timestep()

void TimeStepBase::set_next_timestep ( const TimeStepBase * next)
private

Reset the pointer to the next time step; shall only be called by the time level manager object.

This function is called at the set-up of the manager object and whenever a timestep is inserted or deleted.

Definition at line 389 of file time_dependent.cc.

◆ set_timestep_no()

void TimeStepBase::set_timestep_no ( const unsigned int step_no)
private

Set the number this time step has in the list of timesteps. This function is called by the time step management object at the beginning of each sweep, to update information which may have changed due to addition or deletion of time levels.

Definition at line 397 of file time_dependent.cc.

◆ set_sweep_no()

void TimeStepBase::set_sweep_no ( const unsigned int sweep_no)
private

Set the number of the sweep we are presently in. This function is called by the time level management object at start-up time of each sweep.

Definition at line 405 of file time_dependent.cc.

◆ subscribe()

void Subscriptor::subscribe ( std::atomic< bool > *const validity,
const std::string & identifier = "" ) const
inherited

Subscribes a user of the object by storing the pointer validity. The subscriber may be identified by text supplied as identifier.

Definition at line 135 of file subscriptor.cc.

◆ unsubscribe()

void Subscriptor::unsubscribe ( std::atomic< bool > *const validity,
const std::string & identifier = "" ) const
inherited

Unsubscribes a user from the object.

Note
The identifier and the validity pointer must be the same as the one supplied to subscribe().

Definition at line 155 of file subscriptor.cc.

◆ n_subscriptions()

unsigned int Subscriptor::n_subscriptions ( ) const
inlineinherited

Return the present number of subscriptions to this object. This allows to use this class for reference counted lifetime determination where the last one to unsubscribe also deletes the object.

Definition at line 300 of file subscriptor.h.

◆ list_subscribers() [1/2]

template<typename StreamType >
void Subscriptor::list_subscribers ( StreamType & stream) const
inlineinherited

List the subscribers to the input stream.

Definition at line 317 of file subscriptor.h.

◆ list_subscribers() [2/2]

void Subscriptor::list_subscribers ( ) const
inherited

List the subscribers to deallog.

Definition at line 203 of file subscriptor.cc.

◆ serialize()

template<class Archive >
void Subscriptor::serialize ( Archive & ar,
const unsigned int version )
inlineinherited

Read or write the data of this object to or from a stream for the purpose of serialization using the BOOST serialization library.

This function does not actually serialize any of the member variables of this class. The reason is that what this class stores is only who subscribes to this object, but who does so at the time of storing the contents of this object does not necessarily have anything to do with who subscribes to the object when it is restored. Consequently, we do not want to overwrite the subscribers at the time of restoring, and then there is no reason to write the subscribers out in the first place.

Definition at line 309 of file subscriptor.h.

◆ check_no_subscribers()

void Subscriptor::check_no_subscribers ( ) const
privatenoexceptinherited

Check that there are no objects subscribing to this object. If this check passes then it is safe to destroy the current object. It this check fails then this function will either abort or print an error message to deallog (by using the AssertNothrow mechanism), but will not throw an exception.

Note
Since this function is just a consistency check it does nothing in release mode.
If this function is called when there is an uncaught exception then, rather than aborting, this function prints an error message to the standard error stream and returns.

Definition at line 52 of file subscriptor.cc.

Friends And Related Symbol Documentation

◆ TimeDependent

friend class TimeDependent
friend

Definition at line 942 of file time_dependent.h.

Member Data Documentation

◆ previous_timestep

const TimeStepBase* TimeStepBase::previous_timestep
protected

Pointer to the previous time step object in the list.

Definition at line 872 of file time_dependent.h.

◆ next_timestep

const TimeStepBase* TimeStepBase::next_timestep
protected

Pointer to the next time step object in the list.

Definition at line 877 of file time_dependent.h.

◆ sweep_no

unsigned int TimeStepBase::sweep_no
protected

Number of the sweep we are presently in. This number is reset by the time level manager before a sweep is started.

Definition at line 883 of file time_dependent.h.

◆ timestep_no

unsigned int TimeStepBase::timestep_no
protected

Number of the time step, counted from zero onwards. This number is reset at the start of each sweep by the time level manager, since some time steps may have been inserted or deleted after the previous sweep.

Definition at line 890 of file time_dependent.h.

◆ time

const double TimeStepBase::time
protected

Discrete time this level operates on.

Definition at line 895 of file time_dependent.h.

◆ next_action

unsigned int TimeStepBase::next_action
protected

Variable storing whether the solution of a primal or a dual problem is actual, or any of the other actions specified. This variable is set by the init_for_* functions.

Definition at line 902 of file time_dependent.h.

◆ counter

std::atomic<unsigned int> Subscriptor::counter
mutableprivateinherited

Store the number of objects which subscribed to this object. Initially, this number is zero, and upon destruction it shall be zero again (i.e. all objects which subscribed should have unsubscribed again).

The creator (and owner) of an object is counted in the map below if HE manages to supply identification.

We use the mutable keyword in order to allow subscription to constant objects also.

This counter may be read from and written to concurrently in multithreaded code: hence we use the std::atomic class template.

Definition at line 218 of file subscriptor.h.

◆ counter_map

std::map<std::string, unsigned int> Subscriptor::counter_map
mutableprivateinherited

In this map, we count subscriptions for each different identification string supplied to subscribe().

Definition at line 224 of file subscriptor.h.

◆ validity_pointers

std::vector<std::atomic<bool> *> Subscriptor::validity_pointers
mutableprivateinherited

In this vector, we store pointers to the validity bool in the SmartPointer objects that subscribe to this class.

Definition at line 240 of file subscriptor.h.

◆ object_info

const std::type_info* Subscriptor::object_info
mutableprivateinherited

Pointer to the typeinfo object of this object, from which we can later deduce the class name. Since this information on the derived class is neither available in the destructor, nor in the constructor, we obtain it in between and store it here.

Definition at line 248 of file subscriptor.h.

◆ mutex

std::mutex Subscriptor::mutex
staticprivateinherited

A mutex used to ensure data consistency when accessing the mutable members of this class. This lock is used in the subscribe() and unsubscribe() functions, as well as in list_subscribers().

Definition at line 271 of file subscriptor.h.


The documentation for this class was generated from the following files: