https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
15class THMControl;
16
21{
22public:
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
77protected:
79 const std::string _name;
84};
85
90template <typename T>
92{
93public:
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
127private:
132};
133
134// ------------------------------------------------------------
135// ControlData<> class inline methods
136template <typename T>
137inline std::string
139{
140 return typeid(T).name();
141}
142
143template <typename T>
144inline void
146{
147 _value_old = _value;
148}
const double T
const std::string name
Definition Setup.h:21
Abstract definition of a ControlData value.
Definition ControlData.h:21
const std::string & name() const
The full (unique) name of this particular piece of data.
Definition ControlData.h:50
const THMControl * getControl() const
Get the pointer to the control object that declared this control data.
Definition ControlData.h:55
THMControl * _control
The control object that declared this control data.
Definition ControlData.h:83
bool getDeclared()
Get the declared state.
Definition ControlData.h:70
virtual void copyValuesBack()=0
Copy the current value into old (i.e.
void setControl(THMControl *ctrl)
Set the pointer to the control object that declared this control data.
Definition ControlData.h:60
virtual ~ControlDataValue()=default
Destructor.
virtual std::string type()=0
String identifying the type of parameter stored.
bool _declared
true if the data was declared by calling declareControlData. All data must be declared up front.
Definition ControlData.h:81
const std::string _name
The full (unique) name of this particular piece of data.
Definition ControlData.h:79
void setDeclared()
Mark the data as declared.
Definition ControlData.h:65
ControlDataValue(MooseApp &moose_app, const std::string &name)
Constructor.
Definition ControlData.h:28
Concrete definition of a parameter value for a specified type.
Definition ControlData.h:92
virtual std::string type() override
String identifying the type of parameter stored.
T & _value
Stored value.
T & _value_old
Stored old value.
const T & getOld() const
virtual void copyValuesBack() override
Copy the current value into old (i.e.
ControlData(MooseApp &moose_app, std::string name)
Constructor.
Definition ControlData.h:98
const T & get() const
T & declareRestartableData(const std::string &data_name, Args &&... args)