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 : #include "Restartable.h" 13 : #include "MooseUtils.h" 14 : 15 : class ChainControl; 16 : 17 : /** 18 : * Abstract definition of a ChainControlData value. 19 : */ 20 : class ChainControlDataBase : public Restartable 21 : { 22 : public: 23 : /** 24 : * Constructor 25 : * @param moose_app MooseApp object this object belong to 26 : * @param name The full (unique) name for this piece of data. 27 : */ 28 448 : ChainControlDataBase(MooseApp & moose_app, const std::string & name) 29 448 : : Restartable(moose_app, name, "chain_control", 0), 30 448 : _name(name), 31 448 : _declared(false), 32 448 : _chain_control(nullptr) 33 : { 34 448 : } 35 : 36 392 : virtual ~ChainControlDataBase() = default; 37 : 38 : /** 39 : * String identifying the type of parameter stored. 40 : * Must be reimplemented in derived classes. 41 : */ 42 : virtual std::string type() = 0; 43 : 44 : /** 45 : * The full (unique) name of this particular piece of data. 46 : */ 47 48 : const std::string & name() const { return _name; } 48 : 49 : /** 50 : * Get the pointer to the control object that declared this control data 51 : */ 52 : const ChainControl & getChainControl() const; 53 : 54 : /** 55 : * Set the pointer to the control object that declared this control data 56 : */ 57 448 : void setChainControl(ChainControl & ctrl) { _chain_control = &ctrl; } 58 : 59 : /** 60 : * Mark the data as declared 61 : */ 62 448 : void setDeclared() { _declared = true; } 63 : 64 : /** 65 : * Get the declared state 66 : */ 67 880 : bool getDeclared() { return _declared; } 68 : 69 : /** 70 : * Copy the current value into the old value 71 : */ 72 : virtual void copyValuesBack() = 0; 73 : 74 : protected: 75 : /// The full (unique) name of this particular piece of data. 76 : const std::string _name; 77 : /// true if the data was declared by calling declareControlData. All data must be declared up front. 78 : bool _declared; 79 : /// The control object that declared this control data 80 : ChainControl * _chain_control; 81 : }; 82 : 83 : /** 84 : * Concrete definition of a parameter value 85 : * for a specified type. 86 : */ 87 : template <typename T> 88 : class ChainControlData : public ChainControlDataBase 89 : { 90 : public: 91 : /** 92 : * Constructor 93 : * @param name The full (unique) name for this piece of data. 94 : */ 95 448 : ChainControlData(MooseApp & moose_app, std::string name) 96 : : ChainControlDataBase(moose_app, name), 97 896 : _value(declareRestartableData<T>(name)), 98 448 : _value_old(declareRestartableData<T>(name + "_old")) 99 : { 100 448 : } 101 : 102 : /** 103 : * @returns a read-only reference to the parameter value. 104 : */ 105 2162 : const T & get() const { return _value; } 106 : 107 : /** 108 : * @returns a read-only reference to the old value. 109 : */ 110 36 : const T & getOld() const { return _value_old; } 111 : 112 : /** 113 : * @returns a writable reference to the current value. 114 : */ 115 448 : T & set() { return _value; } 116 : 117 : /** 118 : * String identifying the type of parameter stored. 119 : */ 120 : virtual std::string type() override; 121 : 122 : virtual void copyValuesBack() override; 123 : 124 : private: 125 : /// Current value 126 : T & _value; 127 : /// Old value 128 : T & _value_old; 129 : }; 130 : 131 : template <typename T> 132 : inline std::string 133 4 : ChainControlData<T>::type() 134 : { 135 4 : return MooseUtils::prettyCppType<T>(); 136 : } 137 : 138 : template <typename T> 139 : inline void 140 5859 : ChainControlData<T>::copyValuesBack() 141 : { 142 5859 : _value_old = _value; 143 5859 : }