www.mooseframework.org
InputParameters.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #include "InputParameters.h"
16 
17 // MOOSE includes
18 #include "MooseEnum.h"
19 #include "MooseTypes.h"
20 #include "MooseUtils.h"
21 #include "MultiMooseEnum.h"
22 
23 #include "pcrecpp.h"
24 
25 #include <cmath>
26 
29 {
30  InputParameters params;
31  return params;
32 }
33 
35  : Parameters(),
36  _collapse_nesting(false),
37  _moose_object_syntax_visibility(true),
38  _show_deprecated_message(true),
39  _allow_copy(true)
40 {
41 }
42 
44  : Parameters(), _show_deprecated_message(true), _allow_copy(true)
45 
46 {
47  *this = rhs;
48 }
49 
50 InputParameters::InputParameters(const Parameters & rhs)
52 {
53  Parameters::operator=(rhs);
54  _collapse_nesting = false;
56 }
57 
58 void
60 {
61  Parameters::clear();
62  _doc_string.clear();
63  _custom_type.clear();
64  _group.clear();
65  _range_functions.clear();
66  _auto_build_vectors.clear();
67  _required_params.clear();
68  _valid_params.clear();
69  _private_params.clear();
70  _coupled_vars.clear();
71  _syntax.clear();
72  _default_coupled_value.clear();
74  _collapse_nesting = false;
77  _allow_copy = true;
78 }
79 
80 void
81 InputParameters::addClassDescription(const std::string & doc_string)
82 {
83  _doc_string["_class"] = doc_string;
84 }
85 
86 void
87 InputParameters::set_attributes(const std::string & name, bool inserted_only)
88 {
89  if (!inserted_only)
90  {
97  _set_by_add_param.erase(name);
98 
99  // valid_params don't make sense for MooseEnums
100  if (!have_parameter<MooseEnum>(name) && !have_parameter<MultiMooseEnum>(name))
101  _valid_params.insert(name);
102 
104  {
105  std::map<std::string, std::string>::const_iterator pos = _deprecated_params.find(name);
106  if (pos != _deprecated_params.end())
107  {
108  mooseDeprecated("The parameter ", name, " is deprecated.\n", pos->second);
109  }
110  }
111  }
112 }
113 
114 std::string
116 {
117  std::map<std::string, std::string>::const_iterator pos = _doc_string.find("_class");
118  if (pos != _doc_string.end())
119  return pos->second;
120  else
121  return std::string();
122 }
123 
126 {
127  // An error to help minimize the segmentation faults that occure when MooseObjects do not have the
128  // correct constructor
129  if (!rhs._allow_copy)
130  {
131  const std::string & name =
132  rhs.get<std::string>("_object_name"); // If _allow_parameter_copy is set then so is name
133  // (see InputParameterWarehouse::addInputParameters)
134  mooseError("Copying of the InputParameters object for the ",
135  name,
136  " object is not allowed.\n\nThe likely cause for this error ",
137  "is having a constructor that does not use a const reference, all constructors\nfor "
138  "MooseObject based classes should be as follows:\n\n",
139  " MyObject::MyObject(const InputParameters & parameters);");
140  }
141 
142  Parameters::operator=(rhs);
143 
144  _doc_string = rhs._doc_string;
146  _group = rhs._group;
156  _syntax = rhs._syntax;
160  _allow_copy = rhs._allow_copy;
163 
164  return *this;
165 }
166 
169 {
170  Parameters::operator+=(rhs);
171 
172  _doc_string.insert(rhs._doc_string.begin(), rhs._doc_string.end());
173  _custom_type.insert(rhs._custom_type.begin(), rhs._custom_type.end());
174  _group.insert(rhs._group.begin(), rhs._group.end());
175  _range_functions.insert(rhs._range_functions.begin(), rhs._range_functions.end());
176  _auto_build_vectors.insert(rhs._auto_build_vectors.begin(), rhs._auto_build_vectors.end());
177  _buildable_types.insert(
178  _buildable_types.end(), rhs._buildable_types.begin(), rhs._buildable_types.end());
179  // Collapse nesting and moose object syntax hiding are not modified with +=
180  _required_params.insert(rhs._required_params.begin(), rhs._required_params.end());
181  _private_params.insert(rhs._private_params.begin(), rhs._private_params.end());
182  _valid_params.insert(rhs._valid_params.begin(), rhs._valid_params.end());
183  _coupled_vars.insert(rhs._coupled_vars.begin(), rhs._coupled_vars.end());
184  _syntax.insert(rhs._syntax.begin(), rhs._syntax.end());
186  rhs._default_coupled_value.end());
188  rhs._default_postprocessor_value.end());
189  _set_by_add_param.insert(rhs._set_by_add_param.begin(), rhs._set_by_add_param.end());
190  _controllable_params.insert(rhs._controllable_params.begin(), rhs._controllable_params.end());
191  _reserved_values.insert(rhs._reserved_values.begin(), rhs._reserved_values.end());
192  return *this;
193 }
194 
195 void
196 InputParameters::addCoupledVar(const std::string & name, Real value, const std::string & doc_string)
197 {
198  // std::vector<VariableName>(1, Moose::stringify(value)),
199  addParam<std::vector<VariableName>>(name, doc_string);
200  _coupled_vars.insert(name);
201  _default_coupled_value[name] = value;
202 }
203 
204 void
205 InputParameters::addCoupledVar(const std::string & name, const std::string & doc_string)
206 {
207  addParam<std::vector<VariableName>>(name, doc_string);
208  _coupled_vars.insert(name);
209 }
210 
211 void
213  const std::string & base_name,
214  const std::string & num_name,
215  const std::string & doc_string)
216 {
217  addParam<std::vector<VariableName>>(name, doc_string);
218  _coupled_vars.insert(name);
219  _auto_build_vectors[name] = std::make_pair(base_name, num_name);
220 
221  // Additionally there are two more parameters that need to be added:
222  addParam<std::string>(base_name, doc_string + " (base_name)");
223  addParam<unsigned int>(num_name, doc_string + " (num_name)");
224 }
225 
226 void
228  const std::string & base_name,
229  const std::string & num_name,
230  const std::string & doc_string)
231 {
232  addRequiredParam<std::vector<VariableName>>(name, doc_string);
233 
234  addCoupledVarWithAutoBuild(name, base_name, num_name, doc_string);
235 }
236 
237 void
238 InputParameters::addRequiredCoupledVar(const std::string & name, const std::string & doc_string)
239 {
240  addRequiredParam<std::vector<VariableName>>(name, doc_string);
241  _coupled_vars.insert(name);
242 }
243 
244 std::string
245 InputParameters::getDocString(const std::string & name) const
246 {
247  std::string doc_string;
248  std::map<std::string, std::string>::const_iterator doc_string_it = _doc_string.find(name);
249  if (doc_string_it != _doc_string.end())
250  for (const auto & ch : doc_string_it->second)
251  {
252  if (ch == '\n')
253  doc_string += " ... ";
254  else
255  doc_string += ch;
256  }
257 
258  return doc_string;
259 }
260 
261 void
262 InputParameters::setDocString(const std::string & name, const std::string & doc)
263 {
264  std::map<std::string, std::string>::iterator doc_string_it = _doc_string.find(name);
265  if (doc_string_it == _doc_string.end())
266  mooseError("Unable to set the documentation string (using setDocString) for the \"",
267  name,
268  "\" parameter, the parameter does not exist.");
269  else
270  doc_string_it->second = doc;
271 }
272 
273 bool
274 InputParameters::isParamRequired(const std::string & name) const
275 {
276  return _required_params.find(name) != _required_params.end();
277 }
278 
279 bool
280 InputParameters::isParamValid(const std::string & name) const
281 {
282  if (have_parameter<MooseEnum>(name))
283  return get<MooseEnum>(name).isValid();
284  else if (have_parameter<MultiMooseEnum>(name))
285  return get<MultiMooseEnum>(name).isValid();
286  else
287  return _valid_params.find(name) != _valid_params.end();
288 }
289 
290 bool
291 InputParameters::isParamSetByAddParam(const std::string & name) const
292 {
293  return _set_by_add_param.find(name) != _set_by_add_param.end();
294 }
295 
296 bool
298 {
299  for (const auto & it : *this)
300  if (isParamRequired(it.first) && !isParamValid(it.first))
301  return false;
302  return true;
303 }
304 
305 bool
306 InputParameters::isPrivate(const std::string & name) const
307 {
308  return _private_params.find(name) != _private_params.end();
309 }
310 
311 void
312 InputParameters::declareControllable(const std::string & input_names)
313 {
314  std::vector<std::string> names;
315  MooseUtils::tokenize<std::string>(input_names, names, 1, " ");
316  _controllable_params.insert(names.begin(), names.end());
317 }
318 
319 bool
320 InputParameters::isControllable(const std::string & name)
321 {
322  return _controllable_params.find(name) != _controllable_params.end();
323 }
324 
325 void
326 InputParameters::registerBase(const std::string & value)
327 {
328  InputParameters::set<std::string>("_moose_base") = value;
329  _private_params.insert("_moose_base");
330 }
331 
332 void
333 InputParameters::registerBuildableTypes(const std::string & names)
334 {
335  _buildable_types.clear();
336  MooseUtils::tokenize(names, _buildable_types, 1, " \t\n\v\f\r"); // tokenize on whitespace
337 }
338 
339 const std::vector<std::string> &
341 {
342  return _buildable_types;
343 }
344 
345 void
347 {
348  _collapse_nesting = collapse;
349 }
350 
351 bool
353 {
354  return _collapse_nesting;
355 }
356 
357 void
359 {
360  _moose_object_syntax_visibility = visibility;
361 }
362 
363 bool
365 {
367 }
368 
369 #define dynamicCastRangeCheck(type, up_type, long_name, short_name, param, oss) \
370  do \
371  { \
372  InputParameters::Parameter<type> * scalar_p = \
373  dynamic_cast<InputParameters::Parameter<type> *>(param); \
374  if (scalar_p) \
375  rangeCheck<type, up_type>(long_name, short_name, scalar_p, oss); \
376  InputParameters::Parameter<std::vector<type>> * vector_p = \
377  dynamic_cast<InputParameters::Parameter<std::vector<type>> *>(param); \
378  if (vector_p) \
379  rangeCheck<type, up_type>(long_name, short_name, vector_p, oss); \
380  } while (0)
381 
382 #define checkMooseType(param_type, name) \
383  if (have_parameter<param_type>(name) || have_parameter<std::vector<param_type>>(name)) \
384  mooseError("Parameter '", \
385  name, \
386  "' cannot be marked as controllable because its type (", \
387  this->type(name), \
388  ") is not controllable.")
389 
390 void
391 InputParameters::checkParams(const std::string & parsing_syntax)
392 {
393  std::string l_prefix = this->have_parameter<std::string>("parser_syntax")
394  ? this->get<std::string>("parser_syntax")
395  : parsing_syntax;
396 
397  std::ostringstream oss;
398  // Required parameters
399  for (const auto & it : *this)
400  {
401  if (!isParamValid(it.first) && isParamRequired(it.first))
402  {
403  // The parameter is required but missing
404  if (oss.str().empty())
405  oss << "The following required parameters are missing:" << std::endl;
406  oss << l_prefix << "/" << it.first << std::endl;
407  oss << "\tDoc String: \"" + getDocString(it.first) + "\"" << std::endl;
408  }
409  }
410 
411  // Range checked parameters
412  for (const auto & it : *this)
413  {
414  std::string long_name(l_prefix + "/" + it.first);
415 
416  dynamicCastRangeCheck(Real, Real, long_name, it.first, it.second, oss);
417  dynamicCastRangeCheck(int, long, long_name, it.first, it.second, oss);
418  dynamicCastRangeCheck(long, long, long_name, it.first, it.second, oss);
419  dynamicCastRangeCheck(unsigned int, long, long_name, it.first, it.second, oss);
420  }
421 
422  if (!oss.str().empty())
423  mooseError(oss.str());
424 
425  // Controllable parameters
426  for (const auto & param_name : _controllable_params)
427  {
428  // Check that parameter is valid
429  if (!isParamValid(param_name))
430  mooseError("The parameter '",
431  param_name,
432  "' is not a valid parameter for the object ",
433  l_prefix,
434  " thus cannot be marked as controllable.");
435 
436  if (isPrivate(param_name))
437  mooseError("The parameter, '",
438  param_name,
439  "', in ",
440  l_prefix,
441  " is a private parameter and cannot be marked as controllable");
442 
443  checkMooseType(NonlinearVariableName, param_name);
444  checkMooseType(AuxVariableName, param_name);
445  checkMooseType(VariableName, param_name);
446  checkMooseType(BoundaryName, param_name);
447  checkMooseType(SubdomainName, param_name);
448  checkMooseType(PostprocessorName, param_name);
449  checkMooseType(VectorPostprocessorName, param_name);
450  checkMooseType(UserObjectName, param_name);
451  checkMooseType(MaterialPropertyName, param_name);
452  }
453 }
454 
455 bool
456 InputParameters::hasCoupledValue(const std::string & coupling_name) const
457 {
458  return _coupled_vars.find(coupling_name) != _coupled_vars.end();
459 }
460 
461 bool
462 InputParameters::hasDefaultCoupledValue(const std::string & coupling_name) const
463 {
464  return _default_coupled_value.find(coupling_name) != _default_coupled_value.end();
465 }
466 
467 void
468 InputParameters::defaultCoupledValue(const std::string & coupling_name, Real value)
469 {
470  _default_coupled_value[coupling_name] = value;
471 }
472 
473 Real
474 InputParameters::defaultCoupledValue(const std::string & coupling_name) const
475 {
476  std::map<std::string, Real>::const_iterator value_it = _default_coupled_value.find(coupling_name);
477 
478  if (value_it == _default_coupled_value.end())
479  mooseError("Attempted to retrieve default value for coupled variable '",
480  coupling_name,
481  "' when none was provided. \n\nThere are three reasons why this may have "
482  "occurred:\n 1. The other version of params.addCoupledVar() should be used in order "
483  "to provide a default value. \n 2. This should have been a required coupled "
484  "variable added with params.addRequiredCoupledVar() \n 3. The call to get the "
485  "coupled value should have been properly guarded with isCoupled()\n");
486 
487  return value_it->second;
488 }
489 
490 const std::map<std::string, std::pair<std::string, std::string>> &
492 {
493  return _auto_build_vectors;
494 }
495 
496 std::string
497 InputParameters::type(const std::string & name)
498 {
499  if (_coupled_vars.find(name) != _coupled_vars.end())
500  return "std::vector<VariableName>";
501  else if (_custom_type.find(name) != _custom_type.end())
502  return _custom_type[name];
503  else
504  return _values[name]->type();
505 }
506 
507 std::string
508 InputParameters::getMooseType(const std::string & name) const
509 {
510  std::string var;
511 
512  if (have_parameter<VariableName>(name))
513  var = get<VariableName>(name);
514  else if (have_parameter<NonlinearVariableName>(name))
515  var = get<NonlinearVariableName>(name);
516  else if (have_parameter<AuxVariableName>(name))
517  var = get<AuxVariableName>(name);
518  else if (have_parameter<PostprocessorName>(name))
519  var = get<PostprocessorName>(name);
520  else if (have_parameter<VectorPostprocessorName>(name))
521  var = get<VectorPostprocessorName>(name);
522  else if (have_parameter<FunctionName>(name))
523  var = get<FunctionName>(name);
524  else if (have_parameter<UserObjectName>(name))
525  var = get<UserObjectName>(name);
526  else if (have_parameter<MaterialPropertyName>(name))
527  var = get<MaterialPropertyName>(name);
528  else if (have_parameter<std::string>(name))
529  var = get<std::string>(name);
530 
531  return var;
532 }
533 
534 std::vector<std::string>
535 InputParameters::getVecMooseType(const std::string & name) const
536 {
537  std::vector<std::string> svars;
538 
539  if (have_parameter<std::vector<VariableName>>(name))
540  {
541  std::vector<VariableName> vars = get<std::vector<VariableName>>(name);
542  std::copy(vars.begin(), vars.end(), std::back_inserter(svars));
543  }
544  else if (have_parameter<std::vector<NonlinearVariableName>>(name))
545  {
546  std::vector<NonlinearVariableName> vars = get<std::vector<NonlinearVariableName>>(name);
547  std::copy(vars.begin(), vars.end(), std::back_inserter(svars));
548  }
549  else if (have_parameter<std::vector<AuxVariableName>>(name))
550  {
551  std::vector<AuxVariableName> vars = get<std::vector<AuxVariableName>>(name);
552  std::copy(vars.begin(), vars.end(), std::back_inserter(svars));
553  }
554  else if (have_parameter<std::vector<MaterialPropertyName>>(name))
555  {
556  std::vector<MaterialPropertyName> vars = get<std::vector<MaterialPropertyName>>(name);
557  std::copy(vars.begin(), vars.end(), std::back_inserter(svars));
558  }
559  else if (have_parameter<std::vector<std::string>>(name))
560  {
561  std::vector<std::string> vars = get<std::vector<std::string>>(name);
562  std::copy(vars.begin(), vars.end(), std::back_inserter(svars));
563  }
564 
565  return svars;
566 }
567 
568 void
569 InputParameters::addParamNamesToGroup(const std::string & space_delim_names,
570  const std::string group_name)
571 {
572  std::vector<std::string> elements;
573  MooseUtils::tokenize(space_delim_names, elements, 1, " \t\n\v\f\r"); // tokenize on whitespace
574 
575  // Since we don't require types (templates) for this method, we need
576  // to get a raw list of parameter names to compare against.
577  std::set<std::string> param_names;
578  for (const auto & it : *this)
579  param_names.insert(it.first);
580 
581  for (const auto & param_name : elements)
582  if (param_names.find(param_name) != param_names.end())
583  _group[param_name] = group_name;
584  else
585  mooseError("Unable to find a parameter with name: ",
586  param_name,
587  " when adding to group ",
588  group_name,
589  '.');
590 }
591 
592 std::vector<std::string>
593 InputParameters::getSyntax(const std::string & name)
594 {
595  return _syntax[name];
596 }
597 
598 std::string
599 InputParameters::getGroupName(const std::string & param_name) const
600 {
601  std::map<std::string, std::string>::const_iterator it = _group.find(param_name);
602 
603  if (it != _group.end())
604  return it->second;
605  else
606  return std::string();
607 }
608 
609 const PostprocessorValue &
610 InputParameters::getDefaultPostprocessorValue(const std::string & name, bool suppress_error) const
611 {
612  // Check that a default exists, error if it does not
613  std::map<std::string, PostprocessorValue>::const_iterator it =
614  _default_postprocessor_value.find(name);
615  if (!(suppress_error || it != _default_postprocessor_value.end()))
616  mooseError("A default PostprcessorValue does not exist for the given name: ", name);
617 
618  // Return the value
619  return it->second;
620 }
621 
622 void
624  const PostprocessorValue & value)
625 {
626  _default_postprocessor_value[name] = value;
627 }
628 
629 bool
630 InputParameters::hasDefaultPostprocessorValue(const std::string & name) const
631 {
633 }
634 
635 void
637  const std::vector<std::string> exclude)
638 {
639  // Loop through the common parameters
640  for (const auto & it : common)
641  {
642  // Common parameter name
643  const std::string & common_name = it.first;
644 
645  // Continue to next parameter, if the current is in list of excluded parameters
646  if (std::find(exclude.begin(), exclude.end(), common_name) != exclude.end())
647  continue;
648 
649  applyParameter(common, common_name);
650  }
651 
652  // Loop through the coupled variables
653  for (std::set<std::string>::const_iterator it = common.coupledVarsBegin();
654  it != common.coupledVarsEnd();
655  ++it)
656  {
657  // Variable name
658  const std::string var_name = *it;
659 
660  // Continue to next variable, if the current is in list of excluded parameters
661  if (std::find(exclude.begin(), exclude.end(), var_name) != exclude.end())
662  continue;
663 
664  applyCoupledVar(common, var_name);
665  }
666 }
667 
668 void
670  const std::vector<std::string> & include)
671 {
672  // Loop through the common parameters
673  for (const auto & it : common)
674  {
675  // Common parameter name
676  const std::string & common_name = it.first;
677 
678  // Continue to next parameter, if the current is not in list of included parameters
679  if (std::find(include.begin(), include.end(), common_name) == include.end())
680  continue;
681 
682  applyParameter(common, common_name);
683  }
684 
685  // Loop through the coupled variables
686  for (std::set<std::string>::const_iterator it = common.coupledVarsBegin();
687  it != common.coupledVarsEnd();
688  ++it)
689  {
690  // Variable name
691  const std::string var_name = *it;
692 
693  // Continue to next variable, if the current is not in list of included parameters
694  if (std::find(include.begin(), include.end(), var_name) == include.end())
695  continue;
696 
697  applyCoupledVar(common, var_name);
698  }
699 }
700 
701 void
702 InputParameters::applyCoupledVar(const InputParameters & common, const std::string & var_name)
703 {
704  // Disable the display of deprecated message when applying common parameters, this avoids a dump
705  // of messages
706  _show_deprecated_message = false;
707 
708  // If the local parameters has a coupled variable, populate it with the value from the common
709  // parameters, if the common parameters has the coupled variable too
710  if (hasCoupledValue(var_name))
711  {
712  if (common.hasDefaultCoupledValue(var_name))
713  addCoupledVar(var_name, common.defaultCoupledValue(var_name), common.getDocString(var_name));
714  else if (common.hasCoupledValue(var_name))
715  addCoupledVar(var_name, common.getDocString(var_name));
716  }
717 
718  // Enable deprecated message printing
720 }
721 
722 void
723 InputParameters::applyParameter(const InputParameters & common, const std::string & common_name)
724 {
725  // Disable the display of deprecated message when applying common parameters, this avoids a dump
726  // of messages
727  _show_deprecated_message = false;
728 
729  // Extract the properties from the local parameter for the current common parameter name
730  const bool local_exist = _values.find(common_name) != _values.end();
731  const bool local_set = _set_by_add_param.find(common_name) == _set_by_add_param.end();
732  const bool local_priv = isPrivate(common_name);
733  const bool local_valid = isParamValid(common_name);
734 
735  // Extract the properties from the common parameter
736  const bool common_exist = common._values.find(common_name) != common._values.end();
737  const bool common_priv = common.isPrivate(common_name);
738  const bool common_valid = common.isParamValid(common_name);
739 
740  /* In order to apply common parameter 4 statements must be satisfied
741  * (1) A local parameter must exist with the same name as common parameter
742  * (2) Common parameter must valid and exist
743  * (3) Local parameter must be invalid OR not have been set from its default
744  * (4) Both cannot be private
745  */
746  if (local_exist && common_exist && common_valid && (!local_valid || !local_set) &&
747  (!common_priv || !local_priv))
748  {
749  delete _values[common_name];
750  _values[common_name] = common._values.find(common_name)->second->clone();
751  set_attributes(common_name, false);
752  }
753 
754  // Enable deprecated message printing
756 }
757 
759 bool
760 InputParameters::paramSetByUser(const std::string & name) const
761 {
762  mooseDeprecated("paramSetByUser() is deprecated. Use isParamSetByUser() instead.");
763  return isParamSetByUser(name);
764 }
765 
766 bool
767 InputParameters::isParamSetByUser(const std::string & name) const
768 {
769  if (!isParamValid(name))
770  // if the parameter is invalid, it is for sure not set by the user
771  return false;
772  else
773  // If the parameters is not located in the list, then it was set by the user
774  return _set_by_add_param.find(name) == _set_by_add_param.end();
775 }
776 
777 const std::string &
778 InputParameters::getDescription(const std::string & name)
779 {
780  if (_doc_string.find(name) == _doc_string.end())
781  mooseError("No parameter exists with the name ", name);
782  return _doc_string[name];
783 }
784 
785 template <>
786 void
787 InputParameters::addRequiredParam<MooseEnum>(const std::string & name,
788  const MooseEnum & moose_enum,
789  const std::string & doc_string)
790 {
791  InputParameters::set<MooseEnum>(name) = moose_enum; // valid parameter is set by set_attributes
792  _required_params.insert(name);
793  _doc_string[name] = doc_string;
794 }
795 
796 template <>
797 void
798 InputParameters::addRequiredParam<MultiMooseEnum>(const std::string & name,
799  const MultiMooseEnum & moose_enum,
800  const std::string & doc_string)
801 {
802  InputParameters::set<MultiMooseEnum>(name) =
803  moose_enum; // valid parameter is set by set_attributes
804  _required_params.insert(name);
805  _doc_string[name] = doc_string;
806 }
807 
808 template <>
809 void
810 InputParameters::addRequiredParam<std::vector<MooseEnum>>(
811  const std::string & name,
812  const std::vector<MooseEnum> & moose_enums,
813  const std::string & doc_string)
814 {
815  InputParameters::set<std::vector<MooseEnum>>(name) =
816  moose_enums; // valid parameter is set by set_attributes
817  _required_params.insert(name);
818  _doc_string[name] = doc_string;
819 }
820 
821 template <>
822 void
823 InputParameters::addParam<MooseEnum>(const std::string & /*name*/,
824  const std::string & /*doc_string*/)
825 {
826  mooseError("You must supply a MooseEnum object when using addParam, even if the parameter is not "
827  "required!");
828 }
829 
830 template <>
831 void
832 InputParameters::addParam<MultiMooseEnum>(const std::string & /*name*/,
833  const std::string & /*doc_string*/)
834 {
835  mooseError("You must supply a MultiMooseEnum object when using addParam, even if the parameter "
836  "is not required!");
837 }
838 
839 template <>
840 void
841 InputParameters::addParam<std::vector<MooseEnum>>(const std::string & /*name*/,
842  const std::string & /*doc_string*/)
843 {
844  mooseError("You must supply a vector of MooseEnum object(s) when using addParam, even if the "
845  "parameter is not required!");
846 }
847 
848 template <>
849 void
850 InputParameters::addDeprecatedParam<MooseEnum>(const std::string & /*name*/,
851  const std::string & /*doc_string*/,
852  const std::string & /*deprecation_message*/)
853 {
854  mooseError("You must supply a MooseEnum object and the deprecation string when using "
855  "addDeprecatedParam, even if the parameter is not required!");
856 }
857 
858 template <>
859 void
860 InputParameters::addDeprecatedParam<MultiMooseEnum>(const std::string & /*name*/,
861  const std::string & /*doc_string*/,
862  const std::string & /*deprecation_message*/)
863 {
864  mooseError("You must supply a MultiMooseEnum object and the deprecation string when using "
865  "addDeprecatedParam, even if the parameter is not required!");
866 }
867 
868 template <>
869 void
870 InputParameters::addDeprecatedParam<std::vector<MooseEnum>>(
871  const std::string & /*name*/,
872  const std::string & /*doc_string*/,
873  const std::string & /*deprecation_message*/)
874 {
875  mooseError("You must supply a vector of MooseEnum object(s) and the deprecation string when "
876  "using addDeprecatedParam, even if the parameter is not required!");
877 }
878 
879 template <>
880 void
881 InputParameters::setParamHelper<PostprocessorName, Real>(const std::string & name,
882  PostprocessorName & l_value,
883  const Real & r_value)
884 {
885  // Store the default value
886  _default_postprocessor_value[name] = r_value;
887 
888  // Assign the default value so that it appears in the dump
889  std::ostringstream oss;
890  oss << r_value;
891  l_value = oss.str();
892 }
893 
894 template <>
895 void
896 InputParameters::setParamHelper<PostprocessorName, int>(const std::string & name,
897  PostprocessorName & l_value,
898  const int & r_value)
899 {
900  // Store the default value
901  _default_postprocessor_value[name] = r_value;
902 
903  // Assign the default value so that it appears in the dump
904  std::ostringstream oss;
905  oss << r_value;
906  l_value = oss.str();
907 }
908 
909 template <>
910 void
911 InputParameters::setParamHelper<FunctionName, Real>(const std::string & /*name*/,
912  FunctionName & l_value,
913  const Real & r_value)
914 {
915  // Assign the default value so that it appears in the dump
916  std::ostringstream oss;
917  oss << r_value;
918  l_value = oss.str();
919 }
920 
921 template <>
922 void
923 InputParameters::setParamHelper<FunctionName, int>(const std::string & /*name*/,
924  FunctionName & l_value,
925  const int & r_value)
926 {
927  // Assign the default value so that it appears in the dump
928  std::ostringstream oss;
929  oss << r_value;
930  l_value = oss.str();
931 }
932 
933 template <>
934 void
935 InputParameters::setParamHelper<MaterialPropertyName, Real>(const std::string & /*name*/,
936  MaterialPropertyName & l_value,
937  const Real & r_value)
938 {
939  // Assign the default value so that it appears in the dump
940  std::ostringstream oss;
941  oss << r_value;
942  l_value = oss.str();
943 }
944 
945 template <>
946 void
947 InputParameters::setParamHelper<MaterialPropertyName, int>(const std::string & /*name*/,
948  MaterialPropertyName & l_value,
949  const int & r_value)
950 {
951  // Assign the default value so that it appears in the dump
952  std::ostringstream oss;
953  oss << r_value;
954  l_value = oss.str();
955 }
956 
957 template <>
958 const MooseEnum &
959 InputParameters::getParamHelper<MooseEnum>(const std::string & name,
960  const InputParameters & pars,
961  const MooseEnum *)
962 {
963  return pars.get<MooseEnum>(name);
964 }
965 
966 template <>
967 const MultiMooseEnum &
968 InputParameters::getParamHelper<MultiMooseEnum>(const std::string & name,
969  const InputParameters & pars,
970  const MultiMooseEnum *)
971 {
972  return pars.get<MultiMooseEnum>(name);
973 }
974 
975 void
976 InputParameters::setReservedValues(const std::string & name, const std::set<std::string> & reserved)
977 {
978  _reserved_values.insert(std::make_pair(name, reserved));
979 }
980 
981 std::set<std::string>
982 InputParameters::reservedValues(const std::string & name) const
983 {
984  auto it = _reserved_values.find(name);
985  if (it == _reserved_values.end())
986  return std::set<std::string>();
987  else
988  return it->second;
989 }
990 
991 void
992 InputParameters::checkParamName(const std::string & name) const
993 {
994  const static pcrecpp::RE valid("[\\w:/]+");
995  if (!valid.FullMatch(name))
996  mooseError("Invalid parameter name: '", name, "'");
997 }
void applySpecificParameters(const InputParameters &common, const std::vector< std::string > &include)
Method for applying common parameters.
const std::map< std::string, std::pair< std::string, std::string > > & getAutoBuildVectors() const
Returns the auto build vectors for all parameters.
bool _allow_copy
A flag for toggling the error message in the copy constructor.
bool isParamSetByUser(const std::string &name) const
Method returns true if the parameter was by the user.
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:350
std::vector< std::string > getSyntax(const std::string &name)
Get the syntax for a command-line parameter.
std::map< std::string, std::string > _custom_type
The custom type that will be printed in the YAML dump for a parameter if supplied.
InputParameters & operator=(const InputParameters &rhs)
bool hasCoupledValue(const std::string &coupling_name) const
Return whether or not the coupled variable exists.
void setDocString(const std::string &name, const std::string &doc)
Set the doc string of a parameter.
std::map< std::string, std::string > _deprecated_params
The list of deprecated params.
std::map< std::string, std::string > _doc_string
The documentation strings for each parameter.
std::vector< std::string > getVecMooseType(const std::string &name) const
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
std::map< std::string, std::string > _range_functions
The map of functions used for range checked parameters.
void mooseDeprecated(Args &&...args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
Definition: MooseError.h:202
bool isParamRequired(const std::string &name) const
Returns a boolean indicating whether the specified parameter is required or not.
InputParameters & operator+=(const InputParameters &rhs)
std::set< std::string > _required_params
The set of parameters that are required (i.e. will cause an abort if not supplied) ...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void applyParameter(const InputParameters &common, const std::string &common_name)
Apply values from a single parameter in common, to a single parameter stored in this object...
bool collapseSyntaxNesting() const
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.
std::string getDocString(const std::string &name) const
Returns the documentation string for the specified parameter name.
std::map< std::string, std::string > _group
The names of the parameters organized into groups.
void checkParamName(const std::string &name) const
Make sure the parameter name doesn&#39;t have any invalid characters.
std::set< std::string > _private_params
The set of parameters that will NOT appear in the the dump of the parser tree.
bool areAllRequiredParamsValid() const
This method returns true if all of the parameters in this object are valid (i.e.
std::map< std::string, Real > _default_coupled_value
The default value for optionally coupled variables.
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 _show_deprecated_message
Flag for disabling deprecated parameters message, this is used by applyParameters to avoid dumping me...
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.
bool _collapse_nesting
This parameter collapses one level of nesting in the syntax blocks.
bool mooseObjectSyntaxVisibility() const
const std::string & getDescription(const std::string &name)
Get the documentation string for a parameter.
bool hasDefaultPostprocessorValue(const std::string &name) const
Returns true if a default PostprocessorValue is defined.
Real PostprocessorValue
MOOSE typedefs.
Definition: MooseTypes.h:73
unsigned int get(unsigned int i) const
Indexing operator Operator to retrieve an item from the MultiMooseEnum.
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:37
bool isParamSetByAddParam(const std::string &name) const
Returns whether or not the parameter was set due to addParam.
void declareControllable(const std::string &name)
Declare the given parameters as controllable.
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...
bool isPrivate(const std::string &name) const
Returns a Boolean indicating whether the specified parameter is private or not.
std::string getMooseType(const std::string &name) const
Utility functions for retrieving one of the MooseTypes variables into the common "string" base class...
const PostprocessorValue & getDefaultPostprocessorValue(const std::string &name, bool suppress_error=false) const
Get the default value for a postprocessor added with addPostprocessor.
std::map< std::string, std::pair< std::string, std::string > > _auto_build_vectors
The map of auto build vectors (base_, 5 -> "base_0 base_1 base_2 base_3 base_4")
void applyParameters(const InputParameters &common, std::vector< std::string > exclude=std::vector< std::string >())
Method for applying common parameters.
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.
std::map< std::string, PostprocessorValue > _default_postprocessor_value
The default value for postprocessors.
Real defaultCoupledValue(const std::string &coupling_name) const
Get the default value for an optionally coupled variable.
std::set< std::string > _valid_params
The set of parameters either explicitly set or provided a default value when added Note: We do not st...
bool paramSetByUser(const std::string &name) const
Deprecated method.
std::set< std::string > _coupled_vars
The coupled variables set.
bool hasDefaultCoupledValue(const std::string &coupling_name) const
Return whether or not the requested parameter has a default coupled value.
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::set< std::string > _controllable_params
A list of parameters declared as controllable.
std::string getClassDescription() const
Returns the class description.
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, std::set< std::string > > _reserved_values
The reserved option names for a parameter.
std::string getGroupName(const std::string &param_name) const
This method retrieves the group name for the passed parameter name if one exists. ...
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.
InputParameters emptyInputParameters()
std::set< std::string > reservedValues(const std::string &name) const
Get a set of reserved parameter values.
const std::vector< std::string > & getBuildableTypes() const
Returns the list of buildable types as a std::vector<std::string>
std::map< std::string, std::vector< std::string > > _syntax
Syntax for command-line parameters.
std::set< std::string > _set_by_add_param
If a parameters value was set by addParam, and not set again, it will appear in this list (see applyP...
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...