20 #include "libmesh/parameters.h" 22 #ifdef LIBMESH_HAVE_FPARSER 23 #include "libmesh/fparser.hh" 32 #include <unordered_map> 56 virtual void clear()
override;
90 virtual void set_attributes(
const std::string & name,
bool inserted_only)
override;
114 template <
typename T>
115 T &
set(
const std::string &
name,
bool quiet_mode =
false);
128 template <
typename T,
typename... Ts>
129 void setParameters(
const std::string & name,
const T & value, Ts... extra_input_parameters);
135 template <
typename T,
typename UP_T>
136 void rangeCheck(
const std::string & full_name,
137 const std::string & short_name,
138 InputParameters::Parameter<T> * param,
139 std::ostream & oss = Moose::out);
140 template <
typename T,
typename UP_T>
141 void rangeCheck(
const std::string & full_name,
142 const std::string & short_name,
143 InputParameters::Parameter<std::vector<T>> * param,
144 std::ostream & oss = Moose::out);
150 template <
typename T>
158 template <
typename T>
159 void addRequiredParam(
const std::string & name,
const std::string & doc_string);
165 template <
typename T>
167 addRequiredParam(
const std::string & name,
const T & moose_enum,
const std::string & doc_string);
176 template <
typename T,
typename S>
177 void addParam(
const std::string & name,
const S & value,
const std::string & doc_string);
178 template <
typename T>
179 void addParam(
const std::string & name,
const std::string & doc_string);
185 template <
typename T>
187 const std::initializer_list<typename T::value_type> & value,
188 const std::string & doc_string)
199 template <
typename T>
201 const std::string & parsed_function,
202 const std::string & doc_string);
203 template <
typename T>
206 const std::string & parsed_function,
207 const std::string & doc_string);
208 template <
typename T>
210 const std::string & parsed_function,
211 const std::string & doc_string);
219 template <
typename T>
221 const std::string & custom_type,
222 const std::string & doc_string);
223 template <
typename T>
226 const std::string & custom_type,
227 const std::string & doc_string);
228 template <
typename T>
230 const std::string & custom_type,
231 const std::string & doc_string);
232 template <
typename T>
234 const std::string & custom_type,
235 const std::string & doc_string,
236 const std::string & deprecation_msg);
244 template <
typename T>
246 template <
typename T>
258 template <
typename T>
260 const std::string & syntax,
261 const std::string & doc_string);
262 template <
typename T>
264 const std::string & syntax,
265 const std::string & doc_string);
266 template <
typename T>
268 const std::string & syntax,
270 const std::string & doc_string);
279 template <
typename T>
282 const std::string & doc_string,
283 const std::string & deprecation_message);
285 template <
typename T>
287 const std::string & doc_string,
288 const std::string & deprecation_message);
299 template <
typename T>
320 const std::string &
getDescription(
const std::string & name)
const;
333 std::string
getGroupName(
const std::string & param_name)
const;
341 template <
typename T>
348 template <
typename T>
355 template <
typename T>
363 void addCoupledVar(
const std::string & name,
const std::string & doc_string);
373 const std::string & new_name,
374 const std::string & removal_date =
"");
384 void addCoupledVar(
const std::string & name,
const Real value,
const std::string & doc_string);
395 const std::vector<Real> & value,
396 const std::string & doc_string);
417 const std::string & base_name,
418 const std::string & num_name,
419 const std::string & doc_string);
421 const std::string & base_name,
422 const std::string & num_name,
423 const std::string & doc_string);
431 std::string
getMooseType(
const std::string & name)
const;
432 std::vector<std::string>
getVecMooseType(
const std::string & name)
const;
448 std::string
getDocString(
const std::string & name)
const;
457 void setDocString(
const std::string & name,
const std::string & doc);
497 std::string
type(
const std::string & name)
const;
502 bool isPrivate(
const std::string & name)
const;
574 const std::string & name,
591 const std::vector<std::tuple<std::string,
618 using Parameters::operator=;
619 using Parameters::operator+=;
630 void checkParams(
const std::string & parsing_syntax);
665 bool hasDefault(
const std::string & param_name)
const;
703 void defaultCoupledValue(
const std::string & coupling_name, Real value,
unsigned int i = 0);
729 std::vector<std::string> exclude = std::vector<std::string>());
749 const std::vector<std::string> & include,
750 bool allow_private =
false);
764 const std::string & common_name,
765 bool allow_private =
false);
797 template <
typename T>
807 template <
typename R1,
809 typename V1 =
typename std::conditional<std::is_same<R1, MooseEnumItem>::value,
812 typename V2 =
typename std::conditional<std::is_same<R2, MooseEnumItem>::value,
815 std::vector<std::pair<R1, R2>>
get(
const std::string & param1,
const std::string & param2)
const;
836 void setReservedValues(
const std::string & name,
const std::set<std::string> & reserved);
842 std::set<std::string>
reservedValues(
const std::string & name)
const;
887 std::string
errorPrefix(
const std::string & param)
const;
896 return _params.at(param)._raw_val;
903 template <
typename T>
915 template <
typename T>
916 bool isType(
const std::string & name)
const;
924 std::string
varName(
const std::string & var_param_name,
925 const std::string & moose_object_with_var_param_name)
const;
935 const std::string & new_name,
936 const std::string & new_docstring);
945 const std::string & new_name,
946 const std::string & new_docstring);
949 const std::string & new_name,
950 const std::string & removal_date);
953 const std::string & new_name,
954 const std::string & removal_date);
970 template <
typename T>
971 const T &
get(std::string_view
name)
const;
980 template <
typename T>
990 template <
typename T>
992 const std::string & name,
993 const std::string & new_name =
"",
994 const std::string & new_description =
"");
1008 std::vector<std::string>
paramAliases(
const std::string & param_name)
const;
1030 const std::string & new_name,
1031 const std::string & docstring,
1032 const std::string & removal_date);
1035 const std::string & new_name,
1036 const std::string & docstring,
1037 const std::string & removal_date);
1090 if (
_params.count(param) == 0)
1091 mooseError(
"param '", param,
"' not present in InputParams");
1097 if (
_params.count(param) == 0)
1098 mooseError(
"param '", param,
"' not present in InputParams");
1122 template <
typename T,
typename S>
1123 void setParamHelper(
const std::string & name, T & l_value,
const S & r_value);
1133 template <
typename T>
1161 std::vector<std::tuple<std::string,
1201 template <
typename T>
1208 template <
typename T>
1215 checkConsistentType<T>(
name);
1217 T & result = this->Parameters::set<T>(
name);
1227 template <
typename T,
typename... Ts>
1231 Ts... extra_input_parameters)
1237 template <
typename T,
typename UP_T>
1240 const std::string & short_name,
1241 InputParameters::Parameter<std::vector<T>> * param,
1244 mooseAssert(param,
"Parameter is NULL");
1261 std::vector<std::string> vars;
1262 if (fp.ParseAndDeduceVariables(
_params[short_name]._range_function, vars) != -1)
1264 oss <<
"Error parsing expression: " <<
_params[short_name]._range_function <<
'\n';
1269 std::vector<UP_T> parbuf(vars.size());
1272 const std::vector<T> &
value = param->set();
1275 bool need_to_iterate =
false;
1280 for (
unsigned int j = 0; j < vars.size(); j++)
1282 if (vars[j] == short_name)
1284 if (
value.size() == 0)
1286 oss <<
"Range checking empty vector: " <<
_params[short_name]._range_function <<
'\n';
1290 parbuf[j] =
value[i];
1291 need_to_iterate =
true;
1293 else if (vars[j] == short_name +
"_size")
1294 parbuf[j] =
value.size();
1297 if (vars[j].substr(0, short_name.size() + 1) != short_name +
"_")
1299 oss <<
"Error parsing expression: " <<
_params[short_name]._range_function <<
'\n';
1302 std::istringstream iss(vars[j]);
1303 iss.seekg(short_name.size() + 1);
1306 if (iss >> index && iss.eof())
1308 if (index >=
value.size())
1310 oss <<
"Error parsing expression: " <<
_params[short_name]._range_function
1311 <<
"\nOut of range variable " << vars[j] <<
'\n';
1314 parbuf[j] =
value[index];
1318 oss <<
"Error parsing expression: " <<
_params[short_name]._range_function
1319 <<
"\nInvalid variable " << vars[j] <<
'\n';
1327 auto tmp_eps = fp.epsilon();
1329 UP_T result = fp.Eval(&parbuf[0]);
1330 fp.setEpsilon(tmp_eps);
1335 oss <<
"Error evaluating expression: " <<
_params[short_name]._range_function <<
'\n';
1341 oss <<
"Range check failed for parameter " << full_name
1342 <<
"\n\tExpression: " <<
_params[short_name]._range_function <<
"\n";
1343 if (need_to_iterate)
1344 oss <<
"\t Component: " << i <<
'\n';
1347 }
while (need_to_iterate && ++i <
value.size());
1350 template <
typename T,
typename UP_T>
1353 const std::string & short_name,
1354 InputParameters::Parameter<T> * param,
1357 mooseAssert(param,
"Parameter is NULL");
1364 if (fp.Parse(
_params[short_name]._range_function, short_name) != -1)
1366 oss <<
"Error parsing expression: " <<
_params[short_name]._range_function <<
'\n';
1372 auto tmp_eps = fp.epsilon();
1375 std::vector<UP_T>
value(1, param->set());
1376 UP_T result = fp.Eval(&
value[0]);
1377 fp.setEpsilon(tmp_eps);
1381 oss <<
"Error evaluating expression: " <<
_params[short_name]._range_function
1382 <<
"\nPerhaps you used the wrong variable name?\n";
1387 oss <<
"Range check failed for parameter " << full_name
1388 <<
"\n\tExpression: " <<
_params[short_name]._range_function <<
"\n\tValue: " <<
value[0]
1392 template <
typename T>
1395 const std::string & error_string)
const 1399 T param = this->get<T>(
name);
1405 return this->get<T>(
name);
1408 template <
typename T>
1413 checkConsistentType<T>(
name);
1415 InputParameters::insert<T>(
name);
1417 metadata._required =
true;
1418 if (std::is_same_v<T, MooseFunctorName>)
1421 metadata._doc_string = doc_string;
1424 template <
typename T>
1428 const std::string & )
1430 mooseError(
"You cannot call addRequiredParam and supply a default value for this type, please " 1431 "use addParam instead");
1434 template <
typename T,
typename S>
1439 checkConsistentType<T>(
name);
1441 T & l_value = InputParameters::set<T>(
name);
1443 if (std::is_same_v<T, MooseFunctorName>)
1446 metadata._doc_string = doc_string;
1454 metadata._set_by_add_param =
true;
1457 template <
typename T>
1462 checkConsistentType<T>(
name);
1464 InputParameters::insert<T>(
name);
1465 if (std::is_same_v<T, MooseFunctorName>)
1471 template <
typename T,
typename S>
1478 template <
typename T>
1485 if constexpr (std::is_same_v<T, bool>)
1487 else if constexpr (std::is_same_v<T, MooseEnum>)
1488 cl_data->argument_type = CommandLineMetadata::ArgumentType::REQUIRED;
1490 cl_data->argument_type = CommandLineMetadata::ArgumentType::OPTIONAL;
1493 template <
typename T>
1496 const std::string & parsed_function,
1497 const std::string & doc_string)
1499 addRequiredParam<T>(
name, doc_string);
1503 template <
typename T>
1507 const std::string & parsed_function,
1508 const std::string & doc_string)
1514 template <
typename T>
1517 const std::string & parsed_function,
1518 const std::string & doc_string)
1520 addParam<T>(
name, doc_string);
1524 template <
typename T>
1527 const std::string & custom_type,
1528 const std::string & doc_string)
1530 addRequiredParam<T>(
name, doc_string);
1534 template <
typename T>
1538 const std::string & custom_type,
1539 const std::string & doc_string)
1545 template <
typename T>
1548 const std::string & custom_type,
1549 const std::string & doc_string)
1551 addParam<T>(
name, doc_string);
1555 template <
typename T>
1558 const std::string & custom_type,
1559 const std::string & doc_string,
1560 const std::string & deprecation_message)
1563 addParam<T>(
name, doc_string);
1565 metadata._custom_type = custom_type;
1567 metadata._deprecation_message = deprecation_message;
1571 template <
typename T>
1576 checkConsistentType<T>(
name);
1578 InputParameters::insert<T>(
name);
1582 template <
typename T>
1587 checkConsistentType<T>(
name);
1591 metadata._is_private =
true;
1592 metadata._set_by_add_param =
true;
1595 template <
typename T>
1598 const std::string &
syntax,
1599 const std::string & doc_string)
1601 addRequiredParam<T>(
name, doc_string);
1605 template <
typename T>
1608 const std::string &
syntax,
1609 const std::string & doc_string)
1611 addParam<T>(
name, doc_string);
1615 template <
typename T>
1618 const std::string &
syntax,
1620 const std::string & doc_string)
1626 template <
typename T>
1633 InputParameters::const_iterator it = _values.find(
name);
1634 if (it == _values.end())
1639 if (!this->Parameters::have_parameter<T>(
name))
1644 ")\nbut the parameter already exists as type (",
1649 template <
typename T>
1654 if (!this->have_parameter<T>(
name))
1658 metadata._required =
false;
1659 metadata._is_private =
true;
1660 metadata._controllable =
false;
1663 template <
typename T>
1668 suppressParameter<T>(
name);
1672 template <
typename T>
1678 if (!this->have_parameter<T>(
name))
1684 template <
typename T>
1690 if (!this->have_parameter<T>(
name))
1691 mooseError(
"Unable to un-require nonexistent parameter: ",
name);
1696 template <
typename T>
1700 const std::string & doc_string,
1701 const std::string & deprecation_message)
1706 _params[
name]._deprecation_message = deprecation_message;
1710 template <
typename T>
1713 const std::string & doc_string,
1714 const std::string & deprecation_message)
1717 addParam<T>(
name, doc_string);
1719 _params[
name]._deprecation_message = deprecation_message;
1725 void InputParameters::addRequiredParam<MooseEnum>(
const std::string &
name,
1727 const std::string & doc_string);
1730 void InputParameters::addRequiredParam<MultiMooseEnum>(
const std::string &
name,
1732 const std::string & doc_string);
1735 void InputParameters::addRequiredParam<std::vector<MooseEnum>>(
1736 const std::string &
name,
1737 const std::vector<MooseEnum> & moose_enums,
1738 const std::string & doc_string);
1741 void InputParameters::addParam<MooseEnum>(
const std::string & ,
1742 const std::string & );
1745 void InputParameters::addParam<MultiMooseEnum>(
const std::string & ,
1746 const std::string & );
1749 void InputParameters::addParam<std::vector<MooseEnum>>(
const std::string & ,
1750 const std::string & );
1753 void InputParameters::addPrivateParam<MooseEnum>(
const std::string & );
1756 void InputParameters::addPrivateParam<MultiMooseEnum>(
const std::string & );
1759 void InputParameters::addDeprecatedParam<MooseEnum>(
const std::string &
name,
1760 const std::string & doc_string,
1761 const std::string & deprecation_message);
1764 void InputParameters::addDeprecatedParam<MultiMooseEnum>(
const std::string &
name,
1765 const std::string & doc_string,
1766 const std::string & deprecation_message);
1769 void InputParameters::addDeprecatedParam<std::vector<MooseEnum>>(
1770 const std::string &
name,
1771 const std::string & doc_string,
1772 const std::string & deprecation_message);
1776 void InputParameters::setParamHelper<PostprocessorName, Real>(
const std::string &
name,
1777 PostprocessorName & l_value,
1778 const Real & r_value);
1781 void InputParameters::setParamHelper<PostprocessorName, int>(
const std::string &
name,
1782 PostprocessorName & l_value,
1783 const int & r_value);
1786 void InputParameters::setParamHelper<FunctionName, Real>(
const std::string & ,
1787 FunctionName & l_value,
1788 const Real & r_value);
1791 void InputParameters::setParamHelper<FunctionName, int>(
const std::string & ,
1792 FunctionName & l_value,
1793 const int & r_value);
1796 void InputParameters::setParamHelper<MaterialPropertyName, Real>(
const std::string & ,
1797 MaterialPropertyName & l_value,
1798 const Real & r_value);
1801 void InputParameters::setParamHelper<MaterialPropertyName, int>(
const std::string & ,
1802 MaterialPropertyName & l_value,
1803 const int & r_value);
1806 void InputParameters::setParamHelper<MooseFunctorName, Real>(
const std::string & ,
1807 MooseFunctorName & l_value,
1808 const Real & r_value);
1811 void InputParameters::setParamHelper<MooseFunctorName, int>(
const std::string & ,
1812 MooseFunctorName & l_value,
1813 const int & r_value);
1815 template <
typename T>
1826 std::stringstream
err;
1827 err <<
"The parameter \"" <<
name <<
"\" is being retrieved before being set.";
1842 InputParameters::getParamHelper<MooseEnum>(
const std::string &
name,
1849 InputParameters::getParamHelper<MultiMooseEnum>(
const std::string &
name,
1854 template <
typename R1,
typename R2,
typename V1,
typename V2>
1855 std::vector<std::pair<R1, R2>>
1861 const auto & v1 = get<V1>(param1);
1862 const auto & v2 = get<V2>(param2);
1865 if (controllable.count(param1) || controllable.count(param2))
1869 " are controllable parameters and cannot be retireved using " 1870 "the MooseObject::getParam/InputParameters::get methods for pairs");
1872 if (v1.size() != v2.size())
1880 ") are of different lengths \n");
1882 std::vector<std::pair<R1, R2>> parameter_pairs;
1883 auto i1 = v1.begin();
1884 auto i2 = v2.begin();
1885 for (; i1 != v1.end() && i2 != v2.end(); ++i1, ++i2)
1886 parameter_pairs.emplace_back(std::make_pair(*i1, *i2));
1887 return parameter_pairs;
1892 template <
typename T>
1900 return have_parameter<T>(
name);
1903 template <
typename T>
1909 return Parameters::get<T>(
name);
1912 template <
typename T>
1918 return Parameters::have_parameter<T>(
name);
1921 template <
typename T>
1924 const std::string & name_in,
1925 const std::string & new_name,
1926 const std::string & new_description)
1929 const auto p_name = new_name.empty() ? name_in : new_name;
1933 "' parameter could not be transferred because it does not exist with type '",
1934 MooseUtils::prettyCppType<T>(),
1935 "' in the source parameters");
1936 if (
name != name_in)
1937 mooseWarning(
"The transferred parameter " + name_in +
" is deprecated in favor of " +
name +
1938 " in the source parameters. The new name should likely be used for the parameter " 1939 "transfer instead.");
1940 const std::string description =
1949 else if constexpr (std::is_same_v<MooseEnum, T> || std::is_same_v<MultiMooseEnum, T>)
1950 addRequiredParam<T>(p_name, source_params.
get<T>(
name), description);
1952 addRequiredRangeCheckedParam<T>(
1955 addRequiredParam<T>(p_name, description);
1968 std::vector<Real> coupled_values;
1977 addRangeCheckedParam<T>(p_name,
1984 else if constexpr (std::is_same_v<MooseEnum, T> || std::is_same_v<MultiMooseEnum, T>)
1985 addParam<T>(p_name, source_params.
get<T>(
name), description);
1989 addParam<T>(p_name, source_params.
get<T>(
name), description);
1991 addParam<T>(p_name, description);
1997 _params[p_name]._is_private =
true;
1999 _params[p_name]._controllable =
true;
std::string name(const ElemQuality q)
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 ...
RelationshipManagerType
Main types of Relationship Managers.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
Class that hold the whole problem being solved.
Storage for action instances.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
Every object that can be built by the factory should be derived from this class.
std::function< void(const InputParameters &, InputParameters &)> RelationshipManagerInputParameterCallback
The type for the callback to set RelationshipManager parameters.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
std::string demangle(const char *name)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
IntRange< T > make_range(T beg, T end)
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Class for parsing input files.
ExecFlagEnum execute_flags
Storage for the registered execute flags.