Skip to content

Commit

Permalink
Merge pull request idaholab#25245 from MengnanLi91/vector_parameter_d…
Browse files Browse the repository at this point in the history
…efault_value

Fix inconsistent handling for optional input parameters
  • Loading branch information
GiudGiud authored Nov 22, 2023
2 parents 0e39829 + 49ab69f commit 645eca9
Show file tree
Hide file tree
Showing 192 changed files with 739 additions and 504 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -321,5 +321,6 @@ share/
/modules/reactor/unit/reactor-unit.yaml
/modules/rdg/unit/rdg-unit.yaml
/modules/fsi/unit/fsi-unit.yaml
/modules/misc/misc.yaml
/tutorials/tutorial01_app_development/*/babbler.yaml
/tutorials/darcy_thermo_mech/*/darcy_thermo_mech.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ MaterialDerivativeTestKernelBase<T>::validParams()
params.deprecateCoupledVar("args", "coupled_variables", "02/07/2024");
params.addParam<std::vector<SymbolName>>(
"derivative",
{},
"Select derivative to test derivatives of (leave empty for checking "
"derivatives of the original material property)");
return params;
Expand Down
1 change: 1 addition & 0 deletions framework/include/utils/IndexableProperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ IndexableProperty<T, is_ad>::validParams()
"The name of the material property");
params.template addParam<std::vector<unsigned int>>(
"component",
{},
"Index vector of the scalar component to extract from "
"the material property (empty for scalar properties)");
return params;
Expand Down
54 changes: 27 additions & 27 deletions framework/include/utils/InputParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -763,16 +763,13 @@ class InputParameters : public Parameters
/*
* These methods are here to retrieve parameters for scalar and vector types respectively. We will
* throw errors
* when returning most scalar types, but will allow retrieving empty vectors.
* when returning most scalar and vector types.
*/
template <typename T>
static const T &
getParamHelper(const std::string & name, const InputParameters & pars, const T * the_type);

template <typename T>
static const std::vector<T> & getParamHelper(const std::string & name,
const InputParameters & pars,
const std::vector<T> * the_type);
static const T & getParamHelper(const std::string & name,
const InputParameters & pars,
const T * the_type,
const MooseObject * moose_object = nullptr);
///@}

using Parameters::get;
Expand Down Expand Up @@ -1020,6 +1017,8 @@ class InputParameters : public Parameters
const std::string & docstring,
const std::string & removal_date);

static void callMooseErrorHelper(const MooseObject & object, const std::string & error);

struct Metadata
{
std::string _doc_string;
Expand Down Expand Up @@ -1757,12 +1756,20 @@ template <typename T>
const T &
InputParameters::getParamHelper(const std::string & name_in,
const InputParameters & pars,
const T *)
const T *,
const MooseObject * moose_object /* = nullptr */)
{
const auto name = pars.checkForRename(name_in);

if (!pars.isParamValid(name))
mooseError("The parameter \"", name, "\" is being retrieved before being set.\n");
{
std::stringstream err;
err << "The parameter \"" << name << "\" is being retrieved before being set.";
if (moose_object)
callMooseErrorHelper(*moose_object, err.str());
else
mooseError(err.str());
}

return pars.get<T>(name);
}
Expand All @@ -1771,25 +1778,18 @@ InputParameters::getParamHelper(const std::string & name_in,
// implementation, but the definition will be in InputParameters.C so
// we won't need to bring in *MooseEnum header files here.
template <>
const MooseEnum & InputParameters::getParamHelper<MooseEnum>(const std::string & name,
const InputParameters & pars,
const MooseEnum *);
const MooseEnum &
InputParameters::getParamHelper<MooseEnum>(const std::string & name,
const InputParameters & pars,
const MooseEnum *,
const MooseObject * moose_object /* = nullptr */);

template <>
const MultiMooseEnum & InputParameters::getParamHelper<MultiMooseEnum>(const std::string & name,
const InputParameters & pars,
const MultiMooseEnum *);

template <typename T>
const std::vector<T> &
InputParameters::getParamHelper(const std::string & name_in,
const InputParameters & pars,
const std::vector<T> *)
{
const auto name = pars.checkForRename(name_in);

return pars.get<std::vector<T>>(name);
}
const MultiMooseEnum &
InputParameters::getParamHelper<MultiMooseEnum>(const std::string & name,
const InputParameters & pars,
const MultiMooseEnum *,
const MooseObject * moose_object /* = nullptr */);

template <typename R1, typename R2, typename V1, typename V2>
std::vector<std::pair<R1, R2>>
Expand Down
3 changes: 2 additions & 1 deletion framework/src/actions/AdaptivityAction.C
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ AdaptivityAction::validParams()
"Determines whether information about the mesh is printed when adaptivity occurs",
"Use the Console output parameter 'print_mesh_changed_info'");
params.addParam<std::vector<std::string>>(
"weight_names", "List of names of variables that will be associated with weight_values");
"weight_names", {}, "List of names of variables that will be associated with weight_values");
params.addParam<std::vector<Real>>(
"weight_values",
{},
"List of values between 0 and 1 to weight the associated weight_names error by");
params.addParam<bool>(
"show_initial_progress", true, "Show the progress of the initial adaptivity");
Expand Down
2 changes: 1 addition & 1 deletion framework/src/actions/AddPeriodicBCAction.C
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ AddPeriodicBCAction::validParams()
params.addParam<std::vector<std::string>>("inv_transform_func",
"Functions that specify the inverse transformation");

