www.mooseframework.org
InputParameters.h
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 #pragma once
11 
12 // MOOSE includes
13 #include "MooseUtils.h"
14 #include "MooseError.h"
15 #include "MooseTypes.h"
16 #include "MultiMooseEnum.h"
17 #include "ExecFlagEnum.h"
18 #include "Conversion.h"
19 
20 #include "libmesh/parameters.h"
21 
22 #ifdef LIBMESH_HAVE_FPARSER
23 #include "libmesh/fparser.hh"
24 #else
25 template <typename T>
27 {
28 };
29 #endif
30 
31 #include <tuple>
32 
33 // Forward declarations
34 class Action;
35 class InputParameters;
36 class MooseApp;
37 class MooseEnum;
38 class MooseObject;
39 class MultiMooseEnum;
40 class Problem;
41 
46 template <class T>
48 
53 class InputParameters : public Parameters
54 {
55 public:
56  InputParameters(const InputParameters & rhs);
57  InputParameters(const Parameters & rhs);
58 
59  virtual ~InputParameters() = default;
60 
61  virtual void clear() override;
62 
67  void addClassDescription(const std::string & doc_string);
68 
72  std::string getClassDescription() const;
73 
77  virtual void set_attributes(const std::string & name, bool inserted_only) override;
78 
94  template <typename T>
95  T & set(const std::string & name, bool quiet_mode = false);
96 
101  template <typename T, typename UP_T>
102  void rangeCheck(const std::string & full_name,
103  const std::string & short_name,
104  InputParameters::Parameter<T> * param,
105  std::ostream & oss = Moose::out);
106  template <typename T, typename UP_T>
107  void rangeCheck(const std::string & full_name,
108  const std::string & short_name,
109  InputParameters::Parameter<std::vector<T>> * param,
110  std::ostream & oss = Moose::out);
111 
116  template <typename T>
117  T getCheckedPointerParam(const std::string & name, const std::string & error_string = "") const;
118 
124  template <typename T>
125  void addRequiredParam(const std::string & name, const std::string & doc_string);
126 
131  template <typename T>
132  void
133  addRequiredParam(const std::string & name, const T & moose_enum, const std::string & doc_string);
134 
141  template <typename T, typename S>
142  void addParam(const std::string & name, const S & value, const std::string & doc_string);
143  template <typename T>
144  void addParam(const std::string & name, const std::string & doc_string);
145 
150  template <typename T>
151  void addRequiredRangeCheckedParam(const std::string & name,
152  const std::string & parsed_function,
153  const std::string & doc_string);
154  template <typename T>
155  void addRangeCheckedParam(const std::string & name,
156  const T & value,
157  const std::string & parsed_function,
158  const std::string & doc_string);
159  template <typename T>
160  void addRangeCheckedParam(const std::string & name,
161  const std::string & parsed_function,
162  const std::string & doc_string);
163 
169  template <typename T>
170  void addRequiredCustomTypeParam(const std::string & name,
171  const std::string & custom_type,
172  const std::string & doc_string);
173  template <typename T>
174  void addCustomTypeParam(const std::string & name,
175  const T & value,
176  const std::string & custom_type,
177  const std::string & doc_string);
178  template <typename T>
179  void addCustomTypeParam(const std::string & name,
180  const std::string & custom_type,
181  const std::string & doc_string);
182 
189  template <typename T>
190  void addPrivateParam(const std::string & name, const T & value);
191  template <typename T>
192  void addPrivateParam(const std::string & name);
193 
203  template <typename T>
204  void addRequiredCommandLineParam(const std::string & name,
205  const std::string & syntax,
206  const std::string & doc_string);
207  template <typename T>
208  void addCommandLineParam(const std::string & name,
209  const std::string & syntax,
210  const std::string & doc_string);
211  template <typename T>
212  void addCommandLineParam(const std::string & name,
213  const std::string & syntax,
214  const T & value,
215  const std::string & doc_string);
216 
224  template <typename T>
225  void addDeprecatedParam(const std::string & name,
226  const T & value,
227  const std::string & doc_string,
228  const std::string & deprecation_message);
229 
230  template <typename T>
231  void addDeprecatedParam(const std::string & name,
232  const std::string & doc_string,
233  const std::string & deprecation_message);
234 
244  template <typename T>
245  void checkConsistentType(const std::string & name) const;
246 
250  std::vector<std::string> getSyntax(const std::string & name);
251 
255  const std::string & getDescription(const std::string & name);
256 
262  void addParamNamesToGroup(const std::string & space_delim_names, const std::string group_name);
263 
268  std::string getGroupName(const std::string & param_name) const;
269 
276  template <typename T>
277  void suppressParameter(const std::string & name);
278 
283  template <typename T>
284  void makeParamRequired(const std::string & name);
285 
290  template <typename T>
291  void makeParamNotRequired(const std::string & name);
292 
298  void addCoupledVar(const std::string & name, const std::string & doc_string);
299 
308  void addCoupledVar(const std::string & name, const Real value, const std::string & doc_string);
309 
318  void addCoupledVar(const std::string & name,
319  const std::vector<Real> & value,
320  const std::string & doc_string);
321 
323 
340  void addCoupledVarWithAutoBuild(const std::string & name,
341  const std::string & base_name,
342  const std::string & num_name,
343  const std::string & doc_string);
344  void addRequiredCoupledVarWithAutoBuild(const std::string & name,
345  const std::string & base_name,
346  const std::string & num_name,
347  const std::string & doc_string);
349 
355  std::string getMooseType(const std::string & name) const;
356  std::vector<std::string> getVecMooseType(const std::string & name) const;
357 
367  void addRequiredCoupledVar(const std::string & name, const std::string & doc_string);
368 
372  std::string getDocString(const std::string & name) const;
373 
381  void setDocString(const std::string & name, const std::string & doc);
382 
386  bool isParamRequired(const std::string & name) const;
387 
393  bool isParamValid(const std::string & name) const;
394 
400  bool isParamSetByAddParam(const std::string & name) const;
401 
405  bool isParamDeprecated(const std::string & name) const;
406 
411  bool areAllRequiredParamsValid() const;
412 
416  std::string type(const std::string & name);
417 
421  bool isPrivate(const std::string & name) const;
422 
426  void declareControllable(const std::string & name, std::set<ExecFlagType> execute_flags = {});
427 
431  void markControlled(const std::string & name);
432 
436  bool isControllable(const std::string & name);
437 
441  const std::set<ExecFlagType> & getControllableExecuteOnTypes(const std::string & name);
442 
448  void registerBase(const std::string & value);
449 
457  void registerBuildableTypes(const std::string & names);
458 
474  const std::string & name,
476  Moose::RelationshipManagerInputParameterCallback input_parameter_callback = nullptr);
477 
482 
486  const std::vector<std::string> & getBuildableTypes() const;
487 
491  const std::vector<std::tuple<std::string,
495 
497 
501  void collapseSyntaxNesting(bool collapse);
502  bool collapseSyntaxNesting() const;
504 
506 
510  void mooseObjectSyntaxVisibility(bool visibility);
511  bool mooseObjectSyntaxVisibility() const;
513 
515 
518  using Parameters::operator=;
519  using Parameters::operator+=;
523 
530  void checkParams(const std::string & parsing_syntax);
531 
536  inline std::set<std::string>::const_iterator coupledVarsBegin() const
537  {
538  return _coupled_vars.begin();
539  }
540  inline std::set<std::string>::const_iterator coupledVarsEnd() const
541  {
542  return _coupled_vars.end();
543  }
544 
548  const std::set<std::string> & getCoupledVariableParamNames() const { return _coupled_vars; }
549 
555  bool hasCoupledValue(const std::string & coupling_name) const;
556 
562  bool hasDefaultCoupledValue(const std::string & coupling_name) const;
563 
570  Real defaultCoupledValue(const std::string & coupling_name, unsigned int i = 0) const;
571 
577  unsigned int numberDefaultCoupledValues(const std::string & coupling_name) const;
578 
586  void defaultCoupledValue(const std::string & coupling_name, Real value, unsigned int i = 0);
587 
591  std::map<std::string, std::pair<std::string, std::string>> getAutoBuildVectors() const;
592 
599  const PostprocessorValue & getDefaultPostprocessorValue(const std::string & name,
600  bool suppress_error = false) const;
601 
607  void setDefaultPostprocessorValue(const std::string & name, const PostprocessorValue & value);
608 
614  bool hasDefaultPostprocessorValue(const std::string & name) const;
615 
633  void applyParameters(const InputParameters & common,
634  std::vector<std::string> exclude = std::vector<std::string>());
635 
653  void applySpecificParameters(const InputParameters & common,
654  const std::vector<std::string> & include,
655  bool allow_private = false);
656 
668  void applyParameter(const InputParameters & common,
669  const std::string & common_name,
670  bool allow_private = false);
671 
682  void applyCoupledVar(const InputParameters & common, const std::string & var_name);
683 
687  bool paramSetByUser(const std::string & name) const;
688 
693  bool isParamSetByUser(const std::string & name) const;
694 
696  /*
697  * These methods are here to retrieve parameters for scalar and vector types respectively. We will
698  * throw errors
699  * when returning most scalar types, but will allow retrieving empty vectors.
700  */
701  template <typename T>
702  static const T &
703  getParamHelper(const std::string & name, const InputParameters & pars, const T * the_type);
704 
705  template <typename T>
706  static const std::vector<T> & getParamHelper(const std::string & name,
707  const InputParameters & pars,
708  const std::vector<T> * the_type);
710 
714  std::set<std::string> getControllableParameters() const
715  {
716  std::set<std::string> controllable;
717  for (auto it = _params.begin(); it != _params.end(); ++it)
718  if (it->second._controllable)
719  controllable.insert(it->first);
720  return controllable;
721  }
722 
727  void setReservedValues(const std::string & name, const std::set<std::string> & reserved);
728 
733  std::set<std::string> reservedValues(const std::string & name) const;
734 
739  std::string & blockLocation() { return _block_location; };
740 
742 
746  std::string & blockFullpath() { return _block_fullpath; }
747  const std::string & blockFullpath() const { return _block_fullpath; }
749 
751 
755  const std::string & inputLocation(const std::string & param) const
756  {
757  return at(param)._input_location;
758  };
759  std::string & inputLocation(const std::string & param) { return at(param)._input_location; };
761 
763 
767  const std::string & paramFullpath(const std::string & param) const
768  {
769  return at(param)._param_fullpath;
770  };
771  std::string & paramFullpath(const std::string & param) { return at(param)._param_fullpath; };
773 
778  std::string & rawParamVal(const std::string & param) { return _params[param]._raw_val; };
779 
780 private:
781  // Private constructor so that InputParameters can only be created in certain places.
782  InputParameters();
783 
784  struct Metadata
785  {
786  std::string _doc_string;
788  std::string _custom_type;
789  std::vector<std::string> _cli_flag_names;
791  std::string _group;
793  std::string _range_function;
795  std::pair<std::string, std::string> _autobuild_vecs;
797  bool _required = false;
803  bool _valid = false;
805  bool _is_private = false;
806  bool _have_coupled_default = false;
808  std::vector<Real> _coupled_default = {0};
812  bool _set_by_add_param = false;
814  std::set<std::string> _reserved_values;
816  std::string _deprecation_message;
818  std::string _input_location;
820  std::string _param_fullpath;
822  std::string _raw_val;
824  bool _controllable = false;
826  std::set<ExecFlagType> _controllable_flags;
827  };
828 
829  Metadata & at(const std::string & param)
830  {
831  if (_params.count(param) == 0)
832  mooseError("param '", param, "' not present in InputParams");
833  return _params[param];
834  }
835  const Metadata & at(const std::string & param) const
836  {
837  if (_params.count(param) == 0)
838  mooseError("param '", param, "' not present in InputParams");
839  return _params.at(param);
840  }
841 
851  void allowCopy(bool status) { _allow_copy = status; }
852 
856  void checkParamName(const std::string & name) const;
857 
862  template <typename T, typename S>
863  void setParamHelper(const std::string & name, T & l_value, const S & r_value);
864 
866  std::string _block_location;
867 
869  std::string _block_fullpath;
870 
873  std::map<std::string, Metadata> _params;
874 
876  std::set<std::string> _coupled_vars;
877 
880  std::string _class_description;
881 
884  std::vector<std::string> _buildable_types;
885 
890  std::vector<std::tuple<std::string,
894 
898 
901 
905 
908 
909  // These are the only objects allowed to _create_ InputParameters
912 };
913 
914 // Template and inline function implementations
915 template <typename T>
916 T &
917 InputParameters::set(const std::string & name, bool quiet_mode)
918 {
919  checkParamName(name);
920  checkConsistentType<T>(name);
921 
922  if (!this->have_parameter<T>(name))
923  _values[name] = new Parameter<T>;
924 
925  set_attributes(name, false);
926 
927  if (quiet_mode)
928  _params[name]._set_by_add_param = true;
929 
930  return cast_ptr<Parameter<T> *>(_values[name])->set();
931 }
932 
933 template <typename T, typename UP_T>
934 void
935 InputParameters::rangeCheck(const std::string & full_name,
936  const std::string & short_name,
937  InputParameters::Parameter<std::vector<T>> * param,
938  std::ostream & oss)
939 {
940  mooseAssert(param, "Parameter is NULL");
941 
942  if (!isParamValid(short_name) || _params[short_name]._range_function.empty())
943  return;
944 
957  std::vector<std::string> vars;
958  if (fp.ParseAndDeduceVariables(_params[short_name]._range_function, vars) != -1) // -1 for success
959  {
960  oss << "Error parsing expression: " << _params[short_name]._range_function << '\n';
961  return;
962  }
963 
964  // Fparser parameter buffer
965  std::vector<UP_T> parbuf(vars.size());
966 
967  // parameter vector
968  const std::vector<T> & value = param->set();
969 
970  // iterate over all vector values (maybe ;)
971  bool need_to_iterate = false;
972  unsigned int i = 0;
973  do
974  {
975  // set parameters
976  for (unsigned int j = 0; j < vars.size(); j++)
977  {
978  if (vars[j] == short_name)
979  {
980  if (value.size() == 0)
981  {
982  oss << "Range checking empty vector: " << _params[short_name]._range_function << '\n';
983  return;
984  }
985 
986  parbuf[j] = value[i];
987  need_to_iterate = true;
988  }
989  else if (vars[j] == short_name + "_size")
990  parbuf[j] = value.size();
991  else
992  {
993  if (vars[j].substr(0, short_name.size() + 1) != short_name + "_")
994  {
995  oss << "Error parsing expression: " << _params[short_name]._range_function << '\n';
996  return;
997  }
998  std::istringstream iss(vars[j]);
999  iss.seekg(short_name.size() + 1);
1000 
1001  size_t index;
1002  if (iss >> index && iss.eof())
1003  {
1004  if (index >= value.size())
1005  {
1006  oss << "Error parsing expression: " << _params[short_name]._range_function
1007  << "\nOut of range variable " << vars[j] << '\n';
1008  return;
1009  }
1010  parbuf[j] = value[index];
1011  }
1012  else
1013  {
1014  oss << "Error parsing expression: " << _params[short_name]._range_function
1015  << "\nInvalid variable " << vars[j] << '\n';
1016  return;
1017  }
1018  }
1019  }
1020 
1021  // ensure range-checked input file parameter comparison functions
1022  // do absolute floating point comparisons instead of using a default epsilon.
1023  auto tmp_eps = fp.epsilon();
1024  fp.setEpsilon(0);
1025  UP_T result = fp.Eval(&parbuf[0]);
1026  fp.setEpsilon(tmp_eps);
1027 
1028  // test function using the parameters determined above
1029  if (fp.EvalError())
1030  {
1031  oss << "Error evaluating expression: " << _params[short_name]._range_function << '\n';
1032  return;
1033  }
1034 
1035  if (!result)
1036  {
1037  oss << "Range check failed for parameter " << full_name
1038  << "\n\tExpression: " << _params[short_name]._range_function << "\n";
1039  if (need_to_iterate)
1040  oss << "\t Component: " << i << '\n';
1041  }
1042 
1043  } while (need_to_iterate && ++i < value.size());
1044 }
1045 
1046 template <typename T, typename UP_T>
1047 void
1048 InputParameters::rangeCheck(const std::string & full_name,
1049  const std::string & short_name,
1050  InputParameters::Parameter<T> * param,
1051  std::ostream & oss)
1052 {
1053  mooseAssert(param, "Parameter is NULL");
1054 
1055  if (!isParamValid(short_name) || _params[short_name]._range_function.empty())
1056  return;
1057 
1058  // Parse the expression
1060  if (fp.Parse(_params[short_name]._range_function, short_name) != -1) // -1 for success
1061  {
1062  oss << "Error parsing expression: " << _params[short_name]._range_function << '\n';
1063  return;
1064  }
1065 
1066  // ensure range-checked input file parameter comparison functions
1067  // do absolute floating point comparisons instead of using a default epsilon.
1068  auto tmp_eps = fp.epsilon();
1069  fp.setEpsilon(0);
1070  // We require a non-const value for the implicit upscaling of the parameter type
1071  std::vector<UP_T> value(1, param->set());
1072  UP_T result = fp.Eval(&value[0]);
1073  fp.setEpsilon(tmp_eps);
1074 
1075  if (fp.EvalError())
1076  {
1077  oss << "Error evaluating expression: " << _params[short_name]._range_function
1078  << "\nPerhaps you used the wrong variable name?\n";
1079  return;
1080  }
1081 
1082  if (!result)
1083  oss << "Range check failed for parameter " << full_name
1084  << "\n\tExpression: " << _params[short_name]._range_function << "\n\tValue: " << value[0]
1085  << '\n';
1086 }
1087 
1088 template <typename T>
1089 T
1091  const std::string & error_string) const
1092 {
1093  T param = this->get<T>(name);
1094 
1095  // Note: You will receive a compile error on this line if you attempt to pass a non-pointer
1096  // template type to this method
1097  if (param == NULL)
1098  mooseError("Parameter ", name, " is NULL.\n", error_string);
1099  return this->get<T>(name);
1100 }
1101 
1102 template <typename T>
1103 void
1104 InputParameters::addRequiredParam(const std::string & name, const std::string & doc_string)
1105 {
1106  checkParamName(name);
1107  checkConsistentType<T>(name);
1108 
1109  InputParameters::insert<T>(name);
1110  _params[name]._required = true;
1111  _params[name]._doc_string = doc_string;
1112 }
1113 
1114 template <typename T>
1115 void
1116 InputParameters::addRequiredParam(const std::string & /*name*/,
1117  const T & /*value*/,
1118  const std::string & /*doc_string*/)
1119 {
1120  mooseError("You cannot call addRequiredParam and supply a default value for this type, please "
1121  "use addParam instead");
1122 }
1123 
1124 template <typename T, typename S>
1125 void
1126 InputParameters::addParam(const std::string & name, const S & value, const std::string & doc_string)
1127 {
1128  checkParamName(name);
1129  checkConsistentType<T>(name);
1130 
1131  T & l_value = InputParameters::set<T>(name);
1132  _params[name]._doc_string = doc_string;
1133 
1134  // Set the parameter now
1135  setParamHelper(name, l_value, value);
1136 
1137  /* Indicate the default value, as set via addParam, is being used. The parameter is removed from
1138  the list whenever
1139  it changes, see set_attributes */
1140  _params[name]._set_by_add_param = true;
1141 }
1142 
1143 template <typename T>
1144 void
1145 InputParameters::addParam(const std::string & name, const std::string & doc_string)
1146 {
1147  checkParamName(name);
1148  checkConsistentType<T>(name);
1149 
1150  InputParameters::insert<T>(name);
1151  _params[name]._doc_string = doc_string;
1152 }
1153 
1154 template <typename T, typename S>
1155 void
1156 InputParameters::setParamHelper(const std::string & /*name*/, T & l_value, const S & r_value)
1157 {
1158  l_value = r_value;
1159 }
1160 
1161 template <typename T>
1162 void
1164  const std::string & parsed_function,
1165  const std::string & doc_string)
1166 {
1167  addRequiredParam<T>(name, doc_string);
1168  _params[name]._range_function = parsed_function;
1169 }
1170 
1171 template <typename T>
1172 void
1173 InputParameters::addRangeCheckedParam(const std::string & name,
1174  const T & value,
1175  const std::string & parsed_function,
1176  const std::string & doc_string)
1177 {
1178  addParam<T>(name, value, doc_string);
1179  _params[name]._range_function = parsed_function;
1180 }
1181 
1182 template <typename T>
1183 void
1184 InputParameters::addRangeCheckedParam(const std::string & name,
1185  const std::string & parsed_function,
1186  const std::string & doc_string)
1187 {
1188  addParam<T>(name, doc_string);
1189  _params[name]._range_function = parsed_function;
1190 }
1191 
1192 template <typename T>
1193 void
1195  const std::string & custom_type,
1196  const std::string & doc_string)
1197 {
1198  addRequiredParam<T>(name, doc_string);
1199  _params[name]._custom_type = custom_type;
1200 }
1201 
1202 template <typename T>
1203 void
1204 InputParameters::addCustomTypeParam(const std::string & name,
1205  const T & value,
1206  const std::string & custom_type,
1207  const std::string & doc_string)
1208 {
1209  addParam<T>(name, value, doc_string);
1210  _params[name]._custom_type = custom_type;
1211 }
1212 
1213 template <typename T>
1214 void
1215 InputParameters::addCustomTypeParam(const std::string & name,
1216  const std::string & custom_type,
1217  const std::string & doc_string)
1218 {
1219  addParam<T>(name, doc_string);
1220  _params[name]._custom_type = custom_type;
1221 }
1222 
1223 template <typename T>
1224 void
1225 InputParameters::addPrivateParam(const std::string & name)
1226 {
1227  checkParamName(name);
1228  checkConsistentType<T>(name);
1229 
1230  InputParameters::insert<T>(name);
1231  _params[name]._is_private = true;
1232 }
1233 
1234 template <typename T>
1235 void
1236 InputParameters::addPrivateParam(const std::string & name, const T & value)
1237 {
1238  checkParamName(name);
1239  checkConsistentType<T>(name);
1240 
1241  InputParameters::set<T>(name) = value;
1242  _params[name]._is_private = true;
1243  _params[name]._set_by_add_param = true;
1244 }
1245 
1246 template <typename T>
1247 void
1249  const std::string & syntax,
1250  const std::string & doc_string)
1251 {
1252  addRequiredParam<T>(name, doc_string);
1253  MooseUtils::tokenize(syntax, _params[name]._cli_flag_names, 1, " \t\n\v\f\r");
1254 }
1255 
1256 template <typename T>
1257 void
1258 InputParameters::addCommandLineParam(const std::string & name,
1259  const std::string & syntax,
1260  const std::string & doc_string)
1261 {
1262  addParam<T>(name, doc_string);
1263  MooseUtils::tokenize(syntax, _params[name]._cli_flag_names, 1, " \t\n\v\f\r");
1264 }
1265 
1266 template <typename T>
1267 void
1268 InputParameters::addCommandLineParam(const std::string & name,
1269  const std::string & syntax,
1270  const T & value,
1271  const std::string & doc_string)
1272 {
1273  addParam<T>(name, value, doc_string);
1274  MooseUtils::tokenize(syntax, _params[name]._cli_flag_names, 1, " \t\n\v\f\r");
1275 }
1276 
1277 template <typename T>
1278 void
1279 InputParameters::checkConsistentType(const std::string & name) const
1280 {
1281  // Do we have a paremeter with the same name but a different type?
1282  InputParameters::const_iterator it = _values.find(name);
1283  if (it != _values.end() && dynamic_cast<const Parameter<T> *>(it->second) == NULL)
1284  mooseError("Attempting to set parameter \"",
1285  name,
1286  "\" with type (",
1287  demangle(typeid(T).name()),
1288  ")\nbut the parameter already exists as type (",
1289  it->second->type(),
1290  ")");
1291 }
1292 
1293 template <typename T>
1294 void
1295 InputParameters::suppressParameter(const std::string & name)
1296 {
1297  if (!this->have_parameter<T>(name))
1298  mooseError("Unable to suppress nonexistent parameter: ", name);
1299 
1300  _params[name]._required = false;
1301  _params[name]._is_private = true;
1302 }
1303 
1304 template <typename T>
1305 void
1306 InputParameters::makeParamRequired(const std::string & name)
1307 {
1308  if (!this->have_parameter<T>(name))
1309  mooseError("Unable to require nonexistent parameter: ", name);
1310 
1311  _params[name]._required = true;
1312 }
1313 
1314 template <typename T>
1315 void
1316 InputParameters::makeParamNotRequired(const std::string & name)
1317 {
1318  if (!this->have_parameter<T>(name))
1319  mooseError("Unable to un-require nonexistent parameter: ", name);
1320 
1321  _params[name]._required = false;
1322 }
1323 
1324 template <typename T>
1325 void
1326 InputParameters::addDeprecatedParam(const std::string & name,
1327  const T & value,
1328  const std::string & doc_string,
1329  const std::string & deprecation_message)
1330 {
1331  _show_deprecated_message = false;
1332  addParam<T>(name, value, doc_string);
1333 
1334  _params[name]._deprecation_message = deprecation_message;
1335  _show_deprecated_message = true;
1336 }
1337 
1338 template <typename T>
1339 void
1340 InputParameters::addDeprecatedParam(const std::string & name,
1341  const std::string & doc_string,
1342  const std::string & deprecation_message)
1343 {
1344  _show_deprecated_message = false;
1345  addParam<T>(name, doc_string);
1346 
1347  _params[name]._deprecation_message = deprecation_message;
1348  _show_deprecated_message = true;
1349 }
1350 
1351 // Forward declare MooseEnum specializations for add*Param
1352 template <>
1353 void InputParameters::addRequiredParam<MooseEnum>(const std::string & name,
1354  const MooseEnum & moose_enum,
1355  const std::string & doc_string);
1356 
1357 template <>
1358 void InputParameters::addRequiredParam<MultiMooseEnum>(const std::string & name,
1359  const MultiMooseEnum & moose_enum,
1360  const std::string & doc_string);
1361 
1362 template <>
1363 void InputParameters::addRequiredParam<std::vector<MooseEnum>>(
1364  const std::string & name,
1365  const std::vector<MooseEnum> & moose_enums,
1366  const std::string & doc_string);
1367 
1368 template <>
1369 void InputParameters::addParam<MooseEnum>(const std::string & /*name*/,
1370  const std::string & /*doc_string*/);
1371 
1372 template <>
1373 void InputParameters::addParam<MultiMooseEnum>(const std::string & /*name*/,
1374  const std::string & /*doc_string*/);
1375 
1376 template <>
1377 void InputParameters::addParam<std::vector<MooseEnum>>(const std::string & /*name*/,
1378  const std::string & /*doc_string*/);
1379 
1380 template <>
1381 void InputParameters::addPrivateParam<MooseEnum>(const std::string & /*name*/);
1382 
1383 template <>
1384 void InputParameters::addPrivateParam<MultiMooseEnum>(const std::string & /*name*/);
1385 
1386 template <>
1387 void InputParameters::addDeprecatedParam<MooseEnum>(const std::string & name,
1388  const std::string & doc_string,
1389  const std::string & deprecation_message);
1390 
1391 template <>
1392 void InputParameters::addDeprecatedParam<MultiMooseEnum>(const std::string & name,
1393  const std::string & doc_string,
1394  const std::string & deprecation_message);
1395 
1396 template <>
1397 void InputParameters::addDeprecatedParam<std::vector<MooseEnum>>(
1398  const std::string & name,
1399  const std::string & doc_string,
1400  const std::string & deprecation_message);
1401 
1402 // Forward declare specializations for setParamHelper
1403 template <>
1404 void InputParameters::setParamHelper<PostprocessorName, Real>(const std::string & name,
1405  PostprocessorName & l_value,
1406  const Real & r_value);
1407 
1408 template <>
1409 void InputParameters::setParamHelper<PostprocessorName, int>(const std::string & name,
1410  PostprocessorName & l_value,
1411  const int & r_value);
1412 
1413 template <>
1414 void InputParameters::setParamHelper<FunctionName, Real>(const std::string & /*name*/,
1415  FunctionName & l_value,
1416  const Real & r_value);
1417 
1418 template <>
1419 void InputParameters::setParamHelper<FunctionName, int>(const std::string & /*name*/,
1420  FunctionName & l_value,
1421  const int & r_value);
1422 
1423 template <>
1424 void InputParameters::setParamHelper<MaterialPropertyName, Real>(const std::string & /*name*/,
1425  MaterialPropertyName & l_value,
1426  const Real & r_value);
1427 
1428 template <>
1429 void InputParameters::setParamHelper<MaterialPropertyName, int>(const std::string & /*name*/,
1430  MaterialPropertyName & l_value,
1431  const int & r_value);
1432 
1433 template <typename T>
1434 const T &
1435 InputParameters::getParamHelper(const std::string & name, const InputParameters & pars, const T *)
1436 {
1437  if (!pars.isParamValid(name))
1438  mooseError("The parameter \"", name, "\" is being retrieved before being set.\n");
1439 
1440  return pars.get<T>(name);
1441 }
1442 
1443 // Declare specializations so we don't fall back on the generic
1444 // implementation, but the definition will be in InputParameters.C so
1445 // we won't need to bring in *MooseEnum header files here.
1446 template <>
1447 const MooseEnum & InputParameters::getParamHelper<MooseEnum>(const std::string & name,
1448  const InputParameters & pars,
1449  const MooseEnum *);
1450 
1451 template <>
1452 const MultiMooseEnum & InputParameters::getParamHelper<MultiMooseEnum>(const std::string & name,
1453  const InputParameters & pars,
1454  const MultiMooseEnum *);
1455 
1456 template <typename T>
1457 const std::vector<T> &
1458 InputParameters::getParamHelper(const std::string & name,
1459  const InputParameters & pars,
1460  const std::vector<T> *)
1461 {
1462  return pars.get<std::vector<T>>(name);
1463 }
1464 
1466 
1467 template <class T>
1470 {
1471  static_assert(false && sizeof(T), "Missing validParams declaration!");
1472 
1473  mooseError("Missing validParams declaration!");
1474 }
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.
void clearRelationshipManagers()
Clears all currently registered RelationshipManagers.
static const T & getParamHelper(const std::string &name, const InputParameters &pars, const T *the_type)
std::string _input_location
original location of parameter (i.e. filename,linenum) - used for nice error messages.
void addRequiredRangeCheckedParam(const std::string &name, const std::string &parsed_function, const std::string &doc_string)
These methods add an range checked parameters.
bool hasCoupledValue(const std::string &coupling_name) const
Return whether or not the coupled variable exists.
std::string _raw_val
raw token text for a parameter - usually only set for filepath type params.
Storage container for all InputParamter objects.
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
void addDeprecatedParam(const std::string &name, const T &value, const std::string &doc_string, const std::string &deprecation_message)
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.
std::string & rawParamVal(const std::string &param)
Get/set a string representing the raw, unmodified token text for the given param. ...
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.
std::string _custom_type
The custom type that will be printed in the YAML dump for a parameter if supplied.
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.
void addPrivateParam(const std::string &name, const T &value)
These method add a parameter to the InputParameters object which can be retrieved like any other para...
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::set< ExecFlagType > _controllable_flags
Controllable execute flag restriction.
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>
void addCustomTypeParam(const std::string &name, const T &value, const std::string &custom_type, const std::string &doc_string)
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
Class that hold the whole problem being solved.
Definition: Problem.h:24
T getCheckedPointerParam(const std::string &name, const std::string &error_string="") const
Verifies that the requested parameter exists and is not NULL and returns it to the caller...
InputParameters & operator+=(const InputParameters &rhs)
const std::set< std::string > & getCoupledVariableParamNames() const
Return the coupled variable parameter names.
Base class for MOOSE-based applications.
Definition: MooseApp.h:59
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::set< std::string >::const_iterator coupledVarsBegin() const
Methods returning iterators to the coupled variables names stored in this InputParameters object...
std::string & paramFullpath(const std::string &param)
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 ...
friend InputParameters emptyInputParameters()
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 checkConsistentType(const std::string &name) const
This method checks to make sure that we aren&#39;t adding a parameter with the same name but a different ...
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.
std::set< std::string > _reserved_values
The reserved option names for a parameter.
void addRequiredCommandLineParam(const std::string &name, const std::string &syntax, const std::string &doc_string)
Add parameters for retrieval from the command line.
Base class for actions.
Definition: Action.h:35
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
InputParameters emptyInputParameters()
void checkParamName(const std::string &name) const
Make sure the parameter name doesn&#39;t have any invalid characters.
void suppressParameter(const std::string &name)
This method suppresses an inherited parameter so that it isn&#39;t required or valid in the derived class...
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.
InputParameters validParams()
This is the templated validParams() function that every MooseObject-derived class is required to spec...
void registerBase(const std::string &value)
This method must be called from every base "Moose System" to create linkage with the Action System...
std::string _param_fullpath
full HIT path of the parameter from the input file - used for nice error messages.
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 _required
True for parameters that are required (i.e. will cause an abort if not supplied)
std::string _range_function
The map of functions used for range checked parameters.
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::set< std::string >::const_iterator coupledVarsEnd() const
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:42
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.
void markControlled(const std::string &name)
Marker a parameter that has been changed by the Control system (this is for output purposes) ...
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 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 rangeCheck(const std::string &full_name, const std::string &short_name, InputParameters::Parameter< T > *param, std::ostream &oss=Moose::out)
Runs a range on the supplied parameter if it exists and throws an error if that check fails...
std::vector< Real > _coupled_default
The default value for optionally coupled variables.
void addCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
PostprocessorValue _default_postprocessor_val
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.
void makeParamNotRequired(const std::string &name)
Changes the parameter to not be required.
void allowCopy(bool status)
Toggle the availability of the copy constructor.
bool isParamSetByUser(const std::string &name) const
Method returns true if the parameter was by the user.
Metadata & at(const std::string &param)
std::string _deprecation_message
If non-empty, this parameter is deprecated.
void addCommandLineParam(const std::string &name, const std::string &syntax, const std::string &doc_string)
const std::string & blockFullpath() const
bool _is_private
The set of parameters that will NOT appear in the the dump of the parser tree.
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.
virtual ~InputParameters()=default
std::string getGroupName(const std::string &param_name) const
This method retrieves the group name for the passed parameter name if one exists. ...
const Metadata & at(const std::string &param) const
std::pair< std::string, std::string > _autobuild_vecs
directions for auto build vectors (base_, 5) -> "base_0 base_1 base_2 base_3 base_4") ...
bool paramSetByUser(const std::string &name) const
Deprecated method.
void makeParamRequired(const std::string &name)
Changes the parameter to be required.
bool _valid
Whether the parameter is either explicitly set or provided a default value when added Note: We do not...
void addRequiredCustomTypeParam(const std::string &name, const std::string &custom_type, const std::string &doc_string)
These methods add an option parameter and with a customer type to the InputParameters object...
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.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
bool _moose_object_syntax_visibility
This parameter hides derived MOOSE object types from appearing in syntax dumps.
virtual void clear() override
void addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
bool _controllable
True if the parameters is controllable.
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.
bool _set_by_add_param
True if a parameters value was set by addParam, and not set again.
void setParamHelper(const std::string &name, T &l_value, const S &r_value)
This method is called when adding a Parameter with a default value, can be specialized for non-matchi...
std::vector< std::string > getVecMooseType(const std::string &name) const
std::vector< std::string > _cli_flag_names
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.
std::string _group
The names of the parameters organized into groups.
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.
std::string & inputLocation(const std::string &param)