https://mooseframework.inl.gov
ControlData.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 #include "Restartable.h"
13 
14 class ControlDataValue;
15 class THMControl;
16 
21 {
22 public:
28  ControlDataValue(MooseApp & moose_app, const std::string & name)
29  : Restartable(moose_app, name, "thm::control_logic", 0),
30  _name(name),
31  _declared(false),
32  _control(nullptr)
33  {
34  }
35 
39  virtual ~ControlDataValue() = default;
40 
45  virtual std::string type() = 0;
46 
50  const std::string & name() const { return _name; }
51 
55  const THMControl * getControl() const { return _control; }
56 
60  void setControl(THMControl * ctrl) { _control = ctrl; }
61 
65  void setDeclared() { _declared = true; }
66 
70  bool getDeclared() { return _declared; }
71 
75  virtual void copyValuesBack() = 0;
76 
77 protected:
79  const std::string _name;
81  bool _declared;
84 };
85 
90 template <typename T>
92 {
93 public:
98  ControlData(MooseApp & moose_app, std::string name)
99  : ControlDataValue(moose_app, name),
102  {
103  }
104 
108  const T & get() const { return _value; }
109 
113  const T & getOld() const { return _value_old; }
114 
118  T & set() { return _value; }
119 
123  virtual std::string type() override;
124 
125  virtual void copyValuesBack() override;
126 
127 private:
129  T & _value;
132 };
133 
134 // ------------------------------------------------------------
135 // ControlData<> class inline methods
136 template <typename T>
137 inline std::string
139 {
140  return typeid(T).name();
141 }
142 
143 template <typename T>
144 inline void
146 {
147  _value_old = _value;
148 }
Abstract definition of a ControlData value.
Definition: ControlData.h:20
void setDeclared()
Mark the data as declared.
Definition: ControlData.h:65
virtual void copyValuesBack()=0
Copy the current value into old (i.e.
bool _declared
true if the data was declared by calling declareControlData. All data must be declared up front...
Definition: ControlData.h:81
const T & getOld() const
Definition: ControlData.h:113
T & _value_old
Stored old value.
Definition: ControlData.h:131
T & declareRestartableData(const std::string &data_name, Args &&... args)
virtual std::string type()=0
String identifying the type of parameter stored.
virtual std::string type() override
String identifying the type of parameter stored.
Definition: ControlData.h:138
ControlData(MooseApp &moose_app, std::string name)
Constructor.
Definition: ControlData.h:98
Concrete definition of a parameter value for a specified type.
Definition: ControlData.h:91
bool getDeclared()
Get the declared state.
Definition: ControlData.h:70
const THMControl * getControl() const
Get the pointer to the control object that declared this control data.
Definition: ControlData.h:55
const std::string name
Definition: Setup.h:20
const std::string _name
The full (unique) name of this particular piece of data.
Definition: ControlData.h:79
T & _value
Stored value.
Definition: ControlData.h:129
void setControl(THMControl *ctrl)
Set the pointer to the control object that declared this control data.
Definition: ControlData.h:60
virtual void copyValuesBack() override
Copy the current value into old (i.e.
Definition: ControlData.h:145
THMControl * _control
The control object that declared this control data.
Definition: ControlData.h:83
const std::string & name() const
The full (unique) name of this particular piece of data.
Definition: ControlData.h:50
ControlDataValue(MooseApp &moose_app, const std::string &name)
Constructor.
Definition: ControlData.h:28
virtual ~ControlDataValue()=default
Destructor.