https://mooseframework.inl.gov
THMControl.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 "Control.h"
13 #include "ControlData.h"
14 #include "THMProblem.h"
15 
16 class THMControl : public Control
17 {
18 public:
20 
21  virtual void init() {}
22 
26  const std::vector<std::string> & getControlDataDependencies() const
27  {
29  }
30 
31 protected:
37  template <typename T>
38  T & declareComponentControlData(const std::string & data_name);
39 
45  template <typename T>
46  T & declareControlData(const std::string & data_name);
47 
53  template <typename T>
54  const T & getControlData(const std::string & param_name);
55 
62  template <typename T>
63  const T & getControlDataOld(const std::string & param_name);
64 
70  template <typename T>
71  const T & getControlDataByName(const std::string & data_name);
72 
79  template <typename T>
80  const T & getControlDataOldByName(const std::string & data_name);
81 
87  template <typename T>
88  const T & getComponentControlDataOld(const std::string & data_name);
89 
91 
93  std::vector<std::string> _control_data_depends_on;
94 
95 public:
97 };
98 
99 template <typename T>
100 T &
101 THMControl::declareComponentControlData(const std::string & data_name)
102 {
103  std::string full_name = name() + ":" + data_name;
104  ControlData<T> * data_ptr = _sim->declareControlData<T>(full_name, this);
105  return data_ptr->set();
106 }
107 
108 template <typename T>
109 T &
110 THMControl::declareControlData(const std::string & data_name)
111 {
112  ControlData<T> * data_ptr = _sim->declareControlData<T>(data_name, this);
113  return data_ptr->set();
114 }
115 
116 template <typename T>
117 const T &
118 THMControl::getControlData(const std::string & param_name)
119 {
120  std::string data_name = getParam<std::string>(param_name);
121  return getControlDataByName<T>(data_name);
122 }
123 
124 template <typename T>
125 const T &
126 THMControl::getControlDataOld(const std::string & param_name)
127 {
128  std::string data_name = getParam<std::string>(param_name);
129  return getControlDataOldByName<T>(data_name);
130 }
131 
132 template <typename T>
133 const T &
134 THMControl::getControlDataByName(const std::string & data_name)
135 {
136  ControlData<T> * data_ptr = _sim->getControlData<T>(data_name);
137  if (data_ptr == nullptr)
138  mooseError("Trying to get control data '",
139  data_name,
140  "', but it does not exist in the system. Check your spelling.");
141 
142  // set up dependencies for this control object
143  auto it = std::find(_control_data_depends_on.begin(), _control_data_depends_on.end(), data_name);
144  if (it == _control_data_depends_on.end())
145  _control_data_depends_on.push_back(data_name);
146 
147  return data_ptr->get();
148 }
149 
150 template <typename T>
151 const T &
152 THMControl::getControlDataOldByName(const std::string & data_name)
153 {
154  ControlData<T> * data_ptr = _sim->getControlData<T>(data_name);
155  if (data_ptr == nullptr)
156  mooseError("Trying to get control data '",
157  data_name,
158  "', but it does not exist in the system. Check your spelling.");
159 
160  return data_ptr->getOld();
161 }
162 
163 template <typename T>
164 const T &
165 THMControl::getComponentControlDataOld(const std::string & data_name)
166 {
167  std::string full_name = name() + ":" + data_name;
168  return getControlDataOldByName<T>(full_name);
169 }
Specialization of FEProblem to run with component subsystem.
Definition: THMProblem.h:18
THMControl(const InputParameters &parameters)
Definition: THMControl.C:23
const T & getOld() const
Definition: ControlData.h:113
const T & get() const
Definition: ControlData.h:108
const T & getControlData(const std::string &param_name)
Get a reference to control data that are specified in the input parameter &#39;param_name&#39;.
Definition: THMControl.h:118
const std::vector< std::string > & getControlDataDependencies() const
Return the Controls that must run before this Control.
Definition: THMControl.h:26
T & declareControlData(const std::string &data_name)
Declare control data with name &#39;data_name&#39;.
Definition: THMControl.h:110
virtual const std::string & name() const
Concrete definition of a parameter value for a specified type.
Definition: ControlData.h:91
std::vector< std::string > _control_data_depends_on
A list of control data that are required to run before this control may run.
Definition: THMControl.h:93
static InputParameters validParams()
Definition: THMControl.C:13
const T & getControlDataOldByName(const std::string &data_name)
Get a reference to control data value from previous time step that is specified by &#39;data_name&#39; name...
Definition: THMControl.h:152
ControlData< T > * declareControlData(const std::string &name, THMControl *ctrl)
Declare control data of type T and name &#39;name&#39;, if it does not exist it will be created.
Definition: Simulation.h:311
THMProblem * _sim
Definition: THMControl.h:90
ControlData< T > * getControlData(const std::string &name)
Get control data of type T and name &#39;name&#39;, if it does not exist it will be created.
Definition: Simulation.h:290
const T & getControlDataOld(const std::string &param_name)
Get a reference to control data value from a previous time step that is specified in the input parame...
Definition: THMControl.h:126
void mooseError(Args &&... args) const
const InputParameters & parameters() const
T & declareComponentControlData(const std::string &data_name)
Declare control data with name &#39;component:data_name&#39;.
Definition: THMControl.h:101
const T & getControlDataByName(const std::string &data_name)
Get a reference to control data that are specified by &#39;data_name&#39; name.
Definition: THMControl.h:134
virtual void init()
Definition: THMControl.h:21
const T & getComponentControlDataOld(const std::string &data_name)
Get a reference to a component control data value from previous time step.
Definition: THMControl.h:165