Skip to content

Commit

Permalink
allow custom actions to take parameters in Problem input block #12002
Browse files Browse the repository at this point in the history
  • Loading branch information
YaqiWang committed Sep 4, 2018
1 parent e162b60 commit 7a0586b
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 11 deletions.
8 changes: 1 addition & 7 deletions framework/src/actions/CreateProblemAction.C
Expand Up @@ -32,7 +32,7 @@ void
CreateProblemAction::act()
{
// build the problem only if we have mesh
if (_mesh.get() != NULL)
if (_mesh.get() != NULL && _pars.isParamSetByUser("type"))
{
// when this action is built by parser with Problem input block, this action
// must act i.e. create a problem. Thus if a problem has been created, it will error out.
Expand All @@ -42,12 +42,6 @@ CreateProblemAction::act()
_moose_object_pars.set<MooseMesh *>("mesh") = _mesh.get();
_moose_object_pars.set<bool>("use_nonlinear") = _app.useNonlinear();

// we can change the type only because FEProblem and EigenProblem have the same valid
// parameters.
// Ideally, type should be required but it will require large change on existing files.
if (_app.useEigenvalue() && !_pars.isParamSetByUser("type"))
_type = "EigenProblem";

_problem =
_factory.create<FEProblemBase>(_type, getParam<std::string>("name"), _moose_object_pars);

Expand Down
17 changes: 17 additions & 0 deletions framework/src/actions/CreateProblemDefaultAction.C
Expand Up @@ -14,6 +14,7 @@
#include "EigenProblem.h"
#include "MooseApp.h"
#include "CreateExecutionerAction.h"
#include "CreateProblemAction.h"

registerMooseAction("MooseApp", CreateProblemDefaultAction, "create_problem_default");
registerMooseAction("MooseApp", CreateProblemDefaultAction, "determine_system_type");
Expand Down Expand Up @@ -85,6 +86,22 @@ CreateProblemDefaultAction::act()
type = "FEProblem";
auto params = _factory.getValidParams(type);

// apply comman parameters of the object held by CreateProblemAction to honor user inputs in
// [Problem]
if (_awh.hasActions("create_problem"))
{
CreateProblemAction * p = nullptr;
const auto & actions = _awh.getActionListByName("create_problem");
for (const auto & action : actions)
{
p = dynamic_cast<CreateProblemAction *>(action);
if (p)
break;
}
if (p)
params.applyParameters(p->getObjectParams());
}

params.set<MooseMesh *>("mesh") = _mesh.get();
params.set<bool>("use_nonlinear") = _app.useNonlinear();
params.set<bool>("solve") = getParam<bool>("solve");
Expand Down
17 changes: 17 additions & 0 deletions test/src/actions/CreateSpecialProblemAction.C
Expand Up @@ -11,6 +11,7 @@

#include "MooseApp.h"
#include "FEProblemBase.h"
#include "CreateProblemAction.h"

registerMooseAction("MooseTestApp", CreateSpecialProblemAction, "create_problem_custom");

Expand Down Expand Up @@ -44,6 +45,22 @@ CreateSpecialProblemAction::act()

auto params = _factory.getValidParams("MooseTestProblem");

// apply comman parameters of the object held by CreateProblemAction to honor user inputs in
// [Problem]
if (_awh.hasActions("create_problem"))
{
CreateProblemAction * p = nullptr;
const auto & actions = _awh.getActionListByName("create_problem");
for (const auto & action : actions)
{
p = dynamic_cast<CreateProblemAction *>(action);
if (p)
break;
}
if (p)
params.applyParameters(p->getObjectParams());
}

params.set<MooseMesh *>("mesh") = _mesh.get();
params.set<bool>("use_nonlinear") = _app.useNonlinear();

Expand Down
3 changes: 2 additions & 1 deletion test/src/problems/MooseTestProblem.C
Expand Up @@ -21,7 +21,8 @@ validParams<MooseTestProblem>()

MooseTestProblem::MooseTestProblem(const InputParameters & params) : FEProblem(params)
{
_console << "Hello, I am your FEProblemBase-derived class and my name is '" << this->name() << "'"
_console << "Hello, I am your FEProblemBase-derived class with coordinate type "
<< getParam<MultiMooseEnum>("coord_type") << " and my name is '" << this->name() << "'"
<< std::endl;
}

Expand Down
15 changes: 12 additions & 3 deletions test/tests/problems/action_custom_fe_problem/tests
Expand Up @@ -5,24 +5,33 @@
[./no_problem_block]
type = 'RunApp'
input = 'action_custom_fe_problem_test.i'
expect_out = 'Hello, I am your FEProblemBase-derived class and my name is \S+'
expect_out = 'Hello, I am your FEProblemBase-derived class with coordinate type XYZ and my name is \S+'

requirement = 'The system shall allow the creation of a custom problem through a user-defined Action.'
[../]

[./with_problem_block_without_type]
type = 'RunApp'
input = 'action_custom_fe_problem_test.i'
expect_out = 'Hello, I am your FEProblemBase-derived class with coordinate type RZ and my name is \S+'
cli_args = 'Problem/coord_type=RZ'

requirement = 'The system shall support the creation of a custom problem with parameters in Problem block.'
[../]

[./with_problem_block_with_wrong_type]
type = 'RunException'
input = 'action_custom_fe_problem_test.i'
expect_err = 'TestProblem input block requires Problem/type to be MooseTestProblem'
cli_args = 'Problem/coord_type=RZ'
cli_args = 'Problem/coord_type=RZ Problem/type=FEProblem'

requirement = 'The system shall error out when Problem block type is not specified.'
[../]

[./with_problem_block_with_type]
type = 'RunApp'
input = 'action_custom_fe_problem_test.i'
expect_out = 'Hello, I am your FEProblemBase-derived class and my name is \S+'
expect_out = 'Hello, I am your FEProblemBase-derived class with coordinate type RZ and my name is \S+'
cli_args = 'Problem/coord_type=RZ Problem/type=MooseTestProblem'

requirement = 'The system shall support the creation of a custom problem through Problem block with type specified.'
Expand Down

0 comments on commit 7a0586b

Please sign in to comment.