www.mooseframework.org
Control.h
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #ifndef CONTROL_H
16 #define CONTROL_H
17 
18 // MOOSE includes
19 #include "MooseObject.h"
20 #include "ControllableParameter.h"
22 #include "TransientInterface.h"
23 #include "SetupInterface.h"
24 #include "FunctionInterface.h"
25 #include "UserObjectInterface.h"
26 #include "PostprocessorInterface.h"
28 
29 // Forward declarations
30 class Control;
31 class FEProblemBase;
32 
33 template <>
35 
43 class Control : public MooseObject,
44  public TransientInterface,
45  public SetupInterface,
46  public FunctionInterface,
47  public UserObjectInterface,
48  protected PostprocessorInterface,
50 {
51 public:
57 
61  virtual ~Control() {}
62 
66  virtual void execute() = 0;
67 
72 
76  std::vector<std::string> & getDependencies() { return _depends_on; }
77 
78 protected:
81 
83  std::vector<std::string> _depends_on;
84 
86 
94  template <typename T>
95  const T & getControllableValue(const std::string & name, bool warn_when_values_differ = true);
96 
97  template <typename T>
98  const T & getControllableValueByName(const std::string & name,
99  bool warn_when_values_differ = true);
100 
101  template <typename T>
102  const T & getControllableValueByName(const std::string & object_name,
103  const std::string & param_name,
104  bool warn_when_values_differ = true);
105 
106  template <typename T>
107  const T & getControllableValueByName(const MooseObjectName & object_name,
108  const std::string & param_name,
109  bool warn_when_values_differ = true);
110 
111  template <typename T>
112  const T & getControllableValueByName(const std::string & tag,
113  const std::string & object_name,
114  const std::string & param_name,
115  bool warn_when_values_differ = true);
116 
117  template <typename T>
118  const T & getControllableValueByName(const MooseObjectParameterName & desired,
119  bool warn_when_values_differ = true);
121 
123 
130  template <typename T>
131  void setControllableValue(const std::string & name,
132  const T & value,
133  bool warn_when_values_differ = false);
134 
135  template <typename T>
136  void setControllableValueByName(const std::string & name,
137  const T & value,
138  bool warn_when_values_differ = false);
139 
140  template <typename T>
141  void setControllableValueByName(const std::string & object_name,
142  const std::string & param_name,
143  const T & value,
144  bool warn_when_values_differ = false);
145 
146  template <typename T>
147  void setControllableValueByName(const MooseObjectName & object_name,
148  const std::string & param_name,
149  const T & value,
150  bool warn_when_values_differ = false);
151 
152  template <typename T>
153  void setControllableValueByName(const std::string & tag,
154  const std::string & object_name,
155  const std::string & param_name,
156  const T & value,
157  bool warn_when_values_differ = false);
158 
159  template <typename T>
161  const T & value,
162  bool warn_when_values_differ = false);
164 
165 private:
168 
170  template <typename T>
172  bool warn_when_values_differ,
173  bool mark_as_set = false);
174 };
175 
176 template <typename T>
177 const T &
178 Control::getControllableValue(const std::string & name, bool warn_when_values_differ)
179 {
180  return getControllableValueByName<T>(getParam<std::string>(name), warn_when_values_differ);
181 }
182 
183 template <typename T>
184 const T &
185 Control::getControllableValueByName(const std::string & name, bool warn_when_values_differ)
186 {
187  MooseObjectParameterName desired(name);
188  ControllableParameter<T> helper =
189  getControllableParameterHelper<T>(desired, warn_when_values_differ);
190  return *(helper.get()[0]);
191 }
192 
193 template <typename T>
194 const T &
195 Control::getControllableValueByName(const std::string & object_name,
196  const std::string & param_name,
197  bool warn_when_values_differ)
198 {
199  MooseObjectParameterName desired(MooseObjectName(object_name), param_name);
200  ControllableParameter<T> helper =
201  getControllableParameterHelper<T>(desired, warn_when_values_differ);
202  return *(helper.get()[0]);
203 }
204 
205 template <typename T>
206 const T &
208  const std::string & param_name,
209  bool warn_when_values_differ)
210 {
211  MooseObjectParameterName desired(object_name, param_name);
212  ControllableParameter<T> helper =
213  getControllableParameterHelper<T>(desired, warn_when_values_differ);
214  return *(helper.get()[0]);
215 }
216 
217 template <typename T>
218 const T &
219 Control::getControllableValueByName(const std::string & tag,
220  const std::string & object_name,
221  const std::string & param_name,
222  bool warn_when_values_differ)
223 {
224  MooseObjectParameterName desired(tag, object_name, param_name);
225  ControllableParameter<T> helper =
226  getControllableParameterHelper<T>(desired, warn_when_values_differ);
227  return *(helper.get()[0]);
228 }
229 
230 template <typename T>
231 const T &
233  bool warn_when_values_differ)
234 {
235  ControllableParameter<T> helper =
236  getControllableParameterHelper<T>(desired, warn_when_values_differ);
237  return *(helper.get()[0]);
238 }
239 
240 template <typename T>
241 void
243  const T & value,
244  bool warn_when_values_differ)
245 {
246  ControllableParameter<T> helper =
247  getControllableParameterHelper<T>(desired, warn_when_values_differ, /*mark_as_set=*/true);
248  helper.set(value);
249 }
250 
251 template <typename T>
252 void
254  const T & value,
255  bool warn_when_values_differ)
256 {
257  setControllableValueByName<T>(getParam<std::string>(name), value, warn_when_values_differ);
258 }
259 
260 template <typename T>
261 void
263  const T & value,
264  bool warn_when_values_differ)
265 {
266  MooseObjectParameterName desired(name);
267  ControllableParameter<T> helper =
268  getControllableParameterHelper<T>(desired, warn_when_values_differ, /*mark_as_set=*/true);
269  helper.set(value);
270 }
271 
272 template <typename T>
273 void
274 Control::setControllableValueByName(const std::string & object_name,
275  const std::string & param_name,
276  const T & value,
277  bool warn_when_values_differ)
278 {
279  MooseObjectParameterName desired(MooseObjectName(object_name), param_name);
280  ControllableParameter<T> helper =
281  getControllableParameterHelper<T>(desired, warn_when_values_differ, /*mark_as_set=*/true);
282  helper.set(value);
283 }
284 
285 template <typename T>
286 void
288  const std::string & param_name,
289  const T & value,
290  bool warn_when_values_differ)
291 {
292  MooseObjectParameterName desired(object_name, param_name);
293  ControllableParameter<T> helper =
294  getControllableParameterHelper<T>(desired, warn_when_values_differ, /*mark_as_set=*/true);
295  helper.set(value);
296 }
297 
298 template <typename T>
299 void
300 Control::setControllableValueByName(const std::string & tag,
301  const std::string & object_name,
302  const std::string & param_name,
303  const T & value,
304  bool warn_when_values_differ)
305 {
306  MooseObjectParameterName desired(tag, object_name, param_name);
307  ControllableParameter<T> helper =
308  getControllableParameterHelper<T>(desired, warn_when_values_differ, /*mark_as_set=*/true);
309  helper.set(value);
310 }
311 
312 template <typename T>
315  bool warn_when_values_differ,
316  bool mark_as_set)
317 {
318 
319  // The ControllableParameter object to return
320  ControllableParameter<T> output =
321  _input_parameter_warehouse.getControllableParameter<T>(desired, mark_as_set);
322 
323  // Produce a warning, if the flag is true, when multiple parameters have differing values
324  if (warn_when_values_differ)
325  {
326  // Inspect the values for differing values
327  const std::vector<T *> & values = output.get();
328 
329  // The first parameter to test against
330  const T & value0 = *values[0];
331 
332  // Loop over all other parameter values
333  for (typename std::vector<T *>::const_iterator it = values.begin() + 1; it != values.end();
334  ++it)
335  {
336  if (value0 != **it)
337  {
338  std::ostringstream oss;
339  oss << "The controlled parameter with tag, '" << desired.tag() << "', and name, '"
340  << desired.name() << "', in " << name() << " was found,\n";
341  oss << "but the number of parameters have differing values.\n\n";
342  oss << output.dump();
343  mooseWarning(oss.str());
344  }
345  }
346  }
347 
348  return output;
349 }
350 
351 #endif // CONTROL_H
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:47
void mooseWarning(Args &&...args) const
Definition: MooseObject.h:89
Storage container for all InputParamter objects.
void setControllableValue(const std::string &name, const T &value, bool warn_when_values_differ=false)
Set the value(s) of a controllable parameter of class given input file syntax or actual name...
Definition: Control.h:253
std::string dump()
Return a string that lists the parameters stored by this object.
const std::vector< T * > & get() const
Retrieve a copy of the parameter values controlled by this class.
std::vector< std::string > _depends_on
A list of controls that are required to run before this control may run.
Definition: Control.h:83
const T & getControllableValueByName(const std::string &name, bool warn_when_values_differ=true)
Definition: Control.h:185
A class for accessing controllable InputParameters.
void setControllableValueByName(const std::string &name, const T &value, bool warn_when_values_differ=false)
Definition: Control.h:262
InputParameterWarehouse & _input_parameter_warehouse
A reference to the InputParameterWarehouse which is used for access the parameter objects...
Definition: Control.h:167
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.
Interface for objects that needs transient capabilities.
ControllableParameter< T > getControllableParameterHelper(const MooseObjectParameterName &desired, bool warn_when_values_differ, bool mark_as_set=false)
Helper method for retrieving controllable parameters.
Definition: Control.h:314
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:36
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this object.
Definition: Control.h:80
Interface for objects that need to use UserObjects.
static MultiMooseEnum getExecuteOptions()
Return the valid "execute_on" options for Control objects.
Definition: Control.C:51
const 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:178
Base class for Control objects.
Definition: Control.h:43
Control(const InputParameters &parameters)
Class constructor.
Definition: Control.C:36
InputParameters validParams< Control >()
Definition: Control.C:20
void set(const T &value)
Set the value(s) of the controlled parameters stored in this class.
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseObject.h:53
virtual ~Control()
Class destructor.
Definition: Control.h:61
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...
A class for storing the names of MooseObject by tag and object name.
Interface for objects that need to use functions.
ControllableParameter< T > getControllableParameter(const MooseObjectParameterName &desired, bool mark_as_controlled=false)
Returns a ControllableParameter object.
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:76