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 #include "ReporterInterface.h"
23 
24 class FEProblemBase;
26 
34 class Control : public MooseObject,
35  protected PerfGraphInterface,
36  public TransientInterface,
37  public SetupInterface,
38  public FunctionInterface,
39  public UserObjectInterface,
40  public Restartable,
41  protected PostprocessorInterface,
43  protected ReporterInterface
44 {
45 public:
51 
53 
57  virtual ~Control() {}
58 
62  virtual void execute() = 0;
63 
68 
72  std::vector<std::string> & getDependencies() { return _depends_on; }
73 
74 protected:
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 
170 private:
173 };
174 
175 template <typename T>
176 T
177 Control::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 
182 template <typename T>
183 T
184 Control::getControllableValueByName(const std::string & name, bool warn_when_values_differ)
185 {
188  return helper.get<T>(true, warn_when_values_differ)[0];
189 }
190 
191 template <typename T>
192 T
193 Control::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 
202 template <typename T>
203 T
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 
213 template <typename T>
214 T
215 Control::getControllableValueByName(const std::string & tag,
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 
225 template <typename T>
226 T
228  bool warn_when_values_differ)
229 {
231  return helper.get<T>(true, warn_when_values_differ)[0];
232 }
233 
234 template <typename T>
235 void
237 {
239  helper.set<T>(value);
240 }
241 
242 template <typename T>
243 void
244 Control::setControllableValue(const std::string & name, const T & value)
245 {
246  setControllableValueByName<T>(getParam<std::string>(name), value);
247 }
248 
249 template <typename T>
250 void
251 Control::setControllableValueByName(const std::string & name, const T & value)
252 {
255  helper.set<T>(value);
256 }
257 
258 template <typename T>
259 void
260 Control::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 
269 template <typename T>
270 void
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 
280 template <typename T>
281 void
282 Control::setControllableValueByName(const std::string & tag,
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 }
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
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:79
The ControllableParameter class is simply a set of ControllableItem objects.
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:127
InputParameterWarehouse & _input_parameter_warehouse
A reference to the InputParameterWarehouse which is used for access the parameter objects...
Definition: Control.h:172
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.
ControllableParameter getControllableParameter(const std::string &param_name)
Direct access to the ControllableParameter object.
Interface for objects that needs transient capabilities.
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:99
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:184
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:27
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this object.
Definition: Control.h:76
Interface to allow object to consume Reporter values.
bool hasControllableParameterByName(const std::string &name) const
Definition: Control.C:70
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:59
void setControllableValueByName(const std::string &name, const T &value)
Definition: Control.h:251
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:34
Control(const InputParameters &parameters)
Definition: Control.C:37
virtual ~Control()
Class destructor.
Definition: Control.h:57
ControllableParameter getControllableParameterByName(const std::string &param_name)
Definition: Control.C:77
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:177
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:72