https://mooseframework.inl.gov
ChainControlData.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 #include "MooseUtils.h"
14 
15 class ChainControl;
16 
21 {
22 public:
28  ChainControlDataBase(MooseApp & moose_app, const std::string & name)
29  : Restartable(moose_app, name, "chain_control", 0),
30  _name(name),
31  _declared(false),
32  _chain_control(nullptr)
33  {
34  }
35 
36  virtual ~ChainControlDataBase() = default;
37 
42  virtual std::string type() = 0;
43 
47  const std::string & name() const { return _name; }
48 
52  const ChainControl & getChainControl() const;
53 
57  void setChainControl(ChainControl & ctrl) { _chain_control = &ctrl; }
58 
62  void setDeclared() { _declared = true; }
63 
67  bool getDeclared() { return _declared; }
68 
72  virtual void copyValuesBack() = 0;
73 
74 protected:
76  const std::string _name;
78  bool _declared;
81 };
82 
87 template <typename T>
89 {
90 public:
95  ChainControlData(MooseApp & moose_app, std::string name)
96  : ChainControlDataBase(moose_app, name),
99  {
100  }
101 
105  const T & get() const { return _value; }
106 
110  const T & getOld() const { return _value_old; }
111 
115  T & set() { return _value; }
116 
120  virtual std::string type() override;
121 
122  virtual void copyValuesBack() override;
123 
124 private:
126  T & _value;
129 };
130 
131 template <typename T>
132 inline std::string
134 {
135  return MooseUtils::prettyCppType<T>();
136 }
137 
138 template <typename T>
139 inline void
141 {
142  _value_old = _value;
143 }
A class for creating restricted objects.
Definition: Restartable.h:28
const std::string _name
The full (unique) name of this particular piece of data.
ChainControlDataBase(MooseApp &moose_app, const std::string &name)
Constructor.
const T & getOld() const
virtual std::string type()=0
String identifying the type of parameter stored.
Base class for MOOSE-based applications.
Definition: MooseApp.h:85
T & declareRestartableData(const std::string &data_name, Args &&... args)
Declare a piece of data as "restartable" and initialize it.
Definition: Restartable.h:269
ChainControlData(MooseApp &moose_app, std::string name)
Constructor.
void setChainControl(ChainControl &ctrl)
Set the pointer to the control object that declared this control data.
T & _value
Current value.
T & _value_old
Old value.
const ChainControl & getChainControl() const
Get the pointer to the control object that declared this control data.
const std::string & name() const
The full (unique) name of this particular piece of data.
void setDeclared()
Mark the data as declared.
ChainControl * _chain_control
The control object that declared this control data.
bool _declared
true if the data was declared by calling declareControlData. All data must be declared up front...
Concrete definition of a parameter value for a specified type.
virtual std::string type() override
String identifying the type of parameter stored.
bool getDeclared()
Get the declared state.
virtual void copyValuesBack() override
Copy the current value into the old value.
Abstract definition of a ChainControlData value.
virtual void copyValuesBack()=0
Copy the current value into the old value.
virtual ~ChainControlDataBase()=default
Control that additionally provides the capability to produce/consume data values, to allow control op...
Definition: ChainControl.h:21