www.mooseframework.org
Restartable.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 // MOOSE includes
13 #include "MooseTypes.h"
14 #include "RestartableData.h"
15 
16 #define adDeclareRestartableData this->template declareRestartableData
17 
18 // Forward declarations
19 class PostprocessorData;
20 class SubProblem;
21 class InputParameters;
22 class MooseObject;
23 class MooseApp;
24 
30 {
31 public:
42  Restartable(const MooseObject * moose_object, const std::string & system_name);
43 
51  Restartable(const MooseObject * moose_object, const std::string & system_name, THREAD_ID tid);
52 
57  Restartable(MooseApp & moose_app,
58  const std::string & name,
59  const std::string & system_name,
60  THREAD_ID tid);
61 
65  virtual ~Restartable() = default;
66 
67 protected:
77  template <typename T>
78  T & declareRestartableData(std::string data_name);
79 
90  template <typename T>
91  T & declareRestartableData(std::string data_name, const T & init_value);
92 
103  template <typename T>
104  T & declareRestartableDataWithContext(std::string data_name, void * context);
105 
117  template <typename T>
118  T &
119  declareRestartableDataWithContext(std::string data_name, const T & init_value, void * context);
120 
132  template <typename T>
133  T & declareRecoverableData(std::string data_name);
134 
147  template <typename T>
148  T & declareRecoverableData(std::string data_name, const T & init_value);
149 
160  template <typename T>
161  T & declareRestartableDataWithObjectName(std::string data_name, std::string object_name);
162 
174  template <typename T>
175  T & declareRestartableDataWithObjectNameWithContext(std::string data_name,
176  std::string object_name,
177  void * context);
178 
179 private:
181  void registerRestartableDataOnApp(std::string name,
182  std::unique_ptr<RestartableDataValue> data,
183  THREAD_ID tid);
184 
186  void registerRecoverableDataOnApp(std::string name);
187 
190 
192  std::string _restartable_name;
193 
196 
199 };
200 
201 template <typename T>
202 T &
204 {
205  return declareRestartableDataWithContext<T>(data_name, nullptr);
206 }
207 
208 template <typename T>
209 T &
210 Restartable::declareRestartableData(std::string data_name, const T & init_value)
211 {
212  return declareRestartableDataWithContext<T>(data_name, init_value, nullptr);
213 }
214 
215 template <typename T>
216 T &
217 Restartable::declareRestartableDataWithContext(std::string data_name, void * context)
218 {
219  std::string full_name = _restartable_system_name + "/" + _restartable_name + "/" + data_name;
220  auto data_ptr = libmesh_make_unique<RestartableData<T>>(full_name, context);
221  T & restartable_data_ref = data_ptr->get();
222 
223  registerRestartableDataOnApp(full_name, std::move(data_ptr), _restartable_tid);
224 
225  return restartable_data_ref;
226 }
227 
228 template <typename T>
229 T &
231  const T & init_value,
232  void * context)
233 {
234  std::string full_name = _restartable_system_name + "/" + _restartable_name + "/" + data_name;
235  auto data_ptr = libmesh_make_unique<RestartableData<T>>(full_name, context);
236  data_ptr->set() = init_value;
237 
238  T & restartable_data_ref = data_ptr->get();
239  registerRestartableDataOnApp(full_name, std::move(data_ptr), _restartable_tid);
240 
241  return restartable_data_ref;
242 }
243 
244 template <typename T>
245 T &
246 Restartable::declareRestartableDataWithObjectName(std::string data_name, std::string object_name)
247 {
248  return declareRestartableDataWithObjectNameWithContext<T>(data_name, object_name, nullptr);
249 }
250 
251 template <typename T>
252 T &
254  std::string object_name,
255  void * context)
256 {
257  std::string old_name = _restartable_name;
258 
259  _restartable_name = object_name;
260 
261  T & value = declareRestartableDataWithContext<T>(data_name, context);
262 
263  _restartable_name = old_name;
264 
265  return value;
266 }
267 
268 template <typename T>
269 T &
271 {
272  std::string full_name = _restartable_system_name + "/" + _restartable_name + "/" + data_name;
273 
274  registerRecoverableDataOnApp(full_name);
275 
276  return declareRestartableDataWithContext<T>(data_name, nullptr);
277 }
278 
279 template <typename T>
280 T &
281 Restartable::declareRecoverableData(std::string data_name, const T & init_value)
282 {
283  std::string full_name = _restartable_system_name + "/" + _restartable_name + "/" + data_name;
284 
285  registerRecoverableDataOnApp(full_name);
286 
287  return declareRestartableDataWithContext<T>(data_name, init_value, nullptr);
288 }
289 
std::string _restartable_system_name
The system name this object is in.
Definition: Restartable.h:195
A class for creating restricted objects.
Definition: Restartable.h:29
T & declareRecoverableData(std::string data_name)
Declare a piece of data as "recoverable".
Definition: Restartable.h:270
T & declareRestartableDataWithObjectName(std::string data_name, std::string object_name)
Declare a piece of data as "restartable".
Definition: Restartable.h:246
Base class for MOOSE-based applications.
Definition: MooseApp.h:59
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::string _restartable_name
The name of the object.
Definition: Restartable.h:192
void registerRecoverableDataOnApp(std::string name)
Helper function for actually registering the restartable data.
Definition: Restartable.C:54
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:42
virtual ~Restartable()=default
Emtpy destructor.
Restartable(const MooseObject *moose_object, const std::string &system_name)
Class constructor.
Definition: Restartable.C:17
T & declareRestartableDataWithObjectNameWithContext(std::string data_name, std::string object_name, void *context)
Declare a piece of data as "restartable".
Definition: Restartable.h:253
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:59
T & declareRestartableDataWithContext(std::string data_name, void *context)
Declare a piece of data as "restartable".
Definition: Restartable.h:217
THREAD_ID _restartable_tid
The thread ID for this object.
Definition: Restartable.h:198
void registerRestartableDataOnApp(std::string name, std::unique_ptr< RestartableDataValue > data, THREAD_ID tid)
Helper function for actually registering the restartable data.
Definition: Restartable.C:46
MooseApp & _restartable_app
Reference to the application.
Definition: Restartable.h:189
unsigned int THREAD_ID
Definition: MooseTypes.h:161
T & declareRestartableData(std::string data_name)
Declare a piece of data as "restartable".
Definition: Restartable.h:203