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 : #include "InputParameters.h"
11 :
12 : // MOOSE includes
13 : #include "MooseEnum.h"
14 : #include "MooseTypes.h"
15 : #include "MooseUtils.h"
16 : #include "MultiMooseEnum.h"
17 : #include "ExecFlagEnum.h"
18 : #include "MooseObject.h"
19 :
20 : #include "libmesh/utility.h"
21 : #include "libmesh/simple_range.h"
22 :
23 : #include "pcrecpp.h"
24 : #include "hit/parse.h"
25 :
26 : #include <cmath>
27 : #include <filesystem>
28 :
29 : InputParameters
30 156903589 : emptyInputParameters()
31 : {
32 156903589 : InputParameters params;
33 156903589 : return params;
34 : }
35 :
36 156903589 : InputParameters::InputParameters()
37 : : Parameters(),
38 156903589 : _collapse_nesting(false),
39 156903589 : _moose_object_syntax_visibility(true),
40 156903589 : _show_deprecated_message(true),
41 156903589 : _allow_copy(true),
42 156903589 : _hit_node(nullptr),
43 156903589 : _finalized(false)
44 : {
45 156903589 : }
46 :
47 9030786 : InputParameters::InputParameters(const InputParameters & rhs)
48 9030786 : : Parameters(), _show_deprecated_message(true), _allow_copy(true)
49 : {
50 9030786 : *this = rhs;
51 9030782 : }
52 :
53 0 : InputParameters::InputParameters(const Parameters & rhs)
54 0 : : _show_deprecated_message(true), _allow_copy(true)
55 : {
56 0 : _params.clear();
57 0 : Parameters::operator=(rhs);
58 0 : _collapse_nesting = false;
59 0 : _moose_object_syntax_visibility = true;
60 0 : }
61 :
62 : void
63 0 : InputParameters::clear()
64 : {
65 0 : Parameters::clear();
66 0 : _params.clear();
67 0 : _coupled_vars.clear();
68 0 : _new_to_deprecated_coupled_vars.clear();
69 0 : _collapse_nesting = false;
70 0 : _moose_object_syntax_visibility = true;
71 0 : _show_deprecated_message = true;
72 0 : _allow_copy = true;
73 0 : _block_fullpath = "";
74 0 : _block_location = "";
75 0 : _old_to_new_name_and_dep.clear();
76 0 : _new_to_old_names.clear();
77 0 : _hit_node = nullptr;
78 0 : _finalized = false;
79 0 : }
80 :
81 : void
82 36673941 : InputParameters::addClassDescription(const std::string & doc_string)
83 : {
84 36673941 : _class_description = doc_string;
85 36673941 : }
86 :
87 : void
88 1152893502 : InputParameters::set_attributes(const std::string & name_in, bool inserted_only)
89 : {
90 1152893502 : const auto name = checkForRename(name_in);
91 :
92 1152893502 : if (!inserted_only)
93 : {
94 810469480 : auto & metadata = _params[name];
95 : /**
96 : * "._set_by_add_param" and ".deprecated_params" are not populated until after
97 : * the default value has already been set in libMesh (first callback to this
98 : * method). Therefore if a variable is in/not in one of these sets, you can
99 : * be assured it was put there outside of the "addParam*()" calls.
100 : */
101 810469480 : metadata._set_by_add_param = false;
102 :
103 : // valid_params don't make sense for MooseEnums
104 810469480 : if (!have_parameter<MooseEnum>(name) && !have_parameter<MultiMooseEnum>(name))
105 773157492 : metadata._valid = true;
106 : }
107 1152893502 : }
108 :
109 : bool
110 2410404 : InputParameters::attemptPrintDeprecated(const std::string & name_in)
111 : {
112 2410404 : const auto name = checkForRename(name_in);
113 2410404 : if (_show_deprecated_message)
114 : {
115 : auto emit_deprecation_message =
116 1240 : [this](const auto & deprecated_name, const auto & deprecation_message)
117 : {
118 : // This is user-facing, no need for a backtrace
119 1240 : const auto current_show_trace = Moose::show_trace;
120 1240 : Moose::show_trace = false;
121 1240 : moose::internal::mooseDeprecatedStream(
122 : Moose::out, false, true, errorPrefix(deprecated_name), ":\n", deprecation_message, "\n");
123 1232 : Moose::show_trace = current_show_trace;
124 1232 : return true;
125 2410404 : };
126 :
127 2410404 : if (_params.count(name) && !libmesh_map_find(_params, name)._deprecation_message.empty())
128 939 : return emit_deprecation_message(name,
129 1878 : "The parameter '" + name + "' is deprecated.\n" +
130 1878 : libmesh_map_find(_params, name)._deprecation_message);
131 2409465 : else if (auto it = _old_to_new_name_and_dep.find(name_in);
132 2409465 : it != _old_to_new_name_and_dep.end() && !it->second.second.empty())
133 301 : return emit_deprecation_message(name_in, it->second.second);
134 : }
135 2409164 : return false;
136 2410396 : }
137 :
138 : std::string
139 1059179 : InputParameters::getClassDescription() const
140 : {
141 1059179 : return _class_description;
142 : }
143 :
144 : InputParameters &
145 10442890 : InputParameters::operator=(const InputParameters & rhs)
146 : {
147 : // An error to help minimize the segmentation faults that occure when MooseObjects do not have the
148 : // correct constructor
149 10442890 : if (!rhs._allow_copy)
150 : {
151 : const std::string & name =
152 4 : rhs.get<std::string>("_object_name"); // If _allow_parameter_copy is set then so is name
153 : // (see InputParameterWarehouse::addInputParameters)
154 4 : mooseError("Copying of the InputParameters object for the ",
155 : name,
156 : " object is not allowed.\n\nThe likely cause for this error ",
157 : "is having a constructor that does not use a const reference, all constructors\nfor "
158 : "MooseObject based classes should be as follows:\n\n",
159 : " MyObject::MyObject(const InputParameters & parameters);");
160 : }
161 :
162 10442886 : Parameters::operator=(rhs);
163 :
164 10442886 : _params = rhs._params;
165 :
166 10442886 : _buildable_types = rhs._buildable_types;
167 10442886 : _buildable_rm_types = rhs._buildable_rm_types;
168 10442886 : _collapse_nesting = rhs._collapse_nesting;
169 10442886 : _moose_object_syntax_visibility = rhs._moose_object_syntax_visibility;
170 10442886 : _coupled_vars = rhs._coupled_vars;
171 10442886 : _new_to_deprecated_coupled_vars = rhs._new_to_deprecated_coupled_vars;
172 10442886 : _allow_copy = rhs._allow_copy;
173 10442886 : _block_fullpath = rhs._block_fullpath;
174 10442886 : _block_location = rhs._block_location;
175 10442886 : _old_to_new_name_and_dep = rhs._old_to_new_name_and_dep;
176 10442886 : _new_to_old_names = rhs._new_to_old_names;
177 10442886 : _hit_node = rhs._hit_node;
178 10442886 : _finalized = false;
179 :
180 10442886 : return *this;
181 : }
182 :
183 : InputParameters &
184 124249179 : InputParameters::operator+=(const InputParameters & rhs)
185 : {
186 124249179 : Parameters::operator+=(rhs);
187 :
188 : // TODO: this is not a proper merge - if a particular parameter exists in both this and rhs,
189 : // then we should actually smartly merge both metadata structs before storing in this.
190 437381341 : for (auto it = rhs._params.begin(); it != rhs._params.end(); ++it)
191 313132162 : _params[it->first] = it->second;
192 :
193 248498358 : _buildable_types.insert(
194 124249179 : _buildable_types.end(), rhs._buildable_types.begin(), rhs._buildable_types.end());
195 248498358 : _buildable_rm_types.insert(
196 124249179 : _buildable_rm_types.end(), rhs._buildable_rm_types.begin(), rhs._buildable_rm_types.end());
197 :
198 : // Collapse nesting and moose object syntax hiding are not modified with +=
199 124249179 : _coupled_vars.insert(rhs._coupled_vars.begin(), rhs._coupled_vars.end());
200 124249179 : _new_to_deprecated_coupled_vars.insert(rhs._new_to_deprecated_coupled_vars.begin(),
201 : rhs._new_to_deprecated_coupled_vars.end());
202 :
203 124249179 : _old_to_new_name_and_dep.insert(rhs._old_to_new_name_and_dep.begin(),
204 : rhs._old_to_new_name_and_dep.end());
205 124249179 : _new_to_old_names.insert(rhs._new_to_old_names.begin(), rhs._new_to_old_names.end());
206 124249179 : return *this;
207 : }
208 :
209 : void
210 6296682 : InputParameters::setDeprecatedVarDocString(const std::string & new_name,
211 : const std::string & doc_string)
212 : {
213 6296682 : auto coupled_vars_it = _new_to_deprecated_coupled_vars.find(new_name);
214 6296682 : if (coupled_vars_it != _new_to_deprecated_coupled_vars.end())
215 : {
216 0 : auto params_it = _params.find(coupled_vars_it->second);
217 0 : if (params_it == _params.end())
218 0 : mooseError("There must have been a mistake in the construction of the new to deprecated "
219 : "coupled vars map because the old name ",
220 0 : coupled_vars_it->second,
221 : " doesn't exist in the parameters data.");
222 :
223 0 : params_it->second._doc_string = doc_string;
224 : }
225 6296682 : }
226 :
227 : void
228 345536 : InputParameters::addCoupledVar(const std::string & name, Real value, const std::string & doc_string)
229 : {
230 345536 : addParam<std::vector<VariableName>>(name, doc_string);
231 345536 : _coupled_vars.insert(name);
232 345536 : auto & metadata = _params[name];
233 345536 : metadata._coupled_default.assign(1, value);
234 345536 : metadata._have_coupled_default = true;
235 :
236 : // Set the doc string for any associated deprecated coupled var
237 345536 : setDeprecatedVarDocString(name, doc_string);
238 345536 : }
239 :
240 : void
241 114916 : InputParameters::addCoupledVar(const std::string & name,
242 : const std::vector<Real> & value,
243 : const std::string & doc_string)
244 : {
245 : // std::vector<VariableName>(1, Moose::stringify(value)),
246 114916 : addParam<std::vector<VariableName>>(name, doc_string);
247 114916 : _coupled_vars.insert(name);
248 114916 : auto & metadata = _params[name];
249 114916 : metadata._coupled_default = value;
250 114916 : metadata._have_coupled_default = true;
251 :
252 : // Set the doc string for any associated deprecated coupled var
253 114916 : setDeprecatedVarDocString(name, doc_string);
254 114916 : }
255 :
256 : void
257 5836230 : InputParameters::addCoupledVar(const std::string & name, const std::string & doc_string)
258 : {
259 5836230 : addParam<std::vector<VariableName>>(name, doc_string);
260 5836230 : _coupled_vars.insert(name);
261 :
262 : // Set the doc string for any associated deprecated coupled var
263 5836230 : setDeprecatedVarDocString(name, doc_string);
264 5836230 : }
265 :
266 : void
267 0 : InputParameters::addDeprecatedCoupledVar(const std::string & old_name,
268 : const std::string & new_name,
269 : const std::string & removal_date /*=""*/)
270 : {
271 0 : mooseDeprecated("Please use 'deprecateCoupledVar'");
272 :
273 0 : _show_deprecated_message = false;
274 :
275 : // Set the doc string if we are adding the deprecated var after the new var has already been added
276 0 : auto params_it = _params.find(new_name);
277 0 : std::string doc_string;
278 0 : if (params_it != _params.end())
279 0 : doc_string = params_it->second._doc_string;
280 :
281 0 : addParam<std::vector<VariableName>>(old_name, doc_string);
282 0 : _coupled_vars.insert(old_name);
283 0 : _new_to_deprecated_coupled_vars.emplace(new_name, old_name);
284 :
285 : std::string deprecation_message =
286 0 : "The coupled variable parameter '" + old_name + "' has been deprecated";
287 0 : if (!removal_date.empty())
288 0 : deprecation_message += " and will be removed " + removal_date;
289 0 : deprecation_message += ". Please use the '" + new_name + "' coupled variable parameter instead.";
290 0 : _params[old_name]._deprecation_message = deprecation_message;
291 0 : _show_deprecated_message = true;
292 0 : }
293 :
294 : void
295 4 : InputParameters::addCoupledVarWithAutoBuild(const std::string & name,
296 : const std::string & base_name,
297 : const std::string & num_name,
298 : const std::string & doc_string)
299 : {
300 4 : addParam<std::vector<VariableName>>(name, doc_string);
301 4 : _coupled_vars.insert(name);
302 4 : _params[name]._autobuild_vecs = std::make_pair(base_name, num_name);
303 :
304 : // Additionally there are two more parameters that need to be added:
305 4 : addParam<std::string>(base_name, doc_string + " (base_name)");
306 4 : addParam<unsigned int>(num_name, doc_string + " (num_name)");
307 4 : }
308 :
309 : void
310 4 : InputParameters::addRequiredCoupledVarWithAutoBuild(const std::string & name,
311 : const std::string & base_name,
312 : const std::string & num_name,
313 : const std::string & doc_string)
314 : {
315 4 : addRequiredParam<std::vector<VariableName>>(name, doc_string);
316 :
317 4 : addCoupledVarWithAutoBuild(name, base_name, num_name, doc_string);
318 4 : }
319 :
320 : void
321 4533652 : InputParameters::addRequiredCoupledVar(const std::string & name, const std::string & doc_string)
322 : {
323 4533652 : addRequiredParam<std::vector<VariableName>>(name, doc_string);
324 4533652 : _coupled_vars.insert(name);
325 4533652 : }
326 :
327 : std::string
328 11615554 : InputParameters::getDocString(const std::string & name_in) const
329 : {
330 11615554 : const auto name = checkForRename(name_in);
331 :
332 11615554 : std::string doc_string;
333 11615554 : auto it = _params.find(name);
334 11615554 : if (it != _params.end())
335 963136046 : for (const auto & ch : it->second._doc_string)
336 : {
337 951520492 : if (ch == '\n')
338 0 : doc_string += " ... ";
339 : else
340 951520492 : doc_string += ch;
341 : }
342 :
343 23231108 : return doc_string;
344 11615554 : }
345 :
346 : void
347 3880368 : InputParameters::setDocString(const std::string & name_in, const std::string & doc)
348 : {
349 3880368 : const auto name = checkForRename(name_in);
350 :
351 3880368 : auto it = _params.find(name);
352 3880368 : if (it == _params.end())
353 1 : mooseError("Unable to set the documentation string (using setDocString) for the \"",
354 : name,
355 : "\" parameter, the parameter does not exist.");
356 3880367 : it->second._doc_string = doc;
357 3880368 : }
358 :
359 : std::string
360 7056800 : InputParameters::getDocUnit(const std::string & name_in) const
361 : {
362 7056800 : const auto name = checkForRename(name_in);
363 14113600 : return _params.at(name)._doc_unit;
364 7056800 : }
365 :
366 : void
367 0 : InputParameters::setDocUnit(const std::string & name_in, const std::string & doc_unit)
368 : {
369 0 : const auto name = checkForRename(name_in);
370 0 : _params[name]._doc_unit = doc_unit;
371 0 : }
372 :
373 : bool
374 58708124 : InputParameters::isParamRequired(const std::string & name_in) const
375 : {
376 58708124 : const auto name = checkForRename(name_in);
377 117416248 : return _params.count(name) > 0 && _params.at(name)._required;
378 58708124 : }
379 :
380 : void
381 14484 : InputParameters::makeParamNotRequired(const std::string & name_in)
382 : {
383 14484 : const auto name = checkForRename(name_in);
384 :
385 14484 : if (_params.count(name))
386 14482 : _params[name]._required = false;
387 14484 : }
388 :
389 : bool
390 330995140 : InputParameters::isParamValid(const std::string & name_in) const
391 : {
392 330995140 : const auto name = checkForRename(name_in);
393 330995140 : if (have_parameter<MooseEnum>(name))
394 6145103 : return get<MooseEnum>(name).isValid();
395 324850037 : else if (have_parameter<std::vector<MooseEnum>>(name))
396 : {
397 8863 : for (auto it = get<std::vector<MooseEnum>>(name).begin();
398 17864 : it != get<std::vector<MooseEnum>>(name).end();
399 9001 : ++it)
400 9003 : if (!it->isValid())
401 2 : return false;
402 8861 : return true;
403 : }
404 324841174 : else if (have_parameter<MultiMooseEnum>(name))
405 1960759 : return get<MultiMooseEnum>(name).isValid();
406 322880415 : else if (have_parameter<std::vector<MultiMooseEnum>>(name))
407 : {
408 241 : for (auto it = get<std::vector<MultiMooseEnum>>(name).begin();
409 505 : it != get<std::vector<MultiMooseEnum>>(name).end();
410 264 : ++it)
411 439 : if (!it->isValid())
412 175 : return false;
413 66 : return true;
414 : }
415 322880174 : else if (have_parameter<ExecFlagEnum>(name))
416 6209872 : return get<ExecFlagEnum>(name).isValid();
417 : else
418 316670302 : return _params.count(name) > 0 && _params.at(name)._valid;
419 330995140 : }
420 :
421 : bool
422 2474737 : InputParameters::isParamSetByAddParam(const std::string & name_in) const
423 : {
424 2474737 : const auto name = checkForRename(name_in);
425 4949474 : return _params.count(name) > 0 && _params.at(name)._set_by_add_param;
426 2474737 : }
427 :
428 : bool
429 6654784 : InputParameters::isParamDeprecated(const std::string & name_in) const
430 : {
431 6654784 : const auto name = checkForRename(name_in);
432 13309568 : return _params.count(name) > 0 && !_params.at(name)._deprecation_message.empty();
433 6654784 : }
434 :
435 : bool
436 2031661 : InputParameters::areAllRequiredParamsValid() const
437 : {
438 31466332 : for (const auto & it : *this)
439 29535520 : if (isParamRequired(it.first) && !isParamValid(it.first))
440 100849 : return false;
441 1930812 : return true;
442 : }
443 :
444 : bool
445 211295758 : InputParameters::isPrivate(const std::string & name_in) const
446 : {
447 211295758 : const auto name = checkForRename(name_in);
448 422591516 : return _params.count(name) > 0 && _params.at(name)._is_private;
449 211295758 : }
450 :
451 : void
452 23510868 : InputParameters::declareControllable(const std::string & input_names,
453 : std::set<ExecFlagType> execute_flags)
454 : {
455 23510868 : std::vector<std::string> names;
456 23510868 : MooseUtils::tokenize<std::string>(input_names, names, 1, " ");
457 47138063 : for (auto & name_in : names)
458 : {
459 23627196 : const auto name = checkForRename(name_in);
460 23627196 : auto map_iter = _params.find(name);
461 23627196 : if (map_iter != _params.end()) // error is handled by checkParams method
462 : {
463 23627195 : map_iter->second._controllable = true;
464 23627195 : map_iter->second._controllable_flags = execute_flags;
465 : }
466 : else
467 1 : mooseError("The input parameter '",
468 : name,
469 : "' does not exist, thus cannot be marked as controllable.");
470 23627196 : }
471 23510868 : }
472 :
473 : bool
474 120344678 : InputParameters::isControllable(const std::string & name_in) const
475 : {
476 120344678 : const auto name = checkForRename(name_in);
477 240689356 : return _params.count(name) > 0 && _params.at(name)._controllable;
478 120344678 : }
479 :
480 : const std::set<ExecFlagType> &
481 1317774 : InputParameters::getControllableExecuteOnTypes(const std::string & name_in) const
482 : {
483 1317774 : const auto name = checkForRename(name_in);
484 2635548 : return at(name)._controllable_flags;
485 1317774 : }
486 :
487 : void
488 42062586 : InputParameters::registerBase(const std::string & value)
489 : {
490 42062586 : InputParameters::set<std::string>("_moose_base") = value;
491 42062586 : _params["_moose_base"]._is_private = true;
492 42062586 : }
493 :
494 : std::optional<std::string>
495 159415 : InputParameters::getBase() const
496 : {
497 159415 : if (have_parameter<std::string>("_moose_base"))
498 159415 : return get<std::string>("_moose_base");
499 0 : return {};
500 : }
501 :
502 : void
503 18085592 : InputParameters::registerSystemAttributeName(const std::string & value)
504 : {
505 18085592 : InputParameters::set<std::string>("_moose_warehouse_system_name") = value;
506 18085592 : _params["_moose_warehouse_system_name"]._is_private = true;
507 18085592 : }
508 :
509 : const std::string &
510 288408 : InputParameters::getSystemAttributeName() const
511 : {
512 : mooseAssert(have_parameter<std::string>("_moose_warehouse_system_name"),
513 : "SystemAttributeName is not available! Call 'registerSystemAttributeName' (usually "
514 : "in the validParams function) before you try accessing it!");
515 288408 : return Parameters::get<std::string>("_moose_warehouse_system_name");
516 : }
517 :
518 : void
519 0 : InputParameters::registerBuildableTypes(const std::string & names)
520 : {
521 0 : _buildable_types.clear();
522 0 : MooseUtils::tokenize(names, _buildable_types, 1, " \t\n\v\f\r"); // tokenize on whitespace
523 0 : }
524 :
525 : void
526 8199268 : InputParameters::addRelationshipManager(
527 : const std::string & name,
528 : Moose::RelationshipManagerType rm_type,
529 : Moose::RelationshipManagerInputParameterCallback input_parameter_callback)
530 : {
531 8199268 : _buildable_rm_types.emplace_back(name, rm_type, input_parameter_callback);
532 8199268 : }
533 :
534 : const std::vector<std::string> &
535 21271212 : InputParameters::getBuildableTypes() const
536 : {
537 21271212 : return _buildable_types;
538 : }
539 :
540 : const std::vector<std::tuple<std::string,
541 : Moose::RelationshipManagerType,
542 : Moose::RelationshipManagerInputParameterCallback>> &
543 2700002 : InputParameters::getBuildableRelationshipManagerTypes() const
544 : {
545 2700002 : return _buildable_rm_types;
546 : }
547 :
548 : void
549 0 : InputParameters::collapseSyntaxNesting(bool collapse)
550 : {
551 0 : _collapse_nesting = collapse;
552 0 : }
553 :
554 : bool
555 391001 : InputParameters::collapseSyntaxNesting() const
556 : {
557 391001 : return _collapse_nesting;
558 : }
559 :
560 : void
561 0 : InputParameters::mooseObjectSyntaxVisibility(bool visibility)
562 : {
563 0 : _moose_object_syntax_visibility = visibility;
564 0 : }
565 :
566 : bool
567 449306 : InputParameters::mooseObjectSyntaxVisibility() const
568 : {
569 449306 : return _moose_object_syntax_visibility;
570 : }
571 :
572 : #define dynamicCastRangeCheck(type, up_type, long_name, short_name, param, oss) \
573 : do \
574 : { \
575 : libMesh::Parameters::Value * val = MooseUtils::get(param); \
576 : InputParameters::Parameter<type> * scalar_p = \
577 : dynamic_cast<InputParameters::Parameter<type> *>(val); \
578 : if (scalar_p) \
579 : rangeCheck<type, up_type>(long_name, short_name, scalar_p, oss); \
580 : InputParameters::Parameter<std::vector<type>> * vector_p = \
581 : dynamic_cast<InputParameters::Parameter<std::vector<type>> *>(val); \
582 : if (vector_p) \
583 : rangeCheck<type, up_type>(long_name, short_name, vector_p, oss); \
584 : } while (0)
585 :
586 : #define checkMooseType(param_type, name) \
587 : if (have_parameter<param_type>(name) || have_parameter<std::vector<param_type>>(name)) \
588 : oss << inputLocation(param_name) << ": non-controllable type '" << type(name) \
589 : << "' for parameter '" << paramFullpath(param_name) << "' marked controllable";
590 :
591 : void
592 5044283 : InputParameters::checkParams(const std::string & parsing_syntax)
593 : {
594 5044283 : std::string parampath = blockFullpath() != "" ? blockFullpath() : parsing_syntax;
595 5044283 : std::ostringstream oss;
596 : // Required parameters
597 132134674 : for (const auto & it : *this)
598 : {
599 127090391 : const auto param_name = checkForRename(it.first);
600 127090391 : if (!isParamValid(param_name) && isParamRequired(param_name))
601 : {
602 : // check if an old, deprecated name exists for this parameter that may be specified
603 36 : auto oit = _new_to_deprecated_coupled_vars.find(param_name);
604 36 : if (oit != _new_to_deprecated_coupled_vars.end() && isParamValid(oit->second))
605 0 : continue;
606 :
607 108 : oss << blockLocation() << ": missing required parameter '" << parampath + "/" + param_name
608 72 : << "'\n";
609 36 : oss << "\tDoc String: \"" + getDocString(param_name) + "\"" << std::endl;
610 : }
611 127090391 : }
612 :
613 : // Range checked parameters
614 132134674 : for (const auto & it : *this)
615 : {
616 127090391 : std::string long_name(parampath + "/" + it.first);
617 :
618 127090391 : dynamicCastRangeCheck(Real, Real, long_name, it.first, it.second, oss);
619 127090391 : dynamicCastRangeCheck(int, long, long_name, it.first, it.second, oss);
620 127090391 : dynamicCastRangeCheck(long, long, long_name, it.first, it.second, oss);
621 127090391 : dynamicCastRangeCheck(unsigned int, long, long_name, it.first, it.second, oss);
622 127090391 : }
623 :
624 : // Controllable parameters
625 5896571 : for (const auto & param_name : getControllableParameters())
626 : {
627 852288 : if (isPrivate(param_name))
628 2 : oss << inputLocation(param_name) << ": private parameter '" << paramFullpath(param_name)
629 1 : << "' marked controllable";
630 :
631 852288 : checkMooseType(NonlinearVariableName, param_name);
632 852288 : checkMooseType(AuxVariableName, param_name);
633 852288 : checkMooseType(VariableName, param_name);
634 852288 : checkMooseType(BoundaryName, param_name);
635 852288 : checkMooseType(SubdomainName, param_name);
636 852288 : checkMooseType(PostprocessorName, param_name);
637 852288 : checkMooseType(VectorPostprocessorName, param_name);
638 852288 : checkMooseType(UserObjectName, param_name);
639 852288 : checkMooseType(MaterialPropertyName, param_name);
640 5044283 : }
641 :
642 5044283 : if (!oss.str().empty())
643 78 : mooseError(oss.str());
644 5044214 : }
645 :
646 : void
647 5013775 : InputParameters::finalize(const std::string & parsing_syntax)
648 : {
649 : mooseAssert(!isFinalized(), "Already finalized");
650 :
651 5013775 : checkParams(parsing_syntax);
652 :
653 : // Helper for setting the absolute paths for each set file name parameter
654 252271 : const auto set_absolute_path = [this](const std::string & param_name, auto & value)
655 : {
656 : // We don't need to set a path if nothing is there
657 235060 : if (value.empty())
658 217849 : return;
659 :
660 17315 : std::filesystem::path value_path = std::string(value);
661 : // Is already absolute, nothing to do
662 17315 : if (value_path.is_absolute())
663 104 : return;
664 :
665 : // The base by which to make things relative to
666 17211 : const auto file_base = getFileBase(param_name);
667 17211 : value = std::filesystem::absolute(file_base / value_path).c_str();
668 5031022 : };
669 :
670 : // Set the absolute path for each file name typed parameter
671 131316619 : for (const auto & [param_name, param_value] : *this)
672 : {
673 : #define set_if_filename(type) \
674 : else if (auto type_value = dynamic_cast<Parameters::Parameter<type> *>(param_value.get())) \
675 : set_absolute_path(param_name, type_value->set()); \
676 : else if (auto type_values = dynamic_cast<Parameters::Parameter<std::vector<type>> *>( \
677 : param_value.get())) for (auto & value : type_values->set()) \
678 : set_absolute_path(param_name, value)
679 :
680 : if (false)
681 : ;
682 : // Note that we explicitly skip DataFileName here because we do not want absolute
683 : // file paths for data files, as they're searched in the data directories
684 126311398 : set_if_filename(FileName);
685 126213591 : set_if_filename(FileNameNoExtension);
686 126097503 : set_if_filename(MeshFileName);
687 126055967 : set_if_filename(MatrixFileName);
688 : #undef set_if_filename
689 : // Set paths for data files
690 126053836 : else if (auto data_file_name =
691 126053836 : dynamic_cast<Parameters::Parameter<DataFileName> *>(param_value.get()))
692 : {
693 205 : Moose::DataFileUtils::Path found_path;
694 205 : std::optional<std::string> error;
695 :
696 : // Catch this so that we can add additional error context if it fails (the param path)
697 205 : const auto throw_on_error_before = Moose::_throw_on_error;
698 205 : Moose::_throw_on_error = true;
699 : try
700 : {
701 221 : found_path = Moose::DataFileUtils::getPath(data_file_name->get(), getFileBase(param_name));
702 : }
703 4 : catch (std::exception & e)
704 : {
705 4 : error = errorPrefix(param_name) + " " + e.what();
706 4 : }
707 205 : Moose::_throw_on_error = throw_on_error_before;
708 :
709 205 : if (error)
710 4 : mooseError(*error);
711 :
712 : // Set the value to the absolute searched path
713 201 : data_file_name->set() = found_path.path;
714 : // And store the path in metadata so that we can dump it later
715 201 : at(param_name)._data_file_name_path = found_path;
716 201 : }
717 : }
718 :
719 5013703 : _finalized = true;
720 5013703 : }
721 :
722 : std::filesystem::path
723 17416 : InputParameters::getFileBase(const std::optional<std::string> & param_name) const
724 : {
725 : mooseAssert(!have_parameter<std::string>("_app_name"),
726 : "Not currently setup to work with app FileName parameters");
727 :
728 17416 : const hit::Node * hit_node = nullptr;
729 :
730 : // Context from the individual parameter
731 17416 : if (param_name)
732 17416 : hit_node = getHitNode(*param_name);
733 : // Context from the parameters
734 17416 : if (!hit_node)
735 931 : hit_node = getHitNode();
736 : // No hit node, so use the cwd (no input files)
737 17416 : if (!hit_node)
738 136 : return std::filesystem::current_path();
739 :
740 : // Find any context that isn't command line arguments
741 17738 : while (hit_node && hit_node->filename() == "CLI_ARGS")
742 458 : hit_node = hit_node->parent();
743 :
744 : // Failed to find a node up the tree that isn't a command line argument
745 17280 : if (!hit_node)
746 : {
747 0 : std::string prefix = "";
748 0 : if (param_name)
749 0 : prefix = errorPrefix(*param_name) + " ";
750 0 : mooseError(prefix,
751 : "Input context was set via a command-line argument and does not have sufficient "
752 : "context for "
753 : "determining a file path.");
754 0 : }
755 :
756 34560 : return std::filesystem::absolute(std::filesystem::path(hit_node->filename()).parent_path());
757 : }
758 :
759 : bool
760 2021414 : InputParameters::isRangeChecked(const std::string & param_name) const
761 : {
762 2021414 : const auto name = checkForRename(param_name);
763 4042828 : return !_params.find(name)->second._range_function.empty();
764 2021414 : }
765 :
766 : std::string
767 3 : InputParameters::rangeCheckedFunction(const std::string & param_name) const
768 : {
769 3 : const auto name = checkForRename(param_name);
770 6 : return _params.at(name)._range_function;
771 3 : }
772 :
773 : bool
774 2021049 : InputParameters::hasDefault(const std::string & param_name) const
775 : {
776 2021049 : const auto name = checkForRename(param_name);
777 2021049 : if (hasDefaultCoupledValue(name))
778 0 : return true;
779 : // If it has a default, it's already valid
780 2021049 : else if (isParamSetByAddParam(name))
781 2 : return true;
782 2021047 : else if (isParamValid(name))
783 0 : mooseError("No way to know if the parameter '", param_name, "' has a default");
784 : else
785 2021047 : return false;
786 2021049 : }
787 :
788 : bool
789 2145527 : InputParameters::hasCoupledValue(const std::string & coupling_name) const
790 : {
791 2145527 : return _coupled_vars.find(coupling_name) != _coupled_vars.end();
792 : }
793 :
794 : bool
795 8649457 : InputParameters::hasDefaultCoupledValue(const std::string & coupling_name) const
796 : {
797 8655662 : return _params.count(coupling_name) > 0 && _params.at(coupling_name)._have_coupled_default &&
798 8655662 : _coupled_vars.count(coupling_name) > 0;
799 : }
800 :
801 : void
802 921 : InputParameters::defaultCoupledValue(const std::string & coupling_name, Real value, unsigned int i)
803 : {
804 921 : const auto actual_name = checkForRename(coupling_name);
805 921 : _params[actual_name]._coupled_default.resize(i + 1);
806 921 : _params[actual_name]._coupled_default[i] = value;
807 921 : _params[actual_name]._have_coupled_default = true;
808 921 : }
809 :
810 : Real
811 909581 : InputParameters::defaultCoupledValue(const std::string & coupling_name, unsigned int i) const
812 : {
813 909581 : auto value_it = _params.find(coupling_name);
814 :
815 909581 : if (value_it == _params.end() || !value_it->second._have_coupled_default)
816 0 : mooseError("Attempted to retrieve default value for coupled variable '",
817 : coupling_name,
818 : "' when none was provided. \n\nThere are three reasons why this may have "
819 : "occurred:\n 1. The other version of params.addCoupledVar() should be used in order "
820 : "to provide a default value. \n 2. This should have been a required coupled "
821 : "variable added with params.addRequiredCoupledVar() \n 3. The call to get the "
822 : "coupled value should have been properly guarded with isCoupled()\n");
823 :
824 909581 : return value_it->second._coupled_default.at(i);
825 : }
826 :
827 : unsigned int
828 214894 : InputParameters::numberDefaultCoupledValues(const std::string & coupling_name) const
829 : {
830 214894 : auto value_it = _params.find(coupling_name);
831 214894 : if (value_it == _params.end())
832 0 : mooseError("Attempted to retrieve default value for coupled variable '",
833 : coupling_name,
834 : "' when none was provided.");
835 214894 : return value_it->second._coupled_default.size();
836 : }
837 :
838 : std::map<std::string, std::pair<std::string, std::string>>
839 2107072 : InputParameters::getAutoBuildVectors() const
840 : {
841 2107072 : std::map<std::string, std::pair<std::string, std::string>> abv;
842 55102642 : for (auto it = _params.begin(); it != _params.end(); ++it)
843 : {
844 52995570 : if (!it->second._autobuild_vecs.first.empty())
845 2 : abv[it->first] = it->second._autobuild_vecs;
846 : }
847 2107072 : return abv;
848 0 : }
849 :
850 : std::string
851 7058485 : InputParameters::type(const std::string & name_in) const
852 : {
853 7058485 : const auto name = checkForRename(name_in);
854 7058485 : if (!_values.count(name))
855 0 : mooseError("Parameter \"", name, "\" not found.\n\n", *this);
856 :
857 7058485 : if (_coupled_vars.find(name) != _coupled_vars.end())
858 183965 : return "std::vector<VariableName>";
859 6874520 : else if (_params.count(name) > 0 && !_params.at(name)._custom_type.empty())
860 7725 : return _params.at(name)._custom_type;
861 6866795 : return _values.at(name)->type();
862 7058485 : }
863 :
864 : std::string
865 1524704 : InputParameters::getMooseType(const std::string & name_in) const
866 : {
867 1524704 : const auto name = checkForRename(name_in);
868 1524704 : std::string var;
869 :
870 1524704 : if (have_parameter<VariableName>(name))
871 72488 : var = get<VariableName>(name);
872 1452216 : else if (have_parameter<NonlinearVariableName>(name))
873 747697 : var = get<NonlinearVariableName>(name);
874 704519 : else if (have_parameter<LinearVariableName>(name))
875 19544 : var = get<LinearVariableName>(name);
876 684975 : else if (have_parameter<AuxVariableName>(name))
877 420343 : var = get<AuxVariableName>(name);
878 264632 : else if (have_parameter<PostprocessorName>(name))
879 0 : var = get<PostprocessorName>(name);
880 264632 : else if (have_parameter<VectorPostprocessorName>(name))
881 0 : var = get<VectorPostprocessorName>(name);
882 264632 : else if (have_parameter<FunctionName>(name))
883 0 : var = get<FunctionName>(name);
884 264632 : else if (have_parameter<UserObjectName>(name))
885 0 : var = get<UserObjectName>(name);
886 264632 : else if (have_parameter<MaterialPropertyName>(name))
887 0 : var = get<MaterialPropertyName>(name);
888 264632 : else if (have_parameter<std::string>(name))
889 0 : var = get<std::string>(name);
890 :
891 3049408 : return var;
892 1524704 : }
893 :
894 : std::vector<std::string>
895 842576 : InputParameters::getVecMooseType(const std::string & name_in) const
896 : {
897 842576 : const auto name = checkForRename(name_in);
898 842576 : std::vector<std::string> svars;
899 :
900 842576 : if (have_parameter<std::vector<VariableName>>(name))
901 : {
902 842568 : std::vector<VariableName> vars = get<std::vector<VariableName>>(name);
903 842568 : std::copy(vars.begin(), vars.end(), std::back_inserter(svars));
904 842568 : }
905 8 : else if (have_parameter<std::vector<NonlinearVariableName>>(name))
906 : {
907 0 : std::vector<NonlinearVariableName> vars = get<std::vector<NonlinearVariableName>>(name);
908 0 : std::copy(vars.begin(), vars.end(), std::back_inserter(svars));
909 0 : }
910 8 : else if (have_parameter<std::vector<AuxVariableName>>(name))
911 : {
912 0 : std::vector<AuxVariableName> vars = get<std::vector<AuxVariableName>>(name);
913 0 : std::copy(vars.begin(), vars.end(), std::back_inserter(svars));
914 0 : }
915 8 : else if (have_parameter<std::vector<MaterialPropertyName>>(name))
916 : {
917 0 : std::vector<MaterialPropertyName> vars = get<std::vector<MaterialPropertyName>>(name);
918 0 : std::copy(vars.begin(), vars.end(), std::back_inserter(svars));
919 0 : }
920 8 : else if (have_parameter<std::vector<std::string>>(name))
921 : {
922 0 : std::vector<std::string> vars = get<std::vector<std::string>>(name);
923 0 : std::copy(vars.begin(), vars.end(), std::back_inserter(svars));
924 0 : }
925 :
926 1685152 : return svars;
927 842576 : }
928 :
929 : void
930 157558968 : InputParameters::addParamNamesToGroup(const std::string & space_delim_names,
931 : const std::string group_name)
932 : {
933 157558968 : std::vector<std::string> elements;
934 157558968 : MooseUtils::tokenize(space_delim_names, elements, 1, " \t\n\v\f\r"); // tokenize on whitespace
935 :
936 : // Since we don't require types (templates) for this method, we need
937 : // to get a raw list of parameter names to compare against.
938 157558968 : std::set<std::string> param_names;
939 2344214354 : for (const auto & it : *this)
940 2186655386 : param_names.insert(it.first);
941 :
942 514396584 : for (const auto & param_name : elements)
943 356837616 : if (_params.count(param_name) > 0)
944 356837616 : _params[param_name]._group = group_name;
945 : else
946 0 : mooseError("Unable to find a parameter with name: ",
947 : param_name,
948 : " when adding to group ",
949 : group_name,
950 0 : '.');
951 157558968 : }
952 :
953 : void
954 0 : InputParameters::renameParameterGroup(const std::string & old_name, const std::string & new_name)
955 : {
956 0 : for (auto & param : _params)
957 0 : if (param.second._group == old_name)
958 0 : param.second._group = new_name;
959 0 : }
960 :
961 : void
962 1757062 : InputParameters::setGlobalCommandLineParam(const std::string & name)
963 : {
964 1757062 : auto & cl_data = at(checkForRename(name))._cl_data;
965 1757062 : if (!cl_data)
966 1 : mooseError("InputParameters::setGlobalCommandLineParam: The parameter '",
967 : name,
968 : "' is not a command line parameter");
969 1757061 : cl_data->global = true;
970 1757061 : }
971 :
972 : bool
973 2 : InputParameters::isCommandLineParameter(const std::string & name) const
974 : {
975 2 : return at(checkForRename(name))._cl_data.has_value();
976 : }
977 :
978 : std::optional<InputParameters::CommandLineMetadata>
979 8695705 : InputParameters::queryCommandLineMetadata(const std::string & name) const
980 : {
981 8695705 : const auto & cl_data = at(checkForRename(name))._cl_data;
982 8695705 : if (!cl_data)
983 3680152 : return {};
984 5015553 : return *cl_data;
985 : }
986 :
987 : const InputParameters::CommandLineMetadata &
988 22 : InputParameters::getCommandLineMetadata(const std::string & name) const
989 : {
990 22 : const auto & cl_data = at(checkForRename(name))._cl_data;
991 22 : if (!cl_data)
992 1 : mooseError("InputParameters::getCommandLineMetadata: The parameter '",
993 : name,
994 : "' is not a command line parameter");
995 21 : return *cl_data;
996 : }
997 :
998 : void
999 351462 : InputParameters::commandLineParamSet(const std::string & name, const CommandLineParamSetKey)
1000 : {
1001 351462 : auto & cl_data = at(checkForRename(name))._cl_data;
1002 351462 : if (!cl_data)
1003 1 : mooseError("InputParameters::commandLineParamSet: The parameter '",
1004 : name,
1005 : "' is not a command line parameter");
1006 351461 : cl_data->set_by_command_line = true;
1007 351461 : }
1008 :
1009 : std::string
1010 7056800 : InputParameters::getGroupName(const std::string & param_name_in) const
1011 : {
1012 7056800 : const auto param_name = checkForRename(param_name_in);
1013 7056800 : auto it = _params.find(param_name);
1014 7056800 : if (it != _params.end())
1015 7056800 : return it->second._group;
1016 0 : return std::string();
1017 7056800 : }
1018 :
1019 : void
1020 518934 : InputParameters::applyParameters(const InputParameters & common,
1021 : const std::vector<std::string> & exclude,
1022 : const bool allow_private)
1023 : {
1024 : // If we're applying all of the things, also associate the top level hit node
1025 518934 : if (exclude.empty() && !getHitNode() && common.getHitNode())
1026 150289 : setHitNode(*common.getHitNode(), {});
1027 :
1028 : // Loop through the common parameters
1029 33892339 : for (const auto & it : common)
1030 : {
1031 : // Common parameter name
1032 33373405 : const std::string & common_name = it.first;
1033 : // Continue to next parameter, if the current is in list of excluded parameters
1034 33373405 : if (std::find(exclude.begin(), exclude.end(), common_name) != exclude.end())
1035 102144 : continue;
1036 :
1037 33271261 : applyParameter(common, common_name, allow_private);
1038 : }
1039 :
1040 : // Loop through the coupled variables
1041 518934 : for (std::set<std::string>::const_iterator it = common.coupledVarsBegin();
1042 520331 : it != common.coupledVarsEnd();
1043 1397 : ++it)
1044 : {
1045 : // Variable name
1046 1397 : const std::string var_name = *it;
1047 :
1048 : // Continue to next variable, if the current is in list of excluded parameters
1049 1397 : if (std::find(exclude.begin(), exclude.end(), var_name) != exclude.end())
1050 0 : continue;
1051 :
1052 1397 : applyCoupledVar(common, var_name);
1053 1397 : }
1054 518934 : }
1055 :
1056 : void
1057 115472 : InputParameters::applySpecificParameters(const InputParameters & common,
1058 : const std::vector<std::string> & include,
1059 : bool allow_private)
1060 : {
1061 : // Loop through the common parameters
1062 2648856 : for (const auto & it : common)
1063 : {
1064 :
1065 : // Common parameter name
1066 2533384 : const std::string & common_name = it.first;
1067 :
1068 : // Continue to next parameter, if the current is not in list of included parameters
1069 2533384 : if (std::find(include.begin(), include.end(), common_name) == include.end())
1070 2193991 : continue;
1071 :
1072 339393 : applyParameter(common, common_name, allow_private);
1073 : }
1074 :
1075 : // Loop through the coupled variables
1076 115472 : for (std::set<std::string>::const_iterator it = common.coupledVarsBegin();
1077 115472 : it != common.coupledVarsEnd();
1078 0 : ++it)
1079 : {
1080 : // Variable name
1081 0 : const std::string var_name = *it;
1082 :
1083 : // Continue to next variable, if the current is not in list of included parameters
1084 0 : if (std::find(include.begin(), include.end(), var_name) == include.end())
1085 0 : continue;
1086 :
1087 0 : applyCoupledVar(common, var_name);
1088 0 : }
1089 115472 : }
1090 :
1091 : void
1092 1397 : InputParameters::applyCoupledVar(const InputParameters & common, const std::string & var_name)
1093 : {
1094 : // Disable the display of deprecated message when applying common parameters, this avoids a dump
1095 : // of messages
1096 1397 : _show_deprecated_message = false;
1097 :
1098 : // If the local parameters has a coupled variable, populate it with the value from the common
1099 : // parameters, if the common parameters has the coupled variable too
1100 1397 : if (hasCoupledValue(var_name))
1101 : {
1102 1393 : if (common.hasDefaultCoupledValue(var_name))
1103 : {
1104 : // prepare a vector of default coupled values
1105 0 : std::vector<Real> defaults(common.numberDefaultCoupledValues(var_name));
1106 0 : for (unsigned int j = 0; j < common.numberDefaultCoupledValues(var_name); ++j)
1107 0 : defaults[j] = common.defaultCoupledValue(var_name, j);
1108 0 : addCoupledVar(var_name, defaults, common.getDocString(var_name));
1109 0 : }
1110 1393 : else if (common.hasCoupledValue(var_name))
1111 1393 : addCoupledVar(var_name, common.getDocString(var_name));
1112 : }
1113 :
1114 : // Enable deprecated message printing
1115 1397 : _show_deprecated_message = true;
1116 1397 : }
1117 :
1118 : void
1119 33610756 : InputParameters::applyParameter(const InputParameters & common,
1120 : const std::string & common_name,
1121 : bool allow_private,
1122 : bool override_default)
1123 : {
1124 : // Disable the display of deprecated message when applying common parameters, this avoids a dump
1125 : // of messages
1126 33610756 : _show_deprecated_message = false;
1127 :
1128 33610756 : const auto local_name = checkForRename(common_name);
1129 :
1130 : // Extract the properties from the local parameter for the current common parameter name
1131 33610756 : const bool local_exist = _values.find(local_name) != _values.end();
1132 33610756 : const bool local_set = _params.count(local_name) > 0 && !_params[local_name]._set_by_add_param;
1133 33610756 : const bool local_priv = allow_private ? false : isPrivate(local_name);
1134 33610756 : const bool local_valid = isParamValid(local_name);
1135 :
1136 : // Extract the properties from the common parameter
1137 33610756 : const bool common_exist = common._values.find(common_name) != common._values.end();
1138 33610756 : const bool common_priv = allow_private ? false : common.isPrivate(common_name);
1139 33610756 : const bool common_valid = common.isParamValid(common_name) || override_default;
1140 :
1141 : /* In order to apply a common parameter 4 statements must be satisfied
1142 : * (1) A local parameter must exist with the same name as the common parameter
1143 : * (2) Common parameter must be valid and exist
1144 : * (3) Local parameter must be invalid OR not have been set from its default
1145 : * (4) Both cannot be private
1146 : */
1147 33610756 : if (local_exist && common_exist && common_valid && (!local_valid || !local_set) &&
1148 8378865 : (!common_priv || !local_priv))
1149 : {
1150 4150197 : remove(local_name);
1151 4150197 : _values[local_name] = common._values.find(common_name)->second->clone();
1152 4150197 : set_attributes(local_name, false);
1153 8300394 : _params[local_name]._set_by_add_param =
1154 4150197 : libmesh_map_find(common._params, common_name)._set_by_add_param;
1155 : // Keep track of where this param came from if we can. This will enable us to
1156 : // produce param errors from objects created within an action that link to
1157 : // the parameter in the action
1158 4150197 : at(local_name)._hit_node = common.getHitNode(common_name);
1159 : }
1160 29460559 : else if (!local_exist && !common_exist)
1161 1 : mooseError("InputParameters::applyParameter(): Attempted to apply invalid parameter \"",
1162 : common_name,
1163 : "\"");
1164 :
1165 : // Enable deprecated message printing
1166 33610755 : _show_deprecated_message = true;
1167 33610756 : }
1168 :
1169 : ///Deprecated method
1170 : bool
1171 0 : InputParameters::paramSetByUser(const std::string & name) const
1172 : {
1173 0 : mooseDeprecated("paramSetByUser() is deprecated. Use isParamSetByUser() instead.");
1174 0 : return isParamSetByUser(name);
1175 : }
1176 :
1177 : bool
1178 4204188 : InputParameters::isParamSetByUser(const std::string & name_in) const
1179 : {
1180 4204188 : const auto name = checkForRename(name_in);
1181 : // Invalid; for sure not set by the user
1182 4204188 : if (!isParamValid(name))
1183 1143955 : return false;
1184 : // Parameter is not located in the list (called Parameters::set)
1185 3060233 : if (!_params.count(name))
1186 0 : return false;
1187 : // Special case for a command line option, which is a private parameter
1188 3060233 : if (const auto cl_data = queryCommandLineMetadata(name))
1189 3060233 : return cl_data->set_by_command_line;
1190 : // Not a command line option, not set by addParam and not private
1191 2601917 : return !_params.at(name)._set_by_add_param && !_params.at(name)._is_private;
1192 4204188 : }
1193 :
1194 : bool
1195 2 : InputParameters::isParamDefined(const std::string & name_in) const
1196 : {
1197 2 : const auto name = checkForRename(name_in);
1198 4 : return _params.count(name) > 0;
1199 2 : }
1200 :
1201 : const std::string &
1202 2021420 : InputParameters::getDescription(const std::string & name_in) const
1203 : {
1204 2021420 : const auto name = checkForRename(name_in);
1205 2021420 : auto it = _params.find(name);
1206 2021420 : if (it == _params.end())
1207 0 : mooseError("No parameter exists with the name ", name);
1208 4042840 : return it->second._doc_string;
1209 2021420 : }
1210 :
1211 : template <>
1212 : void
1213 1728340 : InputParameters::addRequiredParam<MooseEnum>(const std::string & name,
1214 : const MooseEnum & moose_enum,
1215 : const std::string & doc_string)
1216 : {
1217 1728340 : InputParameters::set<MooseEnum>(name) = moose_enum; // valid parameter is set by set_attributes
1218 1728340 : auto & metadata = _params[name];
1219 1728340 : metadata._required = true;
1220 1728340 : metadata._doc_string = doc_string;
1221 1728340 : }
1222 :
1223 : template <>
1224 : void
1225 2 : InputParameters::addRequiredParam<MultiMooseEnum>(const std::string & name,
1226 : const MultiMooseEnum & moose_enum,
1227 : const std::string & doc_string)
1228 : {
1229 2 : InputParameters::set<MultiMooseEnum>(name) =
1230 2 : moose_enum; // valid parameter is set by set_attributes
1231 2 : auto & metadata = _params[name];
1232 2 : metadata._required = true;
1233 2 : metadata._doc_string = doc_string;
1234 2 : }
1235 :
1236 : template <>
1237 : void
1238 2 : InputParameters::addRequiredParam<std::vector<MooseEnum>>(
1239 : const std::string & name,
1240 : const std::vector<MooseEnum> & moose_enums,
1241 : const std::string & doc_string)
1242 : {
1243 2 : InputParameters::set<std::vector<MooseEnum>>(name) =
1244 2 : moose_enums; // valid parameter is set by set_attributes
1245 2 : auto & metadata = _params[name];
1246 2 : metadata._required = true;
1247 2 : metadata._doc_string = doc_string;
1248 2 : }
1249 :
1250 : template <>
1251 : void
1252 14314 : InputParameters::addRequiredParam<std::vector<MultiMooseEnum>>(
1253 : const std::string & name,
1254 : const std::vector<MultiMooseEnum> & moose_enums,
1255 : const std::string & doc_string)
1256 : {
1257 : mooseAssert(
1258 : moose_enums.size() == 1,
1259 : "Only 1 MultiMooseEnum is supported in addRequiredParam<std::vector<MultiMooseEnum>> for " +
1260 : name);
1261 : mooseAssert(!moose_enums[0].items().empty(),
1262 : "The MultiMooseEnum in addRequiredParam<std::vector<MultiMooseEnum>> is empty for " +
1263 : name);
1264 14314 : InputParameters::set<std::vector<MultiMooseEnum>>(name) =
1265 14314 : moose_enums; // valid parameter is set by set_attributes
1266 14314 : auto & metadata = _params[name];
1267 14314 : metadata._required = true;
1268 14314 : metadata._doc_string = doc_string;
1269 14314 : }
1270 :
1271 : template <>
1272 : void
1273 0 : InputParameters::addParam<MooseEnum>(const std::string & /*name*/,
1274 : const std::string & /*doc_string*/)
1275 : {
1276 0 : mooseError("You must supply a MooseEnum object when using addParam, even if the parameter is not "
1277 : "required!");
1278 : }
1279 :
1280 : template <>
1281 : void
1282 0 : InputParameters::addParam<MultiMooseEnum>(const std::string & /*name*/,
1283 : const std::string & /*doc_string*/)
1284 : {
1285 0 : mooseError("You must supply a MultiMooseEnum object when using addParam, even if the parameter "
1286 : "is not required!");
1287 : }
1288 :
1289 : template <>
1290 : void
1291 0 : InputParameters::addParam<std::vector<MooseEnum>>(const std::string & /*name*/,
1292 : const std::string & /*doc_string*/)
1293 : {
1294 0 : mooseError("You must supply a vector of MooseEnum object(s) when using addParam, even if the "
1295 : "parameter is not required!");
1296 : }
1297 :
1298 : template <>
1299 : void
1300 0 : InputParameters::addParam<std::vector<MultiMooseEnum>>(const std::string & /*name*/,
1301 : const std::string & /*doc_string*/)
1302 : {
1303 0 : mooseError(
1304 : "You must supply a vector of MultiMooseEnum object(s) when using addParam, even if the "
1305 : "parameter is not required!");
1306 : }
1307 :
1308 : template <>
1309 : void
1310 0 : InputParameters::addRequiredParam<std::vector<MultiMooseEnum>>(const std::string & /*name*/,
1311 : const std::string & /*doc_string*/)
1312 : {
1313 0 : mooseError("You must supply a vector of MultiMooseEnum object(s) when using addRequiredParam!");
1314 : }
1315 :
1316 : template <>
1317 : void
1318 0 : InputParameters::addPrivateParam<MooseEnum>(const std::string & /*name*/)
1319 : {
1320 0 : mooseError("You must supply a MooseEnum object when using addPrivateParam, even if the parameter "
1321 : "is not required!");
1322 : }
1323 :
1324 : template <>
1325 : void
1326 0 : InputParameters::addPrivateParam<MultiMooseEnum>(const std::string & /*name*/)
1327 : {
1328 0 : mooseError("You must supply a MultiMooseEnum object when using addPrivateParam, even if the "
1329 : "parameter is not required!");
1330 : }
1331 :
1332 : template <>
1333 : void
1334 0 : InputParameters::addDeprecatedParam<MooseEnum>(const std::string & /*name*/,
1335 : const std::string & /*doc_string*/,
1336 : const std::string & /*deprecation_message*/)
1337 : {
1338 0 : mooseError("You must supply a MooseEnum object and the deprecation string when using "
1339 : "addDeprecatedParam, even if the parameter is not required!");
1340 : }
1341 :
1342 : template <>
1343 : void
1344 0 : InputParameters::addDeprecatedParam<MultiMooseEnum>(const std::string & /*name*/,
1345 : const std::string & /*doc_string*/,
1346 : const std::string & /*deprecation_message*/)
1347 : {
1348 0 : mooseError("You must supply a MultiMooseEnum object and the deprecation string when using "
1349 : "addDeprecatedParam, even if the parameter is not required!");
1350 : }
1351 :
1352 : template <>
1353 : void
1354 0 : InputParameters::addDeprecatedParam<std::vector<MooseEnum>>(
1355 : const std::string & /*name*/,
1356 : const std::string & /*doc_string*/,
1357 : const std::string & /*deprecation_message*/)
1358 : {
1359 0 : mooseError("You must supply a vector of MooseEnum object(s) and the deprecation string when "
1360 : "using addDeprecatedParam, even if the parameter is not required!");
1361 : }
1362 :
1363 : template <>
1364 : void
1365 159065 : InputParameters::setParamHelper<PostprocessorName, Real>(const std::string & /*name*/,
1366 : PostprocessorName & l_value,
1367 : const Real & r_value)
1368 : {
1369 : // Assign the default value so that it appears in the dump
1370 159065 : std::ostringstream oss;
1371 159065 : oss << r_value;
1372 159065 : l_value = oss.str();
1373 159065 : }
1374 :
1375 : template <>
1376 : void
1377 180647 : InputParameters::setParamHelper<PostprocessorName, int>(const std::string & /*name*/,
1378 : PostprocessorName & l_value,
1379 : const int & r_value)
1380 : {
1381 : // Assign the default value so that it appears in the dump
1382 180647 : std::ostringstream oss;
1383 180647 : oss << r_value;
1384 180647 : l_value = oss.str();
1385 180647 : }
1386 :
1387 : template <>
1388 : void
1389 43204 : InputParameters::setParamHelper<FunctionName, Real>(const std::string & /*name*/,
1390 : FunctionName & l_value,
1391 : const Real & r_value)
1392 : {
1393 : // Assign the default value so that it appears in the dump
1394 43204 : std::ostringstream oss;
1395 43204 : oss << r_value;
1396 43204 : l_value = oss.str();
1397 43204 : }
1398 :
1399 : template <>
1400 : void
1401 749597 : InputParameters::setParamHelper<FunctionName, int>(const std::string & /*name*/,
1402 : FunctionName & l_value,
1403 : const int & r_value)
1404 : {
1405 : // Assign the default value so that it appears in the dump
1406 749597 : std::ostringstream oss;
1407 749597 : oss << r_value;
1408 749597 : l_value = oss.str();
1409 749597 : }
1410 :
1411 : template <>
1412 : void
1413 87563 : InputParameters::setParamHelper<MaterialPropertyName, Real>(const std::string & /*name*/,
1414 : MaterialPropertyName & l_value,
1415 : const Real & r_value)
1416 : {
1417 : // Assign the default value so that it appears in the dump
1418 87563 : std::ostringstream oss;
1419 87563 : oss << r_value;
1420 87563 : l_value = oss.str();
1421 87563 : }
1422 :
1423 : template <>
1424 : void
1425 145972 : InputParameters::setParamHelper<MaterialPropertyName, int>(const std::string & /*name*/,
1426 : MaterialPropertyName & l_value,
1427 : const int & r_value)
1428 : {
1429 : // Assign the default value so that it appears in the dump
1430 145972 : std::ostringstream oss;
1431 145972 : oss << r_value;
1432 145972 : l_value = oss.str();
1433 145972 : }
1434 :
1435 : template <>
1436 : void
1437 180036 : InputParameters::setParamHelper<MooseFunctorName, Real>(const std::string & /*name*/,
1438 : MooseFunctorName & l_value,
1439 : const Real & r_value)
1440 : {
1441 : // Assign the default value so that it appears in the dump
1442 180036 : std::ostringstream oss;
1443 180036 : oss << r_value;
1444 180036 : l_value = oss.str();
1445 180036 : }
1446 :
1447 : template <>
1448 : void
1449 331591 : InputParameters::setParamHelper<MooseFunctorName, int>(const std::string & /*name*/,
1450 : MooseFunctorName & l_value,
1451 : const int & r_value)
1452 : {
1453 : // Assign the default value so that it appears in the dump
1454 331591 : std::ostringstream oss;
1455 331591 : oss << r_value;
1456 331591 : l_value = oss.str();
1457 331591 : }
1458 :
1459 : template <>
1460 : const MooseEnum &
1461 1868401 : InputParameters::getParamHelper<MooseEnum>(const std::string & name_in,
1462 : const InputParameters & pars,
1463 : const MooseEnum *,
1464 : const MooseBase * /* = nullptr */)
1465 : {
1466 1868401 : const auto name = pars.checkForRename(name_in);
1467 3736802 : return pars.get<MooseEnum>(name);
1468 1868401 : }
1469 :
1470 : template <>
1471 : const MultiMooseEnum &
1472 124558 : InputParameters::getParamHelper<MultiMooseEnum>(const std::string & name_in,
1473 : const InputParameters & pars,
1474 : const MultiMooseEnum *,
1475 : const MooseBase * /* = nullptr */)
1476 : {
1477 124558 : const auto name = pars.checkForRename(name_in);
1478 249116 : return pars.get<MultiMooseEnum>(name);
1479 124558 : }
1480 :
1481 : void
1482 7117023 : InputParameters::setReservedValues(const std::string & name_in,
1483 : const std::set<std::string> & reserved)
1484 : {
1485 7117023 : const auto name = checkForRename(name_in);
1486 7117023 : _params[name]._reserved_values = reserved;
1487 7117023 : }
1488 :
1489 : std::set<std::string>
1490 6639684 : InputParameters::reservedValues(const std::string & name_in) const
1491 : {
1492 6639684 : const auto name = checkForRename(name_in);
1493 6639684 : auto it = _params.find(name);
1494 6639684 : if (it == _params.end())
1495 0 : return std::set<std::string>();
1496 6639684 : return it->second._reserved_values;
1497 6639684 : }
1498 :
1499 : std::string
1500 36 : InputParameters::blockLocation() const
1501 : {
1502 36 : if (const auto hit_node = getHitNode())
1503 36 : return hit_node->fileLocation(/* with_column = */ false);
1504 0 : return "";
1505 : }
1506 :
1507 : std::string
1508 13700060 : InputParameters::blockFullpath() const
1509 : {
1510 13700060 : if (const auto hit_node = getHitNode())
1511 12676113 : return hit_node->fullpath();
1512 1023947 : return "";
1513 : }
1514 :
1515 : const hit::Node *
1516 4427982 : InputParameters::getHitNode(const std::string & param) const
1517 : {
1518 4427982 : return at(param)._hit_node;
1519 : }
1520 :
1521 : void
1522 2468200 : InputParameters::setHitNode(const std::string & param,
1523 : const hit::Node & node,
1524 : const InputParameters::SetParamHitNodeKey)
1525 : {
1526 : mooseAssert(node.type() == hit::NodeType::Field, "Must be a field");
1527 2468200 : at(param)._hit_node = &node;
1528 2468200 : }
1529 :
1530 : std::string
1531 7264 : InputParameters::inputLocation(const std::string & param) const
1532 : {
1533 7264 : if (const auto hit_node = getHitNode(param))
1534 6986 : return hit_node->fileLocation(/* with_column = */ false);
1535 278 : return "";
1536 : }
1537 :
1538 : std::string
1539 2776 : InputParameters::paramFullpath(const std::string & param) const
1540 : {
1541 2776 : if (const auto hit_node = getHitNode(param))
1542 2774 : return hit_node->fullpath();
1543 2 : return "";
1544 : }
1545 :
1546 : void
1547 1821842659 : InputParameters::checkParamName(const std::string & name) const
1548 : {
1549 1821842659 : const static pcrecpp::RE valid("[\\w:/]+");
1550 1821842659 : if (!valid.FullMatch(name))
1551 3 : mooseError("Invalid parameter name: '", name, "'");
1552 1821842656 : }
1553 :
1554 : bool
1555 52997290 : InputParameters::shouldIgnore(const std::string & name_in)
1556 : {
1557 52997290 : const auto name = checkForRename(name_in);
1558 52997290 : auto it = _params.find(name);
1559 52997290 : if (it != _params.end())
1560 105994580 : return it->second._ignore;
1561 0 : mooseError("Parameter ", name, " does not exist");
1562 52997290 : }
1563 :
1564 : std::set<std::string>
1565 0 : InputParameters::getGroupParameters(const std::string & group) const
1566 : {
1567 0 : std::set<std::string> names;
1568 0 : for (auto it = _params.begin(); it != _params.end(); ++it)
1569 0 : if (it->second._group == group)
1570 0 : names.emplace(it->first);
1571 0 : return names;
1572 0 : }
1573 :
1574 : std::set<std::string>
1575 131 : InputParameters::getParametersList() const
1576 : {
1577 131 : std::set<std::string> param_set;
1578 1843 : for (auto it = _params.begin(); it != _params.end(); ++it)
1579 1712 : param_set.emplace(it->first);
1580 131 : return param_set;
1581 0 : }
1582 :
1583 : std::set<std::string>
1584 5182800 : InputParameters::getControllableParameters() const
1585 : {
1586 5182800 : std::set<std::string> controllable;
1587 139508753 : for (auto it = _params.begin(); it != _params.end(); ++it)
1588 134325953 : if (it->second._controllable)
1589 853869 : controllable.emplace(it->first);
1590 5182800 : return controllable;
1591 0 : }
1592 :
1593 : std::string
1594 2894 : InputParameters::errorPrefix(const std::string & param) const
1595 : {
1596 2894 : auto prefix = param + ":";
1597 2894 : if (!inputLocation(param).empty())
1598 2754 : prefix = inputLocation(param) + ": (" + paramFullpath(param) + ")";
1599 2894 : return prefix;
1600 0 : }
1601 :
1602 : std::string
1603 0 : InputParameters::rawParamVal(const std::string & param) const
1604 : {
1605 0 : if (const auto hit_node = getHitNode(param))
1606 0 : return hit_node->strVal();
1607 0 : return "";
1608 : }
1609 :
1610 : std::string
1611 553826 : InputParameters::varName(const std::string & var_param_name,
1612 : const std::string & moose_object_with_var_param_name) const
1613 : {
1614 : // Try the scalar version first
1615 553826 : std::string variable_name = getMooseType(var_param_name);
1616 553826 : if (variable_name == "")
1617 : {
1618 90635 : auto vec = getVecMooseType(var_param_name);
1619 :
1620 : // Catch the (very unlikely) case where a user specifies
1621 : // variable = '' (the empty string)
1622 : // in their input file. This could happen if e.g. something goes
1623 : // wrong with dollar bracket expression expansion.
1624 90635 : if (vec.empty())
1625 8 : mooseError("Error constructing object '",
1626 : moose_object_with_var_param_name,
1627 : "' while retrieving value for '",
1628 : var_param_name,
1629 : "' parameter! Did you forget to set '",
1630 : var_param_name,
1631 : "' or set it to '' (empty string) by accident?");
1632 :
1633 : // When using vector variables, we are only going to use the first one in the list at the
1634 : // interface level...
1635 90627 : variable_name = vec[0];
1636 90627 : }
1637 :
1638 553818 : return variable_name;
1639 0 : }
1640 :
1641 : void
1642 3262693 : InputParameters::renameParamInternal(const std::string & old_name,
1643 : const std::string & new_name,
1644 : const std::string & docstring,
1645 : const std::string & removal_date)
1646 : {
1647 3262693 : auto params_it = _params.find(old_name);
1648 3262693 : if (params_it == _params.end())
1649 0 : mooseError("Requested to rename parameter '",
1650 : old_name,
1651 : "' but that parameter name doesn't exist in the parameters object.");
1652 : mooseAssert(params_it->second._deprecation_message.empty(),
1653 : "Attempting to rename the parameter, '" << old_name << "', that is deprecated");
1654 :
1655 3262693 : auto new_metadata = std::move(params_it->second);
1656 3262693 : if (!docstring.empty())
1657 364593 : new_metadata._doc_string = docstring;
1658 3262693 : _params.emplace(new_name, std::move(new_metadata));
1659 3262693 : _params.erase(params_it);
1660 :
1661 3262693 : auto values_it = _values.find(old_name);
1662 3262693 : auto new_value = std::move(values_it->second);
1663 3262693 : _values.emplace(new_name, std::move(new_value));
1664 3262693 : _values.erase(values_it);
1665 :
1666 3262693 : std::string deprecation_message;
1667 3262693 : if (!removal_date.empty())
1668 5725692 : deprecation_message = "'" + old_name + "' has been deprecated and will be removed on " +
1669 5725692 : removal_date + ". Please use '" + new_name + "' instead.";
1670 :
1671 3262693 : _old_to_new_name_and_dep.emplace(old_name, std::make_pair(new_name, deprecation_message));
1672 3262693 : _new_to_old_names.emplace(new_name, old_name);
1673 3262693 : }
1674 :
1675 : void
1676 396207 : InputParameters::renameCoupledVarInternal(const std::string & old_name,
1677 : const std::string & new_name,
1678 : const std::string & docstring,
1679 : const std::string & removal_date)
1680 : {
1681 396207 : auto coupled_vars_it = _coupled_vars.find(old_name);
1682 396207 : if (coupled_vars_it == _coupled_vars.end())
1683 0 : mooseError("Requested to rename coupled variable '",
1684 : old_name,
1685 : "' but that coupled variable name doesn't exist in the parameters object.");
1686 :
1687 396207 : _coupled_vars.insert(new_name);
1688 396207 : _coupled_vars.erase(coupled_vars_it);
1689 :
1690 396207 : renameParamInternal(old_name, new_name, docstring, removal_date);
1691 396207 : }
1692 :
1693 : void
1694 241997 : InputParameters::renameParam(const std::string & old_name,
1695 : const std::string & new_name,
1696 : const std::string & new_docstring)
1697 : {
1698 241997 : renameParamInternal(old_name, new_name, new_docstring, "");
1699 241997 : }
1700 :
1701 : void
1702 157850 : InputParameters::renameCoupledVar(const std::string & old_name,
1703 : const std::string & new_name,
1704 : const std::string & new_docstring)
1705 : {
1706 157850 : renameCoupledVarInternal(old_name, new_name, new_docstring, "");
1707 157850 : }
1708 :
1709 : void
1710 2624489 : InputParameters::deprecateParam(const std::string & old_name,
1711 : const std::string & new_name,
1712 : const std::string & removal_date)
1713 : {
1714 2624489 : renameParamInternal(old_name, new_name, "", removal_date);
1715 2624489 : }
1716 :
1717 : void
1718 238357 : InputParameters::deprecateCoupledVar(const std::string & old_name,
1719 : const std::string & new_name,
1720 : const std::string & removal_date)
1721 : {
1722 238357 : renameCoupledVarInternal(old_name, new_name, "", removal_date);
1723 238357 : }
1724 :
1725 : std::string
1726 8457944915 : InputParameters::checkForRename(const std::string & name) const
1727 : {
1728 8457944915 : if (auto it = _old_to_new_name_and_dep.find(name); it != _old_to_new_name_and_dep.end())
1729 305913 : return it->second.first;
1730 : else
1731 8457639002 : return name;
1732 : }
1733 :
1734 : std::vector<std::string>
1735 52994738 : InputParameters::paramAliases(const std::string & param_name) const
1736 : {
1737 : mooseAssert(_values.find(param_name) != _values.end(),
1738 : "The parameter we are searching for aliases for should exist in our parameter map");
1739 105989476 : std::vector<std::string> aliases = {param_name};
1740 :
1741 53171381 : for (const auto & pr : as_range(_new_to_old_names.equal_range(param_name)))
1742 176643 : aliases.push_back(pr.second);
1743 :
1744 52994738 : return aliases;
1745 52994738 : }
1746 :
1747 : std::optional<Moose::DataFileUtils::Path>
1748 12820 : InputParameters::queryDataFileNamePath(const std::string & name) const
1749 : {
1750 25640 : return at(checkForRename(name))._data_file_name_path;
1751 : }
1752 :
1753 : void
1754 0 : InputParameters::callMooseErrorHelper(const MooseBase & moose_base, const std::string & error)
1755 : {
1756 0 : moose_base.callMooseError(error, true);
1757 : }
|