Skip to content
Permalink
Browse files

Merge pull request #13349 from aeslaughter/pr13344

Add support for private parameters in applySpecificParameters
  • Loading branch information...
permcody committed May 2, 2019
2 parents 4785e89 + a5578e0 commit eaae6330d274d32d3d8ec2ee0de7d9300ce37aee
@@ -644,7 +644,8 @@ class InputParameters : public Parameters
* @see CommonOutputAction AddOutputAction
*/
void applySpecificParameters(const InputParameters & common,
const std::vector<std::string> & include);
const std::vector<std::string> & include,
bool allow_private = false);

/**
* Apply values from a single parameter in common, to a single parameter stored in this object
@@ -657,7 +658,9 @@ class InputParameters : public Parameters
* (3) Local parameter must be invalid OR not have been set from its default
* (4) Both cannot be private
*/
void applyParameter(const InputParameters & common, const std::string & common_name);
void applyParameter(const InputParameters & common,
const std::string & common_name,
bool allow_private = false);

/**
* Apply properties of a single coupled variable in common, to a single coupled variable stored in
@@ -1452,4 +1455,3 @@ validParams()

mooseError("Missing validParams declaration!");
}

@@ -685,7 +685,8 @@ InputParameters::applyParameters(const InputParameters & common,

void
InputParameters::applySpecificParameters(const InputParameters & common,
const std::vector<std::string> & include)
const std::vector<std::string> & include,
bool allow_private)
{
// Loop through the common parameters
for (const auto & it : common)
@@ -698,7 +699,7 @@ InputParameters::applySpecificParameters(const InputParameters & common,
if (std::find(include.begin(), include.end(), common_name) == include.end())
continue;

applyParameter(common, common_name);
applyParameter(common, common_name, allow_private);
}

// Loop through the coupled variables
@@ -745,7 +746,9 @@ InputParameters::applyCoupledVar(const InputParameters & common, const std::stri
}

void
InputParameters::applyParameter(const InputParameters & common, const std::string & common_name)
InputParameters::applyParameter(const InputParameters & common,
const std::string & common_name,
bool allow_private)
{
// Disable the display of deprecated message when applying common parameters, this avoids a dump
// of messages
@@ -754,12 +757,12 @@ InputParameters::applyParameter(const InputParameters & common, const std::strin
// Extract the properties from the local parameter for the current common parameter name
const bool local_exist = _values.find(common_name) != _values.end();
const bool local_set = _params.count(common_name) > 0 && !_params[common_name]._set_by_add_param;
const bool local_priv = isPrivate(common_name);
const bool local_priv = allow_private ? false : isPrivate(common_name);
const bool local_valid = isParamValid(common_name);

// Extract the properties from the common parameter
const bool common_exist = common._values.find(common_name) != common._values.end();
const bool common_priv = common.isPrivate(common_name);
const bool common_priv = allow_private ? false : common.isPrivate(common_name);
const bool common_valid = common.isParamValid(common_name);

/* In order to apply common parameter 4 statements must be satisfied
@@ -1596,11 +1596,8 @@ SolidModel::createConstitutiveModel(const std::string & cm_name)

params.applyParameters(parameters());
params.set<SubProblem *>("_subproblem") = &_subproblem;
if (parameters().isParamValid("_material_data_type"))
params.set<Moose::MaterialDataType>("_material_data_type") =
getParam<Moose::MaterialDataType>("_material_data_type");
if (parameters().isParamValid("_neighbor"))
params.set<bool>("_neighbor") = getParam<bool>("_neighbor");
params.applySpecificParameters(parameters(), {"_material_data_type", "_neighbor"}, true);

MooseSharedPointer<ConstitutiveModel> cm =
factory.create<ConstitutiveModel>(cm_name, name() + "Model", params, _tid);

@@ -206,6 +206,20 @@ TEST(InputParameters, applyParameters)
EXPECT_TRUE(p1.get<MultiMooseEnum>("enum").contains("foo"));
}

TEST(InputParameters, applyParametersPrivateOverride)
{
InputParameters p1 = emptyInputParameters();
p1.addPrivateParam<bool>("_flag", true);
EXPECT_TRUE(p1.get<bool>("_flag"));

InputParameters p2 = emptyInputParameters();
p2.addPrivateParam<bool>("_flag", false);
EXPECT_FALSE(p2.get<bool>("_flag"));

p1.applySpecificParameters(p2, {"_flag"}, true);
EXPECT_FALSE(p1.get<bool>("_flag"));
}

TEST(InputParameters, makeParamRequired)
{
InputParameters params = emptyInputParameters();

0 comments on commit eaae633

Please sign in to comment.
You can’t perform that action at this time.