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 // Forward declarations
23 class Control;
24 class FEProblemBase;
26 
27 template <>
29 
37 class Control : public MooseObject,
38  public TransientInterface,
39  public SetupInterface,
40  public FunctionInterface,
41  public UserObjectInterface,
42  public Restartable,
43  protected PostprocessorInterface,
45 {
46 public:
52 
56  virtual ~Control() {}
57 
61  virtual void execute() = 0;
62 
67 
71  std::vector<std::string> & getDependencies() { return _depends_on; }
72 
73 protected:
76 
78  std::vector<std::string> _depends_on;
79 
81 
84  ControllableParameter getControllableParameter(const std::string & param_name);
85  ControllableParameter getControllableParameterByName(const std::string & param_name);
87  const std::string & object_name,
88  const std::string & param_name);
90  const std::string & param_name);
93 
95 
103  template <typename T>
104  T getControllableValue(const std::string & name, bool warn_when_values_differ = true);
105 
106  template <typename T>
107  T getControllableValueByName(const std::string & name, bool warn_when_values_differ = true);
108 
109  template <typename T>
110  T getControllableValueByName(const std::string & object_name,
111  const std::string & param_name,
112  bool warn_when_values_differ = true);
113 
114  template <typename T>
115  T getControllableValueByName(const MooseObjectName & object_name,
116  const std::string & param_name,
117  bool warn_when_values_differ = true);
118 
119  template <typename T>
120  T getControllableValueByName(const std::string & tag,
121  const std::string & object_name,
122  const std::string & param_name,
123  bool warn_when_values_differ = true);
124 
125  template <typename T>
127  bool warn_when_values_differ = true);
129 
131 
138  template <typename T>
139  void setControllableValue(const std::string & name, const T & value);
140 
141  template <typename T>
142  void setControllableValueByName(const std::string & name, const T & value);
143 
144  template <typename T>
145  void setControllableValueByName(const std::string & object_name,
146  const std::string & param_name,
147  const T & value);
148 
149  template <typename T>
150  void setControllableValueByName(const MooseObjectName & object_name,
151  const std::string & param_name,
152  const T & value);
153 
154  template <typename T>
155  void setControllableValueByName(const std::string & tag,
156  const std::string & object_name,
157  const std::string & param_name,
158  const T & value);
159 
160  template <typename T>
161  void setControllableValueByName(const MooseObjectParameterName & name, const T & value);
163 
164 private:
167 
168 };
169 
170 template <typename T>
171 T
172 Control::getControllableValue(const std::string & name, bool warn_when_values_differ)
173 {
174  return getControllableValueByName<T>(getParam<std::string>(name), warn_when_values_differ);
175 }
176 
177 template <typename T>
178 T
179 Control::getControllableValueByName(const std::string & name, bool warn_when_values_differ)
180 {
183  return helper.get<T>(true, warn_when_values_differ)[0];
184 }
185 
186 template <typename T>
187 T
188 Control::getControllableValueByName(const std::string & object_name,
189  const std::string & param_name,
190  bool warn_when_values_differ)
191 {
192  MooseObjectParameterName desired(MooseObjectName(object_name), param_name);
194  return helper.get<T>(true, warn_when_values_differ)[0];
195 }
196 
197 template <typename T>
198 T
200  const std::string & param_name,
201  bool warn_when_values_differ)
202 {
203  MooseObjectParameterName desired(object_name, param_name);
205  return helper.get<T>(true, warn_when_values_differ)[0];
206 }
207 
208 template <typename T>
209 T
210 Control::getControllableValueByName(const std::string & tag,
211  const std::string & object_name,
212  const std::string & param_name,
213  bool warn_when_values_differ)
214 {
215  MooseObjectParameterName desired(tag, object_name, param_name);
217  return helper.get<T>(true, warn_when_values_differ)[0];
218 }
219 
220 template <typename T>
221 T
223  bool warn_when_values_differ)
224 {
226  return helper.get<T>(true, warn_when_values_differ)[0];
227 }
228 
229 template <typename T>
230 void
232 {
234  helper.set<T>(value);
235 }
236 
237 template <typename T>
238 void
239 Control::setControllableValue(const std::string & name, const T & value)
240 {
241  setControllableValueByName<T>(getParam<std::string>(name), value);
242 }
243 
244 template <typename T>
245 void
246 Control::setControllableValueByName(const std::string & name, const T & value)
247 {
250  helper.set<T>(value);
251 }
252 
253 template <typename T>
254 void
255 Control::setControllableValueByName(const std::string & object_name,
256  const std::string & param_name,
257  const T & value)
258 {
259  MooseObjectParameterName desired(MooseObjectName(object_name), param_name);
261  helper.set<T>(value);
262 }
263 
264 template <typename T>
265 void
267  const std::string & param_name,
268  const T & value)
269 {
270  MooseObjectParameterName desired(object_name, param_name);
272  helper.set<T>(value);
273 }
274 
275 template <typename T>
276 void
277 Control::setControllableValueByName(const std::string & tag,
278  const std::string & object_name,
279  const std::string & param_name,
280  const T & value)
281 {
282  MooseObjectParameterName desired(tag, object_name, param_name);
284  helper.set<T>(value);
285 }
286 
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:239
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:29
Storage container for all InputParamter objects.
std::vector< std::string > _depends_on
A list of controls that are required to run before this control may run.
Definition: Control.h:78
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:166
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.
T getControllableValueByName(const std::string &name, bool warn_when_values_differ=true)
Definition: Control.h:179
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:42
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseObject.h:65
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this object.
Definition: Control.h:75
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:246
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:37
Control(const InputParameters &parameters)
Class constructor.
Definition: Control.C:36
InputParameters validParams< Control >()
Definition: Control.C:16
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:59
virtual ~Control()
Class destructor.
Definition: Control.h:56
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:172
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:71