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 
22 template <>
25 {
27  params.addPrivateParam<bool>("_solve");
28  return params;
29 }
30 
32  : Action(parameters)
33 {
34 }
35 
36 void
38 {
39  if (_current_task == "determine_system_type")
40  {
41  // Determine whether the Executioner is derived from EigenExecutionerBase and
42  // set a flag on MooseApp that can be used during problem construction.
43  bool use_nonlinear = true;
44  bool use_eigenvalue = false;
45  auto p = _awh.getActionByTask<CreateExecutionerAction>("setup_executioner");
46  if (p)
47  {
48  auto & exparams = p->getObjectParams();
49  use_nonlinear = !(exparams.isParamValid("_eigen") && exparams.get<bool>("_eigen"));
50  use_eigenvalue =
51  (exparams.isParamValid("_use_eigen_value") && exparams.get<bool>("_use_eigen_value"));
52  }
53 
54  _app.useNonlinear() = use_nonlinear;
55  _app.useEigenvalue() = use_eigenvalue;
56  return;
57  }
58 
59  // act only if we have mesh
60  if (_mesh.get() != NULL)
61  {
62  // Make sure the problem hasn't already been created elsewhere
63  if (!_problem)
64  {
65  std::string type;
66  if (_app.useEigenvalue())
67  type = "EigenProblem";
68  else
69  type = "FEProblem";
70  auto params = _factory.getValidParams(type);
71 
72  // apply common parameters of the object held by CreateProblemAction to honor user inputs in
73  // [Problem]
74  auto p = _awh.getActionByTask<CreateProblemAction>("create_problem");
75  if (p)
76  params.applyParameters(p->getObjectParams());
77 
78  params.set<MooseMesh *>("mesh") = _mesh.get();
79  params.set<bool>("use_nonlinear") = _app.useNonlinear();
80  if (_pars.isParamSetByUser("_solve"))
81  params.set<bool>("solve") = getParam<bool>("_solve");
82 
83  _problem = _factory.create<FEProblemBase>(type, "MOOSE Problem", params);
84  }
85  else
86  {
87  // otherwise perform necessary sanity checks
89  mooseError("Problem has to be of a EigenProblem (or derived subclass) type when using "
90  "eigen executioner");
91  }
92  }
93 }
CreateProblemDefaultAction(InputParameters parameters)
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
bool & useNonlinear()
Set a Boolean indicating whether this app will use a Nonlinear or Eigen System.
Definition: MooseApp.h:276
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:87
ActionWarehouse & _awh
Reference to ActionWarehouse where we store object build by actions.
Definition: Action.h:207
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...
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:207
InputParameters getValidParams(const std::string &name)
Get valid parameters for the object.
Definition: Factory.C:67
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Factory & _factory
The Factory associated with the MooseApp.
Definition: Action.h:186
std::unique_ptr< T_DEST, T_DELETER > dynamic_pointer_cast(std::unique_ptr< T_SRC, T_DELETER > &src)
These are reworked from https://stackoverflow.com/a/11003103.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Base class for actions.
Definition: Action.h:35
bool & useEigenvalue()
Set a Boolean indicating whether this app will use an eigenvalue executioner.
Definition: MooseApp.h:281
InputParameters & getObjectParams()
Retreive the parameters of the object to be created by this action.
InputParameters _pars
Input parameters for the action.
Definition: Action.h:171
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:74
const std::string & _current_task
The current action (even though we have seperate instances for each action)
Definition: Action.h:210
InputParameters validParams< CreateProblemDefaultAction >()
bool isParamSetByUser(const std::string &name) const
Method returns true if the parameter was by the user.
std::shared_ptr< MooseMesh > & _mesh
Definition: Action.h:212
const std::string & type() const
Definition: Action.h:86
const T * getActionByTask(const std::string &task)
Retrieve the action on a specific task with its type.
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
Definition: Action.h:216
Problem for solving eigenvalue problems.
Definition: EigenProblem.h:25
MooseApp & _app
The MOOSE application this is associated with.
Definition: Action.h:183
registerMooseAction("MooseApp", CreateProblemDefaultAction, "create_problem_default")
InputParameters validParams< Action >()
Definition: Action.C:22