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 
24 {
26  params.addPrivateParam<bool>("_solve");
27  return params;
28 }
29 
31  : Action(parameters)
32 {
33 }
34 
35 void
37 {
38  if (_current_task == "determine_system_type")
39  {
40  // Determine whether the Executioner is derived from EigenExecutionerBase and
41  // set a flag on MooseApp that can be used during problem construction.
42  bool use_nonlinear = true;
43  bool use_eigenvalue = false;
44  auto p = _awh.getActionByTask<CreateExecutionerAction>("setup_executioner");
45  if (p)
46  {
47  auto & exparams = p->getObjectParams();
48  use_nonlinear = !(exparams.isParamValid("_eigen") && exparams.get<bool>("_eigen"));
49  use_eigenvalue =
50  (exparams.isParamValid("_use_eigen_value") && exparams.get<bool>("_use_eigen_value"));
51  }
52 
53  _app.useNonlinear() = use_nonlinear;
54  _app.useEigenvalue() = use_eigenvalue;
55  return;
56  }
57 
58  // act only if we have mesh
59  if (_mesh.get() != NULL)
60  {
61  // Make sure the problem hasn't already been created elsewhere
62  if (!_problem)
63  {
64  std::string type;
65  if (_app.useEigenvalue())
66  type = "EigenProblem";
67  else
68  type = "FEProblem";
69  auto params = _factory.getValidParams(type);
70 
71  // apply common parameters of the object held by CreateProblemAction to honor user inputs in
72  // [Problem]
73  auto p = _awh.getActionByTask<CreateProblemAction>("create_problem");
74  if (p)
75  params.applyParameters(p->getObjectParams());
76 
77  params.set<MooseMesh *>("mesh") = _mesh.get();
78  params.set<bool>("use_nonlinear") = _app.useNonlinear();
79  if (_pars.isParamValid("_solve"))
80  params.set<bool>("solve") = getParam<bool>("_solve");
81 
82  _problem = _factory.create<FEProblemBase>(type, "MOOSE Problem", params);
83  }
84  else
85  {
86  // otherwise perform necessary sanity checks
88  mooseError("Problem has to be of a EigenProblem (or derived subclass) type when using "
89  "eigen executioner");
90  }
91  }
92 }
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
bool & useNonlinear()
Returns a writable Boolean indicating whether this app will use a Nonlinear or Eigen System...
Definition: MooseApp.h:386
ActionWarehouse & _awh
Reference to ActionWarehouse where we store object build by actions.
Definition: Action.h:170
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...
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, const InputParameters &parameters, THREAD_ID tid=0, bool print_deprecated=true)
Definition: Factory.C:110
InputParameters getValidParams(const std::string &name) const
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...
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.
static InputParameters validParams()
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Base class for actions.
Definition: Action.h:38
Factory & _factory
The Factory associated with the MooseApp.
static InputParameters validParams()
Definition: Action.C:24
bool & useEigenvalue()
Returns a writable Boolean indicating whether this app will use an eigenvalue executioner.
Definition: MooseApp.h:391
InputParameters & getObjectParams()
Retreive the parameters of the object to be created by this action.
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:88
const std::string & type() const
Get the type of this class.
Definition: MooseBase.h:51
const std::string & _current_task
The current action (even though we have separate instances for each action)
Definition: Action.h:173
MooseApp & _app
The MOOSE application this is associated with.
Definition: MooseBase.h:84
std::shared_ptr< MooseMesh > & _mesh
Definition: Action.h:175
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
const InputParameters & _pars
Parameters of this object, references the InputParameters stored in the InputParametersWarehouse.
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:179
CreateProblemDefaultAction(const InputParameters &parameters)
Problem for solving eigenvalue problems.
Definition: EigenProblem.h:21
registerMooseAction("MooseApp", CreateProblemDefaultAction, "create_problem_default")
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.