From 7a0586bff901ae79c1c5abeafedc3a19696e07ad Mon Sep 17 00:00:00 2001 From: Yaqi Wang Date: Tue, 4 Sep 2018 12:26:52 -0600 Subject: [PATCH] allow custom actions to take parameters in Problem input block #12002 --- framework/src/actions/CreateProblemAction.C | 8 +------- .../src/actions/CreateProblemDefaultAction.C | 17 +++++++++++++++++ test/src/actions/CreateSpecialProblemAction.C | 17 +++++++++++++++++ test/src/problems/MooseTestProblem.C | 3 ++- .../problems/action_custom_fe_problem/tests | 15 ++++++++++++--- 5 files changed, 49 insertions(+), 11 deletions(-) diff --git a/framework/src/actions/CreateProblemAction.C b/framework/src/actions/CreateProblemAction.C index 65d2a8395e79..3d6de68d4cf9 100644 --- a/framework/src/actions/CreateProblemAction.C +++ b/framework/src/actions/CreateProblemAction.C @@ -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. @@ -42,12 +42,6 @@ CreateProblemAction::act() _moose_object_pars.set("mesh") = _mesh.get(); _moose_object_pars.set("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(_type, getParam("name"), _moose_object_pars); diff --git a/framework/src/actions/CreateProblemDefaultAction.C b/framework/src/actions/CreateProblemDefaultAction.C index 3fddf473e285..60816acdc7b9 100644 --- a/framework/src/actions/CreateProblemDefaultAction.C +++ b/framework/src/actions/CreateProblemDefaultAction.C @@ -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"); @@ -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(action); + if (p) + break; + } + if (p) + params.applyParameters(p->getObjectParams()); + } + params.set("mesh") = _mesh.get(); params.set("use_nonlinear") = _app.useNonlinear(); params.set("solve") = getParam("solve"); diff --git a/test/src/actions/CreateSpecialProblemAction.C b/test/src/actions/CreateSpecialProblemAction.C index 7251fbb40e89..185bd38ec579 100644 --- a/test/src/actions/CreateSpecialProblemAction.C +++ b/test/src/actions/CreateSpecialProblemAction.C @@ -11,6 +11,7 @@ #include "MooseApp.h" #include "FEProblemBase.h" +#include "CreateProblemAction.h" registerMooseAction("MooseTestApp", CreateSpecialProblemAction, "create_problem_custom"); @@ -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(action); + if (p) + break; + } + if (p) + params.applyParameters(p->getObjectParams()); + } + params.set("mesh") = _mesh.get(); params.set("use_nonlinear") = _app.useNonlinear(); diff --git a/test/src/problems/MooseTestProblem.C b/test/src/problems/MooseTestProblem.C index 860e84c3ef1c..24bd4626a54a 100644 --- a/test/src/problems/MooseTestProblem.C +++ b/test/src/problems/MooseTestProblem.C @@ -21,7 +21,8 @@ validParams() 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("coord_type") << " and my name is '" << this->name() << "'" << std::endl; } diff --git a/test/tests/problems/action_custom_fe_problem/tests b/test/tests/problems/action_custom_fe_problem/tests index c23940c15f4f..f5168e0b49b7 100644 --- a/test/tests/problems/action_custom_fe_problem/tests +++ b/test/tests/problems/action_custom_fe_problem/tests @@ -5,16 +5,25 @@ [./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.' [../] @@ -22,7 +31,7 @@ [./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.'