www.mooseframework.org
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
Restartable Class Reference

A class for creating restricted objects. More...

#include <Restartable.h>

Inheritance diagram for Restartable:
[legend]

Classes

class  ManagedValue
 Wrapper class for restartable data that is "managed. More...
 

Public Member Functions

 Restartable (const MooseObject *moose_object, const std::string &system_name)
 Class constructor. More...
 
 Restartable (const MooseObject *moose_object, const std::string &system_name, THREAD_ID tid)
 Class constructor. More...
 
 Restartable (MooseApp &moose_app, const std::string &name, const std::string &system_name, THREAD_ID tid, const bool read_only=false, const RestartableDataMapName &metaname="")
 This class constructor is used for non-Moose-based objects like interfaces. More...
 

Protected Member Functions

template<typename T , typename... Args>
T & declareRestartableData (const std::string &data_name, Args &&... args)
 Declare a piece of data as "restartable" and initialize it. More...
 
template<typename T , typename... Args>
ManagedValue< T > declareManagedRestartableDataWithContext (const std::string &data_name, void *context, Args &&... args)
 Declares a piece of "managed" restartable data and initialize it. More...
 
template<typename T , typename... Args>
const T & getRestartableData (const std::string &data_name) const
 Declare a piece of data as "restartable" and initialize it Similar to declareRestartableData but returns a const reference to the object. More...
 
template<typename T , typename... Args>
T & declareRestartableDataWithContext (const std::string &data_name, void *context, Args &&... args)
 Declare a piece of data as "restartable" and initialize it. More...
 
template<typename T , typename... Args>
T & declareRecoverableData (const std::string &data_name, Args &&... args)
 Declare a piece of data as "recoverable" and initialize it. More...
 
template<typename T , typename... Args>
T & declareRestartableDataWithObjectName (const std::string &data_name, const std::string &object_name, Args &&... args)
 Declare a piece of data as "restartable". More...
 
template<typename T , typename... Args>
T & declareRestartableDataWithObjectNameWithContext (const std::string &data_name, const std::string &object_name, void *context, Args &&... args)
 Declare a piece of data as "restartable". More...
 
std::string restartableName (const std::string &data_name) const
 Gets the name of a piece of restartable data given a data name, adding the system name and object name prefix. More...
 

Protected Attributes

MooseApp_restartable_app
 Reference to the application. More...
 
const std::string _restartable_system_name
 The system name this object is in. More...
 
const THREAD_ID _restartable_tid
 The thread ID for this object. More...
 
const bool _restartable_read_only
 Flag for toggling read only status (see ReporterData) More...
 

Private Member Functions

RestartableDataValueregisterRestartableDataOnApp (std::unique_ptr< RestartableDataValue > data, THREAD_ID tid) const
 Helper function for actually registering the restartable data. More...
 
void registerRestartableNameWithFilterOnApp (const std::string &name, Moose::RESTARTABLE_FILTER filter)
 Helper function for actually registering the restartable data. More...
 
template<typename T , typename... Args>
RestartableData< T > & declareRestartableDataHelper (const std::string &data_name, void *context, Args &&... args) const
 Helper function for declaring restartable data. More...
 

Private Attributes

const RestartableDataMapName _metaname
 Restartable metadata name. More...
 
std::string _restartable_name
 The name of the object. More...
 

Detailed Description

A class for creating restricted objects.

See also
BlockRestartable BoundaryRestartable

Definition at line 28 of file Restartable.h.

Constructor & Destructor Documentation

◆ Restartable() [1/3]

Restartable::Restartable ( const MooseObject moose_object,
const std::string &  system_name 
)

Class constructor.

Parameters
moose_objectThe MooseObject that this interface is being implemented on.
system_nameThe name of the MOOSE system. ie "Kernel", "BCs", etc. Should roughly correspond to the section in the input file so errors are easy to understand.

This method will forward the thread id if it exists in the moose_object parameters. Delegates to the "MooseApp &" constructor.

Definition at line 18 of file Restartable.C.

19  : Restartable(moose_object->getMooseApp(),
20  moose_object->name(),
21  system_name,
22  moose_object->parameters().isParamValid("_tid")
23  ? moose_object->parameters().get<THREAD_ID>("_tid")
24  : 0)
25 {
26 }
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
virtual const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:56
MooseApp & getMooseApp() const
Get the MooseApp this class is associated with.
Definition: MooseBase.h:44
Restartable(const MooseObject *moose_object, const std::string &system_name)
Class constructor.
Definition: Restartable.C:18
const InputParameters & parameters() const
Get the parameters of the object.
unsigned int THREAD_ID
Definition: MooseTypes.h:198
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.

