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 : #include "MooseApp.h"
20 :
21 : #include "libmesh/utility.h"
22 : #include "libmesh/simple_range.h"
23 :
24 : #include "pcrecpp.h"
25 : #include "hit/parse.h"
26 :
27 : #include <cmath>
28 : #include <filesystem>
29 :
30 : InputParameters
31 188761633 : emptyInputParameters()
32 : {
33 188761633 : InputParameters params;
34 188761633 : return params;
35 : }
36 :
37 188761633 : InputParameters::InputParameters()
38 : : Parameters(),
39 188761633 : _collapse_nesting(false),
40 188761633 : _moose_object_syntax_visibility(true),
41 188761633 : _show_deprecated_message(true),
42 188761633 : _allow_copy(true),
43 188761633 : _hit_node(nullptr),
44 188761633 : _finalized(false)
45 : {
46 188761633 : }
47 :
48 8886682 : InputParameters::InputParameters(const InputParameters & rhs)
49 8886682 : : Parameters(), _show_deprecated_message(true), _allow_copy(true)
50 : {
51 8886682 : *this = rhs;
52 8886678 : }
53 :
54 0 : InputParameters::InputParameters(const Parameters & rhs)
55 0 : : _show_deprecated_message(true), _allow_copy(true)
56 : {
57 0 : _params.clear();
58 0 : Parameters::operator=(rhs);
59 0 : _collapse_nesting = false;
60 0 : _moose_object_syntax_visibility = true;
61 0 : }
62 :
63 : void
64 0 : InputParameters::clear()
65 : {
66 0 : Parameters::clear();
67 0 : _params.clear();
68 0 : _coupled_vars.clear();
69 0 : _new_to_deprecated_coupled_vars.clear();
70 0 : _collapse_nesting = false;
71 0 : _moose_object_syntax_visibility = true;
72 0 : _show_deprecated_message = true;
73 0 : _allow_copy = true;
74 0 : _old_to_new_name_and_dep.clear();
75 0 : _new_to_old_names.clear();
76 0 : _hit_node = nullptr;
77 0 : _finalized = false;
78 0 : }
79 :
80 : void
81 39980250 : InputParameters::addClassDescription(const std::string & doc_string)
82 : {
83 39980250 : _class_description = doc_string;
84 39980250 : }
85 :
86 : void
87 1285392454 : InputParameters::set_attributes(const std::string & name_in, bool inserted_only)
88 : {
89 1285392454 : const auto name = checkForRename(name_in);
90 :
91 1285392454 : if (!inserted_only)
92 : {
93 897706490 : auto & metadata = _params[name];
94 : /**
95 : * "._set_by_add_param" and ".deprecated_params" are not populated until after
96 : * the default value has already been set in libMesh (first callback to this
97 : * method). Therefore if a variable is in/not in one of these sets, you can
98 : * be assured it was put there outside of the "addParam*()" calls.
99 : */
100 897706490 : metadata._set_by_add_param = false;
101 :
102 : // valid_params don't make sense for MooseEnums
103 897706490 : if (!have_parameter<MooseEnum>(name) && !have_parameter<MultiMooseEnum>(name))
104 847961393 : metadata._valid = true;
105 : }
106 1285392454 : }
107 :
108 : std::optional<std::string>
109 2716818 : InputParameters::queryDeprecatedParamMessage(const std::string & name_in) const
110 : {
111 2716818 : const auto name = checkForRename(name_in);
112 2716818 : if (_show_deprecated_message)
113 : {
114 1786 : auto deprecation_message = [this](const auto & name, const auto & message) -> std::string
115 1786 : { return paramMessagePrefix(name) + message; };
116 :
117 2716818 : if (_params.count(name) && !libmesh_map_find(_params, name)._deprecation_message.empty())
118 2878 : return deprecation_message(name,
119 2878 : "The parameter '" + name + "' is deprecated.\n" +
120 2878 : libmesh_map_find(_params, name)._deprecation_message);
121 2715379 : else if (auto it = _old_to_new_name_and_dep.find(name_in);
122 2715379 : it != _old_to_new_name_and_dep.end() && !it->second.second.empty())
123 347 : return deprecation_message(name_in, it->second.second);
124 : }
125 2715032 : return {};
126 2716818 : }
127 :
128 : std::string
129 1206038 : InputParameters::getClassDescription() const
130 : {
131 1206038 : return _class_description;
132 : }
133 :
134 : InputParameters &
135 10459291 : InputParameters::operator=(const InputParameters & rhs)
136 : {
137 : // An error to help minimize the segmentation faults that occure when MooseObjects do not have the
138 : // correct constructor
139 10459291 : if (!rhs._allow_copy)
140 : {
141 : // If _allow_parameter_copy is set, these should be too (see
142 : // InputParameterWarehouse::addInputParameters)
143 4 : const std::string & name = rhs.getObjectName();
144 4 : const std::string & type = rhs.getObjectType(); // could be empty
145 4 : const std::string name_example = type.size() ? type : "the " + name + " object";
146 4 : const std::string type_example = type.size() ? type : "MyObject";
147 4 : ::mooseError(
148 : "Copying of the InputParameters object for ",
149 : name_example,
150 : " is not allowed.\n\nThe likely cause for this error ",
151 : "is having a constructor that does not use a const reference, all constructors\nfor "
152 : "MooseObject based classes should be as follows:\n\n",
153 : " ",
154 : type_example,
155 : "::",
156 : type_example,
157 : "(const InputParameters & parameters);");
158 0 : }
159 :
160 10459287 : Parameters::operator=(rhs);
161 :
162 10459287 : _params = rhs._params;
163 :
164 10459287 : _buildable_types = rhs._buildable_types;
165 10459287 : _buildable_rm_types = rhs._buildable_rm_types;
166 10459287 : _collapse_nesting = rhs._collapse_nesting;
167 10459287 : _moose_object_syntax_visibility = rhs._moose_object_syntax_visibility;
168 10459287 : _coupled_vars = rhs._coupled_vars;
169 10459287 : _new_to_deprecated_coupled_vars = rhs._new_to_deprecated_coupled_vars;
170 10459287 : _allow_copy = rhs._allow_copy;
171 10459287 : _old_to_new_name_and_dep = rhs._old_to_new_name_and_dep;
172 10459287 : _new_to_old_names = rhs._new_to_old_names;
173 10459287 : _hit_node = rhs._hit_node;
174 10459287 : _finalized = false;
175 :
176 10459287 : return *this;
177 : }
178 :
179 : InputParameters &
180 153185045 : InputParameters::operator+=(const InputParameters & rhs)
181 : {
182 153185045 : Parameters::operator+=(rhs);
183 :
184 : // TODO: this is not a proper merge - if a particular parameter exists in both this and rhs,
185 : // then we should actually smartly merge both metadata structs before storing in this.
186 516204391 : for (auto it = rhs._params.begin(); it != rhs._params.end(); ++it)
187 363019346 : _params[it->first] = it->second;
188 :
189 306370090 : _buildable_types.insert(
190 153185045 : _buildable_types.end(), rhs._buildable_types.begin(), rhs._buildable_types.end());
191 306370090 : _buildable_rm_types.insert(
192 153185045 : _buildable_rm_types.end(), rhs._buildable_rm_types.begin(), rhs._buildable_rm_types.end());
193 :
194 : // Collapse nesting and moose object syntax hiding are not modified with +=
195 153185045 : _coupled_vars.insert(rhs._coupled_vars.begin(), rhs._coupled_vars.end());
196 153185045 : _new_to_deprecated_coupled_vars.insert(rhs._new_to_deprecated_coupled_vars.begin(),
197 : rhs._new_to_deprecated_coupled_vars.end());
198 :
199 153185045 : _old_to_new_name_and_dep.insert(rhs._old_to_new_name_and_dep.begin(),
200 : rhs._old_to_new_name_and_dep.end());
201 153185045 : _new_to_old_names.insert(rhs._new_to_old_names.begin(), rhs._new_to_old_names.end());
202 153185045 : return *this;
203 : }
204 :
205 : void
206 6896418 : InputParameters::setDeprecatedVarDocString(const std::string & new_name,
207 : const std::string & doc_string)
208 : {
209 6896418 : auto coupled_vars_it = _new_to_deprecated_coupled_vars.find(new_name);
210 6896418 : if (coupled_vars_it != _new_to_deprecated_coupled_vars.end())
211 : {
212 0 : auto params_it = _params.find(coupled_vars_it->second);
213 0 : if (params_it == _params.end())
214 0 : mooseError("There must have been a mistake in the construction of the new to deprecated "
215 : "coupled vars map because the old name ",
216 0 : coupled_vars_it->second,
217 : " doesn't exist in the parameters data.");
218 :
219 0 : params_it->second._doc_string = doc_string;
220 : }
221 6896418 : }
222 :
223 : void
224 367028 : InputParameters::addCoupledVar(const std::string & name, Real value, const std::string & doc_string)
225 : {
226 367028 : addParam<std::vector<VariableName>>(name, doc_string);
227 367028 : _coupled_vars.insert(name);
228 367028 : auto & metadata = _params[name];
229 367028 : metadata._coupled_default.assign(1, value);
230 367028 : metadata._have_coupled_default = true;
231 :
232 : // Set the doc string for any associated deprecated coupled var
233 367028 : setDeprecatedVarDocString(name, doc_string);
234 367028 : }
235 :
236 : void
237 118826 : InputParameters::addCoupledVar(const std::string & name,
238 : const std::vector<Real> & value,
239 : const std::string & doc_string)
240 : {
241 : // std::vector<VariableName>(1, Moose::stringify(value)),
242 118826 : addParam<std::vector<VariableName>>(name, doc_string);
243 118826 : _coupled_vars.insert(name);
244 118826 : auto & metadata = _params[name];
245 118826 : metadata._coupled_default = value;
246 118826 : metadata._have_coupled_default = true;
247 :
248 : // Set the doc string for any associated deprecated coupled var
249 118826 : setDeprecatedVarDocString(name, doc_string);
250 118826 : }
251 :
252 : void
253 6410564 : InputParameters::addCoupledVar(const std::string & name, const std::string & doc_string)
254 : {
255 6410564 : addParam<std::vector<VariableName>>(name, doc_string);
256 6410564 : _coupled_vars.insert(name);
257 :
258 : // Set the doc string for any associated deprecated coupled var
259 6410564 : setDeprecatedVarDocString(name, doc_string);
260 6410564 : }
261 :
262 : void
263 0 : InputParameters::addDeprecatedCoupledVar(const std::string & old_name,
264 : const std::string & new_name,
265 : const std::string & removal_date /*=""*/)
266 : {
267 0 : mooseDeprecated("Please use 'deprecateCoupledVar'");
268 :
269 0 : _show_deprecated_message = false;
270 :
271 : // Set the doc string if we are adding the deprecated var after the new var has already been added
272 0 : auto params_it = _params.find(new_name);
273 0 : std::string doc_string;
274 0 : if (params_it != _params.end())
275 0 : doc_string = params_it->second._doc_string;
276 :
277 0 : addParam<std::vector<VariableName>>(old_name, doc_string);
278 0 : _coupled_vars.insert(old_name);
279 0 : _new_to_deprecated_coupled_vars.emplace(new_name, old_name);
280 :
281 : std::string deprecation_message =
282 0 : "The coupled variable parameter '" + old_name + "' has been deprecated";
283 0 : if (!removal_date.empty())
284 0 : deprecation_message += " and will be removed " + removal_date;
285 0 : deprecation_message += ". Please use the '" + new_name + "' coupled variable parameter instead.";
286 0 : _params[old_name]._deprecation_message = deprecation_message;
287 0 : _show_deprecated_message = true;
288 0 : }
289 :
290 : void
291 4 : InputParameters::addCoupledVarWithAutoBuild(const std::string & name,
292 : const std::string & base_name,
293 : const std::string & num_name,
294 : const std::string & doc_string)
295 : {
296 4 : addParam<std::vector<VariableName>>(name, doc_string);
297 4 : _coupled_vars.insert(name);
298 4 : _params[name]._autobuild_vecs = std::make_pair(base_name, num_name);
299 :
300 : // Additionally there are two more parameters that need to be added:
301 4 : addParam<std::string>(base_name, doc_string + " (base_name)");
302 4 : addParam<unsigned int>(num_name, doc_string + " (num_name)");
303 4 : }
304 :
305 : void
306 4 : InputParameters::addRequiredCoupledVarWithAutoBuild(const std::string & name,
307 : const std::string & base_name,
308 : const std::string & num_name,
309 : const std::string & doc_string)
310 : {
311 4 : addRequiredParam<std::vector<VariableName>>(name, doc_string);
312 :
313 4 : addCoupledVarWithAutoBuild(name, base_name, num_name, doc_string);
314 4 : }
315 :
316 : void
317 4829923 : InputParameters::addRequiredCoupledVar(const std::string & name, const std::string & doc_string)
318 : {
319 4829923 : addRequiredParam<std::vector<VariableName>>(name, doc_string);
320 4829923 : _coupled_vars.insert(name);
321 4829923 : }
322 :
323 : std::string
324 13646461 : InputParameters::getDocString(const std::string & name_in) const
325 : {
326 13646461 : const auto name = checkForRename(name_in);
327 :
328 13646461 : std::string doc_string;
329 13646461 : auto it = _params.find(name);
330 13646461 : if (it != _params.end())
331 1278706938 : for (const auto & ch : it->second._doc_string)
332 : {
333 1265060477 : if (ch == '\n')
334 0 : doc_string += " ... ";
335 : else
336 1265060477 : doc_string += ch;
337 : }
338 :
339 27292922 : return doc_string;
340 13646461 : }
341 :
342 : void
343 4704179 : InputParameters::setDocString(const std::string & name_in, const std::string & doc)
344 : {
345 4704179 : const auto name = checkForRename(name_in);
346 :
347 4704179 : auto it = _params.find(name);
348 4704179 : if (it == _params.end())
349 2 : mooseError("Unable to set the documentation string (using setDocString) for the \"",
350 : name,
351 : "\" parameter, the parameter does not exist.");
352 4704177 : it->second._doc_string = doc;
353 4704179 : }
354 :
355 : std::string
356 8506101 : InputParameters::getDocUnit(const std::string & name_in) const
357 : {
358 8506101 : const auto name = checkForRename(name_in);
359 17012202 : return _params.at(name)._doc_unit;
360 8506101 : }
361 :
362 : void
363 0 : InputParameters::setDocUnit(const std::string & name_in, const std::string & doc_unit)
364 : {
365 0 : const auto name = checkForRename(name_in);
366 0 : _params[name]._doc_unit = doc_unit;
367 0 : }
368 :
369 : bool
370 66215340 : InputParameters::isParamRequired(const std::string & name_in) const
371 : {
372 66215340 : const auto name = checkForRename(name_in);
373 132430680 : return _params.count(name) > 0 && _params.at(name)._required;
374 66215340 : }
375 :
376 : void
377 29831 : InputParameters::makeParamNotRequired(const std::string & name_in)
378 : {
379 29831 : const auto name = checkForRename(name_in);
380 :
381 29831 : if (_params.count(name))
382 29827 : _params[name]._required = false;
383 29831 : }
384 :
385 : bool
386 378375069 : InputParameters::isParamValid(const std::string & name_in) const
387 : {
388 378375069 : const auto name = checkForRename(name_in);
389 378375069 : if (have_parameter<MooseEnum>(name))
390 7447575 : return get<MooseEnum>(name).isValid();
391 370927494 : else if (have_parameter<std::vector<MooseEnum>>(name))
392 : {
393 12793 : for (auto it = get<std::vector<MooseEnum>>(name).begin();
394 26179 : it != get<std::vector<MooseEnum>>(name).end();
395 13386 : ++it)
396 13390 : if (!it->isValid())
397 4 : return false;
398 12789 : return true;
399 : }
400 370914701 : else if (have_parameter<MultiMooseEnum>(name))
401 1946670 : return get<MultiMooseEnum>(name).isValid();
402 368968031 : else if (have_parameter<std::vector<MultiMooseEnum>>(name))
403 : {
404 345 : for (auto it = get<std::vector<MultiMooseEnum>>(name).begin();
405 609 : it != get<std::vector<MultiMooseEnum>>(name).end();
406 264 : ++it)
407 543 : if (!it->isValid())
408 279 : return false;
409 66 : return true;
410 : }
411 368967686 : else if (have_parameter<ExecFlagEnum>(name))
412 6991210 : return get<ExecFlagEnum>(name).isValid();
413 : else
414 361976476 : return _params.count(name) > 0 && _params.at(name)._valid;
415 378375069 : }
416 :
417 : bool
418 2611034 : InputParameters::isParamSetByAddParam(const std::string & name_in) const
419 : {
420 2611034 : const auto name = checkForRename(name_in);
421 5222068 : return _params.count(name) > 0 && _params.at(name)._set_by_add_param;
422 2611034 : }
423 :
424 : bool
425 8041461 : InputParameters::isParamDeprecated(const std::string & name_in) const
426 : {
427 8041461 : const auto name = checkForRename(name_in);
428 16082922 : return _params.count(name) > 0 && !_params.at(name)._deprecation_message.empty();
429 8041461 : }
430 :
431 : bool
432 2282616 : InputParameters::areAllRequiredParamsValid() const
433 : {
434 38555502 : for (const auto & it : *this)
435 36386667 : if (isParamRequired(it.first) && !isParamValid(it.first))
436 113781 : return false;
437 2168835 : return true;
438 : }
439 :
440 : bool
441 220704854 : InputParameters::isPrivate(const std::string & name_in) const
442 : {
443 220704854 : const auto name = checkForRename(name_in);
444 441409708 : return _params.count(name) > 0 && _params.at(name)._is_private;
445 220704854 : }
446 :
447 : void
448 25381306 : InputParameters::declareControllable(const std::string & input_names,
449 : std::set<ExecFlagType> execute_flags)
450 : {
451 25381306 : std::vector<std::string> names;
452 25381306 : MooseUtils::tokenize<std::string>(input_names, names, 1, " ");
453 50897959 : for (auto & name_in : names)
454 : {
455 25516655 : const auto name = checkForRename(name_in);
456 25516655 : auto map_iter = _params.find(name);
457 25516655 : if (map_iter != _params.end()) // error is handled by checkParams method
458 : {
459 25516653 : map_iter->second._controllable = true;
460 25516653 : map_iter->second._controllable_flags = execute_flags;
461 : }
462 : else
463 2 : mooseError("The input parameter '",
464 : name,
465 : "' does not exist, thus cannot be marked as controllable.");
466 25516655 : }
467 25381306 : }
468 :
469 : bool
470 142286932 : InputParameters::isControllable(const std::string & name_in) const
471 : {
472 142286932 : const auto name = checkForRename(name_in);
473 284573864 : return _params.count(name) > 0 && _params.at(name)._controllable;
474 142286932 : }
475 :
476 : const std::set<ExecFlagType> &
477 1470134 : InputParameters::getControllableExecuteOnTypes(const std::string & name_in) const
478 : {
479 1470134 : const auto name = checkForRename(name_in);
480 2940268 : return at(name)._controllable_flags;
481 1470134 : }
482 :
483 : void
484 46059029 : InputParameters::registerBase(const std::string & value)
485 : {
486 46059029 : InputParameters::set<std::string>(MooseBase::moose_base_param) = value;
487 46059029 : _params[MooseBase::moose_base_param]._is_private = true;
488 46059029 : }
489 :
490 : bool
491 25102575 : InputParameters::hasBase() const
492 : {
493 25102575 : return have_parameter<std::string>(MooseBase::moose_base_param);
494 : }
495 :
496 : const std::string &
497 31677367 : InputParameters::getBase() const
498 : {
499 31677367 : if (!have_parameter<std::string>(MooseBase::moose_base_param))
500 0 : mooseError("InputParameters::getBase(): Parameters do not have base; one needs to be set with "
501 : "registerBase()");
502 31677367 : return get<std::string>(MooseBase::moose_base_param);
503 : }
504 :
505 : void
506 19108165 : InputParameters::registerSystemAttributeName(const std::string & value)
507 : {
508 19108165 : InputParameters::set<std::string>("_moose_warehouse_system_name") = value;
509 38216330 : _params["_moose_warehouse_system_name"]._is_private = true;
510 19108165 : }
511 :
512 : const std::string &
513 319683 : InputParameters::getSystemAttributeName() const
514 : {
515 : mooseAssert(have_parameter<std::string>("_moose_warehouse_system_name"),
516 : "SystemAttributeName is not available! Call 'registerSystemAttributeName' (usually "
517 : "in the validParams function) before you try accessing it!");
518 319683 : return Parameters::get<std::string>("_moose_warehouse_system_name");
519 : }
520 :
521 : void
522 0 : InputParameters::registerBuildableTypes(const std::string & names)
523 : {
524 0 : _buildable_types.clear();
525 0 : MooseUtils::tokenize(names, _buildable_types, 1, " \t\n\v\f\r"); // tokenize on whitespace
526 0 : }
527 :
528 : void
529 8682357 : InputParameters::addRelationshipManager(
530 : const std::string & name,
531 : Moose::RelationshipManagerType rm_type,
532 : Moose::RelationshipManagerInputParameterCallback input_parameter_callback)
533 : {
534 8682357 : _buildable_rm_types.emplace_back(name, rm_type, input_parameter_callback);
535 8682357 : }
536 :
537 : const std::vector<std::string> &
538 22872602 : InputParameters::getBuildableTypes() const
539 : {
540 22872602 : return _buildable_types;
541 : }
542 :
543 : const std::vector<std::tuple<std::string,
544 : Moose::RelationshipManagerType,
545 : Moose::RelationshipManagerInputParameterCallback>> &
546 3012959 : InputParameters::getBuildableRelationshipManagerTypes() const
547 : {
548 3012959 : return _buildable_rm_types;
549 : }
550 :
551 : void
552 0 : InputParameters::collapseSyntaxNesting(bool collapse)
553 : {
554 0 : _collapse_nesting = collapse;
555 0 : }
556 :
557 : bool
558 464880 : InputParameters::collapseSyntaxNesting() const
559 : {
560 464880 : return _collapse_nesting;
561 : }
562 :
563 : void
564 0 : InputParameters::mooseObjectSyntaxVisibility(bool visibility)
565 : {
566 0 : _moose_object_syntax_visibility = visibility;
567 0 : }
568 :
569 : bool
570 524311 : InputParameters::mooseObjectSyntaxVisibility() const
571 : {
572 524311 : return _moose_object_syntax_visibility;
573 : }
574 :
575 : #define checkMooseType(param_type, name) \
576 : if (have_parameter<param_type>(name) || have_parameter<std::vector<param_type>>(name)) \
577 : error = "non-controllable type '" + type(name) + "' for parameter '" + \
578 : paramFullpath(param_name) + "' marked controllable";
579 :
580 : void
581 5665255 : InputParameters::checkParams(const std::string & parsing_syntax)
582 : {
583 5665255 : const std::string parampath = blockFullpath() != "" ? blockFullpath() : parsing_syntax;
584 :
585 : // Required parameters
586 5665255 : std::vector<std::string> required_param_errors;
587 148447750 : for (const auto & it : *this)
588 : {
589 142782495 : const auto param_name = checkForRename(it.first);
590 142782495 : if (!isParamValid(param_name) && isParamRequired(param_name))
591 : {
592 : // check if an old, deprecated name exists for this parameter that may be specified
593 36 : auto oit = _new_to_deprecated_coupled_vars.find(param_name);
594 36 : if (oit != _new_to_deprecated_coupled_vars.end() && isParamValid(oit->second))
595 0 : continue;
596 :
597 108 : required_param_errors.push_back("missing required parameter '" + parampath + "/" +
598 72 : param_name + "'\n\tDoc String: \"" +
599 144 : getDocString(param_name) + "\"");
600 : }
601 142782495 : }
602 :
603 5665255 : if (required_param_errors.size())
604 36 : mooseError(MooseUtils::stringJoin(required_param_errors, "\n"));
605 :
606 : // Range checked parameters
607 148446400 : for (const auto & [name, param_ptr] : *this)
608 : {
609 142781183 : if (const auto error = parameterRangeCheck(*param_ptr, parampath + "/" + name, name, false))
610 : {
611 2 : if (error->first)
612 4 : paramError(name, error->second);
613 : else
614 0 : mooseError("For range checked parameter '" + name + "': " + error->second);
615 142781183 : }
616 : }
617 :
618 : // Controllable parameters
619 6614906 : for (const auto & param_name : getControllableParameters())
620 : {
621 949693 : if (isPrivate(param_name))
622 2 : paramError(param_name,
623 10 : "private parameter '" + paramFullpath(param_name) + "' marked controllable");
624 :
625 949691 : std::optional<std::string> error;
626 949691 : checkMooseType(NonlinearVariableName, param_name);
627 949691 : checkMooseType(AuxVariableName, param_name);
628 949691 : checkMooseType(VariableName, param_name);
629 949691 : checkMooseType(BoundaryName, param_name);
630 949691 : checkMooseType(SubdomainName, param_name);
631 949691 : checkMooseType(PostprocessorName, param_name);
632 949691 : checkMooseType(VectorPostprocessorName, param_name);
633 949691 : checkMooseType(UserObjectName, param_name);
634 949691 : checkMooseType(MaterialPropertyName, param_name);
635 949691 : if (error)
636 4 : paramError(param_name, *error);
637 6614908 : }
638 5665225 : }
639 :
640 : std::optional<std::pair<bool, std::string>>
641 142796056 : InputParameters::parameterRangeCheck(const Parameters::Value & value,
642 : const std::string & long_name,
643 : const std::string & short_name,
644 : const bool include_param_path)
645 : {
646 : #define dynamicCastRangeCheck(type, up_type, long_name, short_name) \
647 : do \
648 : { \
649 : if (const auto scalar_p = dynamic_cast<const InputParameters::Parameter<type> *>(&value)) \
650 : return rangeCheck<type, up_type>(long_name, short_name, *scalar_p, include_param_path); \
651 : if (const auto vector_p = \
652 : dynamic_cast<const InputParameters::Parameter<std::vector<type>> *>(&value)) \
653 : return rangeCheck<type, up_type>(long_name, short_name, *vector_p, include_param_path); \
654 : } while (0)
655 :
656 142796056 : dynamicCastRangeCheck(Real, Real, long_name, short_name);
657 135088584 : dynamicCastRangeCheck(int, long, long_name, short_name);
658 134362329 : dynamicCastRangeCheck(long, long, long_name, short_name);
659 134362265 : dynamicCastRangeCheck(unsigned int, long, long_name, short_name);
660 : #undef dynamicCastRangeCheck
661 :
662 124304277 : return {};
663 : }
664 :
665 : void
666 5631358 : InputParameters::finalize(const std::string & parsing_syntax)
667 : {
668 : mooseAssert(!isFinalized(), "Already finalized");
669 :
670 5631358 : checkParams(parsing_syntax);
671 :
672 : // Helper for setting the absolute paths for each set file name parameter
673 261484 : const auto set_absolute_path = [this](const std::string & param_name, auto & value)
674 : {
675 : // We don't need to set a path if nothing is there
676 261484 : if (value.empty())
677 242199 : return;
678 :
679 19433 : std::filesystem::path value_path = std::string(value);
680 : // Is already absolute, nothing to do
681 19433 : if (value_path.is_absolute())
682 148 : return;
683 :
684 : // The base by which to make things relative to
685 19285 : const auto file_base = getFileBase(param_name);
686 19285 : value = std::filesystem::absolute(file_base / value_path).c_str();
687 5650759 : };
688 :
689 : // Set the absolute path for each file name typed parameter
690 147540879 : for (const auto & [param_name, param_value] : *this)
691 : {
692 : #define set_if_filename(type) \
693 : else if (auto type_value = dynamic_cast<Parameters::Parameter<type> *>(param_value.get())) \
694 : set_absolute_path(param_name, type_value->set()); \
695 : else if (auto type_values = dynamic_cast<Parameters::Parameter<std::vector<type>> *>( \
696 : param_value.get())) for (auto & value : type_values->set()) \
697 : set_absolute_path(param_name, value)
698 :
699 : if (false)
700 : ;
701 : // Note that we explicitly skip DataFileName here because we do not want absolute
702 : // file paths for data files, as they're searched in the data directories
703 141918776 : set_if_filename(FileName);
704 141810807 : set_if_filename(FileNameNoExtension);
705 141681764 : set_if_filename(MeshFileName);
706 141635121 : set_if_filename(MatrixFileName);
707 : #undef set_if_filename
708 : // Set paths for data files
709 141632752 : else if (auto data_file_name =
710 141632752 : dynamic_cast<Parameters::Parameter<DataFileName> *>(param_value.get()))
711 : {
712 190 : Moose::DataFileUtils::Path found_path;
713 190 : std::optional<std::string> error;
714 :
715 : // Catch this so that we can add additional error context if it fails (the param path)
716 : {
717 190 : Moose::ScopedThrowOnError scoped_throw_on_error;
718 : try
719 : {
720 : found_path =
721 206 : Moose::DataFileUtils::getPath(data_file_name->get(), getFileBase(param_name));
722 : }
723 4 : catch (std::exception & e)
724 : {
725 4 : error = e.what();
726 4 : }
727 190 : }
728 :
729 190 : if (error)
730 4 : paramError(param_name, *error);
731 :
732 : // Set the value to the absolute searched path
733 186 : data_file_name->set() = found_path.path;
734 : // And store the path in metadata so that we can dump it later
735 186 : at(param_name)._data_file_name_path = found_path;
736 186 : }
737 : }
738 :
739 5631322 : _finalized = true;
740 5631322 : }
741 :
742 : std::filesystem::path
743 19475 : InputParameters::getFileBase(const std::optional<std::string> & param_name) const
744 : {
745 : mooseAssert(!have_parameter<std::string>("_app_name"),
746 : "Not currently setup to work with app FileName parameters");
747 :
748 19475 : const hit::Node * hit_node = nullptr;
749 :
750 : // Context from the individual parameter
751 19475 : if (param_name)
752 19475 : hit_node = getHitNode(*param_name);
753 : // Context from the parameters
754 19475 : if (!hit_node)
755 1139 : hit_node = getHitNode();
756 : // No hit node, so use the cwd (no input files)
757 19475 : if (!hit_node)
758 274 : return std::filesystem::current_path();
759 :
760 : // Find any context that isn't command line arguments
761 19727 : while (hit_node && hit_node->filename() == "CLI_ARGS")
762 526 : hit_node = hit_node->parent();
763 :
764 : // Failed to find a node up the tree that isn't a command line argument
765 19201 : if (!hit_node)
766 : {
767 : const std::string error = "Input context was set via a command-line argument and does not have "
768 0 : "sufficient context for determining a file path.";
769 0 : if (param_name)
770 0 : paramError(*param_name, error);
771 : else
772 0 : mooseError(error);
773 0 : }
774 :
775 19201 : return std::filesystem::absolute(std::filesystem::path(hit_node->filename()).parent_path());
776 : }
777 :
778 : bool
779 4979428 : InputParameters::isRangeChecked(const std::string & param_name) const
780 : {
781 4979428 : const auto name = checkForRename(param_name);
782 9958856 : return !_params.find(name)->second._range_function.empty();
783 4979428 : }
784 :
785 : std::string
786 6 : InputParameters::rangeCheckedFunction(const std::string & param_name) const
787 : {
788 6 : const auto name = checkForRename(param_name);
789 12 : return _params.at(name)._range_function;
790 6 : }
791 :
792 : bool
793 2197965 : InputParameters::hasDefault(const std::string & param_name) const
794 : {
795 2197965 : const auto name = checkForRename(param_name);
796 2197965 : if (hasDefaultCoupledValue(name))
797 0 : return true;
798 : // If it has a default, it's already valid
799 2197965 : else if (isParamSetByAddParam(name))
800 4 : return true;
801 2197961 : else if (isParamValid(name))
802 0 : mooseError("No way to know if the parameter '", param_name, "' has a default");
803 : else
804 2197961 : return false;
805 2197965 : }
806 :
807 : bool
808 2334721 : InputParameters::hasCoupledValue(const std::string & coupling_name) const
809 : {
810 2334721 : return _coupled_vars.find(coupling_name) != _coupled_vars.end();
811 : }
812 :
813 : bool
814 9664645 : InputParameters::hasDefaultCoupledValue(const std::string & coupling_name) const
815 : {
816 9672286 : return _params.count(coupling_name) > 0 && _params.at(coupling_name)._have_coupled_default &&
817 9672286 : _coupled_vars.count(coupling_name) > 0;
818 : }
819 :
820 : void
821 1143 : InputParameters::defaultCoupledValue(const std::string & coupling_name, Real value, unsigned int i)
822 : {
823 1143 : const auto actual_name = checkForRename(coupling_name);
824 1143 : _params[actual_name]._coupled_default.resize(i + 1);
825 1143 : _params[actual_name]._coupled_default[i] = value;
826 1143 : _params[actual_name]._have_coupled_default = true;
827 1143 : }
828 :
829 : Real
830 970366 : InputParameters::defaultCoupledValue(const std::string & coupling_name, unsigned int i) const
831 : {
832 970366 : auto value_it = _params.find(coupling_name);
833 :
834 970366 : if (value_it == _params.end() || !value_it->second._have_coupled_default)
835 0 : mooseError("Attempted to retrieve default value for coupled variable '",
836 : coupling_name,
837 : "' when none was provided. \n\nThere are three reasons why this may have "
838 : "occurred:\n 1. The other version of params.addCoupledVar() should be used in order "
839 : "to provide a default value. \n 2. This should have been a required coupled "
840 : "variable added with params.addRequiredCoupledVar() \n 3. The call to get the "
841 : "coupled value should have been properly guarded with isCoupled()\n");
842 :
843 1929732 : return value_it->second._coupled_default.at(i);
844 : }
845 :
846 : unsigned int
847 238381 : InputParameters::numberDefaultCoupledValues(const std::string & coupling_name) const
848 : {
849 238381 : auto value_it = _params.find(coupling_name);
850 238381 : if (value_it == _params.end())
851 0 : mooseError("Attempted to retrieve default value for coupled variable '",
852 : coupling_name,
853 : "' when none was provided.");
854 476762 : return value_it->second._coupled_default.size();
855 : }
856 :
857 : std::map<std::string, std::pair<std::string, std::string>>
858 2408350 : InputParameters::getAutoBuildVectors() const
859 : {
860 2408350 : std::map<std::string, std::pair<std::string, std::string>> abv;
861 68215852 : for (auto it = _params.begin(); it != _params.end(); ++it)
862 : {
863 65807502 : if (!it->second._autobuild_vecs.first.empty())
864 2 : abv[it->first] = it->second._autobuild_vecs;
865 : }
866 2408350 : return abv;
867 0 : }
868 :
869 : std::string
870 8508129 : InputParameters::type(const std::string & name_in) const
871 : {
872 8508129 : const auto name = checkForRename(name_in);
873 8508129 : if (!_values.count(name))
874 0 : mooseError("Parameter \"", name, "\" not found.\n\n", *this);
875 :
876 8508129 : if (_coupled_vars.find(name) != _coupled_vars.end())
877 474504 : return "std::vector<VariableName>";
878 8270877 : else if (_params.count(name) > 0 && !_params.at(name)._custom_type.empty())
879 10193 : return _params.at(name)._custom_type;
880 8260684 : return _values.at(name)->type();
881 8508129 : }
882 :
883 : std::string
884 1615408 : InputParameters::getMooseType(const std::string & name_in) const
885 : {
886 1615408 : const auto name = checkForRename(name_in);
887 1615408 : std::string var;
888 :
889 1615408 : if (have_parameter<VariableName>(name))
890 79369 : var = get<VariableName>(name);
891 1536039 : else if (have_parameter<NonlinearVariableName>(name))
892 807781 : var = get<NonlinearVariableName>(name);
893 728258 : else if (have_parameter<LinearVariableName>(name))
894 17862 : var = get<LinearVariableName>(name);
895 710396 : else if (have_parameter<AuxVariableName>(name))
896 454916 : var = get<AuxVariableName>(name);
897 255480 : else if (have_parameter<PostprocessorName>(name))
898 0 : var = get<PostprocessorName>(name);
899 255480 : else if (have_parameter<VectorPostprocessorName>(name))
900 0 : var = get<VectorPostprocessorName>(name);
901 255480 : else if (have_parameter<FunctionName>(name))
902 0 : var = get<FunctionName>(name);
903 255480 : else if (have_parameter<UserObjectName>(name))
904 0 : var = get<UserObjectName>(name);
905 255480 : else if (have_parameter<MaterialPropertyName>(name))
906 0 : var = get<MaterialPropertyName>(name);
907 255480 : else if (have_parameter<std::string>(name))
908 0 : var = get<std::string>(name);
909 :
910 3230816 : return var;
911 1615408 : }
912 :
913 : std::vector<std::string>
914 896171 : InputParameters::getVecMooseType(const std::string & name_in) const
915 : {
916 896171 : const auto name = checkForRename(name_in);
917 896171 : std::vector<std::string> svars;
918 :
919 896171 : if (have_parameter<std::vector<VariableName>>(name))
920 : {
921 896163 : std::vector<VariableName> vars = get<std::vector<VariableName>>(name);
922 896163 : std::copy(vars.begin(), vars.end(), std::back_inserter(svars));
923 896163 : }
924 8 : else if (have_parameter<std::vector<NonlinearVariableName>>(name))
925 : {
926 0 : std::vector<NonlinearVariableName> vars = get<std::vector<NonlinearVariableName>>(name);
927 0 : std::copy(vars.begin(), vars.end(), std::back_inserter(svars));
928 0 : }
929 8 : else if (have_parameter<std::vector<AuxVariableName>>(name))
930 : {
931 0 : std::vector<AuxVariableName> vars = get<std::vector<AuxVariableName>>(name);
932 0 : std::copy(vars.begin(), vars.end(), std::back_inserter(svars));
933 0 : }
934 8 : else if (have_parameter<std::vector<MaterialPropertyName>>(name))
935 : {
936 0 : std::vector<MaterialPropertyName> vars = get<std::vector<MaterialPropertyName>>(name);
937 0 : std::copy(vars.begin(), vars.end(), std::back_inserter(svars));
938 0 : }
939 8 : else if (have_parameter<std::vector<std::string>>(name))
940 : {
941 0 : std::vector<std::string> vars = get<std::vector<std::string>>(name);
942 0 : std::copy(vars.begin(), vars.end(), std::back_inserter(svars));
943 0 : }
944 :
945 1792342 : return svars;
946 896171 : }
947 :
948 : bool
949 19382 : InputParameters::isMooseBaseObject() const
950 : {
951 38692 : return have_parameter<std::string>(MooseBase::type_param) &&
952 38692 : get<std::string>(MooseBase::type_param).size() &&
953 38656 : have_parameter<std::string>(MooseBase::name_param);
954 : }
955 :
956 : const std::string *
957 12688593 : InputParameters::queryObjectType() const
958 : {
959 12688593 : return have_parameter<std::string>(MooseBase::type_param)
960 12688593 : ? &get<std::string>(MooseBase::type_param)
961 12688593 : : nullptr;
962 : }
963 :
964 : const std::string &
965 12686803 : InputParameters::getObjectType() const
966 : {
967 12686803 : if (const auto type_ptr = queryObjectType())
968 12686801 : return *type_ptr;
969 2 : ::mooseError("InputParameters::getObjectType(): Missing '", MooseBase::type_param, "' param");
970 : }
971 :
972 : const std::string &
973 13820996 : InputParameters::getObjectName() const
974 : {
975 13820996 : if (!have_parameter<std::string>(MooseBase::name_param))
976 0 : ::mooseError("InputParameters::getObjectName(): Missing '", MooseBase::name_param, "' param");
977 13820996 : return get<std::string>(MooseBase::name_param);
978 : }
979 :
980 : void
981 180537593 : InputParameters::addParamNamesToGroup(const std::string & space_delim_names,
982 : const std::string group_name)
983 : {
984 180537593 : std::vector<std::string> elements;
985 180537593 : MooseUtils::tokenize(space_delim_names, elements, 1, " \t\n\v\f\r"); // tokenize on whitespace
986 :
987 : // Since we don't require types (templates) for this method, we need
988 : // to get a raw list of parameter names to compare against.
989 180537593 : std::set<std::string> param_names;
990 2671158289 : for (const auto & it : *this)
991 2490620696 : param_names.insert(it.first);
992 :
993 575653497 : for (const auto & param_name : elements)
994 395115904 : if (_params.count(param_name) > 0)
995 395115904 : _params[param_name]._group = group_name;
996 : else
997 0 : mooseError("Unable to find a parameter with name: ",
998 : param_name,
999 : " when adding to group ",
1000 : group_name,
1001 0 : '.');
1002 180537593 : }
1003 :
1004 : void
1005 0 : InputParameters::renameParameterGroup(const std::string & old_name, const std::string & new_name)
1006 : {
1007 0 : for (auto & param : _params)
1008 0 : if (param.second._group == old_name)
1009 0 : param.second._group = new_name;
1010 0 : }
1011 :
1012 : void
1013 1954272 : InputParameters::setGlobalCommandLineParam(const std::string & name)
1014 : {
1015 1954272 : auto & cl_data = at(checkForRename(name))._cl_data;
1016 1954272 : if (!cl_data)
1017 2 : mooseError("InputParameters::setGlobalCommandLineParam: The parameter '",
1018 : name,
1019 : "' is not a command line parameter");
1020 1954270 : cl_data->global = true;
1021 1954270 : }
1022 :
1023 : bool
1024 4 : InputParameters::isCommandLineParameter(const std::string & name) const
1025 : {
1026 4 : return at(checkForRename(name))._cl_data.has_value();
1027 : }
1028 :
1029 : std::optional<InputParameters::CommandLineMetadata>
1030 9868690 : InputParameters::queryCommandLineMetadata(const std::string & name) const
1031 : {
1032 9868690 : const auto & cl_data = at(checkForRename(name))._cl_data;
1033 9868690 : if (!cl_data)
1034 4219787 : return {};
1035 5648903 : return *cl_data;
1036 : }
1037 :
1038 : const InputParameters::CommandLineMetadata &
1039 23 : InputParameters::getCommandLineMetadata(const std::string & name) const
1040 : {
1041 23 : const auto & cl_data = at(checkForRename(name))._cl_data;
1042 23 : if (!cl_data)
1043 2 : mooseError("InputParameters::getCommandLineMetadata: The parameter '",
1044 : name,
1045 : "' is not a command line parameter");
1046 21 : return *cl_data;
1047 : }
1048 :
1049 : void
1050 466988 : InputParameters::commandLineParamSet(const std::string & name, const CommandLineParamSetKey)
1051 : {
1052 466988 : auto & cl_data = at(checkForRename(name))._cl_data;
1053 466988 : if (!cl_data)
1054 2 : mooseError("InputParameters::commandLineParamSet: The parameter '",
1055 : name,
1056 : "' is not a command line parameter");
1057 466986 : cl_data->set_by_command_line = true;
1058 466986 : }
1059 :
1060 : std::string
1061 8506101 : InputParameters::getGroupName(const std::string & param_name_in) const
1062 : {
1063 8506101 : const auto param_name = checkForRename(param_name_in);
1064 8506101 : auto it = _params.find(param_name);
1065 8506101 : if (it != _params.end())
1066 8506101 : return it->second._group;
1067 0 : return std::string();
1068 8506101 : }
1069 :
1070 : void
1071 640634 : InputParameters::applyParameters(const InputParameters & common,
1072 : const std::vector<std::string> & exclude,
1073 : const bool allow_private)
1074 : {
1075 : // If we're applying all of the things, also associate the top level hit node
1076 640634 : if (exclude.empty() && !getHitNode() && common.getHitNode())
1077 198318 : setHitNode(*common.getHitNode(), {});
1078 :
1079 : // Loop through the common parameters
1080 42104661 : for (const auto & it : common)
1081 : {
1082 : // Common parameter name
1083 41464027 : const std::string & common_name = it.first;
1084 : // Continue to next parameter, if the current is in list of excluded parameters
1085 41464027 : if (std::find(exclude.begin(), exclude.end(), common_name) != exclude.end())
1086 113880 : continue;
1087 :
1088 41350147 : applyParameter(common, common_name, allow_private);
1089 : }
1090 :
1091 : // Loop through the coupled variables
1092 640634 : for (std::set<std::string>::const_iterator it = common.coupledVarsBegin();
1093 642182 : it != common.coupledVarsEnd();
1094 1548 : ++it)
1095 : {
1096 : // Variable name
1097 1548 : const std::string var_name = *it;
1098 :
1099 : // Continue to next variable, if the current is in list of excluded parameters
1100 1548 : if (std::find(exclude.begin(), exclude.end(), var_name) != exclude.end())
1101 0 : continue;
1102 :
1103 1548 : applyCoupledVar(common, var_name);
1104 1548 : }
1105 640634 : }
1106 :
1107 : void
1108 128383 : InputParameters::applySpecificParameters(const InputParameters & common,
1109 : const std::vector<std::string> & include,
1110 : bool allow_private)
1111 : {
1112 : // Loop through the common parameters
1113 2816841 : for (const auto & it : common)
1114 : {
1115 : // Common parameter name
1116 2688458 : const std::string & common_name = it.first;
1117 :
1118 : // Continue to next parameter, if the current is not in list of included parameters
1119 2688458 : if (std::find(include.begin(), include.end(), common_name) == include.end())
1120 2310913 : continue;
1121 :
1122 377545 : applyParameter(common, common_name, allow_private);
1123 : }
1124 :
1125 : // Loop through the coupled variables
1126 128383 : for (std::set<std::string>::const_iterator it = common.coupledVarsBegin();
1127 128383 : it != common.coupledVarsEnd();
1128 0 : ++it)
1129 : {
1130 : // Variable name
1131 0 : const std::string var_name = *it;
1132 :
1133 : // Continue to next variable, if the current is not in list of included parameters
1134 0 : if (std::find(include.begin(), include.end(), var_name) == include.end())
1135 0 : continue;
1136 :
1137 0 : applyCoupledVar(common, var_name);
1138 0 : }
1139 128383 : }
1140 :
1141 : void
1142 1548 : InputParameters::applyCoupledVar(const InputParameters & common, const std::string & var_name)
1143 : {
1144 : // Disable the display of deprecated message when applying common parameters, this avoids a dump
1145 : // of messages
1146 1548 : _show_deprecated_message = false;
1147 :
1148 : // If the local parameters has a coupled variable, populate it with the value from the common
1149 : // parameters, if the common parameters has the coupled variable too
1150 1548 : if (hasCoupledValue(var_name))
1151 : {
1152 1544 : if (common.hasDefaultCoupledValue(var_name))
1153 : {
1154 : // prepare a vector of default coupled values
1155 0 : std::vector<Real> defaults(common.numberDefaultCoupledValues(var_name));
1156 0 : for (unsigned int j = 0; j < common.numberDefaultCoupledValues(var_name); ++j)
1157 0 : defaults[j] = common.defaultCoupledValue(var_name, j);
1158 0 : addCoupledVar(var_name, defaults, common.getDocString(var_name));
1159 0 : }
1160 1544 : else if (common.hasCoupledValue(var_name))
1161 1544 : addCoupledVar(var_name, common.getDocString(var_name));
1162 : }
1163 :
1164 : // Enable deprecated message printing
1165 1548 : _show_deprecated_message = true;
1166 1548 : }
1167 :
1168 : void
1169 41727842 : InputParameters::applyParameter(const InputParameters & common,
1170 : const std::string & common_name,
1171 : bool allow_private,
1172 : bool override_default)
1173 : {
1174 : // Disable the display of deprecated message when applying common parameters, this avoids a dump
1175 : // of messages
1176 41727842 : _show_deprecated_message = false;
1177 :
1178 41727842 : const auto local_name = checkForRename(common_name);
1179 :
1180 : // Extract the properties from the local parameter for the current common parameter name
1181 41727842 : const bool local_exist = _values.find(local_name) != _values.end();
1182 41727842 : const bool local_set = _params.count(local_name) > 0 && !_params[local_name]._set_by_add_param;
1183 41727842 : const bool local_priv = allow_private ? false : isPrivate(local_name);
1184 41727842 : const bool local_valid = isParamValid(local_name);
1185 :
1186 : // Extract the properties from the common parameter
1187 41727842 : const bool common_exist = common._values.find(common_name) != common._values.end();
1188 41727842 : const bool common_priv = allow_private ? false : common.isPrivate(common_name);
1189 41727842 : const bool common_valid = common.isParamValid(common_name) || override_default;
1190 :
1191 : /* In order to apply a common parameter 4 statements must be satisfied
1192 : * (1) A local parameter must exist with the same name as the common parameter
1193 : * (2) Common parameter must be valid and exist
1194 : * (3) Local parameter must be invalid OR not have been set from its default
1195 : * (4) Both cannot be private
1196 : */
1197 41727842 : if (local_exist && common_exist && common_valid && (!local_valid || !local_set) &&
1198 10597109 : (!common_priv || !local_priv))
1199 : {
1200 4774694 : remove(local_name);
1201 4774694 : _values[local_name] = common._values.find(common_name)->second->clone();
1202 4774694 : set_attributes(local_name, false);
1203 9549388 : _params[local_name]._set_by_add_param =
1204 4774694 : libmesh_map_find(common._params, common_name)._set_by_add_param;
1205 : // Keep track of where this param came from if we can. This will enable us to
1206 : // produce param errors from objects created within an action that link to
1207 : // the parameter in the action
1208 4774694 : at(local_name)._hit_node = common.getHitNode(common_name);
1209 : }
1210 36953148 : else if (!local_exist && !common_exist)
1211 2 : mooseError("InputParameters::applyParameter(): Attempted to apply invalid parameter \"",
1212 : common_name,
1213 : "\"");
1214 :
1215 : // Enable deprecated message printing
1216 41727840 : _show_deprecated_message = true;
1217 41727842 : }
1218 :
1219 : ///Deprecated method
1220 : bool
1221 0 : InputParameters::paramSetByUser(const std::string & name) const
1222 : {
1223 0 : mooseDeprecated("paramSetByUser() is deprecated. Use isParamSetByUser() instead.");
1224 0 : return isParamSetByUser(name);
1225 : }
1226 :
1227 : bool
1228 4638010 : InputParameters::isParamSetByUser(const std::string & name_in) const
1229 : {
1230 4638010 : const auto name = checkForRename(name_in);
1231 : // Invalid; for sure not set by the user
1232 4638010 : if (!isParamValid(name))
1233 1269099 : return false;
1234 : // Parameter is not located in the list (called Parameters::set)
1235 3368911 : if (!_params.count(name))
1236 0 : return false;
1237 : // Special case for a command line option, which is a private parameter
1238 3368911 : if (const auto cl_data = queryCommandLineMetadata(name))
1239 3368911 : return cl_data->set_by_command_line;
1240 : // Not a command line option, not set by addParam and not private
1241 2858612 : return !_params.at(name)._set_by_add_param && !_params.at(name)._is_private;
1242 4638010 : }
1243 :
1244 : bool
1245 4 : InputParameters::isParamDefined(const std::string & name_in) const
1246 : {
1247 4 : const auto name = checkForRename(name_in);
1248 8 : return _params.count(name) > 0;
1249 4 : }
1250 :
1251 : const std::string &
1252 2198355 : InputParameters::getDescription(const std::string & name_in) const
1253 : {
1254 2198355 : const auto name = checkForRename(name_in);
1255 2198355 : auto it = _params.find(name);
1256 2198355 : if (it == _params.end())
1257 0 : mooseError("No parameter exists with the name ", name);
1258 4396710 : return it->second._doc_string;
1259 2198355 : }
1260 :
1261 : template <>
1262 : void
1263 1886741 : InputParameters::addRequiredParam<MooseEnum>(const std::string & name,
1264 : const MooseEnum & moose_enum,
1265 : const std::string & doc_string)
1266 : {
1267 1886741 : InputParameters::set<MooseEnum>(name) = moose_enum; // valid parameter is set by set_attributes
1268 1886741 : auto & metadata = _params[name];
1269 1886741 : metadata._required = true;
1270 1886741 : metadata._doc_string = doc_string;
1271 1886741 : }
1272 :
1273 : template <>
1274 : void
1275 4 : InputParameters::addRequiredParam<MultiMooseEnum>(const std::string & name,
1276 : const MultiMooseEnum & moose_enum,
1277 : const std::string & doc_string)
1278 : {
1279 4 : InputParameters::set<MultiMooseEnum>(name) =
1280 4 : moose_enum; // valid parameter is set by set_attributes
1281 4 : auto & metadata = _params[name];
1282 4 : metadata._required = true;
1283 4 : metadata._doc_string = doc_string;
1284 4 : }
1285 :
1286 : template <>
1287 : void
1288 4 : InputParameters::addRequiredParam<std::vector<MooseEnum>>(
1289 : const std::string & name,
1290 : const std::vector<MooseEnum> & moose_enums,
1291 : const std::string & doc_string)
1292 : {
1293 4 : InputParameters::set<std::vector<MooseEnum>>(name) =
1294 4 : moose_enums; // valid parameter is set by set_attributes
1295 4 : auto & metadata = _params[name];
1296 4 : metadata._required = true;
1297 4 : metadata._doc_string = doc_string;
1298 4 : }
1299 :
1300 : template <>
1301 : void
1302 14794 : InputParameters::addRequiredParam<std::vector<MultiMooseEnum>>(
1303 : const std::string & name,
1304 : const std::vector<MultiMooseEnum> & moose_enums,
1305 : const std::string & doc_string)
1306 : {
1307 : mooseAssert(
1308 : moose_enums.size() == 1,
1309 : "Only 1 MultiMooseEnum is supported in addRequiredParam<std::vector<MultiMooseEnum>> for " +
1310 : name);
1311 : mooseAssert(!moose_enums[0].items().empty(),
1312 : "The MultiMooseEnum in addRequiredParam<std::vector<MultiMooseEnum>> is empty for " +
1313 : name);
1314 14794 : InputParameters::set<std::vector<MultiMooseEnum>>(name) =
1315 14794 : moose_enums; // valid parameter is set by set_attributes
1316 14794 : auto & metadata = _params[name];
1317 14794 : metadata._required = true;
1318 14794 : metadata._doc_string = doc_string;
1319 14794 : }
1320 :
1321 : template <>
1322 : void
1323 0 : InputParameters::addParam<MooseEnum>(const std::string & /*name*/,
1324 : const std::string & /*doc_string*/)
1325 : {
1326 0 : mooseError("You must supply a MooseEnum object when using addParam, even if the parameter is not "
1327 : "required!");
1328 : }
1329 :
1330 : template <>
1331 : void
1332 0 : InputParameters::addParam<MultiMooseEnum>(const std::string & /*name*/,
1333 : const std::string & /*doc_string*/)
1334 : {
1335 0 : mooseError("You must supply a MultiMooseEnum object when using addParam, even if the parameter "
1336 : "is not required!");
1337 : }
1338 :
1339 : template <>
1340 : void
1341 0 : InputParameters::addParam<std::vector<MooseEnum>>(const std::string & /*name*/,
1342 : const std::string & /*doc_string*/)
1343 : {
1344 0 : mooseError("You must supply a vector of MooseEnum object(s) when using addParam, even if the "
1345 : "parameter is not required!");
1346 : }
1347 :
1348 : template <>
1349 : void
1350 0 : InputParameters::addParam<std::vector<MultiMooseEnum>>(const std::string & /*name*/,
1351 : const std::string & /*doc_string*/)
1352 : {
1353 0 : mooseError(
1354 : "You must supply a vector of MultiMooseEnum object(s) when using addParam, even if the "
1355 : "parameter is not required!");
1356 : }
1357 :
1358 : template <>
1359 : void
1360 0 : InputParameters::addRequiredParam<std::vector<MultiMooseEnum>>(const std::string & /*name*/,
1361 : const std::string & /*doc_string*/)
1362 : {
1363 0 : mooseError("You must supply a vector of MultiMooseEnum object(s) when using addRequiredParam!");
1364 : }
1365 :
1366 : template <>
1367 : void
1368 0 : InputParameters::addPrivateParam<MooseEnum>(const std::string & /*name*/)
1369 : {
1370 0 : mooseError("You must supply a MooseEnum object when using addPrivateParam, even if the parameter "
1371 : "is not required!");
1372 : }
1373 :
1374 : template <>
1375 : void
1376 0 : InputParameters::addPrivateParam<MultiMooseEnum>(const std::string & /*name*/)
1377 : {
1378 0 : mooseError("You must supply a MultiMooseEnum object when using addPrivateParam, even if the "
1379 : "parameter is not required!");
1380 : }
1381 :
1382 : template <>
1383 : void
1384 0 : InputParameters::addDeprecatedParam<MooseEnum>(const std::string & /*name*/,
1385 : const std::string & /*doc_string*/,
1386 : const std::string & /*deprecation_message*/)
1387 : {
1388 0 : mooseError("You must supply a MooseEnum object and the deprecation string when using "
1389 : "addDeprecatedParam, even if the parameter is not required!");
1390 : }
1391 :
1392 : template <>
1393 : void
1394 0 : InputParameters::addDeprecatedParam<MultiMooseEnum>(const std::string & /*name*/,
1395 : const std::string & /*doc_string*/,
1396 : const std::string & /*deprecation_message*/)
1397 : {
1398 0 : mooseError("You must supply a MultiMooseEnum object and the deprecation string when using "
1399 : "addDeprecatedParam, even if the parameter is not required!");
1400 : }
1401 :
1402 : template <>
1403 : void
1404 0 : InputParameters::addDeprecatedParam<std::vector<MooseEnum>>(
1405 : const std::string & /*name*/,
1406 : const std::string & /*doc_string*/,
1407 : const std::string & /*deprecation_message*/)
1408 : {
1409 0 : mooseError("You must supply a vector of MooseEnum object(s) and the deprecation string when "
1410 : "using addDeprecatedParam, even if the parameter is not required!");
1411 : }
1412 :
1413 : template <>
1414 : void
1415 173656 : InputParameters::setParamHelper<PostprocessorName, Real>(const std::string & /*name*/,
1416 : PostprocessorName & l_value,
1417 : const Real & r_value)
1418 : {
1419 : // Assign the default value so that it appears in the dump
1420 173656 : std::ostringstream oss;
1421 173656 : oss << r_value;
1422 173656 : l_value = oss.str();
1423 173656 : }
1424 :
1425 : template <>
1426 : void
1427 206207 : InputParameters::setParamHelper<PostprocessorName, int>(const std::string & /*name*/,
1428 : PostprocessorName & l_value,
1429 : const int & r_value)
1430 : {
1431 : // Assign the default value so that it appears in the dump
1432 206207 : std::ostringstream oss;
1433 206207 : oss << r_value;
1434 206207 : l_value = oss.str();
1435 206207 : }
1436 :
1437 : template <>
1438 : void
1439 44768 : InputParameters::setParamHelper<FunctionName, Real>(const std::string & /*name*/,
1440 : FunctionName & l_value,
1441 : const Real & r_value)
1442 : {
1443 : // Assign the default value so that it appears in the dump
1444 44768 : std::ostringstream oss;
1445 44768 : oss << r_value;
1446 44768 : l_value = oss.str();
1447 44768 : }
1448 :
1449 : template <>
1450 : void
1451 775183 : InputParameters::setParamHelper<FunctionName, int>(const std::string & /*name*/,
1452 : FunctionName & l_value,
1453 : const int & r_value)
1454 : {
1455 : // Assign the default value so that it appears in the dump
1456 775183 : std::ostringstream oss;
1457 775183 : oss << r_value;
1458 775183 : l_value = oss.str();
1459 775183 : }
1460 :
1461 : template <>
1462 : void
1463 120271 : InputParameters::setParamHelper<MaterialPropertyName, Real>(const std::string & /*name*/,
1464 : MaterialPropertyName & l_value,
1465 : const Real & r_value)
1466 : {
1467 : // Assign the default value so that it appears in the dump
1468 120271 : std::ostringstream oss;
1469 120271 : oss << r_value;
1470 120271 : l_value = oss.str();
1471 120271 : }
1472 :
1473 : template <>
1474 : void
1475 136458 : InputParameters::setParamHelper<MaterialPropertyName, int>(const std::string & /*name*/,
1476 : MaterialPropertyName & l_value,
1477 : const int & r_value)
1478 : {
1479 : // Assign the default value so that it appears in the dump
1480 136458 : std::ostringstream oss;
1481 136458 : oss << r_value;
1482 136458 : l_value = oss.str();
1483 136458 : }
1484 :
1485 : template <>
1486 : void
1487 187166 : InputParameters::setParamHelper<MooseFunctorName, Real>(const std::string & /*name*/,
1488 : MooseFunctorName & l_value,
1489 : const Real & r_value)
1490 : {
1491 : // Assign the default value so that it appears in the dump
1492 187166 : std::ostringstream oss;
1493 187166 : oss << r_value;
1494 187166 : l_value = oss.str();
1495 187166 : }
1496 :
1497 : template <>
1498 : void
1499 342927 : InputParameters::setParamHelper<MooseFunctorName, int>(const std::string & /*name*/,
1500 : MooseFunctorName & l_value,
1501 : const int & r_value)
1502 : {
1503 : // Assign the default value so that it appears in the dump
1504 342927 : std::ostringstream oss;
1505 342927 : oss << r_value;
1506 342927 : l_value = oss.str();
1507 342927 : }
1508 :
1509 : template <>
1510 : const MooseEnum &
1511 2444817 : InputParameters::getParamHelper<MooseEnum>(const std::string & name_in,
1512 : const InputParameters & pars)
1513 : {
1514 2444817 : const auto name = pars.checkForRename(name_in);
1515 4889634 : return pars.get<MooseEnum>(name);
1516 2444817 : }
1517 :
1518 : template <>
1519 : const MultiMooseEnum &
1520 138257 : InputParameters::getParamHelper<MultiMooseEnum>(const std::string & name_in,
1521 : const InputParameters & pars)
1522 : {
1523 138257 : const auto name = pars.checkForRename(name_in);
1524 276514 : return pars.get<MultiMooseEnum>(name);
1525 138257 : }
1526 :
1527 : void
1528 7735234 : InputParameters::setReservedValues(const std::string & name_in,
1529 : const std::set<std::string> & reserved)
1530 : {
1531 7735234 : const auto name = checkForRename(name_in);
1532 7735234 : _params[name]._reserved_values = reserved;
1533 7735234 : }
1534 :
1535 : std::set<std::string>
1536 8005266 : InputParameters::reservedValues(const std::string & name_in) const
1537 : {
1538 8005266 : const auto name = checkForRename(name_in);
1539 8005266 : auto it = _params.find(name);
1540 8005266 : if (it == _params.end())
1541 0 : return std::set<std::string>();
1542 8005266 : return it->second._reserved_values;
1543 8005266 : }
1544 :
1545 : std::string
1546 0 : InputParameters::blockLocation() const
1547 : {
1548 0 : if (const auto hit_node = getHitNode())
1549 0 : return hit_node->fileLocation(/* with_column = */ false);
1550 0 : return "";
1551 : }
1552 :
1553 : std::string
1554 15414882 : InputParameters::blockFullpath() const
1555 : {
1556 15414882 : if (const auto hit_node = getHitNode())
1557 14273544 : return hit_node->fullpath();
1558 2282676 : return "";
1559 : }
1560 :
1561 : const hit::Node *
1562 5076050 : InputParameters::getHitNode(const std::string & param) const
1563 : {
1564 5076050 : return at(param)._hit_node;
1565 : }
1566 :
1567 : void
1568 2781269 : InputParameters::setHitNode(const std::string & param,
1569 : const hit::Node & node,
1570 : const InputParameters::SetParamHitNodeKey)
1571 : {
1572 : mooseAssert(node.type() == hit::NodeType::Field, "Must be a field");
1573 2781269 : at(param)._hit_node = &node;
1574 2781269 : }
1575 :
1576 : std::string
1577 32 : InputParameters::inputLocation(const std::string & param) const
1578 : {
1579 32 : if (const auto hit_node = getHitNode(param))
1580 32 : return hit_node->fileLocation(/* with_column = */ false);
1581 0 : return "";
1582 : }
1583 :
1584 : std::string
1585 40 : InputParameters::paramFullpath(const std::string & param) const
1586 : {
1587 40 : if (const auto hit_node = getHitNode(param))
1588 36 : return hit_node->fullpath();
1589 8 : return "";
1590 : }
1591 :
1592 : void
1593 2016951486 : InputParameters::checkParamName(const std::string & name) const
1594 : {
1595 2016951486 : const static pcrecpp::RE valid("[\\w:/]+");
1596 2016951486 : if (!valid.FullMatch(name))
1597 6 : mooseError("Invalid parameter name: '", name, "'");
1598 2016951480 : }
1599 :
1600 : bool
1601 65807502 : InputParameters::shouldIgnore(const std::string & name_in)
1602 : {
1603 65807502 : const auto name = checkForRename(name_in);
1604 65807502 : auto it = _params.find(name);
1605 65807502 : if (it != _params.end())
1606 131615004 : return it->second._ignore;
1607 0 : mooseError("Parameter ", name, " does not exist");
1608 65807502 : }
1609 :
1610 : std::set<std::string>
1611 0 : InputParameters::getGroupParameters(const std::string & group) const
1612 : {
1613 0 : std::set<std::string> names;
1614 0 : for (auto it = _params.begin(); it != _params.end(); ++it)
1615 0 : if (it->second._group == group)
1616 0 : names.emplace(it->first);
1617 0 : return names;
1618 0 : }
1619 :
1620 : std::set<std::string>
1621 498 : InputParameters::getParametersList() const
1622 : {
1623 498 : std::set<std::string> param_set;
1624 18097 : for (auto it = _params.begin(); it != _params.end(); ++it)
1625 17599 : param_set.emplace(it->first);
1626 498 : return param_set;
1627 0 : }
1628 :
1629 : std::set<std::string>
1630 5818611 : InputParameters::getControllableParameters() const
1631 : {
1632 5818611 : std::set<std::string> controllable;
1633 156484241 : for (auto it = _params.begin(); it != _params.end(); ++it)
1634 150665630 : if (it->second._controllable)
1635 951275 : controllable.emplace(it->first);
1636 5818611 : return controllable;
1637 0 : }
1638 :
1639 : std::string
1640 16 : InputParameters::paramLocationPrefix(const std::string & param) const
1641 : {
1642 16 : auto prefix = param + ":";
1643 16 : if (!inputLocation(param).empty())
1644 16 : prefix = inputLocation(param) + ": (" + paramFullpath(param) + ")";
1645 16 : return prefix;
1646 0 : }
1647 :
1648 : std::string
1649 0 : InputParameters::rawParamVal(const std::string & param) const
1650 : {
1651 0 : if (const auto hit_node = getHitNode(param))
1652 0 : return hit_node->strVal();
1653 0 : return "";
1654 : }
1655 :
1656 : std::string
1657 550887 : InputParameters::varName(const std::string & var_param_name,
1658 : const std::string & moose_object_with_var_param_name) const
1659 : {
1660 : // Try the scalar version first
1661 550887 : std::string variable_name = getMooseType(var_param_name);
1662 550887 : if (variable_name == "")
1663 : {
1664 66481 : auto vec = getVecMooseType(var_param_name);
1665 :
1666 : // Catch the (very unlikely) case where a user specifies
1667 : // variable = '' (the empty string)
1668 : // in their input file. This could happen if e.g. something goes
1669 : // wrong with dollar bracket expression expansion.
1670 66481 : if (vec.empty())
1671 8 : mooseError("Error constructing object '",
1672 : moose_object_with_var_param_name,
1673 : "' while retrieving value for '",
1674 : var_param_name,
1675 : "' parameter! Did you forget to set '",
1676 : var_param_name,
1677 : "' or set it to '' (empty string) by accident?");
1678 :
1679 : // When using vector variables, we are only going to use the first one in the list at the
1680 : // interface level...
1681 66473 : variable_name = vec[0];
1682 66473 : }
1683 :
1684 550879 : return variable_name;
1685 0 : }
1686 :
1687 : void
1688 3497022 : InputParameters::renameParamInternal(const std::string & old_name,
1689 : const std::string & new_name,
1690 : const std::string & docstring,
1691 : const std::string & removal_date)
1692 : {
1693 3497022 : auto params_it = _params.find(old_name);
1694 3497022 : if (params_it == _params.end())
1695 0 : mooseError("Requested to rename parameter '",
1696 : old_name,
1697 : "' but that parameter name doesn't exist in the parameters object.");
1698 : mooseAssert(params_it->second._deprecation_message.empty(),
1699 : "Attempting to rename the parameter, '" << old_name << "', that is deprecated");
1700 :
1701 3497022 : auto new_metadata = std::move(params_it->second);
1702 3497022 : if (!docstring.empty())
1703 392674 : new_metadata._doc_string = docstring;
1704 3497022 : _params.emplace(new_name, std::move(new_metadata));
1705 3497022 : _params.erase(params_it);
1706 :
1707 3497022 : auto values_it = _values.find(old_name);
1708 3497022 : auto new_value = std::move(values_it->second);
1709 3497022 : _values.emplace(new_name, std::move(new_value));
1710 3497022 : _values.erase(values_it);
1711 :
1712 3497022 : std::string deprecation_message;
1713 3497022 : if (!removal_date.empty())
1714 6134992 : deprecation_message = "'" + old_name + "' has been deprecated and will be removed on " +
1715 6134992 : removal_date + ". Please use '" + new_name + "' instead.";
1716 :
1717 3497022 : _old_to_new_name_and_dep.emplace(old_name, std::make_pair(new_name, deprecation_message));
1718 3497022 : _new_to_old_names.emplace(new_name, old_name);
1719 3497022 : }
1720 :
1721 : void
1722 410638 : InputParameters::renameCoupledVarInternal(const std::string & old_name,
1723 : const std::string & new_name,
1724 : const std::string & docstring,
1725 : const std::string & removal_date)
1726 : {
1727 410638 : auto coupled_vars_it = _coupled_vars.find(old_name);
1728 410638 : if (coupled_vars_it == _coupled_vars.end())
1729 0 : mooseError("Requested to rename coupled variable '",
1730 : old_name,
1731 : "' but that coupled variable name doesn't exist in the parameters object.");
1732 :
1733 410638 : _coupled_vars.insert(new_name);
1734 410638 : _coupled_vars.erase(coupled_vars_it);
1735 :
1736 410638 : renameParamInternal(old_name, new_name, docstring, removal_date);
1737 410638 : }
1738 :
1739 : void
1740 266322 : InputParameters::renameParam(const std::string & old_name,
1741 : const std::string & new_name,
1742 : const std::string & new_docstring)
1743 : {
1744 266322 : renameParamInternal(old_name, new_name, new_docstring, "");
1745 266322 : }
1746 :
1747 : void
1748 163204 : InputParameters::renameCoupledVar(const std::string & old_name,
1749 : const std::string & new_name,
1750 : const std::string & new_docstring)
1751 : {
1752 163204 : renameCoupledVarInternal(old_name, new_name, new_docstring, "");
1753 163204 : }
1754 :
1755 : void
1756 2820062 : InputParameters::deprecateParam(const std::string & old_name,
1757 : const std::string & new_name,
1758 : const std::string & removal_date)
1759 : {
1760 2820062 : renameParamInternal(old_name, new_name, "", removal_date);
1761 2820062 : }
1762 :
1763 : void
1764 247434 : InputParameters::deprecateCoupledVar(const std::string & old_name,
1765 : const std::string & new_name,
1766 : const std::string & removal_date)
1767 : {
1768 247434 : renameCoupledVarInternal(old_name, new_name, "", removal_date);
1769 247434 : }
1770 :
1771 : std::string
1772 9491668171 : InputParameters::checkForRename(const std::string & name) const
1773 : {
1774 9491668171 : if (auto it = _old_to_new_name_and_dep.find(name); it != _old_to_new_name_and_dep.end())
1775 338724 : return it->second.first;
1776 : else
1777 9491329447 : return name;
1778 : }
1779 :
1780 : std::vector<std::string>
1781 65804698 : InputParameters::paramAliases(const std::string & param_name) const
1782 : {
1783 : mooseAssert(_values.find(param_name) != _values.end(),
1784 : "The parameter we are searching for aliases for should exist in our parameter map");
1785 197414094 : std::vector<std::string> aliases = {param_name};
1786 :
1787 66001277 : for (const auto & pr : as_range(_new_to_old_names.equal_range(param_name)))
1788 196579 : aliases.push_back(pr.second);
1789 :
1790 65804698 : return aliases;
1791 65804698 : }
1792 :
1793 : std::optional<Moose::DataFileUtils::Path>
1794 12484 : InputParameters::queryDataFileNamePath(const std::string & name) const
1795 : {
1796 12484 : return at(checkForRename(name))._data_file_name_path;
1797 : }
1798 :
1799 : std::optional<std::string>
1800 79174 : InputParameters::setupVariableNames(std::vector<VariableName> & names,
1801 : const hit::Node & node,
1802 : const Moose::PassKey<Moose::Builder>)
1803 : {
1804 : // Whether or not a name was found
1805 79174 : bool has_name = false;
1806 : // Whether or not a default value (real) was found
1807 79174 : bool has_default = false;
1808 :
1809 : // Search through the names for values that convert to Real values,
1810 : // which are default values. If defaults are found, set appropriately
1811 : // in the InputParameters object. Keep track of if names or defaults
1812 : // were found because we don't allow having both
1813 168372 : for (const auto i : index_range(names))
1814 : {
1815 89198 : auto & name = names[i];
1816 : Real real_value;
1817 89198 : if (MooseUtils::convert<Real>(name, real_value, false))
1818 : {
1819 1143 : has_default = true;
1820 1143 : defaultCoupledValue(node.path(), real_value, i);
1821 : }
1822 : else
1823 88055 : has_name = true;
1824 : }
1825 :
1826 79174 : if (has_default)
1827 : {
1828 578 : if (has_name)
1829 8 : return {"invalid value for '" + node.fullpath() +
1830 : "': coupled vectors where some parameters are reals and others are variables are not "
1831 4 : "supported"};
1832 :
1833 : // Don't actually use the names if these don't represent names
1834 574 : names.clear();
1835 : }
1836 :
1837 79170 : return {};
1838 : }
1839 :
1840 : std::pair<std::string, const hit::Node *>
1841 3595 : InputParameters::paramMessageContext(const std::string & param) const
1842 : {
1843 3595 : const hit::Node * node = nullptr;
1844 :
1845 3595 : std::string fullpath;
1846 : // First try to find the parameter
1847 3595 : if (const hit::Node * param_node = getHitNode(param))
1848 : {
1849 3407 : fullpath = param_node->fullpath();
1850 3407 : node = param_node;
1851 : }
1852 : // If no parameter node, hope for a block node
1853 188 : else if (const hit::Node * block_node = getHitNode())
1854 : {
1855 172 : node = block_node;
1856 172 : fullpath = block_node->fullpath() + "/" + param;
1857 : }
1858 : // Didn't find anything, at least use the parameter
1859 : else
1860 16 : fullpath = param;
1861 :
1862 7190 : return {fullpath + ": ", node};
1863 3595 : }
1864 :
1865 : std::string
1866 1999 : InputParameters::paramMessagePrefix(const std::string & param) const
1867 : {
1868 1999 : auto [prefix, node] = paramMessageContext(param);
1869 1999 : if (node)
1870 1999 : prefix = Moose::hitMessagePrefix(*node) + prefix;
1871 3998 : return prefix;
1872 1999 : }
1873 :
1874 : [[noreturn]] void
1875 1684 : InputParameters::callMooseError(std::string msg,
1876 : const bool with_prefix /* = true */,
1877 : const hit::Node * node /* = nullptr */) const
1878 : {
1879 : // Find the context of the app if we can. This will let our errors be
1880 : // prefixed by the multiapp name (if applicable) and will flush the
1881 : // console before outputting an error
1882 1684 : MooseApp * app = nullptr;
1883 1684 : if (isMooseBaseObject() && have_parameter<MooseApp *>(MooseBase::app_param))
1884 1620 : app = get<MooseApp *>(MooseBase::app_param);
1885 :
1886 1684 : MooseBase::callMooseError(app, *this, msg, with_prefix, node);
1887 : }
|