https://mooseframework.inl.gov
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"
14 #include "ControllableParameter.h"
15 #include "TransientInterface.h"
16 #include "SetupInterface.h"
17 #include "FunctionInterface.h"
18 #include "UserObjectInterface.h"
19 #include "PostprocessorInterface.h"
21 #include "PerfGraphInterface.h"
22 
23 class FEProblemBase;
25 
33 class Control : public MooseObject,
34  protected PerfGraphInterface,
35  public TransientInterface,
36  public SetupInterface,
37  public FunctionInterface,
38  public UserObjectInterface,
39  public Restartable,
40  protected PostprocessorInterface,
42 {
43 public:
49 
51 
55  virtual ~Control() {}
56 
60  virtual void execute() = 0;
61 
66 
70  std::vector<std::string> & getDependencies() { return _depends_on; }
71 
72 protected:
75 
77  std::vector<std::string> _depends_on;
78 
82  bool hasControllableParameterByName(const std::string & name) const;
83 
85 
88  ControllableParameter getControllableParameter(const std::string & param_name);
89  ControllableParameter getControllableParameterByName(const std::string & param_name);
91  const std::string & object_name,
92  const std::string & param_name);
94  const std::string & param_name);
97 
99 
107  template <typename T>
108  T getControllableValue(const std::string & name, bool warn_when_values_differ = true);
109 
110  template <typename T>
111  T getControllableValueByName(const std::string & name, bool warn_when_values_differ = true);
112 
113  template <typename T>
114  T getControllableValueByName(const std::string & object_name,
115  const std::string & param_name,
116  bool warn_when_values_differ = true);
117 
118  template <typename T>
119  T getControllableValueByName(const MooseObjectName & object_name,
120  const std::string & param_name,
121  bool warn_when_values_differ = true);
122 
123  template <typename T>
124  T getControllableValueByName(const std::string & tag,
125  const std::string & object_name,
126  const std::string & param_name,
127  bool warn_when_values_differ = true);
128 
129  template <typename T>
131  bool warn_when_values_differ = true);
133 
135 
142  template <typename T>
143  void setControllableValue(const std::string & name, const T & value);
144 
145  template <typename T>
146  void setControllableValueByName(const std::string & name, const T & value);
147 
148  template <typename T>
149  void setControllableValueByName(const std::string & object_name,
150  const std::string & param_name,
151  const T & value);
152 
153  template <typename T>
154  void setControllableValueByName(const MooseObjectName & object_name,
155  const std::string & param_name,
156  const T & value);
157 
158  template <typename T>
159  void setControllableValueByName(const std::string & tag,
160  const std::string & object_name,
161  const std::string & param_name,
162  const T & value);
163 
164  template <typename T>
165  void setControllableValueByName(const MooseObjectParameterName & name, const T & value);
167 
168 private:
171 };
172 
173 template <typename T>
174 T
175 Control::getControllableValue(const std::string & name, bool warn_when_values_differ)
176 {
177  return getControllableValueByName<T>(getParam<std::string>(name), warn_when_values_differ);
178 }
179 
180 template <typename T>
181 T
182 Control::getControllableValueByName(const std::string & name, bool warn_when_values_differ)
183 {
186  return helper.get<T>(true, warn_when_values_differ)[0];
187 }
188 
189 template <typename T>
190 T
191 Control::getControllableValueByName(const std::string & object_name,
192  const std::string & param_name,
193  bool warn_when_values_differ)
194 {
195  MooseObjectParameterName desired(MooseObjectName(object_name), param_name);
197  return helper.get<T>(true, warn_when_values_differ)[0];
198 }
199 
200 template <typename T>
201 T
203  const std::string & param_name,
204  bool warn_when_values_differ)
205 {
206  MooseObjectParameterName desired(object_name, param_name);
208  return helper.get<T>(true, warn_when_values_differ)[0];
209 }
210 
211 template <typename T>
212 T
213 Control::getControllableValueByName(const std::string & tag,
214  const std::string & object_name,
215  const std::string & param_name,
216  bool warn_when_values_differ)
217 {
218  MooseObjectParameterName desired(tag, object_name, param_name);
220  return helper.get<T>(true, warn_when_values_differ)[0];
221 }
222 
223 template <typename T>
224 T
226  bool warn_when_values_differ)
227 {
229  return helper.get<T>(true, warn_when_values_differ)[0];
230 }
231 
232 template <typename T>
233 void
235 {
237  helper.set<T>(value);
238 }
239 
240 template <typename T>
241 void
242 Control::setControllableValue(const std::string & name, const T & value)
243 {
244  setControllableValueByName<T>(getParam<std::string>(name), value);
245 }
246 
247 template <typename T>
248 void
249 Control::setControllableValueByName(const std::string & name, const T & value)
250 {
253  helper.set<T>(value);
254 }
255 
256 template <typename T>
257 void
258 Control::setControllableValueByName(const std::string & object_name,
259  const std::string & param_name,
260  const T & value)
261 {
262  MooseObjectParameterName desired(MooseObjectName(object_name), param_name);
264  helper.set<T>(value);
265 }
266 
267 template <typename T>
268 void
270  const std::string & param_name,
271  const T & value)
272 {
273  MooseObjectParameterName desired(object_name, param_name);
275  helper.set<T>(value);
276 }
277 
278 template <typename T>
279 void
280 Control::setControllableValueByName(const std::string & tag,
281  const std::string & object_name,
282  const std::string & param_name,
283  const T & value)
284 {
285  MooseObjectParameterName desired(tag, object_name, param_name);
287  helper.set<T>(value);
288 }
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:242
void set(const T &value, bool type_check=true)
Set the value(s) of the controlled parameters stored in this class.
A class for creating restricted objects.
Definition: Restartable.h:28
Storage container for all InputParamter objects.
static InputParameters validParams()
Class constructor.
Definition: Control.C:16
std::vector< std::string > _depends_on
A list of controls that are required to run before this control may run.
Definition: Control.h:77
The ControllableParameter class is simply a set of ControllableItem objects.
InputParameterWarehouse & _input_parameter_warehouse
A reference to the InputParameterWarehouse which is used for access the parameter objects...
Definition: Control.h:170
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:57
ControllableParameter getControllableParameter(const std::string &param_name)
Direct access to the ControllableParameter object.
Interface for objects that needs transient capabilities.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
T getControllableValueByName(const std::string &name, bool warn_when_values_differ=true)
Definition: Control.h:182
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:28
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this object.
Definition: Control.h:74
bool hasControllableParameterByName(const std::string &name) const
Definition: Control.C:69
Interface for objects that need to use UserObjects.
Interface for objects interacting with the PerfGraph.
static MultiMooseEnum getExecuteOptions()
(DEPRECATED) Return the valid "execute_on" options for Control objects
Definition: Control.C:58
void setControllableValueByName(const std::string &name, const T &value)
Definition: Control.h:249
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.
Base class for Control objects.
Definition: Control.h:33
Control(const InputParameters &parameters)
Definition: Control.C:37
virtual ~Control()
Class destructor.
Definition: Control.h:55
const InputParameters & parameters() const
Get the parameters of the object.
ControllableParameter getControllableParameterByName(const std::string &param_name)
Definition: Control.C:76
A class for storing an input parameter name.
virtual void execute()=0
Execute the control.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type...
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:175
A class for storing the names of MooseObject by tag and object name.
Interface for objects that need to use functions.
Interface class for classes which interact with Postprocessors.
std::vector< std::string > & getDependencies()
Return the Controls that must run before this Control.
Definition: Control.h:70