Line data Source code
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 "Restartable.h" 14 : 15 : /** 16 : * A class which creates public interface functions for declaring and 17 : * getting restartable data. This is needed for objects which need to 18 : * store Restartable as a data member instead of inheriting from it. 19 : */ 20 170 : class PublicRestartable : public Restartable 21 : { 22 : public: 23 : /** 24 : * This class constructor is used for non-Moose-based objects like interfaces. A name for the 25 : * storage as well as a system name must be passed in along with the thread ID explicitly. 26 : * @param moose_app Reference to the application 27 : * @param name The name which is used when constructing the full-names of the restartable data. 28 : * It is used with the following logic: `system_name/name/data_name`. 29 : * (e.g. UserObjects/diffusion_kernel/coefficient). In most of the cases this is the 30 : * name of the moose object. 31 : * @param system_name The name of the system where this object belongs to. 32 : * @param tid The thread ID. 33 : * @param read_only Switch to restrict the data for read-only. 34 : * @param metaname The name of the datamap where the restartable objects should be registered to. 35 : */ 36 : PublicRestartable(MooseApp & moose_app, 37 : const std::string & name, 38 : const std::string & system_name, 39 : THREAD_ID tid, 40 : const bool read_only = false, 41 : const RestartableDataMapName & metaname = "") 42 3060 : : Restartable(moose_app, name, system_name, tid, read_only, metaname) 43 : { 44 3060 : } 45 : 46 : /** 47 : * Declare a piece of data as "restartable" and initialize it. 48 : * This means that in the event of a restart this piece of data 49 : * will be restored back to its previous value. 50 : * 51 : * NOTE: This returns a _reference_! Make sure you store it in a _reference_! 52 : * 53 : * @param data_name The name of the data (usually just use the same name as the member 54 : * variable) 55 : * @param args Arguments to forward to the constructor of the data 56 : */ 57 : template <typename T, typename... Args> 58 : T & declareRestartableData(const std::string & data_name, Args &&... args) 59 : { 60 3430 : return Restartable::declareRestartableData<T>(data_name, std::forward<Args>(args)...); 61 : } 62 : 63 : /** 64 : * Declare a piece of data as "restartable" and initialize it 65 : * Similar to `declareRestartableData` but returns a const reference to the object. 66 : * Forwarded arguments are not allowed in this case because we assume that the 67 : * object is restarted and we won't need different constructors to initialize it. 68 : * 69 : * NOTE: This returns a _const reference_! Make sure you store it in a _const reference_! 70 : * 71 : * @param data_name The name of the data (usually just use the same name as the member variable) 72 : */ 73 : template <typename T, typename... Args> 74 : const T & getRestartableData(const std::string & data_name) const 75 : { 76 1256 : return Restartable::getRestartableData<T>(data_name); 77 : } 78 : };