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 5, 2018
1 parent 2aea039 commit 1934b46
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 19 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: 10 additions & 7 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 All @@ -23,12 +24,7 @@ InputParameters
validParams<CreateProblemDefaultAction>()
{
InputParameters params = validParams<Action>();
params.addParam<bool>("solve",
true,
"Whether or not to actually solve the Nonlinear system. "
"This is handy in the case that all you want to do is "
"execute AuxKernels, Transfers, etc. without actually "
"solving anything");
params.addPrivateParam<bool>("_solve");
return params;
}

Expand Down Expand Up @@ -75,9 +71,16 @@ CreateProblemDefaultAction::act()
type = "FEProblem";
auto params = _factory.getValidParams(type);

// apply comman parameters of the object held by CreateProblemAction to honor user inputs in
// [Problem]
auto p = _awh.getActionByTask<CreateProblemAction>("create_problem");
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");
if (_pars.isParamSetByUser("_solve"))
params.set<bool>("solve") = getParam<bool>("_solve");

_problem = _factory.create<FEProblemBase>(type, "MOOSE Problem", params);
}
Expand Down
2 changes: 1 addition & 1 deletion framework/src/base/MooseApp.C
Expand Up @@ -1508,7 +1508,7 @@ MooseApp::createMinimalApp()
{
// Build the Action parameters
InputParameters action_params = _action_factory.getValidParams("CreateProblemDefaultAction");
action_params.set<bool>("solve") = false;
action_params.set<bool>("_solve") = false;

// Create the action
std::shared_ptr<Action> action = std::static_pointer_cast<Action>(
Expand Down
7 changes: 7 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,12 @@ CreateSpecialProblemAction::act()

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

// apply comman parameters of the object held by CreateProblemAction to honor user inputs in
// [Problem]
auto p = _awh.getActionByTask<CreateProblemAction>("create_problem");
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 1934b46

Please sign in to comment.