params.addParam<std::vector<VariableName>>("variable", "Variable for the periodic boundary");
params.addParam<std::vector<VariableName>>("variable", {}, "Variable for the periodic boundary");
params.addClassDescription("Action that adds periodic boundary conditions");
return params;
}
Expand Down
2 changes: 2 additions & 0 deletions framework/src/actions/CommonOutputAction.C
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,12 @@ CommonOutputAction::validParams()

params.addParam<std::vector<VariableName>>(
"hide",
{},
"A list of the variables and postprocessors that should NOT be output to the Exodus "
"file (may include Variables, ScalarVariables, and Postprocessor names).");
params.addParam<std::vector<VariableName>>(
"show",
{},
"A list of the variables and postprocessors that should be output to the Exodus file "
"(may include Variables, ScalarVariables, and Postprocessor names).");

Expand Down
8 changes: 3 additions & 5 deletions framework/src/actions/SetupMeshAction.C
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,9 @@ SetupMeshAction::SetupMeshAction(const InputParameters & params)
void
SetupMeshAction::setupMesh(MooseMesh * mesh)
{
std::vector<BoundaryName> ghosted_boundaries =
getParam<std::vector<BoundaryName>>("ghosted_boundaries");

for (const auto & bnd_name : ghosted_boundaries)
mesh->addGhostedBoundary(mesh->getBoundaryID(bnd_name));
if (isParamValid("ghosted_boundaries"))
for (const auto & bnd_name : getParam<std::vector<BoundaryName>>("ghosted_boundaries"))
mesh->addGhostedBoundary(mesh->getBoundaryID(bnd_name));

if (isParamValid("ghosted_boundaries_inflation"))
{
Expand Down
2 changes: 1 addition & 1 deletion framework/src/actions/SetupResidualDebugAction.C
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ SetupResidualDebugAction::validParams()
{
InputParameters params = Action::validParams();
params.addParam<std::vector<NonlinearVariableName>>(
"show_var_residual", "Variables for which residuals will be sent to the output file.");
"show_var_residual", {}, "Variables for which residuals will be sent to the output file.");
params.addClassDescription(
"Adds the necessary objects for computing the residuals for individual variables.");
return params;
Expand Down
5 changes: 4 additions & 1 deletion framework/src/auxkernels/ArrayParsedAux.C
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ ArrayParsedAux::validParams()
false,
"Make coordinate (x,y,z) and time (t) variables available in the function expression.");
params.addParam<std::vector<std::string>>(
"constant_names", "Vector of constants used in the parsed function (use this for kB etc.)");
"constant_names",
{},
"Vector of constants used in the parsed function (use this for kB etc.)");
params.addParam<std::vector<std::string>>(
"constant_expressions",
{},
"Vector of values for the constants in constant_names (can be an FParser expression)");

return params;
Expand Down
5 changes: 4 additions & 1 deletion framework/src/auxkernels/ParsedAux.C
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ ParsedAux::validParams()
false,
"Make coordinate (x,y,z) and time (t) variables available in the function expression.");
params.addParam<std::vector<std::string>>(
"constant_names", "Vector of constants used in the parsed function (use this for kB etc.)");
"constant_names",
{},
"Vector of constants used in the parsed function (use this for kB etc.)");
params.addParam<std::vector<std::string>>(
"constant_expressions",
{},
"Vector of values for the constants in constant_names (can be an FParser expression)");

return params;
Expand Down
27 changes: 14 additions & 13 deletions framework/src/auxkernels/ParsedVectorAux.C
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,9 @@ ParsedVectorAux::validParams()
false,
"Make coordinate (x,y,z) and time (t) variables available in the function expression.");
params.addParam<std::vector<std::vector<std::string>>>(
"constant_names",
std::vector<std::vector<std::string>>(),
"Vector of constants used in the parsed function (use this for kB etc.)");
"constant_names", "Vector of constants used in the parsed function (use this for kB etc.)");
params.addParam<std::vector<std::vector<std::string>>>(
"constant_expressions",
std::vector<std::vector<std::string>>(),
"Vector of values for the constants in constant_names (can be an FParser expression)");

