20 #include "libmesh/utility.h" 21 #include "libmesh/simple_range.h" 36 _collapse_nesting(false),
37 _moose_object_syntax_visibility(true),
38 _show_deprecated_message(true),
44 : Parameters(), _show_deprecated_message(true), _allow_copy(true)
50 : _show_deprecated_message(true), _allow_copy(true)
95 metadata._set_by_add_param =
false;
98 if (!have_parameter<MooseEnum>(
name) && !have_parameter<MultiMooseEnum>(
name))
99 metadata._valid =
true;
109 auto emit_deprecation_message =
110 [
this](
const auto & deprecated_name,
const auto & deprecation_message)
116 Moose::out,
false,
true,
errorPrefix(deprecated_name),
":\n", deprecation_message,
"\n");
122 return emit_deprecation_message(
name,
123 "The parameter '" +
name +
"' is deprecated.\n" +
124 libmesh_map_find(
_params,
name)._deprecation_message);
127 return emit_deprecation_message(name_in, it->second.second);
145 const std::string &
name =
146 rhs.
get<std::string>(
"_object_name");
148 mooseError(
"Copying of the InputParameters object for the ",
150 " object is not allowed.\n\nThe likely cause for this error ",
151 "is having a constructor that does not use a const reference, all constructors\nfor " 152 "MooseObject based classes should be as follows:\n\n",
153 " MyObject::MyObject(const InputParameters & parameters);");
178 Parameters::operator+=(rhs);
182 for (
auto it = rhs.
_params.begin(); it != rhs.
_params.end(); ++it)
183 _params[it->first] = it->second;
203 const std::string & doc_string)
208 auto params_it =
_params.find(coupled_vars_it->second);
209 if (params_it ==
_params.end())
210 mooseError(
"There must have been a mistake in the construction of the new to deprecated " 211 "coupled vars map because the old name ",
212 coupled_vars_it->second,
213 " doesn't exist in the parameters data.");
215 params_it->second._doc_string = doc_string;
222 addParam<std::vector<VariableName>>(
name, doc_string);
225 metadata._coupled_default.assign(1,
value);
226 metadata._have_coupled_default =
true;
234 const std::vector<Real> & value,
235 const std::string & doc_string)
238 addParam<std::vector<VariableName>>(
name, doc_string);
241 metadata._coupled_default =
value;
242 metadata._have_coupled_default =
true;
251 addParam<std::vector<VariableName>>(
name, doc_string);
260 const std::string & new_name,
261 const std::string & removal_date )
268 auto params_it =
_params.find(new_name);
269 std::string doc_string;
270 if (params_it !=
_params.end())
271 doc_string = params_it->second._doc_string;
273 addParam<std::vector<VariableName>>(old_name, doc_string);
277 std::string deprecation_message =
278 "The coupled variable parameter '" + old_name +
"' has been deprecated";
279 if (!removal_date.empty())
280 deprecation_message +=
" and will be removed " + removal_date;
281 deprecation_message +=
". Please use the '" + new_name +
"' coupled variable parameter instead.";
282 _params[old_name]._deprecation_message = deprecation_message;
288 const std::string & base_name,
289 const std::string & num_name,
290 const std::string & doc_string)
292 addParam<std::vector<VariableName>>(
name, doc_string);
294 _params[
name]._autobuild_vecs = std::make_pair(base_name, num_name);
297 addParam<std::string>(base_name, doc_string +
" (base_name)");
298 addParam<unsigned int>(num_name, doc_string +
" (num_name)");
303 const std::string & base_name,
304 const std::string & num_name,
305 const std::string & doc_string)
307 addRequiredParam<std::vector<VariableName>>(
name, doc_string);
315 addRequiredParam<std::vector<VariableName>>(
name, doc_string);
324 std::string doc_string;
327 for (
const auto & ch : it->second._doc_string)
330 doc_string +=
" ... ";
345 mooseError(
"Unable to set the documentation string (using setDocString) for the \"",
347 "\" parameter, the parameter does not exist.");
348 it->second._doc_string = doc;
371 if (have_parameter<MooseEnum>(
name))
375 for (
auto it =
get<std::vector<MooseEnum>>(
name).begin();
376 it != get<std::vector<MooseEnum>>(
name).end();
382 else if (have_parameter<MultiMooseEnum>(
name))
383 return get<MultiMooseEnum>(
name).isValid();
384 else if (have_parameter<ExecFlagEnum>(
name))
407 for (
const auto & it : *
this)
424 std::vector<std::string> names;
425 MooseUtils::tokenize<std::string>(input_names, names, 1,
" ");
426 for (
auto & name_in : names)
432 map_iter->second._controllable =
true;
438 "' does not exist, thus cannot be marked as controllable.");
449 const std::set<ExecFlagType> &
459 InputParameters::set<std::string>(
"_moose_base") =
value;
460 _params[
"_moose_base"]._is_private =
true;
466 InputParameters::set<std::string>(
"_moose_warehouse_system_name") =
value;
467 _params[
"_moose_warehouse_system_name"]._is_private =
true;
473 mooseAssert(have_parameter<std::string>(
"_moose_warehouse_system_name"),
474 "SystemAttributeName is not available! Call 'registerSystemAttributeName' (usually " 475 "in the validParams function) before you try accessing it!");
476 return Parameters::get<std::string>(
"_moose_warehouse_system_name");
488 const std::string & name,
495 const std::vector<std::string> &
501 const std::vector<std::tuple<std::string,
533 #define dynamicCastRangeCheck(type, up_type, long_name, short_name, param, oss) \ 536 libMesh::Parameters::Value * val = MooseUtils::get(param); \ 537 InputParameters::Parameter<type> * scalar_p = \ 538 dynamic_cast<InputParameters::Parameter<type> *>(val); \ 540 rangeCheck<type, up_type>(long_name, short_name, scalar_p, oss); \ 541 InputParameters::Parameter<std::vector<type>> * vector_p = \ 542 dynamic_cast<InputParameters::Parameter<std::vector<type>> *>(val); \ 544 rangeCheck<type, up_type>(long_name, short_name, vector_p, oss); \ 547 #define checkMooseType(param_type, name) \ 548 if (have_parameter<param_type>(name) || have_parameter<std::vector<param_type>>(name)) \ 549 oss << inputLocation(param_name) << ": non-controllable type '" << type(name) \ 550 << "' for parameter '" << paramFullpath(param_name) << "' marked controllable"; 556 std::ostringstream oss;
558 for (
const auto & it : *
this)
568 oss <<
blockLocation() <<
": missing required parameter '" << parampath +
"/" + param_name
570 oss <<
"\tDoc String: \"" +
getDocString(param_name) +
"\"" << std::endl;
575 for (
const auto & it : *
this)
577 std::string long_name(parampath +
"/" + it.first);
579 dynamicCastRangeCheck(
Real,
Real, long_name, it.first, it.second, oss);
580 dynamicCastRangeCheck(
int,
long, long_name, it.first, it.second, oss);
581 dynamicCastRangeCheck(
long,
long, long_name, it.first, it.second, oss);
582 dynamicCastRangeCheck(
unsigned int,
long, long_name, it.first, it.second, oss);
590 <<
"' marked controllable";
592 checkMooseType(NonlinearVariableName, param_name);
593 checkMooseType(AuxVariableName, param_name);
594 checkMooseType(VariableName, param_name);
595 checkMooseType(BoundaryName, param_name);
596 checkMooseType(SubdomainName, param_name);
597 checkMooseType(PostprocessorName, param_name);
598 checkMooseType(VectorPostprocessorName, param_name);
599 checkMooseType(UserObjectName, param_name);
600 checkMooseType(MaterialPropertyName, param_name);
603 if (!oss.str().empty())
611 return !
_params.find(
name)->second._range_function.empty();
631 mooseError(
"No way to know if the parameter", param_name,
"has a default");
645 return _params.count(coupling_name) > 0 &&
_params.at(coupling_name)._have_coupled_default &&
652 _params[coupling_name]._coupled_default.resize(i + 1);
654 _params[coupling_name]._have_coupled_default =
true;
660 auto value_it =
_params.find(coupling_name);
662 if (value_it ==
_params.end() || !value_it->second._have_coupled_default)
663 mooseError(
"Attempted to retrieve default value for coupled variable '",
665 "' when none was provided. \n\nThere are three reasons why this may have " 666 "occurred:\n 1. The other version of params.addCoupledVar() should be used in order " 667 "to provide a default value. \n 2. This should have been a required coupled " 668 "variable added with params.addRequiredCoupledVar() \n 3. The call to get the " 669 "coupled value should have been properly guarded with isCoupled()\n");
671 return value_it->second._coupled_default.at(i);
677 auto value_it =
_params.find(coupling_name);
679 mooseError(
"Attempted to retrieve default value for coupled variable '",
681 "' when none was provided.");
682 return value_it->second._coupled_default.size();
685 std::map<std::string, std::pair<std::string, std::string>>
688 std::map<std::string, std::pair<std::string, std::string>> abv;
691 if (!it->second._autobuild_vecs.first.empty())
692 abv[it->first] = it->second._autobuild_vecs;
701 if (!_values.count(
name))
705 return "std::vector<VariableName>";
708 return _values.at(
name)->type();
717 if (have_parameter<VariableName>(
name))
718 var = get<VariableName>(
name);
719 else if (have_parameter<NonlinearVariableName>(
name))
720 var = get<NonlinearVariableName>(
name);
721 else if (have_parameter<AuxVariableName>(
name))
722 var = get<AuxVariableName>(
name);
723 else if (have_parameter<PostprocessorName>(
name))
724 var = get<PostprocessorName>(
name);
725 else if (have_parameter<VectorPostprocessorName>(
name))
726 var = get<VectorPostprocessorName>(
name);
727 else if (have_parameter<FunctionName>(
name))
728 var = get<FunctionName>(
name);
729 else if (have_parameter<UserObjectName>(
name))
730 var = get<UserObjectName>(
name);
731 else if (have_parameter<MaterialPropertyName>(
name))
732 var = get<MaterialPropertyName>(
name);
733 else if (have_parameter<std::string>(
name))
734 var = get<std::string>(
name);
739 std::vector<std::string>
743 std::vector<std::string> svars;
747 std::vector<VariableName> vars = get<std::vector<VariableName>>(
name);
748 std::copy(vars.begin(), vars.end(), std::back_inserter(svars));
752 std::vector<NonlinearVariableName> vars = get<std::vector<NonlinearVariableName>>(
name);
753 std::copy(vars.begin(), vars.end(), std::back_inserter(svars));
757 std::vector<AuxVariableName> vars = get<std::vector<AuxVariableName>>(
name);
758 std::copy(vars.begin(), vars.end(), std::back_inserter(svars));
762 std::vector<MaterialPropertyName> vars = get<std::vector<MaterialPropertyName>>(
name);
763 std::copy(vars.begin(), vars.end(), std::back_inserter(svars));
767 std::vector<std::string> vars = get<std::vector<std::string>>(
name);
768 std::copy(vars.begin(), vars.end(), std::back_inserter(svars));
776 const std::string group_name)
778 std::vector<std::string> elements;
783 std::set<std::string> param_names;
784 for (
const auto & it : *
this)
785 param_names.insert(it.first);
787 for (
const auto & param_name : elements)
788 if (
_params.count(param_name) > 0)
789 _params[param_name]._group = group_name;
791 mooseError(
"Unable to find a parameter with name: ",
793 " when adding to group ",
804 const std::vector<std::string> &
820 auto it =
_params.find(param_name);
822 return it->second._group;
823 return std::string();
828 const std::vector<std::string> exclude)
831 for (
const auto & it : common)
834 const std::string & common_name = it.first;
836 if (std::find(exclude.begin(), exclude.end(), common_name) != exclude.end())
843 for (std::set<std::string>::const_iterator it = common.coupledVarsBegin();
844 it != common.coupledVarsEnd();
848 const std::string var_name = *it;
851 if (std::find(exclude.begin(), exclude.end(), var_name) != exclude.end())
860 const std::vector<std::string> & include,
864 for (
const auto & it : common)
868 const std::string & common_name = it.first;
871 if (std::find(include.begin(), include.end(), common_name) == include.end())
878 for (std::set<std::string>::const_iterator it = common.coupledVarsBegin();
879 it != common.coupledVarsEnd();
883 const std::string var_name = *it;
886 if (std::find(include.begin(), include.end(), var_name) == include.end())
922 const std::string & common_name,
932 const bool local_exist = _values.find(local_name) != _values.end();
933 const bool local_set =
_params.count(local_name) > 0 && !
_params[local_name]._set_by_add_param;
934 const bool local_priv = allow_private ? false :
isPrivate(local_name);
938 const bool common_exist = common._values.find(common_name) != common._values.end();
939 const bool common_priv = allow_private ? false : common.
isPrivate(common_name);
940 const bool common_valid = common.
isParamValid(common_name);
948 if (local_exist && common_exist && common_valid && (!local_valid || !local_set) &&
949 (!common_priv || !local_priv))
952 _values[local_name] = common._values.find(common_name)->second->clone();
954 _params[local_name]._set_by_add_param =
955 libmesh_map_find(common.
_params, common_name)._set_by_add_param;
966 mooseDeprecated(
"paramSetByUser() is deprecated. Use isParamSetByUser() instead.");
991 return it->second._doc_string;
996 InputParameters::addRequiredParam<MooseEnum>(
const std::string &
name,
998 const std::string & doc_string)
1000 InputParameters::set<MooseEnum>(
name) = moose_enum;
1001 auto & metadata = _params[
name];
1002 metadata._required =
true;
1003 metadata._doc_string = doc_string;
1008 InputParameters::addRequiredParam<MultiMooseEnum>(
const std::string &
name,
1010 const std::string & doc_string)
1012 InputParameters::set<MultiMooseEnum>(
name) =
1014 auto & metadata = _params[
name];
1015 metadata._required =
true;
1016 metadata._doc_string = doc_string;
1021 InputParameters::addRequiredParam<std::vector<MooseEnum>>(
1022 const std::string &
name,
1023 const std::vector<MooseEnum> & moose_enums,
1024 const std::string & doc_string)
1026 InputParameters::set<std::vector<MooseEnum>>(
name) =
1028 auto & metadata = _params[
name];
1029 metadata._required =
true;
1030 metadata._doc_string = doc_string;
1035 InputParameters::addParam<MooseEnum>(
const std::string & ,
1036 const std::string & )
1038 mooseError(
"You must supply a MooseEnum object when using addParam, even if the parameter is not " 1044 InputParameters::addParam<MultiMooseEnum>(
const std::string & ,
1045 const std::string & )
1047 mooseError(
"You must supply a MultiMooseEnum object when using addParam, even if the parameter " 1048 "is not required!");
1053 InputParameters::addParam<std::vector<MooseEnum>>(
const std::string & ,
1054 const std::string & )
1056 mooseError(
"You must supply a vector of MooseEnum object(s) when using addParam, even if the " 1057 "parameter is not required!");
1062 InputParameters::addPrivateParam<MooseEnum>(
const std::string & )
1064 mooseError(
"You must supply a MooseEnum object when using addPrivateParam, even if the parameter " 1065 "is not required!");
1070 InputParameters::addPrivateParam<MultiMooseEnum>(
const std::string & )
1072 mooseError(
"You must supply a MultiMooseEnum object when using addPrivateParam, even if the " 1073 "parameter is not required!");
1078 InputParameters::addDeprecatedParam<MooseEnum>(
const std::string & ,
1079 const std::string & ,
1080 const std::string & )
1082 mooseError(
"You must supply a MooseEnum object and the deprecation string when using " 1083 "addDeprecatedParam, even if the parameter is not required!");
1088 InputParameters::addDeprecatedParam<MultiMooseEnum>(
const std::string & ,
1089 const std::string & ,
1090 const std::string & )
1092 mooseError(
"You must supply a MultiMooseEnum object and the deprecation string when using " 1093 "addDeprecatedParam, even if the parameter is not required!");
1098 InputParameters::addDeprecatedParam<std::vector<MooseEnum>>(
1099 const std::string & ,
1100 const std::string & ,
1101 const std::string & )
1103 mooseError(
"You must supply a vector of MooseEnum object(s) and the deprecation string when " 1104 "using addDeprecatedParam, even if the parameter is not required!");
1111 ". A functor is any of the following: a variable, a functor material property, a " 1112 "function, a post-processor, or a number.";
1117 InputParameters::setParamHelper<PostprocessorName, Real>(
const std::string & ,
1118 PostprocessorName & l_value,
1119 const Real & r_value)
1122 std::ostringstream oss;
1124 l_value = oss.str();
1129 InputParameters::setParamHelper<PostprocessorName, int>(
const std::string & ,
1130 PostprocessorName & l_value,
1131 const int & r_value)
1134 std::ostringstream oss;
1136 l_value = oss.str();
1141 InputParameters::setParamHelper<FunctionName, Real>(
const std::string & ,
1142 FunctionName & l_value,
1143 const Real & r_value)
1146 std::ostringstream oss;
1148 l_value = oss.str();
1153 InputParameters::setParamHelper<FunctionName, int>(
const std::string & ,
1154 FunctionName & l_value,
1155 const int & r_value)
1158 std::ostringstream oss;
1160 l_value = oss.str();
1165 InputParameters::setParamHelper<MaterialPropertyName, Real>(
const std::string & ,
1166 MaterialPropertyName & l_value,
1167 const Real & r_value)
1170 std::ostringstream oss;
1172 l_value = oss.str();
1177 InputParameters::setParamHelper<MaterialPropertyName, int>(
const std::string & ,
1178 MaterialPropertyName & l_value,
1179 const int & r_value)
1182 std::ostringstream oss;
1184 l_value = oss.str();
1189 InputParameters::setParamHelper<MooseFunctorName, Real>(
const std::string & ,
1190 MooseFunctorName & l_value,
1191 const Real & r_value)
1194 std::ostringstream oss;
1196 l_value = oss.str();
1201 InputParameters::setParamHelper<MooseFunctorName, int>(
const std::string & ,
1202 MooseFunctorName & l_value,
1203 const int & r_value)
1206 std::ostringstream oss;
1208 l_value = oss.str();
1213 InputParameters::getParamHelper<MooseEnum>(
const std::string & name_in,
1218 const auto name = pars.checkForRename(name_in);
1224 InputParameters::getParamHelper<MultiMooseEnum>(
const std::string & name_in,
1229 const auto name = pars.checkForRename(name_in);
1235 const std::set<std::string> & reserved)
1241 std::set<std::string>
1247 return std::set<std::string>();
1248 return it->second._reserved_values;
1254 const static pcrecpp::RE
valid(
"[\\w:/]+");
1264 mooseError(
"The parameter '",
name,
"' is not a command line parameter.");
1274 return it->second._ignore;
1278 std::set<std::string>
1281 std::set<std::string> names;
1283 if (it->second._group == group)
1284 names.emplace(it->first);
1288 std::set<std::string>
1291 std::set<std::string> param_set;
1293 param_set.emplace(it->first);
1297 std::set<std::string>
1300 std::set<std::string> controllable;
1302 if (it->second._controllable)
1303 controllable.emplace(it->first);
1304 return controllable;
1310 auto prefix = param +
":";
1318 const std::string & moose_object_with_var_param_name)
const 1321 std::string variable_name =
getMooseType(var_param_name);
1322 if (variable_name ==
"")
1332 moose_object_with_var_param_name,
1333 "' while retrieving value for '",
1335 "' parameter! Did you forget to set '",
1337 "' or set it to '' (empty string) by accident?");
1341 variable_name = vec[0];
1344 return variable_name;
1349 const std::string & new_name,
1350 const std::string & docstring,
1351 const std::string & removal_date)
1353 auto params_it =
_params.find(old_name);
1354 if (params_it ==
_params.end())
1355 mooseError(
"Requested to rename parameter '",
1357 "' but that parameter name doesn't exist in the parameters object.");
1359 auto new_metadata = std::move(params_it->second);
1360 if (!docstring.empty())
1361 new_metadata._doc_string = docstring;
1363 new_metadata._doc_string = params_it->second._doc_string;
1364 _params.emplace(new_name, std::move(new_metadata));
1367 auto values_it = _values.find(old_name);
1368 auto new_value = std::move(values_it->second);
1369 _values.emplace(new_name, std::move(new_value));
1370 _values.erase(values_it);
1372 std::string deprecation_message;
1373 if (!removal_date.empty())
1374 deprecation_message =
"'" + old_name +
"' has been deprecated and will be removed on " +
1375 removal_date +
". Please use '" + new_name +
"' instead.";
1383 const std::string & new_name,
1384 const std::string & docstring,
1385 const std::string & removal_date)
1389 mooseError(
"Requested to rename coupled variable '",
1391 "' but that coupled variable name doesn't exist in the parameters object.");
1401 const std::string & new_name,
1402 const std::string & new_docstring)
1409 const std::string & new_name,
1410 const std::string & new_docstring)
1417 const std::string & new_name,
1418 const std::string & removal_date)
1425 const std::string & new_name,
1426 const std::string & removal_date)
1435 return it->second.first;
1440 std::vector<std::string>
1443 mooseAssert(_values.find(param_name) != _values.end(),
1444 "The parameter we are searching for aliases for should exist in our parameter map");
1445 std::vector<std::string> aliases = {param_name};
1448 aliases.push_back(pr.second);
1456 object.mooseError(error);
std::string name(const ElemQuality q)
bool show_trace
Set to true (the default) to print the stack trace with error and warning messages - false to omit it...
void isValid(MooseObject *obj)
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...
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.
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
std::string trim(const std::string &str, const std::string &white_space=" \\\)
Standard scripting language trim function.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
void mooseDeprecated(Args &&... args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
void mooseDeprecatedStream(S &oss, const bool expired, const bool print_title, Args &&... args)
infix_ostream_iterator< T, charT, traits > & operator=(T const &item)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
std::vector< ElemQuality > valid(const ElemType t)
ExecFlagEnum execute_flags
Storage for the registered execute flags.