www.mooseframework.org
CreateExecutionerAction.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 #include "Factory.h"
12 #include "PetscSupport.h"
13 #include "MooseApp.h"
14 #include "Executioner.h"
15 #include "Eigenvalue.h"
16 #include "FEProblem.h"
17 #include "EigenProblem.h"
18 
19 registerMooseAction("MooseApp", CreateExecutionerAction, "setup_executioner");
20 
22 
25 {
27  params.addParam<bool>(
28  "auto_preconditioning",
29  true,
30  "When true and a [Preconditioning] block does not exist, the application will attempt to use "
31  "the correct preconditioning given the Executioner settings.");
32  return params;
33 }
34 
36  : MooseObjectAction(params), _auto_preconditioning(getParam<bool>("auto_preconditioning"))
37 {
38 }
39 
40 void
42 {
43  std::shared_ptr<EigenProblem> eigen_problem = std::dynamic_pointer_cast<EigenProblem>(_problem);
44  if (eigen_problem)
45  _moose_object_pars.set<EigenProblem *>("_eigen_problem") = eigen_problem.get();
46 
47  std::shared_ptr<Executioner> executioner =
49 
50  std::shared_ptr<Eigenvalue> eigen_executioner =
51  std::dynamic_pointer_cast<Eigenvalue>(executioner);
52 
53  if ((eigen_problem == nullptr) != (eigen_executioner == nullptr))
54  mooseError("Executioner is not consistent with each other; EigenExecutioner needs an "
55  "EigenProblem, and Steady and Transient need a FEProblem");
56 
57  // If enabled, automatically create a Preconditioner if the [Preconditioning] block is not found
58  if (_auto_preconditioning && !_awh.hasActions("add_preconditioning"))
60 
61  _app.setExecutioner(std::move(executioner));
62 }
63 
64 void
66 {
67  // If using NEWTON or LINEAR then automatically create SingleMatrixPreconditioner object with
68  // full=true
69  const MooseEnum & solve_type = _moose_object_pars.get<MooseEnum>("solve_type");
70  if (((solve_type.find("NEWTON") != solve_type.items().end()) && (solve_type == "NEWTON")) ||
71  ((solve_type.find("LINEAR") != solve_type.items().end()) && (solve_type == "LINEAR")))
72  {
73  // Action Parameters
74  InputParameters params = _action_factory.getValidParams("SetupPreconditionerAction");
75  params.set<std::string>("type") = "SMP";
76 
77  // Create the Action that will build the Preconditioner object
78  std::shared_ptr<Action> ptr =
79  _action_factory.create("SetupPreconditionerAction", "_moose_auto", params);
80 
81  // Set 'full=true'
82  std::shared_ptr<MooseObjectAction> moa_ptr = std::static_pointer_cast<MooseObjectAction>(ptr);
83  InputParameters & mo_params = moa_ptr->getObjectParams();
84  mo_params.set<bool>("full") = true;
85 
86  _awh.addActionBlock(ptr);
87  }
88 }
CreateExecutionerAction::setupAutoPreconditioning
virtual void setupAutoPreconditioning()
Definition: CreateExecutionerAction.C:65
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
FEProblem.h
CreateExecutionerAction::validParams
static InputParameters validParams()
Definition: CreateExecutionerAction.C:24
ActionFactory::getValidParams
InputParameters getValidParams(const std::string &name)
Definition: ActionFactory.C:70
MooseEnumBase::items
const std::set< MooseEnumItem > & items() const
Return the complete set of available flags.
Definition: MooseEnumBase.h:93
MooseEnum
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:31
CreateExecutionerAction::_auto_preconditioning
const bool _auto_preconditioning
Definition: CreateExecutionerAction.h:32
InputParameters::addParam
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object.
Definition: InputParameters.h:1198
ActionWarehouse::addActionBlock
void addActionBlock(std::shared_ptr< Action > blk)
This method add an Action instance to the warehouse.
Definition: ActionWarehouse.C:73
CreateExecutionerAction::act
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
Definition: CreateExecutionerAction.C:41
defineLegacyParams
defineLegacyParams(CreateExecutionerAction)
Executioner
Executioners are objects that do the actual work of solving your problem.
Definition: Executioner.h:32
registerMooseAction
registerMooseAction("MooseApp", CreateExecutionerAction, "setup_executioner")
CreateExecutionerAction.h
Action::_action_factory
ActionFactory & _action_factory
Builds Actions.
Definition: Action.h:219
Action::_problem
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
Definition: Action.h:246
Executioner.h
mooseError
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition: MooseError.h:210
MooseObjectAction::validParams
static InputParameters validParams()
Definition: MooseObjectAction.C:21
InputParameters
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
Definition: InputParameters.h:53
CreateExecutionerAction::CreateExecutionerAction
CreateExecutionerAction(InputParameters params)
Definition: CreateExecutionerAction.C:35
MooseApp::setExecutioner
void setExecutioner(std::shared_ptr< Executioner > &&executioner)
Set the Executioner for this App.
Definition: MooseApp.h:287
CreateExecutionerAction
Definition: CreateExecutionerAction.h:19
InputParameters::set
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
Definition: InputParameters.h:987
Action::_factory
Factory & _factory
The Factory associated with the MooseApp.
Definition: Action.h:216
ActionFactory::create
std::shared_ptr< Action > create(const std::string &action, const std::string &action_name, InputParameters &parameters)
Definition: ActionFactory.C:41
MooseObjectAction::_type
std::string _type
The Object type that is being created.
Definition: MooseObjectAction.h:48
MooseApp.h
MooseObjectAction::_moose_object_pars
InputParameters _moose_object_pars
The parameters for the object to be created.
Definition: MooseObjectAction.h:51
MooseEnumBase::find
std::set< MooseEnumItem >::const_iterator find(const MooseEnumItem &other) const
Locate an item.
Definition: MooseEnumBase.C:190
Eigenvalue.h
EigenProblem
Problem for solving eigenvalue problems.
Definition: EigenProblem.h:26
MooseObjectAction
Definition: MooseObjectAction.h:21
Action::_awh
ActionWarehouse & _awh
Reference to ActionWarehouse where we store object build by actions.
Definition: Action.h:237
Factory.h
ActionWarehouse::hasActions
bool hasActions(const std::string &task) const
Check if Actions associated with passed in task exist.
Definition: ActionWarehouse.C:198
EigenProblem.h
PetscSupport.h