www.mooseframework.org
Restartable.h
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #ifndef RESTARTABLE_H
16 #define RESTARTABLE_H
17 
18 // MOOSE includes
19 #include "MooseTypes.h"
20 #include "RestartableData.h"
21 
22 // Forward declarations
23 class PostprocessorData;
24 class SubProblem;
25 class InputParameters;
26 
32 {
33 public:
44  Restartable(const InputParameters & parameters,
45  std::string system_name,
46  SubProblem * subproblem = NULL);
47 
57  Restartable(const std::string & name,
58  std::string system_name,
59  SubProblem & subproblem,
60  THREAD_ID tid = 0);
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 
121 private:
134  template <typename T>
135  T & declareRestartableDataWithObjectName(std::string data_name, std::string object_name);
136 
150  template <typename T>
151  T & declareRestartableDataWithObjectNameWithContext(std::string data_name,
152  std::string object_name,
153  void * context);
154 
168  template <typename T>
169  T & declareRecoverableData(std::string data_name);
170 
185  template <typename T>
186  T & declareRecoverableData(std::string data_name, const T & init_value);
187 
189  void
191 
193  void registerRecoverableDataOnSubProblem(std::string name);
194 
196  std::string _restartable_name;
197 
200 
203 
206 
209 
211  friend class PostprocessorData;
213  friend class NearestNodeLocator;
214  friend class ReportableData;
215  friend class FileOutput;
216  friend class FEProblemBase;
217  friend class Transient;
218  friend class TableOutput;
219  friend class TransientMultiApp;
220 };
221 
222 template <typename T>
223 T &
225 {
226  return declareRestartableDataWithContext<T>(data_name, NULL);
227 }
228 
229 template <typename T>
230 T &
231 Restartable::declareRestartableData(std::string data_name, const T & init_value)
232 {
233  return declareRestartableDataWithContext<T>(data_name, init_value, NULL);
234 }
235 
236 template <typename T>
237 T &
238 Restartable::declareRestartableDataWithContext(std::string data_name, void * context)
239 {
241  mooseError("No valid SubProblem found for ", _restartable_system_name, "/", _restartable_name);
242 
243  std::string full_name = _restartable_system_name + "/" + _restartable_name + "/" + data_name;
244  RestartableData<T> * data_ptr = new RestartableData<T>(full_name, context);
245 
247 
248  return data_ptr->get();
249 }
250 
251 template <typename T>
252 T &
254  const T & init_value,
255  void * context)
256 {
258  mooseError("No valid SubProblem found for ", _restartable_system_name, "/", _restartable_name);
259 
260  std::string full_name = _restartable_system_name + "/" + _restartable_name + "/" + data_name;
261  RestartableData<T> * data_ptr = new RestartableData<T>(full_name, context);
262 
263  data_ptr->set() = init_value;
264 
266 
267  return data_ptr->get();
268 }
269 
270 template <typename T>
271 T &
272 Restartable::declareRestartableDataWithObjectName(std::string data_name, std::string object_name)
273 {
274  return declareRestartableDataWithObjectNameWithContext<T>(data_name, object_name, NULL);
275 }
276 
277 template <typename T>
278 T &
280  std::string object_name,
281  void * context)
282 {
283  std::string old_name = _restartable_name;
284 
285  _restartable_name = object_name;
286 
287  T & value = declareRestartableDataWithContext<T>(data_name, context);
288 
289  _restartable_name = old_name;
290 
291  return value;
292 }
293 
294 template <typename T>
295 T &
297 {
299  mooseError("No valid SubProblem found for ", _restartable_system_name, "/", _restartable_name);
300 
301  std::string full_name = _restartable_system_name + "/" + _restartable_name + "/" + data_name;
302 
304 
305  return declareRestartableDataWithContext<T>(data_name, NULL);
306 }
307 
308 template <typename T>
309 T &
310 Restartable::declareRecoverableData(std::string data_name, const T & init_value)
311 {
313  mooseError("No valid SubProblem found for ", _restartable_system_name, "/", _restartable_name);
314 
315  std::string full_name = _restartable_system_name + "/" + _restartable_name + "/" + data_name;
316 
318 
319  return declareRestartableDataWithContext<T>(data_name, init_value, NULL);
320 }
321 
322 #endif // RESTARTABLE
friend class ReportableData
Definition: Restartable.h:214
std::string _restartable_system_name
The system name this object is in.
Definition: Restartable.h:202
const InputParameters * _restartable_params
The object&#39;s parameters.
Definition: Restartable.h:199
Transient executioners usually loop through a number of timesteps...
Definition: Transient.h:36
Restartable(const InputParameters &parameters, std::string system_name, SubProblem *subproblem=NULL)
Class constructor Populates the SubProblem and MooseMesh pointers.
Definition: Restartable.C:20
A class for creating restricted objects.
Definition: Restartable.h:31
T & declareRecoverableData(std::string data_name)
NOTE: These are used internally in MOOSE.
Definition: Restartable.h:296
T & declareRestartableDataWithObjectName(std::string data_name, std::string object_name)
Note: This is only used internally in MOOSE.
Definition: Restartable.h:272
Finds the nearest node to each node in boundary1 to each node in boundary2 and the other way around...
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
MultiApp Implementation for Transient Apps.
std::string _restartable_name
The name of the object.
Definition: Restartable.h:196
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
void registerRecoverableDataOnSubProblem(std::string name)
Helper function so we don&#39;t have to include SubProblem in the header.
Definition: Restartable.C:57
virtual ~Restartable()=default
Emtpy destructor.
void registerRestartableDataOnSubProblem(std::string name, RestartableDataValue *data, THREAD_ID tid)
Helper function so we don&#39;t have to include SubProblem in the header.
Definition: Restartable.C:49
T & declareRestartableDataWithObjectNameWithContext(std::string data_name, std::string object_name, void *context)
Note: This is only used internally in MOOSE.
Definition: Restartable.h:279
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:53
Concrete definition of a parameter value for a specified type.
T & declareRestartableDataWithContext(std::string data_name, void *context)
Declare a piece of data as "restartable".
Definition: Restartable.h:238
SubProblem * _restartable_subproblem
Pointer to the SubProblem class.
Definition: Restartable.h:208
Base class for scalar variables and postprocessors output objects.
Definition: TableOutput.h:39
THREAD_ID _restartable_tid
The thread ID for this object.
Definition: Restartable.h:205
An outputter with filename support.
Definition: FileOutput.h:32
Abstract definition of a RestartableData value.
unsigned int THREAD_ID
Definition: MooseTypes.h:79
T & declareRestartableData(std::string data_name)
Declare a piece of data as "restartable".
Definition: Restartable.h:224