return params;
Expand All @@ -67,10 +64,6 @@ ParsedVectorAux::ParsedVectorAux(const InputParameters & parameters)
_func_F.resize(LIBMESH_DIM);
_function.resize(LIBMESH_DIM);

if (getParam<std::vector<std::vector<std::string>>>("constant_names").size() !=
getParam<std::vector<std::vector<std::string>>>("constant_expressions").size())
paramError("constant_names", "Must be same length as constant_expressions");

for (const auto i : make_range(Moose::dim))
{
// build variables argument
Expand Down Expand Up @@ -98,11 +91,19 @@ ParsedVectorAux::ParsedVectorAux(const InputParameters & parameters)
setParserFeatureFlags(_func_F[i]);

// add the constant expressions
if (getParam<std::vector<std::vector<std::string>>>("constant_names").size())
addFParserConstants(
_func_F[i],
getParam<std::vector<std::vector<std::string>>>("constant_names")[i],
getParam<std::vector<std::vector<std::string>>>("constant_expressions")[i]);
auto constant_names = isParamValid("constant_names")
? getParam<std::vector<std::vector<std::string>>>("constant_names")
: std::vector<std::vector<std::string>>{};
auto constant_expressions =
isParamValid("constant_expressions")
? getParam<std::vector<std::vector<std::string>>>("constant_expressions")
: std::vector<std::vector<std::string>>{};

if (constant_names.size() != constant_expressions.size())
paramError("constant_names", "Must be same length as constant_expressions");

if (isParamValid("constant_names") && isParamValid("constant_expressions"))
addFParserConstants(_func_F[i], constant_names[i], constant_expressions[i]);

// parse function
if (_func_F[i]->Parse(_function[i], variables) >= 0)
Expand Down
2 changes: 2 additions & 0 deletions framework/src/bcs/IntegratedBCBase.C
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ IntegratedBCBase::validParams()

params.addParam<std::vector<AuxVariableName>>(
"save_in",
{},
"The name of auxiliary variables to save this BC's residual contributions to. "
"Everything about that variable must match everything about this variable (the "
"type, what blocks it's on, etc.)");
params.addParam<std::vector<AuxVariableName>>(
"diag_save_in",
{},
"The name of auxiliary variables to save this BC's diagonal jacobian "
"contributions to. Everything about that variable must match everything "
"about this variable (the type, what blocks it's on, etc.)");
Expand Down
2 changes: 2 additions & 0 deletions framework/src/bcs/NodalBCBase.C
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ NodalBCBase::validParams()
InputParameters params = BoundaryCondition::validParams();
params.addParam<std::vector<AuxVariableName>>(
"save_in",
{},
"The name of auxiliary variables to save this BC's residual contributions to. "
"Everything about that variable must match everything about this variable (the "
"type, what blocks it's on, etc.)");
params.addParam<std::vector<AuxVariableName>>(
"diag_save_in",
{},
"The name of auxiliary variables to save this BC's diagonal jacobian "
"contributions to. Everything about that variable must match everything "
"about this variable (the type, what blocks it's on, etc.)");
Expand Down
3 changes: 2 additions & 1 deletion framework/src/constraints/EqualValueBoundaryConstraint.C
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ EqualValueBoundaryConstraint::validParams()
"primary",
std::numeric_limits<unsigned int>::max(),
"The ID of the primary node. If no ID is provided, first node of secondary set is chosen.");
params.addParam<std::vector<unsigned int>>("secondary_node_ids", "The IDs of the secondary node");
params.addParam<std::vector<unsigned int>>(
"secondary_node_ids", {}, "The IDs of the secondary node");
params.addParam<BoundaryName>(
"secondary", "NaN", "The boundary ID associated with the secondary side");
params.addRequiredParam<Real>("penalty", "The penalty used for the boundary term");
Expand Down
4 changes: 2 additions & 2 deletions framework/src/constraints/LinearNodalConstraint.C
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ LinearNodalConstraint::validParams()
params.addClassDescription(
"Constrains secondary node to move as a linear combination of primary nodes.");
params.addRequiredParam<std::vector<unsigned int>>("primary", "The primary node IDs.");
params.addParam<std::vector<unsigned int>>("secondary_node_ids",
"The list of secondary node ids");
params.addParam<std::vector<unsigned int>>(
"secondary_node_ids", {}, "The list of secondary node ids");
params.addParam<BoundaryName>(
"secondary_node_set", "NaN", "The boundary ID associated with the secondary side");
params.addRequiredParam<Real>("penalty", "The penalty used for the boundary term");
Expand Down
1 change: 1 addition & 0 deletions framework/src/controls/Control.C
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Control::validParams()

params.addParam<std::vector<std::string>>(
"depends_on",
{},
"The Controls that this control relies upon (i.e. must execute before this one)");

