www.mooseframework.org
Control.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 
22 class FEProblemBase;
24 
32 class Control : public MooseObject,
33  public TransientInterface,
34  public SetupInterface,
35  public FunctionInterface,
36  public UserObjectInterface,
37  public Restartable,
38  protected PostprocessorInterface,
40 {
41 public:
47 
49 
53  virtual ~Control() {}
54 
58  virtual void execute() = 0;
59 
64 
68  std::vector<std::string> & getDependencies() { return _depends_on; }
69 
70 protected:
73 
75  std::vector<std::string> _depends_on;
76 
78 
81  ControllableParameter getControllableParameter(const std::string & param_name);
82  ControllableParameter getControllableParameterByName(const std::string & param_name);
84  const std::string & object_name,
85  const std::string & param_name);
87  const std::string & param_name);
90 
92 
100  template <typename T>
101  T getControllableValue(const std::string & name, bool warn_when_values_differ = true);
102 
103  template <typename T>
104  T getControllableValueByName(const std::string & name, bool warn_when_values_differ = true);
105 
106  template <typename T>
107  T getControllableValueByName(const std::string & object_name,
108  const std::string & param_name,
109  bool warn_when_values_differ = true);
110 
111  template <typename T>
112  T getControllableValueByName(const MooseObjectName & object_name,
113  const std::string & param_name,
114  bool warn_when_values_differ = true);
115 
116  template <typename T>
117  T getControllableValueByName(const std::string & tag,
118  const std::string & object_name,
119  const std::string & param_name,
120  bool warn_when_values_differ = true);
121 
122  template <typename T>
124  bool warn_when_values_differ = true);
126 
128 
135  template <typename T>
136  void setControllableValue(const std::string & name, const T & value);
137 
138  template <typename T>
139  void setControllableValueByName(const std::string & name, const T & value);
140 
141  template <typename T>
142  void setControllableValueByName(const std::string & object_name,
143  const std::string & param_name,
144  const T & value);
145 
146  template <typename T>
147  void setControllableValueByName(const MooseObjectName & object_name,
148  const std::string & param_name,
149  const T & value);
150 
151  template <typename T>
152  void setControllableValueByName(const std::string & tag,
153  const std::string & object_name,
154  const std::string & param_name,
155  const T & value);
156 
157  template <typename T>
158  void setControllableValueByName(const MooseObjectParameterName & name, const T & value);
160 
161 private:
164 };
165 
166 template <typename T>
167 T
168 Control::getControllableValue(const std::string & name, bool warn_when_values_differ)
169 {
170  return getControllableValueByName<T>(getParam<std::string>(name), warn_when_values_differ);
171 }
172 
173 template <typename T>
174 T
175 Control::getControllableValueByName(const std::string & name, bool warn_when_values_differ)
176 {
179  return helper.get<T>(true, warn_when_values_differ)[0];
180 }
181 
182 template <typename T>
183 T
184 Control::getControllableValueByName(const std::string & object_name,
185  const std::string & param_name,
186  bool warn_when_values_differ)
187 {
188  MooseObjectParameterName desired(MooseObjectName(object_name), param_name);
190  return helper.get<T>(true, warn_when_values_differ)[0];
191 }
192 
193 template <typename T>
194 T
196  const std::string & param_name,
197  bool warn_when_values_differ)
198 {
199  MooseObjectParameterName desired(object_name, param_name);
201  return helper.get<T>(true, warn_when_values_differ)[0];
202 }
203 
204 template <typename T>
205 T
206 Control::getControllableValueByName(const std::string & tag,
207  const std::string & object_name,
208  const std::string & param_name,
209  bool warn_when_values_differ)
210 {
211  MooseObjectParameterName desired(tag, object_name, param_name);
213  return helper.get<T>(true, warn_when_values_differ)[0];
214 }
215 
216 template <typename T>
217 T
219  bool warn_when_values_differ)
220 {
222  return helper.get<T>(true, warn_when_values_differ)[0];
223 }
224 
225 template <typename T>
226 void
228 {
230  helper.set<T>(value);
231 }
232 
233 template <typename T>
234 void
235 Control::setControllableValue(const std::string & name, const T & value)
236 {
237  setControllableValueByName<T>(getParam<std::string>(name), value);
238 }
239 
240 template <typename T>
241 void
242 Control::setControllableValueByName(const std::string & name, const T & value)
243 {
246  helper.set<T>(value);
247 }
248 
249 template <typename T>
250 void
251 Control::setControllableValueByName(const std::string & object_name,
252  const std::string & param_name,
253  const T & value)
254 {
255  MooseObjectParameterName desired(MooseObjectName(object_name), param_name);
257  helper.set<T>(value);
258 }
259 
260 template <typename T>
261 void
263  const std::string & param_name,
264  const T & value)
265 {
266  MooseObjectParameterName desired(object_name, param_name);
268  helper.set<T>(value);
269 }
270 
271 template <typename T>
272 void
273 Control::setControllableValueByName(const std::string & tag,
274  const std::string & object_name,
275  const std::string & param_name,
276  const T & value)
277 {
278  MooseObjectParameterName desired(tag, object_name, param_name);
280  helper.set<T>(value);
281 }
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:235
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:15
std::vector< std::string > _depends_on
A list of controls that are required to run before this control may run.
Definition: Control.h:75
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:163
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:56
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:175
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:33
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this object.
Definition: Control.h:72
Interface for objects that need to use UserObjects.
static MultiMooseEnum getExecuteOptions()
(DEPRECATED) Return the valid "execute_on" options for Control objects
Definition: Control.C:52
void setControllableValueByName(const std::string &name, const T &value)
Definition: Control.h:242
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:32
Control(const InputParameters &parameters)
Definition: Control.C:36
virtual ~Control()
Class destructor.
Definition: Control.h:53
const InputParameters & parameters() const
Get the parameters of the object.
ControllableParameter getControllableParameterByName(const std::string &param_name)
Definition: Control.C:63
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 It sho...
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:168
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:68