https://mooseframework.inl.gov
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...
 
 Restartable (const Restartable &object, const Moose::Kokkos::FunctorCopy &key)
 Special constructor used for Kokkos functor copy during parallel dispatch. 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/4]

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.
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:131
MooseApp & getMooseApp() const
Get the MooseApp this class is associated with.
Definition: MooseBase.h:87
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:103
Restartable(const MooseObject *moose_object, const std::string &system_name)
Class constructor.
Definition: Restartable.C:18
unsigned int THREAD_ID
Definition: MooseTypes.h:209
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.

◆ Restartable() [2/4]

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 }
MooseApp & getMooseApp() const
Get the MooseApp this class is associated with.
Definition: MooseBase.h:87
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:103
Restartable(const MooseObject *moose_object, const std::string &system_name)
Class constructor.
Definition: Restartable.C:18

◆ Restartable() [3/4]

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:250
const std::string _restartable_system_name
The system name this object is in.
Definition: Restartable.h:237
const THREAD_ID _restartable_tid
The thread ID for this object.
Definition: Restartable.h:240
const bool _restartable_read_only
Flag for toggling read only status (see ReporterData)
Definition: Restartable.h:243
const RestartableDataMapName _metaname
Restartable metadata name.
Definition: Restartable.h:247
MooseApp & _restartable_app
Reference to the application.
Definition: Restartable.h:234

◆ Restartable() [4/4]

Restartable::Restartable ( const Restartable object,
const Moose::Kokkos::FunctorCopy key 
)

Special constructor used for Kokkos functor copy during parallel dispatch.

Definition at line 51 of file Restartable.C.

56  _metaname(object._metaname),
58 {
59 }
std::string _restartable_name
The name of the object.
Definition: Restartable.h:250
const std::string _restartable_system_name
The system name this object is in.
Definition: Restartable.h:237
const THREAD_ID _restartable_tid
The thread ID for this object.
Definition: Restartable.h:240
const bool _restartable_read_only
Flag for toggling read only status (see ReporterData)
Definition: Restartable.h:243
const RestartableDataMapName _metaname
Restartable metadata name.
Definition: Restartable.h:247
MooseApp & _restartable_app
Reference to the application.
Definition: Restartable.h:234

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 283 of file Restartable.h.

286 {
287  auto & data_ptr =
288  declareRestartableDataHelper<T>(data_name, context, std::forward<Args>(args)...);
289  return Restartable::ManagedValue<T>(data_ptr);
290 }
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 358 of file Restartable.h.

359 {
360  const auto full_name = restartableName(data_name);
361 
363 
364  return declareRestartableDataWithContext<T>(data_name, nullptr, std::forward<Args>(args)...);
365 }
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:78
void registerRestartableNameWithFilterOnApp(const std::string &name, Moose::RESTARTABLE_FILTER filter)
Helper function for actually registering the restartable data.
Definition: Restartable.C:71

◆ 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 276 of file Restartable.h.

277 {
278  return declareRestartableDataWithContext<T>(data_name, nullptr, std::forward<Args>(args)...);
279 }

◆ 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 310 of file Restartable.h.

313 {
314  const auto full_name = restartableName(data_name);
315 
316  // Here we will create the RestartableData even though we may not use this instance.
317  // If it's already in use, the App will return a reference to the existing instance and we'll
318  // return that one instead. We might refactor this to have the app create the RestartableData
319  // at a later date.
320  auto data_ptr =
321  std::make_unique<RestartableData<T>>(full_name, context, std::forward<Args>(args)...);
322  auto & restartable_data_ref = static_cast<RestartableData<T> &>(
323  registerRestartableDataOnApp(std::move(data_ptr), _restartable_tid));
324 
325  return restartable_data_ref;
326 }
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:78
Concrete definition of a parameter value for a specified type.
const THREAD_ID _restartable_tid
The thread ID for this object.
Definition: Restartable.h:240
RestartableDataValue & registerRestartableDataOnApp(std::unique_ptr< RestartableDataValue > data, THREAD_ID tid) const
Helper function for actually registering the restartable data.
Definition: Restartable.C:63

◆ 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 301 of file Restartable.h.

304 {
305  return declareRestartableDataHelper<T>(data_name, context, std::forward<Args>(args)...).set();
306 }

◆ 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 330 of file Restartable.h.

333 {
334  return declareRestartableDataWithObjectNameWithContext<T>(
335  data_name, object_name, nullptr, std::forward<Args>(args)...);
336 }

◆ 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 340 of file Restartable.h.

344 {
345  std::string old_name = _restartable_name;
346 
347  _restartable_name = object_name;
348 
349  T & value = declareRestartableDataWithContext<T>(data_name, context, std::forward<Args>(args)...);
350 
351  _restartable_name = old_name;
352 
353  return value;
354 }
std::string _restartable_name
The name of the object.
Definition: Restartable.h:250
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 294 of file Restartable.h.

295 {
296  return declareRestartableDataHelper<T>(data_name, nullptr).get();
297 }

◆ 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 63 of file Restartable.C.

Referenced by declareRestartableDataHelper().

65 {
67  std::move(data), tid, _restartable_read_only, _metaname);
68 }
RestartableDataValue & registerRestartableData(std::unique_ptr< RestartableDataValue > data, THREAD_ID tid, bool read_only, const RestartableDataMapName &metaname="")
Definition: MooseApp.C:2522
const bool _restartable_read_only
Flag for toggling read only status (see ReporterData)
Definition: Restartable.h:243
const RestartableDataMapName _metaname
Restartable metadata name.
Definition: Restartable.h:247
MooseApp & _restartable_app
Reference to the application.
Definition: Restartable.h:234

◆ registerRestartableNameWithFilterOnApp()

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

Helper function for actually registering the restartable data.

Definition at line 71 of file Restartable.C.

Referenced by declareRecoverableData().

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

◆ 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 78 of file Restartable.C.

Referenced by declareRecoverableData(), and declareRestartableDataHelper().

79 {
80  return _restartable_system_name + "/" + _restartable_name + "/" + data_name;
81 }
std::string _restartable_name
The name of the object.
Definition: Restartable.h:250
const std::string _restartable_system_name
The system name this object is in.
Definition: Restartable.h:237

Member Data Documentation

◆ _metaname

const RestartableDataMapName Restartable::_metaname
private

Restartable metadata name.

Definition at line 247 of file Restartable.h.

Referenced by registerRestartableDataOnApp().

◆ _restartable_app

MooseApp& Restartable::_restartable_app
protected

Reference to the application.

Definition at line 234 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 250 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 243 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 237 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 240 of file Restartable.h.

Referenced by declareRestartableDataHelper().


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