◆ Restartable() [2/3]

Restartable::Restartable ( const MooseObject moose_object,
const std::string &  system_name,
THREAD_ID  tid 
)

Class constructor.

Similar to the other class constructor but also accepts an individual thread ID. If this method is used, no thread ID in the parameters object is used. Delegates to the "MooseApp &" constructor.

Definition at line 28 of file Restartable.C.

31  : Restartable(moose_object->getMooseApp(), moose_object->name(), system_name, tid)
32 {
33 }
virtual const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:56
MooseApp & getMooseApp() const
Get the MooseApp this class is associated with.
Definition: MooseBase.h:44
Restartable(const MooseObject *moose_object, const std::string &system_name)
Class constructor.
Definition: Restartable.C:18

◆ Restartable() [3/3]

Restartable::Restartable ( MooseApp moose_app,
const std::string &  name,
const std::string &  system_name,
THREAD_ID  tid,
const bool  read_only = false,
const RestartableDataMapName metaname = "" 
)

This class constructor is used for non-Moose-based objects like interfaces.

A name for the storage as well as a system name must be passed in along with the thread ID explicitly.

Parameters
moose_appReference to the application
nameThe name which is used when constructing the full-names of the restartable data. It is used with the following logic: system_name/name/data_name. (e.g. UserObjects/diffusion_kernel/coefficient). In most of the cases this is the name of the moose object.
system_nameThe name of the system where this object belongs to.
tidThe thread ID.
read_onlySwitch to restrict the data for read-only.
metanameThe name of the datamap where the restartable objects should be registered to.

Definition at line 35 of file Restartable.C.

41  : _restartable_app(moose_app),
42  _restartable_system_name(system_name),
43  _restartable_tid(tid),
44  _restartable_read_only(read_only),
45  _metaname(metaname),
46  _restartable_name(name)
47 {
48 }
std::string _restartable_name
The name of the object.
Definition: Restartable.h:243
const std::string _restartable_system_name
The system name this object is in.
Definition: Restartable.h:230
const THREAD_ID _restartable_tid
The thread ID for this object.
Definition: Restartable.h:233
const bool _restartable_read_only
Flag for toggling read only status (see ReporterData)
Definition: Restartable.h:236
const RestartableDataMapName _metaname
Restartable metadata name.
Definition: Restartable.h:240
MooseApp & _restartable_app
Reference to the application.
Definition: Restartable.h:227

Member Function Documentation

◆ declareManagedRestartableDataWithContext()

template<typename T , typename... Args>
Restartable::ManagedValue< T > Restartable::declareManagedRestartableDataWithContext ( const std::string &  data_name,
void context,
Args &&...  args 
)
protected

Declares a piece of "managed" restartable data and initialize it.

Here, "managed" restartable data means that the caller can destruct this data upon destruction of the return value of this method. Therefore, this ManagedValue<T> wrapper should survive after the final calls to dataStore() for it. That is... at the very end.

This is needed for objects whose destruction ordering is important, and enables natural c++ destruction in reverse construction order of the object that declares it.

See delcareRestartableData and declareRestartableDataWithContext for more information.

Definition at line 276 of file Restartable.h.

279 {
280  auto & data_ptr =
281  declareRestartableDataHelper<T>(data_name, context, std::forward<Args>(args)...);
282  return Restartable::ManagedValue<T>(data_ptr);
283 }
Wrapper class for restartable data that is "managed.
Definition: Restartable.h:42

◆ declareRecoverableData()

template<typename T , typename... Args>
T & Restartable::declareRecoverableData ( const std::string &  data_name,
Args &&...  args 
)
protected

Declare a piece of data as "recoverable" and initialize it.

This means that in the event of a restart this piece of data will be restored back to its previous value.

Note - this data will NOT be restored on Restart!

NOTE: This returns a reference! Make sure you store it in a reference!

Parameters
data_nameThe name of the data (usually just use the same name as the member variable)
argsArguments to forward to the constructor of the data

Definition at line 351 of file Restartable.h.

352 {
353  const auto full_name = restartableName(data_name);
354 
356 
357  return declareRestartableDataWithContext<T>(data_name, nullptr, std::forward<Args>(args)...);
358 }
std::string restartableName(const std::string &data_name) const
Gets the name of a piece of restartable data given a data name, adding the system name and object nam...
Definition: Restartable.C:66
void registerRestartableNameWithFilterOnApp(const std::string &name, Moose::RESTARTABLE_FILTER filter)
Helper function for actually registering the restartable data.
Definition: Restartable.C:59

