https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Restartable.h
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
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// Forward declarations
17class PostprocessorData;
18class SubProblem;
19class InputParameters;
20class MooseObject;
21class MooseApp;
22class MooseMesh;
23
29{
30public:
41 template <typename T>
43 {
44 public:
46
52 ~ManagedValue() { _value.reset(); }
53
58 const T & get() const { return _value.get(); }
59 T & set() { return _value.set(); }
61
62 private:
65 };
66
77 Restartable(const MooseObject * moose_object, const std::string & system_name);
78
86 Restartable(const MooseObject * moose_object, const std::string & system_name, THREAD_ID tid);
87
101 Restartable(MooseApp & moose_app,
102 const std::string & name,
103 const std::string & system_name,
104 THREAD_ID tid,
105 const bool read_only = false,
106 const RestartableDataMapName & metaname = "");
107
108#ifdef MOOSE_KOKKOS_ENABLED
112 Restartable(const Restartable & object, const Moose::Kokkos::FunctorCopy & key);
113#endif
114
115protected:
126 template <typename T, typename... Args>
127 T & declareRestartableData(const std::string & data_name, Args &&... args);
128
143 template <typename T, typename... Args>
144 ManagedValue<T> declareManagedRestartableDataWithContext(const std::string & data_name,
145 void * context,
146 Args &&... args);
147
158 template <typename T, typename... Args>
159 const T & getRestartableData(const std::string & data_name) const;
160
172 template <typename T, typename... Args>
173 T &
174 declareRestartableDataWithContext(const std::string & data_name, void * context, Args &&... args);
175
188 template <typename T, typename... Args>
189 T & declareRecoverableData(const std::string & data_name, Args &&... args);
190
202 template <typename T, typename... Args>
203 T & declareRestartableDataWithObjectName(const std::string & data_name,
204 const std::string & object_name,
205 Args &&... args);
206
219 template <typename T, typename... Args>
220 T & declareRestartableDataWithObjectNameWithContext(const std::string & data_name,
221 const std::string & object_name,
222 void * context,
223 Args &&... args);
224
231 std::string restartableName(const std::string & data_name) const;
232
235
237 const std::string _restartable_system_name;
238
241
244
245private:
248
250 std::string _restartable_name;
251
253 RestartableDataValue & registerRestartableDataOnApp(std::unique_ptr<RestartableDataValue> data,
254 THREAD_ID tid) const;
255
257 void registerRestartableNameWithFilterOnApp(const std::string & name,
259
268 template <typename T, typename... Args>
269 RestartableData<T> & declareRestartableDataHelper(const std::string & data_name,
270 void * context,
271 Args &&... args) const;
272};
273
274template <typename T, typename... Args>
275T &
276Restartable::declareRestartableData(const std::string & data_name, Args &&... args)
277{
278 return declareRestartableDataWithContext<T>(data_name, nullptr, std::forward<Args>(args)...);
279}
280
281template <typename T, typename... Args>
284 void * context,
285 Args &&... args)
286{
287 auto & data_ptr =
288 declareRestartableDataHelper<T>(data_name, context, std::forward<Args>(args)...);
289 return Restartable::ManagedValue<T>(data_ptr);
290}
291
292template <typename T, typename... Args>
293const T &
294Restartable::getRestartableData(const std::string & data_name) const
295{
296 return declareRestartableDataHelper<T>(data_name, nullptr).get();
297}
298
299template <typename T, typename... Args>
300T &
302 void * context,
303 Args &&... args)
304{
305 return declareRestartableDataHelper<T>(data_name, context, std::forward<Args>(args)...).set();
306}
307
308template <typename T, typename... Args>
310Restartable::declareRestartableDataHelper(const std::string & data_name,
311 void * context,
312 Args &&... args) const
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}
327
328template <typename T, typename... Args>
329T &
331 const std::string & object_name,
332 Args &&... args)
333{
334 return declareRestartableDataWithObjectNameWithContext<T>(
335 data_name, object_name, nullptr, std::forward<Args>(args)...);
336}
337
338template <typename T, typename... Args>
339T &
341 const std::string & object_name,
342 void * context,
343 Args &&... args)
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}
355
356template <typename T, typename... Args>
357T &
358Restartable::declareRecoverableData(const std::string & data_name, Args &&... args)
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 RestartableDataMapName
Definition MooseTypes.h:242
unsigned int THREAD_ID
Definition MooseTypes.h:237
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
Base class for MOOSE-based applications.
Definition MooseApp.h:110
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition MooseMesh.h:95
Every object that can be built by the factory should be derived from this class.
Definition MooseObject.h:31
Abstract definition of a RestartableData value.
Concrete definition of a parameter value for a specified type.
Wrapper class for restartable data that is "managed.
Definition Restartable.h:43
ManagedValue(RestartableData< T > &value)
Definition Restartable.h:45
RestartableData< T > & _value
The underlying data.
Definition Restartable.h:64
const T & get() const
Get the restartable value.
Definition Restartable.h:58
A class for creating restricted objects.
Definition Restartable.h:29
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
T & declareRestartableData(const std::string &data_name, Args &&... args)
Declare a piece of data as "restartable" and initialize it.
const RestartableDataMapName _metaname
Restartable metadata name.
ManagedValue< T > declareManagedRestartableDataWithContext(const std::string &data_name, void *context, Args &&... args)
Declares a piece of "managed" restartable data and initialize it.
RestartableData< T > & declareRestartableDataHelper(const std::string &data_name, void *context, Args &&... args) const
Helper function for declaring restartable data.
T & declareRestartableDataWithContext(const std::string &data_name, void *context, Args &&... args)
Declare a piece of data as "restartable" and initialize it.
const T & getRestartableData(const std::string &data_name) const
Declare a piece of data as "restartable" and initialize it Similar to declareRestartableData but retu...
T & declareRestartableDataWithObjectName(const std::string &data_name, const std::string &object_name, Args &&... args)
Declare a piece of data as "restartable".
const THREAD_ID _restartable_tid
The thread ID for this object.
T & declareRestartableDataWithObjectNameWithContext(const std::string &data_name, const std::string &object_name, void *context, Args &&... args)
Declare a piece of data as "restartable".
T & declareRecoverableData(const std::string &data_name, Args &&... args)
Declare a piece of data as "recoverable" and initialize it.
const bool _restartable_read_only
Flag for toggling read only status (see ReporterData)
const std::string _restartable_system_name
The system name this object is in.
std::string _restartable_name
The name of the object.
void registerRestartableNameWithFilterOnApp(const std::string &name, Moose::RESTARTABLE_FILTER filter)
Helper function for actually registering the restartable data.
Definition Restartable.C:71
MooseApp & _restartable_app
Reference to the application.
RestartableDataValue & registerRestartableDataOnApp(std::unique_ptr< RestartableDataValue > data, THREAD_ID tid) const
Helper function for actually registering the restartable data.
Definition Restartable.C:63
Generic class for solving transient nonlinear problems.
Definition SubProblem.h:79
RESTARTABLE_FILTER
The filter type applied to a particular piece of "restartable" data.
Definition MooseTypes.h:846