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 :
23 : class FEProblemBase;
24 : class InputParameterWarehouse;
25 :
26 : /**
27 : * Base class for Control objects.
28 : *
29 : * These objects are create by the [Controls] block in the input file after
30 : * all other MooseObjects are created, so they have access to parameters
31 : * in all other MooseObjects.
32 : */
33 : class Control : public MooseObject,
34 : protected PerfGraphInterface,
35 : public TransientInterface,
36 : public SetupInterface,
37 : public FunctionInterface,
38 : public UserObjectInterface,
39 : public Restartable,
40 : protected PostprocessorInterface,
41 : protected VectorPostprocessorInterface
42 : {
43 : public:
44 : /**
45 : * Class constructor
46 : * @param parameters The input parameters for this control object
47 : */
48 : static InputParameters validParams();
49 :
50 : Control(const InputParameters & parameters);
51 :
52 : /**
53 : * Class destructor
54 : */
55 1253 : virtual ~Control() {}
56 :
57 : /**
58 : * Execute the control. This must be overridden.
59 : */
60 : virtual void execute() = 0;
61 :
62 : /**
63 : * (DEPRECATED) Return the valid "execute_on" options for Control objects
64 : */
65 : static MultiMooseEnum getExecuteOptions();
66 :
67 : /**
68 : * Return the Controls that must run before this Control
69 : */
70 11107 : std::vector<std::string> & getDependencies() { return _depends_on; }
71 :
72 : protected:
73 : /// Reference to the FEProblemBase for this object
74 : FEProblemBase & _fe_problem;
75 :
76 : /// A list of controls that are required to run before this control may run
77 : std::vector<std::string> _depends_on;
78 :
79 : /**
80 : * @return True if a controllable parameter exists with the name \p name
81 : */
82 : bool hasControllableParameterByName(const std::string & name) const;
83 :
84 : ///@{
85 : /**
86 : * Direct access to the ControllableParameter object.
87 : */
88 : ControllableParameter getControllableParameter(const std::string & param_name);
89 : ControllableParameter getControllableParameterByName(const std::string & param_name);
90 : ControllableParameter getControllableParameterByName(const std::string & tag,
91 : const std::string & object_name,
92 : const std::string & param_name);
93 : ControllableParameter getControllableParameterByName(const MooseObjectName & object_name,
94 : const std::string & param_name);
95 : ControllableParameter getControllableParameterByName(const MooseObjectParameterName & param_name);
96 : ///@}
97 :
98 : ///@{
99 : /**
100 : * Obtain the value of a controllable parameter given input file syntax or actual name.
101 : * @param name The name of the parameter to retrieve a value.
102 : * @param warn_when_values_diff When true, produce a warning if multiple controllable values share
103 : * the given name but have varying values.
104 : *
105 : * @return A copy of the first parameter that matches the given name.
106 : */
107 : template <typename T>
108 : T getControllableValue(const std::string & name, bool warn_when_values_differ = true);
109 :
110 : template <typename T>
111 : T getControllableValueByName(const std::string & name, bool warn_when_values_differ = true);
112 :
113 : template <typename T>
114 : T getControllableValueByName(const std::string & object_name,
115 : const std::string & param_name,
116 : bool warn_when_values_differ = true);
117 :
118 : template <typename T>
119 : T getControllableValueByName(const MooseObjectName & object_name,
120 : const std::string & param_name,
121 : bool warn_when_values_differ = true);
122 :
123 : template <typename T>
124 : T getControllableValueByName(const std::string & tag,
125 : const std::string & object_name,
126 : const std::string & param_name,
127 : bool warn_when_values_differ = true);
128 :
129 : template <typename T>
130 : T getControllableValueByName(const MooseObjectParameterName & desired,
131 : bool warn_when_values_differ = true);
132 : ///@}
133 :
134 : ///@{
135 : /**
136 : * Set the value(s) of a controllable parameter of class given input file syntax or actual name.
137 : * @param name The name of the parameter to retrieve a value.
138 : * @param value The value to set all matching parameters to.
139 : * @param warn_when_values_diff When true, produce a warning if multiple controllable values share
140 : * the given name but have varying values.
141 : */
142 : template <typename T>
143 : void setControllableValue(const std::string & name, const T & value);
144 :
145 : template <typename T>
146 : void setControllableValueByName(const std::string & name, const T & value);
147 :
148 : template <typename T>
149 : void setControllableValueByName(const std::string & object_name,
150 : const std::string & param_name,
151 : const T & value);
152 :
153 : template <typename T>
154 : void setControllableValueByName(const MooseObjectName & object_name,
155 : const std::string & param_name,
156 : const T & value);
157 :
158 : template <typename T>
159 : void setControllableValueByName(const std::string & tag,
160 : const std::string & object_name,
161 : const std::string & param_name,
162 : const T & value);
163 :
164 : template <typename T>
165 : void setControllableValueByName(const MooseObjectParameterName & name, const T & value);
166 : ///@}
167 :
168 : private:
169 : /// A reference to the InputParameterWarehouse which is used for access the parameter objects
170 : InputParameterWarehouse & _input_parameter_warehouse;
171 : };
172 :
173 : template <typename T>
174 : T
175 871 : Control::getControllableValue(const std::string & name, bool warn_when_values_differ)
176 : {
177 871 : return getControllableValueByName<T>(getParam<std::string>(name), warn_when_values_differ);
178 : }
179 :
180 : template <typename T>
181 : T
182 981 : Control::getControllableValueByName(const std::string & name, bool warn_when_values_differ)
183 : {
184 981 : MooseObjectParameterName desired(name);
185 981 : ControllableParameter helper = getControllableParameterByName(desired);
186 2048 : return helper.get<T>(true, warn_when_values_differ)[0];
187 969 : }
188 :
189 : template <typename T>
190 : T
191 : Control::getControllableValueByName(const std::string & object_name,
192 : const std::string & param_name,
193 : bool warn_when_values_differ)
194 : {
195 : MooseObjectParameterName desired(MooseObjectName(object_name), param_name);
196 : ControllableParameter helper = getControllableParameterByName(desired);
197 : return helper.get<T>(true, warn_when_values_differ)[0];
198 : }
199 :
200 : template <typename T>
201 : T
202 : Control::getControllableValueByName(const MooseObjectName & object_name,
203 : const std::string & param_name,
204 : bool warn_when_values_differ)
205 : {
206 : MooseObjectParameterName desired(object_name, param_name);
207 : ControllableParameter helper = getControllableParameterByName(desired);
208 : return helper.get<T>(true, warn_when_values_differ)[0];
209 : }
210 :
211 : template <typename T>
212 : T
213 : Control::getControllableValueByName(const std::string & tag,
214 : const std::string & object_name,
215 : const std::string & param_name,
216 : bool warn_when_values_differ)
217 : {
218 : MooseObjectParameterName desired(tag, object_name, param_name);
219 : ControllableParameter helper = getControllableParameterByName(desired);
220 : return helper.get<T>(true, warn_when_values_differ)[0];
221 : }
222 :
223 : template <typename T>
224 : T
225 : Control::getControllableValueByName(const MooseObjectParameterName & desired,
226 : bool warn_when_values_differ)
227 : {
228 : ControllableParameter helper = getControllableParameterByName(desired);
229 : return helper.get<T>(true, warn_when_values_differ)[0];
230 : }
231 :
232 : template <typename T>
233 : void
234 12 : Control::setControllableValueByName(const MooseObjectParameterName & desired, const T & value)
235 : {
236 12 : ControllableParameter helper = getControllableParameterByName(desired);
237 12 : helper.set<T>(value);
238 12 : }
239 :
240 : template <typename T>
241 : void
242 1464 : Control::setControllableValue(const std::string & name, const T & value)
243 : {
244 1464 : setControllableValueByName<T>(getParam<std::string>(name), value);
245 1464 : }
246 :
247 : template <typename T>
248 : void
249 1792 : Control::setControllableValueByName(const std::string & name, const T & value)
250 : {
251 1792 : MooseObjectParameterName desired(name);
252 1792 : ControllableParameter helper = getControllableParameterByName(desired);
253 1792 : helper.set<T>(value);
254 1792 : }
255 :
256 : template <typename T>
257 : void
258 7427 : Control::setControllableValueByName(const std::string & object_name,
259 : const std::string & param_name,
260 : const T & value)
261 : {
262 7427 : MooseObjectParameterName desired(MooseObjectName(object_name), param_name);
263 7427 : ControllableParameter helper = getControllableParameterByName(desired);
264 7427 : helper.set<T>(value);
265 7427 : }
266 :
267 : template <typename T>
268 : void
269 : Control::setControllableValueByName(const MooseObjectName & object_name,
270 : const std::string & param_name,
271 : const T & value)
272 : {
273 : MooseObjectParameterName desired(object_name, param_name);
274 : ControllableParameter helper = getControllableParameterByName(desired);
275 : helper.set<T>(value);
276 : }
277 :
278 : template <typename T>
279 : void
280 4 : Control::setControllableValueByName(const std::string & tag,
281 : const std::string & object_name,
282 : const std::string & param_name,
283 : const T & value)
284 : {
285 4 : MooseObjectParameterName desired(tag, object_name, param_name);
286 4 : ControllableParameter helper = getControllableParameterByName(desired);
287 0 : helper.set<T>(value);
288 0 : }
|