◆ declareRestartableData()

template<typename T , typename... Args>
T & Restartable::declareRestartableData ( const std::string &  data_name,
Args &&...  args 
)
protected

Declare a piece of data as "restartable" and initialize it.

This means that in the event of a restart this piece of data will be restored back to its previous value.

NOTE: This returns a reference! Make sure you store it in a reference!

Parameters
data_nameThe name of the data (usually just use the same name as the member variable)
argsArguments to forward to the constructor of the data

Definition at line 269 of file Restartable.h.

270 {
271  return declareRestartableDataWithContext<T>(data_name, nullptr, std::forward<Args>(args)...);
272 }

◆ declareRestartableDataHelper()

template<typename T , typename... Args>
RestartableData< T > & Restartable::declareRestartableDataHelper ( const std::string &  data_name,
void context,
Args &&...  args 
) const
private

Helper function for declaring restartable data.

We use this function to reduce code duplication when returning const/nonconst references to the data.

Parameters
data_nameThe name of the data (usually just use the same name as the member variable)
contextContext pointer that will be passed to the load and store functions
argsArguments to forward to the constructor of the data

Definition at line 303 of file Restartable.h.

306 {
307  const auto full_name = restartableName(data_name);
308 
309  // Here we will create the RestartableData even though we may not use this instance.
310  // If it's already in use, the App will return a reference to the existing instance and we'll
311  // return that one instead. We might refactor this to have the app create the RestartableData
312  // at a later date.
313  auto data_ptr =
314  std::make_unique<RestartableData<T>>(full_name, context, std::forward<Args>(args)...);
315  auto & restartable_data_ref = static_cast<RestartableData<T> &>(
316  registerRestartableDataOnApp(std::move(data_ptr), _restartable_tid));
317 
318  return restartable_data_ref;
319 }
std::string restartableName(const std::string &data_name) const
Gets the name of a piece of restartable data given a data name, adding the system name and object nam...
Definition: Restartable.C:66
Concrete definition of a parameter value for a specified type.
const THREAD_ID _restartable_tid
The thread ID for this object.
Definition: Restartable.h:233
RestartableDataValue & registerRestartableDataOnApp(std::unique_ptr< RestartableDataValue > data, THREAD_ID tid) const
Helper function for actually registering the restartable data.
Definition: Restartable.C:51

◆ declareRestartableDataWithContext()

template<typename T , typename... Args>
T & Restartable::declareRestartableDataWithContext ( const std::string &  data_name,
void context,
Args &&...  args 
)
protected

Declare a piece of data as "restartable" and initialize it.

This means that in the event of a restart this piece of data will be restored back to its previous value.

NOTE: This returns a reference! Make sure you store it in a reference!

Parameters
data_nameThe name of the data (usually just use the same name as the member variable)
contextContext pointer that will be passed to the load and store functions
argsArguments to forward to the constructor of the data

Definition at line 294 of file Restartable.h.

297 {
298  return declareRestartableDataHelper<T>(data_name, context, std::forward<Args>(args)...).set();
299 }

◆ declareRestartableDataWithObjectName()

template<typename T , typename... Args>
T & Restartable::declareRestartableDataWithObjectName ( const std::string &  data_name,
const std::string &  object_name,
Args &&...  args 
)
protected

Declare a piece of data as "restartable".

This means that in the event of a restart this piece of data will be restored back to its previous value.

NOTE: This returns a reference! Make sure you store it in a reference!

Parameters
data_nameThe name of the data (usually just use the same name as the member variable)
object_nameA supplied name for the object that is declaring this data.
argsArguments to forward to the constructor of the data

Definition at line 323 of file Restartable.h.

326 {
327  return declareRestartableDataWithObjectNameWithContext<T>(
328  data_name, object_name, nullptr, std::forward<Args>(args)...);
329 }

◆ declareRestartableDataWithObjectNameWithContext()

template<typename T , typename... Args>
T & Restartable::declareRestartableDataWithObjectNameWithContext ( const std::string &  data_name,
const std::string &  object_name,
void context,
Args &&...  args 
)
protected

Declare a piece of data as "restartable".

This means that in the event of a restart this piece of data will be restored back to its previous value.

NOTE: This returns a reference! Make sure you store it in a reference!

Parameters
data_nameThe name of the data (usually just use the same name as the member variable)
object_nameA supplied name for the object that is declaring this data.
contextContext pointer that will be passed to the load and store functions
argsArguments to forward to the constructor of the data

