www.mooseframework.org
CreateProblemDefaultAction.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
11 
12 #include "Factory.h"
13 #include "FEProblem.h"
14 #include "EigenProblem.h"
15 #include "MooseApp.h"
17 #include "CreateProblemAction.h"
18 
19 registerMooseAction("MooseApp", CreateProblemDefaultAction, "create_problem_default");
20 registerMooseAction("MooseApp", CreateProblemDefaultAction, "determine_system_type");
21 
23 
26 {
28  params.addPrivateParam<bool>("_solve");
29  return params;
30 }
31 
33  : Action(parameters)
34 {
35 }
36 
37 void
39 {
40  if (_current_task == "determine_system_type")
41  {
42  // Determine whether the Executioner is derived from EigenExecutionerBase and
43  // set a flag on MooseApp that can be used during problem construction.
44  bool use_nonlinear = true;
45  bool use_eigenvalue = false;
46  auto p = _awh.getActionByTask<CreateExecutionerAction>("setup_executioner");
47  if (p)
48  {
49  auto & exparams = p->getObjectParams();
50  use_nonlinear = !(exparams.isParamValid("_eigen") && exparams.get<bool>("_eigen"));
51  use_eigenvalue =
52  (exparams.isParamValid("_use_eigen_value") && exparams.get<bool>("_use_eigen_value"));
53  }
54 
55  _app.useNonlinear() = use_nonlinear;
56  _app.useEigenvalue() = use_eigenvalue;
57  return;
58  }
59 
60  // act only if we have mesh
61  if (_mesh.get() != NULL)
62  {
63  // Make sure the problem hasn't already been created elsewhere
64  if (!_problem)
65  {
66  std::string type;
67  if (_app.useEigenvalue())
68  type = "EigenProblem";
69  else
70  type = "FEProblem";
71  auto params = _factory.getValidParams(type);
72 
73  // apply common parameters of the object held by CreateProblemAction to honor user inputs in
74  // [Problem]
75  auto p = _awh.getActionByTask<CreateProblemAction>("create_problem");
76  if (p)
77  params.applyParameters(p->getObjectParams());
78 
79  params.set<MooseMesh *>("mesh") = _mesh.get();
80  params.set<bool>("use_nonlinear") = _app.useNonlinear();
81  if (_pars.isParamSetByUser("_solve"))
82  params.set<bool>("solve") = getParam<bool>("_solve");
83 
84  _problem = _factory.create<FEProblemBase>(type, "MOOSE Problem", params);
85  }
86  else
87  {
88  // otherwise perform necessary sanity checks
89  if (_app.useEigenvalue() && !(std::dynamic_pointer_cast<EigenProblem>(_problem)))
90  mooseError("Problem has to be of a EigenProblem (or derived subclass) type when using "
91  "eigen executioner");
92  }
93  }
94 }
InputParameters::isParamSetByUser
bool isParamSetByUser(const std::string &name) const
Method returns true if the parameter was by the user.
Definition: InputParameters.C:837
Action::_app
MooseApp & _app
The MOOSE application this is associated with.
Definition: Action.h:213
Factory::create
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, InputParameters &parameters, THREAD_ID tid=0, bool print_deprecated=true)
Build an object (must be registered) - THIS METHOD IS DEPRECATED (Use create<T>())
Definition: Factory.C:93
Factory::getValidParams
InputParameters getValidParams(const std::string &name)
Get valid parameters for the object.
Definition: Factory.C:67
FEProblem.h
Action::_current_task
const std::string & _current_task
The current action (even though we have seperate instances for each action)
Definition: Action.h:240
CreateExecutionerAction.h
Action
Base class for actions.
Definition: Action.h:39
CreateProblemDefaultAction
Definition: CreateProblemDefaultAction.h:20
Action::_problem
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
Definition: Action.h:246
defineLegacyParams
defineLegacyParams(CreateProblemDefaultAction)
MooseApp::useEigenvalue
bool & useEigenvalue()
Returns a writable Boolean indicating whether this app will use an eigenvalue executioner.
Definition: MooseApp.h:297
mooseError
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition: MooseError.h:210
InputParameters
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
Definition: InputParameters.h:53
CreateExecutionerAction
Definition: CreateExecutionerAction.h:19
CreateProblemAction.h
Action::_factory
Factory & _factory
The Factory associated with the MooseApp.
Definition: Action.h:216
MooseApp.h
CreateProblemDefaultAction::validParams
static InputParameters validParams()
Definition: CreateProblemDefaultAction.C:25
ActionWarehouse::getActionByTask
const T * getActionByTask(const std::string &task)
Retrieve the action on a specific task with its type.
Definition: ActionWarehouse.h:156
Action::type
const std::string & type() const
Definition: Action.h:115
Action::_pars
InputParameters _pars
Input parameters for the action.
Definition: Action.h:201
CreateProblemDefaultAction.h
MooseApp::useNonlinear
bool & useNonlinear()
Returns a writable Boolean indicating whether this app will use a Nonlinear or Eigen System.
Definition: MooseApp.h:292
registerMooseAction
registerMooseAction("MooseApp", CreateProblemDefaultAction, "create_problem_default")
MooseObjectAction::getObjectParams
InputParameters & getObjectParams()
Retreive the parameters of the object to be created by this action.
Definition: MooseObjectAction.h:34
CreateProblemAction
Definition: CreateProblemAction.h:20
CreateProblemDefaultAction::CreateProblemDefaultAction
CreateProblemDefaultAction(InputParameters parameters)
Definition: CreateProblemDefaultAction.C:32
MooseMesh
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:74
Action::_mesh
std::shared_ptr< MooseMesh > & _mesh
Definition: Action.h:242
Action::validParams
static InputParameters validParams()
Definition: Action.C:23
InputParameters::addPrivateParam
void addPrivateParam(const std::string &name, const T &value)
These method add a parameter to the InputParameters object which can be retrieved like any other para...
Definition: InputParameters.h:1308
Action::_awh
ActionWarehouse & _awh
Reference to ActionWarehouse where we store object build by actions.
Definition: Action.h:237
FEProblemBase
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Definition: FEProblemBase.h:139
Factory.h
CreateProblemDefaultAction::act
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
Definition: CreateProblemDefaultAction.C:38
EigenProblem.h