return params;
Expand Down
2 changes: 2 additions & 0 deletions framework/src/dgkernels/DGKernelBase.C
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ DGKernelBase::validParams()

params.addParam<std::vector<AuxVariableName>>(
"save_in",
{},
"The name of auxiliary variables to save this Kernel's residual contributions to. "
" Everything about that variable must match everything about this variable (the "
"type, what blocks it's on, etc.)");
params.addParam<std::vector<AuxVariableName>>(
"diag_save_in",
{},
"The name of auxiliary variables to save this Kernel's diagonal Jacobian "
"contributions to. Everything about that variable must match everything "
"about this variable (the type, what blocks it's on, etc.)");
Expand Down
1 change: 1 addition & 0 deletions framework/src/executioners/FEProblemSolve.C
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ FEProblemSolve::validParams()
InputParameters params = emptyInputParameters();

params.addParam<std::vector<std::string>>("splitting",
{},
"Top-level splitting defining a "
"hierarchical decomposition into "
"subsystems to help the solver.");
Expand Down
12 changes: 6 additions & 6 deletions framework/src/functormaterials/FunctorADConverter.C
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ FunctorADConverterTempl<T>::validParams()
params.addClassDescription("Converts regular functors to AD functors and "
"AD functors to regular functors");
params.addParam<std::vector<MooseFunctorName>>(
"reg_props_in", "The names of the regular functors to convert to AD functors");
params.addParam<std::vector<MooseFunctorName>>("ad_props_out",
"The names of the output AD functors");
"reg_props_in", {}, "The names of the regular functors to convert to AD functors");
params.addParam<std::vector<MooseFunctorName>>(
"ad_props_in", "The names of the AD functors to convert to regular functors");
params.addParam<std::vector<MooseFunctorName>>("reg_props_out",
"The names of the output regular functors");
"ad_props_out", {}, "The names of the output AD functors");
params.addParam<std::vector<MooseFunctorName>>(
"ad_props_in", {}, "The names of the AD functors to convert to regular functors");
params.addParam<std::vector<MooseFunctorName>>(
"reg_props_out", {}, "The names of the output regular functors");
return params;
}

Expand Down
2 changes: 2 additions & 0 deletions framework/src/interfacekernels/InterfaceKernelBase.C
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ InterfaceKernelBase::validParams()
params.set<std::string>("_moose_base") = "InterfaceKernel";
params.addParam<std::vector<AuxVariableName>>(
"save_in",
{},
"The name of auxiliary variables to save this Kernel's residual contributions to. "
" Everything about that variable must match everything about this variable (the "
"type, what blocks it's on, etc.)");
params.addParam<std::vector<AuxVariableName>>(
"diag_save_in",
{},
"The name of auxiliary variables to save this Kernel's diagonal Jacobian "
"contributions to. Everything about that variable must match everything "
"about this variable (the type, what blocks it's on, etc.)");
Expand Down
2 changes: 2 additions & 0 deletions framework/src/kernels/KernelBase.C
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ KernelBase::validParams()

params.addParam<std::vector<AuxVariableName>>(
"save_in",
{},
"The name of auxiliary variables to save this Kernel's residual contributions to. "
" Everything about that variable must match everything about this variable (the "
"type, what blocks it's on, etc.)");
params.addParam<std::vector<AuxVariableName>>(
"diag_save_in",
{},
"The name of auxiliary variables to save this Kernel's diagonal Jacobian "
"contributions to. Everything about that variable must match everything "
"about this variable (the type, what blocks it's on, etc.)");
Expand Down
4 changes: 2 additions & 2 deletions framework/src/kernels/NodalScalarKernel.C
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ InputParameters
NodalScalarKernel::validParams()
{
InputParameters params = ScalarKernel::validParams();
params.addParam<std::vector<dof_id_type>>("nodes", "Supply nodes using node ids");
params.addParam<std::vector<dof_id_type>>("nodes", {}, "Supply nodes using node ids");
params.addParam<std::vector<BoundaryName>>(
"boundary", "The list of boundary IDs from the mesh where this nodal kernel applies");
"boundary", {}, "The list of boundary IDs from the mesh where this nodal kernel applies");

return params;
}
Expand Down
1 change: 1 addition & 0 deletions framework/src/materials/DerivativeParsedMaterialHelper.C
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ DerivativeParsedMaterialHelperTempl<is_ad>::validParams()
params.addParam<unsigned int>("derivative_order", 3, "Maximum order of derivatives taken");
params.addParam<std::vector<SymbolName>>(
"additional_derivative_symbols",
{},
"A list of additional (non-variable) symbols (such as material property or postprocessor "
"names) to take derivatives w.r.t.");
return params;
Expand Down
Loading

0 comments on commit 645eca9

Please sign in to comment.