Definition at line 333 of file Restartable.h.

337 {
338  std::string old_name = _restartable_name;
339 
340  _restartable_name = object_name;
341 
342  T & value = declareRestartableDataWithContext<T>(data_name, context, std::forward<Args>(args)...);
343 
344  _restartable_name = old_name;
345 
346  return value;
347 }
std::string _restartable_name
The name of the object.
Definition: Restartable.h:243
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)

◆ getRestartableData()

template<typename T , typename... Args>
const T & Restartable::getRestartableData ( const std::string &  data_name) const
protected

Declare a piece of data as "restartable" and initialize it Similar to declareRestartableData but returns a const reference to the object.

Forwarded arguments are not allowed in this case because we assume that the object is restarted and we won't need different constructors to initialize it.

NOTE: This returns a const reference! Make sure you store it in a const reference!

Parameters
data_nameThe name of the data (usually just use the same name as the member variable)

Definition at line 287 of file Restartable.h.

288 {
289  return declareRestartableDataHelper<T>(data_name, nullptr).get();
290 }

◆ registerRestartableDataOnApp()

RestartableDataValue & Restartable::registerRestartableDataOnApp ( std::unique_ptr< RestartableDataValue data,
THREAD_ID  tid 
) const
private

Helper function for actually registering the restartable data.

Definition at line 51 of file Restartable.C.

Referenced by declareRestartableDataHelper().

53 {
55  std::move(data), tid, _restartable_read_only, _metaname);
56 }
RestartableDataValue & registerRestartableData(std::unique_ptr< RestartableDataValue > data, THREAD_ID tid, bool read_only, const RestartableDataMapName &metaname="")
Definition: MooseApp.C:1806
const bool _restartable_read_only
Flag for toggling read only status (see ReporterData)
Definition: Restartable.h:236
const RestartableDataMapName _metaname
Restartable metadata name.
Definition: Restartable.h:240
MooseApp & _restartable_app
Reference to the application.
Definition: Restartable.h:227

◆ registerRestartableNameWithFilterOnApp()

void Restartable::registerRestartableNameWithFilterOnApp ( const std::string &  name,
Moose::RESTARTABLE_FILTER  filter 
)
private

Helper function for actually registering the restartable data.

Definition at line 59 of file Restartable.C.

Referenced by declareRecoverableData().

61 {
63 }
void registerRestartableNameWithFilter(const std::string &name, Moose::RESTARTABLE_FILTER filter)
NOTE: This is an internal function meant for MOOSE use only!
Definition: MooseApp.C:1199
MooseApp & _restartable_app
Reference to the application.
Definition: Restartable.h:227

◆ restartableName()

std::string Restartable::restartableName ( const std::string &  data_name) const
protected

Gets the name of a piece of restartable data given a data name, adding the system name and object name prefix.

This should only be used in this interface and in testing.

Definition at line 66 of file Restartable.C.

Referenced by declareRecoverableData(), and declareRestartableDataHelper().

67 {
68  return _restartable_system_name + "/" + _restartable_name + "/" + data_name;
69 }
std::string _restartable_name
The name of the object.
Definition: Restartable.h:243
const std::string _restartable_system_name
The system name this object is in.
Definition: Restartable.h:230

Member Data Documentation

◆ _metaname

const RestartableDataMapName Restartable::_metaname
private

Restartable metadata name.

Definition at line 240 of file Restartable.h.

Referenced by registerRestartableDataOnApp().

◆ _restartable_app

MooseApp& Restartable::_restartable_app
protected

Reference to the application.

Definition at line 227 of file Restartable.h.

Referenced by registerRestartableDataOnApp(), and registerRestartableNameWithFilterOnApp().

◆ _restartable_name

std::string Restartable::_restartable_name
private

The name of the object.

Definition at line 243 of file Restartable.h.

Referenced by declareRestartableDataWithObjectNameWithContext(), and restartableName().

◆ _restartable_read_only

const bool Restartable::_restartable_read_only
protected

Flag for toggling read only status (see ReporterData)

Definition at line 236 of file Restartable.h.

Referenced by registerRestartableDataOnApp().

◆ _restartable_system_name

const std::string Restartable::_restartable_system_name
protected

The system name this object is in.

Definition at line 230 of file Restartable.h.

Referenced by restartableName().

◆ _restartable_tid

const THREAD_ID Restartable::_restartable_tid
protected

The thread ID for this object.

Definition at line 233 of file Restartable.h.

Referenced by declareRestartableDataHelper().


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