deal.II version GIT relicensing-2233-g9bd70d8389 2024-12-08 16:10:00+00:00
|
#include <deal.II/numerics/time_dependent.h>
Public Types | |
enum | SolutionState { grid_refinement = 0x1000 } |
using | Flags = typename TimeStepBase_Tria_Flags::Flags< dim > |
using | RefinementFlags = typename TimeStepBase_Tria_Flags::RefinementFlags< dim > |
using | RefinementData = typename TimeStepBase_Tria_Flags::RefinementData< dim > |
Public Member Functions | |
TimeStepBase_Tria () | |
TimeStepBase_Tria (const double time, const Triangulation< dim, dim > &coarse_grid, const Flags &flags, const RefinementFlags &refinement_flags=RefinementFlags()) | |
virtual | ~TimeStepBase_Tria () override |
virtual void | wake_up (const unsigned int wakeup_level) override |
virtual void | sleep (const unsigned int) override |
void | refine_grid (const RefinementData data) |
virtual void | init_for_refinement () |
virtual void | get_tria_refinement_criteria (Vector< float > &criteria) const =0 |
void | save_refine_flags () |
virtual std::size_t | memory_consumption () const override |
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 |
template<class Archive > | |
void | serialize (Archive &ar, const unsigned int version) |
EnableObserverPointer functionality | |
Classes derived from EnableObserverPointer provide a facility to subscribe to this object. This is mostly used by the ObserverPointer 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 ::ExceptionBase & | ExcGridNotDeleted () |
static ::ExceptionBase & | ExcInUse (int arg1, std::string arg2, std::string arg3) |
static ::ExceptionBase & | ExcNoSubscriber (std::string arg1, std::string arg2) |
Protected Attributes | |
ObserverPointer< Triangulation< dim, dim >, TimeStepBase_Tria< dim > > | tria |
ObserverPointer< const Triangulation< dim, dim >, TimeStepBase_Tria< dim > > | coarse_grid |
const Flags | flags |
const RefinementFlags | refinement_flags |
const TimeStepBase * | previous_timestep |
const TimeStepBase * | next_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 | restore_grid () |
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::vector< std::vector< bool > > | refine_flags |
std::vector< std::vector< bool > > | coarsen_flags |
std::atomic< unsigned int > | counter |
std::map< std::string, unsigned int > | counter_map |
std::vector< std::atomic< bool > * > | validity_pointers |
const std::type_info * | object_info |
Static Private Attributes | |
static std::mutex | mutex |
Specialization of TimeStepBase which addresses some aspects of grid handling. In particular, this class is thought to make handling of grids available that are adaptively refined on each time step separately or with a loose coupling between time steps. It also takes care of deleting and rebuilding grids when memory resources are a point, through the sleep
and wake_up
functions declared in the base class.
In addition to that, it offers functions which do some rather hairy refinement rules for time dependent problems, trying to avoid too much change in the grids between subsequent time levels, while also trying to retain the freedom of refining each grid separately. There are lots of flags and numbers controlling this function, which might drastically change the behavior of the function – see the description of the flags for further information.
Definition at line 1302 of file time_dependent.h.
using TimeStepBase_Tria< dim >::Flags = typename TimeStepBase_Tria_Flags::Flags<dim> |
Typedef the data types of the TimeStepBase_Tria_Flags() namespace into local scope.
Definition at line 1309 of file time_dependent.h.
using TimeStepBase_Tria< dim >::RefinementFlags = typename TimeStepBase_Tria_Flags::RefinementFlags<dim> |
Definition at line 1310 of file time_dependent.h.
using TimeStepBase_Tria< dim >::RefinementData = typename TimeStepBase_Tria_Flags::RefinementData<dim> |
Definition at line 1312 of file time_dependent.h.
|
privateinherited |
The data type used in counter_map.
Definition at line 238 of file enable_observer_pointer.h.
|
privateinherited |
The iterator type used in counter_map.
Definition at line 243 of file enable_observer_pointer.h.
enum TimeStepBase_Tria::SolutionState |
Extension of the enum in the base class denoting the next action to be done.
Enumerator | |
---|---|
grid_refinement | Perform grid refinement next. |
Definition at line 1319 of file time_dependent.h.
TimeStepBase_Tria< dim >::TimeStepBase_Tria | ( | ) |
Default constructor. Does nothing but throws an exception. We need to have such a constructor in order to satisfy the needs of derived classes, which take this class as a virtual base class and don't need to call this constructor of they are not terminal classes. The compiler would like to know a constructor to call anyway since it can't know that the class is not terminal.
Definition at line 423 of file time_dependent.cc.
TimeStepBase_Tria< dim >::TimeStepBase_Tria | ( | const double | time, |
const Triangulation< dim, dim > & | coarse_grid, | ||
const Flags & | flags, | ||
const RefinementFlags & | refinement_flags = RefinementFlags() |
||
) |
Constructor. Takes a coarse grid from which the grids on this time level will be derived and some flags steering the behavior of this object.
The ownership of the coarse grid stays with the creator of this object. However, it is locked from destruction to guarantee the lifetime of the coarse grid is longer than it is needed by this object.
You need to give the general flags structure to this function since it is needed anyway; the refinement flags can be omitted if you do not intend to call the refinement function of this class.
|
overridevirtual |
Destructor. At present, this does not more than releasing the lock on the coarse grid triangulation given to the constructor.
Definition at line 453 of file time_dependent.cc.
|
overridevirtual |
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. By default, this function rebuilds the triangulation if the respective flag has been set to destroy it in the sleep
function. It does so also the first time we hit this function and wakeup_level
equals flags.wakeup_level_to_build_grid
, independently of the value of the mentioned flag. (Actually, it does so whenever the triangulation pointer equals the Null pointer and the value of wakeup_level
is right.)
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 from TimeStepBase.
Definition at line 471 of file time_dependent.cc.
|
overridevirtual |
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, if the user specified so in the flags for this object, the triangulation is deleted and the refinement history is saved such that the respective wake_up
function can rebuild it. You should therefore call this function from your overloaded version, preferably at the end so that your function can use the triangulation as long as you need it.
Reimplemented from TimeStepBase.
Definition at line 484 of file time_dependent.cc.
void TimeStepBase_Tria< dim >::refine_grid | ( | const RefinementData | data | ) |
Do the refinement according to the flags passed to the constructor of this object and the data passed to this function. For a description of the working of this function refer to the general documentation of this class.
In fact, this function does not actually refine or coarsen the triangulation, but only sets the respective flags. This is done because usually you will not need the grid immediately afterwards but only in the next sweep, so it suffices to store the flags and rebuild it the next time we need it. Also, it may be that the next time step would like to add or delete some flags, so we have to wait anyway with the use of this grid.
Definition at line 737 of file time_dependent.cc.
|
virtual |
Respective init function for the refinement loop; does nothing in the default implementation, apart from setting next_action
to grid_refinement
but can be overloaded.
Definition at line 1141 of file time_dependent.cc.
|
pure virtual |
Virtual function that should fill the vector with the refinement criteria for the present triangulation. It is used within the refine_grid
function to get the criteria for the present time step, since they can't be passed through its argument when using the loop of the time step management object.
void TimeStepBase_Tria< dim >::save_refine_flags | ( | ) |
The refinement flags of the triangulation are stored in a local variable thus allowing a restoration. The coarsening flags are also stored.
Definition at line 505 of file time_dependent.cc.
|
overridevirtual |
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 from TimeStepBase.
Definition at line 1150 of file time_dependent.cc.
|
private |
Restore the grid according to the saved data. For this, the coarse grid is copied and the grid is stepwise rebuilt using the saved flags.
Definition at line 519 of file time_dependent.cc.
|
virtualinherited |
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 292 of file time_dependent.cc.
|
virtualinherited |
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 298 of file time_dependent.cc.
|
virtualinherited |
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 304 of file time_dependent.cc.
|
virtualinherited |
Same as above, but called before a round of dual problem solves.
Definition at line 312 of file time_dependent.cc.
|
virtualinherited |
Same as above, but called before a round of postprocessing steps.
Definition at line 320 of file time_dependent.cc.
|
pure virtualinherited |
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.
|
virtualinherited |
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 328 of file time_dependent.cc.
|
virtualinherited |
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 336 of file time_dependent.cc.
|
inherited |
Return the time value of this time step.
Definition at line 344 of file time_dependent.cc.
|
inherited |
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 352 of file time_dependent.cc.
|
inherited |
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 360 of file time_dependent.cc.
|
inherited |
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 371 of file time_dependent.cc.
|
privateinherited |
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 382 of file time_dependent.cc.
|
privateinherited |
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 390 of file time_dependent.cc.
|
privateinherited |
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 398 of file time_dependent.cc.
|
privateinherited |
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 406 of file time_dependent.cc.
|
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 131 of file enable_observer_pointer.cc.
|
inherited |
Unsubscribes a user from the object.
identifier
and the validity
pointer must be the same as the one supplied to subscribe(). Definition at line 151 of file enable_observer_pointer.cc.
|
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 322 of file enable_observer_pointer.h.
|
inlineinherited |
List the subscribers to the input stream
.
Definition at line 339 of file enable_observer_pointer.h.
|
inherited |
List the subscribers to deallog
.
Definition at line 199 of file enable_observer_pointer.cc.
|
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 331 of file enable_observer_pointer.h.
|
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.
Definition at line 53 of file enable_observer_pointer.cc.
|
protected |
Triangulation used at this time level. Since this is something that every time stepping scheme needs to have, we can safely put it into the base class. Note that the triangulation is frequently deleted and rebuilt by the functions sleep
and wake_up
to save memory, if such a behavior is specified in the flags
structure.
Definition at line 1469 of file time_dependent.h.
|
protected |
Pointer to a grid which is to be used as the coarse grid for this time level. This pointer is set through the constructor; ownership remains with the owner of this management object.
Definition at line 1477 of file time_dependent.h.
|
protected |
Some flags about how this time level shall behave. See the documentation of this struct to find out more about that.
Definition at line 1483 of file time_dependent.h.
|
protected |
Flags controlling the refinement process; see the documentation of the respective structure for more information.
Definition at line 1489 of file time_dependent.h.
|
private |
Vectors holding the refinement and coarsening flags of the different sweeps on this time level. The vectors therefore hold the history of the grid.
Definition at line 1497 of file time_dependent.h.
|
private |
Definition at line 1502 of file time_dependent.h.
|
protectedinherited |
Pointer to the previous time step object in the list.
Definition at line 872 of file time_dependent.h.
|
protectedinherited |
Pointer to the next time step object in the list.
Definition at line 877 of file time_dependent.h.
|
protectedinherited |
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.
|
protectedinherited |
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.
|
protectedinherited |
Discrete time this level operates on.
Definition at line 895 of file time_dependent.h.
|
protectedinherited |
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.
|
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 227 of file enable_observer_pointer.h.
|
mutableprivateinherited |
In this map, we count subscriptions for each different identification string supplied to subscribe().
Definition at line 233 of file enable_observer_pointer.h.
|
mutableprivateinherited |
In this vector, we store pointers to the validity bool in the ObserverPointer objects that subscribe to this class.
Definition at line 249 of file enable_observer_pointer.h.
|
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 257 of file enable_observer_pointer.h.
|
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 280 of file enable_observer_pointer.h.