www.mooseframework.org
InputParameters.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 
19 #include "pcrecpp.h"
20 
21 #include <cmath>
22 
25 {
26  InputParameters params;
27  return params;
28 }
29 
31  : Parameters(),
32  _collapse_nesting(false),
33  _moose_object_syntax_visibility(true),
34  _show_deprecated_message(true),
35  _allow_copy(true)
36 {
37 }
38 
40  : Parameters(), _show_deprecated_message(true), _allow_copy(true)
41 
42 {
43  *this = rhs;
44 }
45 
46 InputParameters::InputParameters(const Parameters & rhs)
47  : _show_deprecated_message(true), _allow_copy(true)
48 {
49  _params.clear();
50  Parameters::operator=(rhs);
51  _collapse_nesting = false;
53 }
54 
55 void
57 {
58  Parameters::clear();
59  _params.clear();
60  _coupled_vars.clear();
61  _collapse_nesting = false;
64  _allow_copy = true;
65  _block_fullpath = "";
66  _block_location = "";
67 }
68 
69 void
70 InputParameters::addClassDescription(const std::string & doc_string)
71 {
72  _class_description = doc_string;
73 }
74 
75 void
76 InputParameters::set_attributes(const std::string & name, bool inserted_only)
77 {
78  if (!inserted_only)
79  {
86  _params[name]._set_by_add_param = false;
87 
88  // valid_params don't make sense for MooseEnums
89  if (!have_parameter<MooseEnum>(name) && !have_parameter<MultiMooseEnum>(name))
90  _params[name]._valid = true;
91 
93  {
94  if (_params.count(name) && !_params[name]._deprecation_message.empty())
96  "The parameter ", name, " is deprecated.\n", _params[name]._deprecation_message);
97  }
98  }
99 }
100 
101 std::string
103 {
104  return _class_description;
105 }
106 
109 {
110  // An error to help minimize the segmentation faults that occure when MooseObjects do not have the
111  // correct constructor
112  if (!rhs._allow_copy)
113  {
114  const std::string & name =
115  rhs.get<std::string>("_object_name"); // If _allow_parameter_copy is set then so is name
116  // (see InputParameterWarehouse::addInputParameters)
117  mooseError("Copying of the InputParameters object for the ",
118  name,
119  " object is not allowed.\n\nThe likely cause for this error ",
120  "is having a constructor that does not use a const reference, all constructors\nfor "
121  "MooseObject based classes should be as follows:\n\n",
122  " MyObject::MyObject(const InputParameters & parameters);");
123  }
124 
125  Parameters::operator=(rhs);
126 
127  _params = rhs._params;
128 
134  _allow_copy = rhs._allow_copy;
137 
138  return *this;
139 }
140 
143 {
144  Parameters::operator+=(rhs);
145 
146  // TODO: this is not a proper merge - if a particular parameter exists in both this and rhs,
147  // then we should actually smartly merge both metadata structs before storing in this.
148  for (auto it = rhs._params.begin(); it != rhs._params.end(); ++it)
149  _params[it->first] = it->second;
150 
151  _buildable_types.insert(
152  _buildable_types.end(), rhs._buildable_types.begin(), rhs._buildable_types.end());
153  _buildable_rm_types.insert(
154  _buildable_rm_types.end(), rhs._buildable_rm_types.begin(), rhs._buildable_rm_types.end());
155 
156  // Collapse nesting and moose object syntax hiding are not modified with +=
157  _coupled_vars.insert(rhs._coupled_vars.begin(), rhs._coupled_vars.end());
158  return *this;
159 }
160 
161 void
162 InputParameters::addCoupledVar(const std::string & name, Real value, const std::string & doc_string)
163 {
164  addParam<std::vector<VariableName>>(name, doc_string);
165  _coupled_vars.insert(name);
166  _params[name]._coupled_default.assign(1, value);
167  _params[name]._have_coupled_default = true;
168 }
169 
170 void
171 InputParameters::addCoupledVar(const std::string & name,
172  const std::vector<Real> & value,
173  const std::string & doc_string)
174 {
175  // std::vector<VariableName>(1, Moose::stringify(value)),
176  addParam<std::vector<VariableName>>(name, doc_string);
177  _coupled_vars.insert(name);
178  _params[name]._coupled_default = value;
179  _params[name]._have_coupled_default = true;
180 }
181 
182 void
183 InputParameters::addCoupledVar(const std::string & name, const std::string & doc_string)
184 {
185  addParam<std::vector<VariableName>>(name, doc_string);
186  _coupled_vars.insert(name);
187 }
188 
189 void
191  const std::string & base_name,
192  const std::string & num_name,
193  const std::string & doc_string)
194 {
195  addParam<std::vector<VariableName>>(name, doc_string);
196  _coupled_vars.insert(name);
197  _params[name]._autobuild_vecs = std::make_pair(base_name, num_name);
198 
199  // Additionally there are two more parameters that need to be added:
200  addParam<std::string>(base_name, doc_string + " (base_name)");
201  addParam<unsigned int>(num_name, doc_string + " (num_name)");
202 }
203 
204 void
206  const std::string & base_name,
207  const std::string & num_name,
208  const std::string & doc_string)
209 {
210  addRequiredParam<std::vector<VariableName>>(name, doc_string);
211 
212  addCoupledVarWithAutoBuild(name, base_name, num_name, doc_string);
213 }
214 
215 void
216 InputParameters::addRequiredCoupledVar(const std::string & name, const std::string & doc_string)
217 {
218  addRequiredParam<std::vector<VariableName>>(name, doc_string);
219  _coupled_vars.insert(name);
220 }
221 
222 std::string
223 InputParameters::getDocString(const std::string & name) const
224 {
225  std::string doc_string;
226  auto it = _params.find(name);
227  if (it != _params.end())
228  for (const auto & ch : it->second._doc_string)
229  {
230  if (ch == '\n')
231  doc_string += " ... ";
232  else
233  doc_string += ch;
234  }
235 
236  return doc_string;
237 }
238 
239 void
240 InputParameters::setDocString(const std::string & name, const std::string & doc)
241 {
242  auto it = _params.find(name);
243  if (it == _params.end())
244  mooseError("Unable to set the documentation string (using setDocString) for the \"",
245  name,
246  "\" parameter, the parameter does not exist.");
247  it->second._doc_string = doc;
248 }
249 
250 bool
251 InputParameters::isParamRequired(const std::string & name) const
252 {
253  return _params.count(name) > 0 && _params.at(name)._required;
254 }
255 
256 bool
257 InputParameters::isParamValid(const std::string & name) const
258 {
259  if (have_parameter<MooseEnum>(name))
260  return get<MooseEnum>(name).isValid();
261  else if (have_parameter<MultiMooseEnum>(name))
262  return get<MultiMooseEnum>(name).isValid();
263  else if (have_parameter<ExecFlagEnum>(name))
264  return get<ExecFlagEnum>(name).isValid();
265  else
266  return _params.count(name) > 0 && _params.at(name)._valid;
267 }
268 
269 bool
270 InputParameters::isParamSetByAddParam(const std::string & name) const
271 {
272  return _params.count(name) > 0 && _params.at(name)._set_by_add_param;
273 }
274 
275 bool
276 InputParameters::isParamDeprecated(const std::string & name) const
277 {
278  return _params.count(name) > 0 && !_params.at(name)._deprecation_message.empty();
279 }
280 
281 bool
283 {
284  for (const auto & it : *this)
285  if (isParamRequired(it.first) && !isParamValid(it.first))
286  return false;
287  return true;
288 }
289 
290 bool
291 InputParameters::isPrivate(const std::string & name) const
292 {
293  return _params.count(name) > 0 && _params.at(name)._is_private;
294 }
295 
296 void
297 InputParameters::declareControllable(const std::string & input_names,
298  std::set<ExecFlagType> execute_flags)
299 {
300  std::vector<std::string> names;
301  MooseUtils::tokenize<std::string>(input_names, names, 1, " ");
302  for (auto & name : names)
303  {
304  auto map_iter = _params.find(name);
305  if (map_iter != _params.end()) // error is handled by checkParams method
306  {
307  map_iter->second._controllable = true;
308  map_iter->second._controllable_flags = execute_flags;
309  }
310  else
311  mooseError("The input parameter '",
312  name,
313  "' does not exist, thus cannot be marked as controllable.");
314  }
315 }
316 
317 bool
318 InputParameters::isControllable(const std::string & name)
319 {
320  return _params.count(name) > 0 && _params[name]._controllable;
321 }
322 
323 const std::set<ExecFlagType> &
325 {
326  return _params[name]._controllable_flags;
327 }
328 
329 void
330 InputParameters::registerBase(const std::string & value)
331 {
332  InputParameters::set<std::string>("_moose_base") = value;
333  _params["_moose_base"]._is_private = true;
334 }
335 
336 void
337 InputParameters::registerBuildableTypes(const std::string & names)
338 {
339  _buildable_types.clear();
340  MooseUtils::tokenize(names, _buildable_types, 1, " \t\n\v\f\r"); // tokenize on whitespace
341 }
342 
343 void
345  const std::string & name,
347  Moose::RelationshipManagerInputParameterCallback input_parameter_callback)
348 {
349  _buildable_rm_types.emplace_back(name, rm_type, input_parameter_callback);
350 }
351 
352 const std::vector<std::string> &
354 {
355  return _buildable_types;
356 }
357 
358 const std::vector<std::tuple<std::string,
362 {
363  return _buildable_rm_types;
364 }
365 
366 void
368 {
369  _collapse_nesting = collapse;
370 }
371 
372 bool
374 {
375  return _collapse_nesting;
376 }
377 
378 void
380 {
381  _moose_object_syntax_visibility = visibility;
382 }
383 
384 bool
386 {
388 }
389 
390 #define dynamicCastRangeCheck(type, up_type, long_name, short_name, param, oss) \
391  do \
392  { \
393  InputParameters::Parameter<type> * scalar_p = \
394  dynamic_cast<InputParameters::Parameter<type> *>(param); \
395  if (scalar_p) \
396  rangeCheck<type, up_type>(long_name, short_name, scalar_p, oss); \
397  InputParameters::Parameter<std::vector<type>> * vector_p = \
398  dynamic_cast<InputParameters::Parameter<std::vector<type>> *>(param); \
399  if (vector_p) \
400  rangeCheck<type, up_type>(long_name, short_name, vector_p, oss); \
401  } while (0)
402 
403 #define checkMooseType(param_type, name) \
404  if (have_parameter<param_type>(name) || have_parameter<std::vector<param_type>>(name)) \
405  oss << inputLocation(param_name) << ": non-controllable type '" << type(name) \
406  << "' for parameter '" << paramFullpath(param_name) << "' marked controllable";
407 
408 void
409 InputParameters::checkParams(const std::string & parsing_syntax)
410 {
411  std::string parampath = blockFullpath() != "" ? blockFullpath() : parsing_syntax;
412  std::ostringstream oss;
413  // Required parameters
414  for (const auto & it : *this)
415  {
416  if (!isParamValid(it.first) && isParamRequired(it.first))
417  {
418  oss << blockLocation() << ": missing required parameter '" << parampath + "/" + it.first
419  << "'\n";
420  oss << "\tDoc String: \"" + getDocString(it.first) + "\"" << std::endl;
421  }
422  }
423 
424  // Range checked parameters
425  for (const auto & it : *this)
426  {
427  std::string long_name(parampath + "/" + it.first);
428 
429  dynamicCastRangeCheck(Real, Real, long_name, it.first, it.second, oss);
430  dynamicCastRangeCheck(int, long, long_name, it.first, it.second, oss);
431  dynamicCastRangeCheck(long, long, long_name, it.first, it.second, oss);
432  dynamicCastRangeCheck(unsigned int, long, long_name, it.first, it.second, oss);
433  }
434 
435  // Controllable parameters
436  for (const auto & param_name : getControllableParameters())
437  {
438  if (isPrivate(param_name))
439  oss << inputLocation(param_name) << ": private parameter '" << paramFullpath(param_name)
440  << "' marked controllable";
441 
442  checkMooseType(NonlinearVariableName, param_name);
443  checkMooseType(AuxVariableName, param_name);
444  checkMooseType(VariableName, param_name);
445  checkMooseType(BoundaryName, param_name);
446  checkMooseType(SubdomainName, param_name);
447  checkMooseType(PostprocessorName, param_name);
448  checkMooseType(VectorPostprocessorName, param_name);
449  checkMooseType(UserObjectName, param_name);
450  checkMooseType(MaterialPropertyName, param_name);
451  }
452 
453  if (!oss.str().empty())
454  mooseError(oss.str());
455 }
456 
457 bool
458 InputParameters::hasCoupledValue(const std::string & coupling_name) const
459 {
460  return _coupled_vars.find(coupling_name) != _coupled_vars.end();
461 }
462 
463 bool
464 InputParameters::hasDefaultCoupledValue(const std::string & coupling_name) const
465 {
466  return _params.count(coupling_name) > 0 && _params.at(coupling_name)._have_coupled_default &&
467  _coupled_vars.count(coupling_name) > 0;
468 }
469 
470 void
471 InputParameters::defaultCoupledValue(const std::string & coupling_name, Real value, unsigned int i)
472 {
473  _params[coupling_name]._coupled_default.resize(i + 1);
474  _params[coupling_name]._coupled_default[i] = value;
475  _params[coupling_name]._have_coupled_default = true;
476 }
477 
478 Real
479 InputParameters::defaultCoupledValue(const std::string & coupling_name, unsigned int i) const
480 {
481  auto value_it = _params.find(coupling_name);
482 
483  if (value_it == _params.end() || !value_it->second._have_coupled_default)
484  mooseError("Attempted to retrieve default value for coupled variable '",
485  coupling_name,
486  "' when none was provided. \n\nThere are three reasons why this may have "
487  "occurred:\n 1. The other version of params.addCoupledVar() should be used in order "
488  "to provide a default value. \n 2. This should have been a required coupled "
489  "variable added with params.addRequiredCoupledVar() \n 3. The call to get the "
490  "coupled value should have been properly guarded with isCoupled()\n");
491 
492  return value_it->second._coupled_default.at(i);
493 }
494 
495 unsigned int
496 InputParameters::numberDefaultCoupledValues(const std::string & coupling_name) const
497 {
498  auto value_it = _params.find(coupling_name);
499  if (value_it == _params.end())
500  mooseError("Attempted to retrieve default value for coupled variable '",
501  coupling_name,
502  "' when none was provided.");
503  return value_it->second._coupled_default.size();
504 }
505 
506 std::map<std::string, std::pair<std::string, std::string>>
508 {
509  std::map<std::string, std::pair<std::string, std::string>> abv;
510  for (auto it = _params.begin(); it != _params.end(); ++it)
511  {
512  if (!it->second._autobuild_vecs.first.empty())
513  abv[it->first] = it->second._autobuild_vecs;
514  }
515  return abv;
516 }
517 
518 std::string
519 InputParameters::type(const std::string & name)
520 {
521  if (_coupled_vars.find(name) != _coupled_vars.end())
522  return "std::vector<VariableName>";
523  else if (_params.count(name) > 0 && !_params[name]._custom_type.empty())
524  return _params[name]._custom_type;
525  return _values[name]->type();
526 }
527 
528 std::string
529 InputParameters::getMooseType(const std::string & name) const
530 {
531  std::string var;
532 
533  if (have_parameter<VariableName>(name))
534  var = get<VariableName>(name);
535  else if (have_parameter<NonlinearVariableName>(name))
536  var = get<NonlinearVariableName>(name);
537  else if (have_parameter<AuxVariableName>(name))
538  var = get<AuxVariableName>(name);
539  else if (have_parameter<PostprocessorName>(name))
540  var = get<PostprocessorName>(name);
541  else if (have_parameter<VectorPostprocessorName>(name))
542  var = get<VectorPostprocessorName>(name);
543  else if (have_parameter<FunctionName>(name))
544  var = get<FunctionName>(name);
545  else if (have_parameter<UserObjectName>(name))
546  var = get<UserObjectName>(name);
547  else if (have_parameter<MaterialPropertyName>(name))
548  var = get<MaterialPropertyName>(name);
549  else if (have_parameter<std::string>(name))
550  var = get<std::string>(name);
551 
552  return var;
553 }
554 
555 std::vector<std::string>
556 InputParameters::getVecMooseType(const std::string & name) const
557 {
558  std::vector<std::string> svars;
559 
560  if (have_parameter<std::vector<VariableName>>(name))
561  {
562  std::vector<VariableName> vars = get<std::vector<VariableName>>(name);
563  std::copy(vars.begin(), vars.end(), std::back_inserter(svars));
564  }
565  else if (have_parameter<std::vector<NonlinearVariableName>>(name))
566  {
567  std::vector<NonlinearVariableName> vars = get<std::vector<NonlinearVariableName>>(name);
568  std::copy(vars.begin(), vars.end(), std::back_inserter(svars));
569  }
570  else if (have_parameter<std::vector<AuxVariableName>>(name))
571  {
572  std::vector<AuxVariableName> vars = get<std::vector<AuxVariableName>>(name);
573  std::copy(vars.begin(), vars.end(), std::back_inserter(svars));
574  }
575  else if (have_parameter<std::vector<MaterialPropertyName>>(name))
576  {
577  std::vector<MaterialPropertyName> vars = get<std::vector<MaterialPropertyName>>(name);
578  std::copy(vars.begin(), vars.end(), std::back_inserter(svars));
579  }
580  else if (have_parameter<std::vector<std::string>>(name))
581  {
582  std::vector<std::string> vars = get<std::vector<std::string>>(name);
583  std::copy(vars.begin(), vars.end(), std::back_inserter(svars));
584  }
585 
586  return svars;
587 }
588 
589 void
590 InputParameters::addParamNamesToGroup(const std::string & space_delim_names,
591  const std::string group_name)
592 {
593  std::vector<std::string> elements;
594  MooseUtils::tokenize(space_delim_names, elements, 1, " \t\n\v\f\r"); // tokenize on whitespace
595 
596  // Since we don't require types (templates) for this method, we need
597  // to get a raw list of parameter names to compare against.
598  std::set<std::string> param_names;
599  for (const auto & it : *this)
600  param_names.insert(it.first);
601 
602  for (const auto & param_name : elements)
603  if (_params.count(param_name) > 0)
604  _params[param_name]._group = group_name;
605  else
606  mooseError("Unable to find a parameter with name: ",
607  param_name,
608  " when adding to group ",
609  group_name,
610  '.');
611 }
612 
613 std::vector<std::string>
614 InputParameters::getSyntax(const std::string & name)
615 {
616  return _params[name]._cli_flag_names;
617 }
618 
619 std::string
620 InputParameters::getGroupName(const std::string & param_name) const
621 {
622  auto it = _params.find(param_name);
623  if (it != _params.end())
624  return it->second._group;
625  return std::string();
626 }
627 
628 const PostprocessorValue &
629 InputParameters::getDefaultPostprocessorValue(const std::string & name, bool suppress_error) const
630 {
631  // Check that a default exists, error if it does not
632  auto it = _params.find(name);
633  if (!suppress_error && (it == _params.end() || !it->second._have_default_postprocessor_val))
634  mooseError("A default PostprcessorValue does not exist for the given name: ", name);
635 
636  return it->second._default_postprocessor_val;
637 }
638 
639 void
641  const PostprocessorValue & value)
642 {
643  _params[name]._default_postprocessor_val = value;
644  _params[name]._have_default_postprocessor_val = true;
645 }
646 
647 bool
648 InputParameters::hasDefaultPostprocessorValue(const std::string & name) const
649 {
650  return _params.count(name) > 0 && _params.at(name)._have_default_postprocessor_val;
651 }
652 
653 void
655  const std::vector<std::string> exclude)
656 {
657  // Loop through the common parameters
658  for (const auto & it : common)
659  {
660  // Common parameter name
661  const std::string & common_name = it.first;
662 
663  // Continue to next parameter, if the current is in list of excluded parameters
664  if (std::find(exclude.begin(), exclude.end(), common_name) != exclude.end())
665  continue;
666 
667  applyParameter(common, common_name);
668  }
669 
670  // Loop through the coupled variables
671  for (std::set<std::string>::const_iterator it = common.coupledVarsBegin();
672  it != common.coupledVarsEnd();
673  ++it)
674  {
675  // Variable name
676  const std::string var_name = *it;
677 
678  // Continue to next variable, if the current is in list of excluded parameters
679  if (std::find(exclude.begin(), exclude.end(), var_name) != exclude.end())
680  continue;
681 
682  applyCoupledVar(common, var_name);
683  }
684 }
685 
686 void
688  const std::vector<std::string> & include,
689  bool allow_private)
690 {
691  // Loop through the common parameters
692  for (const auto & it : common)
693  {
694 
695  // Common parameter name
696  const std::string & common_name = it.first;
697 
698  // Continue to next parameter, if the current is not in list of included parameters
699  if (std::find(include.begin(), include.end(), common_name) == include.end())
700  continue;
701 
702  applyParameter(common, common_name, allow_private);
703  }
704 
705  // Loop through the coupled variables
706  for (std::set<std::string>::const_iterator it = common.coupledVarsBegin();
707  it != common.coupledVarsEnd();
708  ++it)
709  {
710  // Variable name
711  const std::string var_name = *it;
712 
713  // Continue to next variable, if the current is not in list of included parameters
714  if (std::find(include.begin(), include.end(), var_name) == include.end())
715  continue;
716 
717  applyCoupledVar(common, var_name);
718  }
719 }
720 
721 void
722 InputParameters::applyCoupledVar(const InputParameters & common, const std::string & var_name)
723 {
724  // Disable the display of deprecated message when applying common parameters, this avoids a dump
725  // of messages
726  _show_deprecated_message = false;
727 
728  // If the local parameters has a coupled variable, populate it with the value from the common
729  // parameters, if the common parameters has the coupled variable too
730  if (hasCoupledValue(var_name))
731  {
732  if (common.hasDefaultCoupledValue(var_name))
733  {
734  // prepare a vector of default coupled values
735  std::vector<Real> defaults(common.numberDefaultCoupledValues(var_name));
736  for (unsigned int j = 0; j < common.numberDefaultCoupledValues(var_name); ++j)
737  defaults[j] = common.defaultCoupledValue(var_name, j);
738  addCoupledVar(var_name, defaults, common.getDocString(var_name));
739  }
740  else if (common.hasCoupledValue(var_name))
741  addCoupledVar(var_name, common.getDocString(var_name));
742  }
743 
744  // Enable deprecated message printing
746 }
747 
748 void
750  const std::string & common_name,
751  bool allow_private)
752 {
753  // Disable the display of deprecated message when applying common parameters, this avoids a dump
754  // of messages
755  _show_deprecated_message = false;
756 
757  // Extract the properties from the local parameter for the current common parameter name
758  const bool local_exist = _values.find(common_name) != _values.end();
759  const bool local_set = _params.count(common_name) > 0 && !_params[common_name]._set_by_add_param;
760  const bool local_priv = allow_private ? false : isPrivate(common_name);
761  const bool local_valid = isParamValid(common_name);
762 
763  // Extract the properties from the common parameter
764  const bool common_exist = common._values.find(common_name) != common._values.end();
765  const bool common_priv = allow_private ? false : common.isPrivate(common_name);
766  const bool common_valid = common.isParamValid(common_name);
767 
768  /* In order to apply common parameter 4 statements must be satisfied
769  * (1) A local parameter must exist with the same name as common parameter
770  * (2) Common parameter must valid and exist
771  * (3) Local parameter must be invalid OR not have been set from its default
772  * (4) Both cannot be private
773  */
774  if (local_exist && common_exist && common_valid && (!local_valid || !local_set) &&
775  (!common_priv || !local_priv))
776  {
777  delete _values[common_name];
778  _values[common_name] = common._values.find(common_name)->second->clone();
779  set_attributes(common_name, false);
780  }
781 
782  // Enable deprecated message printing
784 }
785 
787 bool
788 InputParameters::paramSetByUser(const std::string & name) const
789 {
790  mooseDeprecated("paramSetByUser() is deprecated. Use isParamSetByUser() instead.");
791  return isParamSetByUser(name);
792 }
793 
794 bool
795 InputParameters::isParamSetByUser(const std::string & name) const
796 {
797  if (!isParamValid(name))
798  // if the parameter is invalid, it is for sure not set by the user
799  return false;
800  else
801  // If the parameters is not located in the list, then it was set by the user
802  return _params.count(name) > 0 && !_params.at(name)._set_by_add_param;
803 }
804 
805 const std::string &
806 InputParameters::getDescription(const std::string & name)
807 {
808  if (_params.count(name) == 0)
809  mooseError("No parameter exists with the name ", name);
810  return _params[name]._doc_string;
811 }
812 
813 template <>
814 void
815 InputParameters::addRequiredParam<MooseEnum>(const std::string & name,
816  const MooseEnum & moose_enum,
817  const std::string & doc_string)
818 {
819  InputParameters::set<MooseEnum>(name) = moose_enum; // valid parameter is set by set_attributes
820  _params[name]._required = true;
821  _params[name]._doc_string = doc_string;
822 }
823 
824 template <>
825 void
826 InputParameters::addRequiredParam<MultiMooseEnum>(const std::string & name,
827  const MultiMooseEnum & moose_enum,
828  const std::string & doc_string)
829 {
830  InputParameters::set<MultiMooseEnum>(name) =
831  moose_enum; // valid parameter is set by set_attributes
832  _params[name]._required = true;
833  _params[name]._doc_string = doc_string;
834 }
835 
836 template <>
837 void
838 InputParameters::addRequiredParam<std::vector<MooseEnum>>(
839  const std::string & name,
840  const std::vector<MooseEnum> & moose_enums,
841  const std::string & doc_string)
842 {
843  InputParameters::set<std::vector<MooseEnum>>(name) =
844  moose_enums; // valid parameter is set by set_attributes
845  _params[name]._required = true;
846  _params[name]._doc_string = doc_string;
847 }
848 
849 template <>
850 void
851 InputParameters::addParam<MooseEnum>(const std::string & /*name*/,
852  const std::string & /*doc_string*/)
853 {
854  mooseError("You must supply a MooseEnum object when using addParam, even if the parameter is not "
855  "required!");
856 }
857 
858 template <>
859 void
860 InputParameters::addParam<MultiMooseEnum>(const std::string & /*name*/,
861  const std::string & /*doc_string*/)
862 {
863  mooseError("You must supply a MultiMooseEnum object when using addParam, even if the parameter "
864  "is not required!");
865 }
866 
867 template <>
868 void
869 InputParameters::addParam<std::vector<MooseEnum>>(const std::string & /*name*/,
870  const std::string & /*doc_string*/)
871 {
872  mooseError("You must supply a vector of MooseEnum object(s) when using addParam, even if the "
873  "parameter is not required!");
874 }
875 
876 template <>
877 void
878 InputParameters::addPrivateParam<MooseEnum>(const std::string & /*name*/)
879 {
880  mooseError("You must supply a MooseEnum object when using addPrivateParam, even if the parameter "
881  "is not required!");
882 }
883 
884 template <>
885 void
886 InputParameters::addPrivateParam<MultiMooseEnum>(const std::string & /*name*/)
887 {
888  mooseError("You must supply a MultiMooseEnum object when using addPrivateParam, even if the "
889  "parameter is not required!");
890 }
891 
892 template <>
893 void
894 InputParameters::addDeprecatedParam<MooseEnum>(const std::string & /*name*/,
895  const std::string & /*doc_string*/,
896  const std::string & /*deprecation_message*/)
897 {
898  mooseError("You must supply a MooseEnum object and the deprecation string when using "
899  "addDeprecatedParam, even if the parameter is not required!");
900 }
901 
902 template <>
903 void
904 InputParameters::addDeprecatedParam<MultiMooseEnum>(const std::string & /*name*/,
905  const std::string & /*doc_string*/,
906  const std::string & /*deprecation_message*/)
907 {
908  mooseError("You must supply a MultiMooseEnum object and the deprecation string when using "
909  "addDeprecatedParam, even if the parameter is not required!");
910 }
911 
912 template <>
913 void
914 InputParameters::addDeprecatedParam<std::vector<MooseEnum>>(
915  const std::string & /*name*/,
916  const std::string & /*doc_string*/,
917  const std::string & /*deprecation_message*/)
918 {
919  mooseError("You must supply a vector of MooseEnum object(s) and the deprecation string when "
920  "using addDeprecatedParam, even if the parameter is not required!");
921 }
922 
923 template <>
924 void
925 InputParameters::setParamHelper<PostprocessorName, Real>(const std::string & name,
926  PostprocessorName & l_value,
927  const Real & r_value)
928 {
929  // Store the default value
930  _params[name]._default_postprocessor_val = r_value;
931  _params[name]._have_default_postprocessor_val = true;
932 
933  // Assign the default value so that it appears in the dump
934  std::ostringstream oss;
935  oss << r_value;
936  l_value = oss.str();
937 }
938 
939 template <>
940 void
941 InputParameters::setParamHelper<PostprocessorName, int>(const std::string & name,
942  PostprocessorName & l_value,
943  const int & r_value)
944 {
945  // Store the default value
946  _params[name]._default_postprocessor_val = r_value;
947  _params[name]._have_default_postprocessor_val = true;
948 
949  // Assign the default value so that it appears in the dump
950  std::ostringstream oss;
951  oss << r_value;
952  l_value = oss.str();
953 }
954 
955 template <>
956 void
957 InputParameters::setParamHelper<FunctionName, Real>(const std::string & /*name*/,
958  FunctionName & l_value,
959  const Real & r_value)
960 {
961  // Assign the default value so that it appears in the dump
962  std::ostringstream oss;
963  oss << r_value;
964  l_value = oss.str();
965 }
966 
967 template <>
968 void
969 InputParameters::setParamHelper<FunctionName, int>(const std::string & /*name*/,
970  FunctionName & l_value,
971  const int & r_value)
972 {
973  // Assign the default value so that it appears in the dump
974  std::ostringstream oss;
975  oss << r_value;
976  l_value = oss.str();
977 }
978 
979 template <>
980 void
981 InputParameters::setParamHelper<MaterialPropertyName, Real>(const std::string & /*name*/,
982  MaterialPropertyName & l_value,
983  const Real & r_value)
984 {
985  // Assign the default value so that it appears in the dump
986  std::ostringstream oss;
987  oss << r_value;
988  l_value = oss.str();
989 }
990 
991 template <>
992 void
993 InputParameters::setParamHelper<MaterialPropertyName, int>(const std::string & /*name*/,
994  MaterialPropertyName & l_value,
995  const int & r_value)
996 {
997  // Assign the default value so that it appears in the dump
998  std::ostringstream oss;
999  oss << r_value;
1000  l_value = oss.str();
1001 }
1002 
1003 template <>
1004 const MooseEnum &
1005 InputParameters::getParamHelper<MooseEnum>(const std::string & name,
1006  const InputParameters & pars,
1007  const MooseEnum *)
1008 {
1009  return pars.get<MooseEnum>(name);
1010 }
1011 
1012 template <>
1013 const MultiMooseEnum &
1014 InputParameters::getParamHelper<MultiMooseEnum>(const std::string & name,
1015  const InputParameters & pars,
1016  const MultiMooseEnum *)
1017 {
1018  return pars.get<MultiMooseEnum>(name);
1019 }
1020 
1021 void
1022 InputParameters::setReservedValues(const std::string & name, const std::set<std::string> & reserved)
1023 {
1024  _params[name]._reserved_values = reserved;
1025 }
1026 
1027 std::set<std::string>
1028 InputParameters::reservedValues(const std::string & name) const
1029 {
1030  auto it = _params.find(name);
1031  if (it == _params.end())
1032  return std::set<std::string>();
1033  return it->second._reserved_values;
1034 }
1035 
1036 void
1037 InputParameters::checkParamName(const std::string & name) const
1038 {
1039  const static pcrecpp::RE valid("[\\w:/]+");
1040  if (!valid.FullMatch(name))
1041  mooseError("Invalid parameter name: '", name, "'");
1042 }
std::string getMooseType(const std::string &name) const
Utility functions for retrieving one of the MooseTypes variables into the common "string" base class...
std::set< std::string > getControllableParameters() const
Return list of controllable parameters.
bool hasCoupledValue(const std::string &coupling_name) const
Return whether or not the coupled variable exists.
void isValid(MooseObject *obj)
Definition: TheWarehouse.C:249
bool _allow_copy
A flag for toggling the error message in the copy constructor.
void tokenize(const std::string &str, std::vector< T > &elements, unsigned int min_len=1, const std::string &delims="/")
This function will split the passed in string on a set of delimiters appending the substrings to the ...
Definition: MooseUtils.h:532
std::vector< std::string > getSyntax(const std::string &name)
Get the syntax for a command-line parameter.
RelationshipManagerType
Main types of Relationship Managers.
Definition: MooseTypes.h:716
bool hasDefaultPostprocessorValue(const std::string &name) const
Returns true if a default PostprocessorValue is defined.
InputParameters & operator=(const InputParameters &rhs)
std::map< std::string, std::pair< std::string, std::string > > getAutoBuildVectors() const
Returns the auto build vectors for all parameters.
void applySpecificParameters(const InputParameters &common, const std::vector< std::string > &include, bool allow_private=false)
Method for applying common parameters.
void setDocString(const std::string &name, const std::string &doc)
Set the doc string of a parameter.
bool isParamDeprecated(const std::string &name) const
Returns True if the parameters is deprecated.
const std::vector< std::tuple< std::string, Moose::RelationshipManagerType, Moose::RelationshipManagerInputParameterCallback > > & getBuildableRelationshipManagerTypes() const
Returns the list of buildable (or required) RelationshipManager object types for this object...
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:207
std::string _block_location
original location of input block (i.e. filename,linenum) - used for nice error messages.
std::string _block_fullpath
full HIT path of the block from the input file - used for nice error messages.
const std::vector< std::string > & getBuildableTypes() const
Returns the list of buildable types as a std::vector<std::string>
InputParameters & operator+=(const InputParameters &rhs)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void applyCoupledVar(const InputParameters &common, const std::string &var_name)
Apply properties of a single coupled variable in common, to a single coupled variable stored in this ...
void registerBuildableTypes(const std::string &names)
This method is here to indicate which Moose types a particular Action may build.
bool isPrivate(const std::string &name) const
Returns a Boolean indicating whether the specified parameter is private or not.
void addRelationshipManager(const std::string &name, Moose::RelationshipManagerType rm_type, Moose::RelationshipManagerInputParameterCallback input_parameter_callback=nullptr)
Tells MOOSE about a RelationshipManager that this object needs.
void checkParamName(const std::string &name) const
Make sure the parameter name doesn&#39;t have any invalid characters.
bool mooseObjectSyntaxVisibility() const
unsigned int numberDefaultCoupledValues(const std::string &coupling_name) const
Get the number of defaulted coupled value entries.
std::string type(const std::string &name)
Prints the type of the requested parameter by name.
void registerBase(const std::string &value)
This method must be called from every base "Moose System" to create linkage with the Action System...
void setDefaultPostprocessorValue(const std::string &name, const PostprocessorValue &value)
Set the default value for a postprocessor added with addPostprocessor.
bool isParamSetByAddParam(const std::string &name) const
Returns whether or not the parameter was set due to addParam.
bool _show_deprecated_message
Flag for disabling deprecated parameters message, this is used by applyParameters to avoid dumping me...
bool _collapse_nesting
This parameter collapses one level of nesting in the syntax blocks.
std::string getDocString(const std::string &name) const
Returns the documentation string for the specified parameter name.
const std::set< ExecFlagType > & getControllableExecuteOnTypes(const std::string &name)
Return the allowed execute flags for a controllable parameter.
std::function< void(const InputParameters &, InputParameters &)> RelationshipManagerInputParameterCallback
The type for the callback to set RelationshipManager parameters.
Definition: MooseTypes.h:728
bool hasDefaultCoupledValue(const std::string &coupling_name) const
Return whether or not the requested parameter has a default coupled value.
const std::string & getDescription(const std::string &name)
Get the documentation string for a parameter.
bool areAllRequiredParamsValid() const
This method returns true if all of the parameters in this object are valid (i.e.
Real defaultCoupledValue(const std::string &coupling_name, unsigned int i=0) const
Get the default value for an optionally coupled variable.
const std::string & inputLocation(const std::string &param) const
Get/set a string representing the location in the input text the parameter originated from (i...
Real PostprocessorValue
MOOSE typedefs.
Definition: MooseTypes.h:154
std::string _class_description
The class description for the owning object.
bool isControllable(const std::string &name)
Returns a Boolean indicating whether the specified parameter is controllable.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:31
void mooseDeprecated(Args &&... args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
Definition: MooseError.h:236
void checkParams(const std::string &parsing_syntax)
This function checks parameters stored in the object to make sure they are in the correct state as th...
void applyParameter(const InputParameters &common, const std::string &common_name, bool allow_private=false)
Apply values from a single parameter in common, to a single parameter stored in this object...
void applyParameters(const InputParameters &common, std::vector< std::string > exclude=std::vector< std::string >())
Method for applying common parameters.
std::set< std::string > reservedValues(const std::string &name) const
Get a set of reserved parameter values.
void addCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
void setReservedValues(const std::string &name, const std::set< std::string > &reserved)
Provide a set of reserved values for a parameter.
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
bool isParamSetByUser(const std::string &name) const
Method returns true if the parameter was by the user.
unsigned int get(unsigned int i) const
Indexing operator Operator to retrieve an item from the MultiMooseEnum.
std::set< std::string > _coupled_vars
The coupled variables set.
std::vector< std::tuple< std::string, Moose::RelationshipManagerType, Moose::RelationshipManagerInputParameterCallback > > _buildable_rm_types
The RelationshipManagers that this object may either build or require.
void addRequiredCoupledVarWithAutoBuild(const std::string &name, const std::string &base_name, const std::string &num_name, const std::string &doc_string)
void addCoupledVarWithAutoBuild(const std::string &name, const std::string &base_name, const std::string &num_name, const std::string &doc_string)
These methods add a coupled variable name pair.
std::string & blockFullpath()
Get/set a string representing the full HIT parameter path from the input file (e.g.
std::string getGroupName(const std::string &param_name) const
This method retrieves the group name for the passed parameter name if one exists. ...
bool paramSetByUser(const std::string &name) const
Deprecated method.
bool isParamRequired(const std::string &name) const
Returns a boolean indicating whether the specified parameter is required or not.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
std::vector< std::string > _buildable_types
The parameter is used to restrict types that can be built.
bool _moose_object_syntax_visibility
This parameter hides derived MOOSE object types from appearing in syntax dumps.
virtual void clear() override
std::map< std::string, Metadata > _params
The actual parameter data.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
virtual void set_attributes(const std::string &name, bool inserted_only) override
Override from libMesh to set user-defined attributes on our parameter.
std::string getClassDescription() const
Returns the class description.
InputParameters emptyInputParameters()
std::vector< std::string > getVecMooseType(const std::string &name) const
void declareControllable(const std::string &name, std::set< ExecFlagType > execute_flags={})
Declare the given parameters as controllable.
bool collapseSyntaxNesting() const
std::string & blockLocation()
Get/set a string representing the location (i.e.
const std::string & paramFullpath(const std::string &param) const
Get/set a string representing the full HIT parameter path from the input file (e.g.
ExecFlagEnum execute_flags
Storage for the registered execute flags.
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
This method takes a space delimited list of parameter names and adds them to the specified group name...
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.
const PostprocessorValue & getDefaultPostprocessorValue(const std::string &name, bool suppress_error=false) const
Get the default value for a postprocessor added with addPostprocessor.