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 159361773 : emptyInputParameters()
31 : {
32 159361773 : InputParameters params;
33 159361773 : return params;
34 : }
35 :
36 159361773 : InputParameters::InputParameters()
37 : : Parameters(),
38 159361773 : _collapse_nesting(false),
39 159361773 : _moose_object_syntax_visibility(true),
40 159361773 : _show_deprecated_message(true),
41 159361773 : _allow_copy(true),
42 159361773 : _hit_node(nullptr),
43 159361773 : _finalized(false)
44 : {
45 159361773 : }
46 :
47 9846081 : InputParameters::InputParameters(const InputParameters & rhs)
48 9846081 : : Parameters(), _show_deprecated_message(true), _allow_copy(true)
49 : {
50 9846081 : *this = rhs;
51 9846077 : }
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 37582985 : InputParameters::addClassDescription(const std::string & doc_string)
83 : {
84 37582985 : _class_description = doc_string;
85 37582985 : }
86 :
87 : void
88 1183102994 : InputParameters::set_attributes(const std::string & name_in, bool inserted_only)
89 : {
90 1183102994 : const auto name = checkForRename(name_in);
91 :
92 1183102994 : if (!inserted_only)
93 : {
94 831966288 : 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 831966288 : metadata._set_by_add_param = false;
102 :
103 : // valid_params don't make sense for MooseEnums
104 831966288 : if (!have_parameter<MooseEnum>(name) && !have_parameter<MultiMooseEnum>(name))
105 793676864 : metadata._valid = true;
106 : }
107 1183102994 : }
108 :
109 : bool
110 2601519 : InputParameters::attemptPrintDeprecated(const std::string & name_in)
111 : {
112 2601519 : const auto name = checkForRename(name_in);
113 2601519 : if (_show_deprecated_message)
114 : {
115 : auto emit_deprecation_message =
116 1318 : [this](const auto & deprecated_name, const auto & deprecation_message)
117 : {
118 : // This is user-facing, no need for a backtrace
119 1318 : const auto current_show_trace = Moose::show_trace;
120 1318 : Moose::show_trace = false;
121 1318 : moose::internal::mooseDeprecatedStream(
122 : Moose::out, false, true, errorPrefix(deprecated_name), ":\n", deprecation_message, "\n");
123 1310 : Moose::show_trace = current_show_trace;
124 1310 : return true;
125 2601519 : };
126 :
127 2601519 : if (_params.count(name) && !libmesh_map_find(_params, name)._deprecation_message.empty())
128 998 : return emit_deprecation_message(name,
129 1996 : "The parameter '" + name + "' is deprecated.\n" +
130 1996 : libmesh_map_find(_params, name)._deprecation_message);
131 2600521 : else if (auto it = _old_to_new_name_and_dep.find(name_in);
132 2600521 : it != _old_to_new_name_and_dep.end() && !it->second.second.empty())
133 320 : return emit_deprecation_message(name_in, it->second.second);
134 : }
135 2600201 : return false;
136 2601511 : }
137 :
138 : std::string
139 1117285 : InputParameters::getClassDescription() const
140 : {
141 1117285 : return _class_description;
142 : }
143 :
144 : InputParameters &
145 11370201 : 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 11370201 : 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 11370197 : Parameters::operator=(rhs);
163 :
164 11370197 : _params = rhs._params;
165 :
166 11370197 : _buildable_types = rhs._buildable_types;
167 11370197 : _buildable_rm_types = rhs._buildable_rm_types;
168 11370197 : _collapse_nesting = rhs._collapse_nesting;
169 11370197 : _moose_object_syntax_visibility = rhs._moose_object_syntax_visibility;
170 11370197 : _coupled_vars = rhs._coupled_vars;
171 11370197 : _new_to_deprecated_coupled_vars = rhs._new_to_deprecated_coupled_vars;
172 11370197 : _allow_copy = rhs._allow_copy;
173 11370197 : _block_fullpath = rhs._block_fullpath;
174 11370197 : _block_location = rhs._block_location;
175 11370197 : _old_to_new_name_and_dep = rhs._old_to_new_name_and_dep;
176 11370197 : _new_to_old_names = rhs._new_to_old_names;
177 11370197 : _hit_node = rhs._hit_node;
178 11370197 : _finalized = false;
179 :
180 11370197 : return *this;
181 : }
182 :
183 : InputParameters &
184 125716065 : InputParameters::operator+=(const InputParameters & rhs)
185 : {
186 125716065 : 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 443013048 : for (auto it = rhs._params.begin(); it != rhs._params.end(); ++it)
191 317296983 : _params[it->first] = it->second;
192 :
193 251432130 : _buildable_types.insert(
194 125716065 : _buildable_types.end(), rhs._buildable_types.begin(), rhs._buildable_types.end());
195 251432130 : _buildable_rm_types.insert(
196 125716065 : _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 125716065 : _coupled_vars.insert(rhs._coupled_vars.begin(), rhs._coupled_vars.end());
200 125716065 : _new_to_deprecated_coupled_vars.insert(rhs._new_to_deprecated_coupled_vars.begin(),
201 : rhs._new_to_deprecated_coupled_vars.end());
202 :
203 125716065 : _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 125716065 : _new_to_old_names.insert(rhs._new_to_old_names.begin(), rhs._new_to_old_names.end());
206 125716065 : return *this;
207 : }
208 :
209 : void
210 6326952 : InputParameters::setDeprecatedVarDocString(const std::string & new_name,
211 : const std::string & doc_string)
212 : {
213 6326952 : auto coupled_vars_it = _new_to_deprecated_coupled_vars.find(new_name);
214 6326952 : 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 6326952 : }
226 :
227 : void
228 345764 : InputParameters::addCoupledVar(const std::string & name, Real value, const std::string & doc_string)
229 : {
230 345764 : addParam<std::vector<VariableName>>(name, doc_string);
231 345764 : _coupled_vars.insert(name);
232 345764 : auto & metadata = _params[name];
233 345764 : metadata._coupled_default.assign(1, value);
234 345764 : metadata._have_coupled_default = true;
235 :
236 : // Set the doc string for any associated deprecated coupled var
237 345764 : setDeprecatedVarDocString(name, doc_string);
238 345764 : }
239 :
240 : void
241 114974 : 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 114974 : addParam<std::vector<VariableName>>(name, doc_string);
247 114974 : _coupled_vars.insert(name);
248 114974 : auto & metadata = _params[name];
249 114974 : metadata._coupled_default = value;
250 114974 : metadata._have_coupled_default = true;
251 :
252 : // Set the doc string for any associated deprecated coupled var
253 114974 : setDeprecatedVarDocString(name, doc_string);
254 114974 : }
255 :
256 : void
257 5866214 : InputParameters::addCoupledVar(const std::string & name, const std::string & doc_string)
258 : {
259 5866214 : addParam<std::vector<VariableName>>(name, doc_string);
260 5866214 : _coupled_vars.insert(name);
261 :
262 : // Set the doc string for any associated deprecated coupled var
263 5866214 : setDeprecatedVarDocString(name, doc_string);
264 5866214 : }
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 4541740 : InputParameters::addRequiredCoupledVar(const std::string & name, const std::string & doc_string)
322 : {
323 4541740 : addRequiredParam<std::vector<VariableName>>(name, doc_string);
324 4541740 : _coupled_vars.insert(name);
325 4541740 : }
326 :
327 : std::string
328 12062229 : InputParameters::getDocString(const std::string & name_in) const
329 : {
330 12062229 : const auto name = checkForRename(name_in);
331 :
332 12062229 : std::string doc_string;
333 12062229 : auto it = _params.find(name);
334 12062229 : if (it != _params.end())
335 993764177 : for (const auto & ch : it->second._doc_string)
336 : {
337 981701948 : if (ch == '\n')
338 0 : doc_string += " ... ";
339 : else
340 981701948 : doc_string += ch;
341 : }
342 :
343 24124458 : return doc_string;
344 12062229 : }
345 :
346 : void
347 4542620 : InputParameters::setDocString(const std::string & name_in, const std::string & doc)
348 : {
349 4542620 : const auto name = checkForRename(name_in);
350 :
351 4542620 : auto it = _params.find(name);
352 4542620 : 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 4542619 : it->second._doc_string = doc;
357 4542620 : }
358 :
359 : std::string
360 7083241 : InputParameters::getDocUnit(const std::string & name_in) const
361 : {
362 7083241 : const auto name = checkForRename(name_in);
363 14166482 : return _params.at(name)._doc_unit;
364 7083241 : }
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 62878588 : InputParameters::isParamRequired(const std::string & name_in) const
375 : {
376 62878588 : const auto name = checkForRename(name_in);
377 125757176 : return _params.count(name) > 0 && _params.at(name)._required;
378 62878588 : }
379 :
380 : void
381 14502 : InputParameters::makeParamNotRequired(const std::string & name_in)
382 : {
383 14502 : const auto name = checkForRename(name_in);
384 :
385 14502 : if (_params.count(name))
386 14500 : _params[name]._required = false;
387 14502 : }
388 :
389 : bool
390 367195279 : InputParameters::isParamValid(const std::string & name_in) const
391 : {
392 367195279 : const auto name = checkForRename(name_in);
393 367195279 : if (have_parameter<MooseEnum>(name))
394 7040678 : return get<MooseEnum>(name).isValid();
395 360154601 : else if (have_parameter<std::vector<MooseEnum>>(name))
396 : {
397 9527 : for (auto it = get<std::vector<MooseEnum>>(name).begin();
398 19204 : it != get<std::vector<MooseEnum>>(name).end();
399 9677 : ++it)
400 9679 : if (!it->isValid())
401 2 : return false;
402 9525 : return true;
403 : }
404 360145074 : else if (have_parameter<MultiMooseEnum>(name))
405 2189830 : return get<MultiMooseEnum>(name).isValid();
406 357955244 : 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 357955003 : else if (have_parameter<ExecFlagEnum>(name))
416 6774163 : return get<ExecFlagEnum>(name).isValid();
417 : else
418 351180840 : return _params.count(name) > 0 && _params.at(name)._valid;
419 367195279 : }
420 :
421 : bool
422 2538895 : InputParameters::isParamSetByAddParam(const std::string & name_in) const
423 : {
424 2538895 : const auto name = checkForRename(name_in);
425 5077790 : return _params.count(name) > 0 && _params.at(name)._set_by_add_param;
426 2538895 : }
427 :
428 : bool
429 6679944 : InputParameters::isParamDeprecated(const std::string & name_in) const
430 : {
431 6679944 : const auto name = checkForRename(name_in);
432 13359888 : return _params.count(name) > 0 && !_params.at(name)._deprecation_message.empty();
433 6679944 : }
434 :
435 : bool
436 2194655 : InputParameters::areAllRequiredParamsValid() const
437 : {
438 33965487 : for (const auto & it : *this)
439 31881151 : if (isParamRequired(it.first) && !isParamValid(it.first))
440 110319 : return false;
441 2084336 : return true;
442 : }
443 :
444 : bool
445 238668989 : InputParameters::isPrivate(const std::string & name_in) const
446 : {
447 238668989 : const auto name = checkForRename(name_in);
448 477337978 : return _params.count(name) > 0 && _params.at(name)._is_private;
449 238668989 : }
450 :
451 : void
452 23712768 : InputParameters::declareControllable(const std::string & input_names,
453 : std::set<ExecFlagType> execute_flags)
454 : {
455 23712768 : std::vector<std::string> names;
456 23712768 : MooseUtils::tokenize<std::string>(input_names, names, 1, " ");
457 47541961 : for (auto & name_in : names)
458 : {
459 23829194 : const auto name = checkForRename(name_in);
460 23829194 : auto map_iter = _params.find(name);
461 23829194 : if (map_iter != _params.end()) // error is handled by checkParams method
462 : {
463 23829193 : map_iter->second._controllable = true;
464 23829193 : 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 23829194 : }
471 23712768 : }
472 :
473 : bool
474 130010099 : InputParameters::isControllable(const std::string & name_in) const
475 : {
476 130010099 : const auto name = checkForRename(name_in);
477 260020198 : return _params.count(name) > 0 && _params.at(name)._controllable;
478 130010099 : }
479 :
480 : const std::set<ExecFlagType> &
481 1417937 : InputParameters::getControllableExecuteOnTypes(const std::string & name_in) const
482 : {
483 1417937 : const auto name = checkForRename(name_in);
484 2835874 : return at(name)._controllable_flags;
485 1417937 : }
486 :
487 : void
488 43122971 : InputParameters::registerBase(const std::string & value)
489 : {
490 43122971 : InputParameters::set<std::string>("_moose_base") = value;
491 43122971 : _params["_moose_base"]._is_private = true;
492 43122971 : }
493 :
494 : std::optional<std::string>
495 176246 : InputParameters::getBase() const
496 : {
497 176246 : if (have_parameter<std::string>("_moose_base"))
498 176246 : return get<std::string>("_moose_base");
499 0 : return {};
500 : }
501 :
502 : void
503 18210333 : InputParameters::registerSystemAttributeName(const std::string & value)
504 : {
505 18210333 : InputParameters::set<std::string>("_moose_warehouse_system_name") = value;
506 18210333 : _params["_moose_warehouse_system_name"]._is_private = true;
507 18210333 : }
508 :
509 : const std::string &
510 310938 : 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 310938 : 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 8232250 : InputParameters::addRelationshipManager(
527 : const std::string & name,
528 : Moose::RelationshipManagerType rm_type,
529 : Moose::RelationshipManagerInputParameterCallback input_parameter_callback)
530 : {
531 8232250 : _buildable_rm_types.emplace_back(name, rm_type, input_parameter_callback);
532 8232250 : }
533 :
534 : const std::vector<std::string> &
535 21345520 : InputParameters::getBuildableTypes() const
536 : {
537 21345520 : return _buildable_types;
538 : }
539 :
540 : const std::vector<std::tuple<std::string,
541 : Moose::RelationshipManagerType,
542 : Moose::RelationshipManagerInputParameterCallback>> &
543 2917852 : InputParameters::getBuildableRelationshipManagerTypes() const
544 : {
545 2917852 : 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 392568 : InputParameters::collapseSyntaxNesting() const
556 : {
557 392568 : 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 450873 : InputParameters::mooseObjectSyntaxVisibility() const
568 : {
569 450873 : 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 5473383 : InputParameters::checkParams(const std::string & parsing_syntax)
593 : {
594 5473383 : std::string parampath = blockFullpath() != "" ? blockFullpath() : parsing_syntax;
595 5473383 : std::ostringstream oss;
596 : // Required parameters
597 143460097 : for (const auto & it : *this)
598 : {
599 137986714 : const auto param_name = checkForRename(it.first);
600 137986714 : 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 137986714 : }
612 :
613 : // Range checked parameters
614 143460097 : for (const auto & it : *this)
615 : {
616 137986714 : std::string long_name(parampath + "/" + it.first);
617 :
618 137986714 : dynamicCastRangeCheck(Real, Real, long_name, it.first, it.second, oss);
619 137986714 : dynamicCastRangeCheck(int, long, long_name, it.first, it.second, oss);
620 137986714 : dynamicCastRangeCheck(long, long, long_name, it.first, it.second, oss);
621 137986714 : dynamicCastRangeCheck(unsigned int, long, long_name, it.first, it.second, oss);
622 137986714 : }
623 :
624 : // Controllable parameters
625 6390732 : for (const auto & param_name : getControllableParameters())
626 : {
627 917349 : if (isPrivate(param_name))
628 2 : oss << inputLocation(param_name) << ": private parameter '" << paramFullpath(param_name)
629 1 : << "' marked controllable";
630 :
631 917349 : checkMooseType(NonlinearVariableName, param_name);
632 917349 : checkMooseType(AuxVariableName, param_name);
633 917349 : checkMooseType(VariableName, param_name);
634 917349 : checkMooseType(BoundaryName, param_name);
635 917349 : checkMooseType(SubdomainName, param_name);
636 917349 : checkMooseType(PostprocessorName, param_name);
637 917349 : checkMooseType(VectorPostprocessorName, param_name);
638 917349 : checkMooseType(UserObjectName, param_name);
639 917349 : checkMooseType(MaterialPropertyName, param_name);
640 5473383 : }
641 :
642 5473383 : if (!oss.str().empty())
643 78 : mooseError(oss.str());
644 5473314 : }
645 :
646 : void
647 5440385 : InputParameters::finalize(const std::string & parsing_syntax)
648 : {
649 : mooseAssert(!isFinalized(), "Already finalized");
650 :
651 5440385 : checkParams(parsing_syntax);
652 :
653 : // Helper for setting the absolute paths for each set file name parameter
654 272245 : 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 253604 : if (value.empty())
658 234963 : return;
659 :
660 18746 : std::filesystem::path value_path = std::string(value);
661 : // Is already absolute, nothing to do
662 18746 : if (value_path.is_absolute())
663 105 : return;
664 :
665 : // The base by which to make things relative to
666 18641 : const auto file_base = getFileBase(param_name);
667 18641 : value = std::filesystem::absolute(file_base / value_path).c_str();
668 5459063 : };
669 :
670 : // Set the absolute path for each file name typed parameter
671 142575801 : 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 137144624 : set_if_filename(FileName);
685 137039168 : set_if_filename(FileNameNoExtension);
686 136913999 : set_if_filename(MeshFileName);
687 136869023 : set_if_filename(MatrixFileName);
688 : #undef set_if_filename
689 : // Set paths for data files
690 136866729 : else if (auto data_file_name =
691 136866729 : dynamic_cast<Parameters::Parameter<DataFileName> *>(param_value.get()))
692 : {
693 190 : Moose::DataFileUtils::Path found_path;
694 190 : std::optional<std::string> error;
695 :
696 : // Catch this so that we can add additional error context if it fails (the param path)
697 190 : const auto throw_on_error_before = Moose::_throw_on_error;
698 190 : Moose::_throw_on_error = true;
699 : try
700 : {
701 206 : 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 190 : Moose::_throw_on_error = throw_on_error_before;
708 :
709 190 : if (error)
710 4 : mooseError(*error);
711 :
712 : // Set the value to the absolute searched path
713 186 : data_file_name->set() = found_path.path;
714 : // And store the path in metadata so that we can dump it later
715 186 : at(param_name)._data_file_name_path = found_path;
716 186 : }
717 : }
718 :
719 5440313 : _finalized = true;
720 5440313 : }
721 :
722 : std::filesystem::path
723 18831 : 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 18831 : const hit::Node * hit_node = nullptr;
729 :
730 : // Context from the individual parameter
731 18831 : if (param_name)
732 18831 : hit_node = getHitNode(*param_name);
733 : // Context from the parameters
734 18831 : if (!hit_node)
735 988 : hit_node = getHitNode();
736 : // No hit node, so use the cwd (no input files)
737 18831 : if (!hit_node)
738 136 : return std::filesystem::current_path();
739 :
740 : // Find any context that isn't command line arguments
741 19218 : while (hit_node && hit_node->filename() == "CLI_ARGS")
742 523 : hit_node = hit_node->parent();
743 :
744 : // Failed to find a node up the tree that isn't a command line argument
745 18695 : 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 37390 : return std::filesystem::absolute(std::filesystem::path(hit_node->filename()).parent_path());
757 : }
758 :
759 : bool
760 2139029 : InputParameters::isRangeChecked(const std::string & param_name) const
761 : {
762 2139029 : const auto name = checkForRename(param_name);
763 4278058 : return !_params.find(name)->second._range_function.empty();
764 2139029 : }
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 2138655 : InputParameters::hasDefault(const std::string & param_name) const
775 : {
776 2138655 : const auto name = checkForRename(param_name);
777 2138655 : if (hasDefaultCoupledValue(name))
778 0 : return true;
779 : // If it has a default, it's already valid
780 2138655 : else if (isParamSetByAddParam(name))
781 2 : return true;
782 2138653 : else if (isParamValid(name))
783 0 : mooseError("No way to know if the parameter '", param_name, "' has a default");
784 : else
785 2138653 : return false;
786 2138655 : }
787 :
788 : bool
789 2272149 : InputParameters::hasCoupledValue(const std::string & coupling_name) const
790 : {
791 2272149 : return _coupled_vars.find(coupling_name) != _coupled_vars.end();
792 : }
793 :
794 : bool
795 9187384 : InputParameters::hasDefaultCoupledValue(const std::string & coupling_name) const
796 : {
797 9193611 : return _params.count(coupling_name) > 0 && _params.at(coupling_name)._have_coupled_default &&
798 9193611 : _coupled_vars.count(coupling_name) > 0;
799 : }
800 :
801 : void
802 983 : InputParameters::defaultCoupledValue(const std::string & coupling_name, Real value, unsigned int i)
803 : {
804 983 : const auto actual_name = checkForRename(coupling_name);
805 983 : _params[actual_name]._coupled_default.resize(i + 1);
806 983 : _params[actual_name]._coupled_default[i] = value;
807 983 : _params[actual_name]._have_coupled_default = true;
808 983 : }
809 :
810 : Real
811 962705 : InputParameters::defaultCoupledValue(const std::string & coupling_name, unsigned int i) const
812 : {
813 962705 : auto value_it = _params.find(coupling_name);
814 :
815 962705 : 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 962705 : return value_it->second._coupled_default.at(i);
825 : }
826 :
827 : unsigned int
828 230348 : InputParameters::numberDefaultCoupledValues(const std::string & coupling_name) const
829 : {
830 230348 : auto value_it = _params.find(coupling_name);
831 230348 : 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 230348 : return value_it->second._coupled_default.size();
836 : }
837 :
838 : std::map<std::string, std::pair<std::string, std::string>>
839 2274349 : InputParameters::getAutoBuildVectors() const
840 : {
841 2274349 : std::map<std::string, std::pair<std::string, std::string>> abv;
842 59481737 : for (auto it = _params.begin(); it != _params.end(); ++it)
843 : {
844 57207388 : if (!it->second._autobuild_vecs.first.empty())
845 2 : abv[it->first] = it->second._autobuild_vecs;
846 : }
847 2274349 : return abv;
848 0 : }
849 :
850 : std::string
851 7084926 : InputParameters::type(const std::string & name_in) const
852 : {
853 7084926 : const auto name = checkForRename(name_in);
854 7084926 : if (!_values.count(name))
855 0 : mooseError("Parameter \"", name, "\" not found.\n\n", *this);
856 :
857 7084926 : if (_coupled_vars.find(name) != _coupled_vars.end())
858 183965 : return "std::vector<VariableName>";
859 6900961 : else if (_params.count(name) > 0 && !_params.at(name)._custom_type.empty())
860 7725 : return _params.at(name)._custom_type;
861 6893236 : return _values.at(name)->type();
862 7084926 : }
863 :
864 : std::string
865 1633674 : InputParameters::getMooseType(const std::string & name_in) const
866 : {
867 1633674 : const auto name = checkForRename(name_in);
868 1633674 : std::string var;
869 :
870 1633674 : if (have_parameter<VariableName>(name))
871 79017 : var = get<VariableName>(name);
872 1554657 : else if (have_parameter<NonlinearVariableName>(name))
873 798843 : var = get<NonlinearVariableName>(name);
874 755814 : else if (have_parameter<LinearVariableName>(name))
875 23201 : var = get<LinearVariableName>(name);
876 732613 : else if (have_parameter<AuxVariableName>(name))
877 449688 : var = get<AuxVariableName>(name);
878 282925 : else if (have_parameter<PostprocessorName>(name))
879 0 : var = get<PostprocessorName>(name);
880 282925 : else if (have_parameter<VectorPostprocessorName>(name))
881 0 : var = get<VectorPostprocessorName>(name);
882 282925 : else if (have_parameter<FunctionName>(name))
883 0 : var = get<FunctionName>(name);
884 282925 : else if (have_parameter<UserObjectName>(name))
885 0 : var = get<UserObjectName>(name);
886 282925 : else if (have_parameter<MaterialPropertyName>(name))
887 0 : var = get<MaterialPropertyName>(name);
888 282925 : else if (have_parameter<std::string>(name))
889 0 : var = get<std::string>(name);
890 :
891 3267348 : return var;
892 1633674 : }
893 :
894 : std::vector<std::string>
895 901893 : InputParameters::getVecMooseType(const std::string & name_in) const
896 : {
897 901893 : const auto name = checkForRename(name_in);
898 901893 : std::vector<std::string> svars;
899 :
900 901893 : if (have_parameter<std::vector<VariableName>>(name))
901 : {
902 901885 : std::vector<VariableName> vars = get<std::vector<VariableName>>(name);
903 901885 : std::copy(vars.begin(), vars.end(), std::back_inserter(svars));
904 901885 : }
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 1803786 : return svars;
927 901893 : }
928 :
929 : void
930 160351987 : InputParameters::addParamNamesToGroup(const std::string & space_delim_names,
931 : const std::string group_name)
932 : {
933 160351987 : std::vector<std::string> elements;
934 160351987 : 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 160351987 : std::set<std::string> param_names;
939 2392778024 : for (const auto & it : *this)
940 2232426037 : param_names.insert(it.first);
941 :
942 524038445 : for (const auto & param_name : elements)
943 363686458 : if (_params.count(param_name) > 0)
944 363686458 : _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 160351987 : }
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 1893002 : InputParameters::setGlobalCommandLineParam(const std::string & name)
963 : {
964 1893002 : auto & cl_data = at(checkForRename(name))._cl_data;
965 1893002 : if (!cl_data)
966 1 : mooseError("InputParameters::setGlobalCommandLineParam: The parameter '",
967 : name,
968 : "' is not a command line parameter");
969 1893001 : cl_data->global = true;
970 1893001 : }
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 9619938 : InputParameters::queryCommandLineMetadata(const std::string & name) const
980 : {
981 9619938 : const auto & cl_data = at(checkForRename(name))._cl_data;
982 9619938 : if (!cl_data)
983 4147812 : return {};
984 5472126 : 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 380927 : InputParameters::commandLineParamSet(const std::string & name, const CommandLineParamSetKey)
1000 : {
1001 380927 : auto & cl_data = at(checkForRename(name))._cl_data;
1002 380927 : if (!cl_data)
1003 1 : mooseError("InputParameters::commandLineParamSet: The parameter '",
1004 : name,
1005 : "' is not a command line parameter");
1006 380926 : cl_data->set_by_command_line = true;
1007 380926 : }
1008 :
1009 : std::string
1010 7083241 : InputParameters::getGroupName(const std::string & param_name_in) const
1011 : {
1012 7083241 : const auto param_name = checkForRename(param_name_in);
1013 7083241 : auto it = _params.find(param_name);
1014 7083241 : if (it != _params.end())
1015 7083241 : return it->second._group;
1016 0 : return std::string();
1017 7083241 : }
1018 :
1019 : void
1020 621073 : 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 621073 : if (exclude.empty() && !getHitNode() && common.getHitNode())
1026 192738 : setHitNode(*common.getHitNode(), {});
1027 :
1028 : // Loop through the common parameters
1029 41607611 : for (const auto & it : common)
1030 : {
1031 : // Common parameter name
1032 40986538 : const std::string & common_name = it.first;
1033 : // Continue to next parameter, if the current is in list of excluded parameters
1034 40986538 : if (std::find(exclude.begin(), exclude.end(), common_name) != exclude.end())
1035 110216 : continue;
1036 :
1037 40876322 : applyParameter(common, common_name, allow_private);
1038 : }
1039 :
1040 : // Loop through the coupled variables
1041 621073 : for (std::set<std::string>::const_iterator it = common.coupledVarsBegin();
1042 622621 : it != common.coupledVarsEnd();
1043 1548 : ++it)
1044 : {
1045 : // Variable name
1046 1548 : const std::string var_name = *it;
1047 :
1048 : // Continue to next variable, if the current is in list of excluded parameters
1049 1548 : if (std::find(exclude.begin(), exclude.end(), var_name) != exclude.end())
1050 0 : continue;
1051 :
1052 1548 : applyCoupledVar(common, var_name);
1053 1548 : }
1054 621073 : }
1055 :
1056 : void
1057 124868 : InputParameters::applySpecificParameters(const InputParameters & common,
1058 : const std::vector<std::string> & include,
1059 : bool allow_private)
1060 : {
1061 : // Loop through the common parameters
1062 2864389 : for (const auto & it : common)
1063 : {
1064 :
1065 : // Common parameter name
1066 2739521 : const std::string & common_name = it.first;
1067 :
1068 : // Continue to next parameter, if the current is not in list of included parameters
1069 2739521 : if (std::find(include.begin(), include.end(), common_name) == include.end())
1070 2372519 : continue;
1071 :
1072 367002 : applyParameter(common, common_name, allow_private);
1073 : }
1074 :
1075 : // Loop through the coupled variables
1076 124868 : for (std::set<std::string>::const_iterator it = common.coupledVarsBegin();
1077 124868 : 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 124868 : }
1090 :
1091 : void
1092 1548 : 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 1548 : _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 1548 : if (hasCoupledValue(var_name))
1101 : {
1102 1544 : 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 1544 : else if (common.hasCoupledValue(var_name))
1111 1544 : addCoupledVar(var_name, common.getDocString(var_name));
1112 : }
1113 :
1114 : // Enable deprecated message printing
1115 1548 : _show_deprecated_message = true;
1116 1548 : }
1117 :
1118 : void
1119 41243432 : 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 41243432 : _show_deprecated_message = false;
1127 :
1128 41243432 : const auto local_name = checkForRename(common_name);
1129 :
1130 : // Extract the properties from the local parameter for the current common parameter name
1131 41243432 : const bool local_exist = _values.find(local_name) != _values.end();
1132 41243432 : const bool local_set = _params.count(local_name) > 0 && !_params[local_name]._set_by_add_param;
1133 41243432 : const bool local_priv = allow_private ? false : isPrivate(local_name);
1134 41243432 : const bool local_valid = isParamValid(local_name);
1135 :
1136 : // Extract the properties from the common parameter
1137 41243432 : const bool common_exist = common._values.find(common_name) != common._values.end();
1138 41243432 : const bool common_priv = allow_private ? false : common.isPrivate(common_name);
1139 41243432 : 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 41243432 : if (local_exist && common_exist && common_valid && (!local_valid || !local_set) &&
1148 10051664 : (!common_priv || !local_priv))
1149 : {
1150 4697275 : remove(local_name);
1151 4697275 : _values[local_name] = common._values.find(common_name)->second->clone();
1152 4697275 : set_attributes(local_name, false);
1153 9394550 : _params[local_name]._set_by_add_param =
1154 4697275 : 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 4697275 : at(local_name)._hit_node = common.getHitNode(common_name);
1159 : }
1160 36546157 : 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 41243431 : _show_deprecated_message = true;
1167 41243432 : }
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 4626635 : InputParameters::isParamSetByUser(const std::string & name_in) const
1179 : {
1180 4626635 : const auto name = checkForRename(name_in);
1181 : // Invalid; for sure not set by the user
1182 4626635 : if (!isParamValid(name))
1183 1234348 : return false;
1184 : // Parameter is not located in the list (called Parameters::set)
1185 3392287 : if (!_params.count(name))
1186 0 : return false;
1187 : // Special case for a command line option, which is a private parameter
1188 3392287 : if (const auto cl_data = queryCommandLineMetadata(name))
1189 3392287 : return cl_data->set_by_command_line;
1190 : // Not a command line option, not set by addParam and not private
1191 2897481 : return !_params.at(name)._set_by_add_param && !_params.at(name)._is_private;
1192 4626635 : }
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 2139035 : InputParameters::getDescription(const std::string & name_in) const
1203 : {
1204 2139035 : const auto name = checkForRename(name_in);
1205 2139035 : auto it = _params.find(name);
1206 2139035 : if (it == _params.end())
1207 0 : mooseError("No parameter exists with the name ", name);
1208 4278070 : return it->second._doc_string;
1209 2139035 : }
1210 :
1211 : template <>
1212 : void
1213 1754275 : InputParameters::addRequiredParam<MooseEnum>(const std::string & name,
1214 : const MooseEnum & moose_enum,
1215 : const std::string & doc_string)
1216 : {
1217 1754275 : InputParameters::set<MooseEnum>(name) = moose_enum; // valid parameter is set by set_attributes
1218 1754275 : auto & metadata = _params[name];
1219 1754275 : metadata._required = true;
1220 1754275 : metadata._doc_string = doc_string;
1221 1754275 : }
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 159230 : 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 159230 : std::ostringstream oss;
1371 159230 : oss << r_value;
1372 159230 : l_value = oss.str();
1373 159230 : }
1374 :
1375 : template <>
1376 : void
1377 182167 : 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 182167 : std::ostringstream oss;
1383 182167 : oss << r_value;
1384 182167 : l_value = oss.str();
1385 182167 : }
1386 :
1387 : template <>
1388 : void
1389 43295 : 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 43295 : std::ostringstream oss;
1395 43295 : oss << r_value;
1396 43295 : l_value = oss.str();
1397 43295 : }
1398 :
1399 : template <>
1400 : void
1401 750139 : 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 750139 : std::ostringstream oss;
1407 750139 : oss << r_value;
1408 750139 : l_value = oss.str();
1409 750139 : }
1410 :
1411 : template <>
1412 : void
1413 87689 : 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 87689 : std::ostringstream oss;
1419 87689 : oss << r_value;
1420 87689 : l_value = oss.str();
1421 87689 : }
1422 :
1423 : template <>
1424 : void
1425 146198 : 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 146198 : std::ostringstream oss;
1431 146198 : oss << r_value;
1432 146198 : l_value = oss.str();
1433 146198 : }
1434 :
1435 : template <>
1436 : void
1437 181176 : 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 181176 : std::ostringstream oss;
1443 181176 : oss << r_value;
1444 181176 : l_value = oss.str();
1445 181176 : }
1446 :
1447 : template <>
1448 : void
1449 331833 : 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 331833 : std::ostringstream oss;
1455 331833 : oss << r_value;
1456 331833 : l_value = oss.str();
1457 331833 : }
1458 :
1459 : template <>
1460 : const MooseEnum &
1461 2080830 : InputParameters::getParamHelper<MooseEnum>(const std::string & name_in,
1462 : const InputParameters & pars,
1463 : const MooseEnum *,
1464 : const MooseBase * /* = nullptr */)
1465 : {
1466 2080830 : const auto name = pars.checkForRename(name_in);
1467 4161660 : return pars.get<MooseEnum>(name);
1468 2080830 : }
1469 :
1470 : template <>
1471 : const MultiMooseEnum &
1472 134370 : InputParameters::getParamHelper<MultiMooseEnum>(const std::string & name_in,
1473 : const InputParameters & pars,
1474 : const MultiMooseEnum *,
1475 : const MooseBase * /* = nullptr */)
1476 : {
1477 134370 : const auto name = pars.checkForRename(name_in);
1478 268740 : return pars.get<MultiMooseEnum>(name);
1479 134370 : }
1480 :
1481 : void
1482 7181048 : InputParameters::setReservedValues(const std::string & name_in,
1483 : const std::set<std::string> & reserved)
1484 : {
1485 7181048 : const auto name = checkForRename(name_in);
1486 7181048 : _params[name]._reserved_values = reserved;
1487 7181048 : }
1488 :
1489 : std::set<std::string>
1490 6664761 : InputParameters::reservedValues(const std::string & name_in) const
1491 : {
1492 6664761 : const auto name = checkForRename(name_in);
1493 6664761 : auto it = _params.find(name);
1494 6664761 : if (it == _params.end())
1495 0 : return std::set<std::string>();
1496 6664761 : return it->second._reserved_values;
1497 6664761 : }
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 14923102 : InputParameters::blockFullpath() const
1509 : {
1510 14923102 : if (const auto hit_node = getHitNode())
1511 13817982 : return hit_node->fullpath();
1512 1105120 : return "";
1513 : }
1514 :
1515 : const hit::Node *
1516 4996564 : InputParameters::getHitNode(const std::string & param) const
1517 : {
1518 4996564 : return at(param)._hit_node;
1519 : }
1520 :
1521 : void
1522 2663675 : 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 2663675 : at(param)._hit_node = &node;
1528 2663675 : }
1529 :
1530 : std::string
1531 7546 : InputParameters::inputLocation(const std::string & param) const
1532 : {
1533 7546 : if (const auto hit_node = getHitNode(param))
1534 7220 : return hit_node->fileLocation(/* with_column = */ false);
1535 326 : return "";
1536 : }
1537 :
1538 : std::string
1539 2880 : InputParameters::paramFullpath(const std::string & param) const
1540 : {
1541 2880 : if (const auto hit_node = getHitNode(param))
1542 2878 : return hit_node->fullpath();
1543 2 : return "";
1544 : }
1545 :
1546 : void
1547 1867453816 : InputParameters::checkParamName(const std::string & name) const
1548 : {
1549 1867453816 : const static pcrecpp::RE valid("[\\w:/]+");
1550 1867453816 : if (!valid.FullMatch(name))
1551 3 : mooseError("Invalid parameter name: '", name, "'");
1552 1867453813 : }
1553 :
1554 : bool
1555 57209102 : InputParameters::shouldIgnore(const std::string & name_in)
1556 : {
1557 57209102 : const auto name = checkForRename(name_in);
1558 57209102 : auto it = _params.find(name);
1559 57209102 : if (it != _params.end())
1560 114418204 : return it->second._ignore;
1561 0 : mooseError("Parameter ", name, " does not exist");
1562 57209102 : }
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 193 : InputParameters::getParametersList() const
1576 : {
1577 193 : std::set<std::string> param_set;
1578 2424 : for (auto it = _params.begin(); it != _params.end(); ++it)
1579 2231 : param_set.emplace(it->first);
1580 193 : return param_set;
1581 0 : }
1582 :
1583 : std::set<std::string>
1584 5622267 : InputParameters::getControllableParameters() const
1585 : {
1586 5622267 : std::set<std::string> controllable;
1587 151394947 : for (auto it = _params.begin(); it != _params.end(); ++it)
1588 145772680 : if (it->second._controllable)
1589 918930 : controllable.emplace(it->first);
1590 5622267 : return controllable;
1591 0 : }
1592 :
1593 : std::string
1594 3022 : InputParameters::errorPrefix(const std::string & param) const
1595 : {
1596 3022 : auto prefix = param + ":";
1597 3022 : if (!inputLocation(param).empty())
1598 2858 : prefix = inputLocation(param) + ": (" + paramFullpath(param) + ")";
1599 3022 : 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 595155 : 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 595155 : std::string variable_name = getMooseType(var_param_name);
1616 595155 : if (variable_name == "")
1617 : {
1618 97188 : 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 97188 : 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 97180 : variable_name = vec[0];
1636 97180 : }
1637 :
1638 595147 : return variable_name;
1639 0 : }
1640 :
1641 : void
1642 3385489 : 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 3385489 : auto params_it = _params.find(old_name);
1648 3385489 : 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 3385489 : auto new_metadata = std::move(params_it->second);
1656 3385489 : if (!docstring.empty())
1657 380480 : new_metadata._doc_string = docstring;
1658 3385489 : _params.emplace(new_name, std::move(new_metadata));
1659 3385489 : _params.erase(params_it);
1660 :
1661 3385489 : auto values_it = _values.find(old_name);
1662 3385489 : auto new_value = std::move(values_it->second);
1663 3385489 : _values.emplace(new_name, std::move(new_value));
1664 3385489 : _values.erase(values_it);
1665 :
1666 3385489 : std::string deprecation_message;
1667 3385489 : if (!removal_date.empty())
1668 5938514 : deprecation_message = "'" + old_name + "' has been deprecated and will be removed on " +
1669 5938514 : removal_date + ". Please use '" + new_name + "' instead.";
1670 :
1671 3385489 : _old_to_new_name_and_dep.emplace(old_name, std::make_pair(new_name, deprecation_message));
1672 3385489 : _new_to_old_names.emplace(new_name, old_name);
1673 3385489 : }
1674 :
1675 : void
1676 397073 : 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 397073 : auto coupled_vars_it = _coupled_vars.find(old_name);
1682 397073 : 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 397073 : _coupled_vars.insert(new_name);
1688 397073 : _coupled_vars.erase(coupled_vars_it);
1689 :
1690 397073 : renameParamInternal(old_name, new_name, docstring, removal_date);
1691 397073 : }
1692 :
1693 : void
1694 258326 : InputParameters::renameParam(const std::string & old_name,
1695 : const std::string & new_name,
1696 : const std::string & new_docstring)
1697 : {
1698 258326 : renameParamInternal(old_name, new_name, new_docstring, "");
1699 258326 : }
1700 :
1701 : void
1702 157906 : InputParameters::renameCoupledVar(const std::string & old_name,
1703 : const std::string & new_name,
1704 : const std::string & new_docstring)
1705 : {
1706 157906 : renameCoupledVarInternal(old_name, new_name, new_docstring, "");
1707 157906 : }
1708 :
1709 : void
1710 2730090 : InputParameters::deprecateParam(const std::string & old_name,
1711 : const std::string & new_name,
1712 : const std::string & removal_date)
1713 : {
1714 2730090 : renameParamInternal(old_name, new_name, "", removal_date);
1715 2730090 : }
1716 :
1717 : void
1718 239167 : InputParameters::deprecateCoupledVar(const std::string & old_name,
1719 : const std::string & new_name,
1720 : const std::string & removal_date)
1721 : {
1722 239167 : renameCoupledVarInternal(old_name, new_name, "", removal_date);
1723 239167 : }
1724 :
1725 : std::string
1726 8908091366 : InputParameters::checkForRename(const std::string & name) const
1727 : {
1728 8908091366 : if (auto it = _old_to_new_name_and_dep.find(name); it != _old_to_new_name_and_dep.end())
1729 329750 : return it->second.first;
1730 : else
1731 8907761616 : return name;
1732 : }
1733 :
1734 : std::vector<std::string>
1735 57206350 : 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 114412700 : std::vector<std::string> aliases = {param_name};
1740 :
1741 57397119 : for (const auto & pr : as_range(_new_to_old_names.equal_range(param_name)))
1742 190769 : aliases.push_back(pr.second);
1743 :
1744 57206350 : return aliases;
1745 57206350 : }
1746 :
1747 : std::optional<Moose::DataFileUtils::Path>
1748 12840 : InputParameters::queryDataFileNamePath(const std::string & name) const
1749 : {
1750 25680 : 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 : }
|