https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Control.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// MOOSE includes
13#include "MooseObject.h"
15#include "TransientInterface.h"
16#include "SetupInterface.h"
17#include "FunctionInterface.h"
18#include "UserObjectInterface.h"
21#include "PerfGraphInterface.h"
22#include "ReporterInterface.h"
23
24class FEProblemBase;
26
34class Control : public MooseObject,
35 protected PerfGraphInterface,
36 public TransientInterface,
37 public SetupInterface,
38 public FunctionInterface,
40 public Restartable,
41 protected PostprocessorInterface,
43 protected ReporterInterface
44{
45public:
51
53
57 virtual ~Control() {}
58
62 virtual void execute() = 0;
63
68
72 std::vector<std::string> & getDependencies() { return _depends_on; }
73
74protected:
77
79 std::vector<std::string> _depends_on;
80
84 bool hasControllableParameterByName(const std::string & name) const;
85
87
90 ControllableParameter getControllableParameter(const std::string & param_name);
91 ControllableParameter getControllableParameterByName(const std::string & param_name);
93 const std::string & object_name,
94 const std::string & param_name);
96 const std::string & param_name);
99
101
109 template <typename T>
110 T getControllableValue(const std::string & name, bool warn_when_values_differ = true);
111
112 template <typename T>
113 T getControllableValueByName(const std::string & name, bool warn_when_values_differ = true);
114
115 template <typename T>
116 T getControllableValueByName(const std::string & object_name,
117 const std::string & param_name,
118 bool warn_when_values_differ = true);
119
120 template <typename T>
121 T getControllableValueByName(const MooseObjectName & object_name,
122 const std::string & param_name,
123 bool warn_when_values_differ = true);
124
125 template <typename T>
126 T getControllableValueByName(const std::string & tag,
127 const std::string & object_name,
128 const std::string & param_name,
129 bool warn_when_values_differ = true);
130
131 template <typename T>
133 bool warn_when_values_differ = true);
135
137
144 template <typename T>
145 void setControllableValue(const std::string & name, const T & value);
146
147 template <typename T>
148 void setControllableValueByName(const std::string & name, const T & value);
149
150 template <typename T>
151 void setControllableValueByName(const std::string & object_name,
152 const std::string & param_name,
153 const T & value);
154
155 template <typename T>
156 void setControllableValueByName(const MooseObjectName & object_name,
157 const std::string & param_name,
158 const T & value);
159
160 template <typename T>
161 void setControllableValueByName(const std::string & tag,
162 const std::string & object_name,
163 const std::string & param_name,
164 const T & value);
165
166 template <typename T>
167 void setControllableValueByName(const MooseObjectParameterName & name, const T & value);
169
170private:
173};
174
175template <typename T>
176T
177Control::getControllableValue(const std::string & name, bool warn_when_values_differ)
178{
179 return getControllableValueByName<T>(getParam<std::string>(name), warn_when_values_differ);
180}
181
182template <typename T>
183T
184Control::getControllableValueByName(const std::string & name, bool warn_when_values_differ)
185{
188 return helper.get<T>(true, warn_when_values_differ)[0];
189}
190
191template <typename T>
192T
193Control::getControllableValueByName(const std::string & object_name,
194 const std::string & param_name,
195 bool warn_when_values_differ)
196{
197 MooseObjectParameterName desired(MooseObjectName(object_name), param_name);
199 return helper.get<T>(true, warn_when_values_differ)[0];
200}
201
202template <typename T>
203T
205 const std::string & param_name,
206 bool warn_when_values_differ)
207{
208 MooseObjectParameterName desired(object_name, param_name);
210 return helper.get<T>(true, warn_when_values_differ)[0];
211}
212
213template <typename T>
214T
216 const std::string & object_name,
217 const std::string & param_name,
218 bool warn_when_values_differ)
219{
220 MooseObjectParameterName desired(tag, object_name, param_name);
222 return helper.get<T>(true, warn_when_values_differ)[0];
223}
224
225template <typename T>
226T
228 bool warn_when_values_differ)
229{
231 return helper.get<T>(true, warn_when_values_differ)[0];
232}
233
234template <typename T>
235void
237{
239 helper.set<T>(value);
240}
241
242template <typename T>
243void
244Control::setControllableValue(const std::string & name, const T & value)
245{
246 setControllableValueByName<T>(getParam<std::string>(name), value);
247}
248
249template <typename T>
250void
251Control::setControllableValueByName(const std::string & name, const T & value)
252{
255 helper.set<T>(value);
256}
257
258template <typename T>
259void
260Control::setControllableValueByName(const std::string & object_name,
261 const std::string & param_name,
262 const T & value)
263{
264 MooseObjectParameterName desired(MooseObjectName(object_name), param_name);
266 helper.set<T>(value);
267}
268
269template <typename T>
270void
272 const std::string & param_name,
273 const T & value)
274{
275 MooseObjectParameterName desired(object_name, param_name);
277 helper.set<T>(value);
278}
279
280template <typename T>
281void
283 const std::string & object_name,
284 const std::string & param_name,
285 const T & value)
286{
287 MooseObjectParameterName desired(tag, object_name, param_name);
289 helper.set<T>(value);
290}
Base class for Control objects.
Definition Control.h:44
static InputParameters validParams()
Class constructor.
Definition Control.C:16
static MultiMooseEnum getExecuteOptions()
(DEPRECATED) Return the valid "execute_on" options for Control objects
Definition Control.C:59
virtual void execute()=0
Execute the control.
T getControllableValue(const std::string &name, bool warn_when_values_differ=true)
Obtain the value of a controllable parameter given input file syntax or actual name.
Definition Control.h:177
ControllableParameter getControllableParameterByName(const std::string &param_name)
Definition Control.C:77
virtual ~Control()
Class destructor.
Definition Control.h:57
bool hasControllableParameterByName(const std::string &name) const
Definition Control.C:70
void setControllableValueByName(const std::string &name, const T &value)
Definition Control.h:251
std::vector< std::string > & getDependencies()
Return the Controls that must run before this Control.
Definition Control.h:72
InputParameterWarehouse & _input_parameter_warehouse
A reference to the InputParameterWarehouse which is used for access the parameter objects.
Definition Control.h:172
void setControllableValue(const std::string &name, const T &value)
Set the value(s) of a controllable parameter of class given input file syntax or actual name.
Definition Control.h:244
T getControllableValueByName(const std::string &name, bool warn_when_values_differ=true)
Definition Control.h:184
std::vector< std::string > _depends_on
A list of controls that are required to run before this control may run.
Definition Control.h:79
ControllableParameter getControllableParameter(const std::string &param_name)
Direct access to the ControllableParameter object.
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this object.
Definition Control.h:76
The ControllableParameter class is simply a set of ControllableItem objects.
void set(const T &value, bool type_check=true)
Set the value(s) of the controlled parameters stored in this class.
std::vector< T > get(bool type_check=true, bool warn_when_values_difffer=false) const
Return a copy of the values of the given type.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Interface for objects that need to use functions.
Storage container for all InputParamter objects.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
A class for storing the names of MooseObject by tag and object name.
A class for storing an input parameter name.
Every object that can be built by the factory should be derived from this class.
Definition MooseObject.h:31
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type.
Interface for objects interacting with the PerfGraph.
Interface class for classes which interact with Postprocessors.
Interface to allow object to consume Reporter values.
A class for creating restricted objects.
Definition Restartable.h:29
Interface for objects that needs transient capabilities.
Interface for objects that need to use UserObjects.