https://mooseframework.inl.gov
CreateExecutionerAction.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
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 #include "Factory.h"
12 #include "PetscSupport.h"
13 #include "MooseApp.h"
14 #include "Executioner.h"
15 #include "FEProblem.h"
16 #include "EigenProblem.h"
17 #include "EigenProblemSolve.h"
18 
19 registerMooseAction("MooseApp", CreateExecutionerAction, "setup_executioner");
20 
23 {
25  params.addClassDescription("Add an Executioner object to the simulation.");
26  params.addParam<bool>(
27  "auto_preconditioning",
28  true,
29  "When true and a [Preconditioning] block does not exist, the application will attempt to use "
30  "the correct preconditioning given the Executioner settings.");
31  return params;
32 }
33 
35  : MooseObjectAction(params), _auto_preconditioning(getParam<bool>("auto_preconditioning"))
36 {
37 }
38 
39 void
41 {
42  std::shared_ptr<EigenProblem> eigen_problem = std::dynamic_pointer_cast<EigenProblem>(_problem);
43  if (eigen_problem)
44  _moose_object_pars.set<EigenProblem *>("_eigen_problem") = eigen_problem.get();
45  _moose_object_pars.set<SubProblem *>("_subproblem") = static_cast<SubProblem *>(_problem.get());
46 
47  std::shared_ptr<Executioner> executioner =
49 
50  if ((eigen_problem != nullptr) != executioner->hasSolveObject<EigenProblemSolve>())
51  mooseError("Executioner is not consistent with each other; EigenExecutioner needs an "
52  "EigenProblem, and Steady and Transient need a FEProblem");
53 
54  // If enabled, automatically create a Preconditioner if the [Preconditioning] block is not found
55  if (_auto_preconditioning && !_awh.hasActions("add_preconditioning") &&
56  _moose_object_pars.isParamValid("solve_type"))
58 
59  _app.setExecutioner(std::move(executioner));
60 }
61 
62 void
64 {
65  // If using NEWTON or LINEAR then automatically create SingleMatrixPreconditioner object with
66  // full=true
67  const MooseEnum & solve_type = _moose_object_pars.get<MooseEnum>("solve_type");
68  if (((solve_type.find("NEWTON") != solve_type.items().end()) && (solve_type == "NEWTON")) ||
69  ((solve_type.find("LINEAR") != solve_type.items().end()) && (solve_type == "LINEAR")))
70  for (const auto & nl_sys_name : _problem->getNonlinearSystemNames())
71  {
72  // Action Parameters
73  InputParameters params = _action_factory.getValidParams("SetupPreconditionerAction");
74  params.set<std::string>("type") = "SMP";
75 
76  // Associate errors with "solve_type"
77  associateWithParameter(_moose_object_pars, "solve_type", params);
78 
79  // Create the Action that will build the Preconditioner object
80  std::shared_ptr<Action> ptr = _action_factory.create(
81  "SetupPreconditionerAction",
82  MooseUtils::join(
83  std::vector<std::string>({"_moose_auto", static_cast<std::string>(nl_sys_name)}),
84  "_"),
85  params);
86 
87  // Set 'full=true'
88  std::shared_ptr<MooseObjectAction> moa_ptr = std::static_pointer_cast<MooseObjectAction>(ptr);
89  InputParameters & mo_params = moa_ptr->getObjectParams();
90  mo_params.set<bool>("full") = true;
91  mo_params.set<NonlinearSystemName>("nl_sys") = nl_sys_name;
92 
93  _awh.addActionBlock(ptr);
94  }
95 }
const std::set< MooseEnumItem > & items() const
Return the complete set of available flags.
Definition: MooseEnumBase.h:93
void setExecutioner(std::shared_ptr< Executioner > &&executioner)
Set the Executioner for this App.
Definition: MooseApp.h:348
CreateExecutionerAction(const InputParameters &params)
EigenProblemSolve is used to solve an eigenvalue problem interfacing SLEPc.
ActionWarehouse & _awh
Reference to ActionWarehouse where we store object build by actions.
Definition: Action.h:169
InputParameters getValidParams(const std::string &name)
Definition: ActionFactory.C:94
static InputParameters validParams()
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
Factory & _factory
The Factory associated with the MooseApp.
ActionFactory & _action_factory
Builds Actions.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
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:142
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
static InputParameters validParams()
void addActionBlock(std::shared_ptr< Action > blk)
This method add an Action instance to the warehouse.
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.
std::shared_ptr< Action > create(const std::string &action, const std::string &action_name, InputParameters &parameters)
Definition: ActionFactory.C:40
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:54
Executioners are objects that do the actual work of solving your problem.
Definition: Executioner.h:30
MooseApp & _app
The MOOSE application this is associated with.
Definition: MooseBase.h:385
std::string _type
The Object type that is being created.
bool hasActions(const std::string &task) const
Check if Actions associated with passed in task exist.
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:78
InputParameters _moose_object_pars
The parameters for the object to be created.
registerMooseAction("MooseApp", CreateExecutionerAction, "setup_executioner")
void associateWithParameter(const std::string &param_name, InputParameters &params) const
Associates the object&#39;s parameters params with the input location from this Action&#39;s parameter with t...
Definition: Action.C:153
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition: MooseBase.h:281
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
Definition: Action.h:178
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
Problem for solving eigenvalue problems.
Definition: EigenProblem.h:21
std::set< MooseEnumItem >::const_iterator find(const MooseEnumItem &other) const
Locate an item.
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.