Line data Source code
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"
20 : #include "VectorPostprocessorInterface.h"
21 : #include "PerfGraphInterface.h"
22 : #include "ReporterInterface.h"
23 :
24 : class FEProblemBase;
25 : class InputParameterWarehouse;
26 :
27 : /**
28 : * Base class for Control objects.
29 : *
30 : * These objects are create by the [Controls] block in the input file after
31 : * all other MooseObjects are created, so they have access to parameters
32 : * in all other MooseObjects.
33 : */
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,
42 : protected VectorPostprocessorInterface,
43 : protected ReporterInterface
44 : {
45 : public:
46 : /**
47 : * Class constructor
48 : * @param parameters The input parameters for this control object
49 : */
50 : static InputParameters validParams();
51 :
52 : Control(const InputParameters & parameters);
53 :
54 : /**
55 : * Class destructor
56 : */
57 1397 : virtual ~Control() {}
58 :
59 : /**
60 : * Execute the control. This must be overridden.
61 : */
62 : virtual void execute() = 0;
63 :
64 : /**
65 : * (DEPRECATED) Return the valid "execute_on" options for Control objects
66 : */
67 : static MultiMooseEnum getExecuteOptions();
68 :
69 : /**
70 : * Return the Controls that must run before this Control
71 : */
72 12265 : std::vector<std::string> & getDependencies() { return _depends_on; }
73 :
74 : protected:
75 : /// Reference to the FEProblemBase for this object
76 : FEProblemBase & _fe_problem;
77 :
78 : /// A list of controls that are required to run before this control may run
79 : std::vector<std::string> _depends_on;
80 :
81 : /**
82 : * @return True if a controllable parameter exists with the name \p name
83 : */
84 : bool hasControllableParameterByName(const std::string & name) const;
85 :
86 : ///@{
87 : /**
88 : * Direct access to the ControllableParameter object.
89 : */
90 : ControllableParameter getControllableParameter(const std::string & param_name);
91 : ControllableParameter getControllableParameterByName(const std::string & param_name);
92 : ControllableParameter getControllableParameterByName(const std::string & tag,
93 : const std::string & object_name,
94 : const std::string & param_name);
95 : ControllableParameter getControllableParameterByName(const MooseObjectName & object_name,
96 : const std::string & param_name);
97 : ControllableParameter getControllableParameterByName(const MooseObjectParameterName & param_name);
98 : ///@}
99 :
100 : ///@{
101 : /**
102 : * Obtain the value of a controllable parameter given input file syntax or actual name.
103 : * @param name The name of the parameter to retrieve a value.
104 : * @param warn_when_values_diff When true, produce a warning if multiple controllable values share
105 : * the given name but have varying values.
106 : *
107 : * @return A copy of the first parameter that matches the given name.
108 : */
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>
132 : T getControllableValueByName(const MooseObjectParameterName & desired,
133 : bool warn_when_values_differ = true);
134 : ///@}
135 :
136 : ///@{
137 : /**
138 : * Set the value(s) of a controllable parameter of class given input file syntax or actual name.
139 : * @param name The name of the parameter to retrieve a value.
140 : * @param value The value to set all matching parameters to.
141 : * @param warn_when_values_diff When true, produce a warning if multiple controllable values share
142 : * the given name but have varying values.
143 : */
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);
168 : ///@}
169 :
170 : private:
171 : /// A reference to the InputParameterWarehouse which is used for access the parameter objects
172 : InputParameterWarehouse & _input_parameter_warehouse;
173 : };
174 :
175 : template <typename T>
176 : T
177 952 : Control::getControllableValue(const std::string & name, bool warn_when_values_differ)
178 : {
179 952 : return getControllableValueByName<T>(getParam<std::string>(name), warn_when_values_differ);
180 : }
181 :
182 : template <typename T>
183 : T
184 1073 : Control::getControllableValueByName(const std::string & name, bool warn_when_values_differ)
185 : {
186 1073 : MooseObjectParameterName desired(name);
187 1073 : ControllableParameter helper = getControllableParameterByName(desired);
188 2122 : return helper.get<T>(true, warn_when_values_differ)[0];
189 1061 : }
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);
198 : ControllableParameter helper = getControllableParameterByName(desired);
199 : return helper.get<T>(true, warn_when_values_differ)[0];
200 : }
201 :
202 : template <typename T>
203 : T
204 : Control::getControllableValueByName(const MooseObjectName & object_name,
205 : const std::string & param_name,
206 : bool warn_when_values_differ)
207 : {
208 : MooseObjectParameterName desired(object_name, param_name);
209 : ControllableParameter helper = getControllableParameterByName(desired);
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);
221 : ControllableParameter helper = getControllableParameterByName(desired);
222 : return helper.get<T>(true, warn_when_values_differ)[0];
223 : }
224 :
225 : template <typename T>
226 : T
227 : Control::getControllableValueByName(const MooseObjectParameterName & desired,
228 : bool warn_when_values_differ)
229 : {
230 : ControllableParameter helper = getControllableParameterByName(desired);
231 : return helper.get<T>(true, warn_when_values_differ)[0];
232 : }
233 :
234 : template <typename T>
235 : void
236 13 : Control::setControllableValueByName(const MooseObjectParameterName & desired, const T & value)
237 : {
238 13 : ControllableParameter helper = getControllableParameterByName(desired);
239 13 : helper.set<T>(value);
240 13 : }
241 :
242 : template <typename T>
243 : void
244 1744 : Control::setControllableValue(const std::string & name, const T & value)
245 : {
246 1744 : setControllableValueByName<T>(getParam<std::string>(name), value);
247 1744 : }
248 :
249 : template <typename T>
250 : void
251 2105 : Control::setControllableValueByName(const std::string & name, const T & value)
252 : {
253 2105 : MooseObjectParameterName desired(name);
254 2105 : ControllableParameter helper = getControllableParameterByName(desired);
255 2105 : helper.set<T>(value);
256 2105 : }
257 :
258 : template <typename T>
259 : void
260 8033 : Control::setControllableValueByName(const std::string & object_name,
261 : const std::string & param_name,
262 : const T & value)
263 : {
264 8033 : MooseObjectParameterName desired(MooseObjectName(object_name), param_name);
265 8033 : ControllableParameter helper = getControllableParameterByName(desired);
266 8033 : helper.set<T>(value);
267 8033 : }
268 :
269 : template <typename T>
270 : void
271 : Control::setControllableValueByName(const MooseObjectName & object_name,
272 : const std::string & param_name,
273 : const T & value)
274 : {
275 : MooseObjectParameterName desired(object_name, param_name);
276 : ControllableParameter helper = getControllableParameterByName(desired);
277 : helper.set<T>(value);
278 : }
279 :
280 : template <typename T>
281 : void
282 4 : Control::setControllableValueByName(const std::string & tag,
283 : const std::string & object_name,
284 : const std::string & param_name,
285 : const T & value)
286 : {
287 4 : MooseObjectParameterName desired(tag, object_name, param_name);
288 4 : ControllableParameter helper = getControllableParameterByName(desired);
289 0 : helper.set<T>(value);
290 0 : }
|