Go to the documentation of this file.
20 #include "libmesh/parameters.h"
22 #ifdef LIBMESH_HAVE_FPARSER
23 #include "libmesh/fparser.hh"
61 virtual void clear()
override;
77 virtual void set_attributes(
const std::string & name,
bool inserted_only)
override;
99 T &
set(
const std::string & name,
bool quiet_mode =
false);
105 template <
typename T,
typename UP_T>
106 void rangeCheck(
const std::string & full_name,
107 const std::string & short_name,
108 InputParameters::Parameter<T> * param,
109 std::ostream & oss = Moose::out);
110 template <
typename T,
typename UP_T>
111 void rangeCheck(
const std::string & full_name,
112 const std::string & short_name,
113 InputParameters::Parameter<std::vector<T>> * param,
114 std::ostream & oss = Moose::out);
120 template <
typename T>
128 template <
typename T>
129 void addRequiredParam(
const std::string & name,
const std::string & doc_string);
135 template <
typename T>
137 addRequiredParam(
const std::string & name,
const T & moose_enum,
const std::string & doc_string);
146 template <
typename T,
typename S>
147 void addParam(
const std::string & name,
const S & value,
const std::string & doc_string);
148 template <
typename T>
149 void addParam(
const std::string & name,
const std::string & doc_string);
158 template <
typename T>
160 const std::string & parsed_function,
161 const std::string & doc_string);
162 template <
typename T>
165 const std::string & parsed_function,
166 const std::string & doc_string);
167 template <
typename T>
169 const std::string & parsed_function,
170 const std::string & doc_string);
179 template <
typename T>
181 const std::string & custom_type,
182 const std::string & doc_string);
183 template <
typename T>
186 const std::string & custom_type,
187 const std::string & doc_string);
188 template <
typename T>
190 const std::string & custom_type,
191 const std::string & doc_string);
199 template <
typename T>
201 template <
typename T>
213 template <
typename T>
215 const std::string & syntax,
216 const std::string & doc_string);
217 template <
typename T>
219 const std::string & syntax,
220 const std::string & doc_string);
221 template <
typename T>
223 const std::string & syntax,
225 const std::string & doc_string);
234 template <
typename T>
237 const std::string & doc_string,
238 const std::string & deprecation_message);
240 template <
typename T>
242 const std::string & doc_string,
243 const std::string & deprecation_message);
254 template <
typename T>
260 std::vector<std::string>
getSyntax(
const std::string & name);
278 std::string
getGroupName(
const std::string & param_name)
const;
286 template <
typename T>
293 template <
typename T>
300 template <
typename T>
308 void addCoupledVar(
const std::string & name,
const std::string & doc_string);
318 void addCoupledVar(
const std::string & name,
const Real value,
const std::string & doc_string);
329 const std::vector<Real> & value,
330 const std::string & doc_string);
351 const std::string & base_name,
352 const std::string & num_name,
353 const std::string & doc_string);
355 const std::string & base_name,
356 const std::string & num_name,
357 const std::string & doc_string);
365 std::string
getMooseType(
const std::string & name)
const;
366 std::vector<std::string>
getVecMooseType(
const std::string & name)
const;
382 std::string
getDocString(
const std::string & name)
const;
391 void setDocString(
const std::string & name,
const std::string & doc);
426 std::string
type(
const std::string & name);
431 bool isPrivate(
const std::string & name)
const;
484 const std::string & name,
501 const std::vector<std::tuple<std::string,
528 using Parameters::operator=;
529 using Parameters::operator+=;
540 void checkParams(
const std::string & parsing_syntax);
596 void defaultCoupledValue(
const std::string & coupling_name, Real value,
unsigned int i = 0);
611 bool suppress_error =
false,
612 unsigned int index = 0)
const;
622 unsigned int index = 0);
651 std::vector<std::string> exclude = std::vector<std::string>());
671 const std::vector<std::string> & include,
672 bool allow_private =
false);
686 const std::string & common_name,
687 bool allow_private =
false);
719 template <
typename T>
723 template <
typename T>
724 static const std::vector<T> &
getParamHelper(
const std::string & name,
726 const std::vector<T> * the_type);
734 std::set<std::string> controllable;
736 if (it->second._controllable)
737 controllable.insert(it->first);
745 void setReservedValues(
const std::string & name,
const std::set<std::string> & reserved);
751 std::set<std::string>
reservedValues(
const std::string & name)
const;
802 template <
typename T>
818 return !
_params.find(pp_name)->second._vector_of_postprocessors;
877 mooseError(
"param '", param,
"' not present in InputParams");
883 mooseError(
"param '", param,
"' not present in InputParams");
907 template <
typename T,
typename S>
908 void setParamHelper(
const std::string & name, T & l_value,
const S & r_value);
925 _params[pp_name]._vector_of_postprocessors = b;
953 std::vector<std::tuple<std::string,
978 template <
typename T>
985 template <
typename T>
990 checkConsistentType<T>(name);
992 if (!this->have_parameter<T>(name))
993 _values[name] =
new Parameter<T>;
998 _params[name]._set_by_add_param =
true;
1002 return cast_ptr<Parameter<T> *>(_values[name])->
set();
1005 template <
typename T,
typename UP_T>
1008 const std::string & short_name,
1009 InputParameters::Parameter<std::vector<T>> * param,
1012 mooseAssert(param,
"Parameter is NULL");
1029 std::vector<std::string> vars;
1030 if (fp.ParseAndDeduceVariables(
_params[short_name]._range_function, vars) != -1)
1032 oss <<
"Error parsing expression: " <<
_params[short_name]._range_function <<
'\n';
1037 std::vector<UP_T> parbuf(vars.size());
1040 const std::vector<T> & value = param->set();
1043 bool need_to_iterate =
false;
1048 for (
unsigned int j = 0; j < vars.size(); j++)
1050 if (vars[j] == short_name)
1052 if (value.size() == 0)
1054 oss <<
"Range checking empty vector: " <<
_params[short_name]._range_function <<
'\n';
1058 parbuf[j] = value[i];
1059 need_to_iterate =
true;
1061 else if (vars[j] == short_name +
"_size")
1062 parbuf[j] = value.size();
1065 if (vars[j].substr(0, short_name.size() + 1) != short_name +
"_")
1067 oss <<
"Error parsing expression: " <<
_params[short_name]._range_function <<
'\n';
1070 std::istringstream iss(vars[j]);
1071 iss.seekg(short_name.size() + 1);
1074 if (iss >> index && iss.eof())
1076 if (index >= value.size())
1078 oss <<
"Error parsing expression: " <<
_params[short_name]._range_function
1079 <<
"\nOut of range variable " << vars[j] <<
'\n';
1082 parbuf[j] = value[index];
1086 oss <<
"Error parsing expression: " <<
_params[short_name]._range_function
1087 <<
"\nInvalid variable " << vars[j] <<
'\n';
1095 auto tmp_eps = fp.epsilon();
1097 UP_T result = fp.Eval(&parbuf[0]);
1098 fp.setEpsilon(tmp_eps);
1103 oss <<
"Error evaluating expression: " <<
_params[short_name]._range_function <<
'\n';
1109 oss <<
"Range check failed for parameter " << full_name
1110 <<
"\n\tExpression: " <<
_params[short_name]._range_function <<
"\n";
1111 if (need_to_iterate)
1112 oss <<
"\t Component: " << i <<
'\n';
1115 }
while (need_to_iterate && ++i < value.size());
1118 template <
typename T,
typename UP_T>
1121 const std::string & short_name,
1122 InputParameters::Parameter<T> * param,
1125 mooseAssert(param,
"Parameter is NULL");
1132 if (fp.Parse(
_params[short_name]._range_function, short_name) != -1)
1134 oss <<
"Error parsing expression: " <<
_params[short_name]._range_function <<
'\n';
1140 auto tmp_eps = fp.epsilon();
1143 std::vector<UP_T> value(1, param->set());
1144 UP_T result = fp.Eval(&value[0]);
1145 fp.setEpsilon(tmp_eps);
1149 oss <<
"Error evaluating expression: " <<
_params[short_name]._range_function
1150 <<
"\nPerhaps you used the wrong variable name?\n";
1155 oss <<
"Range check failed for parameter " << full_name
1156 <<
"\n\tExpression: " <<
_params[short_name]._range_function <<
"\n\tValue: " << value[0]
1160 template <
typename T>
1163 const std::string & error_string)
const
1165 T param = this->get<T>(name);
1170 mooseError(
"Parameter ", name,
" is NULL.\n", error_string);
1171 return this->get<T>(name);
1174 template <
typename T>
1179 checkConsistentType<T>(name);
1181 InputParameters::insert<T>(name);
1182 _params[name]._required =
true;
1183 _params[name]._doc_string = doc_string;
1186 template <
typename T>
1190 const std::string & )
1192 mooseError(
"You cannot call addRequiredParam and supply a default value for this type, please "
1193 "use addParam instead");
1196 template <
typename T,
typename S>
1201 checkConsistentType<T>(name);
1203 T & l_value = InputParameters::set<T>(name);
1204 _params[name]._doc_string = doc_string;
1212 _params[name]._set_by_add_param =
true;
1215 template <
typename T>
1220 checkConsistentType<T>(name);
1222 InputParameters::insert<T>(name);
1223 _params[name]._doc_string = doc_string;
1226 template <
typename T,
typename S>
1233 template <
typename T>
1236 const std::string & parsed_function,
1237 const std::string & doc_string)
1239 addRequiredParam<T>(name, doc_string);
1240 _params[name]._range_function = parsed_function;
1243 template <
typename T>
1247 const std::string & parsed_function,
1248 const std::string & doc_string)
1250 addParam<T>(name, value, doc_string);
1251 _params[name]._range_function = parsed_function;
1254 template <
typename T>
1257 const std::string & parsed_function,
1258 const std::string & doc_string)
1260 addParam<T>(name, doc_string);
1261 _params[name]._range_function = parsed_function;
1264 template <
typename T>
1267 const std::string & custom_type,
1268 const std::string & doc_string)
1270 addRequiredParam<T>(name, doc_string);
1271 _params[name]._custom_type = custom_type;
1274 template <
typename T>
1278 const std::string & custom_type,
1279 const std::string & doc_string)
1281 addParam<T>(name, value, doc_string);
1282 _params[name]._custom_type = custom_type;
1285 template <
typename T>
1288 const std::string & custom_type,
1289 const std::string & doc_string)
1291 addParam<T>(name, doc_string);
1292 _params[name]._custom_type = custom_type;
1295 template <
typename T>
1300 checkConsistentType<T>(name);
1302 InputParameters::insert<T>(name);
1303 _params[name]._is_private =
true;
1306 template <
typename T>
1311 checkConsistentType<T>(name);
1313 InputParameters::set<T>(name) = value;
1314 _params[name]._is_private =
true;
1315 _params[name]._set_by_add_param =
true;
1318 template <
typename T>
1321 const std::string & syntax,
1322 const std::string & doc_string)
1324 addRequiredParam<T>(name, doc_string);
1328 template <
typename T>
1331 const std::string & syntax,
1332 const std::string & doc_string)
1334 addParam<T>(name, doc_string);
1338 template <
typename T>
1341 const std::string & syntax,
1343 const std::string & doc_string)
1345 addParam<T>(name, value, doc_string);
1349 template <
typename T>
1354 InputParameters::const_iterator it = _values.find(name);
1355 if (it != _values.end() &&
dynamic_cast<const Parameter<T> *
>(it->second) == NULL)
1359 demangle(
typeid(T).name()),
1360 ")\nbut the parameter already exists as type (",
1365 template <
typename T>
1369 if (!this->have_parameter<T>(name))
1370 mooseError(
"Unable to suppress nonexistent parameter: ", name);
1372 _params[name]._required =
false;
1373 _params[name]._is_private =
true;
1376 template <
typename T>
1380 suppressParameter<T>(name);
1384 template <
typename T>
1388 if (!this->have_parameter<T>(name))
1389 mooseError(
"Unable to require nonexistent parameter: ", name);
1391 _params[name]._required =
true;
1394 template <
typename T>
1398 if (!this->have_parameter<T>(name))
1399 mooseError(
"Unable to un-require nonexistent parameter: ", name);
1401 _params[name]._required =
false;
1404 template <
typename T>
1408 const std::string & doc_string,
1409 const std::string & deprecation_message)
1412 addParam<T>(name, value, doc_string);
1414 _params[name]._deprecation_message = deprecation_message;
1418 template <
typename T>
1421 const std::string & doc_string,
1422 const std::string & deprecation_message)
1425 addParam<T>(name, doc_string);
1427 _params[name]._deprecation_message = deprecation_message;
1433 void InputParameters::addRequiredParam<MooseEnum>(
const std::string & name,
1435 const std::string & doc_string);
1438 void InputParameters::addRequiredParam<MultiMooseEnum>(
const std::string & name,
1440 const std::string & doc_string);
1443 void InputParameters::addRequiredParam<std::vector<MooseEnum>>(
1444 const std::string & name,
1445 const std::vector<MooseEnum> & moose_enums,
1446 const std::string & doc_string);
1449 void InputParameters::addParam<MooseEnum>(
const std::string & ,
1450 const std::string & );
1453 void InputParameters::addParam<MultiMooseEnum>(
const std::string & ,
1454 const std::string & );
1457 void InputParameters::addParam<std::vector<MooseEnum>>(
const std::string & ,
1458 const std::string & );
1461 void InputParameters::addPrivateParam<MooseEnum>(
const std::string & );
1464 void InputParameters::addPrivateParam<MultiMooseEnum>(
const std::string & );
1467 void InputParameters::addDeprecatedParam<MooseEnum>(
const std::string & name,
1468 const std::string & doc_string,
1469 const std::string & deprecation_message);
1472 void InputParameters::addDeprecatedParam<MultiMooseEnum>(
const std::string & name,
1473 const std::string & doc_string,
1474 const std::string & deprecation_message);
1477 void InputParameters::addDeprecatedParam<std::vector<MooseEnum>>(
1478 const std::string & name,
1479 const std::string & doc_string,
1480 const std::string & deprecation_message);
1484 void InputParameters::setParamHelper<PostprocessorName, Real>(
const std::string & name,
1485 PostprocessorName & l_value,
1486 const Real & r_value);
1489 void InputParameters::setParamHelper<PostprocessorName, int>(
const std::string & name,
1490 PostprocessorName & l_value,
1491 const int & r_value);
1494 void InputParameters::setParamHelper<FunctionName, Real>(
const std::string & ,
1495 FunctionName & l_value,
1496 const Real & r_value);
1499 void InputParameters::setParamHelper<FunctionName, int>(
const std::string & ,
1500 FunctionName & l_value,
1501 const int & r_value);
1504 void InputParameters::setParamHelper<MaterialPropertyName, Real>(
const std::string & ,
1505 MaterialPropertyName & l_value,
1506 const Real & r_value);
1509 void InputParameters::setParamHelper<MaterialPropertyName, int>(
const std::string & ,
1510 MaterialPropertyName & l_value,
1511 const int & r_value);
1513 void InputParameters::setHelper<std::vector<PostprocessorName>>(
const std::string & name);
1515 template <
typename T>
1520 mooseError(
"The parameter \"", name,
"\" is being retrieved before being set.\n");
1522 return pars.get<T>(name);
1529 const MooseEnum & InputParameters::getParamHelper<MooseEnum>(
const std::string & name,
1534 const MultiMooseEnum & InputParameters::getParamHelper<MultiMooseEnum>(
const std::string & name,
1538 template <
typename T>
1539 const std::vector<T> &
1542 const std::vector<T> *)
1544 return pars.get<std::vector<T>>(name);
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
ExecFlagEnum execute_flags
Storage for the registered execute flags.
std::function< void(const InputParameters &, InputParameters &)> RelationshipManagerInputParameterCallback
The type for the callback to set RelationshipManager parameters.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Every object that can be built by the factory should be derived from this class.
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 ...
Real PostprocessorValue
MOOSE typedefs.
Class that hold the whole problem being solved.
RelationshipManagerType
Main types of Relationship Managers.
Class for parsing input files.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Base class for MOOSE-based applications.